Skip to content

Commit

Permalink
Fix group topic test
Browse files Browse the repository at this point in the history
  • Loading branch information
JFreegman committed Apr 1, 2022
1 parent a90dcf6 commit b0e087b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 9 additions & 4 deletions auto_tests/group_topic_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#define TOPIC "They're waiting for you Gordon...in the test chamber"
#define TOPIC_LEN (sizeof(TOPIC) - 1)

#define TOPIC2 "They're waiting for you Gordon...in the test chamber 2.0"
#define TOPIC_LEN2 (sizeof(TOPIC2) - 1)

#define GROUP_NAME "The Test Chamber"
#define GROUP_NAME_LEN (sizeof(GROUP_NAME) - 1)

Expand Down Expand Up @@ -189,7 +192,7 @@ static uint32_t set_topic_all_peers(AutoTox *autotoxes, size_t num_peers, uint32

for (size_t i = 0; i < num_peers; ++i) {
char new_topic[TOX_GROUP_MAX_TOPIC_LENGTH];
snprintf(new_topic, sizeof(new_topic), "peer %zu changes topic", i);
snprintf(new_topic, sizeof(new_topic), "peer %zu changes topic %u", i, random_u32());
size_t length = strlen(new_topic);

if (set_topic(autotoxes[i].tox, groupnumber, new_topic, length) == 0) {
Expand Down Expand Up @@ -296,10 +299,10 @@ static void group_topic_test(AutoTox *autotoxes)
/* Wait for all peers to get topic lock state change */
wait_topic_lock(autotoxes, groupnumber, TOX_GROUP_TOPIC_LOCK_ENABLED);

const int s3_ret = set_topic(tox0, groupnumber, TOPIC, TOPIC_LEN);
const int s3_ret = set_topic(tox0, groupnumber, TOPIC2, TOPIC_LEN2);
ck_assert_msg(s3_ret == 0, "Founder failed to set topic second time: %d", s3_ret);

wait_state_topic(autotoxes, groupnumber, TOPIC, TOPIC_LEN);
wait_state_topic(autotoxes, groupnumber, TOPIC2, TOPIC_LEN2);

/* No peer excluding the founder should be able to set the topic */

Expand All @@ -308,7 +311,7 @@ static void group_topic_test(AutoTox *autotoxes)
ck_assert_msg(change_count == 0, "%u peers changed the topic with topic lock enabled", change_count);

/* A final check that the topic is unchanged */
wait_state_topic(autotoxes, groupnumber, TOPIC, TOPIC_LEN);
wait_state_topic(autotoxes, groupnumber, TOPIC2, TOPIC_LEN2);

for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
Tox_Err_Group_Leave err_exit;
Expand All @@ -335,6 +338,8 @@ int main(void)

#undef TOPIC
#undef TOPIC_LEN
#undef TOPIC2
#undef TOPIC_LEN2
#undef NUM_GROUP_TOXES
#undef GROUP_NAME
#undef GROUP_NAME_LEN
Expand Down
5 changes: 2 additions & 3 deletions toxcore/group_chats.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ static void set_gc_peerlist_checksum(GC_Chat *chat)
non_null()
static uint16_t get_gc_topic_checksum(const GC_TopicInfo *topic_info)
{

return data_checksum(topic_info->topic, topic_info->length);
}

Expand Down Expand Up @@ -3746,8 +3745,6 @@ static bool handle_gc_topic_validate(const GC_Chat *chat, const GC_Peer *peer, c
}
}

// the topic version should never change when the topic lock is disabled except when
// the founder changes the topic prior to enabling the lock
if (topic_info->version == chat->shared_state.topic_lock) {
if (chat->topic_prev_checksum == topic_info->checksum &&
!mono_time_is_timeout(chat->mono_time, chat->topic_time_set, GC_CONFIRMED_PEER_TIMEOUT)) {
Expand All @@ -3758,6 +3755,8 @@ static bool handle_gc_topic_validate(const GC_Chat *chat, const GC_Peer *peer, c
return true;
}

// the topic version should never change when the topic lock is disabled except when
// the founder changes the topic prior to enabling the lock
if (!(peer->role == GR_FOUNDER && topic_info->version == chat->shared_state.topic_lock + 1)) {
LOGGER_ERROR(chat->log, "topic version %u differs from topic lock %u", topic_info->version,
chat->shared_state.topic_lock);
Expand Down

0 comments on commit b0e087b

Please sign in to comment.