/* * ping.c -- Buffered pinging using cyclic arrays. * * This file is donated to the Tox Project. * Copyright 2013 plutooo */ #include #include #include "DHT.h" #include "net_crypto.h" #include "packets.h" #include "network.h" #include "util.h" #define PING_NUM_MAX 256 #define PING_TIMEOUT 5 // 5s typedef struct { IP_Port ipp; uint64_t id; uint64_t timestamp; } pinged_t; static pinged_t pings[PING_NUM_MAX]; static size_t num_pings; static size_t pos_pings; static clientid_t* self_id = (clientid_t*) &self_public_key; extern uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; // DHT.c void init_ping() { num_pings = 0; pos_pings = 0; } static bool is_timeout(uint64_t time) { return (time + PING_TIMEOUT) < now(); } static void remove_timeouts() { // O(n) size_t i, id; size_t new_pos = pos_pings; size_t new_num = num_pings; // Loop through buffer, oldest first for(i=0; i