summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index c98b9d95..521562b8 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -193,6 +193,8 @@ static void dht_pk_callback(void *data, int32_t number, const uint8_t *dht_publi
193 if (friend_not_valid(m, number)) 193 if (friend_not_valid(m, number))
194 return; 194 return;
195 195
196 m->friendlist[number].dht_ping_lastrecv = unix_time();
197
196 if (memcmp(m->friendlist[number].dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES) == 0) 198 if (memcmp(m->friendlist[number].dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES) == 0)
197 return; 199 return;
198 200
@@ -1765,6 +1767,8 @@ static int handle_status(void *object, int i, uint8_t status)
1765 } else { /* Went offline. */ 1767 } else { /* Went offline. */
1766 m->friendlist[i].crypt_connection_id = -1; 1768 m->friendlist[i].crypt_connection_id = -1;
1767 1769
1770 m->friendlist[i].dht_ping_lastrecv = temp_time;
1771
1768 if (m->friendlist[i].status == FRIEND_ONLINE) { 1772 if (m->friendlist[i].status == FRIEND_ONLINE) {
1769 set_friend_status(m, i, FRIEND_CONFIRMED); 1773 set_friend_status(m, i, FRIEND_CONFIRMED);
1770 } 1774 }
@@ -2400,15 +2404,23 @@ void do_friends(Messenger *m)
2400 */ 2404 */
2401 check_friend_request_timed_out(m, i, temp_time); 2405 check_friend_request_timed_out(m, i, temp_time);
2402 2406
2403 if (m->friendlist[i].dht_lock) 2407 } else {
2404 set_connection_dht_public_key(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_temp_pk, 2408 if (m->friendlist[i].dht_ping_lastrecv + FRIEND_DHT_TIMEOUT < temp_time) {
2405 current_time_monotonic()); 2409 if (m->friendlist[i].dht_lock) {
2406 2410 DHT_delfriend(m->dht, m->friendlist[i].dht_temp_pk, m->friendlist[i].dht_lock);
2407 set_direct_ip_port(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_ip_port); 2411 m->friendlist[i].dht_lock = 0;
2408 2412 }
2413 }
2409 } 2414 }
2410 2415
2411 friend_new_connection(m, i, m->friendlist[i].client_id); 2416 friend_new_connection(m, i, m->friendlist[i].client_id);
2417
2418 if (m->friendlist[i].dht_lock)
2419 set_connection_dht_public_key(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_temp_pk,
2420 current_time_monotonic());
2421
2422 set_direct_ip_port(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_ip_port);
2423
2412 } 2424 }
2413 2425
2414 if (m->friendlist[i].status == FRIEND_ONLINE) { /* friend is online. */ 2426 if (m->friendlist[i].status == FRIEND_ONLINE) { /* friend is online. */