summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-06-23 17:16:28 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-06-24 19:17:32 +0000
commit8e00294b3cb9808ce55160240454359638178275 (patch)
tree095a7708b3fe3566951ebe7b068ee66a8beed3c1 /toxcore
parent5a8790eab0ed9421445adce40526462b9e6742c3 (diff)
Add Logger to various net_crypto functions.
In preparation for adding log statements. Also, fix an uninitialised variable warning in cppcheck.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/DHT.c8
-rw-r--r--toxcore/DHT.h2
-rw-r--r--toxcore/net_crypto.c63
-rw-r--r--toxcore/net_crypto.h2
-rw-r--r--toxcore/network.c12
-rw-r--r--toxcore/network.h6
-rw-r--r--toxcore/util.c2
-rw-r--r--toxcore/util.h2
8 files changed, 49 insertions, 48 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 6134f59b..bb996e2d 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -85,7 +85,7 @@ struct DHT_Friend {
85}; 85};
86 86
87struct DHT { 87struct DHT {
88 Logger *log; 88 const Logger *log;
89 Networking_Core *net; 89 Networking_Core *net;
90 90
91 bool hole_punching_enabled; 91 bool hole_punching_enabled;
@@ -658,7 +658,7 @@ static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size,
658 658
659/* Update ip_port of client if it's needed. 659/* Update ip_port of client if it's needed.
660 */ 660 */
661static void update_client(Logger *log, int index, Client_data *client, IP_Port ip_port) 661static void update_client(const Logger *log, int index, Client_data *client, IP_Port ip_port)
662{ 662{
663 IPPTsPng *assoc; 663 IPPTsPng *assoc;
664 int ip_version; 664 int ip_version;
@@ -698,7 +698,7 @@ static void update_client(Logger *log, int index, Client_data *client, IP_Port i
698 * 698 *
699 * return True(1) or False(0) 699 * return True(1) or False(0)
700 */ 700 */
701static int client_or_ip_port_in_list(Logger *log, Client_data *list, uint16_t length, const uint8_t *public_key, 701static int client_or_ip_port_in_list(const Logger *log, Client_data *list, uint16_t length, const uint8_t *public_key,
702 IP_Port ip_port) 702 IP_Port ip_port)
703{ 703{
704 const uint64_t temp_time = unix_time(); 704 const uint64_t temp_time = unix_time();
@@ -2673,7 +2673,7 @@ static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *pack
2673 2673
2674/*----------------------------------------------------------------------------------*/ 2674/*----------------------------------------------------------------------------------*/
2675 2675
2676DHT *new_DHT(Logger *log, Networking_Core *net, bool holepunching_enabled) 2676DHT *new_DHT(const Logger *log, Networking_Core *net, bool holepunching_enabled)
2677{ 2677{
2678 /* init time */ 2678 /* init time */
2679 unix_time_update(); 2679 unix_time_update();
diff --git a/toxcore/DHT.h b/toxcore/DHT.h
index 3ad28d8c..bbfeb307 100644
--- a/toxcore/DHT.h
+++ b/toxcore/DHT.h
@@ -405,7 +405,7 @@ void DHT_save(const DHT *dht, uint8_t *data);
405int DHT_load(DHT *dht, const uint8_t *data, uint32_t length); 405int DHT_load(DHT *dht, const uint8_t *data, uint32_t length);
406 406
407/* Initialize DHT. */ 407/* Initialize DHT. */
408DHT *new_DHT(Logger *log, Networking_Core *net, bool holepunching_enabled); 408DHT *new_DHT(const Logger *log, Networking_Core *net, bool holepunching_enabled);
409 409
410void kill_DHT(DHT *dht); 410void kill_DHT(DHT *dht);
411 411
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index fbf41552..f82cef69 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -130,7 +130,7 @@ typedef struct {
130} Crypto_Connection; 130} Crypto_Connection;
131 131
132struct Net_Crypto { 132struct Net_Crypto {
133 Logger *log; 133 const Logger *log;
134 134
135 DHT *dht; 135 DHT *dht;
136 TCP_Connections *tcp_c; 136 TCP_Connections *tcp_c;
@@ -245,7 +245,7 @@ static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, uint8_t *
245 * return -1 on failure. 245 * return -1 on failure.
246 * return 0 on success. 246 * return 0 on success.
247 */ 247 */
248static int create_cookie(uint8_t *cookie, const uint8_t *bytes, const uint8_t *encryption_key) 248static int create_cookie(const Logger *log, uint8_t *cookie, const uint8_t *bytes, const uint8_t *encryption_key)
249{ 249{
250 uint8_t contents[COOKIE_CONTENTS_LENGTH]; 250 uint8_t contents[COOKIE_CONTENTS_LENGTH];
251 uint64_t temp_time = unix_time(); 251 uint64_t temp_time = unix_time();
@@ -266,7 +266,7 @@ static int create_cookie(uint8_t *cookie, const uint8_t *bytes, const uint8_t *e
266 * return -1 on failure. 266 * return -1 on failure.
267 * return 0 on success. 267 * return 0 on success.
268 */ 268 */
269static int open_cookie(uint8_t *bytes, const uint8_t *cookie, const uint8_t *encryption_key) 269static int open_cookie(const Logger *log, uint8_t *bytes, const uint8_t *cookie, const uint8_t *encryption_key)
270{ 270{
271 uint8_t contents[COOKIE_CONTENTS_LENGTH]; 271 uint8_t contents[COOKIE_CONTENTS_LENGTH];
272 int len = decrypt_data_symmetric(encryption_key, cookie, cookie + CRYPTO_NONCE_SIZE, 272 int len = decrypt_data_symmetric(encryption_key, cookie, cookie + CRYPTO_NONCE_SIZE,
@@ -304,7 +304,7 @@ static int create_cookie_response(const Net_Crypto *c, uint8_t *packet, const ui
304 memcpy(cookie_plain + CRYPTO_PUBLIC_KEY_SIZE, dht_public_key, CRYPTO_PUBLIC_KEY_SIZE); 304 memcpy(cookie_plain + CRYPTO_PUBLIC_KEY_SIZE, dht_public_key, CRYPTO_PUBLIC_KEY_SIZE);
305 uint8_t plain[COOKIE_LENGTH + sizeof(uint64_t)]; 305 uint8_t plain[COOKIE_LENGTH + sizeof(uint64_t)];
306 306
307 if (create_cookie(plain, cookie_plain, c->secret_symmetric_key) != 0) { 307 if (create_cookie(c->log, plain, cookie_plain, c->secret_symmetric_key) != 0) {
308 return -1; 308 return -1;
309 } 309 }
310 310
@@ -431,7 +431,8 @@ static int tcp_oob_handle_cookie_request(const Net_Crypto *c, unsigned int tcp_c
431 * return -1 on failure. 431 * return -1 on failure.
432 * return COOKIE_LENGTH on success. 432 * return COOKIE_LENGTH on success.
433 */ 433 */
434static int handle_cookie_response(uint8_t *cookie, uint64_t *number, const uint8_t *packet, uint16_t length, 434static int handle_cookie_response(const Logger *log, uint8_t *cookie, uint64_t *number,
435 const uint8_t *packet, uint16_t length,
435 const uint8_t *shared_key) 436 const uint8_t *shared_key)
436{ 437{
437 if (length != COOKIE_RESPONSE_LENGTH) { 438 if (length != COOKIE_RESPONSE_LENGTH) {
@@ -471,7 +472,7 @@ static int create_crypto_handshake(const Net_Crypto *c, uint8_t *packet, const u
471 memcpy(cookie_plain, peer_real_pk, CRYPTO_PUBLIC_KEY_SIZE); 472 memcpy(cookie_plain, peer_real_pk, CRYPTO_PUBLIC_KEY_SIZE);
472 memcpy(cookie_plain + CRYPTO_PUBLIC_KEY_SIZE, peer_dht_pubkey, CRYPTO_PUBLIC_KEY_SIZE); 473 memcpy(cookie_plain + CRYPTO_PUBLIC_KEY_SIZE, peer_dht_pubkey, CRYPTO_PUBLIC_KEY_SIZE);
473 474
474 if (create_cookie(plain + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SHA512_SIZE, cookie_plain, 475 if (create_cookie(c->log, plain + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SHA512_SIZE, cookie_plain,
475 c->secret_symmetric_key) != 0) { 476 c->secret_symmetric_key) != 0) {
476 return -1; 477 return -1;
477 } 478 }
@@ -517,7 +518,7 @@ static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t
517 518
518 uint8_t cookie_plain[COOKIE_DATA_LENGTH]; 519 uint8_t cookie_plain[COOKIE_DATA_LENGTH];
519 520
520 if (open_cookie(cookie_plain, packet + 1, c->secret_symmetric_key) != 0) { 521 if (open_cookie(c->log, cookie_plain, packet + 1, c->secret_symmetric_key) != 0) {
521 return -1; 522 return -1;
522 } 523 }
523 524
@@ -724,7 +725,7 @@ static uint32_t num_packets_array(const Packets_Array *array)
724 * return -1 on failure. 725 * return -1 on failure.
725 * return 0 on success. 726 * return 0 on success.
726 */ 727 */
727static int add_data_to_buffer(Packets_Array *array, uint32_t number, const Packet_Data *data) 728static int add_data_to_buffer(const Logger *log, Packets_Array *array, uint32_t number, const Packet_Data *data)
728{ 729{
729 if (number - array->buffer_start > CRYPTO_PACKET_BUFFER_SIZE) { 730 if (number - array->buffer_start > CRYPTO_PACKET_BUFFER_SIZE) {
730 return -1; 731 return -1;
@@ -758,7 +759,7 @@ static int add_data_to_buffer(Packets_Array *array, uint32_t number, const Packe
758 * return 0 if data at number is empty. 759 * return 0 if data at number is empty.
759 * return 1 if data pointer was put in data. 760 * return 1 if data pointer was put in data.
760 */ 761 */
761static int get_data_pointer(const Packets_Array *array, Packet_Data **data, uint32_t number) 762static int get_data_pointer(const Logger *log, const Packets_Array *array, Packet_Data **data, uint32_t number)
762{ 763{
763 uint32_t num_spots = array->buffer_end - array->buffer_start; 764 uint32_t num_spots = array->buffer_end - array->buffer_start;
764 765
@@ -781,7 +782,7 @@ static int get_data_pointer(const Packets_Array *array, Packet_Data **data, uint
781 * return -1 on failure. 782 * return -1 on failure.
782 * return packet number on success. 783 * return packet number on success.
783 */ 784 */
784static int64_t add_data_end_of_buffer(Packets_Array *array, const Packet_Data *data) 785static int64_t add_data_end_of_buffer(const Logger *log, Packets_Array *array, const Packet_Data *data)
785{ 786{
786 if (num_packets_array(array) >= CRYPTO_PACKET_BUFFER_SIZE) { 787 if (num_packets_array(array) >= CRYPTO_PACKET_BUFFER_SIZE) {
787 return -1; 788 return -1;
@@ -800,12 +801,12 @@ static int64_t add_data_end_of_buffer(Packets_Array *array, const Packet_Data *d
800 return id; 801 return id;
801} 802}
802 803
803/* Read data from begginning of array. 804/* Read data from beginning of array.
804 * 805 *
805 * return -1 on failure. 806 * return -1 on failure.
806 * return packet number on success. 807 * return packet number on success.
807 */ 808 */
808static int64_t read_data_beg_buffer(Packets_Array *array, Packet_Data *data) 809static int64_t read_data_beg_buffer(const Logger *log, Packets_Array *array, Packet_Data *data)
809{ 810{
810 if (array->buffer_end == array->buffer_start) { 811 if (array->buffer_end == array->buffer_start) {
811 return -1; 812 return -1;
@@ -830,7 +831,7 @@ static int64_t read_data_beg_buffer(Packets_Array *array, Packet_Data *data)
830 * return -1 on failure. 831 * return -1 on failure.
831 * return 0 on success 832 * return 0 on success
832 */ 833 */
833static int clear_buffer_until(Packets_Array *array, uint32_t number) 834static int clear_buffer_until(const Logger *log, Packets_Array *array, uint32_t number)
834{ 835{
835 uint32_t num_spots = array->buffer_end - array->buffer_start; 836 uint32_t num_spots = array->buffer_end - array->buffer_start;
836 837
@@ -875,7 +876,7 @@ static int clear_buffer(Packets_Array *array)
875 * return -1 on failure. 876 * return -1 on failure.
876 * return 0 on success. 877 * return 0 on success.
877 */ 878 */
878static int set_buffer_end(Packets_Array *array, uint32_t number) 879static int set_buffer_end(const Logger *log, Packets_Array *array, uint32_t number)
879{ 880{
880 if ((number - array->buffer_start) > CRYPTO_PACKET_BUFFER_SIZE) { 881 if ((number - array->buffer_start) > CRYPTO_PACKET_BUFFER_SIZE) {
881 return -1; 882 return -1;
@@ -895,7 +896,7 @@ static int set_buffer_end(Packets_Array *array, uint32_t number)
895 * return -1 on failure. 896 * return -1 on failure.
896 * return length of packet on success. 897 * return length of packet on success.
897 */ 898 */
898static int generate_request_packet(uint8_t *data, uint16_t length, const Packets_Array *recv_array) 899static int generate_request_packet(const Logger *log, uint8_t *data, uint16_t length, const Packets_Array *recv_array)
899{ 900{
900 if (length == 0) { 901 if (length == 0) {
901 return -1; 902 return -1;
@@ -948,7 +949,7 @@ static int generate_request_packet(uint8_t *data, uint16_t length, const Packets
948 * return -1 on failure. 949 * return -1 on failure.
949 * return number of requested packets on success. 950 * return number of requested packets on success.
950 */ 951 */
951static int handle_request_packet(Packets_Array *send_array, const uint8_t *data, uint16_t length, 952static int handle_request_packet(const Logger *log, Packets_Array *send_array, const uint8_t *data, uint16_t length,
952 uint64_t *latest_send_time, uint64_t rtt_time) 953 uint64_t *latest_send_time, uint64_t rtt_time)
953{ 954{
954 if (length < 1) { 955 if (length < 1) {
@@ -1101,7 +1102,7 @@ static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id)
1101 if (conn->maximum_speed_reached) { 1102 if (conn->maximum_speed_reached) {
1102 Packet_Data *dt = nullptr; 1103 Packet_Data *dt = nullptr;
1103 uint32_t packet_num = conn->send_array.buffer_end - 1; 1104 uint32_t packet_num = conn->send_array.buffer_end - 1;
1104 int ret = get_data_pointer(&conn->send_array, &dt, packet_num); 1105 int ret = get_data_pointer(c->log, &conn->send_array, &dt, packet_num);
1105 1106
1106 uint8_t send_failed = 0; 1107 uint8_t send_failed = 0;
1107 1108
@@ -1155,7 +1156,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons
1155 dt.length = length; 1156 dt.length = length;
1156 memcpy(dt.data, data, length); 1157 memcpy(dt.data, data, length);
1157 pthread_mutex_lock(&conn->mutex); 1158 pthread_mutex_lock(&conn->mutex);
1158 int64_t packet_num = add_data_end_of_buffer(&conn->send_array, &dt); 1159 int64_t packet_num = add_data_end_of_buffer(c->log, &conn->send_array, &dt);
1159 pthread_mutex_unlock(&conn->mutex); 1160 pthread_mutex_unlock(&conn->mutex);
1160 1161
1161 if (packet_num == -1) { 1162 if (packet_num == -1) {
@@ -1169,7 +1170,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons
1169 if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, data, length) == 0) { 1170 if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, data, length) == 0) {
1170 Packet_Data *dt1 = nullptr; 1171 Packet_Data *dt1 = nullptr;
1171 1172
1172 if (get_data_pointer(&conn->send_array, &dt1, packet_num) == 1) { 1173 if (get_data_pointer(c->log, &conn->send_array, &dt1, packet_num) == 1) {
1173 dt1->sent_time = current_time_monotonic(); 1174 dt1->sent_time = current_time_monotonic();
1174 } 1175 }
1175 } else { 1176 } else {
@@ -1248,7 +1249,7 @@ static int send_request_packet(Net_Crypto *c, int crypt_connection_id)
1248 } 1249 }
1249 1250
1250 uint8_t data[MAX_CRYPTO_DATA_SIZE]; 1251 uint8_t data[MAX_CRYPTO_DATA_SIZE];
1251 int len = generate_request_packet(data, sizeof(data), &conn->recv_array); 1252 int len = generate_request_packet(c->log, data, sizeof(data), &conn->recv_array);
1252 1253
1253 if (len == -1) { 1254 if (len == -1) {
1254 return -1; 1255 return -1;
@@ -1281,7 +1282,7 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32
1281 for (i = 0; i < array_size; ++i) { 1282 for (i = 0; i < array_size; ++i) {
1282 Packet_Data *dt; 1283 Packet_Data *dt;
1283 uint32_t packet_num = (i + conn->send_array.buffer_start); 1284 uint32_t packet_num = (i + conn->send_array.buffer_start);
1284 int ret = get_data_pointer(&conn->send_array, &dt, packet_num); 1285 int ret = get_data_pointer(c->log, &conn->send_array, &dt, packet_num);
1285 1286
1286 if (ret == -1) { 1287 if (ret == -1) {
1287 return -1; 1288 return -1;
@@ -1496,11 +1497,11 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
1496 if (buffer_start != conn->send_array.buffer_start) { 1497 if (buffer_start != conn->send_array.buffer_start) {
1497 Packet_Data *packet_time; 1498 Packet_Data *packet_time;
1498 1499
1499 if (get_data_pointer(&conn->send_array, &packet_time, conn->send_array.buffer_start) == 1) { 1500 if (get_data_pointer(c->log, &conn->send_array, &packet_time, conn->send_array.buffer_start) == 1) {
1500 rtt_calc_time = packet_time->sent_time; 1501 rtt_calc_time = packet_time->sent_time;
1501 } 1502 }
1502 1503
1503 if (clear_buffer_until(&conn->send_array, buffer_start) != 0) { 1504 if (clear_buffer_until(c->log, &conn->send_array, buffer_start) != 0) {
1504 return -1; 1505 return -1;
1505 } 1506 }
1506 } 1507 }
@@ -1541,25 +1542,25 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
1541 rtt_time = DEFAULT_TCP_PING_CONNECTION; 1542 rtt_time = DEFAULT_TCP_PING_CONNECTION;
1542 } 1543 }
1543 1544
1544 int requested = handle_request_packet(&conn->send_array, real_data, real_length, &rtt_calc_time, rtt_time); 1545 int requested = handle_request_packet(c->log, &conn->send_array, real_data, real_length, &rtt_calc_time, rtt_time);
1545 1546
1546 if (requested == -1) { 1547 if (requested == -1) {
1547 return -1; 1548 return -1;
1548 } 1549 }
1549 1550
1550 set_buffer_end(&conn->recv_array, num); 1551 set_buffer_end(c->log, &conn->recv_array, num);
1551 } else if (real_data[0] >= CRYPTO_RESERVED_PACKETS && real_data[0] < PACKET_ID_LOSSY_RANGE_START) { 1552 } else if (real_data[0] >= CRYPTO_RESERVED_PACKETS && real_data[0] < PACKET_ID_LOSSY_RANGE_START) {
1552 Packet_Data dt; 1553 Packet_Data dt = {0};
1553 dt.length = real_length; 1554 dt.length = real_length;
1554 memcpy(dt.data, real_data, real_length); 1555 memcpy(dt.data, real_data, real_length);
1555 1556
1556 if (add_data_to_buffer(&conn->recv_array, num, &dt) != 0) { 1557 if (add_data_to_buffer(c->log, &conn->recv_array, num, &dt) != 0) {
1557 return -1; 1558 return -1;
1558 } 1559 }
1559 1560
1560 while (1) { 1561 while (1) {
1561 pthread_mutex_lock(&conn->mutex); 1562 pthread_mutex_lock(&conn->mutex);
1562 int ret = read_data_beg_buffer(&conn->recv_array, &dt); 1563 int ret = read_data_beg_buffer(c->log, &conn->recv_array, &dt);
1563 pthread_mutex_unlock(&conn->mutex); 1564 pthread_mutex_unlock(&conn->mutex);
1564 1565
1565 if (ret == -1) { 1566 if (ret == -1) {
@@ -1584,7 +1585,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
1584 } else if (real_data[0] >= PACKET_ID_LOSSY_RANGE_START && 1585 } else if (real_data[0] >= PACKET_ID_LOSSY_RANGE_START &&
1585 real_data[0] < (PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE)) { 1586 real_data[0] < (PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE)) {
1586 1587
1587 set_buffer_end(&conn->recv_array, num); 1588 set_buffer_end(c->log, &conn->recv_array, num);
1588 1589
1589 if (conn->connection_lossy_data_callback) { 1590 if (conn->connection_lossy_data_callback) {
1590 conn->connection_lossy_data_callback(conn->connection_lossy_data_callback_object, 1591 conn->connection_lossy_data_callback(conn->connection_lossy_data_callback_object,
@@ -1632,7 +1633,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons
1632 uint8_t cookie[COOKIE_LENGTH]; 1633 uint8_t cookie[COOKIE_LENGTH];
1633 uint64_t number; 1634 uint64_t number;
1634 1635
1635 if (handle_cookie_response(cookie, &number, packet, length, conn->shared_key) != sizeof(cookie)) { 1636 if (handle_cookie_response(c->log, cookie, &number, packet, length, conn->shared_key) != sizeof(cookie)) {
1636 return -1; 1637 return -1;
1637 } 1638 }
1638 1639
@@ -2928,7 +2929,7 @@ void load_secret_key(Net_Crypto *c, const uint8_t *sk)
2928/* Run this to (re)initialize net_crypto. 2929/* Run this to (re)initialize net_crypto.
2929 * Sets all the global connection variables to their default values. 2930 * Sets all the global connection variables to their default values.
2930 */ 2931 */
2931Net_Crypto *new_net_crypto(Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info) 2932Net_Crypto *new_net_crypto(const Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info)
2932{ 2933{
2933 unix_time_update(); 2934 unix_time_update();
2934 2935
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index f6b2648e..2a76013e 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -299,7 +299,7 @@ void load_secret_key(Net_Crypto *c, const uint8_t *sk);
299/* Create new instance of Net_Crypto. 299/* Create new instance of Net_Crypto.
300 * Sets all the global connection variables to their default values. 300 * Sets all the global connection variables to their default values.
301 */ 301 */
302Net_Crypto *new_net_crypto(Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info); 302Net_Crypto *new_net_crypto(const Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info);
303 303
304/* return the optimal interval in ms for running do_net_crypto. 304/* return the optimal interval in ms for running do_net_crypto.
305 */ 305 */
diff --git a/toxcore/network.c b/toxcore/network.c
index 44ca2dee..30c3bb6c 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -495,7 +495,7 @@ static uint32_t data_1(uint16_t buflen, const uint8_t *buffer)
495 return buflen > 7 ? net_ntohl(*(const uint32_t *)&buffer[5]) : 0; 495 return buflen > 7 ? net_ntohl(*(const uint32_t *)&buffer[5]) : 0;
496} 496}
497 497
498static void loglogdata(Logger *log, const char *message, const uint8_t *buffer, 498static void loglogdata(const Logger *log, const char *message, const uint8_t *buffer,
499 uint16_t buflen, IP_Port ip_port, int res) 499 uint16_t buflen, IP_Port ip_port, int res)
500{ 500{
501 char ip_str[IP_NTOA_LEN]; 501 char ip_str[IP_NTOA_LEN];
@@ -527,7 +527,7 @@ typedef struct {
527} Packet_Handler; 527} Packet_Handler;
528 528
529struct Networking_Core { 529struct Networking_Core {
530 Logger *log; 530 const Logger *log;
531 Packet_Handler packethandlers[256]; 531 Packet_Handler packethandlers[256];
532 532
533 Family family; 533 Family family;
@@ -616,7 +616,7 @@ int sendpacket(Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint1
616 * Packet data is put into data. 616 * Packet data is put into data.
617 * Packet length is put into length. 617 * Packet length is put into length.
618 */ 618 */
619static int receivepacket(Logger *log, Socket sock, IP_Port *ip_port, uint8_t *data, uint32_t *length) 619static int receivepacket(const Logger *log, Socket sock, IP_Port *ip_port, uint8_t *data, uint32_t *length)
620{ 620{
621 memset(ip_port, 0, sizeof(IP_Port)); 621 memset(ip_port, 0, sizeof(IP_Port));
622 struct sockaddr_storage addr; 622 struct sockaddr_storage addr;
@@ -766,7 +766,7 @@ static void at_shutdown(void)
766/* Initialize networking. 766/* Initialize networking.
767 * Added for reverse compatibility with old new_networking calls. 767 * Added for reverse compatibility with old new_networking calls.
768 */ 768 */
769Networking_Core *new_networking(Logger *log, IP ip, uint16_t port) 769Networking_Core *new_networking(const Logger *log, IP ip, uint16_t port)
770{ 770{
771 return new_networking_ex(log, ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), nullptr); 771 return new_networking_ex(log, ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), nullptr);
772} 772}
@@ -781,7 +781,7 @@ Networking_Core *new_networking(Logger *log, IP ip, uint16_t port)
781 * 781 *
782 * If error is non NULL it is set to 0 if no issues, 1 if socket related error, 2 if other. 782 * If error is non NULL it is set to 0 if no issues, 1 if socket related error, 2 if other.
783 */ 783 */
784Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint16_t port_to, unsigned int *error) 784Networking_Core *new_networking_ex(const Logger *log, IP ip, uint16_t port_from, uint16_t port_to, unsigned int *error)
785{ 785{
786 /* If both from and to are 0, use default port range 786 /* If both from and to are 0, use default port range
787 * If one is 0 and the other is non-0, use the non-0 value as only port 787 * If one is 0 and the other is non-0, use the non-0 value as only port
@@ -996,7 +996,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
996 return nullptr; 996 return nullptr;
997} 997}
998 998
999Networking_Core *new_networking_no_udp(Logger *log) 999Networking_Core *new_networking_no_udp(const Logger *log)
1000{ 1000{
1001 /* this is the easiest way to completely disable UDP without changing too much code. */ 1001 /* this is the easiest way to completely disable UDP without changing too much code. */
1002 Networking_Core *net = (Networking_Core *)calloc(1, sizeof(Networking_Core)); 1002 Networking_Core *net = (Networking_Core *)calloc(1, sizeof(Networking_Core));
diff --git a/toxcore/network.h b/toxcore/network.h
index 8071375b..fbd12bb7 100644
--- a/toxcore/network.h
+++ b/toxcore/network.h
@@ -458,9 +458,9 @@ void net_kill_strerror(const char *strerror);
458 * 458 *
459 * If error is non NULL it is set to 0 if no issues, 1 if socket related error, 2 if other. 459 * If error is non NULL it is set to 0 if no issues, 1 if socket related error, 2 if other.
460 */ 460 */
461Networking_Core *new_networking(Logger *log, IP ip, uint16_t port); 461Networking_Core *new_networking(const Logger *log, IP ip, uint16_t port);
462Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint16_t port_to, unsigned int *error); 462Networking_Core *new_networking_ex(const Logger *log, IP ip, uint16_t port_from, uint16_t port_to, unsigned int *error);
463Networking_Core *new_networking_no_udp(Logger *log); 463Networking_Core *new_networking_no_udp(const Logger *log);
464 464
465/* Function to cleanup networking stuff (doesn't do much right now). */ 465/* Function to cleanup networking stuff (doesn't do much right now). */
466void kill_networking(Networking_Core *net); 466void kill_networking(Networking_Core *net);
diff --git a/toxcore/util.c b/toxcore/util.c
index 082e453f..57d1762e 100644
--- a/toxcore/util.c
+++ b/toxcore/util.c
@@ -122,7 +122,7 @@ void lendian_to_host32(uint32_t *dest, const uint8_t *lendian)
122} 122}
123 123
124/* state load/save */ 124/* state load/save */
125int load_state(load_state_callback_func load_state_callback, Logger *log, void *outer, 125int load_state(load_state_callback_func load_state_callback, const Logger *log, void *outer,
126 const uint8_t *data, uint32_t length, uint16_t cookie_inner) 126 const uint8_t *data, uint32_t length, uint16_t cookie_inner)
127{ 127{
128 if (!load_state_callback || !data) { 128 if (!load_state_callback || !data) {
diff --git a/toxcore/util.h b/toxcore/util.h
index a9faa863..3979cefe 100644
--- a/toxcore/util.h
+++ b/toxcore/util.h
@@ -59,7 +59,7 @@ void lendian_to_host32(uint32_t *dest, const uint8_t *lendian);
59 59
60/* state load/save */ 60/* state load/save */
61typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type); 61typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type);
62int load_state(load_state_callback_func load_state_callback, Logger *log, void *outer, 62int load_state(load_state_callback_func load_state_callback, const Logger *log, void *outer,
63 const uint8_t *data, uint32_t length, uint16_t cookie_inner); 63 const uint8_t *data, uint32_t length, uint16_t cookie_inner);
64 64
65/* Returns -1 if failed or 0 if success */ 65/* Returns -1 if failed or 0 if success */