diff options
author | irungentoo <irungentoo@gmail.com> | 2014-02-24 17:14:47 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-02-24 17:14:47 -0500 |
commit | 718b5e8ca3aa3ef316dc4cfb00edc6999258724e (patch) | |
tree | bbf030fd04098c04b831edd9446abb3407aa9f01 /toxcore | |
parent | 95d0c831a88d243f64c47b739fcc4f428b897ae2 (diff) |
Speeded up DHT peer finding and decreased DHT bandwidth usage.
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/DHT.c | 18 | ||||
-rw-r--r-- | toxcore/DHT.h | 3 |
2 files changed, 14 insertions, 7 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 2b8ec5b5..df067dc5 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -44,7 +44,7 @@ | |||
44 | #define KILL_NODE_TIMEOUT 300 | 44 | #define KILL_NODE_TIMEOUT 300 |
45 | 45 | ||
46 | /* Ping interval in seconds for each random sending of a get nodes request. */ | 46 | /* Ping interval in seconds for each random sending of a get nodes request. */ |
47 | #define GET_NODE_INTERVAL 5 | 47 | #define GET_NODE_INTERVAL 20 |
48 | 48 | ||
49 | #define MAX_PUNCHING_PORTS 48 | 49 | #define MAX_PUNCHING_PORTS 48 |
50 | 50 | ||
@@ -56,6 +56,9 @@ | |||
56 | #define NAT_PING_REQUEST 0 | 56 | #define NAT_PING_REQUEST 0 |
57 | #define NAT_PING_RESPONSE 1 | 57 | #define NAT_PING_RESPONSE 1 |
58 | 58 | ||
59 | /* Number of get node requests to send to quickly find close nodes. */ | ||
60 | #define MAX_BOOTSTRAP_TIMES 10 | ||
61 | |||
59 | /* Used in the comparison function for sorting lists of Client_data. */ | 62 | /* Used in the comparison function for sorting lists of Client_data. */ |
60 | typedef struct { | 63 | typedef struct { |
61 | Client_data c1; | 64 | Client_data c1; |
@@ -1311,7 +1314,7 @@ int DHT_getfriendip(DHT *dht, uint8_t *client_id, IP_Port *ip_port) | |||
1311 | 1314 | ||
1312 | /* returns number of nodes not in kill-timeout */ | 1315 | /* returns number of nodes not in kill-timeout */ |
1313 | static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, uint8_t *client_id, | 1316 | static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, uint8_t *client_id, |
1314 | Client_data *list, uint32_t list_count) | 1317 | Client_data *list, uint32_t list_count, uint32_t *bootstrap_times) |
1315 | { | 1318 | { |
1316 | uint32_t i; | 1319 | uint32_t i; |
1317 | uint8_t not_kill = 0; | 1320 | uint8_t not_kill = 0; |
@@ -1345,11 +1348,12 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, ui | |||
1345 | } | 1348 | } |
1346 | } | 1349 | } |
1347 | 1350 | ||
1348 | if ((num_nodes != 0) && is_timeout(*lastgetnode, GET_NODE_INTERVAL)) { | 1351 | if ((num_nodes != 0) && (is_timeout(*lastgetnode, GET_NODE_INTERVAL) || *bootstrap_times < MAX_BOOTSTRAP_TIMES)) { |
1349 | uint32_t rand_node = rand() % num_nodes; | 1352 | uint32_t rand_node = rand() % num_nodes; |
1350 | getnodes(dht, assoc_list[rand_node]->ip_port, client_list[rand_node]->client_id, | 1353 | getnodes(dht, assoc_list[rand_node]->ip_port, client_list[rand_node]->client_id, |
1351 | client_id, NULL); | 1354 | client_id, NULL); |
1352 | *lastgetnode = temp_time; | 1355 | *lastgetnode = temp_time; |
1356 | ++*bootstrap_times; | ||
1353 | } | 1357 | } |
1354 | 1358 | ||
1355 | return not_kill; | 1359 | return not_kill; |
@@ -1364,7 +1368,7 @@ static void do_DHT_friends(DHT *dht) | |||
1364 | 1368 | ||
1365 | for (i = 0; i < dht->num_friends; ++i) | 1369 | for (i = 0; i < dht->num_friends; ++i) |
1366 | do_ping_and_sendnode_requests(dht, &dht->friends_list[i].lastgetnode, dht->friends_list[i].client_id, | 1370 | do_ping_and_sendnode_requests(dht, &dht->friends_list[i].lastgetnode, dht->friends_list[i].client_id, |
1367 | dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS); | 1371 | dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &dht->friends_list[i].bootstrap_times); |
1368 | } | 1372 | } |
1369 | 1373 | ||
1370 | /* Ping each client in the close nodes list every PING_INTERVAL seconds. | 1374 | /* Ping each client in the close nodes list every PING_INTERVAL seconds. |
@@ -1373,7 +1377,7 @@ static void do_DHT_friends(DHT *dht) | |||
1373 | static void do_Close(DHT *dht) | 1377 | static void do_Close(DHT *dht) |
1374 | { | 1378 | { |
1375 | uint8_t not_killed = do_ping_and_sendnode_requests(dht, &dht->close_lastgetnodes, dht->self_public_key, | 1379 | uint8_t not_killed = do_ping_and_sendnode_requests(dht, &dht->close_lastgetnodes, dht->self_public_key, |
1376 | dht->close_clientlist, LCLIENT_LIST); | 1380 | dht->close_clientlist, LCLIENT_LIST, &dht->close_bootstrap_times); |
1377 | 1381 | ||
1378 | if (!not_killed) { | 1382 | if (!not_killed) { |
1379 | /* all existing nodes are at least KILL_NODE_TIMEOUT, | 1383 | /* all existing nodes are at least KILL_NODE_TIMEOUT, |
@@ -1970,8 +1974,8 @@ static uint32_t have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num) | |||
1970 | } | 1974 | } |
1971 | 1975 | ||
1972 | /* Interval in seconds between hardening checks */ | 1976 | /* Interval in seconds between hardening checks */ |
1973 | #define HARDENING_INTERVAL 20 | 1977 | #define HARDENING_INTERVAL 120 |
1974 | #define HARDEN_TIMEOUT 600 | 1978 | #define HARDEN_TIMEOUT 1200 |
1975 | 1979 | ||
1976 | /* Handle a received hardening packet */ | 1980 | /* Handle a received hardening packet */ |
1977 | static int handle_hardening(void *object, IP_Port source, uint8_t *source_pubkey, uint8_t *packet, uint32_t length) | 1981 | static int handle_hardening(void *object, IP_Port source, uint8_t *source_pubkey, uint8_t *packet, uint32_t length) |
diff --git a/toxcore/DHT.h b/toxcore/DHT.h index b649338a..490d2306 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h | |||
@@ -124,6 +124,8 @@ typedef struct { | |||
124 | 124 | ||
125 | /* Time at which the last get_nodes request was sent. */ | 125 | /* Time at which the last get_nodes request was sent. */ |
126 | uint64_t lastgetnode; | 126 | uint64_t lastgetnode; |
127 | /* number of times get_node packets were sent. */ | ||
128 | uint32_t bootstrap_times; | ||
127 | 129 | ||
128 | /* Symetric NAT hole punching stuff. */ | 130 | /* Symetric NAT hole punching stuff. */ |
129 | NAT nat; | 131 | NAT nat; |
@@ -149,6 +151,7 @@ typedef struct { | |||
149 | 151 | ||
150 | Client_data close_clientlist[LCLIENT_LIST]; | 152 | Client_data close_clientlist[LCLIENT_LIST]; |
151 | uint64_t close_lastgetnodes; | 153 | uint64_t close_lastgetnodes; |
154 | uint32_t close_bootstrap_times; | ||
152 | 155 | ||
153 | /* Note: this key should not be/is not used to transmit any sensitive materials */ | 156 | /* Note: this key should not be/is not used to transmit any sensitive materials */ |
154 | uint8_t secret_symmetric_key[crypto_secretbox_KEYBYTES]; | 157 | uint8_t secret_symmetric_key[crypto_secretbox_KEYBYTES]; |