summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schütz <schuetzm@gmx.net>2014-06-30 21:41:03 +0200
committerMarc Schütz <schuetzm@gmx.net>2014-06-30 21:41:03 +0200
commit9762089badd10189c59fddce1e0f95c4adc084aa (patch)
treee2fd82db795a04f1e2416adb6011f948691a88d4
parent1494992a9f11a517413f9208bf97ef4b2797002d (diff)
Const-correctness for onion_client.c
-rw-r--r--toxcore/DHT.c2
-rw-r--r--toxcore/DHT.h2
-rw-r--r--toxcore/onion_client.c28
-rw-r--r--toxcore/onion_client.h4
4 files changed, 18 insertions, 18 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 133e9392..77d126c1 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -2212,7 +2212,7 @@ static int random_node_fromlist(Client_data *list, uint16_t list_size, Node_form
2212 * 2212 *
2213 * TODO: remove the LAN stuff from this. 2213 * TODO: remove the LAN stuff from this.
2214 */ 2214 */
2215uint16_t random_nodes_path(DHT *dht, Node_format *nodes, uint16_t max_num) 2215uint16_t random_nodes_path(const DHT *dht, Node_format *nodes, uint16_t max_num)
2216{ 2216{
2217 if (max_num == 0) 2217 if (max_num == 0)
2218 return 0; 2218 return 0;
diff --git a/toxcore/DHT.h b/toxcore/DHT.h
index c7fddb4f..ea94e4ca 100644
--- a/toxcore/DHT.h
+++ b/toxcore/DHT.h
@@ -306,7 +306,7 @@ uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num);
306 * 306 *
307 * NOTE:this is used to pick nodes for paths. 307 * NOTE:this is used to pick nodes for paths.
308 */ 308 */
309uint16_t random_nodes_path(DHT *dht, Node_format *nodes, uint16_t max_num); 309uint16_t random_nodes_path(const DHT *dht, Node_format *nodes, uint16_t max_num);
310 310
311/* Run this function at least a couple times per second (It's the main loop). */ 311/* Run this function at least a couple times per second (It's the main loop). */
312void do_DHT(DHT *dht); 312void do_DHT(DHT *dht);
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index be06e1c7..03453680 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,7 @@ 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, uint64_t *sendback)
161{ 161{
162 uint8_t data[sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + sizeof(IP_Port)]; 162 uint8_t data[sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + sizeof(IP_Port)];
163 memcpy(data, &num, sizeof(uint32_t)); 163 memcpy(data, &num, sizeof(uint32_t));
@@ -198,8 +198,8 @@ static uint32_t check_sendback(Onion_Client *onion_c, const uint8_t *sendback, u
198 return num; 198 return num;
199} 199}
200 200
201static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, IP_Port dest, uint8_t *dest_pubkey, 201static 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) 202 const uint8_t *ping_id, uint32_t pathnum)
203{ 203{
204 if (num > onion_c->num_friends) 204 if (num > onion_c->num_friends)
205 return -1; 205 return -1;
@@ -279,8 +279,8 @@ static int cmp_entry(const void *a, const void *b)
279 return 0; 279 return 0;
280} 280}
281 281
282static int client_add_to_list(Onion_Client *onion_c, uint32_t num, uint8_t *public_key, IP_Port ip_port, 282static 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) 283 uint8_t is_stored, const uint8_t *pingid_or_key, IP_Port source)
284{ 284{
285 if (num > onion_c->num_friends) 285 if (num > onion_c->num_friends)
286 return -1; 286 return -1;
@@ -338,7 +338,7 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, uint8_t *publ
338 return 0; 338 return 0;
339} 339}
340 340
341static int good_to_ping(Last_Pinged *last_pinged, uint8_t *last_pinged_index, uint8_t *client_id) 341static int good_to_ping(Last_Pinged *last_pinged, uint8_t *last_pinged_index, const uint8_t *client_id)
342{ 342{
343 uint32_t i; 343 uint32_t i;
344 344
@@ -354,7 +354,7 @@ static int good_to_ping(Last_Pinged *last_pinged, uint8_t *last_pinged_index, ui
354 return 1; 354 return 1;
355} 355}
356 356
357static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, Node_format *nodes, uint16_t num_nodes, 357static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_format *nodes, uint16_t num_nodes,
358 IP_Port source) 358 IP_Port source)
359{ 359{
360 if (num > onion_c->num_friends) 360 if (num > onion_c->num_friends)
@@ -630,7 +630,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 630 * return the number of packets sent on success
631 * return -1 on failure. 631 * return -1 on failure.
632 */ 632 */
633static int send_dht_fakeid(Onion_Client *onion_c, int friend_num, uint8_t *data, uint32_t length) 633static int send_dht_fakeid(const Onion_Client *onion_c, int friend_num, const uint8_t *data, uint32_t length)
634{ 634{
635 if ((uint32_t)friend_num >= onion_c->num_friends) 635 if ((uint32_t)friend_num >= onion_c->num_friends)
636 return -1; 636 return -1;
@@ -693,7 +693,7 @@ static int handle_dht_fakeid(void *object, IP_Port source, const uint8_t *source
693 * return the number of packets sent on success 693 * return the number of packets sent on success
694 * return -1 on failure. 694 * return -1 on failure.
695 */ 695 */
696static int send_fakeid_announce(Onion_Client *onion_c, uint16_t friend_num, uint8_t onion_dht_both) 696static int send_fakeid_announce(const Onion_Client *onion_c, uint16_t friend_num, uint8_t onion_dht_both)
697{ 697{
698 if (friend_num >= onion_c->num_friends) 698 if (friend_num >= onion_c->num_friends)
699 return -1; 699 return -1;
@@ -905,7 +905,7 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin
905 * return 0 on failure (no key copied). 905 * return 0 on failure (no key copied).
906 * return timestamp on success (key copied). 906 * return timestamp on success (key copied).
907 */ 907 */
908uint64_t onion_getfriend_DHT_pubkey(Onion_Client *onion_c, int friend_num, uint8_t *dht_key) 908uint64_t onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key)
909{ 909{
910 if ((uint32_t)friend_num >= onion_c->num_friends) 910 if ((uint32_t)friend_num >= onion_c->num_friends)
911 return 0; 911 return 0;
@@ -927,7 +927,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 927 * return 1, ip if client_id refers to a friend and we found him
928 * 928 *
929 */ 929 */
930int onion_getfriendip(Onion_Client *onion_c, int friend_num, IP_Port *ip_port) 930int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_port)
931{ 931{
932 uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES]; 932 uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES];
933 933
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h
index 1f15d4bf..bf891e7a 100644
--- a/toxcore/onion_client.h
+++ b/toxcore/onion_client.h
@@ -171,7 +171,7 @@ int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_on
171 * return 1, ip if client_id refers to a friend and we found him 171 * return 1, ip if client_id refers to a friend and we found him
172 * 172 *
173 */ 173 */
174int onion_getfriendip(Onion_Client *onion_c, int friend_num, IP_Port *ip_port); 174int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_port);
175 175
176/* Set the function for this friend that will be callbacked with object and number 176/* Set the function for this friend that will be callbacked with object and number
177 * when that friends gives us one of the TCP relays he is connected to. 177 * when that friends gives us one of the TCP relays he is connected to.
@@ -198,7 +198,7 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin
198 * return 0 on failure (no key copied). 198 * return 0 on failure (no key copied).
199 * return timestamp on success (key copied). 199 * return timestamp on success (key copied).
200 */ 200 */
201uint64_t onion_getfriend_DHT_pubkey(Onion_Client *onion_c, int friend_num, uint8_t *dht_key); 201uint64_t onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key);
202 202
203#define ONION_DATA_IN_RESPONSE_MIN_SIZE (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES) 203#define ONION_DATA_IN_RESPONSE_MIN_SIZE (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES)
204#define ONION_CLIENT_MAX_DATA_SIZE (MAX_DATA_REQUEST_SIZE - ONION_DATA_IN_RESPONSE_MIN_SIZE) 204#define ONION_CLIENT_MAX_DATA_SIZE (MAX_DATA_REQUEST_SIZE - ONION_DATA_IN_RESPONSE_MIN_SIZE)