diff options
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r-- | toxcore/onion_client.c | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 56c79cc5..97afeb79 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -638,9 +638,12 @@ static int handle_fakeid_announce(void *object, const uint8_t *source_pubkey, co | |||
638 | return 1; | 638 | return 1; |
639 | 639 | ||
640 | onion_c->friends_list[friend_num].last_noreplay = no_replay; | 640 | onion_c->friends_list[friend_num].last_noreplay = no_replay; |
641 | |||
641 | if (onion_c->friends_list[friend_num].dht_pk_callback) | 642 | if (onion_c->friends_list[friend_num].dht_pk_callback) |
642 | onion_c->friends_list[friend_num].dht_pk_callback(onion_c->friends_list[friend_num].dht_pk_callback_object, onion_c->friends_list[friend_num].dht_pk_callback_number, data + 1 + sizeof(uint64_t)); | 643 | onion_c->friends_list[friend_num].dht_pk_callback(onion_c->friends_list[friend_num].dht_pk_callback_object, |
643 | //onion_set_friend_DHT_pubkey(onion_c, friend_num, data + 1 + sizeof(uint64_t), current_time_monotonic()); | 644 | onion_c->friends_list[friend_num].dht_pk_callback_number, data + 1 + sizeof(uint64_t)); |
645 | |||
646 | onion_set_friend_DHT_pubkey(onion_c, friend_num, data + 1 + sizeof(uint64_t)); | ||
644 | onion_c->friends_list[friend_num].last_seen = unix_time(); | 647 | onion_c->friends_list[friend_num].last_seen = unix_time(); |
645 | 648 | ||
646 | uint16_t len_nodes = length - FAKEID_DATA_MIN_LENGTH; | 649 | uint16_t len_nodes = length - FAKEID_DATA_MIN_LENGTH; |
@@ -1006,7 +1009,8 @@ int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_rela | |||
1006 | * return -1 on failure. | 1009 | * return -1 on failure. |
1007 | * return 0 on success. | 1010 | * return 0 on success. |
1008 | */ | 1011 | */ |
1009 | int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function)(void *data, int32_t number, const uint8_t *dht_public_key), void *object, uint32_t number) | 1012 | int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function)(void *data, int32_t number, |
1013 | const uint8_t *dht_public_key), void *object, uint32_t number) | ||
1010 | { | 1014 | { |
1011 | if ((uint32_t)friend_num >= onion_c->num_friends) | 1015 | if ((uint32_t)friend_num >= onion_c->num_friends) |
1012 | return -1; | 1016 | return -1; |
@@ -1018,13 +1022,11 @@ int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function | |||
1018 | } | 1022 | } |
1019 | 1023 | ||
1020 | /* Set a friends DHT public key. | 1024 | /* Set a friends DHT public key. |
1021 | * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to | ||
1022 | * the other peer. | ||
1023 | * | 1025 | * |
1024 | * return -1 on failure. | 1026 | * return -1 on failure. |
1025 | * return 0 on success. | 1027 | * return 0 on success. |
1026 | */ | 1028 | */ |
1027 | int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key, uint64_t timestamp) | 1029 | int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key) |
1028 | { | 1030 | { |
1029 | if ((uint32_t)friend_num >= onion_c->num_friends) | 1031 | if ((uint32_t)friend_num >= onion_c->num_friends) |
1030 | return -1; | 1032 | return -1; |
@@ -1032,25 +1034,16 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin | |||
1032 | if (onion_c->friends_list[friend_num].status == 0) | 1034 | if (onion_c->friends_list[friend_num].status == 0) |
1033 | return -1; | 1035 | return -1; |
1034 | 1036 | ||
1035 | if (onion_c->friends_list[friend_num].fake_client_id_timestamp >= timestamp) | ||
1036 | return -1; | ||
1037 | |||
1038 | if (onion_c->friends_list[friend_num].is_fake_clientid) { | 1037 | if (onion_c->friends_list[friend_num].is_fake_clientid) { |
1039 | if (memcmp(dht_key, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES) == 0) { | 1038 | if (memcmp(dht_key, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES) == 0) { |
1040 | return -1; | 1039 | return -1; |
1041 | } | 1040 | } |
1042 | 1041 | ||
1043 | //DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id, 0); | ||
1044 | onion_c->friends_list[friend_num].is_fake_clientid = 0; | 1042 | onion_c->friends_list[friend_num].is_fake_clientid = 0; |
1045 | } | 1043 | } |
1046 | 1044 | ||
1047 | //if (DHT_addfriend(onion_c->dht, dht_key, 0, 0, 0, 0) == -1) { | ||
1048 | // return -1; | ||
1049 | //} | ||
1050 | |||
1051 | onion_c->friends_list[friend_num].last_seen = unix_time(); | 1045 | onion_c->friends_list[friend_num].last_seen = unix_time(); |
1052 | onion_c->friends_list[friend_num].is_fake_clientid = 1; | 1046 | onion_c->friends_list[friend_num].is_fake_clientid = 1; |
1053 | onion_c->friends_list[friend_num].fake_client_id_timestamp = timestamp; | ||
1054 | memcpy(onion_c->friends_list[friend_num].fake_client_id, dht_key, crypto_box_PUBLICKEYBYTES); | 1047 | memcpy(onion_c->friends_list[friend_num].fake_client_id, dht_key, crypto_box_PUBLICKEYBYTES); |
1055 | 1048 | ||
1056 | return 0; | 1049 | return 0; |
@@ -1059,9 +1052,9 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin | |||
1059 | /* Copy friends DHT public key into dht_key. | 1052 | /* Copy friends DHT public key into dht_key. |
1060 | * | 1053 | * |
1061 | * return 0 on failure (no key copied). | 1054 | * return 0 on failure (no key copied). |
1062 | * return timestamp on success (key copied). | 1055 | * return 1 on success (key copied). |
1063 | */ | 1056 | */ |
1064 | uint64_t onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key) | 1057 | unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key) |
1065 | { | 1058 | { |
1066 | if ((uint32_t)friend_num >= onion_c->num_friends) | 1059 | if ((uint32_t)friend_num >= onion_c->num_friends) |
1067 | return 0; | 1060 | return 0; |
@@ -1073,7 +1066,7 @@ uint64_t onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, | |||
1073 | return 0; | 1066 | return 0; |
1074 | 1067 | ||
1075 | memcpy(dht_key, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES); | 1068 | memcpy(dht_key, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES); |
1076 | return onion_c->friends_list[friend_num].fake_client_id_timestamp; | 1069 | return 1; |
1077 | } | 1070 | } |
1078 | 1071 | ||
1079 | /* Get the ip of friend friendnum and put it in ip_port | 1072 | /* Get the ip of friend friendnum and put it in ip_port |