From c959f6c019aae0e1b52385e0f473c9e91107d27b Mon Sep 17 00:00:00 2001 From: irungentoo Date: Mon, 18 Aug 2014 18:56:02 -0400 Subject: [PATCH] Added function to check if we were only connected to LAN DHT peers. --- toxcore/DHT.c | 23 +++++++++++++++++++++++ toxcore/DHT.h | 6 ++++++ 2 files changed, 29 insertions(+) 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) return -1; } + /* return 0 if we are not connected to the DHT. * return 1 if we are. */ @@ -2431,3 +2432,25 @@ int DHT_isconnected(const DHT *dht) return 0; } + +/* return 0 if we are not connected or only connected to lan peers with the DHT. + * return 1 if we are. + */ +int DHT_non_lan_connected(const DHT *dht) +{ + uint32_t i; + unix_time_update(); + + for (i = 0; i < LCLIENT_LIST; ++i) { + const Client_data *client = &dht->close_clientlist[i]; + + if (!is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT) && LAN_ip(client->assoc4.ip_port.ip) == -1) + return 1; + + if (!is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT) && LAN_ip(client->assoc6.ip_port.ip) == -1) + return 1; + + } + + return 0; +} 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); */ int DHT_isconnected(const DHT *dht); +/* return 0 if we are not connected or only connected to lan peers with the DHT. + * return 1 if we are. + */ +int DHT_non_lan_connected(const DHT *dht); + + int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id); #endif