Skip to content

Commit

Permalink
Remove recursive calling code
Browse files Browse the repository at this point in the history
Remove recursive calling code
  • Loading branch information
zgfzgf committed Jun 16, 2020
1 parent 470fa79 commit 399d647
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions toxcore/DHT.c
Expand Up @@ -753,23 +753,22 @@ static int client_or_ip_port_in_list(const Logger *log, const Mono_Time *mono_ti
bool add_to_list(Node_format *nodes_list, uint32_t length, const uint8_t *pk, IP_Port ip_port,
const uint8_t *cmp_pk)
{
bool ret = false;
uint8_t pk_bak[CRYPTO_PUBLIC_KEY_SIZE];
memcpy(pk_bak, pk, CRYPTO_PUBLIC_KEY_SIZE);
IP_Port ip_port_bak = ip_port;
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(nodes_list[i].public_key, pk_bak, CRYPTO_PUBLIC_KEY_SIZE);
memcpy(pk_bak, nodes_list[i].public_key, CRYPTO_PUBLIC_KEY_SIZE);
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) {
add_to_list(nodes_list, length, pk_bak, ip_port_bak, cmp_pk);
}
nodes_list[i].ip_port = ip_port_bak;
ip_port_bak = nodes_list[i].ip_port;

return true;
ret = true;
}
}

return false;
return ret;
}

/* TODO(irungentoo): change this to 7 when done*/
Expand Down

0 comments on commit 399d647

Please sign in to comment.