diff options
Diffstat (limited to 'toxcore/friend_connection.c')
-rw-r--r-- | toxcore/friend_connection.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index c13ca949..1656def0 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c | |||
@@ -158,6 +158,15 @@ int friend_add_tcp_relay(Friend_Connections *fr_c, int friendcon_id, IP_Port ip_ | |||
158 | if (!friend_con) | 158 | if (!friend_con) |
159 | return -1; | 159 | return -1; |
160 | 160 | ||
161 | /* Local ip and same pk means that they are hosting a TCP relay. */ | ||
162 | if (Local_ip(ip_port.ip) && memcmp(friend_con->dht_temp_pk, public_key, crypto_box_PUBLICKEYBYTES) == 0) { | ||
163 | if (friend_con->dht_ip_port.ip.family != 0) { | ||
164 | ip_port.ip = friend_con->dht_ip_port.ip; | ||
165 | } else { | ||
166 | friend_con->hosting_tcp_relay = 0; | ||
167 | } | ||
168 | } | ||
169 | |||
161 | unsigned int i; | 170 | unsigned int i; |
162 | 171 | ||
163 | uint16_t index = friend_con->tcp_relay_counter % FRIEND_MAX_STORED_TCP_RELAYS; | 172 | uint16_t index = friend_con->tcp_relay_counter % FRIEND_MAX_STORED_TCP_RELAYS; |
@@ -265,9 +274,14 @@ static void dht_ip_callback(void *object, int32_t number, IP_Port ip_port) | |||
265 | friend_new_connection(fr_c, number); | 274 | friend_new_connection(fr_c, number); |
266 | } | 275 | } |
267 | 276 | ||
268 | set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, ip_port); | 277 | set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, ip_port, 1); |
269 | friend_con->dht_ip_port = ip_port; | 278 | friend_con->dht_ip_port = ip_port; |
270 | friend_con->dht_ip_port_lastrecv = unix_time(); | 279 | friend_con->dht_ip_port_lastrecv = unix_time(); |
280 | |||
281 | if (friend_con->hosting_tcp_relay) { | ||
282 | friend_add_tcp_relay(fr_c, number, ip_port, friend_con->dht_temp_pk); | ||
283 | friend_con->hosting_tcp_relay = 0; | ||
284 | } | ||
271 | } | 285 | } |
272 | 286 | ||
273 | static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *dht_public_key) | 287 | static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *dht_public_key) |
@@ -317,6 +331,7 @@ static int handle_status(void *object, int number, uint8_t status) | |||
317 | 331 | ||
318 | friend_con->status = FRIENDCONN_STATUS_CONNECTING; | 332 | friend_con->status = FRIENDCONN_STATUS_CONNECTING; |
319 | friend_con->crypt_connection_id = -1; | 333 | friend_con->crypt_connection_id = -1; |
334 | friend_con->hosting_tcp_relay = 0; | ||
320 | } | 335 | } |
321 | 336 | ||
322 | if (call_cb) { | 337 | if (call_cb) { |
@@ -458,7 +473,7 @@ static int handle_new_connections(void *object, New_Connection *n_c) | |||
458 | friend_con->crypt_connection_id = id; | 473 | friend_con->crypt_connection_id = id; |
459 | 474 | ||
460 | if (n_c->source.ip.family != AF_INET && n_c->source.ip.family != AF_INET6) { | 475 | 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); | 476 | set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, friend_con->dht_ip_port, 0); |
462 | } else { | 477 | } else { |
463 | friend_con->dht_ip_port = n_c->source; | 478 | friend_con->dht_ip_port = n_c->source; |
464 | friend_con->dht_ip_port_lastrecv = unix_time(); | 479 | friend_con->dht_ip_port_lastrecv = unix_time(); |
@@ -796,7 +811,7 @@ void do_friend_connections(Friend_Connections *fr_c) | |||
796 | 811 | ||
797 | if (friend_con->dht_lock) { | 812 | if (friend_con->dht_lock) { |
798 | if (friend_new_connection(fr_c, i) == 0) { | 813 | 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); | 814 | 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. */ | 815 | connect_to_saved_tcp_relays(fr_c, i, (MAX_FRIEND_TCP_CONNECTIONS / 2)); /* Only fill it half up. */ |
801 | } | 816 | } |
802 | } | 817 | } |