summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-09-25 10:07:07 -0400
committerirungentoo <irungentoo@gmail.com>2013-09-25 10:07:07 -0400
commit3c78aefce07cf83a5236b0fcdb202ff463ff6a60 (patch)
tree037c60eb141cb7b427c51e8b5ce1919ed9f48eeb
parent83c665f2c40928935a26963dbc3689defb332687 (diff)
Fixed bug where hole punching was attempted even though the
clients were connected. Increased the number of ports tried per interval of time. Also astyled the files.
-rw-r--r--toxcore/DHT.c24
-rw-r--r--toxcore/ping.c7
2 files changed, 19 insertions, 12 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 }
diff --git a/toxcore/ping.c b/toxcore/ping.c
index 09b80f0d..b9940ce1 100644
--- a/toxcore/ping.c
+++ b/toxcore/ping.c
@@ -15,7 +15,7 @@
15#include "net_crypto.h" 15#include "net_crypto.h"
16#include "DHT.h" 16#include "DHT.h"
17 17
18#define PING_NUM_MAX 256 18#define PING_NUM_MAX 384
19#define PING_TIMEOUT 5 // 5s 19#define PING_TIMEOUT 5 // 5s
20 20
21/* Ping newly announced nodes to ping per TIME_TOPING seconds*/ 21/* Ping newly announced nodes to ping per TIME_TOPING seconds*/
@@ -180,6 +180,7 @@ static int handle_ping_request(void *_dht, IP_Port source, uint8_t *packet, uint
180 return 1; 180 return 1;
181 181
182 PING *ping = dht->ping; 182 PING *ping = dht->ping;
183
183 if (id_eq(packet + 1, ping->c->self_public_key)) 184 if (id_eq(packet + 1, ping->c->self_public_key))
184 return 1; 185 return 1;
185 186
@@ -211,6 +212,7 @@ static int handle_ping_response(void *_dht, IP_Port source, uint8_t *packet, uin
211 return 1; 212 return 1;
212 213
213 PING *ping = dht->ping; 214 PING *ping = dht->ping;
215
214 if (id_eq(packet + 1, ping->c->self_public_key)) 216 if (id_eq(packet + 1, ping->c->self_public_key))
215 return 1; 217 return 1;
216 218
@@ -283,7 +285,7 @@ static int is_timeout(uint64_t time_now, uint64_t timestamp, uint64_t timeout)
283void do_toping(PING *ping) 285void do_toping(PING *ping)
284{ 286{
285 uint64_t temp_time = unix_time(); 287 uint64_t temp_time = unix_time();
286 288
287 if (!is_timeout(temp_time, ping->last_toping, TIME_TOPING)) 289 if (!is_timeout(temp_time, ping->last_toping, TIME_TOPING))
288 return; 290 return;
289 291
@@ -303,6 +305,7 @@ void do_toping(PING *ping)
303PING *new_ping(DHT *dht, Net_Crypto *c) 305PING *new_ping(DHT *dht, Net_Crypto *c)
304{ 306{
305 PING *ping = calloc(1, sizeof(PING)); 307 PING *ping = calloc(1, sizeof(PING));
308
306 if (ping == NULL) 309 if (ping == NULL)
307 return NULL; 310 return NULL;
308 311