diff options
author | irungentoo <irungentoo@gmail.com> | 2014-08-14 17:34:42 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-08-14 17:34:42 -0400 |
commit | f0b2cd7ad2b6f8223161a6ed850c7bc6548dde62 (patch) | |
tree | e68cd085e5c9537ffbf67541f9ae29e3b8ce496d | |
parent | cb815f7584ba15a05ac65ee6cc3ec53bb9732fa5 (diff) |
Function to save path nodes.
Forgot to commit it with before last commit.
-rw-r--r-- | toxcore/onion_client.c | 26 | ||||
-rw-r--r-- | toxcore/onion_client.h | 6 |
2 files changed, 32 insertions, 0 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 719bd261..424711d5 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -59,6 +59,32 @@ int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *c | |||
59 | return 0; | 59 | return 0; |
60 | } | 60 | } |
61 | 61 | ||
62 | /* Put up to max_num nodes in nodes. | ||
63 | * | ||
64 | * return the number of nodes. | ||
65 | */ | ||
66 | uint16_t onion_backup_nodes(const Onion_Client *onion_c, Node_format *nodes, uint16_t max_num) | ||
67 | { | ||
68 | unsigned int i; | ||
69 | |||
70 | if (!max_num) | ||
71 | return 0; | ||
72 | |||
73 | unsigned int num_nodes = (onion_c->path_nodes_index < MAX_PATH_NODES) ? onion_c->path_nodes_index : MAX_PATH_NODES; | ||
74 | |||
75 | if (num_nodes == 0) | ||
76 | return 0; | ||
77 | |||
78 | if (num_nodes < max_num) | ||
79 | max_num = num_nodes; | ||
80 | |||
81 | for (i = 0; i < max_num; ++i) { | ||
82 | nodes[i] = onion_c->path_nodes[(onion_c->path_nodes_index - (1 + i)) % num_nodes]; | ||
83 | } | ||
84 | |||
85 | return max_num; | ||
86 | } | ||
87 | |||
62 | /* Put up to max_num random nodes in nodes. | 88 | /* Put up to max_num random nodes in nodes. |
63 | * | 89 | * |
64 | * return the number of nodes. | 90 | * return the number of nodes. |
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index 61e0eca9..d0393712 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h | |||
@@ -145,6 +145,12 @@ typedef struct { | |||
145 | */ | 145 | */ |
146 | int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id); | 146 | int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id); |
147 | 147 | ||
148 | /* Put up to max_num nodes in nodes. | ||
149 | * | ||
150 | * return the number of nodes. | ||
151 | */ | ||
152 | uint16_t onion_backup_nodes(const Onion_Client *onion_c, Node_format *nodes, uint16_t max_num); | ||
153 | |||
148 | /* Add a friend who we want to connect to. | 154 | /* Add a friend who we want to connect to. |
149 | * | 155 | * |
150 | * return -1 on failure. | 156 | * return -1 on failure. |