Skip to content

Commit

Permalink
Merge 175a751 into 470fa79
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-io[bot] committed Jul 7, 2020
2 parents 470fa79 + 175a751 commit 6a67810
Show file tree
Hide file tree
Showing 66 changed files with 17,009 additions and 182 deletions.
1 change: 1 addition & 0 deletions .circleci/cmake-asan
Expand Up @@ -21,6 +21,7 @@ cmake -B_build -H. -GNinja \
-DSTRICT_ABI=ON \
-DTEST_TIMEOUT_SECONDS=120 \
-DUSE_IPV6=OFF \
-DUSE_TEST_NETWORK=ON \
-DAUTOTEST=ON

cd _build
Expand Down
1 change: 1 addition & 0 deletions .circleci/cmake-tsan
Expand Up @@ -21,6 +21,7 @@ cmake -B_build -H. -GNinja \
-DSTRICT_ABI=ON \
-DTEST_TIMEOUT_SECONDS=120 \
-DUSE_IPV6=OFF \
-DUSE_TEST_NETWORK=ON \
-DAUTOTEST=ON

cd _build
Expand Down
6 changes: 4 additions & 2 deletions .cirrus.yml
Expand Up @@ -7,10 +7,12 @@ cirrus-ci_task:
configure_script:
- /src/workspace/tools/inject-repo c-toxcore
test_all_script:
- bazel test -k
- TEST="bazel test -k
--build_tag_filters=-haskell
--test_tag_filters=-haskell
--remote_download_minimal
--config=ci
--config=release
//c-toxcore/...
--config=testnet
//c-toxcore/..."
- $TEST || $TEST || $TEST || $TEST
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -87,3 +87,5 @@ cscope.files

# rpm
tox.spec

