Add function to get nodes from onion path.

This commit is contained in:
irungentoo 2014-12-25 15:01:12 -05:00
parent d8b0d2e19b
commit 18b45ffade
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
2 changed files with 39 additions and 0 deletions

View File

@ -77,6 +77,10 @@ int create_onion_path(const DHT *dht, Onion_Path *new_path, const Node_format *n
new_path->ip_port2 = nodes[1].ip_port;
new_path->ip_port3 = nodes[2].ip_port;
memcpy(new_path->node_public_key1, nodes[0].client_id, crypto_box_PUBLICKEYBYTES);
memcpy(new_path->node_public_key2, nodes[1].client_id, crypto_box_PUBLICKEYBYTES);
memcpy(new_path->node_public_key3, nodes[2].client_id, crypto_box_PUBLICKEYBYTES);
/* to_net_family(&new_path->ip_port1.ip); */
to_net_family(&new_path->ip_port2.ip);
to_net_family(&new_path->ip_port3.ip);
@ -84,6 +88,29 @@ int create_onion_path(const DHT *dht, Onion_Path *new_path, const Node_format *n
return 0;
}
/* Dump nodes in onion path to nodes of length num_nodes;
*
* return -1 on failure.
* return 0 on success.
*/
int onion_path_to_nodes(Node_format *nodes, unsigned int num_nodes, const Onion_Path *path)
{
if (num_nodes < 3)
return -1;
nodes[0].ip_port = path->ip_port1;
nodes[1].ip_port = path->ip_port2;
nodes[2].ip_port = path->ip_port3;
to_host_family(&nodes[1].ip_port.ip);
to_host_family(&nodes[2].ip_port.ip);
memcpy(nodes[0].client_id, path->node_public_key1, crypto_box_PUBLICKEYBYTES);
memcpy(nodes[1].client_id, path->node_public_key2, crypto_box_PUBLICKEYBYTES);
memcpy(nodes[2].client_id, path->node_public_key3, crypto_box_PUBLICKEYBYTES);
return 0;
}
/* Create a onion packet.
*
* Use Onion_Path path to create packet for data of length to dest.

View File

@ -63,8 +63,13 @@ typedef struct {
uint8_t public_key3[crypto_box_PUBLICKEYBYTES];
IP_Port ip_port1;
uint8_t node_public_key1[crypto_box_PUBLICKEYBYTES];
IP_Port ip_port2;
uint8_t node_public_key2[crypto_box_PUBLICKEYBYTES];
IP_Port ip_port3;
uint8_t node_public_key3[crypto_box_PUBLICKEYBYTES];
uint32_t path_num;
} Onion_Path;
@ -80,6 +85,13 @@ typedef struct {
*/
int create_onion_path(const DHT *dht, Onion_Path *new_path, const Node_format *nodes);
/* Dump nodes in onion path to nodes of length num_nodes;
*
* return -1 on failure.
* return 0 on success.
*/
int onion_path_to_nodes(Node_format *nodes, unsigned int num_nodes, const Onion_Path *path);
/* Create a onion packet.
*
* Use Onion_Path path to create packet for data of length to dest.