diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 68143421..b2f2e625 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -755,30 +755,26 @@ static int client_or_ip_port_in_list(const Logger *log, const Mono_Time *mono_ti return 1; } -/* Add node to the node list making sure only the nodes closest to cmp_pk are in the list. - */ -bool add_to_list(Node_format *nodes_list, unsigned int length, const uint8_t *pk, IP_Port ip_port, +bool add_to_list(Node_format *nodes_list, uint32_t length, const uint8_t *pk, IP_Port ip_port, const uint8_t *cmp_pk) { - uint8_t pk_bak[CRYPTO_PUBLIC_KEY_SIZE]; - IP_Port ip_port_bak; - - for (size_t i = 0; i < length; ++i) { + for (uint32_t i = 0; i < length; ++i) { if (id_closest(cmp_pk, nodes_list[i].public_key, pk) == 2) { + uint8_t pk_bak[CRYPTO_PUBLIC_KEY_SIZE]; memcpy(pk_bak, nodes_list[i].public_key, CRYPTO_PUBLIC_KEY_SIZE); - ip_port_bak = nodes_list[i].ip_port; + const IP_Port ip_port_bak = nodes_list[i].ip_port; memcpy(nodes_list[i].public_key, pk, CRYPTO_PUBLIC_KEY_SIZE); nodes_list[i].ip_port = ip_port; - if (i != (length - 1)) { + if (i != length - 1) { add_to_list(nodes_list, length, pk_bak, ip_port_bak, cmp_pk); } - return 1; + return true; } } - return 0; + return false; } /* TODO(irungentoo): change this to 7 when done*/ diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 4a7af4c7..9f5f1ec7 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h @@ -302,9 +302,12 @@ int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port) */ int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2); -/* Add node to the node list making sure only the nodes closest to cmp_pk are in the list. +/** + * Add node to the node list making sure only the nodes closest to cmp_pk are in the list. + * + * @return true iff the node was added to the list. */ -bool add_to_list(Node_format *nodes_list, unsigned int length, const uint8_t *pk, IP_Port ip_port, +bool add_to_list(Node_format *nodes_list, uint32_t length, const uint8_t *pk, IP_Port ip_port, const uint8_t *cmp_pk); /* Return 1 if node can be added to close list, 0 if it can't.