Skip to content

Commit

Permalink
Disable UDP when proxy is enabled.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iphydf committed Jun 23, 2018
1 parent 64d115e commit ca75c01
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
17 changes: 8 additions & 9 deletions auto_tests/invalid_proxy_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Test that if UDP is enabled, and an invalid proxy is provided, then we get a
// UDP connection only.
// Test that if UDP is enabled, and a proxy is provided that does not support
// UDP proxying, we disable UDP.
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
Expand All @@ -13,6 +13,9 @@ static uint8_t const key[] = {
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)
{
setvbuf(stdout, nullptr, _IONBF, 0);
Expand All @@ -30,17 +33,13 @@ int main(void)

printf("Waiting for connection");

while (tox_self_get_connection_status(tox) == TOX_CONNECTION_NONE) {
printf(".");
fflush(stdout);

for (unsigned i = 0; i < NUM_ITERATIONS; i++) {
tox_iterate(tox, nullptr);
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);
return 0;
}
6 changes: 6 additions & 0 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -1993,6 +1993,12 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)

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) {
m->net = new_networking_no_udp(m->log);
} else {
Expand Down
4 changes: 3 additions & 1 deletion toxcore/tox.api.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,9 @@ static class options {
*
* 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.
* 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;

Expand Down
4 changes: 3 additions & 1 deletion toxcore/tox.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,9 @@ struct Tox_Options {
*
* 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.
* 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;

Expand Down

0 comments on commit ca75c01

Please sign in to comment.