diff options
Diffstat (limited to 'toxcore/ping.c')
-rw-r--r-- | toxcore/ping.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/toxcore/ping.c b/toxcore/ping.c index 80e85a45..e3db6ed1 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c | |||
@@ -27,14 +27,16 @@ | |||
27 | #include "config.h" | 27 | #include "config.h" |
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | #include <stdbool.h> | ||
31 | #include <stdint.h> | 30 | #include <stdint.h> |
32 | 31 | ||
33 | #include "net_crypto.h" | ||
34 | #include "DHT.h" | 32 | #include "DHT.h" |
33 | #include "assoc.h" | ||
34 | #include "ping.h" | ||
35 | |||
36 | #include "network.h" | ||
37 | #include "util.h" | ||
35 | 38 | ||
36 | #define PING_NUM_MAX 384 | 39 | #define PING_NUM_MAX 384 |
37 | #define PING_TIMEOUT 5 // 5s | ||
38 | 40 | ||
39 | /* Ping newly announced nodes to ping per TIME_TOPING seconds*/ | 41 | /* Ping newly announced nodes to ping per TIME_TOPING seconds*/ |
40 | #define TIME_TOPING 5 | 42 | #define TIME_TOPING 5 |
@@ -45,7 +47,7 @@ typedef struct { | |||
45 | uint64_t timestamp; | 47 | uint64_t timestamp; |
46 | } pinged_t; | 48 | } pinged_t; |
47 | 49 | ||
48 | typedef struct { | 50 | struct PING { |
49 | Net_Crypto *c; | 51 | Net_Crypto *c; |
50 | 52 | ||
51 | pinged_t pings[PING_NUM_MAX]; | 53 | pinged_t pings[PING_NUM_MAX]; |
@@ -54,15 +56,9 @@ typedef struct { | |||
54 | 56 | ||
55 | Node_format toping[MAX_TOPING]; | 57 | Node_format toping[MAX_TOPING]; |
56 | uint64_t last_toping; | 58 | uint64_t last_toping; |
57 | } PING; | 59 | }; |
58 | |||
59 | #define __PING_C__ | ||
60 | |||
61 | #include "network.h" | ||
62 | #include "util.h" | ||
63 | #include "ping.h" | ||
64 | 60 | ||
65 | static bool is_ping_timeout(uint64_t time) | 61 | static int is_ping_timeout(uint64_t time) |
66 | { | 62 | { |
67 | return is_timeout(time, PING_TIMEOUT); | 63 | return is_timeout(time, PING_TIMEOUT); |
68 | } | 64 | } |
@@ -265,7 +261,16 @@ static int handle_ping_response(void *_dht, IP_Port source, uint8_t *packet, uin | |||
265 | return 1; | 261 | return 1; |
266 | 262 | ||
267 | /* Associate client_id with the ip the request was sent to */ | 263 | /* Associate client_id with the ip the request was sent to */ |
268 | addto_lists(dht, ping->pings[ping_index - 1].ip_port, packet + 1); | 264 | int used = addto_lists(dht, ping->pings[ping_index - 1].ip_port, packet + 1); |
265 | |||
266 | if (dht->assoc) { | ||
267 | IPPTs ippts; | ||
268 | ippts.ip_port = ping->pings[ping_index - 1].ip_port; | ||
269 | ippts.timestamp = ping->pings[ping_index - 1].timestamp; | ||
270 | |||
271 | Assoc_add_entry(dht->assoc, packet + 1, &ippts, &source, used > 0 ? 1 : 0); | ||
272 | } | ||
273 | |||
269 | return 0; | 274 | return 0; |
270 | } | 275 | } |
271 | 276 | ||