Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: partially fix a bug that prevented group part messages from sending #2609

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions auto_tests/group_general_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,13 @@ static void group_announce_test(AutoTox *autotoxes)
tox_group_leave(tox1, groupnumber, nullptr, 0, &err_exit);
ck_assert(err_exit == TOX_ERR_GROUP_LEAVE_OK);

num_groups1 = tox_group_get_number_groups(tox0);
num_groups2 = tox_group_get_number_groups(tox1);
while (num_groups1 != 0 || num_groups2 != 0) {
num_groups1 = tox_group_get_number_groups(tox0);
num_groups2 = tox_group_get_number_groups(tox1);

iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
}

ck_assert(num_groups1 == num_groups2 && num_groups2 == 0);

printf("All tests passed!\n");
}
Expand Down
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7dfcf534fb80fbd8337337f5aa9eaa120febc72386046c7ab0d5c7545e900657 /usr/local/bin/tox-bootstrapd
e5ccf844b7ece48d1153c226bdf8462d0e85d517dfcd720c8d6c4abad7da6929 /usr/local/bin/tox-bootstrapd
21 changes: 15 additions & 6 deletions toxcore/group_chats.c
Original file line number Diff line number Diff line change
Expand Up @@ -7281,6 +7281,10 @@

do_new_connection_cooldown(chat);
do_peer_delete(c, chat, userdata);

if (chat->flag_exit) { // should always come last as it modifies the chats array
group_delete(c, chat);
}
}
}

Expand Down Expand Up @@ -8270,14 +8274,21 @@
c->chats_index = i;

if (!realloc_groupchats(c, c->chats_index)) {
LOGGER_ERROR(chat->log, "Failed to reallocate groupchats array");
LOGGER_ERROR(c->messenger->log, "Failed to reallocate groupchats array");

Check warning on line 8277 in toxcore/group_chats.c

View check run for this annotation

Codecov / codecov/patch

toxcore/group_chats.c#L8277

Added line #L8277 was not covered by tests
}
}
}

int gc_group_exit(GC_Session *c, GC_Chat *chat, const uint8_t *message, uint16_t length)
{
const int ret = group_can_handle_packets(chat) ? send_gc_self_exit(chat, message, length) : 0;
chat->flag_exit = true;
return group_can_handle_packets(chat) ? send_gc_self_exit(chat, message, length) : 0;
}

non_null()
static int kill_group(GC_Session *c, GC_Chat *chat)
{
const int ret = gc_group_exit(c, chat, nullptr, 0);
group_delete(c, chat);
nurupo marked this conversation as resolved.
Show resolved Hide resolved
return ret;
}
Expand All @@ -8295,11 +8306,9 @@
continue;
}

if (group_can_handle_packets(chat)) {
send_gc_self_exit(chat, nullptr, 0);
if (kill_group(c, chat) != 0) {
LOGGER_WARNING(c->messenger->log, "Failed to send group exit packet");
}

group_cleanup(c, chat);
}

networking_registerhandler(c->messenger->net, NET_PACKET_GC_LOSSY, nullptr, nullptr);
Expand Down
2 changes: 2 additions & 0 deletions toxcore/group_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ typedef struct GC_Chat {

uint8_t m_group_public_key[CRYPTO_PUBLIC_KEY_SIZE]; // public key for group's messenger friend connection
int friend_connection_id; // identifier for group's messenger friend connection

bool flag_exit; // true if the group will be deleted after the next do_gc() iteration
} GC_Chat;

#ifndef MESSENGER_DEFINED
Expand Down
Loading