Skip to content

Commit

Permalink
Added path_nodes array and add_path_node() function.
Browse files Browse the repository at this point in the history
  • Loading branch information
irungentoo committed Aug 9, 2014
1 parent 545cc91 commit bb2a6cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions toxcore/onion_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions toxcore/onion_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bb2a6cb

Please sign in to comment.