Skip to content

Commit

Permalink
Merge de32402 into 597f23b
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Jul 6, 2018
2 parents 597f23b + de32402 commit a3ca64e
Show file tree
Hide file tree
Showing 62 changed files with 19,240 additions and 1,536 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ cscope.files

# rpm
tox.spec

.idea/
27 changes: 24 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,27 @@ set(toxcore_SOURCES ${toxcore_SOURCES}
toxcore/friend_requests.c
toxcore/friend_requests.h)

# LAYER 6: Tox messenger
# LAYER 6: DHT based group chats
# ----------------------
set(toxcore_SOURCES ${toxcore_SOURCES}
toxcore/group_announce.c
toxcore/group_chats.c
toxcore/group_connection.c
toxcore/group_moderation.c)

# LAYER 7: Tox messenger
# ----------------------
set(toxcore_SOURCES ${toxcore_SOURCES}
toxcore/Messenger.c
toxcore/Messenger.h)

# LAYER 7: Group chats
# LAYER 8: Conferences: friend based group chats
# --------------------
set(toxcore_SOURCES ${toxcore_SOURCES}
toxcore/group.c
toxcore/group.h)

# LAYER 8: Public API
# LAYER 9: Public API
# -------------------
apidsl(toxcore/tox.api.h)
set(toxcore_SOURCES ${toxcore_SOURCES}
Expand Down Expand Up @@ -395,6 +403,7 @@ auto_test(encryptsave)
auto_test(file_transfer)
auto_test(friend_connection)
auto_test(friend_request)
auto_test(groupchat)
auto_test(invalid_proxy)
auto_test(invalid_tcp_proxy)
auto_test(lan_discovery)
Expand Down Expand Up @@ -505,3 +514,15 @@ target_link_modules(Messenger_test toxcore)
add_executable(random_testing ${CPUFEATURES}
testing/random_testing.cc)
target_link_modules(random_testing toxcore)

add_executable(group_announce_test ${CPUFEATURES}
testing/groupchats/group_announce_test.c)
target_link_modules(group_announce_test toxcore)

add_executable(group_bootstrap_n_chat ${CPUFEATURES}
testing/groupchats/group_bootstrap_n_chat.c)
target_link_modules(group_bootstrap_n_chat toxcore)

add_executable(group_newpeers_dos_attack ${CPUFEATURES}
testing/groupchats/group_newpeers_dos_attack.c)
target_link_modules(group_newpeers_dos_attack toxcore)
11 changes: 9 additions & 2 deletions auto_tests/Makefile.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if BUILD_TESTS

TESTS = encryptsave_test messenger_autotest crypto_test network_test onion_test TCP_test dht_autotest tox_strncasecmp_test
check_PROGRAMS = encryptsave_test messenger_autotest crypto_test network_test onion_test TCP_test dht_autotest tox_strncasecmp_test
TESTS = groupchat_test encryptsave_test messenger_autotest crypto_test network_test onion_test TCP_test dht_autotest tox_strncasecmp_test
check_PROGRAMS = groupchat_test encryptsave_test messenger_autotest crypto_test network_test onion_test TCP_test dht_autotest tox_strncasecmp_test

AUTOTEST_CFLAGS = \
$(LIBSODIUM_CFLAGS) \
Expand Down Expand Up @@ -114,5 +114,12 @@ tox_strncasecmp_test_CFLAGS = $(AUTOTEST_CFLAGS)
tox_strncasecmp_test_LDADD = $(AUTOTEST_LDADD)


groupchat_test_SOURCES = ../auto_tests/groupchat_test.c

groupchat_test_CFLAGS = $(AUTOTEST_CFLAGS)

groupchat_test_LDADD = $(AUTOTEST_LDADD)


EXTRA_DIST += $(top_srcdir)/auto_tests/check_compat.h
EXTRA_DIST += $(top_srcdir)/auto_tests/helpers.h
108 changes: 59 additions & 49 deletions auto_tests/conference_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

#include "helpers.h"

#define NUM_GROUP_TOX 5
#define NUM_GROUP_TOX 16
#define GROUP_MESSAGE "Install Gentoo"

static void handle_self_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *user_data)
static void handle_self_connection_status(
Tox *tox, TOX_CONNECTION connection_status, void *user_data)
{
const int id = *(int *)user_data;

Expand All @@ -35,8 +36,8 @@ static void handle_self_connection_status(Tox *tox, TOX_CONNECTION connection_st
}
}

