summaryrefslogtreecommitdiff
path: root/toxcore/onion_client.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/onion_client.c')
-rw-r--r--toxcore/onion_client.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index 40701e2d..7d0efc79 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -38,7 +38,7 @@
38 * return -1 if nodes are suitable for creating a new path. 38 * return -1 if nodes are suitable for creating a new path.
39 * return path number of already existing similar path if one already exists. 39 * return path number of already existing similar path if one already exists.
40 */ 40 */
41static int is_path_used(Onion_Client_Paths *onion_paths, Node_format *nodes) 41static int is_path_used(const Onion_Client_Paths *onion_paths, const Node_format *nodes)
42{ 42{
43 uint32_t i; 43 uint32_t i;
44 44
@@ -68,7 +68,7 @@ static int is_path_used(Onion_Client_Paths *onion_paths, Node_format *nodes)
68 * TODO: Make this function better, it currently probably is vulnerable to some attacks that 68 * TODO: Make this function better, it currently probably is vulnerable to some attacks that
69 * could de anonimize us. 69 * could de anonimize us.
70 */ 70 */
71static int random_path(DHT *dht, Onion_Client_Paths *onion_paths, uint32_t pathnum, Onion_Path *path) 71static int random_path(const DHT *dht, Onion_Client_Paths *onion_paths, uint32_t pathnum, Onion_Path *path)
72{ 72{
73 if (pathnum >= NUMBER_ONION_PATHS) 73 if (pathnum >= NUMBER_ONION_PATHS)
74 pathnum = rand() % NUMBER_ONION_PATHS; 74 pathnum = rand() % NUMBER_ONION_PATHS;
@@ -130,7 +130,7 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, IP_Port s
130 * return -1 on failure. 130 * return -1 on failure.
131 * return 0 on success. 131 * return 0 on success.
132 */ 132 */
133static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, IP_Port ip_port, uint8_t *data, uint32_t length) 133static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, IP_Port ip_port, const uint8_t *data, uint32_t length)
134{ 134{
135 if (ip_port.ip.family == AF_INET || ip_port.ip.family == AF_INET6) { 135 if (ip_port.ip.family == AF_INET || ip_port.ip.family == AF_INET6) {
136 if ((uint32_t)sendpacket(onion_c->net, ip_port, data, length) != length) 136 if ((uint32_t)sendpacket(onion_c->net, ip_port, data, length) != length)
@@ -157,7 +157,8 @@ static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, IP_Port ip_por
157 * return 0 on success 157 * return 0 on success
158 * 158 *
159 */ 159 */
160static int new_sendback(Onion_Client *onion_c, uint32_t num, uint8_t *public_key, IP_Port ip_port, uint64_t *sendback) 160static int new_sendback(Onion_Client *onion_c, uint32_t num, const uint8_t *public_key, IP_Port ip_port,
161 uint64_t *sendback)
161{ 162{
162 uint8_t data[sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + sizeof(IP_Port)]; 163 uint8_t data[sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + sizeof(IP_Port)];
163 memcpy(data, &num, sizeof(uint32_t)); 164 memcpy(data, &num, sizeof(uint32_t));
@@ -198,8 +199,8 @@ static uint32_t check_sendback(Onion_Client *onion_c, const uint8_t *sendback, u
198 return num; 199 return num;
199} 200}
200 201
201static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, IP_Port dest, uint8_t *dest_pubkey, 202static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, IP_Port dest, const uint8_t *dest_pubkey,
202 uint8_t *ping_id, uint32_t pathnum) 203 const uint8_t *ping_id, uint32_t pathnum)
203{ 204{
204 if (num > onion_c->num_friends) 205 if (num > onion_c->num_friends)
205 return -1; 206 return -1;
@@ -279,8 +280,8 @@ static int cmp_entry(const void *a, const void *b)
279 return 0; 280 return 0;
280} 281}
281 282
282static int client_add_to_list(Onion_Client *onion_c, uint32_t num, uint8_t *public_key, IP_Port ip_port, 283static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t *public_key, IP_Port ip_port,
283 uint8_t is_stored, uint8_t *pingid_or_key, IP_Port source) 284 uint8_t is_stored, const uint8_t *pingid_or_key, IP_Port source)
284{ 285{
285 if (num > onion_c->num_friends) 286 if (num > onion_c->num_friends)
286 return -1; 287 return -1;
@@ -338,7 +339,7 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, uint8_t *publ
338 return 0; 339 return 0;
339} 340}
340 341
341static int good_to_ping(Last_Pinged *last_pinged, uint8_t *last_pinged_index, uint8_t *client_id) 342static int good_to_ping(Last_Pinged *last_pinged, uint8_t *last_pinged_index, const uint8_t *client_id)
342{ 343{
343 uint32_t i; 344 uint32_t i;
344 345
@@ -354,7 +355,7 @@ static int good_to_ping(Last_Pinged *last_pinged, uint8_t *last_pinged_index, ui
354 return 1; 355 return 1;
355} 356}
356 357
357static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, Node_format *nodes, uint16_t num_nodes, 358static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_format *nodes, uint16_t num_nodes,
358 IP_Port source) 359 IP_Port source)
359{ 360{
360 if (num > onion_c->num_friends) 361 if (num > onion_c->num_friends)
@@ -630,7 +631,7 @@ int send_onion_data(const Onion_Client *onion_c, int friend_num, const uint8_t *
630 * return the number of packets sent on success 631 * return the number of packets sent on success
631 * return -1 on failure. 632 * return -1 on failure.
632 */ 633 */
633static int send_dht_fakeid(Onion_Client *onion_c, int friend_num, uint8_t *data, uint32_t length) 634static int send_dht_fakeid(const Onion_Client *onion_c, int friend_num, const uint8_t *data, uint32_t length)
634{ 635{
635 if ((uint32_t)friend_num >= onion_c->num_friends) 636 if ((uint32_t)friend_num >= onion_c->num_friends)
636 return -1; 637 return -1;
@@ -693,7 +694,7 @@ static int handle_dht_fakeid(void *object, IP_Port source, const uint8_t *source
693 * return the number of packets sent on success 694 * return the number of packets sent on success
694 * return -1 on failure. 695 * return -1 on failure.
695 */ 696 */
696static int send_fakeid_announce(Onion_Client *onion_c, uint16_t friend_num, uint8_t onion_dht_both) 697static int send_fakeid_announce(const Onion_Client *onion_c, uint16_t friend_num, uint8_t onion_dht_both)
697{ 698{
698 if (friend_num >= onion_c->num_friends) 699 if (friend_num >= onion_c->num_friends)
699 return -1; 700 return -1;
@@ -851,7 +852,7 @@ int onion_delfriend(Onion_Client *onion_c, int friend_num)
851 * return 0 on success. 852 * return 0 on success.
852 */ 853 */
853int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_relay_node_callback)(void *object, 854int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_relay_node_callback)(void *object,
854 uint32_t number, IP_Port ip_port, uint8_t *public_key), void *object, uint32_t number) 855 uint32_t number, IP_Port ip_port, const uint8_t *public_key), void *object, uint32_t number)
855{ 856{
856 if ((uint32_t)friend_num >= onion_c->num_friends) 857 if ((uint32_t)friend_num >= onion_c->num_friends)
857 return -1; 858 return -1;
@@ -905,7 +906,7 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin
905 * return 0 on failure (no key copied). 906 * return 0 on failure (no key copied).
906 * return timestamp on success (key copied). 907 * return timestamp on success (key copied).
907 */ 908 */
908uint64_t onion_getfriend_DHT_pubkey(Onion_Client *onion_c, int friend_num, uint8_t *dht_key) 909uint64_t onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key)
909{ 910{
910 if ((uint32_t)friend_num >= onion_c->num_friends) 911 if ((uint32_t)friend_num >= onion_c->num_friends)
911 return 0; 912 return 0;
@@ -927,7 +928,7 @@ uint64_t onion_getfriend_DHT_pubkey(Onion_Client *onion_c, int friend_num, uint8
927 * return 1, ip if client_id refers to a friend and we found him 928 * return 1, ip if client_id refers to a friend and we found him
928 * 929 *
929 */ 930 */
930int onion_getfriendip(Onion_Client *onion_c, int friend_num, IP_Port *ip_port) 931int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_port)
931{ 932{
932 uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES]; 933 uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES];
933 934