diff options
Diffstat (limited to 'core/ping.c')
-rw-r--r-- | core/ping.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/core/ping.c b/core/ping.c index d1cc182f..a687f2fb 100644 --- a/core/ping.c +++ b/core/ping.c | |||
@@ -18,9 +18,9 @@ | |||
18 | #define PING_TIMEOUT 5 // 5s | 18 | #define PING_TIMEOUT 5 // 5s |
19 | 19 | ||
20 | typedef struct { | 20 | typedef struct { |
21 | IP_Port ipp; | 21 | IP_Port ipp; |
22 | uint64_t id; | 22 | uint64_t id; |
23 | uint64_t timestamp; | 23 | uint64_t timestamp; |
24 | } pinged_t; | 24 | } pinged_t; |
25 | 25 | ||
26 | static pinged_t pings[PING_NUM_MAX]; | 26 | static pinged_t pings[PING_NUM_MAX]; |
@@ -30,7 +30,6 @@ static clientid_t* self_id = (clientid_t*) &self_public_key; | |||
30 | 30 | ||
31 | extern uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; // DHT.c | 31 | extern uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; // DHT.c |
32 | 32 | ||
33 | |||
34 | void init_ping() | 33 | void init_ping() |
35 | { | 34 | { |
36 | num_pings = 0; | 35 | num_pings = 0; |
@@ -42,7 +41,7 @@ static bool is_timeout(uint64_t time) | |||
42 | return (time + PING_TIMEOUT) < now(); | 41 | return (time + PING_TIMEOUT) < now(); |
43 | } | 42 | } |
44 | 43 | ||
45 | static void remove_timeouts() // O(n) | 44 | static void remove_timeouts() // O(n) |
46 | { | 45 | { |
47 | size_t i, id; | 46 | size_t i, id; |
48 | size_t new_pos = pos_pings; | 47 | size_t new_pos = pos_pings; |
@@ -62,8 +61,8 @@ static void remove_timeouts() // O(n) | |||
62 | } | 61 | } |
63 | } | 62 | } |
64 | 63 | ||
65 | num_pings = new_num; | 64 | num_pings = new_num; |
66 | pos_pings = new_pos % PING_NUM_MAX; | 65 | pos_pings = new_pos % PING_NUM_MAX; |
67 | } | 66 | } |
68 | 67 | ||
69 | uint64_t add_ping(IP_Port ipp) // O(n) | 68 | uint64_t add_ping(IP_Port ipp) // O(n) |
@@ -89,12 +88,12 @@ uint64_t add_ping(IP_Port ipp) // O(n) | |||
89 | return pings[p].id; | 88 | return pings[p].id; |
90 | } | 89 | } |
91 | 90 | ||
92 | bool is_pinging(IP_Port ipp, uint64_t ping_id) // O(n) | 91 | bool is_pinging(IP_Port ipp, uint64_t ping_id) // O(n) TODO: replace this with something else. |
93 | { | 92 | { |
94 | size_t i, id; | ||
95 | |||
96 | if (ipp.ip.i == 0 && ping_id == 0) | 93 | if (ipp.ip.i == 0 && ping_id == 0) |
97 | return false; | 94 | return false; |
95 | |||
96 | size_t i, id; | ||
98 | 97 | ||
99 | remove_timeouts(); | 98 | remove_timeouts(); |
100 | 99 | ||