summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/TODO2
-rw-r--r--toxav/msi.c1
-rw-r--r--toxcore/TCP_client.c37
-rw-r--r--toxcore/TCP_client.h2
4 files changed, 25 insertions, 17 deletions
diff --git a/docs/TODO b/docs/TODO
index 966a1b5f..dea513b2 100644
--- a/docs/TODO
+++ b/docs/TODO
@@ -52,7 +52,7 @@ blocks UDP (or is just unpunchable) (docs/TCP_Network.txt)
52See: (https://github.com/jencka/ProjectTox-libtoxdata) 52See: (https://github.com/jencka/ProjectTox-libtoxdata)
53 53
54[IN PROGRESS] GUI (no official one chosen yet, a list of promising ones follows) 54[IN PROGRESS] GUI (no official one chosen yet, a list of promising ones follows)
55https://github.com/notsecure/wintox 55https://github.com/notsecure/uTox
56https://github.com/naxuroqa/Venom 56https://github.com/naxuroqa/Venom
57https://github.com/Impyy/Toxy 57https://github.com/Impyy/Toxy
58https://github.com/lehitoskin/blight 58https://github.com/lehitoskin/blight
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..bc1b7ff4 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
200static int send_ping_response(TCP_Client_Connection *con); 200static int send_ping_response(TCP_Client_Connection *con);
201static 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 */
289static int send_ping_request(TCP_Client_Connection *con, uint64_t ping_id) 290static 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.
@@ -441,7 +451,7 @@ static int handle_TCP_packet(TCP_Client_Connection *conn, const uint8_t *data, u
441 uint8_t con_id = data[1] - NUM_RESERVED_PORTS; 451 uint8_t con_id = data[1] - NUM_RESERVED_PORTS;
442 452
443 if (conn->connections[con_id].status != 1) 453 if (conn->connections[con_id].status != 1)
444 return -1; 454 return 0;
445 455
446 conn->connections[con_id].status = 2; 456 conn->connections[con_id].status = 2;
447 457
@@ -465,7 +475,7 @@ static int handle_TCP_packet(TCP_Client_Connection *conn, const uint8_t *data, u
465 return 0; 475 return 0;
466 476
467 if (conn->connections[con_id].status != 2) 477 if (conn->connections[con_id].status != 2)
468 return -1; 478 return 0;
469 479
470 conn->connections[con_id].status = 1; 480 conn->connections[con_id].status = 1;
471 481
@@ -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 {