summaryrefslogtreecommitdiff
path: root/core/DHT.c
diff options
context:
space:
mode:
authorMichael Rose <michael_rose@gmx.de>2013-08-21 10:08:03 +0200
committerMichael Rose <michael_rose@gmx.de>2013-08-21 10:08:03 +0200
commit734b611b3061ce27455c3ab29c19f7e89741d84b (patch)
treedda035bc2bc78d7e82433bb283c41ed735ebf3e7 /core/DHT.c
parent3868a5326c651a8e70039a1184ab0c0a7795dc02 (diff)
more ID extraction
Diffstat (limited to 'core/DHT.c')
-rw-r--r--core/DHT.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/core/DHT.c b/core/DHT.c
index 1817fb2e..60e4704f 100644
--- a/core/DHT.c
+++ b/core/DHT.c
@@ -53,6 +53,9 @@
53/*Ping newly announced nodes to ping per TIME_TOPING seconds*/ 53/*Ping newly announced nodes to ping per TIME_TOPING seconds*/
54#define TIME_TOPING 5 54#define TIME_TOPING 5
55 55
56#define NAT_PING_REQUEST 0
57#define NAT_PING_RESPONSE 1
58
56 59
57Client_data *DHT_get_close_list(DHT *dht) 60Client_data *DHT_get_close_list(DHT *dht)
58{ 61{
@@ -933,7 +936,7 @@ static int send_NATping(DHT *dht, uint8_t *public_key, uint64_t ping_id, uint8_t
933 memcpy(data + 1, &ping_id, sizeof(uint64_t)); 936 memcpy(data + 1, &ping_id, sizeof(uint64_t));
934 /* 254 is NAT ping request packet id */ 937 /* 254 is NAT ping request packet id */
935 int len = create_request(dht->c->self_public_key, dht->c->self_secret_key, packet, public_key, data, 938 int len = create_request(dht->c->self_public_key, dht->c->self_secret_key, packet, public_key, data,
936 sizeof(uint64_t) + 1, 254); 939 sizeof(uint64_t) + 1, CRYPTO_PACKET_NAT_PING);
937 940
938 if (len == -1) 941 if (len == -1)
939 return -1; 942 return -1;
@@ -963,12 +966,12 @@ static int handle_NATping(void *object, IP_Port source, uint8_t *source_pubkey,
963 966
964 DHT_Friend *friend = &dht->friends_list[friendnumber]; 967 DHT_Friend *friend = &dht->friends_list[friendnumber];
965 968
966 if (packet[0] == 0) { 969 if (packet[0] == NAT_PING_REQUEST) {
967 /* 1 is reply */ 970 /* 1 is reply */
968 send_NATping(dht, source_pubkey, ping_id, 1); 971 send_NATping(dht, source_pubkey, ping_id, NAT_PING_RESPONSE);
969 friend->recvNATping_timestamp = unix_time(); 972 friend->recvNATping_timestamp = unix_time();
970 return 0; 973 return 0;
971 } else if (packet[0] == 1) { 974 } else if (packet[0] == NAT_PING_RESPONSE) {
972 if (friend->NATping_id == ping_id) { 975 if (friend->NATping_id == ping_id) {
973 friend->NATping_id = ((uint64_t)random_int() << 32) + random_int(); 976 friend->NATping_id = ((uint64_t)random_int() << 32) + random_int();
974 friend->hole_punching = 1; 977 friend->hole_punching = 1;
@@ -1059,7 +1062,7 @@ static void do_NAT(DHT *dht)
1059 continue; 1062 continue;
1060 1063
1061 if (dht->friends_list[i].NATping_timestamp + PUNCH_INTERVAL < temp_time) { 1064 if (dht->friends_list[i].NATping_timestamp + PUNCH_INTERVAL < temp_time) {
1062 send_NATping(dht, dht->friends_list[i].client_id, dht->friends_list[i].NATping_id, 0); /*0 is request*/ 1065 send_NATping(dht, dht->friends_list[i].client_id, dht->friends_list[i].NATping_id, NAT_PING_REQUEST);
1063 dht->friends_list[i].NATping_timestamp = temp_time; 1066 dht->friends_list[i].NATping_timestamp = temp_time;
1064 } 1067 }
1065 1068
@@ -1166,7 +1169,7 @@ DHT *new_DHT(Net_Crypto *c)
1166 networking_registerhandler(c->lossless_udp->net, NET_PACKET_PING_RESPONSE, &handle_ping_response, temp); 1169 networking_registerhandler(c->lossless_udp->net, NET_PACKET_PING_RESPONSE, &handle_ping_response, temp);
1167 networking_registerhandler(c->lossless_udp->net, NET_PACKET_GET_NODES, &handle_getnodes, temp); 1170 networking_registerhandler(c->lossless_udp->net, NET_PACKET_GET_NODES, &handle_getnodes, temp);
1168 networking_registerhandler(c->lossless_udp->net, NET_PACKET_SEND_NODES, &handle_sendnodes, temp); 1171 networking_registerhandler(c->lossless_udp->net, NET_PACKET_SEND_NODES, &handle_sendnodes, temp);
1169 cryptopacket_registerhandler(c, 254, &handle_NATping, temp); 1172 cryptopacket_registerhandler(c, CRYPTO_PACKET_NAT_PING, &handle_NATping, temp);
1170 return temp; 1173 return temp;
1171} 1174}
1172 1175