summaryrefslogtreecommitdiff
path: root/toxcore/onion_client.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r--toxcore/onion_client.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index c7ebcd15..ca92ee42 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -796,14 +796,12 @@ int onion_delfriend(Onion_Client *onion_c, int friend_num)
796 return friend_num; 796 return friend_num;
797} 797}
798 798
799/* Get the ip of friend friendnum and put it in ip_port 799/* Copy friends DHT public key into dht_key.
800 *
801 * return -1, -- if client_id does NOT refer to a friend
802 * return 0, -- if client_id refers to a friend and we failed to find the friend (yet)
803 * return 1, ip if client_id refers to a friend and we found him
804 * 800 *
801 * return -1 on failure (no key copied).
802 * return 0 on success (key copied).
805 */ 803 */
806int onion_getfriendip(Onion_Client *onion_c, int friend_num, IP_Port *ip_port) 804int onion_getfriend_DHT_pubkey(Onion_Client *onion_c, int friend_num, uint8_t *dht_key)
807{ 805{
808 if ((uint32_t)friend_num >= onion_c->num_friends) 806 if ((uint32_t)friend_num >= onion_c->num_friends)
809 return -1; 807 return -1;
@@ -814,9 +812,28 @@ int onion_getfriendip(Onion_Client *onion_c, int friend_num, IP_Port *ip_port)
814 if (!onion_c->friends_list[friend_num].is_fake_clientid) 812 if (!onion_c->friends_list[friend_num].is_fake_clientid)
815 return -1; 813 return -1;
816 814
817 return DHT_getfriendip(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id, ip_port); 815 memcpy(dht_key, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES);
816 return 0;
817}
818
819/* Get the ip of friend friendnum and put it in ip_port
820 *
821 * return -1, -- if client_id does NOT refer to a friend
822 * return 0, -- if client_id refers to a friend and we failed to find the friend (yet)
823 * return 1, ip if client_id refers to a friend and we found him
824 *
825 */
826int onion_getfriendip(Onion_Client *onion_c, int friend_num, IP_Port *ip_port)
827{
828 uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES];
829
830 if (onion_getfriend_DHT_pubkey(onion_c, friend_num, dht_public_key) != 0)
831 return -1;
832
833 return DHT_getfriendip(onion_c->dht, dht_public_key, ip_port);
818} 834}
819 835
836
820/* Set if friend is online or not. 837/* Set if friend is online or not.
821 * NOTE: This function is there and should be used so that we don't send useless packets to the friend if he is online. 838 * NOTE: This function is there and should be used so that we don't send useless packets to the friend if he is online.
822 * 839 *