mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Make Onion_Client a module-private type.
This commit is contained in:
parent
d8fcac5b4f
commit
c28d362dd2
|
@ -322,7 +322,7 @@ static void kill_onions(Onions *on)
|
|||
{
|
||||
Networking_Core *net = on->onion->dht->net;
|
||||
DHT *dht = on->onion->dht;
|
||||
Net_Crypto *c = on->onion_c->c;
|
||||
Net_Crypto *c = onion_get_net_crypto(on->onion_c);
|
||||
kill_onion_client(on->onion_c);
|
||||
kill_onion_announce(on->onion_a);
|
||||
kill_onion(on->onion);
|
||||
|
@ -437,8 +437,10 @@ START_TEST(test_announce)
|
|||
memcpy(last_dht_pk, onions[NUM_LAST]->onion->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
|
||||
printf("adding friend\n");
|
||||
int frnum_f = onion_addfriend(onions[NUM_FIRST]->onion_c, onions[NUM_LAST]->onion_c->c->self_public_key);
|
||||
int frnum = onion_addfriend(onions[NUM_LAST]->onion_c, onions[NUM_FIRST]->onion_c->c->self_public_key);
|
||||
int frnum_f = onion_addfriend(onions[NUM_FIRST]->onion_c,
|
||||
onion_get_net_crypto(onions[NUM_LAST]->onion_c)->self_public_key);
|
||||
int frnum = onion_addfriend(onions[NUM_LAST]->onion_c,
|
||||
onion_get_net_crypto(onions[NUM_FIRST]->onion_c)->self_public_key);
|
||||
|
||||
onion_dht_pk_callback(onions[NUM_FIRST]->onion_c, frnum_f, &dht_pk_callback, onions[NUM_FIRST], NUM_FIRST);
|
||||
onion_dht_pk_callback(onions[NUM_LAST]->onion_c, frnum, &dht_pk_callback, onions[NUM_LAST], NUM_LAST);
|
||||
|
|
|
@ -825,8 +825,8 @@ Friend_Connections *new_friend_connections(Onion_Client *onion_c, bool local_dis
|
|||
return NULL;
|
||||
}
|
||||
|
||||
temp->dht = onion_c->dht;
|
||||
temp->net_crypto = onion_c->c;
|
||||
temp->dht = onion_get_dht(onion_c);
|
||||
temp->net_crypto = onion_get_net_crypto(onion_c);
|
||||
temp->onion_c = onion_c;
|
||||
temp->local_discovery_enabled = local_discovery_enabled;
|
||||
// Don't include default port in port range
|
||||
|
|
|
@ -36,6 +36,123 @@
|
|||
#define ANNOUNCE_ARRAY_SIZE 256
|
||||
#define ANNOUNCE_TIMEOUT 10
|
||||
|
||||
typedef struct {
|
||||
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
IP_Port ip_port;
|
||||
uint8_t ping_id[ONION_PING_ID_SIZE];
|
||||
uint8_t data_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t is_stored;
|
||||
|
||||
uint64_t added_time;
|
||||
|
||||
uint64_t timestamp;
|
||||
|
||||
uint64_t last_pinged;
|
||||
|
||||
uint8_t unsuccessful_pings;
|
||||
|
||||
uint32_t path_used;
|
||||
} Onion_Node;
|
||||
|
||||
typedef struct {
|
||||
Onion_Path paths[NUMBER_ONION_PATHS];
|
||||
uint64_t last_path_success[NUMBER_ONION_PATHS];
|
||||
uint64_t last_path_used[NUMBER_ONION_PATHS];
|
||||
uint64_t path_creation_time[NUMBER_ONION_PATHS];
|
||||
/* number of times used without success. */
|
||||
unsigned int last_path_used_times[NUMBER_ONION_PATHS];
|
||||
} Onion_Client_Paths;
|
||||
|
||||
typedef struct {
|
||||
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint64_t timestamp;
|
||||
} Last_Pinged;
|
||||
|
||||
typedef struct {
|
||||
uint8_t status; /* 0 if friend is not valid, 1 if friend is valid.*/
|
||||
uint8_t is_online; /* Set by the onion_set_friend_status function. */
|
||||
|
||||
uint8_t know_dht_public_key; /* 0 if we don't know the dht public key of the other, 1 if we do. */
|
||||
uint8_t dht_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t real_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
|
||||
Onion_Node clients_list[MAX_ONION_CLIENTS];
|
||||
uint8_t temp_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t temp_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
|
||||
uint64_t last_reported_announced;
|
||||
|
||||
uint64_t last_dht_pk_onion_sent;
|
||||
uint64_t last_dht_pk_dht_sent;
|
||||
|
||||
uint64_t last_noreplay;
|
||||
|
||||
uint64_t last_seen;
|
||||
|
||||
Last_Pinged last_pinged[MAX_STORED_PINGED_NODES];
|
||||
uint8_t last_pinged_index;
|
||||
|
||||
int (*tcp_relay_node_callback)(void *object, uint32_t number, IP_Port ip_port, const uint8_t *public_key);
|
||||
void *tcp_relay_node_callback_object;
|
||||
uint32_t tcp_relay_node_callback_number;
|
||||
|
||||
void (*dht_pk_callback)(void *data, int32_t number, const uint8_t *dht_public_key, void *userdata);
|
||||
void *dht_pk_callback_object;
|
||||
uint32_t dht_pk_callback_number;
|
||||
|
||||
uint32_t run_count;
|
||||
} Onion_Friend;
|
||||
|
||||
struct Onion_Client {
|
||||
DHT *dht;
|
||||
Net_Crypto *c;
|
||||
Networking_Core *net;
|
||||
Onion_Friend *friends_list;
|
||||
uint16_t num_friends;
|
||||
|
||||
Onion_Node clients_announce_list[MAX_ONION_CLIENTS_ANNOUNCE];
|
||||
uint64_t last_announce;
|
||||
|
||||
Onion_Client_Paths onion_paths_self;
|
||||
Onion_Client_Paths onion_paths_friends;
|
||||
|
||||
uint8_t secret_symmetric_key[CRYPTO_SYMMETRIC_KEY_SIZE];
|
||||
uint64_t last_run, first_run;
|
||||
|
||||
uint8_t temp_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t temp_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
|
||||
Last_Pinged last_pinged[MAX_STORED_PINGED_NODES];
|
||||
|
||||
Node_format path_nodes[MAX_PATH_NODES];
|
||||
uint16_t path_nodes_index;
|
||||
|
||||
Node_format path_nodes_bs[MAX_PATH_NODES];
|
||||
uint16_t path_nodes_index_bs;
|
||||
|
||||
Ping_Array *announce_ping_array;
|
||||
uint8_t last_pinged_index;
|
||||
struct {
|
||||
oniondata_handler_callback function;
|
||||
void *object;
|
||||
} Onion_Data_Handlers[256];
|
||||
|
||||
uint64_t last_packet_recv;
|
||||
|
||||
unsigned int onion_connected;
|
||||
bool UDP_connected;
|
||||
};
|
||||
|
||||
DHT *onion_get_dht(const Onion_Client *onion_c)
|
||||
{
|
||||
return onion_c->dht;
|
||||
}
|
||||
|
||||
Net_Crypto *onion_get_net_crypto(const Onion_Client *onion_c)
|
||||
{
|
||||
return onion_c->c;
|
||||
}
|
||||
|
||||
/* Add a node to the path_nodes bootstrap array.
|
||||
*
|
||||
* return -1 on failure
|
||||
|
@ -1770,4 +1887,3 @@ void kill_onion_client(Onion_Client *onion_c)
|
|||
crypto_memzero(onion_c, sizeof(Onion_Client));
|
||||
free(onion_c);
|
||||
}
|
||||
|
||||
|
|
|
@ -65,116 +65,10 @@
|
|||
#define ONION_DATA_FRIEND_REQ CRYPTO_PACKET_FRIEND_REQ
|
||||
#define ONION_DATA_DHTPK CRYPTO_PACKET_DHTPK
|
||||
|
||||
typedef struct {
|
||||
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
IP_Port ip_port;
|
||||
uint8_t ping_id[ONION_PING_ID_SIZE];
|
||||
uint8_t data_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t is_stored;
|
||||
|
||||
uint64_t added_time;
|
||||
|
||||
uint64_t timestamp;
|
||||
|
||||
uint64_t last_pinged;
|
||||
|
||||
uint8_t unsuccessful_pings;
|
||||
|
||||
uint32_t path_used;
|
||||
} Onion_Node;
|
||||
|
||||
typedef struct {
|
||||
Onion_Path paths[NUMBER_ONION_PATHS];
|
||||
uint64_t last_path_success[NUMBER_ONION_PATHS];
|
||||
uint64_t last_path_used[NUMBER_ONION_PATHS];
|
||||
uint64_t path_creation_time[NUMBER_ONION_PATHS];
|
||||
/* number of times used without success. */
|
||||
unsigned int last_path_used_times[NUMBER_ONION_PATHS];
|
||||
} Onion_Client_Paths;
|
||||
|
||||
typedef struct {
|
||||
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint64_t timestamp;
|
||||
} Last_Pinged;
|
||||
|
||||
typedef struct {
|
||||
uint8_t status; /* 0 if friend is not valid, 1 if friend is valid.*/
|
||||
uint8_t is_online; /* Set by the onion_set_friend_status function. */
|
||||
|
||||
uint8_t know_dht_public_key; /* 0 if we don't know the dht public key of the other, 1 if we do. */
|
||||
uint8_t dht_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t real_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
|
||||
Onion_Node clients_list[MAX_ONION_CLIENTS];
|
||||
uint8_t temp_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t temp_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
|
||||
uint64_t last_reported_announced;
|
||||
|
||||
uint64_t last_dht_pk_onion_sent;
|
||||
uint64_t last_dht_pk_dht_sent;
|
||||
|
||||
uint64_t last_noreplay;
|
||||
|
||||
uint64_t last_seen;
|
||||
|
||||
Last_Pinged last_pinged[MAX_STORED_PINGED_NODES];
|
||||
uint8_t last_pinged_index;
|
||||
|
||||
int (*tcp_relay_node_callback)(void *object, uint32_t number, IP_Port ip_port, const uint8_t *public_key);
|
||||
void *tcp_relay_node_callback_object;
|
||||
uint32_t tcp_relay_node_callback_number;
|
||||
|
||||
void (*dht_pk_callback)(void *data, int32_t number, const uint8_t *dht_public_key, void *userdata);
|
||||
void *dht_pk_callback_object;
|
||||
uint32_t dht_pk_callback_number;
|
||||
|
||||
uint32_t run_count;
|
||||
} Onion_Friend;
|
||||
|
||||
typedef int (*oniondata_handler_callback)(void *object, const uint8_t *source_pubkey, const uint8_t *data,
|
||||
uint16_t len, void *userdata);
|
||||
|
||||
typedef struct {
|
||||
DHT *dht;
|
||||
Net_Crypto *c;
|
||||
Networking_Core *net;
|
||||
Onion_Friend *friends_list;
|
||||
uint16_t num_friends;
|
||||
|
||||
Onion_Node clients_announce_list[MAX_ONION_CLIENTS_ANNOUNCE];
|
||||
uint64_t last_announce;
|
||||
|
||||
Onion_Client_Paths onion_paths_self;
|
||||
Onion_Client_Paths onion_paths_friends;
|
||||
|
||||
uint8_t secret_symmetric_key[CRYPTO_SYMMETRIC_KEY_SIZE];
|
||||
uint64_t last_run, first_run;
|
||||
|
||||
uint8_t temp_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t temp_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
|
||||
Last_Pinged last_pinged[MAX_STORED_PINGED_NODES];
|
||||
|
||||
Node_format path_nodes[MAX_PATH_NODES];
|
||||
uint16_t path_nodes_index;
|
||||
|
||||
Node_format path_nodes_bs[MAX_PATH_NODES];
|
||||
uint16_t path_nodes_index_bs;
|
||||
|
||||
Ping_Array *announce_ping_array;
|
||||
uint8_t last_pinged_index;
|
||||
struct {
|
||||
oniondata_handler_callback function;
|
||||
void *object;
|
||||
} Onion_Data_Handlers[256];
|
||||
|
||||
uint64_t last_packet_recv;
|
||||
|
||||
unsigned int onion_connected;
|
||||
bool UDP_connected;
|
||||
} Onion_Client;
|
||||
typedef struct Onion_Client Onion_Client;
|
||||
|
||||
DHT *onion_get_dht(const Onion_Client *onion_c);
|
||||
Net_Crypto *onion_get_net_crypto(const Onion_Client *onion_c);
|
||||
|
||||
/* Add a node to the path_nodes bootstrap array.
|
||||
*
|
||||
|
@ -283,6 +177,9 @@ unsigned int onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_
|
|||
*/
|
||||
int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, uint16_t length);
|
||||
|
||||
typedef int (*oniondata_handler_callback)(void *object, const uint8_t *source_pubkey, const uint8_t *data,
|
||||
uint16_t len, void *userdata);
|
||||
|
||||
/* Function to call when onion data packet with contents beginning with byte is received. */
|
||||
void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_handler_callback cb, void *object);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user