diff options
author | zugz (tox) <mbays+tox@sdf.org> | 2018-09-24 21:38:06 +0200 |
---|---|---|
committer | zugz (tox) <mbays+tox@sdf.org> | 2018-09-25 00:08:08 +0200 |
commit | d5d6e3f60f22aee2735cb80db407c201a00e357b (patch) | |
tree | 67c537922c3a65f51bcf93d1635dc6ca45b647c8 /toxcore/onion_client.c | |
parent | b694dbc2234928682efeb0ec6e79b97751036d4c (diff) |
Combine last_reported_announced with last_seen in Onion_Friend
This resets friend search rate in two circumstances where it should be
reset:
* When the friend gets a dhtpk packet to us;
* When a friend connection to the friend goes down.
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r-- | toxcore/onion_client.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 87b0c79c..1c3b34da 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -84,8 +84,6 @@ typedef struct Onion_Friend { | |||
84 | uint8_t temp_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | 84 | uint8_t temp_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
85 | uint8_t temp_secret_key[CRYPTO_SECRET_KEY_SIZE]; | 85 | uint8_t temp_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
86 | 86 | ||
87 | uint64_t last_reported_announced; | ||
88 | |||
89 | uint64_t last_dht_pk_onion_sent; | 87 | uint64_t last_dht_pk_onion_sent; |
90 | uint64_t last_dht_pk_dht_sent; | 88 | uint64_t last_dht_pk_dht_sent; |
91 | 89 | ||
@@ -700,7 +698,7 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t | |||
700 | } | 698 | } |
701 | 699 | ||
702 | if (is_stored == 1) { | 700 | if (is_stored == 1) { |
703 | onion_c->friends_list[num - 1].last_reported_announced = mono_time_get(onion_c->mono_time); | 701 | onion_c->friends_list[num - 1].last_seen = mono_time_get(onion_c->mono_time); |
704 | } | 702 | } |
705 | 703 | ||
706 | list_nodes = onion_c->friends_list[num - 1].clients_list; | 704 | list_nodes = onion_c->friends_list[num - 1].clients_list; |
@@ -1403,7 +1401,7 @@ int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, | |||
1403 | return 0; | 1401 | return 0; |
1404 | } | 1402 | } |
1405 | 1403 | ||
1406 | /* Set a friends DHT public key. | 1404 | /* Set a friend's DHT public key. |
1407 | * | 1405 | * |
1408 | * return -1 on failure. | 1406 | * return -1 on failure. |
1409 | * return 0 on success. | 1407 | * return 0 on success. |
@@ -1422,8 +1420,6 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin | |||
1422 | if (public_key_cmp(dht_key, onion_c->friends_list[friend_num].dht_public_key) == 0) { | 1420 | if (public_key_cmp(dht_key, onion_c->friends_list[friend_num].dht_public_key) == 0) { |
1423 | return -1; | 1421 | return -1; |
1424 | } | 1422 | } |
1425 | |||
1426 | onion_c->friends_list[friend_num].know_dht_public_key = 0; | ||
1427 | } | 1423 | } |
1428 | 1424 | ||
1429 | onion_c->friends_list[friend_num].last_seen = mono_time_get(onion_c->mono_time); | 1425 | onion_c->friends_list[friend_num].last_seen = mono_time_get(onion_c->mono_time); |
@@ -1553,12 +1549,12 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) | |||
1553 | if (onion_c->friends_list[friendnum].run_count < RUN_COUNT_FRIEND_ANNOUNCE_BEGINNING) { | 1549 | if (onion_c->friends_list[friendnum].run_count < RUN_COUNT_FRIEND_ANNOUNCE_BEGINNING) { |
1554 | interval = ANNOUNCE_FRIEND_BEGINNING; | 1550 | interval = ANNOUNCE_FRIEND_BEGINNING; |
1555 | } else { | 1551 | } else { |
1556 | if (onion_c->friends_list[friendnum].last_reported_announced == 0) { | 1552 | if (onion_c->friends_list[friendnum].last_seen == 0) { |
1557 | onion_c->friends_list[friendnum].last_reported_announced = mono_time_get(onion_c->mono_time); | 1553 | onion_c->friends_list[friendnum].last_seen = mono_time_get(onion_c->mono_time); |
1558 | } | 1554 | } |
1559 | 1555 | ||
1560 | uint64_t backoff_interval = (mono_time_get(onion_c->mono_time) - | 1556 | uint64_t backoff_interval = (mono_time_get(onion_c->mono_time) - |
1561 | onion_c->friends_list[friendnum].last_reported_announced) | 1557 | onion_c->friends_list[friendnum].last_seen) |
1562 | / ONION_FRIEND_BACKOFF_FACTOR; | 1558 | / ONION_FRIEND_BACKOFF_FACTOR; |
1563 | 1559 | ||
1564 | if (backoff_interval > ONION_FRIEND_MAX_PING_INTERVAL) { | 1560 | if (backoff_interval > ONION_FRIEND_MAX_PING_INTERVAL) { |