diff options
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index d5808313..02175c2a 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -46,11 +46,13 @@ | |||
46 | /* Ping interval in seconds for each random sending of a get nodes request. */ | 46 | /* Ping interval in seconds for each random sending of a get nodes request. */ |
47 | #define GET_NODE_INTERVAL 5 | 47 | #define GET_NODE_INTERVAL 5 |
48 | 48 | ||
49 | #define MAX_PUNCHING_PORTS 32 | 49 | #define MAX_PUNCHING_PORTS 48 |
50 | 50 | ||
51 | /* Interval in seconds between punching attempts*/ | 51 | /* Interval in seconds between punching attempts*/ |
52 | #define PUNCH_INTERVAL 3 | 52 | #define PUNCH_INTERVAL 3 |
53 | 53 | ||
54 | #define MAX_NORMAL_PUNCHING_TRIES 5 | ||
55 | |||
54 | #define NAT_PING_REQUEST 0 | 56 | #define NAT_PING_REQUEST 0 |
55 | #define NAT_PING_RESPONSE 1 | 57 | #define NAT_PING_RESPONSE 1 |
56 | 58 | ||
@@ -1793,7 +1795,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, | |||
1793 | pinging.port = htons(firstport); | 1795 | pinging.port = htons(firstport); |
1794 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); | 1796 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); |
1795 | } else { | 1797 | } else { |
1796 | for (i = dht->friends_list[friend_num].nat.punching_index; i != top; i++) { | 1798 | for (i = dht->friends_list[friend_num].nat.punching_index; i != top; ++i) { |
1797 | /* TODO: Improve port guessing algorithm. */ | 1799 | /* TODO: Improve port guessing algorithm. */ |
1798 | uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); | 1800 | uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); |
1799 | IP_Port pinging; | 1801 | IP_Port pinging; |
@@ -1804,6 +1806,22 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, | |||
1804 | 1806 | ||
1805 | dht->friends_list[friend_num].nat.punching_index = i; | 1807 | dht->friends_list[friend_num].nat.punching_index = i; |
1806 | } | 1808 | } |
1809 | |||
1810 | if (dht->friends_list[friend_num].nat.tries > MAX_NORMAL_PUNCHING_TRIES) { | ||
1811 | top = dht->friends_list[friend_num].nat.punching_index2 + MAX_PUNCHING_PORTS; | ||
1812 | uint16_t port = 1024; | ||
1813 | IP_Port pinging; | ||
1814 | ip_copy(&pinging.ip, &ip); | ||
1815 | |||
1816 | for (i = dht->friends_list[friend_num].nat.punching_index2; i != top; ++i) { | ||
1817 | pinging.port = htons(port + i); | ||
1818 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); | ||
1819 | } | ||
1820 | |||
1821 | dht->friends_list[friend_num].nat.punching_index2 = i - (MAX_PUNCHING_PORTS / 2); | ||
1822 | } | ||
1823 | |||
1824 | ++dht->friends_list[friend_num].nat.tries; | ||
1807 | } | 1825 | } |
1808 | 1826 | ||
1809 | static void do_NAT(DHT *dht) | 1827 | static void do_NAT(DHT *dht) |