From 9e43d678fb7e42526aa5ee2429efee4776dad69f Mon Sep 17 00:00:00 2001 From: zugz Date: Sat, 5 Aug 2017 20:25:33 +0200 Subject: [PATCH] reset hole-punching parameters after not punching for a while --- toxcore/DHT.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/toxcore/DHT.c b/toxcore/DHT.c index a4b97fb8..4ebe7f33 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -46,6 +46,9 @@ /* Interval in seconds between punching attempts*/ #define PUNCH_INTERVAL 3 +/* Time in seconds after which punching parameters will be reset */ +#define PUNCH_RESET_TIME 40 + #define MAX_NORMAL_PUNCHING_TRIES 5 #define NAT_PING_REQUEST 0 @@ -2129,6 +2132,12 @@ static void do_NAT(DHT *dht) continue; } + if (dht->friends_list[i].nat.punching_timestamp + PUNCH_RESET_TIME < temp_time) { + dht->friends_list[i].nat.tries = 0; + dht->friends_list[i].nat.punching_index = 0; + dht->friends_list[i].nat.punching_index2 = 0; + } + uint16_t port_list[MAX_FRIEND_CLIENTS]; uint16_t numports = NAT_getports(port_list, ip_list, num, ip); punch_holes(dht, ip, port_list, numports, i);