mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added a define for the length of onion paths.
This commit is contained in:
parent
7d13f1928e
commit
bd67129c3e
|
@ -104,7 +104,7 @@ static int ipport_unpack(IP_Port *target, const uint8_t *data, unsigned int data
|
||||||
|
|
||||||
/* Create a new onion path.
|
/* Create a new onion path.
|
||||||
*
|
*
|
||||||
* Create a new onion path out of nodes (nodes is a list of 3 nodes)
|
* Create a new onion path out of nodes (nodes is a list of ONION_PATH_LENGTH nodes)
|
||||||
*
|
*
|
||||||
* new_path must be an empty memory location of atleast Onion_Path size.
|
* new_path must be an empty memory location of atleast Onion_Path size.
|
||||||
*
|
*
|
||||||
|
@ -148,7 +148,7 @@ int create_onion_path(const DHT *dht, Onion_Path *new_path, const Node_format *n
|
||||||
*/
|
*/
|
||||||
int onion_path_to_nodes(Node_format *nodes, unsigned int num_nodes, const Onion_Path *path)
|
int onion_path_to_nodes(Node_format *nodes, unsigned int num_nodes, const Onion_Path *path)
|
||||||
{
|
{
|
||||||
if (num_nodes < 3)
|
if (num_nodes < ONION_PATH_LENGTH)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
nodes[0].ip_port = path->ip_port1;
|
nodes[0].ip_port = path->ip_port1;
|
||||||
|
|
|
@ -53,6 +53,8 @@ typedef struct {
|
||||||
#define ONION_MAX_DATA_SIZE (ONION_MAX_PACKET_SIZE - (ONION_SEND_1 + 1))
|
#define ONION_MAX_DATA_SIZE (ONION_MAX_PACKET_SIZE - (ONION_SEND_1 + 1))
|
||||||
#define ONION_RESPONSE_MAX_DATA_SIZE (ONION_MAX_PACKET_SIZE - (1 + ONION_RETURN_3))
|
#define ONION_RESPONSE_MAX_DATA_SIZE (ONION_MAX_PACKET_SIZE - (1 + ONION_RETURN_3))
|
||||||
|
|
||||||
|
#define ONION_PATH_LENGTH 3
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t shared_key1[crypto_box_BEFORENMBYTES];
|
uint8_t shared_key1[crypto_box_BEFORENMBYTES];
|
||||||
uint8_t shared_key2[crypto_box_BEFORENMBYTES];
|
uint8_t shared_key2[crypto_box_BEFORENMBYTES];
|
||||||
|
@ -76,7 +78,7 @@ typedef struct {
|
||||||
|
|
||||||
/* Create a new onion path.
|
/* Create a new onion path.
|
||||||
*
|
*
|
||||||
* Create a new onion path out of nodes (nodes is a list of 3 nodes)
|
* Create a new onion path out of nodes (nodes is a list of ONION_PATH_LENGTH nodes)
|
||||||
*
|
*
|
||||||
* new_path must be an empty memory location of atleast Onion_Path size.
|
* new_path must be an empty memory location of atleast Onion_Path size.
|
||||||
*
|
*
|
||||||
|
|
|
@ -190,7 +190,7 @@ static int is_path_used(const Onion_Client_Paths *onion_paths, const Node_format
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ipport_equal(&onion_paths->paths[i].ip_port1, &nodes[2].ip_port)) {
|
if (ipport_equal(&onion_paths->paths[i].ip_port1, &nodes[ONION_PATH_LENGTH - 1].ip_port)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,9 +215,9 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa
|
||||||
if ((onion_paths->last_path_success[pathnum] + ONION_PATH_TIMEOUT < onion_paths->last_path_used[pathnum]
|
if ((onion_paths->last_path_success[pathnum] + ONION_PATH_TIMEOUT < onion_paths->last_path_used[pathnum]
|
||||||
&& onion_paths->last_path_used_times[pathnum] >= ONION_PATH_MAX_NO_RESPONSE_USES)
|
&& onion_paths->last_path_used_times[pathnum] >= ONION_PATH_MAX_NO_RESPONSE_USES)
|
||||||
|| is_timeout(onion_paths->path_creation_time[pathnum], ONION_PATH_MAX_LIFETIME)) {
|
|| is_timeout(onion_paths->path_creation_time[pathnum], ONION_PATH_MAX_LIFETIME)) {
|
||||||
Node_format nodes[3];
|
Node_format nodes[ONION_PATH_LENGTH];
|
||||||
|
|
||||||
if (random_nodes_path_onion(onion_c, nodes, 3) != 3)
|
if (random_nodes_path_onion(onion_c, nodes, ONION_PATH_LENGTH) != ONION_PATH_LENGTH)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int n = is_path_used(onion_paths, nodes);
|
int n = is_path_used(onion_paths, nodes);
|
||||||
|
@ -267,13 +267,12 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t
|
||||||
onion_paths->last_path_success[path_num % NUMBER_ONION_PATHS] = unix_time();
|
onion_paths->last_path_success[path_num % NUMBER_ONION_PATHS] = unix_time();
|
||||||
onion_paths->last_path_used_times[path_num % NUMBER_ONION_PATHS] = 0;
|
onion_paths->last_path_used_times[path_num % NUMBER_ONION_PATHS] = 0;
|
||||||
|
|
||||||
unsigned int path_len = 3;
|
Node_format nodes[ONION_PATH_LENGTH];
|
||||||
Node_format nodes[path_len];
|
|
||||||
|
|
||||||
if (onion_path_to_nodes(nodes, path_len, &onion_paths->paths[path_num % NUMBER_ONION_PATHS]) == 0) {
|
if (onion_path_to_nodes(nodes, ONION_PATH_LENGTH, &onion_paths->paths[path_num % NUMBER_ONION_PATHS]) == 0) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < path_len; ++i) {
|
for (i = 0; i < ONION_PATH_LENGTH; ++i) {
|
||||||
onion_add_path_node(onion_c, nodes[i].ip_port, nodes[i].public_key);
|
onion_add_path_node(onion_c, nodes[i].ip_port, nodes[i].public_key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user