diff options
author | irungentoo <irungentoo@gmail.com> | 2014-08-18 18:56:02 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-08-18 18:56:02 -0400 |
commit | c959f6c019aae0e1b52385e0f473c9e91107d27b (patch) | |
tree | f70da0285fca54c443cb6acc6ade9b39c6b7a9b7 | |
parent | 6ca7d86c5053fe146bf14a3d6930059f949f776a (diff) |
Added function to check if we were only connected to LAN DHT peers.
-rw-r--r-- | toxcore/DHT.c | 23 | ||||
-rw-r--r-- | toxcore/DHT.h | 6 |
2 files changed, 29 insertions, 0 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 5658d757..b963d8de 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -2413,6 +2413,7 @@ int DHT_load(DHT *dht, const uint8_t *data, uint32_t length) | |||
2413 | 2413 | ||
2414 | return -1; | 2414 | return -1; |
2415 | } | 2415 | } |
2416 | |||
2416 | /* return 0 if we are not connected to the DHT. | 2417 | /* return 0 if we are not connected to the DHT. |
2417 | * return 1 if we are. | 2418 | * return 1 if we are. |
2418 | */ | 2419 | */ |
@@ -2431,3 +2432,25 @@ int DHT_isconnected(const DHT *dht) | |||
2431 | 2432 | ||
2432 | return 0; | 2433 | return 0; |
2433 | } | 2434 | } |
2435 | |||
2436 | /* return 0 if we are not connected or only connected to lan peers with the DHT. | ||
2437 | * return 1 if we are. | ||
2438 | */ | ||
2439 | int DHT_non_lan_connected(const DHT *dht) | ||
2440 | { | ||
2441 | uint32_t i; | ||
2442 | unix_time_update(); | ||
2443 | |||
2444 | for (i = 0; i < LCLIENT_LIST; ++i) { | ||
2445 | const Client_data *client = &dht->close_clientlist[i]; | ||
2446 | |||
2447 | if (!is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT) && LAN_ip(client->assoc4.ip_port.ip) == -1) | ||
2448 | return 1; | ||
2449 | |||
2450 | if (!is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT) && LAN_ip(client->assoc6.ip_port.ip) == -1) | ||
2451 | return 1; | ||
2452 | |||
2453 | } | ||
2454 | |||
2455 | return 0; | ||
2456 | } | ||
diff --git a/toxcore/DHT.h b/toxcore/DHT.h index ea94e4ca..563ae08c 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h | |||
@@ -386,6 +386,12 @@ void kill_DHT(DHT *dht); | |||
386 | */ | 386 | */ |
387 | int DHT_isconnected(const DHT *dht); | 387 | int DHT_isconnected(const DHT *dht); |
388 | 388 | ||
389 | /* return 0 if we are not connected or only connected to lan peers with the DHT. | ||
390 | * return 1 if we are. | ||
391 | */ | ||
392 | int DHT_non_lan_connected(const DHT *dht); | ||
393 | |||
394 | |||
389 | int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id); | 395 | int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id); |
390 | 396 | ||
391 | #endif | 397 | #endif |