diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-06-23 14:24:04 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-06-23 17:36:37 +0000 |
commit | ca75c014a41c2d207f705f49a9e0ce696dc0f0a7 (patch) | |
tree | 412596b5cea76b7f1f06dc3c7f457d5b09fa6a96 | |
parent | 64d115e52d3e506c360f221b67893ce41423716e (diff) |
Disable UDP when proxy is enabled.
Currently, toxcore does not support UDP over proxies. In the future, we
can relax this by disabling UDP only if the proxy doesn't support it.
-rw-r--r-- | auto_tests/invalid_proxy_test.c | 17 | ||||
-rw-r--r-- | toxcore/Messenger.c | 6 | ||||
-rw-r--r-- | toxcore/tox.api.h | 4 | ||||
-rw-r--r-- | toxcore/tox.h | 4 |
4 files changed, 20 insertions, 11 deletions
diff --git a/auto_tests/invalid_proxy_test.c b/auto_tests/invalid_proxy_test.c index 518ae55f..600efa9e 100644 --- a/auto_tests/invalid_proxy_test.c +++ b/auto_tests/invalid_proxy_test.c | |||
@@ -1,5 +1,5 @@ | |||
1 | // Test that if UDP is enabled, and an invalid proxy is provided, then we get a | 1 | // Test that if UDP is enabled, and a proxy is provided that does not support |
2 | // UDP connection only. | 2 | // UDP proxying, we disable UDP. |
3 | #ifndef _XOPEN_SOURCE | 3 | #ifndef _XOPEN_SOURCE |
4 | #define _XOPEN_SOURCE 600 | 4 | #define _XOPEN_SOURCE 600 |
5 | #endif | 5 | #endif |
@@ -13,6 +13,9 @@ static uint8_t const key[] = { | |||
13 | 0x36, 0xAE, 0x2E, 0x5B, 0xA5, 0xE4, 0x69, 0x0E, | 13 | 0x36, 0xAE, 0x2E, 0x5B, 0xA5, 0xE4, 0x69, 0x0E, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | // Try to bootstrap for 30 seconds. | ||
17 | #define NUM_ITERATIONS (unsigned)(30.0 / (ITERATION_INTERVAL / 1000.0)) | ||
18 | |||
16 | int main(void) | 19 | int main(void) |
17 | { | 20 | { |
18 | setvbuf(stdout, nullptr, _IONBF, 0); | 21 | setvbuf(stdout, nullptr, _IONBF, 0); |
@@ -30,17 +33,13 @@ int main(void) | |||
30 | 33 | ||
31 | printf("Waiting for connection"); | 34 | printf("Waiting for connection"); |
32 | 35 | ||
33 | while (tox_self_get_connection_status(tox) == TOX_CONNECTION_NONE) { | 36 | for (unsigned i = 0; i < NUM_ITERATIONS; i++) { |
34 | printf("."); | ||
35 | fflush(stdout); | ||
36 | |||
37 | tox_iterate(tox, nullptr); | 37 | tox_iterate(tox, nullptr); |
38 | c_sleep(ITERATION_INTERVAL); | 38 | c_sleep(ITERATION_INTERVAL); |
39 | // None of the iterations should have a connection. | ||
40 | assert(tox_self_get_connection_status(tox) == TOX_CONNECTION_NONE); | ||
39 | } | 41 | } |
40 | 42 | ||
41 | assert(tox_self_get_connection_status(tox) == TOX_CONNECTION_UDP); | ||
42 | printf("Connection (UDP): %d\n", tox_self_get_connection_status(tox)); | ||
43 | |||
44 | tox_kill(tox); | 43 | tox_kill(tox); |
45 | return 0; | 44 | return 0; |
46 | } | 45 | } |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 11109815..e3ceeb86 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1993,6 +1993,12 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error) | |||
1993 | 1993 | ||
1994 | unsigned int net_err = 0; | 1994 | unsigned int net_err = 0; |
1995 | 1995 | ||
1996 | if (!options->udp_disabled && options->proxy_info.proxy_type != TCP_PROXY_NONE) { | ||
1997 | // We don't currently support UDP over proxy. | ||
1998 | LOGGER_WARNING(m->log, "UDP enabled and proxy set: disabling UDP"); | ||
1999 | options->udp_disabled = true; | ||
2000 | } | ||
2001 | |||
1996 | if (options->udp_disabled) { | 2002 | if (options->udp_disabled) { |
1997 | m->net = new_networking_no_udp(m->log); | 2003 | m->net = new_networking_no_udp(m->log); |
1998 | } else { | 2004 | } else { |
diff --git a/toxcore/tox.api.h b/toxcore/tox.api.h index 1c3b1121..241441b8 100644 --- a/toxcore/tox.api.h +++ b/toxcore/tox.api.h | |||
@@ -473,7 +473,9 @@ static class options { | |||
473 | * | 473 | * |
474 | * Setting this to false will force Tox to use TCP only. Communications will | 474 | * Setting this to false will force Tox to use TCP only. Communications will |
475 | * need to be relayed through a TCP relay node, potentially slowing them down. | 475 | * need to be relayed through a TCP relay node, potentially slowing them down. |
476 | * Disabling UDP support is necessary when using anonymous proxies or Tor. | 476 | * |
477 | * If a proxy is enabled, UDP will be disabled if either toxcore or the | ||
478 | * proxy don't support proxying UDP messages. | ||
477 | */ | 479 | */ |
478 | bool udp_enabled; | 480 | bool udp_enabled; |
479 | 481 | ||
diff --git a/toxcore/tox.h b/toxcore/tox.h index d5834095..1b4ce7be 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -526,7 +526,9 @@ struct Tox_Options { | |||
526 | * | 526 | * |
527 | * Setting this to false will force Tox to use TCP only. Communications will | 527 | * Setting this to false will force Tox to use TCP only. Communications will |
528 | * need to be relayed through a TCP relay node, potentially slowing them down. | 528 | * need to be relayed through a TCP relay node, potentially slowing them down. |
529 | * Disabling UDP support is necessary when using anonymous proxies or Tor. | 529 | * |
530 | * If a proxy is enabled, UDP will be disabled if either toxcore or the | ||
531 | * proxy don't support proxying UDP messages. | ||
530 | */ | 532 | */ |
531 | bool udp_enabled; | 533 | bool udp_enabled; |
532 | 534 | ||