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 | |
parent | 6578d930f8b3d4961c33283d1ece981af5c41586 (diff) |
Some speedups and small fixes.
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/onion_client.c | 14 | ||||
-rw-r--r-- | toxcore/ping.c | 16 |
2 files changed, 24 insertions, 6 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index ca3ec560..4a5a37d2 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -286,7 +286,7 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, uint8_t *publ | |||
286 | 286 | ||
287 | list_nodes[index].is_stored = is_stored; | 287 | list_nodes[index].is_stored = is_stored; |
288 | list_nodes[index].timestamp = unix_time(); | 288 | list_nodes[index].timestamp = unix_time(); |
289 | list_nodes[index].last_pinged = unix_time(); | 289 | list_nodes[index].last_pinged = 0; |
290 | list_nodes[index].path_used = set_path_timeouts(onion_c, num, source); | 290 | list_nodes[index].path_used = set_path_timeouts(onion_c, num, source); |
291 | return 0; | 291 | return 0; |
292 | } | 292 | } |
@@ -863,6 +863,11 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) | |||
863 | 863 | ||
864 | ++count; | 864 | ++count; |
865 | 865 | ||
866 | if (list_nodes[i].last_pinged == 0) { | ||
867 | list_nodes[i].last_pinged = unix_time(); | ||
868 | continue; | ||
869 | } | ||
870 | |||
866 | if (is_timeout(list_nodes[i].last_pinged, ANNOUNCE_FRIEND)) { | 871 | if (is_timeout(list_nodes[i].last_pinged, ANNOUNCE_FRIEND)) { |
867 | if (client_send_announce_request(onion_c, friendnum + 1, list_nodes[i].ip_port, list_nodes[i].client_id, 0, ~0) == 0) { | 872 | if (client_send_announce_request(onion_c, friendnum + 1, list_nodes[i].ip_port, list_nodes[i].client_id, 0, ~0) == 0) { |
868 | list_nodes[i].last_pinged = unix_time(); | 873 | list_nodes[i].last_pinged = unix_time(); |
@@ -931,6 +936,13 @@ static void do_announce(Onion_Client *onion_c) | |||
931 | continue; | 936 | continue; |
932 | 937 | ||
933 | ++count; | 938 | ++count; |
939 | |||
940 | /* Don't announce ourselves the first time this is run to new peers */ | ||
941 | if (list_nodes[i].last_pinged == 0) { | ||
942 | list_nodes[i].last_pinged = 1; | ||
943 | continue; | ||
944 | } | ||
945 | |||
934 | uint32_t interval = ANNOUNCE_INTERVAL_NOT_ANNOUNCED; | 946 | uint32_t interval = ANNOUNCE_INTERVAL_NOT_ANNOUNCED; |
935 | 947 | ||
936 | if (list_nodes[i].is_stored) { | 948 | if (list_nodes[i].is_stored) { |
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 | } |