summaryrefslogtreecommitdiff
path: root/toxcore/TCP_connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/TCP_connection.c')
-rw-r--r--toxcore/TCP_connection.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c
index ab18daac..574ae3aa 100644
--- a/toxcore/TCP_connection.c
+++ b/toxcore/TCP_connection.c
@@ -274,13 +274,14 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c
274 * return TCP connection number on success. 274 * return TCP connection number on success.
275 * return -1 on failure. 275 * return -1 on failure.
276 */ 276 */
277int get_random_tcp_conn_number(TCP_Connections *tcp_c) 277int get_random_tcp_onion_conn_number(TCP_Connections *tcp_c)
278{ 278{
279 unsigned int i, r = rand(); 279 unsigned int i, r = rand();
280 280
281 for (i = 0; i < tcp_c->tcp_connections_length; ++i) { 281 for (i = 0; i < tcp_c->tcp_connections_length; ++i) {
282 if (tcp_c->tcp_connections[(i + r) % tcp_c->tcp_connections_length].status == TCP_CONN_CONNECTED) { 282 unsigned int index = ((i + r) % tcp_c->tcp_connections_length);
283 return ((i + r) % tcp_c->tcp_connections_length); 283 if (tcp_c->tcp_connections[index].onion && tcp_c->tcp_connections[index].status == TCP_CONN_CONNECTED) {
284 return index;
284 } 285 }
285 } 286 }
286 287
@@ -579,6 +580,10 @@ static int kill_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections
579 } 580 }
580 } 581 }
581 582
583 if (tcp_con->onion) {
584 --tcp_c->onion_num_conns;
585 }
586
582 kill_TCP_connection(tcp_con->connection); 587 kill_TCP_connection(tcp_con->connection);
583 588
584 return wipe_tcp_connection(tcp_c, tcp_connections_number); 589 return wipe_tcp_connection(tcp_c, tcp_connections_number);
@@ -777,6 +782,11 @@ static int tcp_relay_on_online(TCP_Connections *tcp_c, int tcp_connections_numbe
777 tcp_con->connected_time = 0; 782 tcp_con->connected_time = 0;
778 } 783 }
779 784
785 if (tcp_c->onion_num_conns < NUM_ONION_TCP_CONNECTIONS) {
786 tcp_con->onion = 1;
787 ++tcp_c->onion_num_conns;
788 }
789
780 return 0; 790 return 0;
781} 791}
782 792
@@ -978,7 +988,7 @@ static void kill_nonused_tcp(TCP_Connections *tcp_c)
978 988
979 if (tcp_con) { 989 if (tcp_con) {
980 if (tcp_con->status == TCP_CONN_CONNECTED) { 990 if (tcp_con->status == TCP_CONN_CONNECTED) {
981 if (!tcp_con->lock_count && is_timeout(tcp_con->connected_time, TCP_CONNECTION_ANNOUNCE_TIMEOUT)) { 991 if (!tcp_con->onion && !tcp_con->lock_count && is_timeout(tcp_con->connected_time, TCP_CONNECTION_ANNOUNCE_TIMEOUT)) {
982 to_kill[num_kill] = i; 992 to_kill[num_kill] = i;
983 ++num_kill; 993 ++num_kill;
984 } 994 }