diff options
-rw-r--r-- | toxav/msi.c | 1 | ||||
-rw-r--r-- | toxcore/TCP_client.c | 33 | ||||
-rw-r--r-- | toxcore/TCP_client.h | 2 |
3 files changed, 22 insertions, 14 deletions
diff --git a/toxav/msi.c b/toxav/msi.c index 88f62ebd..26b37292 100644 --- a/toxav/msi.c +++ b/toxav/msi.c | |||
@@ -959,6 +959,7 @@ void handle_remote_connection_change(Messenger *messenger, int friend_num, uint8 | |||
959 | for ( ; i < session->calls[j]->peer_count; i ++ ) | 959 | for ( ; i < session->calls[j]->peer_count; i ++ ) |
960 | if ( session->calls[j]->peers[i] == friend_num ) { | 960 | if ( session->calls[j]->peers[i] == friend_num ) { |
961 | invoke_callback(j, MSI_OnPeerTimeout); | 961 | invoke_callback(j, MSI_OnPeerTimeout); |
962 | terminate_call(session, session->calls[j]); | ||
962 | LOGGER_DEBUG("Remote: %d timed out!", friend_num); | 963 | LOGGER_DEBUG("Remote: %d timed out!", friend_num); |
963 | return; /* TODO: On group calls change behaviour */ | 964 | return; /* TODO: On group calls change behaviour */ |
964 | } | 965 | } |
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index 82720ae8..6ead44a5 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c | |||
@@ -198,6 +198,7 @@ void routing_status_handler(TCP_Client_Connection *con, int (*status_callback)(v | |||
198 | } | 198 | } |
199 | 199 | ||
200 | static int send_ping_response(TCP_Client_Connection *con); | 200 | static int send_ping_response(TCP_Client_Connection *con); |
201 | static int send_ping_request(TCP_Client_Connection *con); | ||
201 | 202 | ||
202 | /* return 1 on success. | 203 | /* return 1 on success. |
203 | * return 0 if could not send packet. | 204 | * return 0 if could not send packet. |
@@ -211,7 +212,7 @@ int send_data(TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, u | |||
211 | if (con->connections[con_id].status != 2) | 212 | if (con->connections[con_id].status != 2) |
212 | return -1; | 213 | return -1; |
213 | 214 | ||
214 | if (send_ping_response(con) == 0) | 215 | if (send_ping_response(con) == 0 || send_ping_request(con) == 0) |
215 | return 0; | 216 | return 0; |
216 | 217 | ||
217 | uint8_t packet[1 + length]; | 218 | uint8_t packet[1 + length]; |
@@ -286,12 +287,21 @@ static int send_disconnect_notification(TCP_Client_Connection *con, uint8_t id) | |||
286 | * return 0 if could not send packet. | 287 | * return 0 if could not send packet. |
287 | * return -1 on failure (connection must be killed). | 288 | * return -1 on failure (connection must be killed). |
288 | */ | 289 | */ |
289 | static int send_ping_request(TCP_Client_Connection *con, uint64_t ping_id) | 290 | static int send_ping_request(TCP_Client_Connection *con) |
290 | { | 291 | { |
292 | if (!con->ping_request_id) | ||
293 | return 1; | ||
294 | |||
291 | uint8_t packet[1 + sizeof(uint64_t)]; | 295 | uint8_t packet[1 + sizeof(uint64_t)]; |
292 | packet[0] = TCP_PACKET_PING; | 296 | packet[0] = TCP_PACKET_PING; |
293 | memcpy(packet + 1, &ping_id, sizeof(uint64_t)); | 297 | memcpy(packet + 1, &con->ping_request_id, sizeof(uint64_t)); |
294 | return write_packet_TCP_secure_connection(con, packet, sizeof(packet)); | 298 | int ret; |
299 | |||
300 | if ((ret = write_packet_TCP_secure_connection(con, packet, sizeof(packet))) == 1) { | ||
301 | con->ping_request_id = 0; | ||
302 | } | ||
303 | |||
304 | return ret; | ||
295 | } | 305 | } |
296 | 306 | ||
297 | /* return 1 on success. | 307 | /* return 1 on success. |
@@ -539,6 +549,8 @@ static int do_confirmed_TCP(TCP_Client_Connection *conn) | |||
539 | { | 549 | { |
540 | send_pending_data(conn); | 550 | send_pending_data(conn); |
541 | send_ping_response(conn); | 551 | send_ping_response(conn); |
552 | send_ping_request(conn); | ||
553 | |||
542 | uint8_t packet[MAX_PACKET_SIZE]; | 554 | uint8_t packet[MAX_PACKET_SIZE]; |
543 | int len; | 555 | int len; |
544 | 556 | ||
@@ -548,16 +560,9 @@ static int do_confirmed_TCP(TCP_Client_Connection *conn) | |||
548 | if (!ping_id) | 560 | if (!ping_id) |
549 | ++ping_id; | 561 | ++ping_id; |
550 | 562 | ||
551 | int ret = send_ping_request(conn, ping_id); | 563 | conn->ping_request_id = conn->ping_id = ping_id; |
552 | 564 | send_ping_request(conn); | |
553 | if (ret == 1) { | 565 | conn->last_pinged = unix_time(); |
554 | conn->last_pinged = unix_time(); | ||
555 | conn->ping_id = ping_id; | ||
556 | } else { | ||
557 | if (is_timeout(conn->last_pinged, TCP_PING_FREQUENCY + TCP_PING_TIMEOUT)) { | ||
558 | conn->status = TCP_CLIENT_DISCONNECTED; | ||
559 | } | ||
560 | } | ||
561 | } | 566 | } |
562 | 567 | ||
563 | if (conn->ping_id && is_timeout(conn->last_pinged, TCP_PING_TIMEOUT)) { | 568 | if (conn->ping_id && is_timeout(conn->last_pinged, TCP_PING_TIMEOUT)) { |
diff --git a/toxcore/TCP_client.h b/toxcore/TCP_client.h index e6d232ed..f57f79e6 100644 --- a/toxcore/TCP_client.h +++ b/toxcore/TCP_client.h | |||
@@ -58,6 +58,8 @@ typedef struct { | |||
58 | uint64_t ping_id; | 58 | uint64_t ping_id; |
59 | 59 | ||
60 | uint64_t ping_response_id; | 60 | uint64_t ping_response_id; |
61 | uint64_t ping_request_id; | ||
62 | |||
61 | void *net_crypto_pointer; | 63 | void *net_crypto_pointer; |
62 | uint32_t net_crypto_location; | 64 | uint32_t net_crypto_location; |
63 | struct { | 65 | struct { |