summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-12-02 13:07:11 -0500
committerirungentoo <irungentoo@gmail.com>2013-12-02 13:07:11 -0500
commitb3d55442b6129656f3532622c938faff89a59c83 (patch)
tree3fe2df3cc2e6fb9900c115e2092e9e735fc8db4a /toxcore
parentd87a13ce9441a759d0708f5c6220f76c9e1242bd (diff)
Don't hole punch when we are connected.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/DHT.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index cde38a38..e7020a05 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -1150,7 +1150,7 @@ static void do_DHT_friends(DHT *dht)
1150static void do_Close(DHT *dht) 1150static void do_Close(DHT *dht)
1151{ 1151{
1152 uint8_t not_killed = do_ping_and_sendnode_requests(dht, &dht->close_lastgetnodes, dht->c->self_public_key, 1152 uint8_t not_killed = do_ping_and_sendnode_requests(dht, &dht->close_lastgetnodes, dht->c->self_public_key,
1153 dht->close_clientlist, LCLIENT_LIST); 1153 dht->close_clientlist, LCLIENT_LIST);
1154 1154
1155 if (!not_killed) { 1155 if (!not_killed) {
1156 /* all existing nodes are at least KILL_NODE_TIMEOUT, 1156 /* all existing nodes are at least KILL_NODE_TIMEOUT,
@@ -1256,30 +1256,25 @@ static int friend_iplist(DHT *dht, IP_Port *ip_portlist, uint16_t friend_num)
1256 int num_ipv4s = 0; 1256 int num_ipv4s = 0;
1257 IP_Port ipv6s[MAX_FRIEND_CLIENTS]; 1257 IP_Port ipv6s[MAX_FRIEND_CLIENTS];
1258 int num_ipv6s = 0; 1258 int num_ipv6s = 0;
1259 uint8_t connected;
1260 int i; 1259 int i;
1261 1260
1262 for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { 1261 for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) {
1263 client = &(friend->client_list[i]); 1262 client = &(friend->client_list[i]);
1264 connected = 0;
1265 1263
1266 /* If ip is not zero and node is good. */ 1264 /* If ip is not zero and node is good. */
1267 if (ip_isset(&client->assoc4.ret_ip_port.ip) && !is_timeout(client->assoc4.ret_timestamp, BAD_NODE_TIMEOUT)) { 1265 if (ip_isset(&client->assoc4.ret_ip_port.ip) && !is_timeout(client->assoc4.ret_timestamp, BAD_NODE_TIMEOUT)) {
1268 ipv4s[num_ipv4s] = client->assoc4.ret_ip_port; 1266 ipv4s[num_ipv4s] = client->assoc4.ret_ip_port;
1269 ++num_ipv4s; 1267 ++num_ipv4s;
1270
1271 connected = 1;
1272 } 1268 }
1273 1269
1274 if (ip_isset(&client->assoc6.ret_ip_port.ip) && !is_timeout(client->assoc6.ret_timestamp, BAD_NODE_TIMEOUT)) { 1270 if (ip_isset(&client->assoc6.ret_ip_port.ip) && !is_timeout(client->assoc6.ret_timestamp, BAD_NODE_TIMEOUT)) {
1275 ipv6s[num_ipv6s] = client->assoc6.ret_ip_port; 1271 ipv6s[num_ipv6s] = client->assoc6.ret_ip_port;
1276 ++num_ipv6s; 1272 ++num_ipv6s;
1277
1278 connected = 1;
1279 } 1273 }
1280 1274
1281 if (connected && id_equal(client->client_id, friend->client_id)) 1275 if (id_equal(client->client_id, friend->client_id))
1282 return 0; /* direct connectivity */ 1276 if (!is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT) || !is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT))
1277 return 0; /* direct connectivity */
1283 } 1278 }
1284 1279
1285#ifdef FRIEND_IPLIST_PAD 1280#ifdef FRIEND_IPLIST_PAD
@@ -1662,9 +1657,11 @@ DHT *new_DHT(Net_Crypto *c)
1662void do_DHT(DHT *dht) 1657void do_DHT(DHT *dht)
1663{ 1658{
1664 unix_time_update(); 1659 unix_time_update();
1660
1665 if (dht->last_run == unix_time()) { 1661 if (dht->last_run == unix_time()) {
1666 return; 1662 return;
1667 } 1663 }
1664
1668 do_Close(dht); 1665 do_Close(dht);
1669 do_DHT_friends(dht); 1666 do_DHT_friends(dht);
1670 do_NAT(dht); 1667 do_NAT(dht);