summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
diff options
context:
space:
mode:
authorDiadlo <polsha3@gmail.com>2017-06-04 20:31:20 +0300
committerDiadlo <polsha3@gmail.com>2017-06-05 01:09:39 +0300
commitc12ef2213800d34df768bf5308d6ac79ecee575a (patch)
tree198f5c4cd12897fe54cd6486a48e804567488327 /toxcore/DHT.c
parentb0aec02225b642b2e420e634dce919beee0cd0f2 (diff)
Add using C99 'for' syntax
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r--toxcore/DHT.c192
1 files changed, 70 insertions, 122 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 30e0b816..93f1a52c 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -62,13 +62,10 @@
62 */ 62 */
63int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2) 63int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2)
64{ 64{
65 size_t i; 65 for (size_t i = 0; i < CRYPTO_PUBLIC_KEY_SIZE; ++i) {
66 uint8_t distance1, distance2;
67 66
68 for (i = 0; i < CRYPTO_PUBLIC_KEY_SIZE; ++i) { 67 uint8_t distance1 = pk[i] ^ pk1[i];
69 68 uint8_t distance2 = pk[i] ^ pk2[i];
70 distance1 = pk[i] ^ pk1[i];
71 distance2 = pk[i] ^ pk2[i];
72 69
73 if (distance1 < distance2) { 70 if (distance1 < distance2) {
74 return 1; 71 return 1;
@@ -113,9 +110,9 @@ static unsigned int bit_by_bit_cmp(const uint8_t *pk1, const uint8_t *pk2)
113 */ 110 */
114void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t *secret_key, const uint8_t *public_key) 111void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t *secret_key, const uint8_t *public_key)
115{ 112{
116 uint32_t i, num = ~0, curr = 0; 113 uint32_t num = ~0, curr = 0;
117 114
118 for (i = 0; i < MAX_KEYS_PER_SLOT; ++i) { 115 for (uint32_t i = 0; i < MAX_KEYS_PER_SLOT; ++i) {
119 int index = public_key[30] * MAX_KEYS_PER_SLOT + i; 116 int index = public_key[30] * MAX_KEYS_PER_SLOT + i;
120 117
121 if (shared_keys->keys[index].stored) { 118 if (shared_keys->keys[index].stored) {
@@ -455,9 +452,9 @@ static int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length
455 */ 452 */
456int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_t number) 453int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_t number)
457{ 454{
458 uint32_t i, packed_length = 0; 455 uint32_t packed_length = 0;
459 456
460 for (i = 0; i < number && packed_length < length; ++i) { 457 for (uint32_t i = 0; i < number && packed_length < length; ++i) {
461 int ipp_size = pack_ip_port(data + packed_length, length - packed_length, &nodes[i].ip_port); 458 int ipp_size = pack_ip_port(data + packed_length, length - packed_length, &nodes[i].ip_port);
462 459
463 if (ipp_size == -1) { 460 if (ipp_size == -1) {
@@ -532,11 +529,10 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed
532static int client_or_ip_port_in_list(Logger *log, Client_data *list, uint16_t length, const uint8_t *public_key, 529static int client_or_ip_port_in_list(Logger *log, Client_data *list, uint16_t length, const uint8_t *public_key,
533 IP_Port ip_port) 530 IP_Port ip_port)
534{ 531{
535 uint32_t i;
536 uint64_t temp_time = unix_time(); 532 uint64_t temp_time = unix_time();
537 533
538 /* if public_key is in list, find it and maybe overwrite ip_port */ 534 /* if public_key is in list, find it and maybe overwrite ip_port */
539 for (i = 0; i < length; ++i) { 535 for (uint32_t i = 0; i < length; ++i) {
540 if (id_equal(list[i].public_key, public_key)) { 536 if (id_equal(list[i].public_key, public_key)) {
541 /* Refresh the client timestamp. */ 537 /* Refresh the client timestamp. */
542 if (ip_port.ip.family == AF_INET) { 538 if (ip_port.ip.family == AF_INET) {
@@ -583,7 +579,7 @@ static int client_or_ip_port_in_list(Logger *log, Client_data *list, uint16_t le
583 * that case we kill the old public_key by overwriting it with the new one 579 * that case we kill the old public_key by overwriting it with the new one
584 * TODO(irungentoo): maybe we SHOULDN'T do that if that public_key is in a friend_list 580 * TODO(irungentoo): maybe we SHOULDN'T do that if that public_key is in a friend_list
585 * and the one who is the actual friend's public_key/address set? */ 581 * and the one who is the actual friend's public_key/address set? */
586 for (i = 0; i < length; ++i) { 582 for (uint32_t i = 0; i < length; ++i) {
587 /* MAYBE: check the other address, if valid, don't nuke? */ 583 /* MAYBE: check the other address, if valid, don't nuke? */
588 if ((ip_port.ip.family == AF_INET) && ipport_equal(&list[i].assoc4.ip_port, &ip_port)) { 584 if ((ip_port.ip.family == AF_INET) && ipport_equal(&list[i].assoc4.ip_port, &ip_port)) {
589 /* Initialize client timestamp. */ 585 /* Initialize client timestamp. */
@@ -620,9 +616,7 @@ static int client_or_ip_port_in_list(Logger *log, Client_data *list, uint16_t le
620 */ 616 */
621static int client_in_nodelist(const Node_format *list, uint16_t length, const uint8_t *public_key) 617static int client_in_nodelist(const Node_format *list, uint16_t length, const uint8_t *public_key)
622{ 618{
623 uint32_t i; 619 for (uint32_t i = 0; i < length; ++i) {
624
625 for (i = 0; i < length; ++i) {
626 if (id_equal(list[i].public_key, public_key)) { 620 if (id_equal(list[i].public_key, public_key)) {
627 return 1; 621 return 1;
628 } 622 }
@@ -636,9 +630,7 @@ static int client_in_nodelist(const Node_format *list, uint16_t length, const ui
636 */ 630 */
637static int friend_number(const DHT *dht, const uint8_t *public_key) 631static int friend_number(const DHT *dht, const uint8_t *public_key)
638{ 632{
639 uint32_t i; 633 for (uint32_t i = 0; i < dht->num_friends; ++i) {
640
641 for (i = 0; i < dht->num_friends; ++i) {
642 if (id_equal(dht->friends_list[i].public_key, public_key)) { 634 if (id_equal(dht->friends_list[i].public_key, public_key)) {
643 return i; 635 return i;
644 } 636 }
@@ -655,9 +647,7 @@ bool add_to_list(Node_format *nodes_list, unsigned int length, const uint8_t *pk
655 uint8_t pk_bak[CRYPTO_PUBLIC_KEY_SIZE]; 647 uint8_t pk_bak[CRYPTO_PUBLIC_KEY_SIZE];
656 IP_Port ip_port_bak; 648 IP_Port ip_port_bak;
657 649
658 unsigned int i; 650 for (size_t i = 0; i < length; ++i) {
659
660 for (i = 0; i < length; ++i) {
661 if (id_closest(cmp_pk, nodes_list[i].public_key, pk) == 2) { 651 if (id_closest(cmp_pk, nodes_list[i].public_key, pk) == 2) {
662 memcpy(pk_bak, nodes_list[i].public_key, CRYPTO_PUBLIC_KEY_SIZE); 652 memcpy(pk_bak, nodes_list[i].public_key, CRYPTO_PUBLIC_KEY_SIZE);
663 ip_port_bak = nodes_list[i].ip_port; 653 ip_port_bak = nodes_list[i].ip_port;
@@ -699,9 +689,8 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_
699 } 689 }
700 690
701 uint32_t num_nodes = *num_nodes_ptr; 691 uint32_t num_nodes = *num_nodes_ptr;
702 uint32_t i;
703 692
704 for (i = 0; i < client_list_length; i++) { 693 for (uint32_t i = 0; i < client_list_length; i++) {
705 const Client_data *client = &client_list[i]; 694 const Client_data *client = &client_list[i];
706 695
707 /* node already in list? */ 696 /* node already in list? */
@@ -764,14 +753,14 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_
764static int get_somewhat_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, 753static int get_somewhat_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list,
765 Family sa_family, uint8_t is_LAN, uint8_t want_good) 754 Family sa_family, uint8_t is_LAN, uint8_t want_good)
766{ 755{
767 uint32_t num_nodes = 0, i; 756 uint32_t num_nodes = 0;
768 get_close_nodes_inner(public_key, nodes_list, sa_family, 757 get_close_nodes_inner(public_key, nodes_list, sa_family,
769 dht->close_clientlist, LCLIENT_LIST, &num_nodes, is_LAN, 0); 758 dht->close_clientlist, LCLIENT_LIST, &num_nodes, is_LAN, 0);
770 759
771 /* TODO(irungentoo): uncomment this when hardening is added to close friend clients */ 760 /* TODO(irungentoo): uncomment this when hardening is added to close friend clients */
772#if 0 761#if 0
773 762
774 for (i = 0; i < dht->num_friends; ++i) { 763 for (uint32_t i = 0; i < dht->num_friends; ++i) {
775 get_close_nodes_inner(dht, public_key, nodes_list, sa_family, 764 get_close_nodes_inner(dht, public_key, nodes_list, sa_family,
776 dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, 765 dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS,
777 &num_nodes, is_LAN, want_good); 766 &num_nodes, is_LAN, want_good);
@@ -779,7 +768,7 @@ static int get_somewhat_close_nodes(const DHT *dht, const uint8_t *public_key, N
779 768
780#endif 769#endif
781 770
782 for (i = 0; i < dht->num_friends; ++i) { 771 for (uint32_t i = 0; i < dht->num_friends; ++i) {
783 get_close_nodes_inner(public_key, nodes_list, sa_family, 772 get_close_nodes_inner(public_key, nodes_list, sa_family,
784 dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, 773 dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS,
785 &num_nodes, is_LAN, 0); 774 &num_nodes, is_LAN, 0);
@@ -950,15 +939,13 @@ static int replace_all(Client_data *list,
950 */ 939 */
951static int add_to_close(DHT *dht, const uint8_t *public_key, IP_Port ip_port, bool simulate) 940static int add_to_close(DHT *dht, const uint8_t *public_key, IP_Port ip_port, bool simulate)
952{ 941{
953 unsigned int i;
954
955 unsigned int index = bit_by_bit_cmp(public_key, dht->self_public_key); 942 unsigned int index = bit_by_bit_cmp(public_key, dht->self_public_key);
956 943
957 if (index >= LCLIENT_LENGTH) { 944 if (index >= LCLIENT_LENGTH) {
958 index = LCLIENT_LENGTH - 1; 945 index = LCLIENT_LENGTH - 1;
959 } 946 }
960 947
961 for (i = 0; i < LCLIENT_NODES; ++i) { 948 for (uint32_t i = 0; i < LCLIENT_NODES; ++i) {
962 /* TODO(iphydf): write bounds checking test to catch the case that 949 /* TODO(iphydf): write bounds checking test to catch the case that
963 * index is left as >= LCLIENT_LENGTH */ 950 * index is left as >= LCLIENT_LENGTH */
964 Client_data *client = &dht->close_clientlist[(index * LCLIENT_NODES) + i]; 951 Client_data *client = &dht->close_clientlist[(index * LCLIENT_NODES) + i];
@@ -1009,9 +996,7 @@ bool node_addable_to_close_list(DHT *dht, const uint8_t *public_key, IP_Port ip_
1009static bool is_pk_in_client_list(Client_data *list, unsigned int client_list_length, const uint8_t *public_key, 996static bool is_pk_in_client_list(Client_data *list, unsigned int client_list_length, const uint8_t *public_key,
1010 IP_Port ip_port) 997 IP_Port ip_port)
1011{ 998{
1012 unsigned int i; 999 for (uint32_t i = 0; i < client_list_length; ++i) {
1013
1014 for (i = 0; i < client_list_length; ++i) {
1015 if ((ip_port.ip.family == AF_INET && !is_timeout(list[i].assoc4.timestamp, BAD_NODE_TIMEOUT)) 1000 if ((ip_port.ip.family == AF_INET && !is_timeout(list[i].assoc4.timestamp, BAD_NODE_TIMEOUT))
1016 || (ip_port.ip.family == AF_INET6 && !is_timeout(list[i].assoc6.timestamp, BAD_NODE_TIMEOUT))) { 1001 || (ip_port.ip.family == AF_INET6 && !is_timeout(list[i].assoc6.timestamp, BAD_NODE_TIMEOUT))) {
1017 if (public_key_cmp(list[i].public_key, public_key) == 0) { 1002 if (public_key_cmp(list[i].public_key, public_key) == 0) {
@@ -1060,9 +1045,7 @@ static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_k
1060 } 1045 }
1061 } 1046 }
1062 1047
1063 unsigned int i; 1048 for (uint32_t i = 0; i < dht->num_friends; ++i) {
1064
1065 for (i = 0; i < dht->num_friends; ++i) {
1066 bool store_ok = 0; 1049 bool store_ok = 0;
1067 1050
1068 DHT_Friend *dht_friend = &dht->friends_list[i]; 1051 DHT_Friend *dht_friend = &dht->friends_list[i];
@@ -1099,7 +1082,7 @@ static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_k
1099 */ 1082 */
1100int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key) 1083int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
1101{ 1084{
1102 uint32_t i, used = 0; 1085 uint32_t used = 0;
1103 1086
1104 /* convert IPv4-in-IPv6 to IPv4 */ 1087 /* convert IPv4-in-IPv6 to IPv4 */
1105 if ((ip_port.ip.family == AF_INET6) && IPV6_IPV4_IN_V6(ip_port.ip.ip6)) { 1088 if ((ip_port.ip.family == AF_INET6) && IPV6_IPV4_IN_V6(ip_port.ip.ip6)) {
@@ -1120,7 +1103,7 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
1120 1103
1121 DHT_Friend *friend_foundip = 0; 1104 DHT_Friend *friend_foundip = 0;
1122 1105
1123 for (i = 0; i < dht->num_friends; ++i) { 1106 for (uint32_t i = 0; i < dht->num_friends; ++i) {
1124 if (!client_or_ip_port_in_list(dht->log, dht->friends_list[i].client_list, 1107 if (!client_or_ip_port_in_list(dht->log, dht->friends_list[i].client_list,
1125 MAX_FRIEND_CLIENTS, public_key, ip_port)) { 1108 MAX_FRIEND_CLIENTS, public_key, ip_port)) {
1126 if (replace_all(dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, 1109 if (replace_all(dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS,
@@ -1146,11 +1129,9 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
1146 } 1129 }
1147 1130
1148 if (friend_foundip) { 1131 if (friend_foundip) {
1149 uint32_t j; 1132 for (uint32_t i = 0; i < friend_foundip->lock_count; ++i) {
1150 1133 if (friend_foundip->callbacks[i].ip_callback) {
1151 for (j = 0; j < friend_foundip->lock_count; ++j) { 1134 friend_foundip->callbacks[i].ip_callback(friend_foundip->callbacks[i].data, friend_foundip->callbacks[i].number,
1152 if (friend_foundip->callbacks[j].ip_callback) {
1153 friend_foundip->callbacks[j].ip_callback(friend_foundip->callbacks[j].data, friend_foundip->callbacks[j].number,
1154 ip_port); 1135 ip_port);
1155 } 1136 }
1156 } 1137 }
@@ -1164,7 +1145,6 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
1164 */ 1145 */
1165static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *nodepublic_key) 1146static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *nodepublic_key)
1166{ 1147{
1167 uint32_t i, j;
1168 uint64_t temp_time = unix_time(); 1148 uint64_t temp_time = unix_time();
1169 1149
1170 uint32_t used = 0; 1150 uint32_t used = 0;
@@ -1176,7 +1156,7 @@ static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key
1176 } 1156 }
1177 1157
1178 if (id_equal(public_key, dht->self_public_key)) { 1158 if (id_equal(public_key, dht->self_public_key)) {
1179 for (i = 0; i < LCLIENT_LIST; ++i) { 1159 for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
1180 if (id_equal(nodepublic_key, dht->close_clientlist[i].public_key)) { 1160 if (id_equal(nodepublic_key, dht->close_clientlist[i].public_key)) {
1181 if (ip_port.ip.family == AF_INET) { 1161 if (ip_port.ip.family == AF_INET) {
1182 dht->close_clientlist[i].assoc4.ret_ip_port = ip_port; 1162 dht->close_clientlist[i].assoc4.ret_ip_port = ip_port;
@@ -1191,9 +1171,9 @@ static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key
1191 } 1171 }
1192 } 1172 }
1193 } else { 1173 } else {
1194 for (i = 0; i < dht->num_friends; ++i) { 1174 for (uint32_t i = 0; i < dht->num_friends; ++i) {
1195 if (id_equal(public_key, dht->friends_list[i].public_key)) { 1175 if (id_equal(public_key, dht->friends_list[i].public_key)) {
1196 for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { 1176 for (uint32_t j = 0; j < MAX_FRIEND_CLIENTS; ++j) {
1197 if (id_equal(nodepublic_key, dht->friends_list[i].client_list[j].public_key)) { 1177 if (id_equal(nodepublic_key, dht->friends_list[i].client_list[j].public_key)) {
1198 if (ip_port.ip.family == AF_INET) { 1178 if (ip_port.ip.family == AF_INET) {
1199 dht->friends_list[i].client_list[j].assoc4.ret_ip_port = ip_port; 1179 dht->friends_list[i].client_list[j].assoc4.ret_ip_port = ip_port;
@@ -1458,10 +1438,7 @@ static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *pa
1458 return 0; 1438 return 0;
1459 } 1439 }
1460 1440
1461 uint32_t i; 1441 for (uint32_t i = 0; i < num_nodes; i++) {
1462
1463 for (i = 0; i < num_nodes; i++) {
1464
1465 if (ipport_isset(&plain_nodes[i].ip_port)) { 1442 if (ipport_isset(&plain_nodes[i].ip_port)) {
1466 ping_node_from_getnodes_ok(dht, plain_nodes[i].public_key, plain_nodes[i].ip_port); 1443 ping_node_from_getnodes_ok(dht, plain_nodes[i].public_key, plain_nodes[i].ip_port);
1467 returnedip_ports(dht, plain_nodes[i].ip_port, plain_nodes[i].public_key, packet + 1); 1444 returnedip_ports(dht, plain_nodes[i].ip_port, plain_nodes[i].public_key, packet + 1);
@@ -1576,15 +1553,13 @@ int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
1576/* TODO(irungentoo): Optimize this. */ 1553/* TODO(irungentoo): Optimize this. */
1577int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port) 1554int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
1578{ 1555{
1579 uint32_t i, j;
1580
1581 ip_reset(&ip_port->ip); 1556 ip_reset(&ip_port->ip);
1582 ip_port->port = 0; 1557 ip_port->port = 0;
1583 1558
1584 for (i = 0; i < dht->num_friends; ++i) { 1559 for (uint32_t i = 0; i < dht->num_friends; ++i) {
1585 /* Equal */ 1560 /* Equal */
1586 if (id_equal(dht->friends_list[i].public_key, public_key)) { 1561 if (id_equal(dht->friends_list[i].public_key, public_key)) {
1587 for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { 1562 for (uint32_t j = 0; j < MAX_FRIEND_CLIENTS; ++j) {
1588 Client_data *client = &dht->friends_list[i].client_list[j]; 1563 Client_data *client = &dht->friends_list[i].client_list[j];
1589 1564
1590 if (id_equal(client->public_key, public_key)) { 1565 if (id_equal(client->public_key, public_key)) {
@@ -1611,7 +1586,6 @@ int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
1611static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, const uint8_t *public_key, 1586static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, const uint8_t *public_key,
1612 Client_data *list, uint32_t list_count, uint32_t *bootstrap_times, bool sortable) 1587 Client_data *list, uint32_t list_count, uint32_t *bootstrap_times, bool sortable)
1613{ 1588{
1614 uint32_t i;
1615 uint8_t not_kill = 0; 1589 uint8_t not_kill = 0;
1616 uint64_t temp_time = unix_time(); 1590 uint64_t temp_time = unix_time();
1617 1591
@@ -1621,7 +1595,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
1621 unsigned int sort = 0; 1595 unsigned int sort = 0;
1622 bool sort_ok = 0; 1596 bool sort_ok = 0;
1623 1597
1624 for (i = 0; i < list_count; i++) { 1598 for (uint32_t i = 0; i < list_count; i++) {
1625 /* If node is not dead. */ 1599 /* If node is not dead. */
1626 Client_data *client = &list[i]; 1600 Client_data *client = &list[i];
1627 IPPTsPng *assoc; 1601 IPPTsPng *assoc;
@@ -1679,12 +1653,10 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
1679 */ 1653 */
1680static void do_DHT_friends(DHT *dht) 1654static void do_DHT_friends(DHT *dht)
1681{ 1655{
1682 unsigned int i, j; 1656 for (size_t i = 0; i < dht->num_friends; ++i) {
1683
1684 for (i = 0; i < dht->num_friends; ++i) {
1685 DHT_Friend *dht_friend = &dht->friends_list[i]; 1657 DHT_Friend *dht_friend = &dht->friends_list[i];
1686 1658
1687 for (j = 0; j < dht_friend->num_to_bootstrap; ++j) { 1659 for (size_t j = 0; j < dht_friend->num_to_bootstrap; ++j) {
1688 getnodes(dht, dht_friend->to_bootstrap[j].ip_port, dht_friend->to_bootstrap[j].public_key, dht_friend->public_key, 1660 getnodes(dht, dht_friend->to_bootstrap[j].ip_port, dht_friend->to_bootstrap[j].public_key, dht_friend->public_key,
1689 NULL); 1661 NULL);
1690 } 1662 }
@@ -1702,9 +1674,7 @@ static void do_DHT_friends(DHT *dht)
1702 */ 1674 */
1703static void do_Close(DHT *dht) 1675static void do_Close(DHT *dht)
1704{ 1676{
1705 unsigned int i; 1677 for (size_t i = 0; i < dht->num_to_bootstrap; ++i) {
1706
1707 for (i = 0; i < dht->num_to_bootstrap; ++i) {
1708 getnodes(dht, dht->to_bootstrap[i].ip_port, dht->to_bootstrap[i].public_key, dht->self_public_key, NULL); 1678 getnodes(dht, dht->to_bootstrap[i].ip_port, dht->to_bootstrap[i].public_key, dht->self_public_key, NULL);
1709 } 1679 }
1710 1680
@@ -1721,11 +1691,11 @@ static void do_Close(DHT *dht)
1721 * so: reset all nodes to be BAD_NODE_TIMEOUT, but not 1691 * so: reset all nodes to be BAD_NODE_TIMEOUT, but not
1722 * KILL_NODE_TIMEOUT, so we at least keep trying pings */ 1692 * KILL_NODE_TIMEOUT, so we at least keep trying pings */
1723 uint64_t badonly = unix_time() - BAD_NODE_TIMEOUT; 1693 uint64_t badonly = unix_time() - BAD_NODE_TIMEOUT;
1724 size_t j, a;
1725 1694
1726 for (j = 0; j < LCLIENT_LIST; j++) { 1695 for (size_t i = 0; i < LCLIENT_LIST; i++) {
1727 Client_data *client = &dht->close_clientlist[j]; 1696 Client_data *client = &dht->close_clientlist[i];
1728 IPPTsPng *assoc; 1697 IPPTsPng *assoc;
1698 uint32_t a;
1729 1699
1730 for (a = 0, assoc = &client->assoc4; a < 2; a++, assoc = &client->assoc6) { 1700 for (a = 0, assoc = &client->assoc4; a < 2; a++, assoc = &client->assoc6) {
1731 if (assoc->timestamp) { 1701 if (assoc->timestamp) {
@@ -1781,9 +1751,7 @@ int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enable
1781 */ 1751 */
1782int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packet, uint16_t length) 1752int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packet, uint16_t length)
1783{ 1753{
1784 uint32_t i; 1754 for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
1785
1786 for (i = 0; i < LCLIENT_LIST; ++i) {
1787 if (id_equal(public_key, dht->close_clientlist[i].public_key)) { 1755 if (id_equal(public_key, dht->close_clientlist[i].public_key)) {
1788 const Client_data *client = &dht->close_clientlist[i]; 1756 const Client_data *client = &dht->close_clientlist[i];
1789 1757
@@ -1821,9 +1789,8 @@ static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_n
1821 int num_ipv4s = 0; 1789 int num_ipv4s = 0;
1822 IP_Port ipv6s[MAX_FRIEND_CLIENTS]; 1790 IP_Port ipv6s[MAX_FRIEND_CLIENTS];
1823 int num_ipv6s = 0; 1791 int num_ipv6s = 0;
1824 int i;
1825 1792
1826 for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { 1793 for (size_t i = 0; i < MAX_FRIEND_CLIENTS; ++i) {
1827 client = &(dht_friend->client_list[i]); 1794 client = &(dht_friend->client_list[i]);
1828 1795
1829 /* If ip is not zero and node is good. */ 1796 /* If ip is not zero and node is good. */
@@ -1891,7 +1858,7 @@ int route_tofriend(const DHT *dht, const uint8_t *friend_id, const uint8_t *pack
1891 return 0; 1858 return 0;
1892 } 1859 }
1893 1860
1894 uint32_t i, sent = 0; 1861 uint32_t sent = 0;
1895 uint8_t friend_sent[MAX_FRIEND_CLIENTS] = {0}; 1862 uint8_t friend_sent[MAX_FRIEND_CLIENTS] = {0};
1896 1863
1897 IP_Port ip_list[MAX_FRIEND_CLIENTS]; 1864 IP_Port ip_list[MAX_FRIEND_CLIENTS];
@@ -1906,10 +1873,9 @@ int route_tofriend(const DHT *dht, const uint8_t *friend_id, const uint8_t *pack
1906 1873
1907 /* extra legwork, because having the outside allocating the space for us 1874 /* extra legwork, because having the outside allocating the space for us
1908 * is *usually* good(tm) (bites us in the behind in this case though) */ 1875 * is *usually* good(tm) (bites us in the behind in this case though) */
1909 uint32_t a;
1910 1876
1911 for (a = 0; a < 2; a++) { 1877 for (uint32_t a = 0; a < 2; a++) {
1912 for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { 1878 for (uint32_t i = 0; i < MAX_FRIEND_CLIENTS; ++i) {
1913 if (friend_sent[i]) {/* Send one packet per client.*/ 1879 if (friend_sent[i]) {/* Send one packet per client.*/
1914 continue; 1880 continue;
1915 } 1881 }
@@ -1956,14 +1922,12 @@ static int routeone_tofriend(DHT *dht, const uint8_t *friend_id, const uint8_t *
1956 1922
1957 IP_Port ip_list[MAX_FRIEND_CLIENTS * 2]; 1923 IP_Port ip_list[MAX_FRIEND_CLIENTS * 2];
1958 int n = 0; 1924 int n = 0;
1959 uint32_t i;
1960 1925
1961 /* extra legwork, because having the outside allocating the space for us 1926 /* extra legwork, because having the outside allocating the space for us
1962 * is *usually* good(tm) (bites us in the behind in this case though) */ 1927 * is *usually* good(tm) (bites us in the behind in this case though) */
1963 uint32_t a;
1964 1928
1965 for (a = 0; a < 2; a++) { 1929 for (uint32_t a = 0; a < 2; a++) {
1966 for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { 1930 for (uint32_t i = 0; i < MAX_FRIEND_CLIENTS; ++i) {
1967 client = &dht_friend->client_list[i]; 1931 client = &dht_friend->client_list[i];
1968 IPPTsPng *assoc = NULL; 1932 IPPTsPng *assoc = NULL;
1969 1933
@@ -2080,11 +2044,10 @@ static IP NAT_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
2080 return zero; 2044 return zero;
2081 } 2045 }
2082 2046
2083 uint32_t i, j;
2084 uint16_t numbers[MAX_FRIEND_CLIENTS] = {0}; 2047 uint16_t numbers[MAX_FRIEND_CLIENTS] = {0};
2085 2048
2086 for (i = 0; i < len; ++i) { 2049 for (uint32_t i = 0; i < len; ++i) {
2087 for (j = 0; j < len; ++j) { 2050 for (uint32_t j = 0; j < len; ++j) {
2088 if (ip_equal(&ip_portlist[i].ip, &ip_portlist[j].ip)) { 2051 if (ip_equal(&ip_portlist[i].ip, &ip_portlist[j].ip)) {
2089 ++numbers[i]; 2052 ++numbers[i];
2090 } 2053 }
@@ -2106,10 +2069,9 @@ static IP NAT_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
2106 */ 2069 */
2107static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t len, IP ip) 2070static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t len, IP ip)
2108{ 2071{
2109 uint32_t i;
2110 uint16_t num = 0; 2072 uint16_t num = 0;
2111 2073
2112 for (i = 0; i < len; ++i) { 2074 for (uint32_t i = 0; i < len; ++i) {
2113 if (ip_equal(&ip_portlist[i].ip, &ip)) { 2075 if (ip_equal(&ip_portlist[i].ip, &ip)) {
2114 portlist[num] = net_ntohs(ip_portlist[i].port); 2076 portlist[num] = net_ntohs(ip_portlist[i].port);
2115 ++num; 2077 ++num;
@@ -2145,7 +2107,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports,
2145 pinging.port = net_htons(firstport); 2107 pinging.port = net_htons(firstport);
2146 send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key); 2108 send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key);
2147 } else { 2109 } else {
2148 for (i = dht->friends_list[friend_num].nat.punching_index; i != top; ++i) { 2110 for (uint32_t i = dht->friends_list[friend_num].nat.punching_index; i != top; ++i) {
2149 /* TODO(irungentoo): Improve port guessing algorithm. */ 2111 /* TODO(irungentoo): Improve port guessing algorithm. */
2150 uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); 2112 uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1);
2151 IP_Port pinging; 2113 IP_Port pinging;
@@ -2163,7 +2125,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports,
2163 IP_Port pinging; 2125 IP_Port pinging;
2164 ip_copy(&pinging.ip, &ip); 2126 ip_copy(&pinging.ip, &ip);
2165 2127
2166 for (i = dht->friends_list[friend_num].nat.punching_index2; i != top; ++i) { 2128 for (uint32_t i = dht->friends_list[friend_num].nat.punching_index2; i != top; ++i) {
2167 pinging.port = net_htons(port + i); 2129 pinging.port = net_htons(port + i);
2168 send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key); 2130 send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key);
2169 } 2131 }
@@ -2176,10 +2138,9 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports,
2176 2138
2177static void do_NAT(DHT *dht) 2139static void do_NAT(DHT *dht)
2178{ 2140{
2179 uint32_t i;
2180 uint64_t temp_time = unix_time(); 2141 uint64_t temp_time = unix_time();
2181 2142
2182 for (i = 0; i < dht->num_friends; ++i) { 2143 for (uint32_t i = 0; i < dht->num_friends; ++i) {
2183 IP_Port ip_list[MAX_FRIEND_CLIENTS]; 2144 IP_Port ip_list[MAX_FRIEND_CLIENTS];
2184 int num = friend_iplist(dht, ip_list, i); 2145 int num = friend_iplist(dht, ip_list, i);
2185 2146
@@ -2282,9 +2243,7 @@ static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto,
2282/* TODO(irungentoo): improve */ 2243/* TODO(irungentoo): improve */
2283static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, Family sa_family) 2244static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, Family sa_family)
2284{ 2245{
2285 uint32_t i; 2246 for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
2286
2287 for (i = 0; i < LCLIENT_LIST; ++i) {
2288 if (public_key_cmp(dht->close_clientlist[i].public_key, public_key) != 0) { 2247 if (public_key_cmp(dht->close_clientlist[i].public_key, public_key) != 0) {
2289 continue; 2248 continue;
2290 } 2249 }
@@ -2308,9 +2267,8 @@ static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, Fam
2308static uint32_t have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num) 2267static uint32_t have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num)
2309{ 2268{
2310 uint32_t counter = 0; 2269 uint32_t counter = 0;
2311 uint32_t i;
2312 2270
2313 for (i = 0; i < num; ++i) { 2271 for (uint32_t i = 0; i < num; ++i) {
2314 if (id_equal(nodes[i].public_key, dht->self_public_key)) { 2272 if (id_equal(nodes[i].public_key, dht->self_public_key)) {
2315 ++counter; 2273 ++counter;
2316 continue; 2274 continue;
@@ -2414,9 +2372,8 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_
2414static Node_format random_node(DHT *dht, Family sa_family) 2372static Node_format random_node(DHT *dht, Family sa_family)
2415{ 2373{
2416 uint8_t id[CRYPTO_PUBLIC_KEY_SIZE]; 2374 uint8_t id[CRYPTO_PUBLIC_KEY_SIZE];
2417 uint32_t i;
2418 2375
2419 for (i = 0; i < CRYPTO_PUBLIC_KEY_SIZE / 4; ++i) { /* populate the id with pseudorandom bytes.*/ 2376 for (uint32_t i = 0; i < CRYPTO_PUBLIC_KEY_SIZE / 4; ++i) { /* populate the id with pseudorandom bytes.*/
2420 uint32_t t = rand(); 2377 uint32_t t = rand();
2421 memcpy(id + i * sizeof(t), &t, sizeof(t)); 2378 memcpy(id + i * sizeof(t), &t, sizeof(t));
2422 } 2379 }
@@ -2445,9 +2402,7 @@ static uint16_t list_nodes(Client_data *list, unsigned int length, Node_format *
2445 2402
2446 uint16_t count = 0; 2403 uint16_t count = 0;
2447 2404
2448 unsigned int i; 2405 for (size_t i = length; i != 0; --i) {
2449
2450 for (i = length; i != 0; --i) {
2451 IPPTsPng *assoc = NULL; 2406 IPPTsPng *assoc = NULL;
2452 2407
2453 if (!is_timeout(list[i - 1].assoc4.timestamp, BAD_NODE_TIMEOUT)) { 2408 if (!is_timeout(list[i - 1].assoc4.timestamp, BAD_NODE_TIMEOUT)) {
@@ -2487,9 +2442,9 @@ uint16_t randfriends_nodes(DHT *dht, Node_format *nodes, uint16_t max_num)
2487 } 2442 }
2488 2443
2489 uint16_t count = 0; 2444 uint16_t count = 0;
2490 unsigned int i, r = rand(); 2445 unsigned int r = rand();
2491 2446
2492 for (i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) { 2447 for (size_t i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) {
2493 count += list_nodes(dht->friends_list[(i + r) % DHT_FAKE_FRIEND_NUMBER].client_list, MAX_FRIEND_CLIENTS, nodes + count, 2448 count += list_nodes(dht->friends_list[(i + r) % DHT_FAKE_FRIEND_NUMBER].client_list, MAX_FRIEND_CLIENTS, nodes + count,
2494 max_num - count); 2449 max_num - count);
2495 2450
@@ -2513,9 +2468,7 @@ uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num)
2513#if DHT_HARDENING 2468#if DHT_HARDENING
2514static void do_hardening(DHT *dht) 2469static void do_hardening(DHT *dht)
2515{ 2470{
2516 uint32_t i; 2471 for (uint32_t i = 0; i < LCLIENT_LIST * 2; ++i) {
2517
2518 for (i = 0; i < LCLIENT_LIST * 2; ++i) {
2519 IPPTsPng *cur_iptspng; 2472 IPPTsPng *cur_iptspng;
2520 Family sa_family; 2473 Family sa_family;
2521 uint8_t *public_key = dht->close_clientlist[i / 2].public_key; 2474 uint8_t *public_key = dht->close_clientlist[i / 2].public_key;
@@ -2652,9 +2605,8 @@ DHT *new_DHT(Logger *log, Networking_Core *net, bool holepunching_enabled)
2652 2605
2653 ping_array_init(&dht->dht_ping_array, DHT_PING_ARRAY_SIZE, PING_TIMEOUT); 2606 ping_array_init(&dht->dht_ping_array, DHT_PING_ARRAY_SIZE, PING_TIMEOUT);
2654 ping_array_init(&dht->dht_harden_ping_array, DHT_PING_ARRAY_SIZE, PING_TIMEOUT); 2607 ping_array_init(&dht->dht_harden_ping_array, DHT_PING_ARRAY_SIZE, PING_TIMEOUT);
2655 uint32_t i;
2656 2608
2657 for (i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) { 2609 for (uint32_t i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) {
2658 uint8_t random_key_bytes[CRYPTO_PUBLIC_KEY_SIZE]; 2610 uint8_t random_key_bytes[CRYPTO_PUBLIC_KEY_SIZE];
2659 random_bytes(random_key_bytes, sizeof(random_key_bytes)); 2611 random_bytes(random_key_bytes, sizeof(random_key_bytes));
2660 2612
@@ -2715,17 +2667,17 @@ void kill_DHT(DHT *dht)
2715/* Get the size of the DHT (for saving). */ 2667/* Get the size of the DHT (for saving). */
2716uint32_t DHT_size(const DHT *dht) 2668uint32_t DHT_size(const DHT *dht)
2717{ 2669{
2718 uint32_t numv4 = 0, numv6 = 0, i, j; 2670 uint32_t numv4 = 0, numv6 = 0;
2719 2671
2720 for (i = 0; i < LCLIENT_LIST; ++i) { 2672 for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
2721 numv4 += (dht->close_clientlist[i].assoc4.timestamp != 0); 2673 numv4 += (dht->close_clientlist[i].assoc4.timestamp != 0);
2722 numv6 += (dht->close_clientlist[i].assoc6.timestamp != 0); 2674 numv6 += (dht->close_clientlist[i].assoc6.timestamp != 0);
2723 } 2675 }
2724 2676
2725 for (i = 0; i < DHT_FAKE_FRIEND_NUMBER && i < dht->num_friends; ++i) { 2677 for (uint32_t i = 0; i < DHT_FAKE_FRIEND_NUMBER && i < dht->num_friends; ++i) {
2726 DHT_Friend *fr = &dht->friends_list[i]; 2678 DHT_Friend *fr = &dht->friends_list[i];
2727 2679
2728 for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { 2680 for (uint32_t j = 0; j < MAX_FRIEND_CLIENTS; ++j) {
2729 numv4 += (fr->client_list[j].assoc4.timestamp != 0); 2681 numv4 += (fr->client_list[j].assoc4.timestamp != 0);
2730 numv6 += (fr->client_list[j].assoc6.timestamp != 0); 2682 numv6 += (fr->client_list[j].assoc6.timestamp != 0);
2731 } 2683 }
@@ -2752,8 +2704,6 @@ void DHT_save(DHT *dht, uint8_t *data)
2752 host_to_lendian32(data, DHT_STATE_COOKIE_GLOBAL); 2704 host_to_lendian32(data, DHT_STATE_COOKIE_GLOBAL);
2753 data += sizeof(uint32_t); 2705 data += sizeof(uint32_t);
2754 2706
2755 uint32_t num, i, j;
2756
2757 uint8_t *old_data = data; 2707 uint8_t *old_data = data;
2758 2708
2759 /* get right offset. we write the actual header later. */ 2709 /* get right offset. we write the actual header later. */
@@ -2761,7 +2711,9 @@ void DHT_save(DHT *dht, uint8_t *data)
2761 2711
2762 Node_format clients[MAX_SAVED_DHT_NODES]; 2712 Node_format clients[MAX_SAVED_DHT_NODES];
2763 2713
2764 for (num = 0, i = 0; i < LCLIENT_LIST; ++i) { 2714 uint32_t num = 0;
2715
2716 for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
2765 if (dht->close_clientlist[i].assoc4.timestamp != 0) { 2717 if (dht->close_clientlist[i].assoc4.timestamp != 0) {
2766 memcpy(clients[num].public_key, dht->close_clientlist[i].public_key, CRYPTO_PUBLIC_KEY_SIZE); 2718 memcpy(clients[num].public_key, dht->close_clientlist[i].public_key, CRYPTO_PUBLIC_KEY_SIZE);
2767 clients[num].ip_port = dht->close_clientlist[i].assoc4.ip_port; 2719 clients[num].ip_port = dht->close_clientlist[i].assoc4.ip_port;
@@ -2775,10 +2727,10 @@ void DHT_save(DHT *dht, uint8_t *data)
2775 } 2727 }
2776 } 2728 }
2777 2729
2778 for (i = 0; i < DHT_FAKE_FRIEND_NUMBER && i < dht->num_friends; ++i) { 2730 for (uint32_t i = 0; i < DHT_FAKE_FRIEND_NUMBER && i < dht->num_friends; ++i) {
2779 DHT_Friend *fr = &dht->friends_list[i]; 2731 DHT_Friend *fr = &dht->friends_list[i];
2780 2732
2781 for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { 2733 for (uint32_t j = 0; j < MAX_FRIEND_CLIENTS; ++j) {
2782 if (fr->client_list[j].assoc4.timestamp != 0) { 2734 if (fr->client_list[j].assoc4.timestamp != 0) {
2783 memcpy(clients[num].public_key, fr->client_list[j].public_key, CRYPTO_PUBLIC_KEY_SIZE); 2735 memcpy(clients[num].public_key, fr->client_list[j].public_key, CRYPTO_PUBLIC_KEY_SIZE);
2784 clients[num].ip_port = fr->client_list[j].assoc4.ip_port; 2736 clients[num].ip_port = fr->client_list[j].assoc4.ip_port;
@@ -2818,9 +2770,7 @@ int DHT_connect_after_load(DHT *dht)
2818 return 0; 2770 return 0;
2819 } 2771 }
2820 2772
2821 unsigned int i; 2773 for (uint32_t i = 0; i < dht->loaded_num_nodes && i < SAVE_BOOTSTAP_FREQUENCY; ++i) {
2822
2823 for (i = 0; i < dht->loaded_num_nodes && i < SAVE_BOOTSTAP_FREQUENCY; ++i) {
2824 unsigned int index = dht->loaded_nodes_index % dht->loaded_num_nodes; 2774 unsigned int index = dht->loaded_nodes_index % dht->loaded_num_nodes;
2825 DHT_bootstrap(dht, dht->loaded_nodes_list[index].ip_port, dht->loaded_nodes_list[index].public_key); 2775 DHT_bootstrap(dht, dht->loaded_nodes_list[index].ip_port, dht->loaded_nodes_list[index].public_key);
2826 ++dht->loaded_nodes_index; 2776 ++dht->loaded_nodes_index;
@@ -2891,10 +2841,9 @@ int DHT_load(DHT *dht, const uint8_t *data, uint32_t length)
2891 */ 2841 */
2892int DHT_isconnected(const DHT *dht) 2842int DHT_isconnected(const DHT *dht)
2893{ 2843{
2894 uint32_t i;
2895 unix_time_update(); 2844 unix_time_update();
2896 2845
2897 for (i = 0; i < LCLIENT_LIST; ++i) { 2846 for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
2898 const Client_data *client = &dht->close_clientlist[i]; 2847 const Client_data *client = &dht->close_clientlist[i];
2899 2848
2900 if (!is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT) || 2849 if (!is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT) ||
@@ -2911,10 +2860,9 @@ int DHT_isconnected(const DHT *dht)
2911 */ 2860 */
2912int DHT_non_lan_connected(const DHT *dht) 2861int DHT_non_lan_connected(const DHT *dht)
2913{ 2862{
2914 uint32_t i;
2915 unix_time_update(); 2863 unix_time_update();
2916 2864
2917 for (i = 0; i < LCLIENT_LIST; ++i) { 2865 for (uint32_t i = 0; i < LCLIENT_LIST; ++i) {
2918 const Client_data *client = &dht->close_clientlist[i]; 2866 const Client_data *client = &dht->close_clientlist[i];
2919 2867
2920 if (!is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT) && LAN_ip(client->assoc4.ip_port.ip) == -1) { 2868 if (!is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT) && LAN_ip(client->assoc4.ip_port.ip) == -1) {