summaryrefslogtreecommitdiff
path: root/toxcore/ping.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/ping.c')
-rw-r--r--toxcore/ping.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/toxcore/ping.c b/toxcore/ping.c
index bd754c53..9228649e 100644
--- a/toxcore/ping.c
+++ b/toxcore/ping.c
@@ -27,19 +27,24 @@
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 40
41/* 5 seconds */
42#define PING_TIMEOUT 5
38 43
39/* Ping newly announced nodes to ping per TIME_TOPING seconds*/ 44/* Ping newly announced nodes to ping per TIME_TOPING seconds*/
40#define TIME_TOPING 5 45#define TIME_TOPING 5
41 46
42typedef struct { 47typedef struct PING {
43 Net_Crypto *c; 48 Net_Crypto *c;
44 49
45 pinged_t pings[PING_NUM_MAX]; 50 pinged_t pings[PING_NUM_MAX];
@@ -50,13 +55,7 @@ typedef struct {
50 uint64_t last_toping; 55 uint64_t last_toping;
51} PING; 56} PING;
52 57
53#define __PING_C__ 58static int is_ping_timeout(uint64_t time)
54
55#include "network.h"
56#include "util.h"
57#include "ping.h"
58
59static bool is_ping_timeout(uint64_t time)
60{ 59{
61 return is_timeout(time, PING_TIMEOUT); 60 return is_timeout(time, PING_TIMEOUT);
62} 61}
@@ -259,7 +258,16 @@ static int handle_ping_response(void *_dht, IP_Port source, uint8_t *packet, uin
259 return 1; 258 return 1;
260 259
261 /* Associate client_id with the ip the request was sent to */ 260 /* Associate client_id with the ip the request was sent to */
262 addto_lists(dht, ping->pings[ping_index - 1].ip_port, packet + 1); 261 int used = addto_lists(dht, ping->pings[ping_index - 1].ip_port, packet + 1);
262
263 if (dht->assoc) {
264 IPPTs ippts;
265 ippts.ip_port = ping->pings[ping_index - 1].ip_port;
266 ippts.timestamp = ping->pings[ping_index - 1].timestamp;
267
268 Assoc_add_entry(dht->assoc, packet + 1, &ippts, &source, used > 0 ? 1 : 0);
269 }
270
263 return 0; 271 return 0;
264} 272}
265 273