summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-11-30 21:01:36 -0500
committerirungentoo <irungentoo@gmail.com>2014-11-30 21:01:36 -0500
commit15b73db70c93f827334fcccb6bb0ac979ef67630 (patch)
treeb9481659b77c6300361a4d029ffa539cca740bcb
parentee0f06937fc22e69f4849a781b2b3d40af639069 (diff)
Joining a group chat should be more reliable.
Only disconnect from the friend we used to join when we are connected to at least 3 other people.
-rw-r--r--toxcore/group.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/toxcore/group.c b/toxcore/group.c
index 329a9709..da068e9b 100644
--- a/toxcore/group.c
+++ b/toxcore/group.c
@@ -1315,7 +1315,7 @@ static void handle_friend_invite_packet(Messenger *m, int32_t friendnumber, cons
1315 */ 1315 */
1316static int friend_in_close(Group_c *g, int friendcon_id) 1316static int friend_in_close(Group_c *g, int friendcon_id)
1317{ 1317{
1318 int i; 1318 unsigned int i;
1319 1319
1320 for (i = 0; i < MAX_GROUP_CONNECTIONS; ++i) { 1320 for (i = 0; i < MAX_GROUP_CONNECTIONS; ++i) {
1321 if (g->close[i].type == GROUPCHAT_CLOSE_NONE) 1321 if (g->close[i].type == GROUPCHAT_CLOSE_NONE)
@@ -1330,6 +1330,21 @@ static int friend_in_close(Group_c *g, int friendcon_id)
1330 return -1; 1330 return -1;
1331} 1331}
1332 1332
1333/* return number of connected close connections.
1334 */
1335static unsigned int count_close_connected(Group_c *g)
1336{
1337 unsigned int i, count = 0;
1338
1339 for (i = 0; i < MAX_GROUP_CONNECTIONS; ++i) {
1340 if (g->close[i].type == GROUPCHAT_CLOSE_ONLINE) {
1341 ++count;
1342 }
1343 }
1344
1345 return count;
1346}
1347
1333#define ONLINE_PACKET_DATA_SIZE (sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH) 1348#define ONLINE_PACKET_DATA_SIZE (sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH)
1334 1349
1335static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t *identifier) 1350static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t *identifier)
@@ -1368,24 +1383,20 @@ static int handle_packet_online(Group_Chats *g_c, int friendcon_id, uint8_t *dat
1368 g->close[index].group_number = other_groupnum; 1383 g->close[index].group_number = other_groupnum;
1369 g->close[index].type = GROUPCHAT_CLOSE_ONLINE; 1384 g->close[index].type = GROUPCHAT_CLOSE_ONLINE;
1370 1385
1371 if (g->number_joined != -1 && g->number_joined != friendcon_id) { 1386 if (g->number_joined != -1 && count_close_connected(g) >= DESIRED_CLOSE_CONNECTIONS) {
1372 int fr_close_index = friend_in_close(g, g->number_joined); 1387 int fr_close_index = friend_in_close(g, g->number_joined);
1373 uint8_t real_pk[crypto_box_PUBLICKEYBYTES]; 1388 uint8_t real_pk[crypto_box_PUBLICKEYBYTES];
1374 uint8_t dht_temp_pk[crypto_box_PUBLICKEYBYTES]; 1389 uint8_t dht_temp_pk[crypto_box_PUBLICKEYBYTES];
1375 get_friendcon_public_keys(real_pk, dht_temp_pk, g_c->fr_c, g->number_joined); 1390 get_friendcon_public_keys(real_pk, dht_temp_pk, g_c->fr_c, g->number_joined);
1376 g->number_joined = -1;
1377 1391
1378 if (fr_close_index == -1) 1392 if (fr_close_index == -1)
1379 return -1; 1393 return -1;
1380 1394
1381 if (!g->close[fr_close_index].closest && pk_in_closest_peers(g, real_pk)) {
1382 g->close[fr_close_index].closest = 1;
1383 }
1384
1385 if (!g->close[fr_close_index].closest) { 1395 if (!g->close[fr_close_index].closest) {
1386 g->close[fr_close_index].type = GROUPCHAT_CLOSE_NONE; 1396 g->close[fr_close_index].type = GROUPCHAT_CLOSE_NONE;
1387 send_peer_kill(g_c, g->close[fr_close_index].number, g->close[fr_close_index].group_number); 1397 send_peer_kill(g_c, g->close[fr_close_index].number, g->close[fr_close_index].group_number);
1388 kill_friend_connection(g_c->fr_c, g->close[fr_close_index].number); 1398 kill_friend_connection(g_c->fr_c, g->close[fr_close_index].number);
1399 g->number_joined = -1;
1389 } 1400 }
1390 } 1401 }
1391 1402