summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index ced1e845..267670f9 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -885,7 +885,12 @@ static IP_Port get_friend_ipport(Messenger *m, int32_t friendnumber)
885 885
886 int crypt_id = m->friendlist[friendnumber].crypt_connection_id; 886 int crypt_id = m->friendlist[friendnumber].crypt_connection_id;
887 887
888 if (is_cryptoconnected(m->net_crypto, crypt_id) != CRYPTO_CONN_ESTABLISHED) 888 uint8_t direct_connected;
889
890 if (crypto_connection_status(m->net_crypto, crypt_id, &direct_connected) != CRYPTO_CONN_ESTABLISHED)
891 return zero;
892
893 if (direct_connected == 0)
889 return zero; 894 return zero;
890 895
891 return m->net_crypto->crypto_connections[crypt_id].ip_port; 896 return m->net_crypto->crypto_connections[crypt_id].ip_port;
@@ -2201,10 +2206,15 @@ void do_friends(Messenger *m)
2201 set_conection_dht_public_key(m->net_crypto, m->friendlist[i].crypt_connection_id, dht_public_key); 2206 set_conection_dht_public_key(m->net_crypto, m->friendlist[i].crypt_connection_id, dht_public_key);
2202 } 2207 }
2203 2208
2204 IP_Port friendip; 2209 uint8_t direct_connected;
2210 unsigned int status = crypto_connection_status(m->net_crypto, m->friendlist[i].crypt_connection_id, &direct_connected);
2205 2211
2206 if (onion_getfriendip(m->onion_c, m->friendlist[i].onion_friendnum, &friendip) == 1) { 2212 if (direct_connected == 0 || status == CRYPTO_CONN_COOKIE_REQUESTING) {
2207 set_direct_ip_port(m->net_crypto, m->friendlist[i].crypt_connection_id, friendip); 2213 IP_Port friendip;
2214
2215 if (onion_getfriendip(m->onion_c, m->friendlist[i].onion_friendnum, &friendip) == 1) {
2216 set_direct_ip_port(m->net_crypto, m->friendlist[i].crypt_connection_id, friendip);
2217 }
2208 } 2218 }
2209 } 2219 }
2210 2220
@@ -2233,13 +2243,6 @@ void do_friends(Messenger *m)
2233 send_ping(m, i); 2243 send_ping(m, i);
2234 } 2244 }
2235 2245
2236 if (is_cryptoconnected(m->net_crypto,
2237 m->friendlist[i].crypt_connection_id) == CRYPTO_CONN_TIMED_OUT) { /* If the connection timed out, kill it. */
2238 crypto_kill(m->net_crypto, m->friendlist[i].crypt_connection_id);
2239 m->friendlist[i].crypt_connection_id = -1;
2240 set_friend_status(m, i, FRIEND_CONFIRMED);
2241 }
2242
2243 if (m->friendlist[i].ping_lastrecv + FRIEND_CONNECTION_TIMEOUT < temp_time) { 2246 if (m->friendlist[i].ping_lastrecv + FRIEND_CONNECTION_TIMEOUT < temp_time) {
2244 /* If we stopped receiving ping packets, kill it. */ 2247 /* If we stopped receiving ping packets, kill it. */
2245 crypto_kill(m->net_crypto, m->friendlist[i].crypt_connection_id); 2248 crypto_kill(m->net_crypto, m->friendlist[i].crypt_connection_id);