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.
This commit is contained in:
iphydf 2018-06-23 14:24:04 +00:00
parent 64d115e52d
commit ca75c014a4
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
4 changed files with 20 additions and 11 deletions

View File

@ -1,5 +1,5 @@
// Test that if UDP is enabled, and an invalid proxy is provided, then we get a // Test that if UDP is enabled, and a proxy is provided that does not support
// UDP connection only. // UDP proxying, we disable UDP.
#ifndef _XOPEN_SOURCE #ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600 #define _XOPEN_SOURCE 600
#endif #endif
@ -13,6 +13,9 @@ static uint8_t const key[] = {
0x36, 0xAE, 0x2E, 0x5B, 0xA5, 0xE4, 0x69, 0x0E, 0x36, 0xAE, 0x2E, 0x5B, 0xA5, 0xE4, 0x69, 0x0E,
}; };
// Try to bootstrap for 30 seconds.
#define NUM_ITERATIONS (unsigned)(30.0 / (ITERATION_INTERVAL / 1000.0))
int main(void) int main(void)
{ {
setvbuf(stdout, nullptr, _IONBF, 0); setvbuf(stdout, nullptr, _IONBF, 0);
@ -30,17 +33,13 @@ int main(void)
printf("Waiting for connection"); printf("Waiting for connection");
while (tox_self_get_connection_status(tox) == TOX_CONNECTION_NONE) { for (unsigned i = 0; i < NUM_ITERATIONS; i++) {
printf(".");
fflush(stdout);
tox_iterate(tox, nullptr); tox_iterate(tox, nullptr);
c_sleep(ITERATION_INTERVAL); c_sleep(ITERATION_INTERVAL);
// None of the iterations should have a connection.
assert(tox_self_get_connection_status(tox) == TOX_CONNECTION_NONE);
} }
assert(tox_self_get_connection_status(tox) == TOX_CONNECTION_UDP);
printf("Connection (UDP): %d\n", tox_self_get_connection_status(tox));
tox_kill(tox); tox_kill(tox);
return 0; return 0;
} }

View File

@ -1993,6 +1993,12 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
unsigned int net_err = 0; unsigned int net_err = 0;
if (!options->udp_disabled && options->proxy_info.proxy_type != TCP_PROXY_NONE) {
// We don't currently support UDP over proxy.
LOGGER_WARNING(m->log, "UDP enabled and proxy set: disabling UDP");
options->udp_disabled = true;
}
if (options->udp_disabled) { if (options->udp_disabled) {
m->net = new_networking_no_udp(m->log); m->net = new_networking_no_udp(m->log);
} else { } else {

View File

@ -473,7 +473,9 @@ static class options {
* *
* Setting this to false will force Tox to use TCP only. Communications will * Setting this to false will force Tox to use TCP only. Communications will
* need to be relayed through a TCP relay node, potentially slowing them down. * need to be relayed through a TCP relay node, potentially slowing them down.
* Disabling UDP support is necessary when using anonymous proxies or Tor. *
* If a proxy is enabled, UDP will be disabled if either toxcore or the
* proxy don't support proxying UDP messages.
*/ */
bool udp_enabled; bool udp_enabled;

View File

@ -526,7 +526,9 @@ struct Tox_Options {
* *
* Setting this to false will force Tox to use TCP only. Communications will * Setting this to false will force Tox to use TCP only. Communications will
* need to be relayed through a TCP relay node, potentially slowing them down. * need to be relayed through a TCP relay node, potentially slowing them down.
* Disabling UDP support is necessary when using anonymous proxies or Tor. *
* If a proxy is enabled, UDP will be disabled if either toxcore or the
* proxy don't support proxying UDP messages.
*/ */
bool udp_enabled; bool udp_enabled;