diff options
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index f9297225..c8702c45 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -28,7 +28,11 @@ | |||
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | #include "DHT.h" | 30 | #include "DHT.h" |
31 | |||
32 | #ifdef ENABLE_ASSOC_DHT | ||
31 | #include "assoc.h" | 33 | #include "assoc.h" |
34 | #endif | ||
35 | |||
32 | #include "ping.h" | 36 | #include "ping.h" |
33 | 37 | ||
34 | #include "network.h" | 38 | #include "network.h" |
@@ -304,7 +308,7 @@ static void get_close_nodes_inner(DHT *dht, uint8_t *client_id, Node_format *nod | |||
304 | if (LAN_ip(ipptp->ip_port.ip) == 0 && !is_LAN) | 308 | if (LAN_ip(ipptp->ip_port.ip) == 0 && !is_LAN) |
305 | continue; | 309 | continue; |
306 | 310 | ||
307 | if (want_good && hardening_correct(&ipptp->hardening) != HARDENING_ALL_OK && !id_equal(client_id, client->client_id)) | 311 | if (LAN_ip(ipptp->ip_port.ip) != 0 && want_good && hardening_correct(&ipptp->hardening) != HARDENING_ALL_OK && !id_equal(client_id, client->client_id)) |
308 | continue; | 312 | continue; |
309 | 313 | ||
310 | if (num_nodes < MAX_SENT_NODES) { | 314 | if (num_nodes < MAX_SENT_NODES) { |
@@ -366,9 +370,13 @@ static int get_somewhat_close_nodes(DHT *dht, uint8_t *client_id, Node_format *n | |||
366 | int get_close_nodes(DHT *dht, uint8_t *client_id, Node_format *nodes_list, sa_family_t sa_family, uint8_t is_LAN, | 370 | int get_close_nodes(DHT *dht, uint8_t *client_id, Node_format *nodes_list, sa_family_t sa_family, uint8_t is_LAN, |
367 | uint8_t want_good) | 371 | uint8_t want_good) |
368 | { | 372 | { |
373 | #ifdef ENABLE_ASSOC_DHT | ||
374 | |||
369 | if (!dht->assoc) | 375 | if (!dht->assoc) |
376 | #endif | ||
370 | return get_somewhat_close_nodes(dht, client_id, nodes_list, sa_family, is_LAN, want_good); | 377 | return get_somewhat_close_nodes(dht, client_id, nodes_list, sa_family, is_LAN, want_good); |
371 | 378 | ||
379 | #ifdef ENABLE_ASSOC_DHT | ||
372 | Client_data *result[MAX_SENT_NODES]; | 380 | Client_data *result[MAX_SENT_NODES]; |
373 | 381 | ||
374 | Assoc_close_entries request; | 382 | Assoc_close_entries request; |
@@ -420,6 +428,7 @@ int get_close_nodes(DHT *dht, uint8_t *client_id, Node_format *nodes_list, sa_fa | |||
420 | } | 428 | } |
421 | 429 | ||
422 | return num_returned; | 430 | return num_returned; |
431 | #endif | ||
423 | } | 432 | } |
424 | 433 | ||
425 | /* Replace first bad (or empty) node with this one. | 434 | /* Replace first bad (or empty) node with this one. |
@@ -566,7 +575,7 @@ static int replace_good( Client_data *list, | |||
566 | if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) | 575 | if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) |
567 | return 1; | 576 | return 1; |
568 | 577 | ||
569 | sort_list(list, length, comp_client_id); | 578 | //sort_list(list, length, comp_client_id); |
570 | 579 | ||
571 | int8_t replace = -1; | 580 | int8_t replace = -1; |
572 | 581 | ||
@@ -669,6 +678,8 @@ int addto_lists(DHT *dht, IP_Port ip_port, uint8_t *client_id) | |||
669 | used++; | 678 | used++; |
670 | } | 679 | } |
671 | 680 | ||
681 | #ifdef ENABLE_ASSOC_DHT | ||
682 | |||
672 | if (dht->assoc) { | 683 | if (dht->assoc) { |
673 | IPPTs ippts; | 684 | IPPTs ippts; |
674 | 685 | ||
@@ -678,6 +689,7 @@ int addto_lists(DHT *dht, IP_Port ip_port, uint8_t *client_id) | |||
678 | Assoc_add_entry(dht->assoc, client_id, &ippts, NULL, used ? 1 : 0); | 689 | Assoc_add_entry(dht->assoc, client_id, &ippts, NULL, used ? 1 : 0); |
679 | } | 690 | } |
680 | 691 | ||
692 | #endif | ||
681 | return used; | 693 | return used; |
682 | } | 694 | } |
683 | 695 | ||
@@ -734,6 +746,7 @@ static int returnedip_ports(DHT *dht, IP_Port ip_port, uint8_t *client_id, uint8 | |||
734 | } | 746 | } |
735 | 747 | ||
736 | end: | 748 | end: |
749 | #ifdef ENABLE_ASSOC_DHT | ||
737 | 750 | ||
738 | if (dht->assoc) { | 751 | if (dht->assoc) { |
739 | IPPTs ippts; | 752 | IPPTs ippts; |
@@ -744,6 +757,7 @@ end: | |||
744 | Assoc_add_entry(dht->assoc, client_id, &ippts, NULL, used ? 1 : 0); | 757 | Assoc_add_entry(dht->assoc, client_id, &ippts, NULL, used ? 1 : 0); |
745 | } | 758 | } |
746 | 759 | ||
760 | #endif | ||
747 | return 0; | 761 | return 0; |
748 | } | 762 | } |
749 | 763 | ||
@@ -1177,6 +1191,7 @@ int DHT_addfriend(DHT *dht, uint8_t *client_id) | |||
1177 | 1191 | ||
1178 | dht->friends_list[dht->num_friends].nat.NATping_id = random_64b(); | 1192 | dht->friends_list[dht->num_friends].nat.NATping_id = random_64b(); |
1179 | ++dht->num_friends; | 1193 | ++dht->num_friends; |
1194 | #ifdef ENABLE_ASSOC_DHT | ||
1180 | 1195 | ||
1181 | if (dht->assoc) { | 1196 | if (dht->assoc) { |
1182 | /* get up to MAX_FRIEND_CLIENTS connectable nodes */ | 1197 | /* get up to MAX_FRIEND_CLIENTS connectable nodes */ |
@@ -1206,6 +1221,7 @@ int DHT_addfriend(DHT *dht, uint8_t *client_id) | |||
1206 | } | 1221 | } |
1207 | } | 1222 | } |
1208 | 1223 | ||
1224 | #endif | ||
1209 | /*TODO: make this better?*/ | 1225 | /*TODO: make this better?*/ |
1210 | get_bunchnodes(dht, dht->close_clientlist, LCLIENT_LIST, MAX_FRIEND_CLIENTS, client_id); | 1226 | get_bunchnodes(dht, dht->close_clientlist, LCLIENT_LIST, MAX_FRIEND_CLIENTS, client_id); |
1211 | 1227 | ||
@@ -1374,14 +1390,15 @@ void DHT_getnodes(DHT *dht, IP_Port *from_ipp, uint8_t *from_id, uint8_t *which_ | |||
1374 | 1390 | ||
1375 | void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key) | 1391 | void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key) |
1376 | { | 1392 | { |
1377 | /* | 1393 | /*#ifdef ENABLE_ASSOC_DHT |
1378 | if (dht->assoc) { | 1394 | if (dht->assoc) { |
1379 | IPPTs ippts; | 1395 | IPPTs ippts; |
1380 | ippts.ip_port = ip_port; | 1396 | ippts.ip_port = ip_port; |
1381 | ippts.timestamp = 0; | 1397 | ippts.timestamp = 0; |
1382 | 1398 | ||
1383 | Assoc_add_entry(dht->assoc, public_key, &ippts, NULL, 0); | 1399 | Assoc_add_entry(dht->assoc, public_key, &ippts, NULL, 0); |
1384 | }*/ | 1400 | } |
1401 | #endif*/ | ||
1385 | 1402 | ||
1386 | getnodes(dht, ip_port, public_key, dht->self_public_key, NULL); | 1403 | getnodes(dht, ip_port, public_key, dht->self_public_key, NULL); |
1387 | } | 1404 | } |
@@ -2221,8 +2238,9 @@ DHT *new_DHT(Net_Crypto *c) | |||
2221 | 2238 | ||
2222 | new_symmetric_key(dht->secret_symmetric_key); | 2239 | new_symmetric_key(dht->secret_symmetric_key); |
2223 | crypto_box_keypair(dht->self_public_key, dht->self_secret_key); | 2240 | crypto_box_keypair(dht->self_public_key, dht->self_secret_key); |
2241 | #ifdef ENABLE_ASSOC_DHT | ||
2224 | dht->assoc = new_Assoc_default(dht->self_public_key); | 2242 | dht->assoc = new_Assoc_default(dht->self_public_key); |
2225 | 2243 | #endif | |
2226 | return dht; | 2244 | return dht; |
2227 | } | 2245 | } |
2228 | 2246 | ||
@@ -2239,15 +2257,19 @@ void do_DHT(DHT *dht) | |||
2239 | do_NAT(dht); | 2257 | do_NAT(dht); |
2240 | do_toping(dht->ping); | 2258 | do_toping(dht->ping); |
2241 | do_hardening(dht); | 2259 | do_hardening(dht); |
2260 | #ifdef ENABLE_ASSOC_DHT | ||
2242 | 2261 | ||
2243 | if (dht->assoc) | 2262 | if (dht->assoc) |
2244 | do_Assoc(dht->assoc, dht); | 2263 | do_Assoc(dht->assoc, dht); |
2245 | 2264 | ||
2265 | #endif | ||
2246 | dht->last_run = unix_time(); | 2266 | dht->last_run = unix_time(); |
2247 | } | 2267 | } |
2248 | void kill_DHT(DHT *dht) | 2268 | void kill_DHT(DHT *dht) |
2249 | { | 2269 | { |
2270 | #ifdef ENABLE_ASSOC_DHT | ||
2250 | kill_Assoc(dht->assoc); | 2271 | kill_Assoc(dht->assoc); |
2272 | #endif | ||
2251 | kill_ping(dht->ping); | 2273 | kill_ping(dht->ping); |
2252 | free(dht->friends_list); | 2274 | free(dht->friends_list); |
2253 | free(dht); | 2275 | free(dht); |