mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Code cleanups.
This commit is contained in:
parent
877257dcd3
commit
4d173d783d
@ -681,7 +681,7 @@ static int handle_data_response(void *object, IP_Port source, const uint8_t *pac
|
||||
|
||||
#define FAKEID_DATA_MIN_LENGTH (1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES)
|
||||
#define FAKEID_DATA_MAX_LENGTH (FAKEID_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES)
|
||||
static int handle_fakeid_announce(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t length)
|
||||
static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t length)
|
||||
{
|
||||
Onion_Client *onion_c = object;
|
||||
|
||||
@ -829,14 +829,14 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data,
|
||||
return good;
|
||||
}
|
||||
|
||||
/* Try to send the fakeid via the DHT instead of onion
|
||||
/* Try to send the dht public key via the DHT instead of onion
|
||||
*
|
||||
* Even if this function succeeds, the friend might not receive any data.
|
||||
*
|
||||
* return the number of packets sent on success
|
||||
* return -1 on failure.
|
||||
*/
|
||||
static int send_dht_fakeid(const Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length)
|
||||
static int send_dht_dhtpk(const Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length)
|
||||
{
|
||||
if ((uint32_t)friend_num >= onion_c->num_friends)
|
||||
return -1;
|
||||
@ -866,8 +866,8 @@ static int send_dht_fakeid(const Onion_Client *onion_c, int friend_num, const ui
|
||||
return route_tofriend(onion_c->dht, onion_c->friends_list[friend_num].dht_public_key, packet, len);
|
||||
}
|
||||
|
||||
static int handle_dht_fakeid(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet,
|
||||
uint16_t length)
|
||||
static int handle_dht_dhtpk(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet,
|
||||
uint16_t length)
|
||||
{
|
||||
Onion_Client *onion_c = object;
|
||||
|
||||
@ -888,7 +888,7 @@ static int handle_dht_fakeid(void *object, IP_Port source, const uint8_t *source
|
||||
if (memcmp(source_pubkey, plain + 1 + sizeof(uint64_t), crypto_box_PUBLICKEYBYTES) != 0)
|
||||
return 1;
|
||||
|
||||
return handle_fakeid_announce(onion_c, packet, plain, len);
|
||||
return handle_dhtpk_announce(onion_c, packet, plain, len);
|
||||
}
|
||||
/* Send the packets to tell our friends what our DHT public key is.
|
||||
*
|
||||
@ -899,7 +899,7 @@ static int handle_dht_fakeid(void *object, IP_Port source, const uint8_t *source
|
||||
* return the number of packets sent on success
|
||||
* return -1 on failure.
|
||||
*/
|
||||
static int send_fakeid_announce(Onion_Client *onion_c, uint16_t friend_num, uint8_t onion_dht_both)
|
||||
static int send_dhtpk_announce(Onion_Client *onion_c, uint16_t friend_num, uint8_t onion_dht_both)
|
||||
{
|
||||
if (friend_num >= onion_c->num_friends)
|
||||
return -1;
|
||||
@ -930,7 +930,7 @@ static int send_fakeid_announce(Onion_Client *onion_c, uint16_t friend_num, uint
|
||||
num1 = send_onion_data(onion_c, friend_num, data, FAKEID_DATA_MIN_LENGTH + nodes_len);
|
||||
|
||||
if (onion_dht_both != 0)
|
||||
num2 = send_dht_fakeid(onion_c, friend_num, data, FAKEID_DATA_MIN_LENGTH + nodes_len);
|
||||
num2 = send_dht_dhtpk(onion_c, friend_num, data, FAKEID_DATA_MIN_LENGTH + nodes_len);
|
||||
|
||||
if (num1 == -1)
|
||||
return num2;
|
||||
@ -1274,13 +1274,13 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
|
||||
++onion_c->friends_list[friendnum].run_count;
|
||||
}
|
||||
|
||||
/* send packets to friend telling them our fake DHT id. */
|
||||
/* send packets to friend telling them our DHT public key. */
|
||||
if (is_timeout(onion_c->friends_list[friendnum].last_dht_pk_onion_sent, ONION_FAKEID_INTERVAL))
|
||||
if (send_fakeid_announce(onion_c, friendnum, 0) >= 1)
|
||||
if (send_dhtpk_announce(onion_c, friendnum, 0) >= 1)
|
||||
onion_c->friends_list[friendnum].last_dht_pk_onion_sent = unix_time();
|
||||
|
||||
if (is_timeout(onion_c->friends_list[friendnum].last_dht_pk_dht_sent, DHT_FAKEID_INTERVAL))
|
||||
if (send_fakeid_announce(onion_c, friendnum, 1) >= 1)
|
||||
if (send_dhtpk_announce(onion_c, friendnum, 1) >= 1)
|
||||
onion_c->friends_list[friendnum].last_dht_pk_dht_sent = unix_time();
|
||||
|
||||
}
|
||||
@ -1395,8 +1395,8 @@ Onion_Client *new_onion_client(Net_Crypto *c)
|
||||
crypto_box_keypair(onion_c->temp_public_key, onion_c->temp_secret_key);
|
||||
networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_announce_response, onion_c);
|
||||
networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_data_response, onion_c);
|
||||
oniondata_registerhandler(onion_c, ONION_DATA_FAKEID, &handle_fakeid_announce, onion_c);
|
||||
cryptopacket_registerhandler(onion_c->dht, CRYPTO_PACKET_FAKEID, &handle_dht_fakeid, onion_c);
|
||||
oniondata_registerhandler(onion_c, ONION_DATA_FAKEID, &handle_dhtpk_announce, onion_c);
|
||||
cryptopacket_registerhandler(onion_c->dht, CRYPTO_PACKET_FAKEID, &handle_dht_dhtpk, onion_c);
|
||||
tcp_onion_response_handler(onion_c->c, &handle_tcp_onion, onion_c);
|
||||
|
||||
return onion_c;
|
||||
|
Loading…
x
Reference in New Issue
Block a user