summaryrefslogtreecommitdiff
path: root/core/DHT.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/DHT.c')
-rw-r--r--core/DHT.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/core/DHT.c b/core/DHT.c
index 924e3216..b2aa44f8 100644
--- a/core/DHT.c
+++ b/core/DHT.c
@@ -544,7 +544,7 @@ static int getnodes(IP_Port ip_port, uint8_t *public_key, uint8_t *client_id)
544 memcpy(data + 1 + CLIENT_ID_SIZE, nonce, crypto_box_NONCEBYTES); 544 memcpy(data + 1 + CLIENT_ID_SIZE, nonce, crypto_box_NONCEBYTES);
545 memcpy(data + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, encrypt, len); 545 memcpy(data + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, encrypt, len);
546 546
547 return sendpacket(ip_port, data, sizeof(data)); 547 return sendpacket(temp_net->sock, ip_port, data, sizeof(data));
548} 548}
549 549
550/* send a send nodes response */ 550/* send a send nodes response */
@@ -586,10 +586,10 @@ static int sendnodes(IP_Port ip_port, uint8_t *public_key, uint8_t *client_id, u
586 memcpy(data + 1 + CLIENT_ID_SIZE, nonce, crypto_box_NONCEBYTES); 586 memcpy(data + 1 + CLIENT_ID_SIZE, nonce, crypto_box_NONCEBYTES);
587 memcpy(data + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, encrypt, len); 587 memcpy(data + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, encrypt, len);
588 588
589 return sendpacket(ip_port, data, 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + len); 589 return sendpacket(temp_net->sock, ip_port, data, 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + len);
590} 590}
591 591
592static int handle_getnodes(IP_Port source, uint8_t *packet, uint32_t length) 592static int handle_getnodes(void * object, IP_Port source, uint8_t *packet, uint32_t length)
593{ 593{
594 uint64_t ping_id; 594 uint64_t ping_id;
595 595
@@ -621,7 +621,7 @@ static int handle_getnodes(IP_Port source, uint8_t *packet, uint32_t length)
621 return 0; 621 return 0;
622} 622}
623 623
624static int handle_sendnodes(IP_Port source, uint8_t *packet, uint32_t length) 624static int handle_sendnodes(void * object, IP_Port source, uint8_t *packet, uint32_t length)
625{ 625{
626 uint64_t ping_id; 626 uint64_t ping_id;
627 uint32_t cid_size = 1 + CLIENT_ID_SIZE; 627 uint32_t cid_size = 1 + CLIENT_ID_SIZE;
@@ -841,7 +841,7 @@ int route_packet(uint8_t *client_id, uint8_t *packet, uint32_t length)
841 841
842 for (i = 0; i < LCLIENT_LIST; ++i) { 842 for (i = 0; i < LCLIENT_LIST; ++i) {
843 if (id_equal(client_id, close_clientlist[i].client_id)) 843 if (id_equal(client_id, close_clientlist[i].client_id))
844 return sendpacket(close_clientlist[i].ip_port, packet, length); 844 return sendpacket(temp_net->sock, close_clientlist[i].ip_port, packet, length);
845 } 845 }
846 846
847 return -1; 847 return -1;
@@ -912,7 +912,7 @@ int route_tofriend(uint8_t *friend_id, uint8_t *packet, uint32_t length)
912 912
913 /*If ip is not zero and node is good */ 913 /*If ip is not zero and node is good */
914 if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) { 914 if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
915 if (sendpacket(client->ip_port, packet, length) == length) 915 if (sendpacket(temp_net->sock, client->ip_port, packet, length) == length)
916 ++sent; 916 ++sent;
917 } 917 }
918 } 918 }
@@ -951,7 +951,7 @@ static int routeone_tofriend(uint8_t *friend_id, uint8_t *packet, uint32_t lengt
951 if (n < 1) 951 if (n < 1)
952 return 0; 952 return 0;
953 953
954 if (sendpacket(ip_list[rand() % n], packet, length) == length) 954 if (sendpacket(temp_net->sock, ip_list[rand() % n], packet, length) == length)
955 return 1; 955 return 1;
956 956
957 return 0; 957 return 0;
@@ -989,7 +989,7 @@ static int send_NATping(uint8_t *public_key, uint64_t ping_id, uint8_t type)
989 data[0] = type; 989 data[0] = type;
990 memcpy(data + 1, &ping_id, sizeof(uint64_t)); 990 memcpy(data + 1, &ping_id, sizeof(uint64_t));
991 /* 254 is NAT ping request packet id */ 991 /* 254 is NAT ping request packet id */
992 int len = create_request(packet, public_key, data, sizeof(uint64_t) + 1, 254); 992 int len = create_request(self_public_key, self_secret_key, packet, public_key, data, sizeof(uint64_t) + 1, 254);
993 993
994 if (len == -1) 994 if (len == -1)
995 return -1; 995 return -1;
@@ -1201,11 +1201,11 @@ static void do_toping()
1201 1201
1202void DHT_init(void) 1202void DHT_init(void)
1203{ 1203{
1204 networking_registerhandler(0, &handle_ping_request); 1204 networking_registerhandler(temp_net, 0, &handle_ping_request, NULL);
1205 networking_registerhandler(1, &handle_ping_response); 1205 networking_registerhandler(temp_net, 1, &handle_ping_response, NULL);
1206 networking_registerhandler(2, &handle_getnodes); 1206 networking_registerhandler(temp_net, 2, &handle_getnodes, NULL);
1207 networking_registerhandler(3, &handle_sendnodes); 1207 networking_registerhandler(temp_net, 3, &handle_sendnodes, NULL);
1208 cryptopacket_registerhandler(254, &handle_NATping); 1208 cryptopacket_registerhandler(temp_net_crypto, 254, &handle_NATping);
1209} 1209}
1210 1210
1211void doDHT(void) 1211void doDHT(void)