diff options
author | irungentoo <irungentoo@gmail.com> | 2013-08-20 14:47:32 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-08-20 14:47:32 -0400 |
commit | ac621d96d3139ca09eeebd509d6f6b92380f4f41 (patch) | |
tree | 497a4e5866f0f8d11f98b5e413b24cc650aab1df /core/DHT.c | |
parent | a1c40d753ee8faf15aa0dd314bd4249aa3750b2e (diff) |
Refactor of core done.
Diffstat (limited to 'core/DHT.c')
-rw-r--r-- | core/DHT.c | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -603,7 +603,7 @@ static int handle_sendnodes(void * object, IP_Port source, uint8_t *packet, uint | |||
603 | uint32_t i; | 603 | uint32_t i; |
604 | 604 | ||
605 | for (i = 0; i < num_nodes; ++i) { | 605 | for (i = 0; i < num_nodes; ++i) { |
606 | send_ping_request(nodes_list[i].ip_port, (clientid_t *) &nodes_list[i].client_id); | 606 | send_ping_request(dht->ping, dht->c, nodes_list[i].ip_port, (clientid_t *) &nodes_list[i].client_id); |
607 | returnedip_ports(dht, nodes_list[i].ip_port, nodes_list[i].client_id, packet + 1); | 607 | returnedip_ports(dht, nodes_list[i].ip_port, nodes_list[i].client_id, packet + 1); |
608 | } | 608 | } |
609 | 609 | ||
@@ -709,7 +709,7 @@ static void do_DHT_friends(DHT * dht) | |||
709 | /* if node is not dead. */ | 709 | /* if node is not dead. */ |
710 | if (!is_timeout(temp_time, dht->friends_list[i].client_list[j].timestamp, Kill_NODE_TIMEOUT)) { | 710 | if (!is_timeout(temp_time, dht->friends_list[i].client_list[j].timestamp, Kill_NODE_TIMEOUT)) { |
711 | if ((dht->friends_list[i].client_list[j].last_pinged + PING_INTERVAL) <= temp_time) { | 711 | if ((dht->friends_list[i].client_list[j].last_pinged + PING_INTERVAL) <= temp_time) { |
712 | send_ping_request( dht->friends_list[i].client_list[j].ip_port, | 712 | send_ping_request(dht->ping, dht->c, dht->friends_list[i].client_list[j].ip_port, |
713 | (clientid_t *) &dht->friends_list[i].client_list[j].client_id ); | 713 | (clientid_t *) &dht->friends_list[i].client_list[j].client_id ); |
714 | dht->friends_list[i].client_list[j].last_pinged = temp_time; | 714 | dht->friends_list[i].client_list[j].last_pinged = temp_time; |
715 | } | 715 | } |
@@ -747,7 +747,7 @@ static void do_Close(DHT * dht) | |||
747 | /* if node is not dead. */ | 747 | /* if node is not dead. */ |
748 | if (!is_timeout(temp_time, dht->close_clientlist[i].timestamp, Kill_NODE_TIMEOUT)) { | 748 | if (!is_timeout(temp_time, dht->close_clientlist[i].timestamp, Kill_NODE_TIMEOUT)) { |
749 | if ((dht->close_clientlist[i].last_pinged + PING_INTERVAL) <= temp_time) { | 749 | if ((dht->close_clientlist[i].last_pinged + PING_INTERVAL) <= temp_time) { |
750 | send_ping_request( dht->close_clientlist[i].ip_port, | 750 | send_ping_request(dht->ping, dht->c, dht->close_clientlist[i].ip_port, |
751 | (clientid_t *) &dht->close_clientlist[i].client_id ); | 751 | (clientid_t *) &dht->close_clientlist[i].client_id ); |
752 | dht->close_clientlist[i].last_pinged = temp_time; | 752 | dht->close_clientlist[i].last_pinged = temp_time; |
753 | } | 753 | } |
@@ -772,8 +772,7 @@ static void do_Close(DHT * dht) | |||
772 | void DHT_bootstrap(DHT * dht, IP_Port ip_port, uint8_t *public_key) | 772 | void DHT_bootstrap(DHT * dht, IP_Port ip_port, uint8_t *public_key) |
773 | { | 773 | { |
774 | getnodes(dht, ip_port, public_key, dht->c->self_public_key); | 774 | getnodes(dht, ip_port, public_key, dht->c->self_public_key); |
775 | //send_ping_request(dht, ip_port, (clientid_t *) public_key); | 775 | send_ping_request(dht->ping, dht->c, ip_port, (clientid_t *) public_key); |
776 | send_ping_request(ip_port, (clientid_t *) public_key); | ||
777 | } | 776 | } |
778 | 777 | ||
779 | /* send the given packet to node with client_id | 778 | /* send the given packet to node with client_id |
@@ -1039,8 +1038,7 @@ static void punch_holes(DHT * dht, IP ip, uint16_t *port_list, uint16_t numports | |||
1039 | /*TODO: improve port guessing algorithm*/ | 1038 | /*TODO: improve port guessing algorithm*/ |
1040 | uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); | 1039 | uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); |
1041 | IP_Port pinging = {ip, htons(port)}; | 1040 | IP_Port pinging = {ip, htons(port)}; |
1042 | //send_ping_request(dht, pinging, (clientid_t *) &dht->friends_list[friend_num].client_id); | 1041 | send_ping_request(dht->ping, dht->c, pinging, (clientid_t *) &dht->friends_list[friend_num].client_id); |
1043 | send_ping_request(pinging, (clientid_t *) &dht->friends_list[friend_num].client_id); | ||
1044 | } | 1042 | } |
1045 | 1043 | ||
1046 | dht->friends_list[friend_num].punching_index = i; | 1044 | dht->friends_list[friend_num].punching_index = i; |
@@ -1139,8 +1137,7 @@ static void do_toping(DHT * dht) | |||
1139 | if (dht->toping[i].ip_port.ip.i == 0) | 1137 | if (dht->toping[i].ip_port.ip.i == 0) |
1140 | return; | 1138 | return; |
1141 | 1139 | ||
1142 | //send_ping_request(dht, dht->toping[i].ip_port, (clientid_t *) dht->toping[i].client_id); | 1140 | send_ping_request(dht->ping, dht->c, dht->toping[i].ip_port, (clientid_t *) dht->toping[i].client_id); |
1143 | send_ping_request(dht->toping[i].ip_port, (clientid_t *) dht->toping[i].client_id); | ||
1144 | dht->toping[i].ip_port.ip.i = 0; | 1141 | dht->toping[i].ip_port.ip.i = 0; |
1145 | } | 1142 | } |
1146 | } | 1143 | } |
@@ -1151,13 +1148,17 @@ DHT * new_DHT(Net_Crypto *c) | |||
1151 | DHT * temp = calloc(1, sizeof(DHT)); | 1148 | DHT * temp = calloc(1, sizeof(DHT)); |
1152 | if (temp == NULL) | 1149 | if (temp == NULL) |
1153 | return NULL; | 1150 | return NULL; |
1151 | temp->ping = new_ping(); | ||
1152 | if (temp->ping == NULL){ | ||
1153 | kill_DHT(temp); | ||
1154 | return NULL; | ||
1155 | } | ||
1154 | temp->c = c; | 1156 | temp->c = c; |
1155 | networking_registerhandler(c->lossless_udp->net, 0, &handle_ping_request, temp); | 1157 | networking_registerhandler(c->lossless_udp->net, 0, &handle_ping_request, temp); |
1156 | networking_registerhandler(c->lossless_udp->net, 1, &handle_ping_response, temp); | 1158 | networking_registerhandler(c->lossless_udp->net, 1, &handle_ping_response, temp); |
1157 | networking_registerhandler(c->lossless_udp->net, 2, &handle_getnodes, temp); | 1159 | networking_registerhandler(c->lossless_udp->net, 2, &handle_getnodes, temp); |
1158 | networking_registerhandler(c->lossless_udp->net, 3, &handle_sendnodes, temp); | 1160 | networking_registerhandler(c->lossless_udp->net, 3, &handle_sendnodes, temp); |
1159 | cryptopacket_registerhandler(c, 254, &handle_NATping, temp); | 1161 | cryptopacket_registerhandler(c, 254, &handle_NATping, temp); |
1160 | temp_DHT = temp; | ||
1161 | return temp; | 1162 | return temp; |
1162 | } | 1163 | } |
1163 | 1164 | ||
@@ -1170,6 +1171,7 @@ void do_DHT(DHT * dht) | |||
1170 | } | 1171 | } |
1171 | void kill_DHT(DHT * dht) | 1172 | void kill_DHT(DHT * dht) |
1172 | { | 1173 | { |
1174 | kill_ping(dht->ping); | ||
1173 | free(dht->friends_list); | 1175 | free(dht->friends_list); |
1174 | free(dht); | 1176 | free(dht); |
1175 | } | 1177 | } |
@@ -1193,8 +1195,6 @@ void DHT_save(DHT * dht, uint8_t *data) | |||
1193 | */ | 1195 | */ |
1194 | int DHT_load(DHT * dht, uint8_t *data, uint32_t size) | 1196 | int DHT_load(DHT * dht, uint8_t *data, uint32_t size) |
1195 | { | 1197 | { |
1196 | init_ping(); | ||
1197 | |||
1198 | if (size < sizeof(dht->close_clientlist)) | 1198 | if (size < sizeof(dht->close_clientlist)) |
1199 | return -1; | 1199 | return -1; |
1200 | 1200 | ||