diff options
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 65fe6ae0..02175c2a 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -1794,21 +1794,6 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, | |||
1794 | ip_copy(&pinging.ip, &ip); | 1794 | ip_copy(&pinging.ip, &ip); |
1795 | pinging.port = htons(firstport); | 1795 | pinging.port = htons(firstport); |
1796 | 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); |
1797 | |||
1798 | if (dht->friends_list[friend_num].nat.tries > MAX_NORMAL_PUNCHING_TRIES) { | ||
1799 | top = dht->friends_list[friend_num].nat.punching_index2 + MAX_PUNCHING_PORTS / 2; | ||
1800 | uint16_t port1 = 1024; | ||
1801 | uint16_t port2 = ~0; | ||
1802 | |||
1803 | for (i = dht->friends_list[friend_num].nat.punching_index2; i != top; ++i) { | ||
1804 | pinging.port = htons(port1 + i); | ||
1805 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); | ||
1806 | pinging.port = htons(port2 - i); | ||
1807 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); | ||
1808 | } | ||
1809 | |||
1810 | dht->friends_list[friend_num].nat.punching_index2 = i; | ||
1811 | } | ||
1812 | } else { | 1797 | } else { |
1813 | 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) { |
1814 | /* TODO: Improve port guessing algorithm. */ | 1799 | /* TODO: Improve port guessing algorithm. */ |
@@ -1822,6 +1807,20 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, | |||
1822 | dht->friends_list[friend_num].nat.punching_index = i; | 1807 | dht->friends_list[friend_num].nat.punching_index = i; |
1823 | } | 1808 | } |
1824 | 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 | |||
1825 | ++dht->friends_list[friend_num].nat.tries; | 1824 | ++dht->friends_list[friend_num].nat.tries; |
1826 | } | 1825 | } |
1827 | 1826 | ||