diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-08-27 16:10:01 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-08-30 21:33:15 +0000 |
commit | a5cd4764aa3e5f8f0ba18d8348f5995d255f6c00 (patch) | |
tree | 1bb41adb2c1bf79f5ff3a20b762a3bd316ce1f5f /toxcore/DHT.c | |
parent | 515196dfa2097a9a9f04eeff5130860fc4137b0f (diff) |
Clean up `add_to_list` function a bit.
Can't trivially get rid of recursion here, since it's a non-linear
recursive function.
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 18 |
1 files changed, 7 insertions, 11 deletions
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 | |||
755 | return 1; | 755 | return 1; |
756 | } | 756 | } |
757 | 757 | ||
758 | /* Add node to the node list making sure only the nodes closest to cmp_pk are in the list. | 758 | bool add_to_list(Node_format *nodes_list, uint32_t length, const uint8_t *pk, IP_Port ip_port, |
759 | */ | ||
760 | bool add_to_list(Node_format *nodes_list, unsigned int length, const uint8_t *pk, IP_Port ip_port, | ||
761 | const uint8_t *cmp_pk) | 759 | const uint8_t *cmp_pk) |
762 | { | 760 | { |
763 | uint8_t pk_bak[CRYPTO_PUBLIC_KEY_SIZE]; | 761 | for (uint32_t i = 0; i < length; ++i) { |
764 | IP_Port ip_port_bak; | ||
765 | |||
766 | for (size_t i = 0; i < length; ++i) { | ||
767 | if (id_closest(cmp_pk, nodes_list[i].public_key, pk) == 2) { | 762 | if (id_closest(cmp_pk, nodes_list[i].public_key, pk) == 2) { |
763 | uint8_t pk_bak[CRYPTO_PUBLIC_KEY_SIZE]; | ||
768 | memcpy(pk_bak, nodes_list[i].public_key, CRYPTO_PUBLIC_KEY_SIZE); | 764 | memcpy(pk_bak, nodes_list[i].public_key, CRYPTO_PUBLIC_KEY_SIZE); |
769 | ip_port_bak = nodes_list[i].ip_port; | 765 | const IP_Port ip_port_bak = nodes_list[i].ip_port; |
770 | memcpy(nodes_list[i].public_key, pk, CRYPTO_PUBLIC_KEY_SIZE); | 766 | memcpy(nodes_list[i].public_key, pk, CRYPTO_PUBLIC_KEY_SIZE); |
771 | nodes_list[i].ip_port = ip_port; | 767 | nodes_list[i].ip_port = ip_port; |
772 | 768 | ||
773 | if (i != (length - 1)) { | 769 | if (i != length - 1) { |
774 | add_to_list(nodes_list, length, pk_bak, ip_port_bak, cmp_pk); | 770 | add_to_list(nodes_list, length, pk_bak, ip_port_bak, cmp_pk); |
775 | } | 771 | } |
776 | 772 | ||
777 | return 1; | 773 | return true; |
778 | } | 774 | } |
779 | } | 775 | } |
780 | 776 | ||
781 | return 0; | 777 | return false; |
782 | } | 778 | } |
783 | 779 | ||
784 | /* TODO(irungentoo): change this to 7 when done*/ | 780 | /* TODO(irungentoo): change this to 7 when done*/ |