diff options
author | irungentoo <irungentoo@gmail.com> | 2014-04-16 13:53:51 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-04-16 13:53:51 -0400 |
commit | de079d7cf78c7cc6888aa604c319a736d01f7326 (patch) | |
tree | b3651a37509ce78eaa3734cf7eb6a57d0a20f3a0 /toxcore/ping.c | |
parent | 6578d930f8b3d4961c33283d1ece981af5c41586 (diff) |
Some speedups and small fixes.
Diffstat (limited to 'toxcore/ping.c')
-rw-r--r-- | toxcore/ping.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/toxcore/ping.c b/toxcore/ping.c index 649d3fff..e43c3b1a 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c | |||
@@ -38,10 +38,10 @@ | |||
38 | #define PING_NUM_MAX 512 | 38 | #define PING_NUM_MAX 512 |
39 | 39 | ||
40 | /* Maximum newly announced nodes to ping per TIME_TO_PING seconds. */ | 40 | /* Maximum newly announced nodes to ping per TIME_TO_PING seconds. */ |
41 | #define MAX_TO_PING 16 | 41 | #define MAX_TO_PING 8 |
42 | 42 | ||
43 | /* Ping newly announced nodes to ping per TIME_TO_PING seconds*/ | 43 | /* Ping newly announced nodes to ping per TIME_TO_PING seconds*/ |
44 | #define TIME_TO_PING 5 | 44 | #define TIME_TO_PING 3 |
45 | 45 | ||
46 | typedef struct { | 46 | typedef struct { |
47 | IP_Port ip_port; | 47 | IP_Port ip_port; |
@@ -300,12 +300,18 @@ int add_to_ping(PING *ping, uint8_t *client_id, IP_Port ip_port) | |||
300 | ipport_copy(&ping->to_ping[i].ip_port, &ip_port); | 300 | ipport_copy(&ping->to_ping[i].ip_port, &ip_port); |
301 | return 0; | 301 | return 0; |
302 | } | 302 | } |
303 | |||
304 | if (memcmp(ping->to_ping[i].client_id, client_id, CLIENT_ID_SIZE) == 0) { | ||
305 | return -1; | ||
306 | } | ||
303 | } | 307 | } |
304 | 308 | ||
309 | uint32_t r = rand(); | ||
310 | |||
305 | for (i = 0; i < MAX_TO_PING; ++i) { | 311 | for (i = 0; i < MAX_TO_PING; ++i) { |
306 | if (id_closest(ping->dht->self_public_key, ping->to_ping[i].client_id, client_id) == 2) { | 312 | if (id_closest(ping->dht->self_public_key, ping->to_ping[(i + r) % MAX_TO_PING].client_id, client_id) == 2) { |
307 | memcpy(ping->to_ping[i].client_id, client_id, CLIENT_ID_SIZE); | 313 | memcpy(ping->to_ping[(i + r) % MAX_TO_PING].client_id, client_id, CLIENT_ID_SIZE); |
308 | ipport_copy(&ping->to_ping[i].ip_port, &ip_port); | 314 | ipport_copy(&ping->to_ping[(i + r) % MAX_TO_PING].ip_port, &ip_port); |
309 | return 0; | 315 | return 0; |
310 | } | 316 | } |
311 | } | 317 | } |