summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r--toxcore/DHT.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index ad4c8a1d..db3c5883 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -51,7 +51,7 @@
51/* Ping interval in seconds for each random sending of a get nodes request. */ 51/* Ping interval in seconds for each random sending of a get nodes request. */
52#define GET_NODE_INTERVAL 10 52#define GET_NODE_INTERVAL 10
53 53
54#define MAX_PUNCHING_PORTS 32 54#define MAX_PUNCHING_PORTS 128
55 55
56/* Interval in seconds between punching attempts*/ 56/* Interval in seconds between punching attempts*/
57#define PUNCH_INTERVAL 10 57#define PUNCH_INTERVAL 10
@@ -137,11 +137,12 @@ static int client_or_ip_port_in_list(Client_data *list, uint32_t length, uint8_t
137 uint64_t temp_time = unix_time(); 137 uint64_t temp_time = unix_time();
138 138
139 uint8_t candropipv4 = 1; 139 uint8_t candropipv4 = 1;
140
140 if (ip_port.ip.family == AF_INET6) { 141 if (ip_port.ip.family == AF_INET6) {
141 uint8_t ipv6cnt = 0; 142 uint8_t ipv6cnt = 0;
142 143
143 /* ipv6: count how many spots are used */ 144 /* ipv6: count how many spots are used */
144 for(i = 0; i < length; i++) 145 for (i = 0; i < length; i++)
145 if (list[i].ip_port.ip.family == AF_INET6) 146 if (list[i].ip_port.ip.family == AF_INET6)
146 ipv6cnt++; 147 ipv6cnt++;
147 148
@@ -318,11 +319,12 @@ static int replace_bad( Client_data *list,
318 uint64_t temp_time = unix_time(); 319 uint64_t temp_time = unix_time();
319 320
320 uint8_t candropipv4 = 1; 321 uint8_t candropipv4 = 1;
322
321 if (ip_port.ip.family == AF_INET6) { 323 if (ip_port.ip.family == AF_INET6) {
322 uint32_t ipv6cnt = 0; 324 uint32_t ipv6cnt = 0;
323 325
324 /* ipv6: count how many spots are used */ 326 /* ipv6: count how many spots are used */
325 for(i = 0; i < length; i++) 327 for (i = 0; i < length; i++)
326 if (list[i].ip_port.ip.family == AF_INET6) 328 if (list[i].ip_port.ip.family == AF_INET6)
327 ipv6cnt++; 329 ipv6cnt++;
328 330
@@ -334,8 +336,9 @@ static int replace_bad( Client_data *list,
334 for (i = 0; i < length; ++i) { 336 for (i = 0; i < length; ++i) {
335 /* If node is bad */ 337 /* If node is bad */
336 Client_data *client = &list[i]; 338 Client_data *client = &list[i];
339
337 if ((candropipv4 || (client->ip_port.ip.family == AF_INET6)) && 340 if ((candropipv4 || (client->ip_port.ip.family == AF_INET6)) &&
338 is_timeout(temp_time, client->timestamp, BAD_NODE_TIMEOUT)) { 341 is_timeout(temp_time, client->timestamp, BAD_NODE_TIMEOUT)) {
339 memcpy(client->client_id, client_id, CLIENT_ID_SIZE); 342 memcpy(client->client_id, client_id, CLIENT_ID_SIZE);
340 client->ip_port = ip_port; 343 client->ip_port = ip_port;
341 client->timestamp = temp_time; 344 client->timestamp = temp_time;
@@ -381,11 +384,12 @@ static int replace_good( Client_data *list,
381 sort_list(list, length, comp_client_id); 384 sort_list(list, length, comp_client_id);
382 385
383 uint8_t candropipv4 = 1; 386 uint8_t candropipv4 = 1;
387
384 if (ip_port.ip.family == AF_INET6) { 388 if (ip_port.ip.family == AF_INET6) {
385 uint32_t i, ipv6cnt = 0; 389 uint32_t i, ipv6cnt = 0;
386 390
387 /* ipv6: count how many spots are used */ 391 /* ipv6: count how many spots are used */
388 for(i = 0; i < length; i++) 392 for (i = 0; i < length; i++)
389 if (list[i].ip_port.ip.family == AF_INET6) 393 if (list[i].ip_port.ip.family == AF_INET6)
390 ipv6cnt++; 394 ipv6cnt++;
391 395
@@ -419,6 +423,7 @@ static int replace_good( Client_data *list,
419 */ 423 */
420 for (i = 0; i < length; i++) { 424 for (i = 0; i < length; i++) {
421 Client_data *client = &list[i]; 425 Client_data *client = &list[i];
426
422 if (client->ip_port.ip.family == AF_INET6) { 427 if (client->ip_port.ip.family == AF_INET6) {
423 if (id_closest(comp_client_id, list[i].client_id, client_id) == 2) 428 if (id_closest(comp_client_id, list[i].client_id, client_id) == 2)
424 replace = i; 429 replace = i;
@@ -1138,14 +1143,13 @@ static int friend_iplist(DHT *dht, IP_Port *ip_portlist, uint16_t friend_num)
1138 Client_data *client; 1143 Client_data *client;
1139 1144
1140 for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { 1145 for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) {
1141 client = &friend->client_list[i]; 1146 client = &(friend->client_list[i]);
1147
1148 if (id_equal(client->client_id, friend->client_id) && !is_timeout(temp_time, client->timestamp, BAD_NODE_TIMEOUT))
1149 return 0;
1142 1150
1143 /* If ip is not zero and node is good. */ 1151 /* If ip is not zero and node is good. */
1144 if (ip_isset(&client->ret_ip_port.ip) && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) { 1152 if (ip_isset(&client->ret_ip_port.ip) && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
1145
1146 if (id_equal(client->client_id, friend->client_id))
1147 return 0;
1148
1149 ip_portlist[num_ips] = client->ret_ip_port; 1153 ip_portlist[num_ips] = client->ret_ip_port;
1150 ++num_ips; 1154 ++num_ips;
1151 } 1155 }