diff options
-rw-r--r-- | toxcore/friend_connection.c | 6 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 12 | ||||
-rw-r--r-- | toxcore/net_crypto.h | 4 |
3 files changed, 16 insertions, 6 deletions
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index c13ca949..de34e570 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c | |||
@@ -265,7 +265,7 @@ static void dht_ip_callback(void *object, int32_t number, IP_Port ip_port) | |||
265 | friend_new_connection(fr_c, number); | 265 | friend_new_connection(fr_c, number); |
266 | } | 266 | } |
267 | 267 | ||
268 | set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, ip_port); | 268 | set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, ip_port, 1); |
269 | friend_con->dht_ip_port = ip_port; | 269 | friend_con->dht_ip_port = ip_port; |
270 | friend_con->dht_ip_port_lastrecv = unix_time(); | 270 | friend_con->dht_ip_port_lastrecv = unix_time(); |
271 | } | 271 | } |
@@ -458,7 +458,7 @@ static int handle_new_connections(void *object, New_Connection *n_c) | |||
458 | friend_con->crypt_connection_id = id; | 458 | friend_con->crypt_connection_id = id; |
459 | 459 | ||
460 | if (n_c->source.ip.family != AF_INET && n_c->source.ip.family != AF_INET6) { | 460 | if (n_c->source.ip.family != AF_INET && n_c->source.ip.family != AF_INET6) { |
461 | set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, friend_con->dht_ip_port); | 461 | set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, friend_con->dht_ip_port, 0); |
462 | } else { | 462 | } else { |
463 | friend_con->dht_ip_port = n_c->source; | 463 | friend_con->dht_ip_port = n_c->source; |
464 | friend_con->dht_ip_port_lastrecv = unix_time(); | 464 | friend_con->dht_ip_port_lastrecv = unix_time(); |
@@ -796,7 +796,7 @@ void do_friend_connections(Friend_Connections *fr_c) | |||
796 | 796 | ||
797 | if (friend_con->dht_lock) { | 797 | if (friend_con->dht_lock) { |
798 | if (friend_new_connection(fr_c, i) == 0) { | 798 | if (friend_new_connection(fr_c, i) == 0) { |
799 | set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, friend_con->dht_ip_port); | 799 | set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, friend_con->dht_ip_port, 0); |
800 | connect_to_saved_tcp_relays(fr_c, i, (MAX_FRIEND_TCP_CONNECTIONS / 2)); /* Only fill it half up. */ | 800 | connect_to_saved_tcp_relays(fr_c, i, (MAX_FRIEND_TCP_CONNECTIONS / 2)); /* Only fill it half up. */ |
801 | } | 801 | } |
802 | } | 802 | } |
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index d74f0bf5..43468b73 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -1634,10 +1634,12 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const u | |||
1634 | 1634 | ||
1635 | /* Set the direct ip of the crypto connection. | 1635 | /* Set the direct ip of the crypto connection. |
1636 | * | 1636 | * |
1637 | * Connected is 0 if we are not sure we are connected to that person, 1 if we are sure. | ||
1638 | * | ||
1637 | * return -1 on failure. | 1639 | * return -1 on failure. |
1638 | * return 0 on success. | 1640 | * return 0 on success. |
1639 | */ | 1641 | */ |
1640 | int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port) | 1642 | int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, _Bool connected) |
1641 | { | 1643 | { |
1642 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); | 1644 | Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); |
1643 | 1645 | ||
@@ -1661,7 +1663,13 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port) | |||
1661 | if (bs_list_add(&c->ip_port_list, (uint8_t *)&ip_port, crypt_connection_id)) { | 1663 | if (bs_list_add(&c->ip_port_list, (uint8_t *)&ip_port, crypt_connection_id)) { |
1662 | bs_list_remove(&c->ip_port_list, (uint8_t *)&conn->ip_port, crypt_connection_id); | 1664 | bs_list_remove(&c->ip_port_list, (uint8_t *)&conn->ip_port, crypt_connection_id); |
1663 | conn->ip_port = ip_port; | 1665 | conn->ip_port = ip_port; |
1664 | conn->direct_lastrecv_time = 0; | 1666 | |
1667 | if (connected) { | ||
1668 | conn->direct_lastrecv_time = unix_time(); | ||
1669 | } else { | ||
1670 | conn->direct_lastrecv_time = 0; | ||
1671 | } | ||
1672 | |||
1665 | return 0; | 1673 | return 0; |
1666 | } | 1674 | } |
1667 | } | 1675 | } |
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index 9eb5e2d3..a0498b42 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -224,10 +224,12 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const u | |||
224 | 224 | ||
225 | /* Set the direct ip of the crypto connection. | 225 | /* Set the direct ip of the crypto connection. |
226 | * | 226 | * |
227 | * Connected is 0 if we are not sure we are connected to that person, 1 if we are sure. | ||
228 | * | ||
227 | * return -1 on failure. | 229 | * return -1 on failure. |
228 | * return 0 on success. | 230 | * return 0 on success. |
229 | */ | 231 | */ |
230 | int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port); | 232 | int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, _Bool connected); |
231 | 233 | ||
232 | /* Set function to be called when connection with crypt_connection_id goes connects/disconnects. | 234 | /* Set function to be called when connection with crypt_connection_id goes connects/disconnects. |
233 | * | 235 | * |