summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
diff options
context:
space:
mode:
authorCoren[m] <Break@Ocean>2013-09-10 16:36:20 +0200
committerCoren[m] <Break@Ocean>2013-09-10 16:36:20 +0200
commitbcb283cf4512f36b189ce2d49eb040c205cbc778 (patch)
treeb0678f9acf245e5620d21c046265a7b3ad98c561 /toxcore/DHT.c
parentbcf251ac3190db4230d42be97b539e4df3af736f (diff)
big push, putting all the infrastructure in place behind TOX_ENABLE_IPV6
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r--toxcore/DHT.c116
1 files changed, 54 insertions, 62 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 4c15c1eb..a4734747 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -115,11 +115,6 @@ static int client_id_cmp(ClientPair p1, ClientPair p2)
115 return c; 115 return c;
116} 116}
117 117
118static int ip4port_equal(IP_Port a, IP_Port b)
119{
120 return (a.ip.uint32 == b.ip.uint32) && (a.port == b.port);
121}
122
123static int id_equal(uint8_t *a, uint8_t *b) 118static int id_equal(uint8_t *a, uint8_t *b)
124{ 119{
125 return memcmp(a, b, CLIENT_ID_SIZE) == 0; 120 return memcmp(a, b, CLIENT_ID_SIZE) == 0;
@@ -144,15 +139,14 @@ static int client_in_list(Client_data *list, uint32_t length, uint8_t *client_id
144 139
145 for (i = 0; i < length; ++i) { 140 for (i = 0; i < length; ++i) {
146 /* If ip_port is assigned to a different client_id replace it */ 141 /* If ip_port is assigned to a different client_id replace it */
147 if (ip4port_equal(list[i].ip_port, ip_port)) { 142 if (ipport_equal(&list[i].ip_port, &ip_port)) {
148 memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE); 143 memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE);
149 } 144 }
150 145
151 if (id_equal(list[i].client_id, client_id)) { 146 if (id_equal(list[i].client_id, client_id)) {
152 /* Refresh the client timestamp. */ 147 /* Refresh the client timestamp. */
153 list[i].timestamp = temp_time; 148 list[i].timestamp = temp_time;
154 list[i].ip_port.ip.uint32 = ip_port.ip.uint32; 149 ipport_copy(&list[i].ip_port, &ip_port);
155 list[i].ip_port.port = ip_port.port;
156 return 1; 150 return 1;
157 } 151 }
158 } 152 }
@@ -216,7 +210,7 @@ static int get_close_nodes(DHT *dht, uint8_t *client_id, Node_format *nodes_list
216 * we COULD send ALL as NET_PACKET_SEND_NODES_EX if we KNEW that the 210 * we COULD send ALL as NET_PACKET_SEND_NODES_EX if we KNEW that the
217 * partner node understands - that's true if *they* are on IPv6 211 * partner node understands - that's true if *they* are on IPv6
218 */ 212 */
219#ifdef NETWORK_IP_PORT_IS_IPV6 213#ifdef TOX_ENABLE_IPV6
220 ipv46x = 0; 214 ipv46x = 0;
221 if (sa_family == AF_INET) 215 if (sa_family == AF_INET)
222 ipv46x = dht->close_clientlist[i].ip_port.ip.family != AF_INET; 216 ipv46x = dht->close_clientlist[i].ip_port.ip.family != AF_INET;
@@ -266,7 +260,7 @@ static int get_close_nodes(DHT *dht, uint8_t *client_id, Node_format *nodes_list
266 MAX_SENT_NODES, 260 MAX_SENT_NODES,
267 dht->friends_list[i].client_list[j].client_id); 261 dht->friends_list[i].client_list[j].client_id);
268 262
269#ifdef NETWORK_IP_PORT_IS_IPV6 263#ifdef TOX_ENABLE_IPV6
270 ipv46x = 0; 264 ipv46x = 0;
271 if (sa_family == AF_INET) 265 if (sa_family == AF_INET)
272 ipv46x = dht->friends_list[i].client_list[j].ip_port.ip.family != AF_INET; 266 ipv46x = dht->friends_list[i].client_list[j].ip_port.ip.family != AF_INET;
@@ -330,7 +324,7 @@ static int replace_bad( Client_data *list,
330 memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE); 324 memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE);
331 list[i].ip_port = ip_port; 325 list[i].ip_port = ip_port;
332 list[i].timestamp = temp_time; 326 list[i].timestamp = temp_time;
333 list[i].ret_ip_port.ip.uint32 = 0; 327 ip_reset(&list[i].ret_ip_port.ip);
334 list[i].ret_ip_port.port = 0; 328 list[i].ret_ip_port.port = 0;
335 list[i].ret_timestamp = 0; 329 list[i].ret_timestamp = 0;
336 return 0; 330 return 0;
@@ -378,7 +372,7 @@ static int replace_good( Client_data *list,
378 memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE); 372 memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE);
379 list[i].ip_port = ip_port; 373 list[i].ip_port = ip_port;
380 list[i].timestamp = temp_time; 374 list[i].timestamp = temp_time;
381 list[i].ret_ip_port.ip.uint32 = 0; 375 ip_reset(&list[i].ret_ip_port.ip);
382 list[i].ret_ip_port.port = 0; 376 list[i].ret_ip_port.port = 0;
383 list[i].ret_timestamp = 0; 377 list[i].ret_timestamp = 0;
384 return 0; 378 return 0;
@@ -476,13 +470,13 @@ static int is_gettingnodes(DHT *dht, IP_Port ip_port, uint64_t ping_id)
476 if (!is_timeout(temp_time, dht->send_nodes[i].timestamp, PING_TIMEOUT)) { 470 if (!is_timeout(temp_time, dht->send_nodes[i].timestamp, PING_TIMEOUT)) {
477 pinging = 0; 471 pinging = 0;
478 472
479 if (ip_port.ip.uint32 != 0 && ip4port_equal(dht->send_nodes[i].ip_port, ip_port)) 473 if (ping_id != 0 && dht->send_nodes[i].ping_id == ping_id)
480 ++pinging; 474 ++pinging;
481 475
482 if (ping_id != 0 && dht->send_nodes[i].ping_id == ping_id) 476 if (ip_isset(&ip_port.ip) && ipport_equal(&dht->send_nodes[i].ip_port, &ip_port))
483 ++pinging; 477 ++pinging;
484 478
485 if (pinging == (ping_id != 0) + (ip_port.ip.uint32 != 0)) 479 if (pinging == (ping_id != 0) + (ip_isset(&ip_port.ip) != 0))
486 return 1; 480 return 1;
487 } 481 }
488 } 482 }
@@ -575,11 +569,11 @@ static int sendnodes(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_t *cl
575 random_nonce(nonce); 569 random_nonce(nonce);
576 570
577 memcpy(plain, &ping_id, sizeof(ping_id)); 571 memcpy(plain, &ping_id, sizeof(ping_id));
578#if DHT_NODEFORMAT == 46 572#ifdef TOX_ENABLE_IPV6
579 Node4_format *nodes4_list = &(plain + sizeof(ping_id)); 573 Node4_format *nodes4_list = (Node4_format *)(plain + sizeof(ping_id));
580 int i, num_nodes_ok = 0; 574 int i, num_nodes_ok = 0;
581 for(i = 0; i < num_nodes, i++) 575 for(i = 0; i < num_nodes; i++)
582 if (nodes_list[i].ip.family == AF_INET) { 576 if (nodes_list[i].ip_port.ip.family == AF_INET) {
583 memcpy(nodes4_list[num_nodes_ok].client_id, nodes_list[i].client_id, CLIENT_ID_SIZE); 577 memcpy(nodes4_list[num_nodes_ok].client_id, nodes_list[i].client_id, CLIENT_ID_SIZE);
584 nodes4_list[num_nodes_ok].ip_port.ip.uint32 = nodes_list[i].ip_port.ip.ip4.uint32; 578 nodes4_list[num_nodes_ok].ip_port.ip.uint32 = nodes_list[i].ip_port.ip.ip4.uint32;
585 nodes4_list[num_nodes_ok].ip_port.port = nodes_list[i].ip_port.port; 579 nodes4_list[num_nodes_ok].ip_port.port = nodes_list[i].ip_port.port;
@@ -680,14 +674,15 @@ static int handle_sendnodes(void *object, IP_Port source, uint8_t *packet, uint3
680 if (!is_gettingnodes(dht, source, ping_id)) 674 if (!is_gettingnodes(dht, source, ping_id))
681 return 1; 675 return 1;
682 676
677 uint32_t i;
683 Node_format nodes_list[MAX_SENT_NODES]; 678 Node_format nodes_list[MAX_SENT_NODES];
684 679
685#if DHT_NODEFORMAT == 46 680#ifdef TOX_ENABLE_IPV6
686 Node4_format *nodes4_list = &(plain + sizeof(ping_id)); 681 Node4_format *nodes4_list = (Node4_format *)(plain + sizeof(ping_id));
687 682
688 int i, num_nodes_ok = 0; 683 int num_nodes_ok = 0;
689 for(i = 0; i < num_nodes, i++) 684 for(i = 0; i < num_nodes; i++)
690 if ((nodes_list[i].ip != 0) && (nodes_list[i].ip != ~0)) { 685 if ((nodes4_list[i].ip_port.ip.uint32 != 0) && (nodes4_list[i].ip_port.ip.uint32 != ~0)) {
691 memcpy(nodes_list[num_nodes_ok].client_id, nodes4_list[i].client_id, CLIENT_ID_SIZE); 686 memcpy(nodes_list[num_nodes_ok].client_id, nodes4_list[i].client_id, CLIENT_ID_SIZE);
692 nodes_list[num_nodes_ok].ip_port.ip.family = AF_INET; 687 nodes_list[num_nodes_ok].ip_port.ip.family = AF_INET;
693 nodes_list[num_nodes_ok].ip_port.ip.ip4.uint32 = nodes4_list[i].ip_port.ip.uint32; 688 nodes_list[num_nodes_ok].ip_port.ip.ip4.uint32 = nodes4_list[i].ip_port.ip.uint32;
@@ -706,8 +701,6 @@ static int handle_sendnodes(void *object, IP_Port source, uint8_t *packet, uint3
706 701
707 addto_lists(dht, source, packet + 1); 702 addto_lists(dht, source, packet + 1);
708 703
709 uint32_t i;
710
711 for (i = 0; i < num_nodes; ++i) { 704 for (i = 0; i < num_nodes; ++i) {
712 send_ping_request(dht->ping, dht->c, nodes_list[i].ip_port, nodes_list[i].client_id); 705 send_ping_request(dht->ping, dht->c, nodes_list[i].ip_port, nodes_list[i].client_id);
713 returnedip_ports(dht, nodes_list[i].ip_port, nodes_list[i].client_id, packet + 1); 706 returnedip_ports(dht, nodes_list[i].ip_port, nodes_list[i].client_id, packet + 1);
@@ -775,27 +768,30 @@ int DHT_delfriend(DHT *dht, uint8_t *client_id)
775} 768}
776 769
777/* TODO: Optimize this. */ 770/* TODO: Optimize this. */
778IP_Port DHT_getfriendip(DHT *dht, uint8_t *client_id) 771int DHT_getfriendip(DHT *dht, uint8_t *client_id, IP_Port *ip_port)
779{ 772{
780 uint32_t i, j; 773 uint32_t i, j;
781 uint64_t temp_time = unix_time(); 774 uint64_t temp_time = unix_time();
782 IP_Port empty = {{{{0}}, 0, 0}}; 775
776 ip_reset(&ip_port->ip);
777 ip_port->port = 0;
783 778
784 for (i = 0; i < dht->num_friends; ++i) { 779 for (i = 0; i < dht->num_friends; ++i) {
785 /* Equal */ 780 /* Equal */
786 if (id_equal(dht->friends_list[i].client_id, client_id)) { 781 if (id_equal(dht->friends_list[i].client_id, client_id)) {
787 for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) { 782 for (j = 0; j < MAX_FRIEND_CLIENTS; ++j) {
788 if (id_equal(dht->friends_list[i].client_list[j].client_id, client_id) 783 if (id_equal(dht->friends_list[i].client_list[j].client_id, client_id)
789 && !is_timeout(temp_time, dht->friends_list[i].client_list[j].timestamp, BAD_NODE_TIMEOUT)) 784 && !is_timeout(temp_time, dht->friends_list[i].client_list[j].timestamp, BAD_NODE_TIMEOUT)) {
790 return dht->friends_list[i].client_list[j].ip_port; 785 *ip_port = dht->friends_list[i].client_list[j].ip_port;
786 return 1;
787 }
791 } 788 }
792 789
793 return empty; 790 return 0;
794 } 791 }
795 } 792 }
796 793
797 empty.ip.uint32 = 1; 794 return -1;
798 return empty;
799} 795}
800 796
801/* Ping each client in the "friends" list every PING_INTERVAL seconds. Send a get nodes request 797/* Ping each client in the "friends" list every PING_INTERVAL seconds. Send a get nodes request
@@ -880,16 +876,12 @@ void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key)
880 getnodes(dht, ip_port, public_key, dht->c->self_public_key); 876 getnodes(dht, ip_port, public_key, dht->c->self_public_key);
881 send_ping_request(dht->ping, dht->c, ip_port, public_key); 877 send_ping_request(dht->ping, dht->c, ip_port, public_key);
882} 878}
883void DHT_bootstrap_ex(DHT *dht, const char *address, uint16_t port, uint8_t *public_key) 879void DHT_bootstrap_ex(DHT *dht, const char *address, uint8_t ipv6enabled, uint16_t port, uint8_t *public_key)
884{ 880{
885 IPAny_Port ipany_port; 881 IP_Port ip_port;
886 ipany_port.ip.family = AF_INET; 882 ip_init(&ip_port.ip, ipv6enabled);
887 if (addr_resolve_or_parse_ip(address, &ipany_port.ip)) { 883 if (addr_resolve_or_parse_ip(address, &ip_port.ip)) {
888 /* IPAny temporary: copy down */
889 IP_Port ip_port;
890 ip_port.ip.uint32 = ipany_port.ip.ip4.uint32;
891 ip_port.port = port; 884 ip_port.port = port;
892
893 DHT_bootstrap(dht, ip_port, public_key); 885 DHT_bootstrap(dht, ip_port, public_key);
894 } 886 }
895} 887}
@@ -933,7 +925,7 @@ static int friend_iplist(DHT *dht, IP_Port *ip_portlist, uint16_t friend_num)
933 client = &friend->client_list[i]; 925 client = &friend->client_list[i];
934 926
935 /* If ip is not zero and node is good. */ 927 /* If ip is not zero and node is good. */
936 if (client->ret_ip_port.ip.uint32 != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) { 928 if (ip_isset(&client->ret_ip_port.ip) && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
937 929
938 if (id_equal(client->client_id, friend->client_id)) 930 if (id_equal(client->client_id, friend->client_id))
939 return 0; 931 return 0;
@@ -975,7 +967,7 @@ int route_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint32_t lengt
975 client = &friend->client_list[i]; 967 client = &friend->client_list[i];
976 968
977 /* If ip is not zero and node is good. */ 969 /* If ip is not zero and node is good. */
978 if (client->ret_ip_port.ip.uint32 != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) { 970 if (ip_isset(&client->ret_ip_port.ip) && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
979 int retval = sendpacket(dht->c->lossless_udp->net, client->ip_port, packet, length); 971 int retval = sendpacket(dht->c->lossless_udp->net, client->ip_port, packet, length);
980 972
981 if ((unsigned int)retval == length) 973 if ((unsigned int)retval == length)
@@ -1009,7 +1001,7 @@ static int routeone_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint
1009 client = &friend->client_list[i]; 1001 client = &friend->client_list[i];
1010 1002
1011 /* If ip is not zero and node is good. */ 1003 /* If ip is not zero and node is good. */
1012 if (client->ret_ip_port.ip.uint32 != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) { 1004 if (ip_isset(&client->ret_ip_port.ip) && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
1013 ip_list[n] = client->ip_port; 1005 ip_list[n] = client->ip_port;
1014 ++n; 1006 ++n;
1015 } 1007 }
@@ -1115,9 +1107,10 @@ static int handle_NATping(void *object, IP_Port source, uint8_t *source_pubkey,
1115 * 1107 *
1116 * return ip of 0 if failure. 1108 * return ip of 0 if failure.
1117 */ 1109 */
1118static IP4 NAT_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num) 1110static IP NAT_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
1119{ 1111{
1120 IP4 zero = {{0}}; 1112 IP zero;
1113 ip_reset(&zero);
1121 1114
1122 if (len > MAX_FRIEND_CLIENTS) 1115 if (len > MAX_FRIEND_CLIENTS)
1123 return zero; 1116 return zero;
@@ -1127,7 +1120,7 @@ static IP4 NAT_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
1127 1120
1128 for (i = 0; i < len; ++i) { 1121 for (i = 0; i < len; ++i) {
1129 for (j = 0; j < len; ++j) { 1122 for (j = 0; j < len; ++j) {
1130 if (ip_portlist[i].ip.uint32 == ip_portlist[j].ip.uint32) 1123 if (ip_equal(&ip_portlist[i].ip, &ip_portlist[j].ip))
1131 ++numbers[i]; 1124 ++numbers[i];
1132 } 1125 }
1133 1126
@@ -1144,13 +1137,13 @@ static IP4 NAT_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
1144 * 1137 *
1145 * return number of ports and puts the list of ports in portlist. 1138 * return number of ports and puts the list of ports in portlist.
1146 */ 1139 */
1147static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t len, IP4 ip) 1140static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t len, IP ip)
1148{ 1141{
1149 uint32_t i; 1142 uint32_t i;
1150 uint16_t num = 0; 1143 uint16_t num = 0;
1151 1144
1152 for (i = 0; i < len; ++i) { 1145 for (i = 0; i < len; ++i) {
1153 if (ip_portlist[i].ip.uint32 == ip.uint32) { 1146 if (ip_equal(&ip_portlist[i].ip, &ip)) {
1154 portlist[num] = ntohs(ip_portlist[i].port); 1147 portlist[num] = ntohs(ip_portlist[i].port);
1155 ++num; 1148 ++num;
1156 } 1149 }
@@ -1159,7 +1152,7 @@ static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t
1159 return num; 1152 return num;
1160} 1153}
1161 1154
1162static void punch_holes(DHT *dht, IP4 ip, uint16_t *port_list, uint16_t numports, uint16_t friend_num) 1155static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, uint16_t friend_num)
1163{ 1156{
1164 if (numports > MAX_FRIEND_CLIENTS || numports == 0) 1157 if (numports > MAX_FRIEND_CLIENTS || numports == 0)
1165 return; 1158 return;
@@ -1170,7 +1163,9 @@ static void punch_holes(DHT *dht, IP4 ip, uint16_t *port_list, uint16_t numports
1170 for (i = dht->friends_list[friend_num].punching_index; i != top; i++) { 1163 for (i = dht->friends_list[friend_num].punching_index; i != top; i++) {
1171 /* TODO: Improve port guessing algorithm. */ 1164 /* TODO: Improve port guessing algorithm. */
1172 uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); 1165 uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1);
1173 IP_Port pinging = {{ip, htons(port), 0}}; 1166 IP_Port pinging;
1167 ip_copy(&pinging.ip, &ip);
1168 pinging.port = htons(port);
1174 send_ping_request(dht->ping, dht->c, pinging, dht->friends_list[friend_num].client_id); 1169 send_ping_request(dht->ping, dht->c, pinging, dht->friends_list[friend_num].client_id);
1175 } 1170 }
1176 1171
@@ -1199,9 +1194,8 @@ static void do_NAT(DHT *dht)
1199 dht->friends_list[i].punching_timestamp + PUNCH_INTERVAL < temp_time && 1194 dht->friends_list[i].punching_timestamp + PUNCH_INTERVAL < temp_time &&
1200 dht->friends_list[i].recvNATping_timestamp + PUNCH_INTERVAL * 2 >= temp_time) { 1195 dht->friends_list[i].recvNATping_timestamp + PUNCH_INTERVAL * 2 >= temp_time) {
1201 1196
1202 IP4 ip = NAT_commonip(ip_list, num, MAX_FRIEND_CLIENTS / 2); 1197 IP ip = NAT_commonip(ip_list, num, MAX_FRIEND_CLIENTS / 2);
1203 1198 if (!ip_isset(&ip))
1204 if (ip.uint32 == 0)
1205 continue; 1199 continue;
1206 1200
1207 uint16_t port_list[MAX_FRIEND_CLIENTS]; 1201 uint16_t port_list[MAX_FRIEND_CLIENTS];
@@ -1230,16 +1224,15 @@ static void do_NAT(DHT *dht)
1230 */ 1224 */
1231int add_toping(DHT *dht, uint8_t *client_id, IP_Port ip_port) 1225int add_toping(DHT *dht, uint8_t *client_id, IP_Port ip_port)
1232{ 1226{
1233 if (ip_port.ip.uint32 == 0) 1227 if (!ip_isset(&ip_port.ip))
1234 return -1; 1228 return -1;
1235 1229
1236 uint32_t i; 1230 uint32_t i;
1237 1231
1238 for (i = 0; i < MAX_TOPING; ++i) { 1232 for (i = 0; i < MAX_TOPING; ++i) {
1239 if (dht->toping[i].ip_port.ip.uint32 == 0) { 1233 if (!ip_isset(&dht->toping[i].ip_port.ip)) {
1240 memcpy(dht->toping[i].client_id, client_id, CLIENT_ID_SIZE); 1234 memcpy(dht->toping[i].client_id, client_id, CLIENT_ID_SIZE);
1241 dht->toping[i].ip_port.ip.uint32 = ip_port.ip.uint32; 1235 ipport_copy(&dht->toping[i].ip_port, &ip_port);
1242 dht->toping[i].ip_port.port = ip_port.port;
1243 return 0; 1236 return 0;
1244 } 1237 }
1245 } 1238 }
@@ -1247,8 +1240,7 @@ int add_toping(DHT *dht, uint8_t *client_id, IP_Port ip_port)
1247 for (i = 0; i < MAX_TOPING; ++i) { 1240 for (i = 0; i < MAX_TOPING; ++i) {
1248 if (id_closest(dht->c->self_public_key, dht->toping[i].client_id, client_id) == 2) { 1241 if (id_closest(dht->c->self_public_key, dht->toping[i].client_id, client_id) == 2) {
1249 memcpy(dht->toping[i].client_id, client_id, CLIENT_ID_SIZE); 1242 memcpy(dht->toping[i].client_id, client_id, CLIENT_ID_SIZE);
1250 dht->toping[i].ip_port.ip.uint32 = ip_port.ip.uint32; 1243 ipport_copy(&dht->toping[i].ip_port, &ip_port);
1251 dht->toping[i].ip_port.port = ip_port.port;
1252 return 0; 1244 return 0;
1253 } 1245 }
1254 } 1246 }
@@ -1270,11 +1262,11 @@ static void do_toping(DHT *dht)
1270 uint32_t i; 1262 uint32_t i;
1271 1263
1272 for (i = 0; i < MAX_TOPING; ++i) { 1264 for (i = 0; i < MAX_TOPING; ++i) {
1273 if (dht->toping[i].ip_port.ip.uint32 == 0) 1265 if (!ip_isset(&dht->toping[i].ip_port.ip))
1274 return; 1266 return;
1275 1267
1276 send_ping_request(dht->ping, dht->c, dht->toping[i].ip_port, dht->toping[i].client_id); 1268 send_ping_request(dht->ping, dht->c, dht->toping[i].ip_port, dht->toping[i].client_id);
1277 dht->toping[i].ip_port.ip.uint32 = 0; 1269 ip_reset(&dht->toping[i].ip_port.ip);
1278 } 1270 }
1279} 1271}
1280 1272