diff options
Diffstat (limited to 'core/DHT.c')
-rw-r--r-- | core/DHT.c | 35 |
1 files changed, 9 insertions, 26 deletions
@@ -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 | ||
557 | static int handle_getnodes(uint8_t * packet, uint32_t length, IP_Port source) | 557 | static 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 | ||
589 | static int handle_sendnodes(uint8_t * packet, uint32_t length, IP_Port source) | 589 | static 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 */ |
933 | static int handle_NATping(uint8_t * packet, uint32_t length, IP_Port source) | 933 | static 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 | ||
1077 | int DHT_handlepacket(uint8_t * packet, uint32_t length, IP_Port source) | 1077 | void 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_response); |
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 | ||
1103 | void doDHT(void) | 1086 | void doDHT(void) |