From bb2a6cbbe2da334f86980ecf055b9454a8cedce7 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 8 Aug 2014 22:07:28 -0400 Subject: [PATCH] Added path_nodes array and add_path_node() function. --- toxcore/onion_client.c | 20 ++++++++++++++++++++ toxcore/onion_client.h | 5 +++++ 2 files changed, 25 insertions(+) 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 @@ #define ANNOUNCE_ARRAY_SIZE 256 #define ANNOUNCE_TIMEOUT 10 +/* Add a node to the path_nodes array. + * + * return -1 on failure + * return 0 on success + */ +static int add_path_node(Onion_Client *onion_c, Node_format *node) +{ + unsigned int i; + + for (i = 0; i < MAX_PATH_NODES; ++i) { + if (memcmp(node->client_id, onion_c->path_nodes[i].client_id, crypto_box_PUBLICKEYBYTES) == 0) + return -1; + } + + onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES] = *node; + + ++onion_c->path_nodes_index; + + return 0; +} /* * 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 @@ #define MAX_STORED_PINGED_NODES 9 #define MIN_NODE_PING_TIME 10 +#define MAX_PATH_NODES 32 + typedef struct { uint8_t client_id[CLIENT_ID_SIZE]; IP_Port ip_port; @@ -124,6 +126,9 @@ typedef struct { Last_Pinged last_pinged[MAX_STORED_PINGED_NODES]; + Node_format path_nodes[MAX_PATH_NODES]; + uint16_t path_nodes_index; + Ping_Array announce_ping_array; uint8_t last_pinged_index; struct {