Skip to content

Commit

Permalink
Nodes already in the DHT closelist should not be added to the toping …
Browse files Browse the repository at this point in the history
…list.
  • Loading branch information
irungentoo committed May 13, 2014
1 parent 8d50e4a commit a5ff3f8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ static int client_or_ip_port_in_list(Client_data *list, uint32_t length, uint8_t
/* Check if client with client_id is already in node format list of length length.
*
* return 1 if true.
* return 2 if false.
* return 0 if false.
*/
static int client_in_nodelist(Node_format *list, uint32_t length, uint8_t *client_id)
{
Expand Down
31 changes: 30 additions & 1 deletion toxcore/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#define MAX_TO_PING 8

/* Ping newly announced nodes to ping per TIME_TO_PING seconds*/
#define TIME_TO_PING 3
#define TIME_TO_PING 8


struct PING {
Expand Down Expand Up @@ -201,6 +201,32 @@ static int handle_ping_response(void *_dht, IP_Port source, uint8_t *packet, uin
return 0;
}

/* Check if client_id with ip_port is in the list.
*
* return 1 if it is.
* return 0 if it isn't.
*/
static int in_list(Client_data *list, uint32_t length, uint8_t *client_id, IP_Port ip_port)
{
uint32_t i;

for (i = 0; i < length; ++i) {
if (id_equal(list[i].client_id, client_id)) {
IPPTsPng *ipptp;

if (ip_port.ip.family == AF_INET) {
ipptp = &list[i].assoc4;
} else {
ipptp = &list[i].assoc6;
}

if (!is_timeout(ipptp->timestamp, BAD_NODE_TIMEOUT) && ipport_equal(&ipptp->ip_port, &ip_port))
return 1;
}
}

return 0;
}

/* Add nodes to the to_ping list.
* All nodes in this list are pinged every TIME_TO_PING seconds
Expand All @@ -217,6 +243,9 @@ int add_to_ping(PING *ping, uint8_t *client_id, IP_Port ip_port)
if (!ip_isset(&ip_port.ip))
return -1;

if (in_list(ping->dht->close_clientlist, LCLIENT_LIST, client_id, ip_port))
return -1;

uint32_t i;

for (i = 0; i < MAX_TO_PING; ++i) {
Expand Down

0 comments on commit a5ff3f8

Please sign in to comment.