summaryrefslogtreecommitdiff
path: root/toxcore/ping.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-03-16 13:57:21 -0400
committerirungentoo <irungentoo@gmail.com>2014-03-16 13:57:21 -0400
commitf9c9b263e0f12a58073b04a28befcfe33f2eb917 (patch)
tree717eea053f70ef6ea6e68b1c365186550121d78b /toxcore/ping.c
parente95494482fa8fc18bc7eda5e681fc0a89544bb3c (diff)
Renamed toping to to_ping.
Diffstat (limited to 'toxcore/ping.c')
-rw-r--r--toxcore/ping.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/toxcore/ping.c b/toxcore/ping.c
index 0aad3f9f..649d3fff 100644
--- a/toxcore/ping.c
+++ b/toxcore/ping.c
@@ -37,8 +37,11 @@
37 37
38#define PING_NUM_MAX 512 38#define PING_NUM_MAX 512
39 39
40/* Ping newly announced nodes to ping per TIME_TOPING seconds*/ 40/* Maximum newly announced nodes to ping per TIME_TO_PING seconds. */
41#define TIME_TOPING 5 41#define MAX_TO_PING 16
42
43/* Ping newly announced nodes to ping per TIME_TO_PING seconds*/
44#define TIME_TO_PING 5
42 45
43typedef struct { 46typedef struct {
44 IP_Port ip_port; 47 IP_Port ip_port;
@@ -54,8 +57,8 @@ struct PING {
54 size_t num_pings; 57 size_t num_pings;
55 size_t pos_pings; 58 size_t pos_pings;
56 59
57 Node_format toping[MAX_TOPING]; 60 Node_format to_ping[MAX_TO_PING];
58 uint64_t last_toping; 61 uint64_t last_to_ping;
59}; 62};
60 63
61static int is_ping_timeout(uint64_t time) 64static int is_ping_timeout(uint64_t time)
@@ -230,7 +233,7 @@ static int handle_ping_request(void *_dht, IP_Port source, uint8_t *packet, uint
230 233
231 // Send response 234 // Send response
232 send_ping_response(ping, source, packet + 1, ping_id, shared_key); 235 send_ping_response(ping, source, packet + 1, ping_id, shared_key);
233 add_toping(ping, packet + 1, source); 236 add_to_ping(ping, packet + 1, source);
234 237
235 return 0; 238 return 0;
236} 239}
@@ -274,8 +277,8 @@ static int handle_ping_response(void *_dht, IP_Port source, uint8_t *packet, uin
274} 277}
275 278
276 279
277/* Add nodes to the toping list. 280/* Add nodes to the to_ping list.
278 * All nodes in this list are pinged every TIME_TOPING seconds 281 * All nodes in this list are pinged every TIME_TO_PING seconds
279 * and are then removed from the list. 282 * and are then removed from the list.
280 * If the list is full the nodes farthest from our client_id are replaced. 283 * If the list is full the nodes farthest from our client_id are replaced.
281 * The purpose of this list is to enable quick integration of new nodes into the 284 * The purpose of this list is to enable quick integration of new nodes into the
@@ -284,25 +287,25 @@ static int handle_ping_response(void *_dht, IP_Port source, uint8_t *packet, uin
284 * return 0 if node was added. 287 * return 0 if node was added.
285 * return -1 if node was not added. 288 * return -1 if node was not added.
286 */ 289 */
287int add_toping(PING *ping, uint8_t *client_id, IP_Port ip_port) 290int add_to_ping(PING *ping, uint8_t *client_id, IP_Port ip_port)
288{ 291{
289 if (!ip_isset(&ip_port.ip)) 292 if (!ip_isset(&ip_port.ip))
290 return -1; 293 return -1;
291 294
292 uint32_t i; 295 uint32_t i;
293 296
294 for (i = 0; i < MAX_TOPING; ++i) { 297 for (i = 0; i < MAX_TO_PING; ++i) {
295 if (!ip_isset(&ping->toping[i].ip_port.ip)) { 298 if (!ip_isset(&ping->to_ping[i].ip_port.ip)) {
296 memcpy(ping->toping[i].client_id, client_id, CLIENT_ID_SIZE); 299 memcpy(ping->to_ping[i].client_id, client_id, CLIENT_ID_SIZE);
297 ipport_copy(&ping->toping[i].ip_port, &ip_port); 300 ipport_copy(&ping->to_ping[i].ip_port, &ip_port);
298 return 0; 301 return 0;
299 } 302 }
300 } 303 }
301 304
302 for (i = 0; i < MAX_TOPING; ++i) { 305 for (i = 0; i < MAX_TO_PING; ++i) {
303 if (id_closest(ping->dht->self_public_key, ping->toping[i].client_id, client_id) == 2) { 306 if (id_closest(ping->dht->self_public_key, ping->to_ping[i].client_id, client_id) == 2) {
304 memcpy(ping->toping[i].client_id, client_id, CLIENT_ID_SIZE); 307 memcpy(ping->to_ping[i].client_id, client_id, CLIENT_ID_SIZE);
305 ipport_copy(&ping->toping[i].ip_port, &ip_port); 308 ipport_copy(&ping->to_ping[i].ip_port, &ip_port);
306 return 0; 309 return 0;
307 } 310 }
308 } 311 }
@@ -311,23 +314,23 @@ int add_toping(PING *ping, uint8_t *client_id, IP_Port ip_port)
311} 314}
312 315
313 316
314/* Ping all the valid nodes in the toping list every TIME_TOPING seconds. 317/* Ping all the valid nodes in the to_ping list every TIME_TO_PING seconds.
315 * This function must be run at least once every TIME_TOPING seconds. 318 * This function must be run at least once every TIME_TO_PING seconds.
316 */ 319 */
317void do_toping(PING *ping) 320void do_to_ping(PING *ping)
318{ 321{
319 if (!is_timeout(ping->last_toping, TIME_TOPING)) 322 if (!is_timeout(ping->last_to_ping, TIME_TO_PING))
320 return; 323 return;
321 324
322 ping->last_toping = unix_time(); 325 ping->last_to_ping = unix_time();
323 uint32_t i; 326 uint32_t i;
324 327
325 for (i = 0; i < MAX_TOPING; ++i) { 328 for (i = 0; i < MAX_TO_PING; ++i) {
326 if (!ip_isset(&ping->toping[i].ip_port.ip)) 329 if (!ip_isset(&ping->to_ping[i].ip_port.ip))
327 return; 330 return;
328 331
329 send_ping_request(ping, ping->toping[i].ip_port, ping->toping[i].client_id); 332 send_ping_request(ping, ping->to_ping[i].ip_port, ping->to_ping[i].client_id);
330 ip_reset(&ping->toping[i].ip_port.ip); 333 ip_reset(&ping->to_ping[i].ip_port.ip);
331 } 334 }
332} 335}
333 336