diff options
author | endoffile78 <endoffile78@yahoo.com> | 2016-11-05 15:30:39 -0500 |
---|---|---|
committer | endoffile78 <endoffile78@yahoo.com> | 2016-11-06 09:14:53 -0600 |
commit | 3f53090c1d148da6ede2bbe85a58689c28289e14 (patch) | |
tree | 78bae45122f53a2de2b243e25560ba66bcfbe812 /toxcore/DHT.c | |
parent | 7b6b47a610920e8911a80f4fc261c4b242279cdc (diff) |
Remove assoc
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 105 |
1 files changed, 1 insertions, 104 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index b4ba3fd5..ca9c17ea 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -29,9 +29,6 @@ | |||
29 | 29 | ||
30 | #include "DHT.h" | 30 | #include "DHT.h" |
31 | 31 | ||
32 | #ifdef ENABLE_ASSOC_DHT | ||
33 | #include "assoc.h" | ||
34 | #endif | ||
35 | #include "LAN_discovery.h" | 32 | #include "LAN_discovery.h" |
36 | #include "logger.h" | 33 | #include "logger.h" |
37 | #include "misc_tools.h" | 34 | #include "misc_tools.h" |
@@ -773,60 +770,7 @@ int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *node | |||
773 | uint8_t is_LAN, uint8_t want_good) | 770 | uint8_t is_LAN, uint8_t want_good) |
774 | { | 771 | { |
775 | memset(nodes_list, 0, MAX_SENT_NODES * sizeof(Node_format)); | 772 | memset(nodes_list, 0, MAX_SENT_NODES * sizeof(Node_format)); |
776 | #ifdef ENABLE_ASSOC_DHT | 773 | return get_somewhat_close_nodes(dht, public_key, nodes_list, sa_family, is_LAN, want_good); |
777 | |||
778 | if (!dht->assoc) | ||
779 | #endif | ||
780 | return get_somewhat_close_nodes(dht, public_key, nodes_list, sa_family, is_LAN, want_good); | ||
781 | |||
782 | #ifdef ENABLE_ASSOC_DHT | ||
783 | // TODO(irungentoo): assoc, sa_family 0 (don't care if ipv4 or ipv6) support. | ||
784 | Client_data *result[MAX_SENT_NODES]; | ||
785 | |||
786 | Assoc_close_entries request; | ||
787 | memset(&request, 0, sizeof(request)); | ||
788 | request.count = MAX_SENT_NODES; | ||
789 | request.count_good = MAX_SENT_NODES - 2; /* allow 2 'indirect' nodes */ | ||
790 | request.result = result; | ||
791 | request.wanted_id = public_key; | ||
792 | request.flags = (is_LAN ? LANOk : 0) + (sa_family == AF_INET ? ProtoIPv4 : ProtoIPv6); | ||
793 | |||
794 | uint8_t num_found = Assoc_get_close_entries(dht->assoc, &request); | ||
795 | |||
796 | if (!num_found) { | ||
797 | LOGGER_DEBUG(dht->log, "get_close_nodes(): Assoc_get_close_entries() returned zero nodes"); | ||
798 | return get_somewhat_close_nodes(dht, public_key, nodes_list, sa_family, is_LAN, want_good); | ||
799 | } | ||
800 | |||
801 | LOGGER_DEBUG(dht->log, "get_close_nodes(): Assoc_get_close_entries() returned %i 'direct' and %i 'indirect' nodes", | ||
802 | request.count_good, num_found - request.count_good); | ||
803 | |||
804 | uint8_t i, num_returned = 0; | ||
805 | |||
806 | for (i = 0; i < num_found; i++) { | ||
807 | Client_data *client = result[i]; | ||
808 | |||
809 | if (client) { | ||
810 | id_copy(nodes_list[num_returned].public_key, client->public_key); | ||
811 | |||
812 | if (sa_family == AF_INET) | ||
813 | if (ipport_isset(&client->assoc4.ip_port)) { | ||
814 | nodes_list[num_returned].ip_port = client->assoc4.ip_port; | ||
815 | num_returned++; | ||
816 | continue; | ||
817 | } | ||
818 | |||
819 | if (sa_family == AF_INET6) | ||
820 | if (ipport_isset(&client->assoc6.ip_port)) { | ||
821 | nodes_list[num_returned].ip_port = client->assoc6.ip_port; | ||
822 | num_returned++; | ||
823 | continue; | ||
824 | } | ||
825 | } | ||
826 | } | ||
827 | |||
828 | return num_returned; | ||
829 | #endif | ||
830 | } | 774 | } |
831 | 775 | ||
832 | static uint8_t cmp_public_key[crypto_box_PUBLICKEYBYTES]; | 776 | static uint8_t cmp_public_key[crypto_box_PUBLICKEYBYTES]; |
@@ -1156,18 +1100,6 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key) | |||
1156 | } | 1100 | } |
1157 | } | 1101 | } |
1158 | 1102 | ||
1159 | #ifdef ENABLE_ASSOC_DHT | ||
1160 | |||
1161 | if (dht->assoc) { | ||
1162 | IPPTs ippts; | ||
1163 | |||
1164 | ippts.ip_port = ip_port; | ||
1165 | ippts.timestamp = unix_time(); | ||
1166 | |||
1167 | Assoc_add_entry(dht->assoc, public_key, &ippts, NULL, used ? 1 : 0); | ||
1168 | } | ||
1169 | |||
1170 | #endif | ||
1171 | return used; | 1103 | return used; |
1172 | } | 1104 | } |
1173 | 1105 | ||
@@ -1224,18 +1156,6 @@ static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key | |||
1224 | } | 1156 | } |
1225 | 1157 | ||
1226 | end: | 1158 | end: |
1227 | #ifdef ENABLE_ASSOC_DHT | ||
1228 | |||
1229 | if (dht->assoc) { | ||
1230 | IPPTs ippts; | ||
1231 | ippts.ip_port = ip_port; | ||
1232 | ippts.timestamp = temp_time; | ||
1233 | /* this is only a hear-say entry, so ret-ipp is NULL, but used is required | ||
1234 | * to decide how valuable it is ("used" may throw an "unused" entry out) */ | ||
1235 | Assoc_add_entry(dht->assoc, public_key, &ippts, NULL, used ? 1 : 0); | ||
1236 | } | ||
1237 | |||
1238 | #endif | ||
1239 | return 0; | 1159 | return 0; |
1240 | } | 1160 | } |
1241 | 1161 | ||
@@ -1788,16 +1708,6 @@ void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, con | |||
1788 | 1708 | ||
1789 | void DHT_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key) | 1709 | void DHT_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key) |
1790 | { | 1710 | { |
1791 | /*#ifdef ENABLE_ASSOC_DHT | ||
1792 | if (dht->assoc) { | ||
1793 | IPPTs ippts; | ||
1794 | ippts.ip_port = ip_port; | ||
1795 | ippts.timestamp = 0; | ||
1796 | |||
1797 | Assoc_add_entry(dht->assoc, public_key, &ippts, NULL, 0); | ||
1798 | } | ||
1799 | #endif*/ | ||
1800 | |||
1801 | getnodes(dht, ip_port, public_key, dht->self_public_key, NULL); | 1711 | getnodes(dht, ip_port, public_key, dht->self_public_key, NULL); |
1802 | } | 1712 | } |
1803 | int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled, | 1713 | int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled, |
@@ -2700,9 +2610,6 @@ DHT *new_DHT(Logger *log, Networking_Core *net) | |||
2700 | 2610 | ||
2701 | ping_array_init(&dht->dht_ping_array, DHT_PING_ARRAY_SIZE, PING_TIMEOUT); | 2611 | ping_array_init(&dht->dht_ping_array, DHT_PING_ARRAY_SIZE, PING_TIMEOUT); |
2702 | ping_array_init(&dht->dht_harden_ping_array, DHT_PING_ARRAY_SIZE, PING_TIMEOUT); | 2612 | ping_array_init(&dht->dht_harden_ping_array, DHT_PING_ARRAY_SIZE, PING_TIMEOUT); |
2703 | #ifdef ENABLE_ASSOC_DHT | ||
2704 | dht->assoc = new_Assoc_default(dht->log, dht->self_public_key); | ||
2705 | #endif | ||
2706 | uint32_t i; | 2613 | uint32_t i; |
2707 | 2614 | ||
2708 | for (i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) { | 2615 | for (i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) { |
@@ -2738,20 +2645,10 @@ void do_DHT(DHT *dht) | |||
2738 | #if DHT_HARDENING | 2645 | #if DHT_HARDENING |
2739 | do_hardening(dht); | 2646 | do_hardening(dht); |
2740 | #endif | 2647 | #endif |
2741 | #ifdef ENABLE_ASSOC_DHT | ||
2742 | |||
2743 | if (dht->assoc) { | ||
2744 | do_Assoc(dht->assoc, dht); | ||
2745 | } | ||
2746 | |||
2747 | #endif | ||
2748 | dht->last_run = unix_time(); | 2648 | dht->last_run = unix_time(); |
2749 | } | 2649 | } |
2750 | void kill_DHT(DHT *dht) | 2650 | void kill_DHT(DHT *dht) |
2751 | { | 2651 | { |
2752 | #ifdef ENABLE_ASSOC_DHT | ||
2753 | kill_Assoc(dht->assoc); | ||
2754 | #endif | ||
2755 | networking_registerhandler(dht->net, NET_PACKET_GET_NODES, NULL, NULL); | 2652 | networking_registerhandler(dht->net, NET_PACKET_GET_NODES, NULL, NULL); |
2756 | networking_registerhandler(dht->net, NET_PACKET_SEND_NODES_IPV6, NULL, NULL); | 2653 | networking_registerhandler(dht->net, NET_PACKET_SEND_NODES_IPV6, NULL, NULL); |
2757 | cryptopacket_registerhandler(dht, CRYPTO_PACKET_NAT_PING, NULL, NULL); | 2654 | cryptopacket_registerhandler(dht, CRYPTO_PACKET_NAT_PING, NULL, NULL); |