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.
This commit is contained in:
irungentoo 2014-11-30 21:01:36 -05:00
parent ee0f06937f
commit 15b73db70c
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -1315,7 +1315,7 @@ static void handle_friend_invite_packet(Messenger *m, int32_t friendnumber, cons
*/ */
static int friend_in_close(Group_c *g, int friendcon_id) static int friend_in_close(Group_c *g, int friendcon_id)
{ {
int i; unsigned int i;
for (i = 0; i < MAX_GROUP_CONNECTIONS; ++i) { for (i = 0; i < MAX_GROUP_CONNECTIONS; ++i) {
if (g->close[i].type == GROUPCHAT_CLOSE_NONE) if (g->close[i].type == GROUPCHAT_CLOSE_NONE)
@ -1330,6 +1330,21 @@ static int friend_in_close(Group_c *g, int friendcon_id)
return -1; return -1;
} }
/* return number of connected close connections.
*/
static unsigned int count_close_connected(Group_c *g)
{
unsigned int i, count = 0;
for (i = 0; i < MAX_GROUP_CONNECTIONS; ++i) {
if (g->close[i].type == GROUPCHAT_CLOSE_ONLINE) {
++count;
}
}
return count;
}
#define ONLINE_PACKET_DATA_SIZE (sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH) #define ONLINE_PACKET_DATA_SIZE (sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH)
static int send_packet_online(Friend_Connections *fr_c, int friendcon_id, uint16_t group_num, uint8_t *identifier) static 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
g->close[index].group_number = other_groupnum; g->close[index].group_number = other_groupnum;
g->close[index].type = GROUPCHAT_CLOSE_ONLINE; g->close[index].type = GROUPCHAT_CLOSE_ONLINE;
if (g->number_joined != -1 && g->number_joined != friendcon_id) { if (g->number_joined != -1 && count_close_connected(g) >= DESIRED_CLOSE_CONNECTIONS) {
int fr_close_index = friend_in_close(g, g->number_joined); int fr_close_index = friend_in_close(g, g->number_joined);
uint8_t real_pk[crypto_box_PUBLICKEYBYTES]; uint8_t real_pk[crypto_box_PUBLICKEYBYTES];
uint8_t dht_temp_pk[crypto_box_PUBLICKEYBYTES]; uint8_t dht_temp_pk[crypto_box_PUBLICKEYBYTES];
get_friendcon_public_keys(real_pk, dht_temp_pk, g_c->fr_c, g->number_joined); get_friendcon_public_keys(real_pk, dht_temp_pk, g_c->fr_c, g->number_joined);
g->number_joined = -1;
if (fr_close_index == -1) if (fr_close_index == -1)
return -1; return -1;
if (!g->close[fr_close_index].closest && pk_in_closest_peers(g, real_pk)) {
g->close[fr_close_index].closest = 1;
}
if (!g->close[fr_close_index].closest) { if (!g->close[fr_close_index].closest) {
g->close[fr_close_index].type = GROUPCHAT_CLOSE_NONE; g->close[fr_close_index].type = GROUPCHAT_CLOSE_NONE;
send_peer_kill(g_c, g->close[fr_close_index].number, g->close[fr_close_index].group_number); send_peer_kill(g_c, g->close[fr_close_index].number, g->close[fr_close_index].group_number);
kill_friend_connection(g_c->fr_c, g->close[fr_close_index].number); kill_friend_connection(g_c->fr_c, g->close[fr_close_index].number);
g->number_joined = -1;
} }
} }