Renamed toping to to_ping.

This commit is contained in:
irungentoo 2014-03-16 13:57:21 -04:00
parent e95494482f
commit f9c9b263e0
4 changed files with 33 additions and 33 deletions

View File

@ -1072,7 +1072,7 @@ static int handle_getnodes(void *object, IP_Port source, uint8_t *packet, uint32
sendnodes_ipv6(dht, source, packet + 1, plain, sendnodes_ipv6(dht, source, packet + 1, plain,
plain + CLIENT_ID_SIZE, shared_key); /* TODO: prevent possible amplification attacks */ plain + CLIENT_ID_SIZE, shared_key); /* TODO: prevent possible amplification attacks */
add_toping(dht->ping, packet + 1, source); add_to_ping(dht->ping, packet + 1, source);
//send_ping_request(dht, source, packet + 1); /* TODO: make this smarter? */ //send_ping_request(dht, source, packet + 1); /* TODO: make this smarter? */
return 0; return 0;
@ -2362,7 +2362,7 @@ void do_DHT(DHT *dht)
do_Close(dht); do_Close(dht);
do_DHT_friends(dht); do_DHT_friends(dht);
do_NAT(dht); do_NAT(dht);
do_toping(dht->ping); do_to_ping(dht->ping);
do_hardening(dht); do_hardening(dht);
#ifdef ENABLE_ASSOC_DHT #ifdef ENABLE_ASSOC_DHT

View File

@ -38,9 +38,6 @@
/* The max number of nodes to send with send nodes. */ /* The max number of nodes to send with send nodes. */
#define MAX_SENT_NODES 8 #define MAX_SENT_NODES 8
/* Maximum newly announced nodes to ping per TIME_TOPING seconds. */
#define MAX_TOPING 16
/* Ping timeout in seconds */ /* Ping timeout in seconds */
#define PING_TIMEOUT 3 #define PING_TIMEOUT 3

View File

@ -37,8 +37,11 @@
#define PING_NUM_MAX 512 #define PING_NUM_MAX 512
/* Ping newly announced nodes to ping per TIME_TOPING seconds*/ /* Maximum newly announced nodes to ping per TIME_TO_PING seconds. */
#define TIME_TOPING 5 #define MAX_TO_PING 16
/* Ping newly announced nodes to ping per TIME_TO_PING seconds*/
#define TIME_TO_PING 5
typedef struct { typedef struct {
IP_Port ip_port; IP_Port ip_port;
@ -54,8 +57,8 @@ struct PING {
size_t num_pings; size_t num_pings;
size_t pos_pings; size_t pos_pings;
Node_format toping[MAX_TOPING]; Node_format to_ping[MAX_TO_PING];
uint64_t last_toping; uint64_t last_to_ping;
}; };
static int is_ping_timeout(uint64_t time) static 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
// Send response // Send response
send_ping_response(ping, source, packet + 1, ping_id, shared_key); send_ping_response(ping, source, packet + 1, ping_id, shared_key);
add_toping(ping, packet + 1, source); add_to_ping(ping, packet + 1, source);
return 0; return 0;
} }
@ -274,8 +277,8 @@ static int handle_ping_response(void *_dht, IP_Port source, uint8_t *packet, uin
} }
/* Add nodes to the toping list. /* Add nodes to the to_ping list.
* All nodes in this list are pinged every TIME_TOPING seconds * All nodes in this list are pinged every TIME_TO_PING seconds
* and are then removed from the list. * and are then removed from the list.
* If the list is full the nodes farthest from our client_id are replaced. * If the list is full the nodes farthest from our client_id are replaced.
* The purpose of this list is to enable quick integration of new nodes into the * 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
* return 0 if node was added. * return 0 if node was added.
* return -1 if node was not added. * return -1 if node was not added.
*/ */
int add_toping(PING *ping, uint8_t *client_id, IP_Port ip_port) int add_to_ping(PING *ping, uint8_t *client_id, IP_Port ip_port)
{ {
if (!ip_isset(&ip_port.ip)) if (!ip_isset(&ip_port.ip))
return -1; return -1;
uint32_t i; uint32_t i;
for (i = 0; i < MAX_TOPING; ++i) { for (i = 0; i < MAX_TO_PING; ++i) {
if (!ip_isset(&ping->toping[i].ip_port.ip)) { if (!ip_isset(&ping->to_ping[i].ip_port.ip)) {
memcpy(ping->toping[i].client_id, client_id, CLIENT_ID_SIZE); memcpy(ping->to_ping[i].client_id, client_id, CLIENT_ID_SIZE);
ipport_copy(&ping->toping[i].ip_port, &ip_port); ipport_copy(&ping->to_ping[i].ip_port, &ip_port);
return 0; return 0;
} }
} }
for (i = 0; i < MAX_TOPING; ++i) { for (i = 0; i < MAX_TO_PING; ++i) {
if (id_closest(ping->dht->self_public_key, ping->toping[i].client_id, client_id) == 2) { if (id_closest(ping->dht->self_public_key, ping->to_ping[i].client_id, client_id) == 2) {
memcpy(ping->toping[i].client_id, client_id, CLIENT_ID_SIZE); memcpy(ping->to_ping[i].client_id, client_id, CLIENT_ID_SIZE);
ipport_copy(&ping->toping[i].ip_port, &ip_port); ipport_copy(&ping->to_ping[i].ip_port, &ip_port);
return 0; return 0;
} }
} }
@ -311,23 +314,23 @@ int add_toping(PING *ping, uint8_t *client_id, IP_Port ip_port)
} }
/* Ping all the valid nodes in the toping list every TIME_TOPING seconds. /* Ping all the valid nodes in the to_ping list every TIME_TO_PING seconds.
* This function must be run at least once every TIME_TOPING seconds. * This function must be run at least once every TIME_TO_PING seconds.
*/ */
void do_toping(PING *ping) void do_to_ping(PING *ping)
{ {
if (!is_timeout(ping->last_toping, TIME_TOPING)) if (!is_timeout(ping->last_to_ping, TIME_TO_PING))
return; return;
ping->last_toping = unix_time(); ping->last_to_ping = unix_time();
uint32_t i; uint32_t i;
for (i = 0; i < MAX_TOPING; ++i) { for (i = 0; i < MAX_TO_PING; ++i) {
if (!ip_isset(&ping->toping[i].ip_port.ip)) if (!ip_isset(&ping->to_ping[i].ip_port.ip))
return; return;
send_ping_request(ping, ping->toping[i].ip_port, ping->toping[i].client_id); send_ping_request(ping, ping->to_ping[i].ip_port, ping->to_ping[i].client_id);
ip_reset(&ping->toping[i].ip_port.ip); ip_reset(&ping->to_ping[i].ip_port.ip);
} }
} }

View File

@ -26,7 +26,7 @@
typedef struct PING PING; typedef struct PING PING;
/* Add nodes to the toping list. /* Add nodes to the to_ping list.
* All nodes in this list are pinged every TIME_TOPING seconds * All nodes in this list are pinged every TIME_TOPING seconds
* and are then removed from the list. * and are then removed from the list.
* If the list is full the nodes farthest from our client_id are replaced. * If the list is full the nodes farthest from our client_id are replaced.
@ -36,8 +36,8 @@ typedef struct PING PING;
* return 0 if node was added. * return 0 if node was added.
* return -1 if node was not added. * return -1 if node was not added.
*/ */
int add_toping(PING *ping, uint8_t *client_id, IP_Port ip_port); int add_to_ping(PING *ping, uint8_t *client_id, IP_Port ip_port);
void do_toping(PING *ping); void do_to_ping(PING *ping);
PING *new_ping(DHT *dht); PING *new_ping(DHT *dht);
void kill_ping(PING *ping); void kill_ping(PING *ping);