diff --git a/.circleci/config.yml b/.circleci/config.yml index 867e251a..5e8ad896 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -35,6 +35,7 @@ jobs: libopus-dev libsodium-dev libvpx-dev + llvm-dev ninja-build pkg-config - checkout diff --git a/.github/scripts/flags-gcc.sh b/.github/scripts/flags-gcc.sh index 80375100..63a13a17 100644 --- a/.github/scripts/flags-gcc.sh +++ b/.github/scripts/flags-gcc.sh @@ -17,3 +17,6 @@ add_flag -Wno-sign-compare add_flag -Wno-type-limits # Callbacks often don't use all their parameters. add_flag -Wno-unused-parameter +# struct Foo foo = {0}; is a common idiom. Missing braces means we'd need to +# write {{{0}}} in some cases, which is ugly and a maintenance burden. +add_flag -Wno-missing-braces diff --git a/auto_tests/bootstrap_test.c b/auto_tests/bootstrap_test.c index 66deb267..c5c30c2d 100644 --- a/auto_tests/bootstrap_test.c +++ b/auto_tests/bootstrap_test.c @@ -3,33 +3,12 @@ #include "../testing/misc_tools.h" #include "check_compat.h" -static uint8_t const key1[] = { - 0x02, 0x80, 0x7C, 0xF4, 0xF8, 0xBB, 0x8F, 0xB3, - 0x90, 0xCC, 0x37, 0x94, 0xBD, 0xF1, 0xE8, 0x44, - 0x9E, 0x9A, 0x83, 0x92, 0xC5, 0xD3, 0xF2, 0x20, - 0x00, 0x19, 0xDA, 0x9F, 0x1E, 0x81, 0x2E, 0x46, -}; +typedef struct State { + uint32_t index; + uint64_t clock; +} State; -static uint8_t const key2[] = { - 0x3F, 0x0A, 0x45, 0xA2, 0x68, 0x36, 0x7C, 0x1B, - 0xEA, 0x65, 0x2F, 0x25, 0x8C, 0x85, 0xF4, 0xA6, - 0x6D, 0xA7, 0x6B, 0xCA, 0xA6, 0x67, 0xA4, 0x9E, - 0x77, 0x0B, 0xCC, 0x49, 0x17, 0xAB, 0x6A, 0x25, -}; - -static uint8_t const key3[] = { - 0x7A, 0x60, 0x98, 0xB5, 0x90, 0xBD, 0xC7, 0x3F, - 0x97, 0x23, 0xFC, 0x59, 0xF8, 0x2B, 0x3F, 0x90, - 0x85, 0xA6, 0x4D, 0x1B, 0x21, 0x3A, 0xAF, 0x8E, - 0x61, 0x0F, 0xD3, 0x51, 0x93, 0x0D, 0x05, 0x2D, -}; - -static uint8_t const key4[] = { - 0x8E, 0x8B, 0x63, 0x29, 0x9B, 0x3D, 0x52, 0x0F, - 0xB3, 0x77, 0xFE, 0x51, 0x00, 0xE6, 0x5E, 0x33, - 0x22, 0xF7, 0xAE, 0x5B, 0x20, 0xA0, 0xAC, 0xED, - 0x29, 0x81, 0x76, 0x9F, 0xC5, 0xB4, 0x37, 0x25, -}; +#include "run_auto_test.h" int main(void) { @@ -37,10 +16,7 @@ int main(void) Tox *tox_udp = tox_new_log(nullptr, nullptr, nullptr); - 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, "tox2.abilinski.com", 33445, key3, nullptr); - tox_bootstrap(tox_udp, "tox.plastiras.org", 443, key4, nullptr); + bootstrap_toxes_live_network(&tox_udp, 1, false); printf("Waiting for connection"); @@ -59,5 +35,7 @@ int main(void) tox_kill(tox_udp); + (void)run_auto_test; + return 0; } diff --git a/auto_tests/run_auto_test.h b/auto_tests/run_auto_test.h index d04368e6..3d0afc95 100644 --- a/auto_tests/run_auto_test.h +++ b/auto_tests/run_auto_test.h @@ -1,45 +1,81 @@ #include // calloc, free - #include "check_compat.h" #include "../testing/misc_tools.h" #include "../toxcore/Messenger.h" #include "../toxcore/mono_time.h" -// TCP relay keys, copied from tcp_relay_test.c -static uint8_t const mainnet_tcp_key1[] = { - 0x02, 0x80, 0x7C, 0xF4, 0xF8, 0xBB, 0x8F, 0xB3, - 0x90, 0xCC, 0x37, 0x94, 0xBD, 0xF1, 0xE8, 0x44, - 0x9E, 0x9A, 0x83, 0x92, 0xC5, 0xD3, 0xF2, 0x20, - 0x00, 0x19, 0xDA, 0x9F, 0x1E, 0x81, 0x2E, 0x46, +// List of live bootstrap nodes. These nodes should have TCP server enabled. +static const struct BootstrapNodes { + const char *ip; + uint16_t port; + const uint8_t key[32]; +} BootstrapNodes[] = { +#ifndef USE_TEST_NETWORK + { + "tox.abilinski.com", 33445, + 0x10, 0xC0, 0x0E, 0xB2, 0x50, 0xC3, 0x23, 0x3E, + 0x34, 0x3E, 0x2A, 0xEB, 0xA0, 0x71, 0x15, 0xA5, + 0xC2, 0x89, 0x20, 0xE9, 0xC8, 0xD2, 0x94, 0x92, + 0xF6, 0xD0, 0x0B, 0x29, 0x04, 0x9E, 0xDC, 0x7E, + }, + { + "tox.initramfs.io", 33445, + 0x02, 0x80, 0x7C, 0xF4, 0xF8, 0xBB, 0x8F, 0xB3, + 0x90, 0xCC, 0x37, 0x94, 0xBD, 0xF1, 0xE8, 0x44, + 0x9E, 0x9A, 0x83, 0x92, 0xC5, 0xD3, 0xF2, 0x20, + 0x00, 0x19, 0xDA, 0x9F, 0x1E, 0x81, 0x2E, 0x46, + }, + { + "tox.plastiras.org", 33445, + 0x8E, 0x8B, 0x63, 0x29, 0x9B, 0x3D, 0x52, 0x0F, + 0xB3, 0x77, 0xFE, 0x51, 0x00, 0xE6, 0x5E, 0x33, + 0x22, 0xF7, 0xAE, 0x5B, 0x20, 0xA0, 0xAC, 0xED, + 0x29, 0x81, 0x76, 0x9F, 0xC5, 0xB4, 0x37, 0x25, + }, + { + "tox.novg.net", 33445, + 0xD5, 0x27, 0xE5, 0x84, 0x7F, 0x83, 0x30, 0xD6, + 0x28, 0xDA, 0xB1, 0x81, 0x4F, 0x0A, 0x42, 0x2F, + 0x6D, 0xC9, 0xD0, 0xA3, 0x00, 0xE6, 0xC3, 0x57, + 0x63, 0x4E, 0xE2, 0xDA, 0x88, 0xC3, 0x54, 0x63, + }, +#else + { + "172.93.52.70", 33445, + 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, + }, +#endif // USE_TEST_NETWORK + { nullptr, 0, 0 }, }; -static uint8_t const mainnet_tcp_key2[] = { - 0x3F, 0x0A, 0x45, 0xA2, 0x68, 0x36, 0x7C, 0x1B, - 0xEA, 0x65, 0x2F, 0x25, 0x8C, 0x85, 0xF4, 0xA6, - 0x6D, 0xA7, 0x6B, 0xCA, 0xA6, 0x67, 0xA4, 0x9E, - 0x77, 0x0B, 0xCC, 0x49, 0x17, 0xAB, 0x6A, 0x25, -}; +static void bootstrap_toxes_live_network(Tox **toxes, uint32_t tox_count, bool enable_tcp) +{ + for (size_t i = 0; i < tox_count; ++i) { + for (size_t j = 0; BootstrapNodes[j].ip != nullptr; ++j) { + const char *ip = BootstrapNodes[j].ip; + uint16_t port = BootstrapNodes[j].port; + const uint8_t *key = BootstrapNodes[j].key; -static uint8_t const mainnet_tcp_key3[] = { - 0x7A, 0x60, 0x98, 0xB5, 0x90, 0xBD, 0xC7, 0x3F, - 0x97, 0x23, 0xFC, 0x59, 0xF8, 0x2B, 0x3F, 0x90, - 0x85, 0xA6, 0x4D, 0x1B, 0x21, 0x3A, 0xAF, 0x8E, - 0x61, 0x0F, 0xD3, 0x51, 0x93, 0x0D, 0x05, 0x2D, -}; + Tox_Err_Bootstrap err; + tox_bootstrap(toxes[i], ip, port, key, &err); -static uint8_t const mainnet_tcp_key4[] = { - 0x8E, 0x8B, 0x63, 0x29, 0x9B, 0x3D, 0x52, 0x0F, - 0xB3, 0x77, 0xFE, 0x51, 0x00, 0xE6, 0x5E, 0x33, - 0x22, 0xF7, 0xAE, 0x5B, 0x20, 0xA0, 0xAC, 0xED, - 0x29, 0x81, 0x76, 0x9F, 0xC5, 0xB4, 0x37, 0x25, -}; + if (err != TOX_ERR_BOOTSTRAP_OK) { + fprintf(stderr, "Failed to bootstrap node %zu (%s): error %d\n", j, ip, err); + } -static uint8_t const testnet_tcp_key[] = { - 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, -}; + if (enable_tcp) { + tox_add_tcp_relay(toxes[i], ip, port, key, &err); + + if (err != TOX_ERR_BOOTSTRAP_OK) { + fprintf(stderr, "Failed to add TCP relay %zu (%s): error %d\n", j, ip, err); + } + } + } + } +} static bool all_connected(uint32_t tox_count, Tox **toxes) { @@ -180,17 +216,7 @@ static void run_auto_test(struct Tox_Options *options, uint32_t tox_count, void } } else { printf("bootstrapping all toxes to tcp relays\n"); - - for (uint32_t i = 0; i < tox_count; ++i) { - // tox_bootstrap(toxes[i], "78.46.73.141", 33445, mainnet_key1, nullptr); - // tox_bootstrap(toxes[i], "tox.initramfs.io", 33445, mainnet_key2, nullptr); - tox_bootstrap(toxes[i], "172.93.52.70", 33445, testnet_tcp_key, nullptr); - - // tox_add_tcp_relay(toxes[i], "78.46.73.141", 33445, mainnet_key1, &err); - // tox_add_tcp_relay(toxes[i], "tox.initramfs.io", 33445, mainnet_key2, &err); - tox_add_tcp_relay(toxes[i], "172.93.52.70", 33445, testnet_tcp_key, &err); - ck_assert_msg(err == TOX_ERR_BOOTSTRAP_OK, "%d", err); - } + bootstrap_toxes_live_network(toxes, tox_count, true); } wait_friend_connections(tox_count, toxes, state); diff --git a/auto_tests/tcp_relay_test.c b/auto_tests/tcp_relay_test.c index 6fdcfb5c..8bcd6abe 100644 --- a/auto_tests/tcp_relay_test.c +++ b/auto_tests/tcp_relay_test.c @@ -3,33 +3,12 @@ #include "../testing/misc_tools.h" #include "check_compat.h" -static uint8_t const key1[] = { - 0x02, 0x80, 0x7C, 0xF4, 0xF8, 0xBB, 0x8F, 0xB3, - 0x90, 0xCC, 0x37, 0x94, 0xBD, 0xF1, 0xE8, 0x44, - 0x9E, 0x9A, 0x83, 0x92, 0xC5, 0xD3, 0xF2, 0x20, - 0x00, 0x19, 0xDA, 0x9F, 0x1E, 0x81, 0x2E, 0x46, -}; +typedef struct State { + uint32_t index; + uint64_t clock; +} State; -static uint8_t const key2[] = { - 0x3F, 0x0A, 0x45, 0xA2, 0x68, 0x36, 0x7C, 0x1B, - 0xEA, 0x65, 0x2F, 0x25, 0x8C, 0x85, 0xF4, 0xA6, - 0x6D, 0xA7, 0x6B, 0xCA, 0xA6, 0x67, 0xA4, 0x9E, - 0x77, 0x0B, 0xCC, 0x49, 0x17, 0xAB, 0x6A, 0x25, -}; - -static uint8_t const key3[] = { - 0x7A, 0x60, 0x98, 0xB5, 0x90, 0xBD, 0xC7, 0x3F, - 0x97, 0x23, 0xFC, 0x59, 0xF8, 0x2B, 0x3F, 0x90, - 0x85, 0xA6, 0x4D, 0x1B, 0x21, 0x3A, 0xAF, 0x8E, - 0x61, 0x0F, 0xD3, 0x51, 0x93, 0x0D, 0x05, 0x2D, -}; - -static uint8_t const key4[] = { - 0x8E, 0x8B, 0x63, 0x29, 0x9B, 0x3D, 0x52, 0x0F, - 0xB3, 0x77, 0xFE, 0x51, 0x00, 0xE6, 0x5E, 0x33, - 0x22, 0xF7, 0xAE, 0x5B, 0x20, 0xA0, 0xAC, 0xED, - 0x29, 0x81, 0x76, 0x9F, 0xC5, 0xB4, 0x37, 0x25, -}; +#include "run_auto_test.h" int main(void) { @@ -40,28 +19,8 @@ int main(void) Tox *tox_tcp = tox_new_log(opts, nullptr, nullptr); tox_options_free(opts); - tox_bootstrap(tox_tcp, "78.46.73.141", 33445, key1, nullptr); - tox_bootstrap(tox_tcp, "tox.initramfs.io", 33445, key2, nullptr); - tox_bootstrap(tox_tcp, "tox2.abilinski.com", 33445, key3, nullptr); - tox_bootstrap(tox_tcp, "tox.plastiras.org", 443, key4, nullptr); + bootstrap_toxes_live_network(&tox_tcp, 1, true); - Tox_Err_Bootstrap tcp_err; - tox_add_tcp_relay(tox_tcp, "78.46.73.141", 33445, key1, &tcp_err); - ck_assert_msg(tcp_err == TOX_ERR_BOOTSTRAP_OK, - "attempting to add tcp relay 1 returned with an error: %d", - tcp_err); - tox_add_tcp_relay(tox_tcp, "tox.initramfs.io", 33445, key2, &tcp_err); - ck_assert_msg(tcp_err == TOX_ERR_BOOTSTRAP_OK, - "attempting to add tcp relay 2 returned with an error: %d", - tcp_err); - tox_add_tcp_relay(tox_tcp, "tox2.abilinski.com", 33445, key3, &tcp_err); - ck_assert_msg(tcp_err == TOX_ERR_BOOTSTRAP_OK, - "attempting to add tcp relay 3 returned with an error: %d", - tcp_err); - tox_add_tcp_relay(tox_tcp, "tox.plastiras.org", 443, key4, &tcp_err); - ck_assert_msg(tcp_err == TOX_ERR_BOOTSTRAP_OK, - "attempting to add tcp relay 4 returned with an error: %d", - tcp_err); printf("Waiting for connection"); do { @@ -78,5 +37,8 @@ int main(void) printf("Connection (TCP): %d\n", status); tox_kill(tox_tcp); + + (void)run_auto_test; + return 0; }