diff options
author | irungentoo <irungentoo@gmail.com> | 2015-05-18 20:40:18 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-05-18 20:40:18 -0400 |
commit | 19192920249965fda8931e667bfbffddaeba502c (patch) | |
tree | b14800cde0e68a9cfed1936e4960b7aa23df1fea /toxcore/friend_connection.c | |
parent | 40f113c0773d239a107d7085e3f72468e5014f9b (diff) |
If we get the ip/port of a relay on a local ip, assume that our friend
is hosting a relay on his ip.
Diffstat (limited to 'toxcore/friend_connection.c')
-rw-r--r-- | toxcore/friend_connection.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index de34e570..7dd8e3e3 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c | |||
@@ -158,6 +158,20 @@ 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 means that they are hosting a TCP relay. */ | ||
162 | if (Local_ip(ip_port.ip)) { | ||
163 | if (friend_con->dht_ip_port.ip.family != 0) { | ||
164 | ip_port.ip = friend_con->dht_ip_port.ip; | ||
165 | } else { | ||
166 | if (memcmp(friend_con->dht_temp_pk, public_key, crypto_box_PUBLICKEYBYTES) == 0) { | ||
167 | friend_con->hosting_tcp_relay = 0; | ||
168 | return 0; | ||
169 | } else { | ||
170 | return -1; | ||
171 | } | ||
172 | } | ||
173 | } | ||
174 | |||
161 | unsigned int i; | 175 | unsigned int i; |
162 | 176 | ||
163 | uint16_t index = friend_con->tcp_relay_counter % FRIEND_MAX_STORED_TCP_RELAYS; | 177 | uint16_t index = friend_con->tcp_relay_counter % FRIEND_MAX_STORED_TCP_RELAYS; |
@@ -268,6 +282,11 @@ static void dht_ip_callback(void *object, int32_t number, IP_Port ip_port) | |||
268 | set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, ip_port, 1); | 282 | set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, ip_port, 1); |
269 | friend_con->dht_ip_port = ip_port; | 283 | friend_con->dht_ip_port = ip_port; |
270 | friend_con->dht_ip_port_lastrecv = unix_time(); | 284 | friend_con->dht_ip_port_lastrecv = unix_time(); |
285 | |||
286 | if (friend_con->hosting_tcp_relay) { | ||
287 | friend_add_tcp_relay(fr_c, number, ip_port, friend_con->dht_temp_pk); | ||
288 | friend_con->hosting_tcp_relay = 0; | ||
289 | } | ||
271 | } | 290 | } |
272 | 291 | ||
273 | static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *dht_public_key) | 292 | static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *dht_public_key) |
@@ -317,6 +336,7 @@ static int handle_status(void *object, int number, uint8_t status) | |||
317 | 336 | ||
318 | friend_con->status = FRIENDCONN_STATUS_CONNECTING; | 337 | friend_con->status = FRIENDCONN_STATUS_CONNECTING; |
319 | friend_con->crypt_connection_id = -1; | 338 | friend_con->crypt_connection_id = -1; |
339 | friend_con->hosting_tcp_relay = 0; | ||
320 | } | 340 | } |
321 | 341 | ||
322 | if (call_cb) { | 342 | if (call_cb) { |