diff options
author | irungentoo <irungentoo@gmail.com> | 2014-05-13 12:14:09 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-05-13 12:14:09 -0400 |
commit | a5ff3f8aff43a0f98592eb8b72b0db8671fe4354 (patch) | |
tree | 3d39bdeac4b8cd3b1569193f1fce5161d2930ece /toxcore/ping.c | |
parent | 8d50e4a866731ddccd5fe54420b7a10e12e84327 (diff) |
Nodes already in the DHT closelist should not be added to the toping list.
Diffstat (limited to 'toxcore/ping.c')
-rw-r--r-- | toxcore/ping.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/toxcore/ping.c b/toxcore/ping.c index 52817cd6..2d16e354 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c | |||
@@ -42,7 +42,7 @@ | |||
42 | #define MAX_TO_PING 8 | 42 | #define MAX_TO_PING 8 |
43 | 43 | ||
44 | /* Ping newly announced nodes to ping per TIME_TO_PING seconds*/ | 44 | /* Ping newly announced nodes to ping per TIME_TO_PING seconds*/ |
45 | #define TIME_TO_PING 3 | 45 | #define TIME_TO_PING 8 |
46 | 46 | ||
47 | 47 | ||
48 | struct PING { | 48 | struct PING { |
@@ -201,6 +201,32 @@ static int handle_ping_response(void *_dht, IP_Port source, uint8_t *packet, uin | |||
201 | return 0; | 201 | return 0; |
202 | } | 202 | } |
203 | 203 | ||
204 | /* Check if client_id with ip_port is in the list. | ||
205 | * | ||
206 | * return 1 if it is. | ||
207 | * return 0 if it isn't. | ||
208 | */ | ||
209 | static int in_list(Client_data *list, uint32_t length, uint8_t *client_id, IP_Port ip_port) | ||
210 | { | ||
211 | uint32_t i; | ||
212 | |||
213 | for (i = 0; i < length; ++i) { | ||
214 | if (id_equal(list[i].client_id, client_id)) { | ||
215 | IPPTsPng *ipptp; | ||
216 | |||
217 | if (ip_port.ip.family == AF_INET) { | ||
218 | ipptp = &list[i].assoc4; | ||
219 | } else { | ||
220 | ipptp = &list[i].assoc6; | ||
221 | } | ||
222 | |||
223 | if (!is_timeout(ipptp->timestamp, BAD_NODE_TIMEOUT) && ipport_equal(&ipptp->ip_port, &ip_port)) | ||
224 | return 1; | ||
225 | } | ||
226 | } | ||
227 | |||
228 | return 0; | ||
229 | } | ||
204 | 230 | ||
205 | /* Add nodes to the to_ping list. | 231 | /* Add nodes to the to_ping list. |
206 | * All nodes in this list are pinged every TIME_TO_PING seconds | 232 | * All nodes in this list are pinged every TIME_TO_PING seconds |
@@ -217,6 +243,9 @@ int add_to_ping(PING *ping, uint8_t *client_id, IP_Port ip_port) | |||
217 | if (!ip_isset(&ip_port.ip)) | 243 | if (!ip_isset(&ip_port.ip)) |
218 | return -1; | 244 | return -1; |
219 | 245 | ||
246 | if (in_list(ping->dht->close_clientlist, LCLIENT_LIST, client_id, ip_port)) | ||
247 | return -1; | ||
248 | |||
220 | uint32_t i; | 249 | uint32_t i; |
221 | 250 | ||
222 | for (i = 0; i < MAX_TO_PING; ++i) { | 251 | for (i = 0; i < MAX_TO_PING; ++i) { |