summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-12-16 11:28:30 -0500
committerirungentoo <irungentoo@gmail.com>2015-12-16 11:28:30 -0500
commitc1e00c5d3940fc590d099692b848a106c28633ad (patch)
tree8ec439fba1709ba5d5b4f2c8577baf6143a13a4b
parent1d91699e8e23dab4c221c8402c7f086264a485ee (diff)
Improved the to_ping list.
-rw-r--r--toxcore/DHT.c6
-rw-r--r--toxcore/DHT.h5
-rw-r--r--toxcore/ping.c11
3 files changed, 11 insertions, 11 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index a958938d..c4d1aa4c 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -473,8 +473,10 @@ static int friend_number(const DHT *dht, const uint8_t *public_key)
473 return -1; 473 return -1;
474} 474}
475 475
476static _Bool add_to_list(Node_format *nodes_list, unsigned int length, const uint8_t *pk, IP_Port ip_port, 476/* Add node to the node list making sure only the nodes closest to cmp_pk are in the list.
477 const uint8_t *cmp_pk) 477 */
478_Bool add_to_list(Node_format *nodes_list, unsigned int length, const uint8_t *pk, IP_Port ip_port,
479 const uint8_t *cmp_pk)
478{ 480{
479 uint8_t pk_bak[crypto_box_PUBLICKEYBYTES]; 481 uint8_t pk_bak[crypto_box_PUBLICKEYBYTES];
480 IP_Port ip_port_bak; 482 IP_Port ip_port_bak;
diff --git a/toxcore/DHT.h b/toxcore/DHT.h
index 4ae99049..048bfcf4 100644
--- a/toxcore/DHT.h
+++ b/toxcore/DHT.h
@@ -302,6 +302,11 @@ int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
302 */ 302 */
303int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2); 303int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2);
304 304
305/* Add node to the node list making sure only the nodes closest to cmp_pk are in the list.
306 */
307_Bool add_to_list(Node_format *nodes_list, unsigned int length, const uint8_t *pk, IP_Port ip_port,
308 const uint8_t *cmp_pk);
309
305/* Get the (maximum MAX_SENT_NODES) closest nodes to public_key we know 310/* Get the (maximum MAX_SENT_NODES) closest nodes to public_key we know
306 * and put them in nodes_list (must be MAX_SENT_NODES big). 311 * and put them in nodes_list (must be MAX_SENT_NODES big).
307 * 312 *
diff --git a/toxcore/ping.c b/toxcore/ping.c
index 17fb3e9e..6a480f6f 100644
--- a/toxcore/ping.c
+++ b/toxcore/ping.c
@@ -287,15 +287,8 @@ int add_to_ping(PING *ping, const uint8_t *public_key, IP_Port ip_port)
287 } 287 }
288 } 288 }
289 289
290 unsigned int r = rand(); 290 if (add_to_list(ping->to_ping, MAX_TO_PING, public_key, ip_port, ping->dht->self_public_key))
291 291 return 0;
292 for (i = 0; i < MAX_TO_PING; ++i) {
293 if (id_closest(ping->dht->self_public_key, ping->to_ping[(i + r) % MAX_TO_PING].public_key, public_key) == 2) {
294 memcpy(ping->to_ping[(i + r) % MAX_TO_PING].public_key, public_key, crypto_box_PUBLICKEYBYTES);
295 ipport_copy(&ping->to_ping[(i + r) % MAX_TO_PING].ip_port, &ip_port);
296 return 0;
297 }
298 }
299 292
300 return -1; 293 return -1;
301} 294}