summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxcore/TCP_client.c14
-rw-r--r--toxcore/TCP_client.h18
-rw-r--r--toxcore/net_crypto.c108
-rw-r--r--toxcore/net_crypto.h22
4 files changed, 81 insertions, 81 deletions
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c
index 623c48dc..0b9bc74e 100644
--- a/toxcore/TCP_client.c
+++ b/toxcore/TCP_client.c
@@ -137,7 +137,7 @@ static int send_pending_data(TCP_Client_Connection *con)
137 * return 0 if could not send packet. 137 * return 0 if could not send packet.
138 * return -1 on failure (connection must be killed). 138 * return -1 on failure (connection must be killed).
139 */ 139 */
140static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, uint8_t *data, uint16_t length) 140static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const uint8_t *data, uint16_t length)
141{ 141{
142 if (length + crypto_box_MACBYTES > MAX_PACKET_SIZE) 142 if (length + crypto_box_MACBYTES > MAX_PACKET_SIZE)
143 return -1; 143 return -1;
@@ -183,7 +183,7 @@ int send_routing_request(TCP_Client_Connection *con, uint8_t *public_key)
183} 183}
184 184
185void routing_response_handler(TCP_Client_Connection *con, int (*response_callback)(void *object, uint8_t connection_id, 185void routing_response_handler(TCP_Client_Connection *con, int (*response_callback)(void *object, uint8_t connection_id,
186 uint8_t *public_key), void *object) 186 const uint8_t *public_key), void *object)
187{ 187{
188 con->response_callback = response_callback; 188 con->response_callback = response_callback;
189 con->response_callback_object = object; 189 con->response_callback_object = object;
@@ -200,7 +200,7 @@ void routing_status_handler(TCP_Client_Connection *con, int (*status_callback)(v
200 * return 0 if could not send packet. 200 * return 0 if could not send packet.
201 * return -1 on failure. 201 * return -1 on failure.
202 */ 202 */
203int send_data(TCP_Client_Connection *con, uint8_t con_id, uint8_t *data, uint16_t length) 203int send_data(TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, uint16_t length)
204{ 204{
205 if (con_id >= NUM_CLIENT_CONNECTIONS) 205 if (con_id >= NUM_CLIENT_CONNECTIONS)
206 return -1; 206 return -1;
@@ -218,7 +218,7 @@ int send_data(TCP_Client_Connection *con, uint8_t con_id, uint8_t *data, uint16_
218 * return 0 if could not send packet. 218 * return 0 if could not send packet.
219 * return -1 on failure. 219 * return -1 on failure.
220 */ 220 */
221int send_oob_packet(TCP_Client_Connection *con, uint8_t *public_key, uint8_t *data, uint16_t length) 221int send_oob_packet(TCP_Client_Connection *con, const uint8_t *public_key, const uint8_t *data, uint16_t length)
222{ 222{
223 if (length == 0 || length > TCP_MAX_OOB_DATA_LENGTH) 223 if (length == 0 || length > TCP_MAX_OOB_DATA_LENGTH)
224 return -1; 224 return -1;
@@ -251,14 +251,14 @@ int set_tcp_connection_number(TCP_Client_Connection *con, uint8_t con_id, uint32
251} 251}
252 252
253void routing_data_handler(TCP_Client_Connection *con, int (*data_callback)(void *object, uint32_t number, 253void routing_data_handler(TCP_Client_Connection *con, int (*data_callback)(void *object, uint32_t number,
254 uint8_t connection_id, uint8_t *data, uint16_t length), void *object) 254 uint8_t connection_id, const uint8_t *data, uint16_t length), void *object)
255{ 255{
256 con->data_callback = data_callback; 256 con->data_callback = data_callback;
257 con->data_callback_object = object; 257 con->data_callback_object = object;
258} 258}
259 259
260void oob_data_handler(TCP_Client_Connection *con, int (*oob_data_callback)(void *object, uint8_t *public_key, 260void oob_data_handler(TCP_Client_Connection *con, int (*oob_data_callback)(void *object, const uint8_t *public_key,
261 uint8_t *data, uint16_t length), void *object) 261 const uint8_t *data, uint16_t length), void *object)
262{ 262{
263 con->oob_data_callback = oob_data_callback; 263 con->oob_data_callback = oob_data_callback;
264 con->oob_data_callback_object = object; 264 con->oob_data_callback_object = object;
diff --git a/toxcore/TCP_client.h b/toxcore/TCP_client.h
index 90c79180..82487ab4 100644
--- a/toxcore/TCP_client.h
+++ b/toxcore/TCP_client.h
@@ -64,13 +64,13 @@ typedef struct {
64 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; 64 uint8_t public_key[crypto_box_PUBLICKEYBYTES];
65 uint32_t number; 65 uint32_t number;
66 } connections[NUM_CLIENT_CONNECTIONS]; 66 } connections[NUM_CLIENT_CONNECTIONS];
67 int (*response_callback)(void *object, uint8_t connection_id, uint8_t *public_key); 67 int (*response_callback)(void *object, uint8_t connection_id, const uint8_t *public_key);
68 void *response_callback_object; 68 void *response_callback_object;
69 int (*status_callback)(void *object, uint32_t number, uint8_t connection_id, uint8_t status); 69 int (*status_callback)(void *object, uint32_t number, uint8_t connection_id, uint8_t status);
70 void *status_callback_object; 70 void *status_callback_object;
71 int (*data_callback)(void *object, uint32_t number, uint8_t connection_id, uint8_t *data, uint16_t length); 71 int (*data_callback)(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length);
72 void *data_callback_object; 72 void *data_callback_object;
73 int (*oob_data_callback)(void *object, uint8_t *public_key, uint8_t *data, uint16_t length); 73 int (*oob_data_callback)(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length);
74 void *oob_data_callback_object; 74 void *oob_data_callback_object;
75 75
76 int (*onion_callback)(void *object, uint8_t *data, uint16_t length); 76 int (*onion_callback)(void *object, uint8_t *data, uint16_t length);
@@ -104,7 +104,7 @@ void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(vo
104 */ 104 */
105int send_routing_request(TCP_Client_Connection *con, uint8_t *public_key); 105int send_routing_request(TCP_Client_Connection *con, uint8_t *public_key);
106void routing_response_handler(TCP_Client_Connection *con, int (*response_callback)(void *object, uint8_t connection_id, 106void routing_response_handler(TCP_Client_Connection *con, int (*response_callback)(void *object, uint8_t connection_id,
107 uint8_t *public_key), void *object); 107 const uint8_t *public_key), void *object);
108void routing_status_handler(TCP_Client_Connection *con, int (*status_callback)(void *object, uint32_t number, 108void routing_status_handler(TCP_Client_Connection *con, int (*status_callback)(void *object, uint32_t number,
109 uint8_t connection_id, uint8_t status), void *object); 109 uint8_t connection_id, uint8_t status), void *object);
110 110
@@ -127,17 +127,17 @@ int set_tcp_connection_number(TCP_Client_Connection *con, uint8_t con_id, uint32
127 * return 0 if could not send packet. 127 * return 0 if could not send packet.
128 * return -1 on failure. 128 * return -1 on failure.
129 */ 129 */
130int send_data(TCP_Client_Connection *con, uint8_t con_id, uint8_t *data, uint16_t length); 130int send_data(TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, uint16_t length);
131void routing_data_handler(TCP_Client_Connection *con, int (*data_callback)(void *object, uint32_t number, 131void routing_data_handler(TCP_Client_Connection *con, int (*data_callback)(void *object, uint32_t number,
132 uint8_t connection_id, uint8_t *data, uint16_t length), void *object); 132 uint8_t connection_id, const uint8_t *data, uint16_t length), void *object);
133 133
134/* return 1 on success. 134/* return 1 on success.
135 * return 0 if could not send packet. 135 * return 0 if could not send packet.
136 * return -1 on failure. 136 * return -1 on failure.
137 */ 137 */
138int send_oob_packet(TCP_Client_Connection *con, uint8_t *public_key, uint8_t *data, uint16_t length); 138int send_oob_packet(TCP_Client_Connection *con, const uint8_t *public_key, const uint8_t *data, uint16_t length);
139void oob_data_handler(TCP_Client_Connection *con, int (*oob_data_callback)(void *object, uint8_t *public_key, 139void oob_data_handler(TCP_Client_Connection *con, int (*oob_data_callback)(void *object, const uint8_t *public_key,
140 uint8_t *data, uint16_t length), void *object); 140 const uint8_t *data, uint16_t length), void *object);
141 141
142 142
143#endif 143#endif
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 4dce8391..d90d0278 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -32,7 +32,7 @@
32#include "util.h" 32#include "util.h"
33#include "math.h" 33#include "math.h"
34 34
35static uint8_t crypt_connection_id_not_valid(Net_Crypto *c, int crypt_connection_id) 35static uint8_t crypt_connection_id_not_valid(const Net_Crypto *c, int crypt_connection_id)
36{ 36{
37 return (uint32_t)crypt_connection_id >= c->crypto_connections_length; 37 return (uint32_t)crypt_connection_id >= c->crypto_connections_length;
38} 38}
@@ -70,7 +70,7 @@ static int is_alive(uint8_t status)
70 * return -1 on failure. 70 * return -1 on failure.
71 * return COOKIE_REQUEST_LENGTH on success. 71 * return COOKIE_REQUEST_LENGTH on success.
72 */ 72 */
73static int create_cookie_request(Net_Crypto *c, uint8_t *packet, uint8_t *dht_public_key, uint64_t number, 73static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, uint8_t *dht_public_key, uint64_t number,
74 uint8_t *shared_key) 74 uint8_t *shared_key)
75{ 75{
76 uint8_t plain[COOKIE_REQUEST_PLAIN_LENGTH]; 76 uint8_t plain[COOKIE_REQUEST_PLAIN_LENGTH];
@@ -100,7 +100,7 @@ static int create_cookie_request(Net_Crypto *c, uint8_t *packet, uint8_t *dht_pu
100 * return -1 on failure. 100 * return -1 on failure.
101 * return 0 on success. 101 * return 0 on success.
102 */ 102 */
103static int create_cookie(uint8_t *cookie, uint8_t *bytes, uint8_t *encryption_key) 103static int create_cookie(uint8_t *cookie, const uint8_t *bytes, const uint8_t *encryption_key)
104{ 104{
105 uint8_t contents[COOKIE_CONTENTS_LENGTH]; 105 uint8_t contents[COOKIE_CONTENTS_LENGTH];
106 uint64_t temp_time = unix_time(); 106 uint64_t temp_time = unix_time();
@@ -148,8 +148,8 @@ static int open_cookie(uint8_t *bytes, const uint8_t *cookie, const uint8_t *enc
148 * return -1 on failure. 148 * return -1 on failure.
149 * return COOKIE_RESPONSE_LENGTH on success. 149 * return COOKIE_RESPONSE_LENGTH on success.
150 */ 150 */
151static int create_cookie_response(Net_Crypto *c, uint8_t *packet, uint8_t *request_plain, uint8_t *shared_key, 151static int create_cookie_response(const Net_Crypto *c, uint8_t *packet, const uint8_t *request_plain, const uint8_t *shared_key,
152 uint8_t *dht_public_key) 152 const uint8_t *dht_public_key)
153{ 153{
154 uint8_t cookie_plain[COOKIE_DATA_LENGTH]; 154 uint8_t cookie_plain[COOKIE_DATA_LENGTH];
155 memcpy(cookie_plain, request_plain, crypto_box_PUBLICKEYBYTES); 155 memcpy(cookie_plain, request_plain, crypto_box_PUBLICKEYBYTES);
@@ -177,7 +177,7 @@ static int create_cookie_response(Net_Crypto *c, uint8_t *packet, uint8_t *reque
177 * return -1 on failure. 177 * return -1 on failure.
178 * return 0 on success. 178 * return 0 on success.
179 */ 179 */
180static int handle_cookie_request(Net_Crypto *c, uint8_t *request_plain, uint8_t *shared_key, uint8_t *dht_public_key, 180static int handle_cookie_request(const Net_Crypto *c, uint8_t *request_plain, uint8_t *shared_key, uint8_t *dht_public_key,
181 const uint8_t *packet, uint16_t length) 181 const uint8_t *packet, uint16_t length)
182{ 182{
183 if (length != COOKIE_REQUEST_LENGTH) 183 if (length != COOKIE_REQUEST_LENGTH)
@@ -220,7 +220,7 @@ static int udp_handle_cookie_request(void *object, IP_Port source, const uint8_t
220 220
221/* Handle the cookie request packet (for TCP) 221/* Handle the cookie request packet (for TCP)
222 */ 222 */
223static int tcp_handle_cookie_request(Net_Crypto *c, TCP_Client_Connection *TCP_con, uint8_t conn_id, uint8_t *packet, 223static int tcp_handle_cookie_request(const Net_Crypto *c, TCP_Client_Connection *TCP_con, uint8_t conn_id, const uint8_t *packet,
224 uint32_t length) 224 uint32_t length)
225{ 225{
226 uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH]; 226 uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH];
@@ -243,8 +243,8 @@ static int tcp_handle_cookie_request(Net_Crypto *c, TCP_Client_Connection *TCP_c
243 243
244/* Handle the cookie request packet (for TCP oob packets) 244/* Handle the cookie request packet (for TCP oob packets)
245 */ 245 */
246static int tcp_oob_handle_cookie_request(Net_Crypto *c, TCP_Client_Connection *TCP_con, uint8_t *dht_public_key, 246static int tcp_oob_handle_cookie_request(const Net_Crypto *c, TCP_Client_Connection *TCP_con, const uint8_t *dht_public_key,
247 uint8_t *packet, uint32_t length) 247 const uint8_t *packet, uint32_t length)
248{ 248{
249 uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH]; 249 uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH];
250 uint8_t shared_key[crypto_box_BEFORENMBYTES]; 250 uint8_t shared_key[crypto_box_BEFORENMBYTES];
@@ -302,8 +302,8 @@ static int handle_cookie_response(uint8_t *cookie, uint64_t *number, const uint8
302 * return -1 on failure. 302 * return -1 on failure.
303 * return HANDSHAKE_PACKET_LENGTH on success. 303 * return HANDSHAKE_PACKET_LENGTH on success.
304 */ 304 */
305static int create_crypto_handshake(Net_Crypto *c, uint8_t *packet, uint8_t *cookie, uint8_t *nonce, uint8_t *session_pk, 305static int create_crypto_handshake(const Net_Crypto *c, uint8_t *packet, const uint8_t *cookie, const uint8_t *nonce, const uint8_t *session_pk,
306 uint8_t *peer_real_pk, uint8_t *peer_dht_pubkey) 306 const uint8_t *peer_real_pk, const uint8_t *peer_dht_pubkey)
307{ 307{
308 uint8_t plain[crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + crypto_hash_sha512_BYTES + COOKIE_LENGTH]; 308 uint8_t plain[crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + crypto_hash_sha512_BYTES + COOKIE_LENGTH];
309 memcpy(plain, nonce, crypto_box_NONCEBYTES); 309 memcpy(plain, nonce, crypto_box_NONCEBYTES);
@@ -348,8 +348,8 @@ static int create_crypto_handshake(Net_Crypto *c, uint8_t *packet, uint8_t *cook
348 * return -1 on failure. 348 * return -1 on failure.
349 * return 0 on success. 349 * return 0 on success.
350 */ 350 */
351static int handle_crypto_handshake(Net_Crypto *c, uint8_t *nonce, uint8_t *session_pk, uint8_t *peer_real_pk, 351static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t *session_pk, uint8_t *peer_real_pk,
352 uint8_t *dht_public_key, uint8_t *cookie, const uint8_t *packet, uint32_t length, uint8_t *expected_real_pk) 352 uint8_t *dht_public_key, uint8_t *cookie, const uint8_t *packet, uint32_t length, const uint8_t *expected_real_pk)
353{ 353{
354 if (length != HANDSHAKE_PACKET_LENGTH) 354 if (length != HANDSHAKE_PACKET_LENGTH)
355 return -1; 355 return -1;
@@ -386,7 +386,7 @@ static int handle_crypto_handshake(Net_Crypto *c, uint8_t *nonce, uint8_t *sessi
386} 386}
387 387
388 388
389static Crypto_Connection *get_crypto_connection(Net_Crypto *c, int crypt_connection_id) 389static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_connection_id)
390{ 390{
391 if (crypt_connection_id_not_valid(c, crypt_connection_id)) 391 if (crypt_connection_id_not_valid(c, crypt_connection_id))
392 return 0; 392 return 0;
@@ -400,7 +400,7 @@ static Crypto_Connection *get_crypto_connection(Net_Crypto *c, int crypt_connect
400 * return -1 on failure. 400 * return -1 on failure.
401 * return 0 on success. 401 * return 0 on success.
402 */ 402 */
403static int send_packet_to(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint16_t length) 403static int send_packet_to(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length)
404{ 404{
405//TODO TCP, etc... 405//TODO TCP, etc...
406 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 406 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@@ -456,7 +456,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, uint8_t *data,
456/* Return number of packets in array 456/* Return number of packets in array
457 * Note that holes are counted too. 457 * Note that holes are counted too.
458 */ 458 */
459static uint32_t num_packets_array(Packets_Array *array) 459static uint32_t num_packets_array(const Packets_Array *array)
460{ 460{
461 return array->buffer_end - array->buffer_start; 461 return array->buffer_end - array->buffer_start;
462} 462}
@@ -466,7 +466,7 @@ static uint32_t num_packets_array(Packets_Array *array)
466 * return -1 on failure. 466 * return -1 on failure.
467 * return 0 on success. 467 * return 0 on success.
468 */ 468 */
469static int add_data_to_buffer(Packets_Array *array, uint32_t number, Packet_Data *data) 469static int add_data_to_buffer(Packets_Array *array, uint32_t number, const Packet_Data *data)
470{ 470{
471 if (number - array->buffer_start > CRYPTO_PACKET_BUFFER_SIZE) 471 if (number - array->buffer_start > CRYPTO_PACKET_BUFFER_SIZE)
472 return -1; 472 return -1;
@@ -496,7 +496,7 @@ static int add_data_to_buffer(Packets_Array *array, uint32_t number, Packet_Data
496 * return 0 if data at number is empty. 496 * return 0 if data at number is empty.
497 * return 1 if data pointer was put in data. 497 * return 1 if data pointer was put in data.
498 */ 498 */
499static int get_data_pointer(Packets_Array *array, Packet_Data **data, uint32_t number) 499static int get_data_pointer(const Packets_Array *array, Packet_Data **data, uint32_t number)
500{ 500{
501 uint32_t num_spots = array->buffer_end - array->buffer_start; 501 uint32_t num_spots = array->buffer_end - array->buffer_start;
502 502
@@ -517,7 +517,7 @@ static int get_data_pointer(Packets_Array *array, Packet_Data **data, uint32_t n
517 * return -1 on failure. 517 * return -1 on failure.
518 * return packet number on success. 518 * return packet number on success.
519 */ 519 */
520static int64_t add_data_end_of_buffer(Packets_Array *array, Packet_Data *data) 520static int64_t add_data_end_of_buffer(Packets_Array *array, const Packet_Data *data)
521{ 521{
522 if (num_packets_array(array) >= CRYPTO_PACKET_BUFFER_SIZE) 522 if (num_packets_array(array) >= CRYPTO_PACKET_BUFFER_SIZE)
523 return -1; 523 return -1;
@@ -607,7 +607,7 @@ static int set_buffer_end(Packets_Array *array, uint32_t number)
607 * return -1 on failure. 607 * return -1 on failure.
608 * return length of packet on success. 608 * return length of packet on success.
609 */ 609 */
610static int generate_request_packet(uint8_t *data, uint16_t length, Packets_Array *recv_array) 610static int generate_request_packet(uint8_t *data, uint16_t length, const Packets_Array *recv_array)
611{ 611{
612 if (length == 0) 612 if (length == 0)
613 return -1; 613 return -1;
@@ -656,7 +656,7 @@ static int generate_request_packet(uint8_t *data, uint16_t length, Packets_Array
656 * return -1 on failure. 656 * return -1 on failure.
657 * return number of requested packets on success. 657 * return number of requested packets on success.
658 */ 658 */
659static int handle_request_packet(Packets_Array *send_array, uint8_t *data, uint16_t length) 659static int handle_request_packet(Packets_Array *send_array, const uint8_t *data, uint16_t length)
660{ 660{
661 if (length < 1) 661 if (length < 1)
662 return -1; 662 return -1;
@@ -718,7 +718,7 @@ static int handle_request_packet(Packets_Array *send_array, uint8_t *data, uint1
718 * return -1 on failure. 718 * return -1 on failure.
719 * return 0 on success. 719 * return 0 on success.
720 */ 720 */
721static int send_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint16_t length) 721static int send_data_packet(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length)
722{ 722{
723 if (length == 0 || length + (1 + sizeof(uint16_t) + crypto_box_MACBYTES) > MAX_CRYPTO_PACKET_SIZE) 723 if (length == 0 || length + (1 + sizeof(uint16_t) + crypto_box_MACBYTES) > MAX_CRYPTO_PACKET_SIZE)
724 return -1; 724 return -1;
@@ -750,7 +750,7 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *dat
750 * return -1 on failure. 750 * return -1 on failure.
751 * return 0 on success. 751 * return 0 on success.
752 */ 752 */
753static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint32_t buffer_start, uint32_t num, 753static int send_data_packet_helper(const Net_Crypto *c, int crypt_connection_id, uint32_t buffer_start, uint32_t num,
754 const uint8_t *data, uint32_t length) 754 const uint8_t *data, uint32_t length)
755{ 755{
756 if (length == 0 || length > MAX_CRYPTO_DATA_SIZE) 756 if (length == 0 || length > MAX_CRYPTO_DATA_SIZE)
@@ -771,7 +771,7 @@ static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint3
771/* return -1 if data could not be put in packet queue. 771/* return -1 if data could not be put in packet queue.
772 * return positive packet number if data was put into the queue. 772 * return positive packet number if data was put into the queue.
773 */ 773 */
774static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length) 774static int64_t send_lossless_packet(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length)
775{ 775{
776 if (length == 0 || length > MAX_CRYPTO_DATA_SIZE) 776 if (length == 0 || length > MAX_CRYPTO_DATA_SIZE)
777 return -1; 777 return -1;
@@ -827,7 +827,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons
827/* Get the lowest 2 bytes from the nonce and convert 827/* Get the lowest 2 bytes from the nonce and convert
828 * them to host byte format before returning them. 828 * them to host byte format before returning them.
829 */ 829 */
830static uint16_t get_nonce_uint16(uint8_t *nonce) 830static uint16_t get_nonce_uint16(const uint8_t *nonce)
831{ 831{
832 uint16_t num; 832 uint16_t num;
833 memcpy(&num, nonce + (crypto_box_NONCEBYTES - sizeof(uint16_t)), sizeof(uint16_t)); 833 memcpy(&num, nonce + (crypto_box_NONCEBYTES - sizeof(uint16_t)), sizeof(uint16_t));
@@ -843,7 +843,7 @@ static uint16_t get_nonce_uint16(uint8_t *nonce)
843 * return -1 on failure. 843 * return -1 on failure.
844 * return length of data on success. 844 * return length of data on success.
845 */ 845 */
846static int handle_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *data, const uint8_t *packet, 846static int handle_data_packet(const Net_Crypto *c, int crypt_connection_id, uint8_t *data, const uint8_t *packet,
847 uint16_t length) 847 uint16_t length)
848{ 848{
849 if (length <= (1 + sizeof(uint16_t) + crypto_box_MACBYTES) || length > MAX_CRYPTO_PACKET_SIZE) 849 if (length <= (1 + sizeof(uint16_t) + crypto_box_MACBYTES) || length > MAX_CRYPTO_PACKET_SIZE)
@@ -880,7 +880,7 @@ static int handle_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *d
880 * return -1 on failure. 880 * return -1 on failure.
881 * return 0 on success. 881 * return 0 on success.
882 */ 882 */
883static int send_request_packet(Net_Crypto *c, int crypt_connection_id) 883static int send_request_packet(const Net_Crypto *c, int crypt_connection_id)
884{ 884{
885 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 885 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
886 886
@@ -902,7 +902,7 @@ static int send_request_packet(Net_Crypto *c, int crypt_connection_id)
902 * return -1 on failure. 902 * return -1 on failure.
903 * return number of packets sent on success. 903 * return number of packets sent on success.
904 */ 904 */
905static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint16_t max_num) 905static int send_requested_packets(const Net_Crypto *c, int crypt_connection_id, uint16_t max_num)
906{ 906{
907 if (max_num == 0) 907 if (max_num == 0)
908 return -1; 908 return -1;
@@ -948,7 +948,7 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint16
948 * return -1 on failure. 948 * return -1 on failure.
949 * return 0 on success. 949 * return 0 on success.
950 */ 950 */
951static int new_temp_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *packet, uint16_t length) 951static int new_temp_packet(const Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length)
952{ 952{
953 if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) 953 if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE)
954 return -1; 954 return -1;
@@ -979,7 +979,7 @@ static int new_temp_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *pack
979 * return -1 on failure. 979 * return -1 on failure.
980 * return 0 on success. 980 * return 0 on success.
981 */ 981 */
982static int clear_temp_packet(Net_Crypto *c, int crypt_connection_id) 982static int clear_temp_packet(const Net_Crypto *c, int crypt_connection_id)
983{ 983{
984 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 984 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
985 985
@@ -1002,7 +1002,7 @@ static int clear_temp_packet(Net_Crypto *c, int crypt_connection_id)
1002 * return -1 on failure. 1002 * return -1 on failure.
1003 * return 0 on success. 1003 * return 0 on success.
1004 */ 1004 */
1005static int send_temp_packet(Net_Crypto *c, int crypt_connection_id) 1005static int send_temp_packet(const Net_Crypto *c, int crypt_connection_id)
1006{ 1006{
1007 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1007 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1008 1008
@@ -1026,7 +1026,7 @@ static int send_temp_packet(Net_Crypto *c, int crypt_connection_id)
1026 * return -1 on failure. 1026 * return -1 on failure.
1027 * return 0 on success. 1027 * return 0 on success.
1028 */ 1028 */
1029static int create_send_handshake(Net_Crypto *c, int crypt_connection_id, uint8_t *cookie, uint8_t *dht_public_key) 1029static int create_send_handshake(const Net_Crypto *c, int crypt_connection_id, const uint8_t *cookie, const uint8_t *dht_public_key)
1030{ 1030{
1031 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1031 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1032 1032
@@ -1051,7 +1051,7 @@ static int create_send_handshake(Net_Crypto *c, int crypt_connection_id, uint8_t
1051 * return -1 on failure. 1051 * return -1 on failure.
1052 * return 0 on success. 1052 * return 0 on success.
1053 */ 1053 */
1054static int send_kill_packet(Net_Crypto *c, int crypt_connection_id) 1054static int send_kill_packet(const Net_Crypto *c, int crypt_connection_id)
1055{ 1055{
1056 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1056 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1057 1057
@@ -1068,7 +1068,7 @@ static int send_kill_packet(Net_Crypto *c, int crypt_connection_id)
1068 * return -1 on failure. 1068 * return -1 on failure.
1069 * return 0 on success. 1069 * return 0 on success.
1070 */ 1070 */
1071static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length) 1071static int handle_data_packet_helper(const Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length)
1072{ 1072{
1073 if (length > MAX_CRYPTO_PACKET_SIZE || length <= CRYPTO_DATA_PACKET_MIN_SIZE) 1073 if (length > MAX_CRYPTO_PACKET_SIZE || length <= CRYPTO_DATA_PACKET_MIN_SIZE)
1074 return -1; 1074 return -1;
@@ -1317,7 +1317,7 @@ static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id)
1317 * return -1 if there are no connections like we are looking for. 1317 * return -1 if there are no connections like we are looking for.
1318 * return id if it found it. 1318 * return id if it found it.
1319 */ 1319 */
1320static int getcryptconnection_id(Net_Crypto *c, const uint8_t *public_key) 1320static int getcryptconnection_id(const Net_Crypto *c, const uint8_t *public_key)
1321{ 1321{
1322 uint32_t i; 1322 uint32_t i;
1323 1323
@@ -1335,7 +1335,7 @@ static int getcryptconnection_id(Net_Crypto *c, const uint8_t *public_key)
1335 * return -1 if there are no connections like we are looking for. 1335 * return -1 if there are no connections like we are looking for.
1336 * return id if it found it. 1336 * return id if it found it.
1337 */ 1337 */
1338static int getcryptconnection_id_dht_pubkey(Net_Crypto *c, uint8_t *dht_public_key) 1338static int getcryptconnection_id_dht_pubkey(const Net_Crypto *c, const uint8_t *dht_public_key)
1339{ 1339{
1340 uint32_t i; 1340 uint32_t i;
1341 1341
@@ -1523,7 +1523,7 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key)
1523 * return -1 on failure. 1523 * return -1 on failure.
1524 * return 0 on success. 1524 * return 0 on success.
1525 */ 1525 */
1526static int disconnect_peer_tcp(Net_Crypto *c, int crypt_connection_id) 1526static int disconnect_peer_tcp(const Net_Crypto *c, int crypt_connection_id)
1527{ 1527{
1528 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1528 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1529 1529
@@ -1548,7 +1548,7 @@ static int disconnect_peer_tcp(Net_Crypto *c, int crypt_connection_id)
1548 * return -1 on failure. 1548 * return -1 on failure.
1549 * return 0 on success. 1549 * return 0 on success.
1550 */ 1550 */
1551static int connect_peer_tcp(Net_Crypto *c, int crypt_connection_id) 1551static int connect_peer_tcp(const Net_Crypto *c, int crypt_connection_id)
1552{ 1552{
1553 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1553 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1554 1554
@@ -1573,7 +1573,7 @@ static int connect_peer_tcp(Net_Crypto *c, int crypt_connection_id)
1573 * return 0 on failure (no key copied). 1573 * return 0 on failure (no key copied).
1574 * return timestamp on success (key copied). 1574 * return timestamp on success (key copied).
1575 */ 1575 */
1576uint64_t get_connection_dht_key(Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key) 1576uint64_t get_connection_dht_key(const Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key)
1577{ 1577{
1578 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1578 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1579 1579
@@ -1595,7 +1595,7 @@ uint64_t get_connection_dht_key(Net_Crypto *c, int crypt_connection_id, uint8_t
1595 * return -1 on failure. 1595 * return -1 on failure.
1596 * return 0 on success. 1596 * return 0 on success.
1597 */ 1597 */
1598int set_connection_dht_public_key(Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key, uint64_t timestamp) 1598int set_connection_dht_public_key(const Net_Crypto *c, int crypt_connection_id, const uint8_t *dht_public_key, uint64_t timestamp)
1599{ 1599{
1600 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1600 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1601 1601
@@ -1656,7 +1656,7 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port)
1656 return -1; 1656 return -1;
1657} 1657}
1658 1658
1659static int tcp_response_callback(void *object, uint8_t connection_id, uint8_t *public_key) 1659static int tcp_response_callback(void *object, uint8_t connection_id, const uint8_t *public_key)
1660{ 1660{
1661 TCP_Client_Connection *TCP_con = object; 1661 TCP_Client_Connection *TCP_con = object;
1662 Net_Crypto *c = TCP_con->net_crypto_pointer; 1662 Net_Crypto *c = TCP_con->net_crypto_pointer;
@@ -1723,7 +1723,7 @@ static int tcp_status_callback(void *object, uint32_t number, uint8_t connection
1723 return 0; 1723 return 0;
1724} 1724}
1725 1725
1726static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_id, uint8_t *data, uint16_t length) 1726static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length)
1727{ 1727{
1728 1728
1729 if (length == 0) 1729 if (length == 0)
@@ -1748,7 +1748,7 @@ static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_i
1748 return 0; 1748 return 0;
1749} 1749}
1750 1750
1751static int tcp_oob_callback(void *object, uint8_t *public_key, uint8_t *data, uint16_t length) 1751static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length)
1752{ 1752{
1753 if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) 1753 if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE)
1754 return -1; 1754 return -1;
@@ -1790,7 +1790,7 @@ static int tcp_oob_callback(void *object, uint8_t *public_key, uint8_t *data, ui
1790 * return -1 if it can't. 1790 * return -1 if it can't.
1791 * return 0 if it can. 1791 * return 0 if it can.
1792 */ 1792 */
1793static int tcp_connection_check(Net_Crypto *c, const uint8_t *public_key) 1793static int tcp_connection_check(const Net_Crypto *c, const uint8_t *public_key)
1794{ 1794{
1795 uint32_t i; 1795 uint32_t i;
1796 1796
@@ -1910,7 +1910,7 @@ int add_tcp_relay(Net_Crypto *c, IP_Port ip_port, const uint8_t *public_key)
1910 * return number of relays copied to tcp_relays on success. 1910 * return number of relays copied to tcp_relays on success.
1911 * return 0 on failure. 1911 * return 0 on failure.
1912 */ 1912 */
1913unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, uint16_t num) 1913unsigned int copy_connected_tcp_relays(const Net_Crypto *c, Node_format *tcp_relays, uint16_t num)
1914{ 1914{
1915 if (num == 0) 1915 if (num == 0)
1916 return 0; 1916 return 0;
@@ -2074,7 +2074,7 @@ static void clear_disconnected_tcp(Net_Crypto *c)
2074 * return -1 on failure. 2074 * return -1 on failure.
2075 * return 0 on success. 2075 * return 0 on success.
2076 */ 2076 */
2077int connection_status_handler(Net_Crypto *c, int crypt_connection_id, int (*connection_status_callback)(void *object, 2077int connection_status_handler(const Net_Crypto *c, int crypt_connection_id, int (*connection_status_callback)(void *object,
2078 int id, uint8_t status), void *object, int id) 2078 int id, uint8_t status), void *object, int id)
2079{ 2079{
2080 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2080 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@@ -2096,7 +2096,7 @@ int connection_status_handler(Net_Crypto *c, int crypt_connection_id, int (*conn
2096 * return -1 on failure. 2096 * return -1 on failure.
2097 * return 0 on success. 2097 * return 0 on success.
2098 */ 2098 */
2099int connection_data_handler(Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object, 2099int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object,
2100 int id, uint8_t *data, uint16_t length), void *object, int id) 2100 int id, uint8_t *data, uint16_t length), void *object, int id)
2101{ 2101{
2102 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2102 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@@ -2137,7 +2137,7 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
2137 * return -1 on failure. 2137 * return -1 on failure.
2138 * return connection id on success. 2138 * return connection id on success.
2139 */ 2139 */
2140static int crypto_id_ip_port(Net_Crypto *c, IP_Port ip_port) 2140static int crypto_id_ip_port(const Net_Crypto *c, IP_Port ip_port)
2141{ 2141{
2142 return bs_list_find(&c->ip_port_list, &ip_port); 2142 return bs_list_find(&c->ip_port_list, &ip_port);
2143} 2143}
@@ -2373,7 +2373,7 @@ static void send_crypto_packets(Net_Crypto *c)
2373/* returns the number of packet slots left in the sendbuffer. 2373/* returns the number of packet slots left in the sendbuffer.
2374 * return 0 if failure. 2374 * return 0 if failure.
2375 */ 2375 */
2376uint32_t crypto_num_free_sendqueue_slots(Net_Crypto *c, int crypt_connection_id) 2376uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connection_id)
2377{ 2377{
2378 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2378 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2379 2379
@@ -2390,7 +2390,7 @@ uint32_t crypto_num_free_sendqueue_slots(Net_Crypto *c, int crypt_connection_id)
2390 * 2390 *
2391 * The first byte of data must be in the CRYPTO_RESERVED_PACKETS to PACKET_ID_LOSSY_RANGE_START range. 2391 * The first byte of data must be in the CRYPTO_RESERVED_PACKETS to PACKET_ID_LOSSY_RANGE_START range.
2392 */ 2392 */
2393int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length) 2393int64_t write_cryptpacket(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length)
2394{ 2394{
2395 if (length == 0) 2395 if (length == 0)
2396 return -1; 2396 return -1;
@@ -2427,7 +2427,7 @@ int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t
2427 * 2427 *
2428 * Sends a lossy cryptopacket. (first byte must in the PACKET_ID_LOSSY_RANGE_*) 2428 * Sends a lossy cryptopacket. (first byte must in the PACKET_ID_LOSSY_RANGE_*)
2429 */ 2429 */
2430int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length) 2430int send_lossy_cryptpacket(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length)
2431{ 2431{
2432 if (length == 0 || length > MAX_CRYPTO_DATA_SIZE) 2432 if (length == 0 || length > MAX_CRYPTO_DATA_SIZE)
2433 return -1; 2433 return -1;
@@ -2469,7 +2469,7 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id)
2469 * 2469 *
2470 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't. 2470 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't.
2471 */ 2471 */
2472unsigned int crypto_connection_status(Net_Crypto *c, int crypt_connection_id, uint8_t *direct_connected) 2472unsigned int crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, uint8_t *direct_connected)
2473{ 2473{
2474 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2474 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2475 2475
@@ -2492,7 +2492,7 @@ void new_keys(Net_Crypto *c)
2492/* Save the public and private keys to the keys array. 2492/* Save the public and private keys to the keys array.
2493 * Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES. 2493 * Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES.
2494 */ 2494 */
2495void save_keys(Net_Crypto *c, uint8_t *keys) 2495void save_keys(const Net_Crypto *c, uint8_t *keys)
2496{ 2496{
2497 memcpy(keys, c->self_public_key, crypto_box_PUBLICKEYBYTES); 2497 memcpy(keys, c->self_public_key, crypto_box_PUBLICKEYBYTES);
2498 memcpy(keys + crypto_box_PUBLICKEYBYTES, c->self_secret_key, crypto_box_SECRETKEYBYTES); 2498 memcpy(keys + crypto_box_PUBLICKEYBYTES, c->self_secret_key, crypto_box_SECRETKEYBYTES);
@@ -2580,7 +2580,7 @@ static void kill_timedout(Net_Crypto *c)
2580 2580
2581/* return the optimal interval in ms for running do_net_crypto. 2581/* return the optimal interval in ms for running do_net_crypto.
2582 */ 2582 */
2583uint32_t crypto_run_interval(Net_Crypto *c) 2583uint32_t crypto_run_interval(const Net_Crypto *c)
2584{ 2584{
2585 return c->current_sleep_time; 2585 return c->current_sleep_time;
2586} 2586}
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index 178a83b6..41e2219b 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -227,7 +227,7 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key);
227 * return 0 on failure (no key copied). 227 * return 0 on failure (no key copied).
228 * return timestamp on success (key copied). 228 * return timestamp on success (key copied).
229 */ 229 */
230uint64_t get_connection_dht_key(Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key); 230uint64_t get_connection_dht_key(const Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key);
231 231
232/* Set the DHT public key of the crypto connection. 232/* Set the DHT public key of the crypto connection.
233 * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to 233 * timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to
@@ -236,7 +236,7 @@ uint64_t get_connection_dht_key(Net_Crypto *c, int crypt_connection_id, uint8_t
236 * return -1 on failure. 236 * return -1 on failure.
237 * return 0 on success. 237 * return 0 on success.
238 */ 238 */
239int set_connection_dht_public_key(Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key, uint64_t timestamp); 239int set_connection_dht_public_key(const Net_Crypto *c, int crypt_connection_id, const uint8_t *dht_public_key, uint64_t timestamp);
240 240
241/* Set the direct ip of the crypto connection. 241/* Set the direct ip of the crypto connection.
242 * 242 *
@@ -255,7 +255,7 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port);
255 * return -1 on failure. 255 * return -1 on failure.
256 * return 0 on success. 256 * return 0 on success.
257 */ 257 */
258int connection_status_handler(Net_Crypto *c, int crypt_connection_id, int (*connection_status_callback)(void *object, 258int connection_status_handler(const Net_Crypto *c, int crypt_connection_id, int (*connection_status_callback)(void *object,
259 int id, uint8_t status), void *object, int id); 259 int id, uint8_t status), void *object, int id);
260 260
261/* Set function to be called when connection with crypt_connection_id receives a lossless data packet of length. 261/* Set function to be called when connection with crypt_connection_id receives a lossless data packet of length.
@@ -266,7 +266,7 @@ int connection_status_handler(Net_Crypto *c, int crypt_connection_id, int (*conn
266 * return -1 on failure. 266 * return -1 on failure.
267 * return 0 on success. 267 * return 0 on success.
268 */ 268 */
269int connection_data_handler(Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object, 269int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object,
270 int id, uint8_t *data, uint16_t length), void *object, int id); 270 int id, uint8_t *data, uint16_t length), void *object, int id);
271 271
272 272
@@ -284,7 +284,7 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
284/* returns the number of packet slots left in the sendbuffer. 284/* returns the number of packet slots left in the sendbuffer.
285 * return 0 if failure. 285 * return 0 if failure.
286 */ 286 */
287uint32_t crypto_num_free_sendqueue_slots(Net_Crypto *c, int crypt_connection_id); 287uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connection_id);
288 288
289/* Sends a lossless cryptopacket. 289/* Sends a lossless cryptopacket.
290 * 290 *
@@ -293,14 +293,14 @@ uint32_t crypto_num_free_sendqueue_slots(Net_Crypto *c, int crypt_connection_id)
293 * 293 *
294 * The first byte of data must be in the CRYPTO_RESERVED_PACKETS to PACKET_ID_LOSSY_RANGE_START range. 294 * The first byte of data must be in the CRYPTO_RESERVED_PACKETS to PACKET_ID_LOSSY_RANGE_START range.
295 */ 295 */
296int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length); 296int64_t write_cryptpacket(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length);
297 297
298/* return -1 on failure. 298/* return -1 on failure.
299 * return 0 on success. 299 * return 0 on success.
300 * 300 *
301 * Sends a lossy cryptopacket. (first byte must in the PACKET_ID_LOSSY_RANGE_*) 301 * Sends a lossy cryptopacket. (first byte must in the PACKET_ID_LOSSY_RANGE_*)
302 */ 302 */
303int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length); 303int send_lossy_cryptpacket(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length);
304 304
305/* Add a tcp relay, associating it to a crypt_connection_id. 305/* Add a tcp relay, associating it to a crypt_connection_id.
306 * 306 *
@@ -322,7 +322,7 @@ int add_tcp_relay(Net_Crypto *c, IP_Port ip_port, const uint8_t *public_key);
322 * return number of relays copied to tcp_relays on success. 322 * return number of relays copied to tcp_relays on success.
323 * return 0 on failure. 323 * return 0 on failure.
324 */ 324 */
325unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, uint16_t num); 325unsigned int copy_connected_tcp_relays(const Net_Crypto *c, Node_format *tcp_relays, uint16_t num);
326 326
327/* Kill a crypto connection. 327/* Kill a crypto connection.
328 * 328 *
@@ -336,7 +336,7 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id);
336 * 336 *
337 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't. 337 * sets direct_connected to 1 if connection connects directly to other, 0 if it isn't.
338 */ 338 */
339unsigned int crypto_connection_status(Net_Crypto *c, int crypt_connection_id, uint8_t *direct_connected); 339unsigned int crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, uint8_t *direct_connected);
340 340
341 341
342/* Generate our public and private keys. 342/* Generate our public and private keys.
@@ -347,7 +347,7 @@ void new_keys(Net_Crypto *c);
347/* Save the public and private keys to the keys array. 347/* Save the public and private keys to the keys array.
348 * Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES. 348 * Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES.
349 */ 349 */
350void save_keys(Net_Crypto *c, uint8_t *keys); 350void save_keys(const Net_Crypto *c, uint8_t *keys);
351 351
352/* Load the public and private keys from the keys array. 352/* Load the public and private keys from the keys array.
353 * Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES. 353 * Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES.
@@ -361,7 +361,7 @@ Net_Crypto *new_net_crypto(DHT *dht);
361 361
362/* return the optimal interval in ms for running do_net_crypto. 362/* return the optimal interval in ms for running do_net_crypto.
363 */ 363 */
364uint32_t crypto_run_interval(Net_Crypto *c); 364uint32_t crypto_run_interval(const Net_Crypto *c);
365 365
366/* Main loop. */ 366/* Main loop. */
367void do_net_crypto(Net_Crypto *c); 367void do_net_crypto(Net_Crypto *c);