summaryrefslogtreecommitdiff
path: root/toxcore/TCP_connection.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-04-18 09:24:39 -0400
committerirungentoo <irungentoo@gmail.com>2015-04-18 09:24:39 -0400
commit863b6d6f4cc2c1f22055d92415af5c7421a8fc8a (patch)
tree8e19c43d1af6baab25f2d1c401ad4ec235de36c3 /toxcore/TCP_connection.c
parentc20062e633f67d1c1586198a8c2ca6c7d90d950e (diff)
If connected tcp relay becomes disconnected, try to reconnect once.
Diffstat (limited to 'toxcore/TCP_connection.c')
-rw-r--r--toxcore/TCP_connection.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c
index 574ae3aa..df0c24af 100644
--- a/toxcore/TCP_connection.c
+++ b/toxcore/TCP_connection.c
@@ -589,6 +589,47 @@ static int kill_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections
589 return wipe_tcp_connection(tcp_c, tcp_connections_number); 589 return wipe_tcp_connection(tcp_c, tcp_connections_number);
590} 590}
591 591
592static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number)
593{
594 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
595
596 if (!tcp_con)
597 return -1;
598
599 IP_Port ip_port = tcp_con->connection->ip_port;
600 uint8_t relay_pk[crypto_box_PUBLICKEYBYTES];
601 memcpy(relay_pk, tcp_con->connection->public_key, crypto_box_PUBLICKEYBYTES);
602 kill_TCP_connection(tcp_con->connection);
603 tcp_con->connection = new_TCP_connection(ip_port, relay_pk, tcp_c->dht->self_public_key, tcp_c->dht->self_secret_key,
604 &tcp_c->proxy_info);
605
606 if (!tcp_con->connection) {
607 kill_tcp_relay_connection(tcp_c, tcp_connections_number);
608 return -1;
609 }
610
611 unsigned int i;
612
613 for (i = 0; i < tcp_c->connections_length; ++i) {
614 TCP_Connection_to *con_to = get_connection(tcp_c, i);
615
616 if (con_to) {
617 set_tcp_connection_status(con_to, tcp_connections_number, TCP_CONNECTIONS_STATUS_NONE, 0);
618 }
619 }
620
621 if (tcp_con->onion) {
622 --tcp_c->onion_num_conns;
623 tcp_con->onion = 0;
624 }
625
626 tcp_con->lock_count = 0;
627 tcp_con->connected_time = 0;
628 tcp_con->status = TCP_CONN_VALID;
629
630 return 0;
631}
632
592/* Send a TCP routing request. 633/* Send a TCP routing request.
593 * 634 *
594 * return 0 on success. 635 * return 0 on success.
@@ -965,7 +1006,12 @@ static void do_tcp_conns(TCP_Connections *tcp_c)
965 tcp_con = get_tcp_connection(tcp_c, i); 1006 tcp_con = get_tcp_connection(tcp_c, i);
966 1007
967 if (tcp_con->connection->status == TCP_CLIENT_DISCONNECTED) { 1008 if (tcp_con->connection->status == TCP_CLIENT_DISCONNECTED) {
968 kill_tcp_relay_connection(tcp_c, i); 1009 if (tcp_con->status == TCP_CONN_CONNECTED) {
1010 reconnect_tcp_relay_connection(tcp_c, i);
1011 } else {
1012 kill_tcp_relay_connection(tcp_c, i);
1013 }
1014
969 continue; 1015 continue;
970 } 1016 }
971 1017