diff options
-rw-r--r-- | toxcore/Messenger.c | 24 | ||||
-rw-r--r-- | toxcore/Messenger.h | 2 | ||||
-rw-r--r-- | toxcore/onion_client.c | 18 |
3 files changed, 20 insertions, 24 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. */ |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 2cbc57e5..36da8425 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -120,6 +120,7 @@ enum { | |||
120 | #define AVATAR_DATA_TRANSFER_LIMIT (10*AVATAR_MAX_DATA_LENGTH) | 120 | #define AVATAR_DATA_TRANSFER_LIMIT (10*AVATAR_MAX_DATA_LENGTH) |
121 | #define AVATAR_DATA_TRANSFER_TIMEOUT (60) /* 164kB every 60 seconds is not a lot */ | 121 | #define AVATAR_DATA_TRANSFER_TIMEOUT (60) /* 164kB every 60 seconds is not a lot */ |
122 | 122 | ||
123 | #define FRIEND_DHT_TIMEOUT (5 * 60) /* Time before friend is removed from the DHT after last hearing about him. */ | ||
123 | 124 | ||
124 | /* USERSTATUS - | 125 | /* USERSTATUS - |
125 | * Represents userstatuses someone can have. | 126 | * Represents userstatuses someone can have. |
@@ -200,6 +201,7 @@ typedef struct { | |||
200 | uint8_t dht_temp_pk[crypto_box_PUBLICKEYBYTES]; | 201 | uint8_t dht_temp_pk[crypto_box_PUBLICKEYBYTES]; |
201 | uint16_t dht_lock; | 202 | uint16_t dht_lock; |
202 | IP_Port dht_ip_port; | 203 | IP_Port dht_ip_port; |
204 | uint64_t dht_ping_lastrecv; | ||
203 | 205 | ||
204 | uint32_t onion_friendnum; | 206 | uint32_t onion_friendnum; |
205 | int crypt_connection_id; | 207 | int crypt_connection_id; |
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 97afeb79..8ba1fdc5 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -1204,23 +1204,6 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) | |||
1204 | } | 1204 | } |
1205 | } | 1205 | } |
1206 | 1206 | ||
1207 | /* Timeout before which a peer is considered dead and removed from the DHT search. */ | ||
1208 | #define DEAD_ONION_TIMEOUT (10 * 60) | ||
1209 | |||
1210 | static void cleanup_friend(Onion_Client *onion_c, uint16_t friendnum) | ||
1211 | { | ||
1212 | if (friendnum >= onion_c->num_friends) | ||
1213 | return; | ||
1214 | |||
1215 | if (onion_c->friends_list[friendnum].status == 0) | ||
1216 | return; | ||
1217 | |||
1218 | if (onion_c->friends_list[friendnum].is_fake_clientid && !onion_c->friends_list[friendnum].is_online | ||
1219 | && is_timeout(onion_c->friends_list[friendnum].last_seen, DEAD_ONION_TIMEOUT)) { | ||
1220 | onion_c->friends_list[friendnum].is_fake_clientid = 0; | ||
1221 | //DHT_delfriend(onion_c->dht, onion_c->friends_list[friendnum].fake_client_id, 0); | ||
1222 | } | ||
1223 | } | ||
1224 | 1207 | ||
1225 | /* Function to call when onion data packet with contents beginning with byte is received. */ | 1208 | /* Function to call when onion data packet with contents beginning with byte is received. */ |
1226 | void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_handler_callback cb, void *object) | 1209 | void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_handler_callback cb, void *object) |
@@ -1293,7 +1276,6 @@ void do_onion_client(Onion_Client *onion_c) | |||
1293 | if (onion_isconnected(onion_c)) { | 1276 | if (onion_isconnected(onion_c)) { |
1294 | for (i = 0; i < onion_c->num_friends; ++i) { | 1277 | for (i = 0; i < onion_c->num_friends; ++i) { |
1295 | do_friend(onion_c, i); | 1278 | do_friend(onion_c, i); |
1296 | cleanup_friend(onion_c, i); | ||
1297 | } | 1279 | } |
1298 | } | 1280 | } |
1299 | 1281 | ||