Tox clients now should show they are offline with much better precision.

This commit is contained in:
irungentoo 2014-11-20 21:30:16 -05:00
parent 1ef2092bcc
commit 057f08fb13
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
2 changed files with 15 additions and 1 deletions

View File

@ -572,6 +572,8 @@ static int handle_announce_response(void *object, IP_Port source, const uint8_t
return 1; 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; 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; onion_c->friends_list[friend_num].is_online = is_online;
/* This should prevent some clock related issues */ /* 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].last_noreplay = 0;
onion_c->friends_list[friend_num].run_count = 0;
}
return 0; return 0;
} }
@ -1332,6 +1336,9 @@ int onion_isconnected(const Onion_Client *onion_c)
{ {
unsigned int i, num = 0, announced = 0; 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) { for (i = 0; i < MAX_ONION_CLIENTS; ++i) {
if (!is_timeout(onion_c->clients_announce_list[i].timestamp, ONION_NODE_TIMEOUT)) { if (!is_timeout(onion_c->clients_announce_list[i].timestamp, ONION_NODE_TIMEOUT)) {
++num; ++num;

View File

@ -49,6 +49,11 @@
#define MAX_PATH_NODES 32 #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 { typedef struct {
uint8_t client_id[CLIENT_ID_SIZE]; uint8_t client_id[CLIENT_ID_SIZE];
IP_Port ip_port; IP_Port ip_port;
@ -140,6 +145,8 @@ typedef struct {
oniondata_handler_callback function; oniondata_handler_callback function;
void *object; void *object;
} Onion_Data_Handlers[256]; } Onion_Data_Handlers[256];
uint64_t last_packet_recv;
} Onion_Client; } Onion_Client;