From c259250abb86a01ae7e3fc906380417427f38ca1 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 3 Jul 2015 21:52:53 -0400 Subject: [PATCH] Fixed Tox reporting itself as being connected with TCP when using UDP only on LAN. --- auto_tests/tox_test.c | 2 ++ toxcore/onion_client.c | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index fa1d43e1..682cdb54 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c @@ -281,6 +281,8 @@ void tox_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *use if (connected_t1 && !connection_status) ck_abort_msg("Tox went offline"); + ck_assert_msg(connection_status == TOX_CONNECTION_UDP, "wrong status %u", connection_status); + connected_t1 = connection_status; } diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 4f049fbc..8609c6b6 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -1452,12 +1452,15 @@ void do_onion_client(Onion_Client *onion_c) } } - onion_c->UDP_connected = DHT_non_lan_connected(onion_c->dht); + _Bool UDP_connected = DHT_non_lan_connected(onion_c->dht); if (is_timeout(onion_c->first_run, ONION_CONNECTION_SECONDS)) { - set_tcp_onion_status(onion_c->c->tcp_c, !onion_c->UDP_connected); + set_tcp_onion_status(onion_c->c->tcp_c, !UDP_connected); } + onion_c->UDP_connected = UDP_connected + || get_random_tcp_onion_conn_number(onion_c->c->tcp_c) == -1; /* Check if connected to any TCP relays. */ + if (onion_connection_status(onion_c)) { for (i = 0; i < onion_c->num_friends; ++i) { do_friend(onion_c, i);