diff options
-rw-r--r-- | toxcore/onion_client.c | 54 | ||||
-rw-r--r-- | toxcore/onion_client.h | 9 |
2 files changed, 48 insertions, 15 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 16333e0c..be4d12aa 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -497,21 +497,8 @@ static int handle_fakeid_announce(void *object, uint8_t *source_pubkey, uint8_t | |||
497 | return 1; | 497 | return 1; |
498 | 498 | ||
499 | onion_c->friends_list[friend_num].last_noreplay = no_replay; | 499 | onion_c->friends_list[friend_num].last_noreplay = no_replay; |
500 | 500 | onion_set_friend_DHT_pubkey(onion_c, friend_num, data + 1 + sizeof(uint64_t), current_time_monotonic()); | |
501 | if (memcmp(data + 1 + sizeof(uint64_t), onion_c->friends_list[friend_num].fake_client_id, | 501 | onion_c->friends_list[friend_num].last_seen = unix_time(); |
502 | crypto_box_PUBLICKEYBYTES) != 0) { | ||
503 | DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id); | ||
504 | |||
505 | onion_c->friends_list[friend_num].last_seen = unix_time(); | ||
506 | |||
507 | if (DHT_addfriend(onion_c->dht, data + 1 + sizeof(uint64_t)) == 1) { | ||
508 | return 1; | ||
509 | } | ||
510 | |||
511 | onion_c->friends_list[friend_num].is_fake_clientid = 1; | ||
512 | onion_c->friends_list[friend_num].fake_client_id_timestamp = current_time_monotonic(); | ||
513 | memcpy(onion_c->friends_list[friend_num].fake_client_id, data + 1 + sizeof(uint64_t), crypto_box_PUBLICKEYBYTES); | ||
514 | } | ||
515 | 502 | ||
516 | uint16_t len_nodes = length - FAKEID_DATA_MIN_LENGTH; | 503 | uint16_t len_nodes = length - FAKEID_DATA_MIN_LENGTH; |
517 | 504 | ||
@@ -813,6 +800,43 @@ int onion_delfriend(Onion_Client *onion_c, int friend_num) | |||
813 | return friend_num; | 800 | return friend_num; |
814 | } | 801 | } |
815 | 802 | ||
803 | /* Set a friends DHT public key. | ||
804 | * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to | ||
805 | * the other peer. | ||
806 | * | ||
807 | * return -1 on failure. | ||
808 | * return 0 on success. | ||
809 | */ | ||
810 | int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, uint8_t *dht_key, uint64_t timestamp) | ||
811 | { | ||
812 | if ((uint32_t)friend_num >= onion_c->num_friends) | ||
813 | return -1; | ||
814 | |||
815 | if (onion_c->friends_list[friend_num].status == 0) | ||
816 | return -1; | ||
817 | |||
818 | if (onion_c->friends_list[friend_num].fake_client_id_timestamp >= timestamp) | ||
819 | return -1; | ||
820 | |||
821 | if (onion_c->friends_list[friend_num].is_fake_clientid) { | ||
822 | if (memcmp(dht_key, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES) == 0) { | ||
823 | return -1; | ||
824 | } | ||
825 | |||
826 | DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id); | ||
827 | } | ||
828 | |||
829 | if (DHT_addfriend(onion_c->dht, dht_key) == 1) { | ||
830 | return -1; | ||
831 | } | ||
832 | |||
833 | onion_c->friends_list[friend_num].is_fake_clientid = 1; | ||
834 | onion_c->friends_list[friend_num].fake_client_id_timestamp = timestamp; | ||
835 | memcpy(onion_c->friends_list[friend_num].fake_client_id, dht_key, crypto_box_PUBLICKEYBYTES); | ||
836 | |||
837 | return 0; | ||
838 | } | ||
839 | |||
816 | /* Copy friends DHT public key into dht_key. | 840 | /* Copy friends DHT public key into dht_key. |
817 | * | 841 | * |
818 | * return 0 on failure (no key copied). | 842 | * return 0 on failure (no key copied). |
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index 1d56333a..029f5624 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h | |||
@@ -176,6 +176,15 @@ int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_on | |||
176 | */ | 176 | */ |
177 | int onion_getfriendip(Onion_Client *onion_c, int friend_num, IP_Port *ip_port); | 177 | int onion_getfriendip(Onion_Client *onion_c, int friend_num, IP_Port *ip_port); |
178 | 178 | ||
179 | /* Set a friends DHT public key. | ||
180 | * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to | ||
181 | * the other peer. | ||
182 | * | ||
183 | * return -1 on failure. | ||
184 | * return 0 on success. | ||
185 | */ | ||
186 | int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, uint8_t *dht_key, uint64_t timestamp); | ||
187 | |||
179 | /* Copy friends DHT public key into dht_key. | 188 | /* Copy friends DHT public key into dht_key. |
180 | * | 189 | * |
181 | * return 0 on failure (no key copied). | 190 | * return 0 on failure (no key copied). |