diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index d22b2c8b..fda230b7 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -572,6 +572,8 @@ static int handle_announce_response(void *object, IP_Port source, const uint8_t return 1; } + //TODO: LAN vs non LAN ips?, if we are connected only to LAN, are we offline? + onion_c->last_packet_recv = unix_time(); return 0; } @@ -1104,8 +1106,10 @@ int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_on onion_c->friends_list[friend_num].is_online = is_online; /* This should prevent some clock related issues */ - if (!is_online) + if (!is_online) { onion_c->friends_list[friend_num].last_noreplay = 0; + onion_c->friends_list[friend_num].run_count = 0; + } return 0; } @@ -1332,6 +1336,9 @@ int onion_isconnected(const Onion_Client *onion_c) { unsigned int i, num = 0, announced = 0; + if (is_timeout(onion_c->last_packet_recv, ONION_OFFLINE_TIMEOUT)) + return 0; + for (i = 0; i < MAX_ONION_CLIENTS; ++i) { if (!is_timeout(onion_c->clients_announce_list[i].timestamp, ONION_NODE_TIMEOUT)) { ++num; diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index 217b1645..ec8de383 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h @@ -49,6 +49,11 @@ #define MAX_PATH_NODES 32 +/* If no packets are received within that interval tox will + * be considered offline. + */ +#define ONION_OFFLINE_TIMEOUT (ONION_NODE_PING_INTERVAL * 1.25) + typedef struct { uint8_t client_id[CLIENT_ID_SIZE]; IP_Port ip_port; @@ -140,6 +145,8 @@ typedef struct { oniondata_handler_callback function; void *object; } Onion_Data_Handlers[256]; + + uint64_t last_packet_recv; } Onion_Client;