Skip to content

Commit d94246a

Browse files
committed
fix: partially fix a bug that prevented group part messages from
sending. When a peer leaves a group, they send a packet to the group indicating that they're leaving. However if this packet is sent via TCP, it gets put in a packet queue, which is then destroyed on the rest of the group cleanup process before ever being able to send. This pr allows do_gc() to finish an iteration before cleaning the group up, which allows the TCP packet queue to be emptied. However this bug still exists on a tox_kill() event because we don't have a chance to do another do_gc() iteration.
1 parent eeaa039 commit d94246a

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

auto_tests/group_general_test.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,13 @@ static void group_announce_test(AutoTox *autotoxes)
441441
tox_group_leave(tox1, groupnumber, nullptr, 0, &err_exit);
442442
ck_assert(err_exit == TOX_ERR_GROUP_LEAVE_OK);
443443

444-
num_groups1 = tox_group_get_number_groups(tox0);
445-
num_groups2 = tox_group_get_number_groups(tox1);
444+
while (num_groups1 != 0 || num_groups2 != 0) {
445+
num_groups1 = tox_group_get_number_groups(tox0);
446+
num_groups2 = tox_group_get_number_groups(tox1);
447+
448+
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
449+
}
446450

447-
ck_assert(num_groups1 == num_groups2 && num_groups2 == 0);
448451

449452
printf("All tests passed!\n");
450453
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7dfcf534fb80fbd8337337f5aa9eaa120febc72386046c7ab0d5c7545e900657 /usr/local/bin/tox-bootstrapd
1+
e5ccf844b7ece48d1153c226bdf8462d0e85d517dfcd720c8d6c4abad7da6929 /usr/local/bin/tox-bootstrapd

toxcore/group_chats.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7281,6 +7281,10 @@ void do_gc(GC_Session *c, void *userdata)
72817281

72827282
do_new_connection_cooldown(chat);
72837283
do_peer_delete(c, chat, userdata);
7284+
7285+
if (chat->flag_exit) { // should always come last as it modifies the chats array
7286+
group_delete(c, chat);
7287+
}
72847288
}
72857289
}
72867290

@@ -8270,14 +8274,21 @@ static void group_delete(GC_Session *c, GC_Chat *chat)
82708274
c->chats_index = i;
82718275

82728276
if (!realloc_groupchats(c, c->chats_index)) {
8273-
LOGGER_ERROR(chat->log, "Failed to reallocate groupchats array");
8277+
LOGGER_ERROR(c->messenger->log, "Failed to reallocate groupchats array");
82748278
}
82758279
}
82768280
}
82778281

82788282
int gc_group_exit(GC_Session *c, GC_Chat *chat, const uint8_t *message, uint16_t length)
82798283
{
8280-
const int ret = group_can_handle_packets(chat) ? send_gc_self_exit(chat, message, length) : 0;
8284+
chat->flag_exit = true;
8285+
return group_can_handle_packets(chat) ? send_gc_self_exit(chat, message, length) : 0;
8286+
}
8287+
8288+
non_null()
8289+
static int kill_group(GC_Session *c, GC_Chat *chat)
8290+
{
8291+
const int ret = gc_group_exit(c, chat, nullptr, 0);
82818292
group_delete(c, chat);
82828293
return ret;
82838294
}
@@ -8295,11 +8306,9 @@ void kill_dht_groupchats(GC_Session *c)
82958306
continue;
82968307
}
82978308

8298-
if (group_can_handle_packets(chat)) {
8299-
send_gc_self_exit(chat, nullptr, 0);
8309+
if (kill_group(c, chat) != 0) {
8310+
LOGGER_WARNING(c->messenger->log, "Failed to send group exit packet");
83008311
}
8301-
8302-
group_cleanup(c, chat);
83038312
}
83048313

83058314
networking_registerhandler(c->messenger->net, NET_PACKET_GC_LOSSY, nullptr, nullptr);

toxcore/group_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ typedef struct GC_Chat {
321321

322322
uint8_t m_group_public_key[CRYPTO_PUBLIC_KEY_SIZE]; // public key for group's messenger friend connection
323323
int friend_connection_id; // identifier for group's messenger friend connection
324+
325+
bool flag_exit; // true if the group will be deleted after the next do_gc() iteration
324326
} GC_Chat;
325327

326328
#ifndef MESSENGER_DEFINED

0 commit comments

Comments
 (0)