summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-05-01 15:46:48 -0400
committerirungentoo <irungentoo@gmail.com>2015-05-01 15:46:48 -0400
commitbd67129c3e532a97d13c7ed04541ecefc395ab5a (patch)
tree349afc587a5f73a6eb42f4d544c970b583ce7157 /toxcore
parent7d13f1928e604b87c29ca22d8bf14e962c1cc8ed (diff)
Added a define for the length of onion paths.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/onion.c4
-rw-r--r--toxcore/onion.h4
-rw-r--r--toxcore/onion_client.c13
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
104 104
105/* Create a new onion path. 105/* Create a new onion path.
106 * 106 *
107 * Create a new onion path out of nodes (nodes is a list of 3 nodes) 107 * Create a new onion path out of nodes (nodes is a list of ONION_PATH_LENGTH nodes)
108 * 108 *
109 * new_path must be an empty memory location of atleast Onion_Path size. 109 * new_path must be an empty memory location of atleast Onion_Path size.
110 * 110 *
@@ -148,7 +148,7 @@ int create_onion_path(const DHT *dht, Onion_Path *new_path, const Node_format *n
148 */ 148 */
149int onion_path_to_nodes(Node_format *nodes, unsigned int num_nodes, const Onion_Path *path) 149int onion_path_to_nodes(Node_format *nodes, unsigned int num_nodes, const Onion_Path *path)
150{ 150{
151 if (num_nodes < 3) 151 if (num_nodes < ONION_PATH_LENGTH)
152 return -1; 152 return -1;
153 153
154 nodes[0].ip_port = path->ip_port1; 154 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 {
53#define ONION_MAX_DATA_SIZE (ONION_MAX_PACKET_SIZE - (ONION_SEND_1 + 1)) 53#define ONION_MAX_DATA_SIZE (ONION_MAX_PACKET_SIZE - (ONION_SEND_1 + 1))
54#define ONION_RESPONSE_MAX_DATA_SIZE (ONION_MAX_PACKET_SIZE - (1 + ONION_RETURN_3)) 54#define ONION_RESPONSE_MAX_DATA_SIZE (ONION_MAX_PACKET_SIZE - (1 + ONION_RETURN_3))
55 55
56#define ONION_PATH_LENGTH 3
57
56typedef struct { 58typedef struct {
57 uint8_t shared_key1[crypto_box_BEFORENMBYTES]; 59 uint8_t shared_key1[crypto_box_BEFORENMBYTES];
58 uint8_t shared_key2[crypto_box_BEFORENMBYTES]; 60 uint8_t shared_key2[crypto_box_BEFORENMBYTES];
@@ -76,7 +78,7 @@ typedef struct {
76 78
77/* Create a new onion path. 79/* Create a new onion path.
78 * 80 *
79 * Create a new onion path out of nodes (nodes is a list of 3 nodes) 81 * Create a new onion path out of nodes (nodes is a list of ONION_PATH_LENGTH nodes)
80 * 82 *
81 * new_path must be an empty memory location of atleast Onion_Path size. 83 * new_path must be an empty memory location of atleast Onion_Path size.
82 * 84 *
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
190 continue; 190 continue;
191 } 191 }
192 192
193 if (ipport_equal(&onion_paths->paths[i].ip_port1, &nodes[2].ip_port)) { 193 if (ipport_equal(&onion_paths->paths[i].ip_port1, &nodes[ONION_PATH_LENGTH - 1].ip_port)) {
194 return i; 194 return i;
195 } 195 }
196 } 196 }
@@ -215,9 +215,9 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa
215 if ((onion_paths->last_path_success[pathnum] + ONION_PATH_TIMEOUT < onion_paths->last_path_used[pathnum] 215 if ((onion_paths->last_path_success[pathnum] + ONION_PATH_TIMEOUT < onion_paths->last_path_used[pathnum]
216 && onion_paths->last_path_used_times[pathnum] >= ONION_PATH_MAX_NO_RESPONSE_USES) 216 && onion_paths->last_path_used_times[pathnum] >= ONION_PATH_MAX_NO_RESPONSE_USES)
217 || is_timeout(onion_paths->path_creation_time[pathnum], ONION_PATH_MAX_LIFETIME)) { 217 || is_timeout(onion_paths->path_creation_time[pathnum], ONION_PATH_MAX_LIFETIME)) {
218 Node_format nodes[3]; 218 Node_format nodes[ONION_PATH_LENGTH];
219 219
220 if (random_nodes_path_onion(onion_c, nodes, 3) != 3) 220 if (random_nodes_path_onion(onion_c, nodes, ONION_PATH_LENGTH) != ONION_PATH_LENGTH)
221 return -1; 221 return -1;
222 222
223 int n = is_path_used(onion_paths, nodes); 223 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
267 onion_paths->last_path_success[path_num % NUMBER_ONION_PATHS] = unix_time(); 267 onion_paths->last_path_success[path_num % NUMBER_ONION_PATHS] = unix_time();
268 onion_paths->last_path_used_times[path_num % NUMBER_ONION_PATHS] = 0; 268 onion_paths->last_path_used_times[path_num % NUMBER_ONION_PATHS] = 0;
269 269
270 unsigned int path_len = 3; 270 Node_format nodes[ONION_PATH_LENGTH];
271 Node_format nodes[path_len];
272 271
273 if (onion_path_to_nodes(nodes, path_len, &onion_paths->paths[path_num % NUMBER_ONION_PATHS]) == 0) { 272 if (onion_path_to_nodes(nodes, ONION_PATH_LENGTH, &onion_paths->paths[path_num % NUMBER_ONION_PATHS]) == 0) {
274 unsigned int i; 273 unsigned int i;
275 274
276 for (i = 0; i < path_len; ++i) { 275 for (i = 0; i < ONION_PATH_LENGTH; ++i) {
277 onion_add_path_node(onion_c, nodes[i].ip_port, nodes[i].public_key); 276 onion_add_path_node(onion_c, nodes[i].ip_port, nodes[i].public_key);
278 } 277 }
279 } 278 }