diff options
-rw-r--r-- | toxcore/onion_client.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index a85a07a2..337bc296 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -183,13 +183,19 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, uint8_t *publ | |||
183 | qsort(list_nodes, MAX_ONION_CLIENTS, sizeof(Onion_Node), cmp_entry); | 183 | qsort(list_nodes, MAX_ONION_CLIENTS, sizeof(Onion_Node), cmp_entry); |
184 | 184 | ||
185 | int index = -1; | 185 | int index = -1; |
186 | uint32_t i; | ||
186 | 187 | ||
187 | if (is_timeout(list_nodes[0].timestamp, ONION_NODE_TIMEOUT) | 188 | for (i = 0; i < MAX_ONION_CLIENTS; ++i) { |
188 | || id_closest(reference_id, list_nodes[0].client_id, public_key) == 2) { | 189 | if (is_timeout(list_nodes[i].timestamp, ONION_NODE_TIMEOUT) |
189 | index = 0; | 190 | || id_closest(reference_id, list_nodes[i].client_id, public_key) == 2) { |
190 | } | 191 | index = i; |
191 | 192 | ||
192 | uint32_t i; | 193 | if (i != 0) |
194 | break; | ||
195 | } else { | ||
196 | break; | ||
197 | } | ||
198 | } | ||
193 | 199 | ||
194 | for (i = 0; i < MAX_ONION_CLIENTS; ++i) { | 200 | for (i = 0; i < MAX_ONION_CLIENTS; ++i) { |
195 | if (memcmp(list_nodes[i].client_id, public_key, crypto_box_PUBLICKEYBYTES) == 0) { | 201 | if (memcmp(list_nodes[i].client_id, public_key, crypto_box_PUBLICKEYBYTES) == 0) { |
@@ -255,8 +261,9 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, Node_format *n | |||
255 | } | 261 | } |
256 | } | 262 | } |
257 | 263 | ||
258 | if (j == MAX_ONION_CLIENTS) | 264 | if (j == MAX_ONION_CLIENTS) { |
259 | client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].client_id, NULL); | 265 | client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].client_id, NULL); |
266 | } | ||
260 | } | 267 | } |
261 | } | 268 | } |
262 | 269 | ||
@@ -306,7 +313,10 @@ static int handle_announce_response(void *object, IP_Port source, uint8_t *packe | |||
306 | if (client_add_to_list(onion_c, num, public_key, ip_port, plain[0], plain + 1) == -1) | 313 | if (client_add_to_list(onion_c, num, public_key, ip_port, plain[0], plain + 1) == -1) |
307 | return 1; | 314 | return 1; |
308 | 315 | ||
309 | if (client_ping_nodes(onion_c, num, (Node_format *)plain + 1 + ONION_PING_ID_SIZE, num_nodes, source) == -1) | 316 | Node_format nodes[MAX_SENT_NODES]; |
317 | memcpy(nodes, plain + 1 + ONION_PING_ID_SIZE, num_nodes * sizeof(Node_format)); | ||
318 | |||
319 | if (client_ping_nodes(onion_c, num, nodes, num_nodes, source) == -1) | ||
310 | return 1; | 320 | return 1; |
311 | 321 | ||
312 | return 0; | 322 | return 0; |