mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Function to save path nodes.
Forgot to commit it with before last commit.
This commit is contained in:
parent
cb815f7584
commit
f0b2cd7ad2
|
@ -59,6 +59,32 @@ int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *c
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Put up to max_num nodes in nodes.
|
||||
*
|
||||
* return the number of nodes.
|
||||
*/
|
||||
uint16_t onion_backup_nodes(const Onion_Client *onion_c, Node_format *nodes, uint16_t max_num)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if (!max_num)
|
||||
return 0;
|
||||
|
||||
unsigned int num_nodes = (onion_c->path_nodes_index < MAX_PATH_NODES) ? onion_c->path_nodes_index : MAX_PATH_NODES;
|
||||
|
||||
if (num_nodes == 0)
|
||||
return 0;
|
||||
|
||||
if (num_nodes < max_num)
|
||||
max_num = num_nodes;
|
||||
|
||||
for (i = 0; i < max_num; ++i) {
|
||||
nodes[i] = onion_c->path_nodes[(onion_c->path_nodes_index - (1 + i)) % num_nodes];
|
||||
}
|
||||
|
||||
return max_num;
|
||||
}
|
||||
|
||||
/* Put up to max_num random nodes in nodes.
|
||||
*
|
||||
* return the number of nodes.
|
||||
|
|
|
@ -145,6 +145,12 @@ typedef struct {
|
|||
*/
|
||||
int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id);
|
||||
|
||||
/* Put up to max_num nodes in nodes.
|
||||
*
|
||||
* return the number of nodes.
|
||||
*/
|
||||
uint16_t onion_backup_nodes(const Onion_Client *onion_c, Node_format *nodes, uint16_t max_num);
|
||||
|
||||
/* Add a friend who we want to connect to.
|
||||
*
|
||||
* return -1 on failure.
|
||||
|
|
Loading…
Reference in New Issue
Block a user