1 // Test that if UDP is enabled, and a proxy is provided that does not support
2 // UDP proxying, we disable UDP.
3 
4 #ifdef HAVE_CONFIG_H
5 #include "config.h"
6 #endif
7 
8 #include <stdio.h>
9 
10 #include "../testing/misc_tools.h"
11 #include "check_compat.h"
12 
13 static uint8_t const key[] = {
14     0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
15     0xDF, 0x0E, 0xBA, 0x05, 0x7D, 0xAB, 0xB4, 0x9F,
16     0xE1, 0x5F, 0x38, 0x03, 0xB1, 0xBF, 0xF0, 0x65,
17     0x36, 0xAE, 0x2E, 0x5B, 0xA5, 0xE4, 0x69, 0x0E,
18 };
19 
20 // Try to bootstrap for 30 seconds.
21 #define NUM_ITERATIONS (unsigned)(30.0 / (ITERATION_INTERVAL / 1000.0))
22 
main(void)23 int main(void)
24 {
25     setvbuf(stdout, nullptr, _IONBF, 0);
26 
27     struct Tox_Options *opts = tox_options_new(nullptr);
28     tox_options_set_udp_enabled(opts, true);
29     tox_options_set_proxy_type(opts, TOX_PROXY_TYPE_SOCKS5);
30     tox_options_set_proxy_host(opts, "localhost");
31     tox_options_set_proxy_port(opts, 51724);
32     Tox *tox = tox_new_log(opts, nullptr, nullptr);
33     tox_options_free(opts);
34 
35     tox_add_tcp_relay(tox, "tox.ngc.zone", 33445, key, nullptr);
36     tox_bootstrap(tox, "tox.ngc.zone", 33445, key, nullptr);
37 
38     printf("Waiting for connection...");
39 
40     for (uint16_t i = 0; i < NUM_ITERATIONS; i++) {
41         tox_iterate(tox, nullptr);
42         c_sleep(ITERATION_INTERVAL);
43         // None of the iterations should have a connection.
44         const Tox_Connection status = tox_self_get_connection_status(tox);
45         ck_assert_msg(status == TOX_CONNECTION_NONE,
46                       "unexpectedly got a connection (%d)", status);
47     }
48 
49     tox_kill(tox);
50     return 0;
51 }
52