diff options
-rw-r--r-- | toxcore/onion_client.c | 15 | ||||
-rw-r--r-- | toxcore/onion_client.h | 8 | ||||
-rw-r--r-- | toxcore/tox.c | 1 |
3 files changed, 16 insertions, 8 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 0a519154..6ad55218 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -38,16 +38,17 @@ | |||
38 | * return -1 on failure | 38 | * return -1 on failure |
39 | * return 0 on success | 39 | * return 0 on success |
40 | */ | 40 | */ |
41 | static int add_path_node(Onion_Client *onion_c, Node_format *node) | 41 | int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id) |
42 | { | 42 | { |
43 | unsigned int i; | 43 | unsigned int i; |
44 | 44 | ||
45 | for (i = 0; i < MAX_PATH_NODES; ++i) { | 45 | for (i = 0; i < MAX_PATH_NODES; ++i) { |
46 | if (memcmp(node->client_id, onion_c->path_nodes[i].client_id, crypto_box_PUBLICKEYBYTES) == 0) | 46 | if (memcmp(client_id, onion_c->path_nodes[i].client_id, crypto_box_PUBLICKEYBYTES) == 0) |
47 | return -1; | 47 | return -1; |
48 | } | 48 | } |
49 | 49 | ||
50 | onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES] = *node; | 50 | onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].ip_port = ip_port; |
51 | memcpy(onion_c->path_nodes[onion_c->path_nodes_index % MAX_PATH_NODES].client_id, client_id, crypto_box_PUBLICKEYBYTES); | ||
51 | 52 | ||
52 | uint16_t last = onion_c->path_nodes_index; | 53 | uint16_t last = onion_c->path_nodes_index; |
53 | ++onion_c->path_nodes_index; | 54 | ++onion_c->path_nodes_index; |
@@ -402,10 +403,8 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t | |||
402 | memcpy(list_nodes[index].client_id, public_key, CLIENT_ID_SIZE); | 403 | memcpy(list_nodes[index].client_id, public_key, CLIENT_ID_SIZE); |
403 | list_nodes[index].ip_port = ip_port; | 404 | list_nodes[index].ip_port = ip_port; |
404 | 405 | ||
405 | Node_format add_node; //TODO: remove this and find a better source of nodes to use for paths. | 406 | //TODO: remove this and find a better source of nodes to use for paths. |
406 | memcpy(add_node.client_id, public_key, CLIENT_ID_SIZE); | 407 | onion_add_path_node(onion_c, ip_port, public_key); |
407 | add_node.ip_port = ip_port; | ||
408 | add_path_node(onion_c, &add_node); | ||
409 | 408 | ||
410 | if (is_stored) { | 409 | if (is_stored) { |
411 | memcpy(list_nodes[index].data_public_key, pingid_or_key, crypto_box_PUBLICKEYBYTES); | 410 | memcpy(list_nodes[index].data_public_key, pingid_or_key, crypto_box_PUBLICKEYBYTES); |
@@ -1079,7 +1078,7 @@ static void populate_path_nodes(Onion_Client *onion_c) | |||
1079 | unsigned int i; | 1078 | unsigned int i; |
1080 | 1079 | ||
1081 | for (i = 0; i < num_nodes; ++i) { | 1080 | for (i = 0; i < num_nodes; ++i) { |
1082 | add_path_node(onion_c, nodes_list + i); | 1081 | onion_add_path_node(onion_c, nodes_list[i].ip_port, nodes_list[i].client_id); |
1083 | } | 1082 | } |
1084 | } | 1083 | } |
1085 | } | 1084 | } |
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index 29c252c2..9d4d4832 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h | |||
@@ -137,6 +137,14 @@ typedef struct { | |||
137 | } Onion_Data_Handlers[256]; | 137 | } Onion_Data_Handlers[256]; |
138 | } Onion_Client; | 138 | } Onion_Client; |
139 | 139 | ||
140 | |||
141 | /* Add a node to the path_nodes array. | ||
142 | * | ||
143 | * return -1 on failure | ||
144 | * return 0 on success | ||
145 | */ | ||
146 | int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id); | ||
147 | |||
140 | /* Add a friend who we want to connect to. | 148 | /* Add a friend who we want to connect to. |
141 | * | 149 | * |
142 | * return -1 on failure. | 150 | * return -1 on failure. |
diff --git a/toxcore/tox.c b/toxcore/tox.c index 3c5db1e3..35df1c5b 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -775,6 +775,7 @@ static int tox_add_tcp_relay(Tox *tox, const char *address, uint8_t ipv6enabled, | |||
775 | if (addr_resolve_or_parse_ip(address, &ip_port_v64.ip, ip_extra)) { | 775 | if (addr_resolve_or_parse_ip(address, &ip_port_v64.ip, ip_extra)) { |
776 | ip_port_v64.port = port; | 776 | ip_port_v64.port = port; |
777 | add_tcp_relay(m->net_crypto, ip_port_v64, public_key); | 777 | add_tcp_relay(m->net_crypto, ip_port_v64, public_key); |
778 | onion_add_path_node(m->onion_c, ip_port_v64, public_key); //TODO: move this | ||
778 | return 1; | 779 | return 1; |
779 | } else { | 780 | } else { |
780 | return 0; | 781 | return 0; |