diff options
author | irungentoo <irungentoo@gmail.com> | 2013-09-14 20:38:48 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-09-14 20:38:48 -0400 |
commit | dde98eb34567a274d444893f8c98868ba9d1fa4b (patch) | |
tree | 065ed2886fb64e11c3513ec6649cd772de395552 /toxcore/DHT.c | |
parent | 20a8fb8a231d158368b8f2db2aab01e443f81b98 (diff) |
DHT peer finding for new friends should now be slightly faster.
Also fixed the "[i] could not send message" bug in nTox.
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 51dd60f2..11f25880 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -808,6 +808,24 @@ static int handle_sendnodes_ipv6(void *object, IP_Port source, uint8_t *packet, | |||
808 | /*----------------------------------------------------------------------------------*/ | 808 | /*----------------------------------------------------------------------------------*/ |
809 | /*------------------------END of packet handling functions--------------------------*/ | 809 | /*------------------------END of packet handling functions--------------------------*/ |
810 | 810 | ||
811 | /* | ||
812 | * Send get nodes requests with client_id to max_num peers in list of length length | ||
813 | */ | ||
814 | static void get_bunchnodes(DHT *dht, Client_data *list, uint16_t length, uint16_t max_num, uint8_t *client_id) | ||
815 | { | ||
816 | uint64_t temp_time = unix_time(); | ||
817 | uint32_t i, num = 0; | ||
818 | |||
819 | for (i = 0; i < length; ++i) | ||
820 | if (ipport_isset(&(list[i].ip_port)) && !is_timeout(temp_time, list[i].ret_timestamp, BAD_NODE_TIMEOUT)) { | ||
821 | getnodes(dht, list[i].ip_port, list[i].client_id, client_id); | ||
822 | ++num; | ||
823 | |||
824 | if (num >= max_num) | ||
825 | return; | ||
826 | } | ||
827 | } | ||
828 | |||
811 | int DHT_addfriend(DHT *dht, uint8_t *client_id) | 829 | int DHT_addfriend(DHT *dht, uint8_t *client_id) |
812 | { | 830 | { |
813 | if (friend_number(dht, client_id) != -1) /* Is friend already in DHT? */ | 831 | if (friend_number(dht, client_id) != -1) /* Is friend already in DHT? */ |
@@ -825,6 +843,7 @@ int DHT_addfriend(DHT *dht, uint8_t *client_id) | |||
825 | 843 | ||
826 | dht->friends_list[dht->num_friends].NATping_id = ((uint64_t)random_int() << 32) + random_int(); | 844 | dht->friends_list[dht->num_friends].NATping_id = ((uint64_t)random_int() << 32) + random_int(); |
827 | ++dht->num_friends; | 845 | ++dht->num_friends; |
846 | get_bunchnodes(dht, dht->close_clientlist, LCLIENT_LIST, MAX_FRIEND_CLIENTS, client_id);/*TODO: make this better?*/ | ||
828 | return 0; | 847 | return 0; |
829 | } | 848 | } |
830 | 849 | ||