diff options
-rw-r--r-- | toxcore/DHT.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 2583b891..470826f0 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -1690,17 +1690,30 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, | |||
1690 | 1690 | ||
1691 | uint32_t i; | 1691 | uint32_t i; |
1692 | uint32_t top = dht->friends_list[friend_num].nat.punching_index + MAX_PUNCHING_PORTS; | 1692 | uint32_t top = dht->friends_list[friend_num].nat.punching_index + MAX_PUNCHING_PORTS; |
1693 | uint16_t firstport = port_list[0]; | ||
1693 | 1694 | ||
1694 | for (i = dht->friends_list[friend_num].nat.punching_index; i != top; i++) { | 1695 | for (i = 0; i < numports; ++i) { |
1695 | /* TODO: Improve port guessing algorithm. */ | 1696 | if (firstport != port_list[0]) |
1696 | uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); | 1697 | break; |
1698 | } | ||
1699 | |||
1700 | if (i == numports) { /* If all ports are the same, only try that one port. */ | ||
1697 | IP_Port pinging; | 1701 | IP_Port pinging; |
1698 | ip_copy(&pinging.ip, &ip); | 1702 | ip_copy(&pinging.ip, &ip); |
1699 | pinging.port = htons(port); | 1703 | pinging.port = htons(firstport); |
1700 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); | 1704 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); |
1701 | } | 1705 | } else { |
1706 | for (i = dht->friends_list[friend_num].nat.punching_index; i != top; i++) { | ||
1707 | /* TODO: Improve port guessing algorithm. */ | ||
1708 | uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); | ||
1709 | IP_Port pinging; | ||
1710 | ip_copy(&pinging.ip, &ip); | ||
1711 | pinging.port = htons(port); | ||
1712 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].client_id); | ||
1713 | } | ||
1702 | 1714 | ||
1703 | dht->friends_list[friend_num].nat.punching_index = i; | 1715 | dht->friends_list[friend_num].nat.punching_index = i; |
1716 | } | ||
1704 | } | 1717 | } |
1705 | 1718 | ||
1706 | static void do_NAT(DHT *dht) | 1719 | static void do_NAT(DHT *dht) |