diff options
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r-- | toxcore/onion_client.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 61378fd0..11a7b629 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -1209,16 +1209,14 @@ int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_on | |||
1209 | 1209 | ||
1210 | static void populate_path_nodes(Onion_Client *onion_c) | 1210 | static void populate_path_nodes(Onion_Client *onion_c) |
1211 | { | 1211 | { |
1212 | Node_format nodes_list[MAX_SENT_NODES]; | 1212 | Node_format nodes_list[MAX_FRIEND_CLIENTS]; |
1213 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; | 1213 | |
1214 | uint32_t random_num = rand(); | 1214 | unsigned int num_nodes = randfriends_nodes(onion_c->dht, nodes_list, MAX_FRIEND_CLIENTS); |
1215 | memcpy(public_key, &random_num, sizeof(random_num)); | ||
1216 | 1215 | ||
1217 | unsigned int num_nodes = get_close_nodes(onion_c->dht, public_key, nodes_list, (rand() % 2) ? AF_INET : AF_INET6, 1, 0); | ||
1218 | unsigned int i; | 1216 | unsigned int i; |
1219 | 1217 | ||
1220 | for (i = 0; i < num_nodes; ++i) { | 1218 | for (i = 0; i < num_nodes; ++i) { |
1221 | onion_add_path_node(onion_c, nodes_list[i].ip_port, nodes_list[i].public_key); | 1219 | int r = onion_add_path_node(onion_c, nodes_list[i].ip_port, nodes_list[i].public_key); |
1222 | } | 1220 | } |
1223 | } | 1221 | } |
1224 | 1222 | ||
@@ -1415,7 +1413,7 @@ static int onion_isconnected(const Onion_Client *onion_c) | |||
1415 | return 0; | 1413 | return 0; |
1416 | } | 1414 | } |
1417 | 1415 | ||
1418 | #define ONION_CONNECTION_SECONDS 2 | 1416 | #define ONION_CONNECTION_SECONDS 3 |
1419 | 1417 | ||
1420 | /* return 0 if we are not connected to the network. | 1418 | /* return 0 if we are not connected to the network. |
1421 | * return 1 if we are connected with TCP only. | 1419 | * return 1 if we are connected with TCP only. |
@@ -1441,8 +1439,6 @@ void do_onion_client(Onion_Client *onion_c) | |||
1441 | if (onion_c->last_run == unix_time()) | 1439 | if (onion_c->last_run == unix_time()) |
1442 | return; | 1440 | return; |
1443 | 1441 | ||
1444 | populate_path_nodes(onion_c); | ||
1445 | |||
1446 | do_announce(onion_c); | 1442 | do_announce(onion_c); |
1447 | 1443 | ||
1448 | if (onion_isconnected(onion_c)) { | 1444 | if (onion_isconnected(onion_c)) { |
@@ -1461,6 +1457,7 @@ void do_onion_client(Onion_Client *onion_c) | |||
1461 | _Bool UDP_connected = DHT_non_lan_connected(onion_c->dht); | 1457 | _Bool UDP_connected = DHT_non_lan_connected(onion_c->dht); |
1462 | 1458 | ||
1463 | if (is_timeout(onion_c->first_run, ONION_CONNECTION_SECONDS)) { | 1459 | if (is_timeout(onion_c->first_run, ONION_CONNECTION_SECONDS)) { |
1460 | populate_path_nodes(onion_c); | ||
1464 | set_tcp_onion_status(onion_c->c->tcp_c, !UDP_connected); | 1461 | set_tcp_onion_status(onion_c->c->tcp_c, !UDP_connected); |
1465 | } | 1462 | } |
1466 | 1463 | ||