summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo_trip <irungentoo@gmail.com>2014-10-30 16:06:11 -0400
committerirungentoo_trip <irungentoo@gmail.com>2014-10-30 16:06:11 -0400
commit44f63db6223efe04e6b5f9547c2e47ae5da2d521 (patch)
tree4158ab220f43ef114dc79121c0e2d0435225dafd /toxcore
parentd6685d1c9aa52ce22eb1c2bb83b90b58d4835f95 (diff)
Slightly improved the function that checks if Tox is online.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/onion_client.c19
1 files 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)
1330 */ 1330 */
1331int onion_isconnected(const Onion_Client *onion_c) 1331int onion_isconnected(const Onion_Client *onion_c)
1332{ 1332{
1333 unsigned int i; 1333 unsigned int i, num = 0, announced = 0;
1334 1334
1335 for (i = 0; i < MAX_ONION_CLIENTS; ++i) { 1335 for (i = 0; i < MAX_ONION_CLIENTS; ++i) {
1336 if (!is_timeout(onion_c->clients_announce_list[i].timestamp, ONION_NODE_TIMEOUT)) 1336 if (!is_timeout(onion_c->clients_announce_list[i].timestamp, ONION_NODE_TIMEOUT)) {
1337 if (onion_c->clients_announce_list[i].is_stored) 1337 ++num;
1338 return 1; 1338
1339 if (onion_c->clients_announce_list[i].is_stored) {
1340 ++announced;
1341 }
1342 }
1343 }
1344
1345 /* Consider ourselves online if we are announced to half or more nodes
1346 we are connected to */
1347 if (num && announced) {
1348 if ((num / 2) <= announced)
1349 return 1;
1339 } 1350 }
1340 1351
1341 return 0; 1352 return 0;