From c618263acd7e2ed76befe3c4b6211f8ba15ee79c Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 26 Sep 2014 20:43:59 -0400 Subject: [PATCH] Removed useless code from onion_client. Astyled. --- toxcore/Messenger.c | 9 ++++++--- toxcore/net_crypto.c | 3 ++- toxcore/net_crypto.h | 3 ++- toxcore/onion_client.c | 29 +++++++++++------------------ toxcore/onion_client.h | 10 +++++----- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 8229c270..c98b9d95 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -211,8 +211,9 @@ static void dht_pk_callback(void *data, int32_t number, const uint8_t *dht_publi friend_new_connection(m, number, m->friendlist[number].client_id); } - set_connection_dht_public_key(m->net_crypto, m->friendlist[number].crypt_connection_id, dht_public_key, current_time_monotonic()); - onion_set_friend_DHT_pubkey(m->onion_c, m->friendlist[number].onion_friendnum, dht_public_key, current_time_monotonic()); + set_connection_dht_public_key(m->net_crypto, m->friendlist[number].crypt_connection_id, dht_public_key, + current_time_monotonic()); + onion_set_friend_DHT_pubkey(m->onion_c, m->friendlist[number].onion_friendnum, dht_public_key); memcpy(m->friendlist[number].dht_temp_pk, dht_public_key, crypto_box_PUBLICKEYBYTES); } @@ -389,6 +390,7 @@ int m_delfriend(Messenger *m, int32_t friendnumber) remove_online_friend(m, friendnumber); onion_delfriend(m->onion_c, m->friendlist[friendnumber].onion_friendnum); + if (m->friendlist[friendnumber].dht_lock) { DHT_delfriend(m->dht, m->friendlist[friendnumber].dht_temp_pk, m->friendlist[friendnumber].dht_lock); } @@ -2399,7 +2401,8 @@ void do_friends(Messenger *m) check_friend_request_timed_out(m, i, temp_time); if (m->friendlist[i].dht_lock) - set_connection_dht_public_key(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_temp_pk, current_time_monotonic()); + set_connection_dht_public_key(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_temp_pk, + current_time_monotonic()); set_direct_ip_port(m->net_crypto, m->friendlist[i].crypt_connection_id, m->friendlist[i].dht_ip_port); diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 1d93bc6a..a286df2a 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -2260,7 +2260,8 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id, * return -1 on failure. * return 0 on success. */ -int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(void *data, int32_t number, const uint8_t *dht_public_key), void *object, uint32_t number) +int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(void *data, int32_t number, + const uint8_t *dht_public_key), void *object, uint32_t number) { Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index 8c77a7a1..cfa7c576 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h @@ -306,7 +306,8 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id, * return -1 on failure. * return 0 on success. */ -int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(void *data, int32_t number, const uint8_t *dht_public_key), void *object, uint32_t number); +int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(void *data, int32_t number, + const uint8_t *dht_public_key), void *object, uint32_t number); /* returns the number of packet slots left in the sendbuffer. * return 0 if failure. 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 return 1; onion_c->friends_list[friend_num].last_noreplay = no_replay; + if (onion_c->friends_list[friend_num].dht_pk_callback) - 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)); - //onion_set_friend_DHT_pubkey(onion_c, friend_num, data + 1 + sizeof(uint64_t), current_time_monotonic()); + 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)); + + onion_set_friend_DHT_pubkey(onion_c, friend_num, data + 1 + sizeof(uint64_t)); onion_c->friends_list[friend_num].last_seen = unix_time(); 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 * return -1 on failure. * return 0 on success. */ -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) +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) { if ((uint32_t)friend_num >= onion_c->num_friends) return -1; @@ -1018,13 +1022,11 @@ int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function } /* Set a friends DHT public key. - * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to - * the other peer. * * return -1 on failure. * return 0 on success. */ -int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key, uint64_t timestamp) +int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key) { if ((uint32_t)friend_num >= onion_c->num_friends) return -1; @@ -1032,25 +1034,16 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin if (onion_c->friends_list[friend_num].status == 0) return -1; - if (onion_c->friends_list[friend_num].fake_client_id_timestamp >= timestamp) - return -1; - if (onion_c->friends_list[friend_num].is_fake_clientid) { if (memcmp(dht_key, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES) == 0) { return -1; } - //DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id, 0); onion_c->friends_list[friend_num].is_fake_clientid = 0; } - //if (DHT_addfriend(onion_c->dht, dht_key, 0, 0, 0, 0) == -1) { - // return -1; - //} - onion_c->friends_list[friend_num].last_seen = unix_time(); onion_c->friends_list[friend_num].is_fake_clientid = 1; - onion_c->friends_list[friend_num].fake_client_id_timestamp = timestamp; memcpy(onion_c->friends_list[friend_num].fake_client_id, dht_key, crypto_box_PUBLICKEYBYTES); return 0; @@ -1059,9 +1052,9 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin /* Copy friends DHT public key into dht_key. * * return 0 on failure (no key copied). - * return timestamp on success (key copied). + * return 1 on success (key copied). */ -uint64_t onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key) +unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key) { if ((uint32_t)friend_num >= onion_c->num_friends) return 0; @@ -1073,7 +1066,7 @@ uint64_t onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, return 0; memcpy(dht_key, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES); - return onion_c->friends_list[friend_num].fake_client_id_timestamp; + return 1; } /* Get the ip of friend friendnum and put it in ip_port diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index 5b89a8d9..3143f93a 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h @@ -79,7 +79,6 @@ typedef struct { uint8_t is_online; /* Set by the onion_set_friend_status function. */ uint8_t is_fake_clientid; /* 0 if we don't know the fake client id of the other 1 if we do. */ - uint64_t fake_client_id_timestamp; uint8_t fake_client_id[crypto_box_PUBLICKEYBYTES]; uint8_t real_client_id[crypto_box_PUBLICKEYBYTES]; @@ -218,7 +217,8 @@ int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_rela * return -1 on failure. * return 0 on success. */ -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); +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); /* Set a friends DHT public key. * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to @@ -227,14 +227,14 @@ int onion_dht_pk_callback(Onion_Client *onion_c, int friend_num, void (*function * return -1 on failure. * return 0 on success. */ -int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key, uint64_t timestamp); +int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key); /* Copy friends DHT public key into dht_key. * * return 0 on failure (no key copied). - * return timestamp on success (key copied). + * return 1 on success (key copied). */ -uint64_t onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key); +unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key); #define ONION_DATA_IN_RESPONSE_MIN_SIZE (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES) #define ONION_CLIENT_MAX_DATA_SIZE (MAX_DATA_REQUEST_SIZE - ONION_DATA_IN_RESPONSE_MIN_SIZE)