summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-08-08 22:07:28 -0400
committerirungentoo <irungentoo@gmail.com>2014-08-08 22:07:28 -0400
commitbb2a6cbbe2da334f86980ecf055b9454a8cedce7 (patch)
treefd352be20bfa00d7edc8852dc21411b3943b4480
parent545cc916620c8c9bff5145a216b55a26fcd62d46 (diff)
Added path_nodes array and add_path_node() function.
-rw-r--r--toxcore/onion_client.c20
-rw-r--r--toxcore/onion_client.h5
2 files changed, 25 insertions, 0 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index 96831beb..9b63d253 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -33,6 +33,26 @@
33#define ANNOUNCE_ARRAY_SIZE 256 33#define ANNOUNCE_ARRAY_SIZE 256
34#define ANNOUNCE_TIMEOUT 10 34#define ANNOUNCE_TIMEOUT 10
35 35
36/* Add a node to the path_nodes array.
37 *
38 * return -1 on failure
39 * return 0 on success
40 */
41static int add_path_node(Onion_Client *onion_c, Node_format *node)
42{
43 unsigned int i;
44
45 for (i = 0; i < MAX_PATH_NODES; ++i) {
46 if (memcmp(node->client_id, onion_c->path_nodes[i].client_id, crypto_box_PUBLICKEYBYTES) == 0)
47 return -1;
48 }
49
50 onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES] = *node;
51
52 ++onion_c->path_nodes_index;
53
54 return 0;
55}
36 56
37/* 57/*
38 * return -1 if nodes are suitable for creating a new path. 58 * return -1 if nodes are suitable for creating a new path.
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h
index bf891e7a..29c252c2 100644
--- a/toxcore/onion_client.h
+++ b/toxcore/onion_client.h
@@ -47,6 +47,8 @@
47#define MAX_STORED_PINGED_NODES 9 47#define MAX_STORED_PINGED_NODES 9
48#define MIN_NODE_PING_TIME 10 48#define MIN_NODE_PING_TIME 10
49 49
50#define MAX_PATH_NODES 32
51
50typedef struct { 52typedef struct {
51 uint8_t client_id[CLIENT_ID_SIZE]; 53 uint8_t client_id[CLIENT_ID_SIZE];
52 IP_Port ip_port; 54 IP_Port ip_port;
@@ -124,6 +126,9 @@ typedef struct {
124 126
125 Last_Pinged last_pinged[MAX_STORED_PINGED_NODES]; 127 Last_Pinged last_pinged[MAX_STORED_PINGED_NODES];
126 128
129 Node_format path_nodes[MAX_PATH_NODES];
130 uint16_t path_nodes_index;
131
127 Ping_Array announce_ping_array; 132 Ping_Array announce_ping_array;
128 uint8_t last_pinged_index; 133 uint8_t last_pinged_index;
129 struct { 134 struct {