From bd67129c3e532a97d13c7ed04541ecefc395ab5a Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 1 May 2015 15:46:48 -0400 Subject: [PATCH] Added a define for the length of onion paths. --- toxcore/onion.c | 4 ++-- toxcore/onion.h | 4 +++- toxcore/onion_client.c | 13 ++++++------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/toxcore/onion.c b/toxcore/onion.c index 48e4c769..cec178b9 100644 --- a/toxcore/onion.c +++ b/toxcore/onion.c @@ -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 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. * @@ -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) { - if (num_nodes < 3) + if (num_nodes < ONION_PATH_LENGTH) return -1; nodes[0].ip_port = path->ip_port1; diff --git a/toxcore/onion.h b/toxcore/onion.h index b05d2c8c..2b270ea9 100644 --- a/toxcore/onion.h +++ b/toxcore/onion.h @@ -53,6 +53,8 @@ typedef struct { #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_PATH_LENGTH 3 + typedef struct { uint8_t shared_key1[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 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. * diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index ed328fb3..5db426d3 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -190,7 +190,7 @@ static int is_path_used(const Onion_Client_Paths *onion_paths, const Node_format 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; } } @@ -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] && 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)) { - 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; 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_used_times[path_num % NUMBER_ONION_PATHS] = 0; - unsigned int path_len = 3; - Node_format nodes[path_len]; + Node_format nodes[ONION_PATH_LENGTH]; - 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; - 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); } }