From 44f63db6223efe04e6b5f9547c2e47ae5da2d521 Mon Sep 17 00:00:00 2001 From: irungentoo_trip Date: Thu, 30 Oct 2014 16:06:11 -0400 Subject: [PATCH] Slightly improved the function that checks if Tox is online. --- toxcore/onion_client.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 24949aff..b774956c 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -1330,12 +1330,23 @@ void kill_onion_client(Onion_Client *onion_c) */ int onion_isconnected(const Onion_Client *onion_c) { - unsigned int i; + unsigned int i, num = 0, announced = 0; for (i = 0; i < MAX_ONION_CLIENTS; ++i) { - if (!is_timeout(onion_c->clients_announce_list[i].timestamp, ONION_NODE_TIMEOUT)) - if (onion_c->clients_announce_list[i].is_stored) - return 1; + if (!is_timeout(onion_c->clients_announce_list[i].timestamp, ONION_NODE_TIMEOUT)) { + ++num; + + if (onion_c->clients_announce_list[i].is_stored) { + ++announced; + } + } + } + + /* Consider ourselves online if we are announced to half or more nodes + we are connected to */ + if (num && announced) { + if ((num / 2) <= announced) + return 1; } return 0;