summaryrefslogtreecommitdiff
path: root/core/DHT.c
diff options
context:
space:
mode:
authorslvr <slvr@unsafeio.com>2013-08-10 00:30:18 +0100
committerslvr <slvr@unsafeio.com>2013-08-10 00:43:50 +0100
commit6052b1f119d2b1494a7f2691f4dfed235b560636 (patch)
treeb3f24c586180ba526baf33e3d3814d3c10b8821d /core/DHT.c
parent1ec95162a0b0c4f54bb97ca39684573e73beac87 (diff)
network_registerhandler
Diffstat (limited to 'core/DHT.c')
-rw-r--r--core/DHT.c35
1 files changed, 9 insertions, 26 deletions
diff --git a/core/DHT.c b/core/DHT.c
index 7e3af9d2..2c47d2f1 100644
--- a/core/DHT.c
+++ b/core/DHT.c
@@ -554,7 +554,7 @@ static int sendnodes(IP_Port ip_port, uint8_t * public_key, uint8_t * client_id,
554 return sendpacket(ip_port, data, 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + len); 554 return sendpacket(ip_port, data, 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + len);
555} 555}
556 556
557static int handle_getnodes(uint8_t * packet, uint32_t length, IP_Port source) 557static int handle_getnodes(IP_Port source, uint8_t * packet, uint32_t length)
558{ 558{
559 uint64_t ping_id; 559 uint64_t ping_id;
560 560
@@ -586,7 +586,7 @@ static int handle_getnodes(uint8_t * packet, uint32_t length, IP_Port source)
586 return 0; 586 return 0;
587} 587}
588 588
589static int handle_sendnodes(uint8_t * packet, uint32_t length, IP_Port source) 589static int handle_sendnodes(IP_Port source, uint8_t * packet, uint32_t length)
590{ 590{
591 uint64_t ping_id; 591 uint64_t ping_id;
592 uint32_t cid_size = 1 + CLIENT_ID_SIZE; 592 uint32_t cid_size = 1 + CLIENT_ID_SIZE;
@@ -930,7 +930,7 @@ static int send_NATping(uint8_t * public_key, uint64_t ping_id, uint8_t type)
930} 930}
931 931
932/* Handle a received ping request for */ 932/* Handle a received ping request for */
933static int handle_NATping(uint8_t * packet, uint32_t length, IP_Port source) 933static int handle_NATping(IP_Port source, uint8_t * packet, uint32_t length)
934{ 934{
935 if (length < crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + ENCRYPTION_PADDING 935 if (length < crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + ENCRYPTION_PADDING
936 || length > MAX_DATA_SIZE + ENCRYPTION_PADDING) 936 || length > MAX_DATA_SIZE + ENCRYPTION_PADDING)
@@ -1074,30 +1074,13 @@ static void doNAT(void)
1074/*----------------------------------------------------------------------------------*/ 1074/*----------------------------------------------------------------------------------*/
1075/*-----------------------END OF NAT PUNCHING FUNCTIONS------------------------------*/ 1075/*-----------------------END OF NAT PUNCHING FUNCTIONS------------------------------*/
1076 1076
1077int DHT_handlepacket(uint8_t * packet, uint32_t length, IP_Port source) 1077void DHT_init(void)
1078{ 1078{
1079 switch (packet[0]) { 1079 networking_registerhandler(0, &handle_ping_request);
1080 case 0: 1080 networking_registerhandler(1, &handle_ping_request);
1081 return handle_ping_request(packet, length, source); 1081 networking_registerhandler(2, &handle_getnodes);
1082 1082 networking_registerhandler(3, &handle_sendnodes);
1083 case 1: 1083 networking_registerhandler(254, &handle_NATping);
1084 return handle_ping_response(packet, length, source);
1085
1086 case 2:
1087 return handle_getnodes(packet, length, source);
1088
1089 case 3:
1090 return handle_sendnodes(packet, length, source);
1091
1092 case 254:
1093 return handle_NATping(packet, length, source);
1094
1095 default:
1096 return 1;
1097
1098 }
1099
1100 return 0;
1101} 1084}
1102 1085
1103void doDHT(void) 1086void doDHT(void)