.idea/
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -39,6 +39,7 @@ jobs:
install: .travis/$JOB install
script: .travis/$JOB script
- stage: "Stage 1"
if: type IN (push, api, cron)
env: JOB=tox-bootstrapd-docker
services: [docker]
script: .travis/$JOB
Expand Down
1 change: 1 addition & 0 deletions .travis/autotools-linux
Expand Up @@ -33,6 +33,7 @@ travis_script() {
add_config_flag --with-nacl-libs="$CACHEDIR/lib/amd64"
add_config_flag --with-nacl-headers="$CACHEDIR/include/amd64"
add_config_flag --disable-ipv6
add_config_flag --enable-test-network
add_config_flag --enable-nacl
add_config_flag --enable-daemon
add_config_flag --enable-logging
Expand Down
1 change: 1 addition & 0 deletions .travis/cmake-linux
Expand Up @@ -81,6 +81,7 @@ travis_script() {
-DSTRICT_ABI=ON \
-DTEST_TIMEOUT_SECONDS=120 \
-DUSE_IPV6=OFF \
-DUSE_TEST_NETWORK=ON \
-DAUTOTEST=ON

cmake --build _build --parallel "$NPROC" --target install -- -k 0
Expand Down
24 changes: 21 additions & 3 deletions CMakeLists.txt
Expand Up @@ -105,6 +105,11 @@ if(NOT USE_IPV6)
add_definitions(-DUSE_IPV6=0)
endif()

option(USE_TEST_NETWORK "Use a separate test network with different packet IDs" OFF)
if(USE_TEST_NETWORK)
add_definitions(-DUSE_TEST_NETWORK=1)
endif()

option(USE_STDERR_LOGGER "Enable logging to stderr when the logger is NULL" OFF)
if(USE_STDERR_LOGGER)
add_definitions(-DUSE_STDERR_LOGGER=1)
Expand Down Expand Up @@ -230,19 +235,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 @@ -427,6 +440,10 @@ auto_test(file_transfer)
auto_test(file_saving)
auto_test(friend_connection)
auto_test(friend_request)
auto_test(group_state)
auto_test(group_announce)
auto_test(group_message)
auto_test(group_moderation)
auto_test(invalid_tcp_proxy)
auto_test(invalid_udp_proxy)
auto_test(lan_discovery)
Expand Down Expand Up @@ -535,4 +552,5 @@ if (BUILD_MISC_TESTS)
add_executable(afl_toxsave
testing/afl_toxsave.c)
target_link_modules(afl_toxsave toxcore)

endif()
5 changes: 5 additions & 0 deletions auto_tests/Makefile.inc
Expand Up @@ -15,6 +15,7 @@ TESTS = \
file_transfer_test \
friend_connection_test \
friend_request_test \
group_state_test \
invalid_tcp_proxy_test \
invalid_udp_proxy_test \
lan_discovery_test \
Expand Down Expand Up @@ -120,6 +121,10 @@ friend_request_test_SOURCES = ../auto_tests/friend_request_test.c
friend_request_test_CFLAGS = $(AUTOTEST_CFLAGS)
friend_request_test_LDADD = $(AUTOTEST_LDADD)

group_state_test_SOURCES = ../auto_tests/group_state_test.c
group_state_test_CFLAGS = $(AUTOTEST_CFLAGS)
group_state_test_LDADD = $(AUTOTEST_LDADD)

invalid_tcp_proxy_test_SOURCES = ../auto_tests/invalid_tcp_proxy_test.c
invalid_tcp_proxy_test_CFLAGS = $(AUTOTEST_CFLAGS)
invalid_tcp_proxy_test_LDADD = $(AUTOTEST_LDADD)
Expand Down
8 changes: 8 additions & 0 deletions auto_tests/bootstrap_test.c
Expand Up @@ -21,6 +21,13 @@ static uint8_t const key2[] = {
0x77, 0x0B, 0xCC, 0x49, 0x17, 0xAB, 0x6A, 0x25,
};

static uint8_t const key3[] = {
0x79, 0xCA, 0xDA, 0x49, 0x74, 0xB0, 0x92, 0x6F,
0x28, 0x6F, 0x02, 0x5C, 0xD5, 0xFF, 0xDF, 0x3E,
0x65, 0x4A, 0x37, 0x58, 0xC5, 0x3E, 0x02, 0x73,
0xEC, 0xFC, 0x4D, 0x12, 0xC2, 0x1D, 0xCA, 0x48,
};

int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);
Expand All @@ -29,6 +36,7 @@ int main(void)

tox_bootstrap(tox_udp, "78.46.73.141", 33445, key1, nullptr);
tox_bootstrap(tox_udp, "tox.initramfs.io", 33445, key2, nullptr);
tox_bootstrap(tox_udp, "172.93.52.70", 33445, key3, nullptr);

printf("Waiting for connection");

Expand Down
122 changes: 122 additions & 0 deletions auto_tests/group_announce_test.c
@@ -0,0 +1,122 @@
/*
* Tests that we can connect to a public group chat through the DHT.
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdbool.h>
#include <stdint.h>
#include <string.h>

typedef struct State {
uint32_t index;
uint64_t clock;
bool peer_joined;
bool message_sent;
bool message_received;
} State;

#include "run_auto_test.h"

#define NUM_GROUP_TOXES 2
#define TEST_MESSAGE "The kiosk in my temporal lobe is shaped like Rosalynn Carter"
#define TEST_GROUP_NAME "NASA Headquarters"
#define PEER0_NICK "Lois"
#define PEER1_NICK "Benjamin"

static void group_join_fail_handler(Tox *tox, uint32_t groupnumber, TOX_GROUP_JOIN_FAIL fail_type, void *user_data)
{
fprintf(stderr, "Failed to join group: %d", fail_type);
}

static void group_peer_join_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, void *user_data)
{
State *state = (State *)user_data;
printf("peer %u joined, sending message\n", peer_id);
state->peer_joined = true;
}

static void group_message_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, TOX_MESSAGE_TYPE type,
const uint8_t *message, size_t length, void *user_data)
{
if (length > TOX_MAX_MESSAGE_LENGTH) {
printf("Failed to receive message. Invalid length: %zu\n", length);
return;
}

char message_buf[TOX_MAX_MESSAGE_LENGTH + 1];
memcpy(message_buf, message, length);
message_buf[length] = 0;

State *state = (State *)user_data;
printf("peer %u sent message: %s\n", peer_id, (const char *)message_buf);
ck_assert(memcmp(message_buf, TEST_MESSAGE, length) == 0);
state->message_received = true;
}

static void group_announce_test(Tox **toxes, State *state)
{
#ifndef VANILLA_NACL
ck_assert_msg(NUM_GROUP_TOXES >= 2, "NUM_GROUP_TOXES is too small: %d", NUM_GROUP_TOXES);

tox_self_set_name(toxes[0], (const uint8_t *)"a", 1, nullptr);
tox_self_set_name(toxes[1], (const uint8_t *)"b", 1, nullptr);

tox_callback_group_join_fail(toxes[1], group_join_fail_handler);
tox_callback_group_peer_join(toxes[1], group_peer_join_handler);
tox_callback_group_message(toxes[0], group_message_handler);

// tox0 makes new group.
TOX_ERR_GROUP_NEW err_new;
uint32_t group_number = tox_group_new(toxes[0], TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *) TEST_GROUP_NAME,
strlen(TEST_GROUP_NAME), (const uint8_t *)PEER0_NICK, strlen(PEER0_NICK),
&err_new);
ck_assert(err_new == TOX_ERR_GROUP_NEW_OK);

// get the chat id of the new group.
TOX_ERR_GROUP_STATE_QUERIES err_id;
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(toxes[0], group_number, chat_id, &err_id);
ck_assert(err_id == TOX_ERR_GROUP_STATE_QUERIES_OK);

// tox1 joins it.
TOX_ERR_GROUP_JOIN err_join;
tox_group_join(toxes[1], chat_id, (const uint8_t *)PEER1_NICK, strlen(PEER1_NICK), nullptr, 0, &err_join);
ck_assert(err_join == TOX_ERR_GROUP_JOIN_OK);

while (!state[0].message_received) {
iterate_all_wait(NUM_GROUP_TOXES, toxes, state, ITERATION_INTERVAL);

if (state[1].peer_joined && !state[1].message_sent) {
TOX_ERR_GROUP_SEND_MESSAGE err_send;
tox_group_send_message(toxes[1], group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)TEST_MESSAGE,
strlen(TEST_MESSAGE), &err_send);
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
state[1].message_sent = true;
}
}

TOX_ERR_GROUP_LEAVE err_exit;
tox_group_leave(toxes[0], group_number, nullptr, 0, &err_exit);
ck_assert(err_exit == TOX_ERR_GROUP_LEAVE_OK);

tox_group_leave(toxes[1], group_number, nullptr, 0, &err_exit);
ck_assert(err_exit == TOX_ERR_GROUP_LEAVE_OK);
#endif // VANILLA_NACL
}

int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);

run_auto_test(NUM_GROUP_TOXES, group_announce_test, false);
return 0;
}

#undef NUM_GROUP_TOXES
#undef PEER1_NICK
#undef PEER0_NICK
#undef TEST_GROUP_NAME
#undef TEST_MESSAGE

0 comments on commit 6a67810

Please sign in to comment.