static void handle_friend_connection_status(Tox *tox, uint32_t friendnumber, TOX_CONNECTION connection_status,
void *user_data)
static void handle_friend_connection_status(
Tox *tox, uint32_t friendnumber, TOX_CONNECTION connection_status, void *user_data)
{
const int id = *(int *)user_data;

Expand All @@ -47,8 +48,9 @@ static void handle_friend_connection_status(Tox *tox, uint32_t friendnumber, TOX
}
}

static void handle_conference_invite(Tox *tox, uint32_t friendnumber, TOX_CONFERENCE_TYPE type, const uint8_t *data,
size_t length, void *user_data)
static void handle_conference_invite(
Tox *tox, uint32_t friendnumber, TOX_CONFERENCE_TYPE type,
const uint8_t *data, size_t length, void *user_data)
{
const int id = *(int *)user_data;
ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%d: wrong conference type: %d", id, type);
Expand All @@ -74,14 +76,61 @@ static void handle_conference_invite(Tox *tox, uint32_t friendnumber, TOX_CONFER

static unsigned int num_recv;

static void handle_conference_message(Tox *tox, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type,
const uint8_t *message, size_t length, void *user_data)
static void handle_conference_message(
Tox *tox, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type,
const uint8_t *message, size_t length, void *user_data)
{
if (length == (sizeof(GROUP_MESSAGE) - 1) && memcmp(message, GROUP_MESSAGE, sizeof(GROUP_MESSAGE) - 1) == 0) {
++num_recv;
}
}

static void run_conference_tests(Tox **toxes, uint32_t *tox_index)
{
for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
tox_callback_conference_message(toxes[i], &handle_conference_message);
}

TOX_ERR_CONFERENCE_SEND_MESSAGE err;
ck_assert_msg(
tox_conference_send_message(
toxes[random_u32() % NUM_GROUP_TOX], 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)GROUP_MESSAGE,
sizeof(GROUP_MESSAGE) - 1, &err) != 0, "Failed to send group message.");
ck_assert_msg(
err == TOX_ERR_CONFERENCE_SEND_MESSAGE_OK, "Failed to send group message.");
num_recv = 0;

for (unsigned j = 0; j < 20; ++j) {
for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
tox_iterate(toxes[i], &tox_index[i]);
}

c_sleep(25);
}

c_sleep(25);
ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages.");

for (unsigned k = NUM_GROUP_TOX; k != 0 ; --k) {
tox_conference_delete(toxes[k - 1], 0, nullptr);

for (unsigned j = 0; j < 10; ++j) {
for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
tox_iterate(toxes[i], &tox_index[i]);
}

c_sleep(50);
}

for (unsigned i = 0; i < k - 1; ++i) {
uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)."
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n",
(k - 1), i, peer_count);
}
}
}

static void test_many_group(void)
{
const time_t test_start_time = time(nullptr);
Expand Down Expand Up @@ -203,48 +252,9 @@ static void test_many_group(void)

printf("group connected, took %d seconds\n", (int)(time(nullptr) - cur_time));

for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
tox_callback_conference_message(toxes[i], &handle_conference_message);
}

TOX_ERR_CONFERENCE_SEND_MESSAGE err;
ck_assert_msg(
tox_conference_send_message(
toxes[random_u32() % NUM_GROUP_TOX], 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)GROUP_MESSAGE,
sizeof(GROUP_MESSAGE) - 1, &err) != 0, "Failed to send group message.");
ck_assert_msg(
err == TOX_ERR_CONFERENCE_SEND_MESSAGE_OK, "Failed to send group message.");
num_recv = 0;

for (unsigned j = 0; j < 20; ++j) {
for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
tox_iterate(toxes[i], &tox_index[i]);
}

c_sleep(25);
}
run_conference_tests(toxes, tox_index);

c_sleep(25);
ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages.");

for (unsigned k = NUM_GROUP_TOX; k != 0 ; --k) {
tox_conference_delete(toxes[k - 1], 0, nullptr);

for (unsigned j = 0; j < 10; ++j) {
for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
tox_iterate(toxes[i], &tox_index[i]);
}

c_sleep(50);
}

for (unsigned i = 0; i < k - 1; ++i) {
uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)."
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n",
(k - 1), i, peer_count);
}
}
printf("tearing down toxes\n");

for (unsigned i = 0; i < NUM_GROUP_TOX; ++i) {
tox_kill(toxes[i]);
Expand Down
Loading

0 comments on commit a3ca64e

Please sign in to comment.