diff options
-rw-r--r-- | testing/Messenger_test.c | 2 | ||||
-rw-r--r-- | toxcore/DHT.c | 108 | ||||
-rw-r--r-- | toxcore/DHT.h | 42 | ||||
-rw-r--r-- | toxcore/Messenger.c | 22 | ||||
-rw-r--r-- | toxcore/Messenger.h | 14 | ||||
-rw-r--r-- | toxcore/friend_requests.c | 10 | ||||
-rw-r--r-- | toxcore/friend_requests.h | 8 | ||||
-rw-r--r-- | toxcore/group_chats.c | 2 | ||||
-rw-r--r-- | toxcore/group_chats.h | 2 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 2 | ||||
-rw-r--r-- | toxcore/net_crypto.h | 2 | ||||
-rw-r--r-- | toxcore/onion_client.c | 12 | ||||
-rw-r--r-- | toxcore/onion_client.h | 8 | ||||
-rw-r--r-- | toxcore/ping.c | 10 | ||||
-rw-r--r-- | toxcore/ping.h | 4 | ||||
-rw-r--r-- | toxcore/ping_array.c | 2 | ||||
-rw-r--r-- | toxcore/ping_array.h | 2 | ||||
-rw-r--r-- | toxcore/tox.c | 4 | ||||
-rw-r--r-- | toxcore/tox.h | 4 | ||||
-rw-r--r-- | toxcore/util.c | 2 | ||||
-rw-r--r-- | toxcore/util.h | 4 |
21 files changed, 133 insertions, 133 deletions
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index a6efb433..7c1d64e7 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c | |||
@@ -66,7 +66,7 @@ void print_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t len | |||
66 | * networking_requesthandler and so cannot take a Messenger * */ | 66 | * networking_requesthandler and so cannot take a Messenger * */ |
67 | static Messenger *m; | 67 | static Messenger *m; |
68 | 68 | ||
69 | void print_request(Messenger *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata) | 69 | void print_request(Messenger *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) |
70 | { | 70 | { |
71 | printf("Friend request received from: \n"); | 71 | printf("Friend request received from: \n"); |
72 | printf("ClientID: "); | 72 | printf("ClientID: "); |
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index fed12861..92d6e159 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -83,7 +83,7 @@ Client_data *DHT_get_close_list(DHT *dht) | |||
83 | * return 1 if client_id1 is closer. | 83 | * return 1 if client_id1 is closer. |
84 | * return 2 if client_id2 is closer. | 84 | * return 2 if client_id2 is closer. |
85 | */ | 85 | */ |
86 | int id_closest(uint8_t *id, uint8_t *id1, uint8_t *id2) | 86 | int id_closest(const uint8_t *id, const uint8_t *id1, const uint8_t *id2) |
87 | { | 87 | { |
88 | size_t i; | 88 | size_t i; |
89 | uint8_t distance1, distance2; | 89 | uint8_t distance1, distance2; |
@@ -106,7 +106,7 @@ int id_closest(uint8_t *id, uint8_t *id1, uint8_t *id2) | |||
106 | /* Turns the result of id_closest into something quick_sort can use. | 106 | /* Turns the result of id_closest into something quick_sort can use. |
107 | * Assumes p1->c1 == p2->c1. | 107 | * Assumes p1->c1 == p2->c1. |
108 | */ | 108 | */ |
109 | static int client_id_cmp(ClientPair p1, ClientPair p2) | 109 | static int client_id_cmp(const ClientPair p1, const ClientPair p2) |
110 | { | 110 | { |
111 | int c = id_closest(p1.c1.client_id, p1.c2.client_id, p2.c2.client_id); | 111 | int c = id_closest(p1.c1.client_id, p1.c2.client_id, p2.c2.client_id); |
112 | 112 | ||
@@ -122,7 +122,7 @@ static int client_id_cmp(ClientPair p1, ClientPair p2) | |||
122 | * If shared key is already in shared_keys, copy it to shared_key. | 122 | * If shared key is already in shared_keys, copy it to shared_key. |
123 | * else generate it into shared_key and copy it to shared_keys | 123 | * else generate it into shared_key and copy it to shared_keys |
124 | */ | 124 | */ |
125 | void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, uint8_t *secret_key, uint8_t *client_id) | 125 | void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t *secret_key, const uint8_t *client_id) |
126 | { | 126 | { |
127 | uint32_t i, num = ~0, curr = 0; | 127 | uint32_t i, num = ~0, curr = 0; |
128 | 128 | ||
@@ -168,7 +168,7 @@ void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, uint8_t *secr | |||
168 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key | 168 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key |
169 | * for packets that we receive. | 169 | * for packets that we receive. |
170 | */ | 170 | */ |
171 | void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, uint8_t *client_id) | 171 | void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *client_id) |
172 | { | 172 | { |
173 | return get_shared_key(&dht->shared_keys_recv, shared_key, dht->self_secret_key, client_id); | 173 | return get_shared_key(&dht->shared_keys_recv, shared_key, dht->self_secret_key, client_id); |
174 | } | 174 | } |
@@ -176,7 +176,7 @@ void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, uint8_t *client_id) | |||
176 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key | 176 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key |
177 | * for packets that we send. | 177 | * for packets that we send. |
178 | */ | 178 | */ |
179 | void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, uint8_t *client_id) | 179 | void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *client_id) |
180 | { | 180 | { |
181 | return get_shared_key(&dht->shared_keys_sent, shared_key, dht->self_secret_key, client_id); | 181 | return get_shared_key(&dht->shared_keys_sent, shared_key, dht->self_secret_key, client_id); |
182 | } | 182 | } |
@@ -202,7 +202,7 @@ void to_host_family(IP *ip) | |||
202 | * return length of packed nodes on success. | 202 | * return length of packed nodes on success. |
203 | * return -1 on failure. | 203 | * return -1 on failure. |
204 | */ | 204 | */ |
205 | int pack_nodes(uint8_t *data, uint16_t length, Node_format *nodes, uint16_t number) | 205 | int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_t number) |
206 | { | 206 | { |
207 | uint32_t i, packed_length = 0; | 207 | uint32_t i, packed_length = 0; |
208 | 208 | ||
@@ -263,7 +263,7 @@ int pack_nodes(uint8_t *data, uint16_t length, Node_format *nodes, uint16_t numb | |||
263 | * return number of unpacked nodes on success. | 263 | * return number of unpacked nodes on success. |
264 | * return -1 on failure. | 264 | * return -1 on failure. |
265 | */ | 265 | */ |
266 | int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed_data_len, uint8_t *data, | 266 | int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed_data_len, const uint8_t *data, |
267 | uint16_t length, uint8_t tcp_enabled) | 267 | uint16_t length, uint8_t tcp_enabled) |
268 | { | 268 | { |
269 | uint32_t num = 0, len_processed = 0; | 269 | uint32_t num = 0, len_processed = 0; |
@@ -338,7 +338,7 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed | |||
338 | * | 338 | * |
339 | * return True(1) or False(0) | 339 | * return True(1) or False(0) |
340 | */ | 340 | */ |
341 | static int client_or_ip_port_in_list(Client_data *list, uint32_t length, uint8_t *client_id, IP_Port ip_port) | 341 | static int client_or_ip_port_in_list(Client_data *list, uint32_t length, const uint8_t *client_id, IP_Port ip_port) |
342 | { | 342 | { |
343 | uint32_t i; | 343 | uint32_t i; |
344 | uint64_t temp_time = unix_time(); | 344 | uint64_t temp_time = unix_time(); |
@@ -417,7 +417,7 @@ static int client_or_ip_port_in_list(Client_data *list, uint32_t length, uint8_t | |||
417 | * return 1 if true. | 417 | * return 1 if true. |
418 | * return 0 if false. | 418 | * return 0 if false. |
419 | */ | 419 | */ |
420 | static int client_in_nodelist(Node_format *list, uint32_t length, uint8_t *client_id) | 420 | static int client_in_nodelist(const Node_format *list, uint32_t length, const uint8_t *client_id) |
421 | { | 421 | { |
422 | uint32_t i; | 422 | uint32_t i; |
423 | 423 | ||
@@ -432,7 +432,7 @@ static int client_in_nodelist(Node_format *list, uint32_t length, uint8_t *clien | |||
432 | /* return friend number from the client_id. | 432 | /* return friend number from the client_id. |
433 | * return -1 if a failure occurs. | 433 | * return -1 if a failure occurs. |
434 | */ | 434 | */ |
435 | static int friend_number(DHT *dht, uint8_t *client_id) | 435 | static int friend_number(const DHT *dht, const uint8_t *client_id) |
436 | { | 436 | { |
437 | uint32_t i; | 437 | uint32_t i; |
438 | 438 | ||
@@ -452,15 +452,15 @@ static int friend_number(DHT *dht, uint8_t *client_id) | |||
452 | * return 4 if it can test other nodes correctly | 452 | * return 4 if it can test other nodes correctly |
453 | * return HARDENING_ALL_OK if all ok. | 453 | * return HARDENING_ALL_OK if all ok. |
454 | */ | 454 | */ |
455 | static uint8_t hardening_correct(Hardening *h) | 455 | static uint8_t hardening_correct(const Hardening *h) |
456 | { | 456 | { |
457 | return h->routes_requests_ok + (h->send_nodes_ok << 1) + (h->testing_requests << 2); | 457 | return h->routes_requests_ok + (h->send_nodes_ok << 1) + (h->testing_requests << 2); |
458 | } | 458 | } |
459 | /* | 459 | /* |
460 | * helper for get_close_nodes(). argument list is a monster :D | 460 | * helper for get_close_nodes(). argument list is a monster :D |
461 | */ | 461 | */ |
462 | static void get_close_nodes_inner(uint8_t *client_id, Node_format *nodes_list, | 462 | static void get_close_nodes_inner(const uint8_t *client_id, Node_format *nodes_list, |
463 | sa_family_t sa_family, Client_data *client_list, uint32_t client_list_length, | 463 | sa_family_t sa_family, const Client_data *client_list, uint32_t client_list_length, |
464 | uint32_t *num_nodes_ptr, uint8_t is_LAN, uint8_t want_good) | 464 | uint32_t *num_nodes_ptr, uint8_t is_LAN, uint8_t want_good) |
465 | { | 465 | { |
466 | if ((sa_family != AF_INET) && (sa_family != AF_INET6) && (sa_family != 0)) | 466 | if ((sa_family != AF_INET) && (sa_family != AF_INET6) && (sa_family != 0)) |
@@ -471,13 +471,13 @@ static void get_close_nodes_inner(uint8_t *client_id, Node_format *nodes_list, | |||
471 | uint32_t i; | 471 | uint32_t i; |
472 | 472 | ||
473 | for (i = 0; i < client_list_length; i++) { | 473 | for (i = 0; i < client_list_length; i++) { |
474 | Client_data *client = &client_list[i]; | 474 | const Client_data *client = &client_list[i]; |
475 | 475 | ||
476 | /* node already in list? */ | 476 | /* node already in list? */ |
477 | if (client_in_nodelist(nodes_list, MAX_SENT_NODES, client->client_id)) | 477 | if (client_in_nodelist(nodes_list, MAX_SENT_NODES, client->client_id)) |
478 | continue; | 478 | continue; |
479 | 479 | ||
480 | IPPTsPng *ipptp = NULL; | 480 | const IPPTsPng *ipptp = NULL; |
481 | 481 | ||
482 | if (sa_family == AF_INET) { | 482 | if (sa_family == AF_INET) { |
483 | ipptp = &client->assoc4; | 483 | ipptp = &client->assoc4; |
@@ -544,7 +544,7 @@ static void get_close_nodes_inner(uint8_t *client_id, Node_format *nodes_list, | |||
544 | * | 544 | * |
545 | * want_good : do we want only good nodes as checked with the hardening returned or not? | 545 | * want_good : do we want only good nodes as checked with the hardening returned or not? |
546 | */ | 546 | */ |
547 | static int get_somewhat_close_nodes(DHT *dht, uint8_t *client_id, Node_format *nodes_list, sa_family_t sa_family, | 547 | static int get_somewhat_close_nodes(const DHT *dht, const uint8_t *client_id, Node_format *nodes_list, sa_family_t sa_family, |
548 | uint8_t is_LAN, uint8_t want_good) | 548 | uint8_t is_LAN, uint8_t want_good) |
549 | { | 549 | { |
550 | uint32_t num_nodes = 0, i; | 550 | uint32_t num_nodes = 0, i; |
@@ -565,7 +565,7 @@ static int get_somewhat_close_nodes(DHT *dht, uint8_t *client_id, Node_format *n | |||
565 | return num_nodes; | 565 | return num_nodes; |
566 | } | 566 | } |
567 | 567 | ||
568 | int get_close_nodes(DHT *dht, uint8_t *client_id, Node_format *nodes_list, sa_family_t sa_family, uint8_t is_LAN, | 568 | int get_close_nodes(const DHT *dht, const uint8_t *client_id, Node_format *nodes_list, sa_family_t sa_family, uint8_t is_LAN, |
569 | uint8_t want_good) | 569 | uint8_t want_good) |
570 | { | 570 | { |
571 | memset(nodes_list, 0, MAX_SENT_NODES * sizeof(Node_format)); | 571 | memset(nodes_list, 0, MAX_SENT_NODES * sizeof(Node_format)); |
@@ -632,7 +632,7 @@ int get_close_nodes(DHT *dht, uint8_t *client_id, Node_format *nodes_list, sa_fa | |||
632 | */ | 632 | */ |
633 | static int replace_bad( Client_data *list, | 633 | static int replace_bad( Client_data *list, |
634 | uint32_t length, | 634 | uint32_t length, |
635 | uint8_t *client_id, | 635 | const uint8_t *client_id, |
636 | IP_Port ip_port ) | 636 | IP_Port ip_port ) |
637 | { | 637 | { |
638 | if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) | 638 | if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) |
@@ -680,7 +680,7 @@ static int replace_bad( Client_data *list, | |||
680 | /* Sort the list. It will be sorted from furthest to closest. | 680 | /* Sort the list. It will be sorted from furthest to closest. |
681 | * Turns list into data that quick sort can use and reverts it back. | 681 | * Turns list into data that quick sort can use and reverts it back. |
682 | */ | 682 | */ |
683 | static void sort_list(Client_data *list, uint32_t length, uint8_t *comp_client_id) | 683 | static void sort_list(Client_data *list, uint32_t length, const uint8_t *comp_client_id) |
684 | { | 684 | { |
685 | Client_data cd; | 685 | Client_data cd; |
686 | ClientPair pairs[length]; | 686 | ClientPair pairs[length]; |
@@ -706,9 +706,9 @@ static void sort_list(Client_data *list, uint32_t length, uint8_t *comp_client_i | |||
706 | */ | 706 | */ |
707 | static int replace_possible_bad( Client_data *list, | 707 | static int replace_possible_bad( Client_data *list, |
708 | uint32_t length, | 708 | uint32_t length, |
709 | uint8_t *client_id, | 709 | const uint8_t *client_id, |
710 | IP_Port ip_port, | 710 | IP_Port ip_port, |
711 | uint8_t *comp_client_id ) | 711 | const uint8_t *comp_client_id ) |
712 | { | 712 | { |
713 | if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) | 713 | if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) |
714 | return 1; | 714 | return 1; |
@@ -762,9 +762,9 @@ static int replace_possible_bad( Client_data *list, | |||
762 | * returns 0 when the item was stored, 1 otherwise */ | 762 | * returns 0 when the item was stored, 1 otherwise */ |
763 | static int replace_good( Client_data *list, | 763 | static int replace_good( Client_data *list, |
764 | uint32_t length, | 764 | uint32_t length, |
765 | uint8_t *client_id, | 765 | const uint8_t *client_id, |
766 | IP_Port ip_port, | 766 | IP_Port ip_port, |
767 | uint8_t *comp_client_id ) | 767 | const uint8_t *comp_client_id ) |
768 | { | 768 | { |
769 | if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) | 769 | if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) |
770 | return 1; | 770 | return 1; |
@@ -825,7 +825,7 @@ static int replace_good( Client_data *list, | |||
825 | * | 825 | * |
826 | * returns 1+ if the item is used in any list, 0 else | 826 | * returns 1+ if the item is used in any list, 0 else |
827 | */ | 827 | */ |
828 | int addto_lists(DHT *dht, IP_Port ip_port, uint8_t *client_id) | 828 | int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id) |
829 | { | 829 | { |
830 | uint32_t i, used = 0; | 830 | uint32_t i, used = 0; |
831 | 831 | ||
@@ -892,7 +892,7 @@ int addto_lists(DHT *dht, IP_Port ip_port, uint8_t *client_id) | |||
892 | /* If client_id is a friend or us, update ret_ip_port | 892 | /* If client_id is a friend or us, update ret_ip_port |
893 | * nodeclient_id is the id of the node that sent us this info. | 893 | * nodeclient_id is the id of the node that sent us this info. |
894 | */ | 894 | */ |
895 | static int returnedip_ports(DHT *dht, IP_Port ip_port, uint8_t *client_id, uint8_t *nodeclient_id) | 895 | static int returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *client_id, const uint8_t *nodeclient_id) |
896 | { | 896 | { |
897 | uint32_t i, j; | 897 | uint32_t i, j; |
898 | uint64_t temp_time = unix_time(); | 898 | uint64_t temp_time = unix_time(); |
@@ -961,7 +961,7 @@ end: | |||
961 | 961 | ||
962 | /* Send a getnodes request. | 962 | /* Send a getnodes request. |
963 | sendback_node is the node that it will send back the response to (set to NULL to disable this) */ | 963 | sendback_node is the node that it will send back the response to (set to NULL to disable this) */ |
964 | static int getnodes(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_t *client_id, Node_format *sendback_node) | 964 | static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *client_id, const Node_format *sendback_node) |
965 | { | 965 | { |
966 | /* Check if packet is going to be sent to ourself. */ | 966 | /* Check if packet is going to be sent to ourself. */ |
967 | if (id_equal(public_key, dht->self_public_key)) | 967 | if (id_equal(public_key, dht->self_public_key)) |
@@ -1017,8 +1017,8 @@ static int getnodes(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_t *cli | |||
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | /* Send a send nodes response: message for IPv6 nodes */ | 1019 | /* Send a send nodes response: message for IPv6 nodes */ |
1020 | static int sendnodes_ipv6(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_t *client_id, uint8_t *sendback_data, | 1020 | static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *client_id, const uint8_t *sendback_data, |
1021 | uint16_t length, uint8_t *shared_encryption_key) | 1021 | uint16_t length, const uint8_t *shared_encryption_key) |
1022 | { | 1022 | { |
1023 | /* Check if packet is going to be sent to ourself. */ | 1023 | /* Check if packet is going to be sent to ourself. */ |
1024 | if (id_equal(public_key, dht->self_public_key)) | 1024 | if (id_equal(public_key, dht->self_public_key)) |
@@ -1105,7 +1105,7 @@ static int handle_getnodes(void *object, IP_Port source, uint8_t *packet, uint32 | |||
1105 | } | 1105 | } |
1106 | /* return 0 if no | 1106 | /* return 0 if no |
1107 | return 1 if yes */ | 1107 | return 1 if yes */ |
1108 | static uint8_t sent_getnode_to_node(DHT *dht, uint8_t *client_id, IP_Port node_ip_port, uint64_t ping_id, | 1108 | static uint8_t sent_getnode_to_node(DHT *dht, const uint8_t *client_id, IP_Port node_ip_port, uint64_t ping_id, |
1109 | Node_format *sendback_node) | 1109 | Node_format *sendback_node) |
1110 | { | 1110 | { |
1111 | uint8_t data[sizeof(Node_format) * 2]; | 1111 | uint8_t data[sizeof(Node_format) * 2]; |
@@ -1128,10 +1128,10 @@ static uint8_t sent_getnode_to_node(DHT *dht, uint8_t *client_id, IP_Port node_i | |||
1128 | } | 1128 | } |
1129 | 1129 | ||
1130 | /* Function is needed in following functions. */ | 1130 | /* Function is needed in following functions. */ |
1131 | static int send_hardening_getnode_res(DHT *dht, Node_format *sendto, uint8_t *queried_client_id, uint8_t *nodes_data, | 1131 | static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto, const uint8_t *queried_client_id, const uint8_t *nodes_data, |
1132 | uint16_t nodes_data_length); | 1132 | uint16_t nodes_data_length); |
1133 | 1133 | ||
1134 | static int handle_sendnodes_core(void *object, IP_Port source, uint8_t *packet, uint32_t length, | 1134 | static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *packet, uint32_t length, |
1135 | Node_format *plain_nodes, uint16_t size_plain_nodes, uint32_t *num_nodes_out) | 1135 | Node_format *plain_nodes, uint16_t size_plain_nodes, uint32_t *num_nodes_out) |
1136 | { | 1136 | { |
1137 | DHT *dht = object; | 1137 | DHT *dht = object; |
@@ -1244,7 +1244,7 @@ static void get_bunchnodes(DHT *dht, Client_data *list, uint16_t length, uint16_ | |||
1244 | } | 1244 | } |
1245 | } | 1245 | } |
1246 | */ | 1246 | */ |
1247 | int DHT_addfriend(DHT *dht, uint8_t *client_id) | 1247 | int DHT_addfriend(DHT *dht, const uint8_t *client_id) |
1248 | { | 1248 | { |
1249 | if (friend_number(dht, client_id) != -1) /* Is friend already in DHT? */ | 1249 | if (friend_number(dht, client_id) != -1) /* Is friend already in DHT? */ |
1250 | return 1; | 1250 | return 1; |
@@ -1298,7 +1298,7 @@ int DHT_addfriend(DHT *dht, uint8_t *client_id) | |||
1298 | return 0; | 1298 | return 0; |
1299 | } | 1299 | } |
1300 | 1300 | ||
1301 | int DHT_delfriend(DHT *dht, uint8_t *client_id) | 1301 | int DHT_delfriend(DHT *dht, const uint8_t *client_id) |
1302 | { | 1302 | { |
1303 | uint32_t i; | 1303 | uint32_t i; |
1304 | DHT_Friend *temp; | 1304 | DHT_Friend *temp; |
@@ -1334,7 +1334,7 @@ int DHT_delfriend(DHT *dht, uint8_t *client_id) | |||
1334 | } | 1334 | } |
1335 | 1335 | ||
1336 | /* TODO: Optimize this. */ | 1336 | /* TODO: Optimize this. */ |
1337 | int DHT_getfriendip(DHT *dht, uint8_t *client_id, IP_Port *ip_port) | 1337 | int DHT_getfriendip(const DHT *dht, const uint8_t *client_id, IP_Port *ip_port) |
1338 | { | 1338 | { |
1339 | uint32_t i, j; | 1339 | uint32_t i, j; |
1340 | 1340 | ||
@@ -1367,7 +1367,7 @@ int DHT_getfriendip(DHT *dht, uint8_t *client_id, IP_Port *ip_port) | |||
1367 | } | 1367 | } |
1368 | 1368 | ||
1369 | /* returns number of nodes not in kill-timeout */ | 1369 | /* returns number of nodes not in kill-timeout */ |
1370 | static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, uint8_t *client_id, | 1370 | static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, const uint8_t *client_id, |
1371 | Client_data *list, uint32_t list_count, uint32_t *bootstrap_times) | 1371 | Client_data *list, uint32_t list_count, uint32_t *bootstrap_times) |
1372 | { | 1372 | { |
1373 | uint32_t i; | 1373 | uint32_t i; |
@@ -1454,12 +1454,12 @@ static void do_Close(DHT *dht) | |||
1454 | } | 1454 | } |
1455 | } | 1455 | } |
1456 | 1456 | ||
1457 | void DHT_getnodes(DHT *dht, IP_Port *from_ipp, uint8_t *from_id, uint8_t *which_id) | 1457 | void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id) |
1458 | { | 1458 | { |
1459 | getnodes(dht, *from_ipp, from_id, which_id, NULL); | 1459 | getnodes(dht, *from_ipp, from_id, which_id, NULL); |
1460 | } | 1460 | } |
1461 | 1461 | ||
1462 | void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key) | 1462 | void DHT_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key) |
1463 | { | 1463 | { |
1464 | /*#ifdef ENABLE_ASSOC_DHT | 1464 | /*#ifdef ENABLE_ASSOC_DHT |
1465 | if (dht->assoc) { | 1465 | if (dht->assoc) { |
@@ -1474,7 +1474,7 @@ void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key) | |||
1474 | getnodes(dht, ip_port, public_key, dht->self_public_key, NULL); | 1474 | getnodes(dht, ip_port, public_key, dht->self_public_key, NULL); |
1475 | } | 1475 | } |
1476 | int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled, | 1476 | int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled, |
1477 | uint16_t port, uint8_t *public_key) | 1477 | uint16_t port, const uint8_t *public_key) |
1478 | { | 1478 | { |
1479 | IP_Port ip_port_v64; | 1479 | IP_Port ip_port_v64; |
1480 | IP *ip_extra = NULL; | 1480 | IP *ip_extra = NULL; |
@@ -1506,13 +1506,13 @@ int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enable | |||
1506 | * | 1506 | * |
1507 | * return -1 if failure. | 1507 | * return -1 if failure. |
1508 | */ | 1508 | */ |
1509 | int route_packet(DHT *dht, uint8_t *client_id, uint8_t *packet, uint32_t length) | 1509 | int route_packet(const DHT *dht, const uint8_t *client_id, const uint8_t *packet, uint32_t length) |
1510 | { | 1510 | { |
1511 | uint32_t i; | 1511 | uint32_t i; |
1512 | 1512 | ||
1513 | for (i = 0; i < LCLIENT_LIST; ++i) { | 1513 | for (i = 0; i < LCLIENT_LIST; ++i) { |
1514 | if (id_equal(client_id, dht->close_clientlist[i].client_id)) { | 1514 | if (id_equal(client_id, dht->close_clientlist[i].client_id)) { |
1515 | Client_data *client = &dht->close_clientlist[i]; | 1515 | const Client_data *client = &dht->close_clientlist[i]; |
1516 | 1516 | ||
1517 | if (ip_isset(&client->assoc6.ip_port.ip)) | 1517 | if (ip_isset(&client->assoc6.ip_port.ip)) |
1518 | return sendpacket(dht->net, client->assoc6.ip_port, packet, length); | 1518 | return sendpacket(dht->net, client->assoc6.ip_port, packet, length); |
@@ -1533,7 +1533,7 @@ int route_packet(DHT *dht, uint8_t *client_id, uint8_t *packet, uint32_t length) | |||
1533 | * return 0 if we are connected to friend or if no ips were found. | 1533 | * return 0 if we are connected to friend or if no ips were found. |
1534 | * return -1 if no such friend. | 1534 | * return -1 if no such friend. |
1535 | */ | 1535 | */ |
1536 | static int friend_iplist(DHT *dht, IP_Port *ip_portlist, uint16_t friend_num) | 1536 | static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_num) |
1537 | { | 1537 | { |
1538 | if (friend_num >= dht->num_friends) | 1538 | if (friend_num >= dht->num_friends) |
1539 | return -1; | 1539 | return -1; |
@@ -1601,7 +1601,7 @@ static int friend_iplist(DHT *dht, IP_Port *ip_portlist, uint16_t friend_num) | |||
1601 | * return ip for friend. | 1601 | * return ip for friend. |
1602 | * return number of nodes the packet was sent to. (Only works if more than (MAX_FRIEND_CLIENTS / 4). | 1602 | * return number of nodes the packet was sent to. (Only works if more than (MAX_FRIEND_CLIENTS / 4). |
1603 | */ | 1603 | */ |
1604 | int route_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint32_t length) | 1604 | int route_tofriend(const DHT *dht, const uint8_t *friend_id, const uint8_t *packet, uint32_t length) |
1605 | { | 1605 | { |
1606 | int num = friend_number(dht, friend_id); | 1606 | int num = friend_number(dht, friend_id); |
1607 | 1607 | ||
@@ -1656,7 +1656,7 @@ int route_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint32_t lengt | |||
1656 | * | 1656 | * |
1657 | * return number of nodes the packet was sent to. | 1657 | * return number of nodes the packet was sent to. |
1658 | */ | 1658 | */ |
1659 | static int routeone_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint32_t length) | 1659 | static int routeone_tofriend(DHT *dht, const uint8_t *friend_id, const uint8_t *packet, uint32_t length) |
1660 | { | 1660 | { |
1661 | int num = friend_number(dht, friend_id); | 1661 | int num = friend_number(dht, friend_id); |
1662 | 1662 | ||
@@ -1709,7 +1709,7 @@ static int routeone_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint | |||
1709 | * return 0 if we are connected to friend or if no ips were found. | 1709 | * return 0 if we are connected to friend or if no ips were found. |
1710 | * return -1 if no such friend. | 1710 | * return -1 if no such friend. |
1711 | */ | 1711 | */ |
1712 | int friend_ips(DHT *dht, IP_Port *ip_portlist, uint8_t *friend_id) | 1712 | int friend_ips(const DHT *dht, IP_Port *ip_portlist, const uint8_t *friend_id) |
1713 | { | 1713 | { |
1714 | uint32_t i; | 1714 | uint32_t i; |
1715 | 1715 | ||
@@ -1725,7 +1725,7 @@ int friend_ips(DHT *dht, IP_Port *ip_portlist, uint8_t *friend_id) | |||
1725 | /*----------------------------------------------------------------------------------*/ | 1725 | /*----------------------------------------------------------------------------------*/ |
1726 | /*---------------------BEGINNING OF NAT PUNCHING FUNCTIONS--------------------------*/ | 1726 | /*---------------------BEGINNING OF NAT PUNCHING FUNCTIONS--------------------------*/ |
1727 | 1727 | ||
1728 | static int send_NATping(DHT *dht, uint8_t *public_key, uint64_t ping_id, uint8_t type) | 1728 | static int send_NATping(DHT *dht, const uint8_t *public_key, uint64_t ping_id, uint8_t type) |
1729 | { | 1729 | { |
1730 | uint8_t data[sizeof(uint64_t) + 1]; | 1730 | uint8_t data[sizeof(uint64_t) + 1]; |
1731 | uint8_t packet[MAX_CRYPTO_REQUEST_SIZE]; | 1731 | uint8_t packet[MAX_CRYPTO_REQUEST_SIZE]; |
@@ -1753,7 +1753,7 @@ static int send_NATping(DHT *dht, uint8_t *public_key, uint64_t ping_id, uint8_t | |||
1753 | } | 1753 | } |
1754 | 1754 | ||
1755 | /* Handle a received ping request for. */ | 1755 | /* Handle a received ping request for. */ |
1756 | static int handle_NATping(void *object, IP_Port source, uint8_t *source_pubkey, uint8_t *packet, uint32_t length) | 1756 | static int handle_NATping(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, uint32_t length) |
1757 | { | 1757 | { |
1758 | if (length != sizeof(uint64_t) + 1) | 1758 | if (length != sizeof(uint64_t) + 1) |
1759 | return 1; | 1759 | return 1; |
@@ -1962,7 +1962,7 @@ static int send_hardening_getnode_req(DHT *dht, Node_format *dest, Node_format * | |||
1962 | } | 1962 | } |
1963 | 1963 | ||
1964 | /* Send a get node hardening response */ | 1964 | /* Send a get node hardening response */ |
1965 | static int send_hardening_getnode_res(DHT *dht, Node_format *sendto, uint8_t *queried_client_id, uint8_t *nodes_data, | 1965 | static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto, const uint8_t *queried_client_id, const uint8_t *nodes_data, |
1966 | uint16_t nodes_data_length) | 1966 | uint16_t nodes_data_length) |
1967 | { | 1967 | { |
1968 | if (!ip_isset(&sendto->ip_port.ip)) | 1968 | if (!ip_isset(&sendto->ip_port.ip)) |
@@ -1983,7 +1983,7 @@ static int send_hardening_getnode_res(DHT *dht, Node_format *sendto, uint8_t *qu | |||
1983 | } | 1983 | } |
1984 | 1984 | ||
1985 | /* TODO: improve */ | 1985 | /* TODO: improve */ |
1986 | static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, uint8_t *client_id, sa_family_t sa_family) | 1986 | static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *client_id, sa_family_t sa_family) |
1987 | { | 1987 | { |
1988 | uint32_t i; | 1988 | uint32_t i; |
1989 | 1989 | ||
@@ -2032,7 +2032,7 @@ static uint32_t have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num) | |||
2032 | #define HARDEN_TIMEOUT 1200 | 2032 | #define HARDEN_TIMEOUT 1200 |
2033 | 2033 | ||
2034 | /* Handle a received hardening packet */ | 2034 | /* Handle a received hardening packet */ |
2035 | static int handle_hardening(void *object, IP_Port source, uint8_t *source_pubkey, uint8_t *packet, uint32_t length) | 2035 | static int handle_hardening(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, uint32_t length) |
2036 | { | 2036 | { |
2037 | DHT *dht = object; | 2037 | DHT *dht = object; |
2038 | 2038 | ||
@@ -2422,7 +2422,7 @@ void kill_DHT(DHT *dht) | |||
2422 | #define DHT_STATE_TYPE_CLIENTS_ASSOC46 4 | 2422 | #define DHT_STATE_TYPE_CLIENTS_ASSOC46 4 |
2423 | 2423 | ||
2424 | /* Get the size of the DHT (for saving). */ | 2424 | /* Get the size of the DHT (for saving). */ |
2425 | uint32_t DHT_size(DHT *dht) | 2425 | uint32_t DHT_size(const DHT *dht) |
2426 | { | 2426 | { |
2427 | uint32_t num = 0, i; | 2427 | uint32_t num = 0, i; |
2428 | 2428 | ||
@@ -2481,7 +2481,7 @@ void DHT_save(DHT *dht, uint8_t *data) | |||
2481 | } | 2481 | } |
2482 | } | 2482 | } |
2483 | 2483 | ||
2484 | static int dht_load_state_callback(void *outer, uint8_t *data, uint32_t length, uint16_t type) | 2484 | static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type) |
2485 | { | 2485 | { |
2486 | DHT *dht = outer; | 2486 | DHT *dht = outer; |
2487 | uint32_t num, i, j; | 2487 | uint32_t num, i, j; |
@@ -2547,7 +2547,7 @@ static int dht_load_state_callback(void *outer, uint8_t *data, uint32_t length, | |||
2547 | * return -1 if failure. | 2547 | * return -1 if failure. |
2548 | * return 0 if success. | 2548 | * return 0 if success. |
2549 | */ | 2549 | */ |
2550 | int DHT_load(DHT *dht, uint8_t *data, uint32_t length) | 2550 | int DHT_load(DHT *dht, const uint8_t *data, uint32_t length) |
2551 | { | 2551 | { |
2552 | uint32_t cookie_len = sizeof(uint32_t); | 2552 | uint32_t cookie_len = sizeof(uint32_t); |
2553 | 2553 | ||
@@ -2564,13 +2564,13 @@ int DHT_load(DHT *dht, uint8_t *data, uint32_t length) | |||
2564 | /* return 0 if we are not connected to the DHT. | 2564 | /* return 0 if we are not connected to the DHT. |
2565 | * return 1 if we are. | 2565 | * return 1 if we are. |
2566 | */ | 2566 | */ |
2567 | int DHT_isconnected(DHT *dht) | 2567 | int DHT_isconnected(const DHT *dht) |
2568 | { | 2568 | { |
2569 | uint32_t i; | 2569 | uint32_t i; |
2570 | unix_time_update(); | 2570 | unix_time_update(); |
2571 | 2571 | ||
2572 | for (i = 0; i < LCLIENT_LIST; ++i) { | 2572 | for (i = 0; i < LCLIENT_LIST; ++i) { |
2573 | Client_data *client = &dht->close_clientlist[i]; | 2573 | const Client_data *client = &dht->close_clientlist[i]; |
2574 | 2574 | ||
2575 | if (!is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT) || | 2575 | if (!is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT) || |
2576 | !is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT)) | 2576 | !is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT)) |
diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 57813132..97a7109f 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h | |||
@@ -147,7 +147,7 @@ Node_format; | |||
147 | * return length of packed nodes on success. | 147 | * return length of packed nodes on success. |
148 | * return -1 on failure. | 148 | * return -1 on failure. |
149 | */ | 149 | */ |
150 | int pack_nodes(uint8_t *data, uint16_t length, Node_format *nodes, uint16_t number); | 150 | int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_t number); |
151 | 151 | ||
152 | /* Unpack data of length into nodes of size max_num_nodes. | 152 | /* Unpack data of length into nodes of size max_num_nodes. |
153 | * Put the length of the data processed in processed_data_len. | 153 | * Put the length of the data processed in processed_data_len. |
@@ -156,7 +156,7 @@ int pack_nodes(uint8_t *data, uint16_t length, Node_format *nodes, uint16_t numb | |||
156 | * return number of unpacked nodes on success. | 156 | * return number of unpacked nodes on success. |
157 | * return -1 on failure. | 157 | * return -1 on failure. |
158 | */ | 158 | */ |
159 | int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed_data_len, uint8_t *data, | 159 | int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed_data_len, const uint8_t *data, |
160 | uint16_t length, uint8_t tcp_enabled); | 160 | uint16_t length, uint8_t tcp_enabled); |
161 | 161 | ||
162 | 162 | ||
@@ -176,7 +176,7 @@ typedef struct { | |||
176 | 176 | ||
177 | /*----------------------------------------------------------------------------------*/ | 177 | /*----------------------------------------------------------------------------------*/ |
178 | 178 | ||
179 | typedef int (*cryptopacket_handler_callback)(void *object, IP_Port ip_port, uint8_t *source_pubkey, uint8_t *data, | 179 | typedef int (*cryptopacket_handler_callback)(void *object, IP_Port ip_port, const uint8_t *source_pubkey, const uint8_t *data, |
180 | uint32_t len); | 180 | uint32_t len); |
181 | 181 | ||
182 | typedef struct { | 182 | typedef struct { |
@@ -221,19 +221,19 @@ typedef struct { | |||
221 | * If shared key is already in shared_keys, copy it to shared_key. | 221 | * If shared key is already in shared_keys, copy it to shared_key. |
222 | * else generate it into shared_key and copy it to shared_keys | 222 | * else generate it into shared_key and copy it to shared_keys |
223 | */ | 223 | */ |
224 | void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, uint8_t *secret_key, uint8_t *client_id); | 224 | void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t *secret_key, const uint8_t *client_id); |
225 | 225 | ||
226 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key | 226 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key |
227 | * for packets that we receive. | 227 | * for packets that we receive. |
228 | */ | 228 | */ |
229 | void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, uint8_t *client_id); | 229 | void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *client_id); |
230 | 230 | ||
231 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key | 231 | /* Copy shared_key to encrypt/decrypt DHT packet from client_id into shared_key |
232 | * for packets that we send. | 232 | * for packets that we send. |
233 | */ | 233 | */ |
234 | void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, uint8_t *client_id); | 234 | void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *client_id); |
235 | 235 | ||
236 | void DHT_getnodes(DHT *dht, IP_Port *from_ipp, uint8_t *from_id, uint8_t *which_id); | 236 | void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id); |
237 | 237 | ||
238 | /* Add a new friend to the friends list. | 238 | /* Add a new friend to the friends list. |
239 | * client_id must be CLIENT_ID_SIZE bytes long. | 239 | * client_id must be CLIENT_ID_SIZE bytes long. |
@@ -241,7 +241,7 @@ void DHT_getnodes(DHT *dht, IP_Port *from_ipp, uint8_t *from_id, uint8_t *which_ | |||
241 | * return 0 if success. | 241 | * return 0 if success. |
242 | * return 1 if failure (friends list is full). | 242 | * return 1 if failure (friends list is full). |
243 | */ | 243 | */ |
244 | int DHT_addfriend(DHT *dht, uint8_t *client_id); | 244 | int DHT_addfriend(DHT *dht, const uint8_t *client_id); |
245 | 245 | ||
246 | /* Delete a friend from the friends list. | 246 | /* Delete a friend from the friends list. |
247 | * client_id must be CLIENT_ID_SIZE bytes long. | 247 | * client_id must be CLIENT_ID_SIZE bytes long. |
@@ -249,7 +249,7 @@ int DHT_addfriend(DHT *dht, uint8_t *client_id); | |||
249 | * return 0 if success. | 249 | * return 0 if success. |
250 | * return 1 if failure (client_id not in friends list). | 250 | * return 1 if failure (client_id not in friends list). |
251 | */ | 251 | */ |
252 | int DHT_delfriend(DHT *dht, uint8_t *client_id); | 252 | int DHT_delfriend(DHT *dht, const uint8_t *client_id); |
253 | 253 | ||
254 | /* Get ip of friend. | 254 | /* Get ip of friend. |
255 | * client_id must be CLIENT_ID_SIZE bytes long. | 255 | * client_id must be CLIENT_ID_SIZE bytes long. |
@@ -270,7 +270,7 @@ int DHT_delfriend(DHT *dht, uint8_t *client_id); | |||
270 | * return 0, -- if client_id refers to a friend and we failed to find the friend (yet) | 270 | * return 0, -- if client_id refers to a friend and we failed to find the friend (yet) |
271 | * return 1, ip if client_id refers to a friend and we found him | 271 | * return 1, ip if client_id refers to a friend and we found him |
272 | */ | 272 | */ |
273 | int DHT_getfriendip(DHT *dht, uint8_t *client_id, IP_Port *ip_port); | 273 | int DHT_getfriendip(const DHT *dht, const uint8_t *client_id, IP_Port *ip_port); |
274 | 274 | ||
275 | /* Compares client_id1 and client_id2 with client_id. | 275 | /* Compares client_id1 and client_id2 with client_id. |
276 | * | 276 | * |
@@ -278,7 +278,7 @@ int DHT_getfriendip(DHT *dht, uint8_t *client_id, IP_Port *ip_port); | |||
278 | * return 1 if client_id1 is closer. | 278 | * return 1 if client_id1 is closer. |
279 | * return 2 if client_id2 is closer. | 279 | * return 2 if client_id2 is closer. |
280 | */ | 280 | */ |
281 | int id_closest(uint8_t *id, uint8_t *id1, uint8_t *id2); | 281 | int id_closest(const uint8_t *id, const uint8_t *id1, const uint8_t *id2); |
282 | 282 | ||
283 | /* Get the (maximum MAX_SENT_NODES) closest nodes to client_id we know | 283 | /* Get the (maximum MAX_SENT_NODES) closest nodes to client_id we know |
284 | * and put them in nodes_list (must be MAX_SENT_NODES big). | 284 | * and put them in nodes_list (must be MAX_SENT_NODES big). |
@@ -290,7 +290,7 @@ int id_closest(uint8_t *id, uint8_t *id1, uint8_t *id2); | |||
290 | * return the number of nodes returned. | 290 | * return the number of nodes returned. |
291 | * | 291 | * |
292 | */ | 292 | */ |
293 | int get_close_nodes(DHT *dht, uint8_t *client_id, Node_format *nodes_list, sa_family_t sa_family, uint8_t is_LAN, | 293 | int get_close_nodes(const DHT *dht, const uint8_t *client_id, Node_format *nodes_list, sa_family_t sa_family, uint8_t is_LAN, |
294 | uint8_t want_good); | 294 | uint8_t want_good); |
295 | 295 | ||
296 | 296 | ||
@@ -317,7 +317,7 @@ void do_DHT(DHT *dht); | |||
317 | /* Sends a "get nodes" request to the given node with ip, port and public_key | 317 | /* Sends a "get nodes" request to the given node with ip, port and public_key |
318 | * to setup connections | 318 | * to setup connections |
319 | */ | 319 | */ |
320 | void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key); | 320 | void DHT_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key); |
321 | /* Resolves address into an IP address. If successful, sends a "get nodes" | 321 | /* Resolves address into an IP address. If successful, sends a "get nodes" |
322 | * request to the given node with ip, port and public_key to setup connections | 322 | * request to the given node with ip, port and public_key to setup connections |
323 | * | 323 | * |
@@ -330,7 +330,7 @@ void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key); | |||
330 | * returns 0 otherwise | 330 | * returns 0 otherwise |
331 | */ | 331 | */ |
332 | int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled, | 332 | int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled, |
333 | uint16_t port, uint8_t *public_key); | 333 | uint16_t port, const uint8_t *public_key); |
334 | 334 | ||
335 | 335 | ||
336 | /* ROUTING FUNCTIONS */ | 336 | /* ROUTING FUNCTIONS */ |
@@ -339,13 +339,13 @@ int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enable | |||
339 | * | 339 | * |
340 | * return -1 if failure. | 340 | * return -1 if failure. |
341 | */ | 341 | */ |
342 | int route_packet(DHT *dht, uint8_t *client_id, uint8_t *packet, uint32_t length); | 342 | int route_packet(const DHT *dht, const uint8_t *client_id, const uint8_t *packet, uint32_t length); |
343 | 343 | ||
344 | /* Send the following packet to everyone who tells us they are connected to friend_id. | 344 | /* Send the following packet to everyone who tells us they are connected to friend_id. |
345 | * | 345 | * |
346 | * return number of nodes it sent the packet to. | 346 | * return number of nodes it sent the packet to. |
347 | */ | 347 | */ |
348 | int route_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint32_t length); | 348 | int route_tofriend(const DHT *dht, const uint8_t *friend_id, const uint8_t *packet, uint32_t length); |
349 | 349 | ||
350 | /* Function to handle crypto packets. | 350 | /* Function to handle crypto packets. |
351 | */ | 351 | */ |
@@ -359,12 +359,12 @@ void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_c | |||
359 | * returns number of ips returned. | 359 | * returns number of ips returned. |
360 | * returns -1 if no such friend. | 360 | * returns -1 if no such friend. |
361 | */ | 361 | */ |
362 | int friend_ips(DHT *dht, IP_Port *ip_portlist, uint8_t *friend_id); | 362 | int friend_ips(const DHT *dht, IP_Port *ip_portlist, const uint8_t *friend_id); |
363 | 363 | ||
364 | /* SAVE/LOAD functions */ | 364 | /* SAVE/LOAD functions */ |
365 | 365 | ||
366 | /* Get the size of the DHT (for saving). */ | 366 | /* Get the size of the DHT (for saving). */ |
367 | uint32_t DHT_size(DHT *dht); | 367 | uint32_t DHT_size(const DHT *dht); |
368 | 368 | ||
369 | /* Save the DHT in data where data is an array of size DHT_size(). */ | 369 | /* Save the DHT in data where data is an array of size DHT_size(). */ |
370 | void DHT_save(DHT *dht, uint8_t *data); | 370 | void DHT_save(DHT *dht, uint8_t *data); |
@@ -374,7 +374,7 @@ void DHT_save(DHT *dht, uint8_t *data); | |||
374 | * return -1 if failure. | 374 | * return -1 if failure. |
375 | * return 0 if success. | 375 | * return 0 if success. |
376 | */ | 376 | */ |
377 | int DHT_load(DHT *dht, uint8_t *data, uint32_t length); | 377 | int DHT_load(DHT *dht, const uint8_t *data, uint32_t length); |
378 | 378 | ||
379 | /* Initialize DHT. */ | 379 | /* Initialize DHT. */ |
380 | DHT *new_DHT(Networking_Core *net); | 380 | DHT *new_DHT(Networking_Core *net); |
@@ -384,9 +384,9 @@ void kill_DHT(DHT *dht); | |||
384 | /* return 0 if we are not connected to the DHT. | 384 | /* return 0 if we are not connected to the DHT. |
385 | * return 1 if we are. | 385 | * return 1 if we are. |
386 | */ | 386 | */ |
387 | int DHT_isconnected(DHT *dht); | 387 | int DHT_isconnected(const DHT *dht); |
388 | 388 | ||
389 | int addto_lists(DHT *dht, IP_Port ip_port, uint8_t *client_id); | 389 | int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *client_id); |
390 | 390 | ||
391 | #endif | 391 | #endif |
392 | 392 | ||
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 037b0e66..931468ec 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -86,7 +86,7 @@ int realloc_friendlist(Messenger *m, uint32_t num) | |||
86 | /* return the friend id associated to that public key. | 86 | /* return the friend id associated to that public key. |
87 | * return -1 if no such friend. | 87 | * return -1 if no such friend. |
88 | */ | 88 | */ |
89 | int32_t getfriend_id(Messenger *m, uint8_t *client_id) | 89 | int32_t getfriend_id(const Messenger *m, const uint8_t *client_id) |
90 | { | 90 | { |
91 | uint32_t i; | 91 | uint32_t i; |
92 | 92 | ||
@@ -256,7 +256,7 @@ int32_t m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t leng | |||
256 | return FAERR_UNKNOWN; | 256 | return FAERR_UNKNOWN; |
257 | } | 257 | } |
258 | 258 | ||
259 | int32_t m_addfriend_norequest(Messenger *m, uint8_t *client_id) | 259 | int32_t m_addfriend_norequest(Messenger *m, const uint8_t *client_id) |
260 | { | 260 | { |
261 | if (getfriend_id(m, client_id) != -1) | 261 | if (getfriend_id(m, client_id) != -1) |
262 | return -1; | 262 | return -1; |
@@ -356,7 +356,7 @@ int m_friend_exists(Messenger *m, int32_t friendnumber) | |||
356 | * return the message id if packet was successfully put into the send queue. | 356 | * return the message id if packet was successfully put into the send queue. |
357 | * return 0 if it was not. | 357 | * return 0 if it was not. |
358 | */ | 358 | */ |
359 | uint32_t m_sendmessage(Messenger *m, int32_t friendnumber, uint8_t *message, uint32_t length) | 359 | uint32_t m_sendmessage(Messenger *m, int32_t friendnumber, const uint8_t *message, uint32_t length) |
360 | { | 360 | { |
361 | if (friend_not_valid(m, friendnumber)) | 361 | if (friend_not_valid(m, friendnumber)) |
362 | return 0; | 362 | return 0; |
@@ -373,7 +373,7 @@ uint32_t m_sendmessage(Messenger *m, int32_t friendnumber, uint8_t *message, uin | |||
373 | return 0; | 373 | return 0; |
374 | } | 374 | } |
375 | 375 | ||
376 | uint32_t m_sendmessage_withid(Messenger *m, int32_t friendnumber, uint32_t theid, uint8_t *message, uint32_t length) | 376 | uint32_t m_sendmessage_withid(Messenger *m, int32_t friendnumber, uint32_t theid, const uint8_t *message, uint32_t length) |
377 | { | 377 | { |
378 | if (length >= (MAX_CRYPTO_DATA_SIZE - sizeof(theid))) | 378 | if (length >= (MAX_CRYPTO_DATA_SIZE - sizeof(theid))) |
379 | return 0; | 379 | return 0; |
@@ -456,7 +456,7 @@ int setfriendname(Messenger *m, int32_t friendnumber, uint8_t *name, uint16_t le | |||
456 | * return 0 if success. | 456 | * return 0 if success. |
457 | * return -1 if failure. | 457 | * return -1 if failure. |
458 | */ | 458 | */ |
459 | int setname(Messenger *m, uint8_t *name, uint16_t length) | 459 | int setname(Messenger *m, const uint8_t *name, uint16_t length) |
460 | { | 460 | { |
461 | if (length > MAX_NAME_LENGTH || length == 0) | 461 | if (length > MAX_NAME_LENGTH || length == 0) |
462 | return -1; | 462 | return -1; |
@@ -519,7 +519,7 @@ int m_get_self_name_size(Messenger *m) | |||
519 | return m->name_length; | 519 | return m->name_length; |
520 | } | 520 | } |
521 | 521 | ||
522 | int m_set_statusmessage(Messenger *m, uint8_t *status, uint16_t length) | 522 | int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length) |
523 | { | 523 | { |
524 | if (length > MAX_STATUSMESSAGE_LENGTH) | 524 | if (length > MAX_STATUSMESSAGE_LENGTH) |
525 | return -1; | 525 | return -1; |
@@ -722,10 +722,10 @@ void m_set_sends_receipts(Messenger *m, int32_t friendnumber, int yesno) | |||
722 | 722 | ||
723 | /* static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); */ | 723 | /* static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); */ |
724 | /* Set the function that will be executed when a friend request is received. */ | 724 | /* Set the function that will be executed when a friend request is received. */ |
725 | void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, uint8_t *, uint8_t *, uint16_t, void *), | 725 | void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, const uint8_t *, const uint8_t *, uint16_t, void *), |
726 | void *userdata) | 726 | void *userdata) |
727 | { | 727 | { |
728 | void (*handle_friendrequest)(void *, uint8_t *, uint8_t *, uint16_t, void *) = (void *)function; | 728 | void (*handle_friendrequest)(void *, const uint8_t *, const uint8_t *, uint16_t, void *) = (void *)function; |
729 | callback_friendrequest(&(m->fr), handle_friendrequest, m, userdata); | 729 | callback_friendrequest(&(m->fr), handle_friendrequest, m, userdata); |
730 | } | 730 | } |
731 | 731 | ||
@@ -1701,7 +1701,7 @@ int send_custom_lossy_packet(Messenger *m, int32_t friendnumber, uint8_t *data, | |||
1701 | 1701 | ||
1702 | 1702 | ||
1703 | /* Function to filter out some friend requests*/ | 1703 | /* Function to filter out some friend requests*/ |
1704 | static int friend_already_added(uint8_t *client_id, void *data) | 1704 | static int friend_already_added(const uint8_t *client_id, void *data) |
1705 | { | 1705 | { |
1706 | Messenger *m = data; | 1706 | Messenger *m = data; |
1707 | 1707 | ||
@@ -2503,7 +2503,7 @@ static uint32_t friends_list_save(Messenger *m, uint8_t *data) | |||
2503 | return num * sizeof(struct SAVED_FRIEND); | 2503 | return num * sizeof(struct SAVED_FRIEND); |
2504 | } | 2504 | } |
2505 | 2505 | ||
2506 | static int friends_list_load(Messenger *m, uint8_t *data, uint32_t length) | 2506 | static int friends_list_load(Messenger *m, const uint8_t *data, uint32_t length) |
2507 | { | 2507 | { |
2508 | if (length % sizeof(struct SAVED_FRIEND) != 0) { | 2508 | if (length % sizeof(struct SAVED_FRIEND) != 0) { |
2509 | return -1; | 2509 | return -1; |
@@ -2626,7 +2626,7 @@ void messenger_save(Messenger *m, uint8_t *data) | |||
2626 | data += len; | 2626 | data += len; |
2627 | } | 2627 | } |
2628 | 2628 | ||
2629 | static int messenger_load_state_callback(void *outer, uint8_t *data, uint32_t length, uint16_t type) | 2629 | static int messenger_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type) |
2630 | { | 2630 | { |
2631 | Messenger *m = outer; | 2631 | Messenger *m = outer; |
2632 | 2632 | ||
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 51d5c73b..ad51a754 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -274,12 +274,12 @@ int32_t m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t leng | |||
274 | * return the friend number if success. | 274 | * return the friend number if success. |
275 | * return -1 if failure. | 275 | * return -1 if failure. |
276 | */ | 276 | */ |
277 | int32_t m_addfriend_norequest(Messenger *m, uint8_t *client_id); | 277 | int32_t m_addfriend_norequest(Messenger *m, const uint8_t *client_id); |
278 | 278 | ||
279 | /* return the friend number associated to that client id. | 279 | /* return the friend number associated to that client id. |
280 | * return -1 if no such friend. | 280 | * return -1 if no such friend. |
281 | */ | 281 | */ |
282 | int32_t getfriend_id(Messenger *m, uint8_t *client_id); | 282 | int32_t getfriend_id(const Messenger *m, const uint8_t *client_id); |
283 | 283 | ||
284 | /* Copies the public key associated to that friend id into client_id buffer. | 284 | /* Copies the public key associated to that friend id into client_id buffer. |
285 | * Make sure that client_id is of size CLIENT_ID_SIZE. | 285 | * Make sure that client_id is of size CLIENT_ID_SIZE. |
@@ -321,8 +321,8 @@ int m_friend_exists(Messenger *m, int32_t friendnumber); | |||
321 | * m_sendmessage_withid will send a message with the id of your choosing, | 321 | * m_sendmessage_withid will send a message with the id of your choosing, |
322 | * however we can generate an id for you by calling plain m_sendmessage. | 322 | * however we can generate an id for you by calling plain m_sendmessage. |
323 | */ | 323 | */ |
324 | uint32_t m_sendmessage(Messenger *m, int32_t friendnumber, uint8_t *message, uint32_t length); | 324 | uint32_t m_sendmessage(Messenger *m, int32_t friendnumber, const uint8_t *message, uint32_t length); |
325 | uint32_t m_sendmessage_withid(Messenger *m, int32_t friendnumber, uint32_t theid, uint8_t *message, uint32_t length); | 325 | uint32_t m_sendmessage_withid(Messenger *m, int32_t friendnumber, uint32_t theid, const uint8_t *message, uint32_t length); |
326 | 326 | ||
327 | /* Send an action to an online friend. | 327 | /* Send an action to an online friend. |
328 | * | 328 | * |
@@ -355,7 +355,7 @@ int setfriendname(Messenger *m, int32_t friendnumber, uint8_t *name, uint16_t le | |||
355 | * return 0 if success. | 355 | * return 0 if success. |
356 | * return -1 if failure. | 356 | * return -1 if failure. |
357 | */ | 357 | */ |
358 | int setname(Messenger *m, uint8_t *name, uint16_t length); | 358 | int setname(Messenger *m, const uint8_t *name, uint16_t length); |
359 | 359 | ||
360 | /* | 360 | /* |
361 | * Get your nickname. | 361 | * Get your nickname. |
@@ -387,7 +387,7 @@ int m_get_self_name_size(Messenger *m); | |||
387 | * returns 0 on success. | 387 | * returns 0 on success. |
388 | * returns -1 on failure. | 388 | * returns -1 on failure. |
389 | */ | 389 | */ |
390 | int m_set_statusmessage(Messenger *m, uint8_t *status, uint16_t length); | 390 | int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length); |
391 | int m_set_userstatus(Messenger *m, uint8_t status); | 391 | int m_set_userstatus(Messenger *m, uint8_t status); |
392 | 392 | ||
393 | /* return the length of friendnumber's status message, including null on success. | 393 | /* return the length of friendnumber's status message, including null on success. |
@@ -442,7 +442,7 @@ void m_set_sends_receipts(Messenger *m, int32_t friendnumber, int yesno); | |||
442 | /* Set the function that will be executed when a friend request is received. | 442 | /* Set the function that will be executed when a friend request is received. |
443 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) | 443 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) |
444 | */ | 444 | */ |
445 | void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, uint8_t *, uint8_t *, uint16_t, void *), | 445 | void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, const uint8_t *, const uint8_t *, uint16_t, void *), |
446 | void *userdata); | 446 | void *userdata); |
447 | 447 | ||
448 | /* Set the function that will be executed when a message from a friend is received. | 448 | /* Set the function that will be executed when a message from a friend is received. |
diff --git a/toxcore/friend_requests.c b/toxcore/friend_requests.c index eb2a791c..4bf95a44 100644 --- a/toxcore/friend_requests.c +++ b/toxcore/friend_requests.c | |||
@@ -72,7 +72,7 @@ uint32_t get_nospam(Friend_Requests *fr) | |||
72 | 72 | ||
73 | 73 | ||
74 | /* Set the function that will be executed when a friend request is received. */ | 74 | /* Set the function that will be executed when a friend request is received. */ |
75 | void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, uint8_t *, uint8_t *, uint16_t, void *), | 75 | void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, const uint8_t *, const uint8_t *, uint16_t, void *), |
76 | void *object, void *userdata) | 76 | void *object, void *userdata) |
77 | { | 77 | { |
78 | fr->handle_friendrequest = function; | 78 | fr->handle_friendrequest = function; |
@@ -81,14 +81,14 @@ void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, uint8_ | |||
81 | fr->handle_friendrequest_userdata = userdata; | 81 | fr->handle_friendrequest_userdata = userdata; |
82 | } | 82 | } |
83 | /* Set the function used to check if a friend request should be displayed to the user or not. */ | 83 | /* Set the function used to check if a friend request should be displayed to the user or not. */ |
84 | void set_filter_function(Friend_Requests *fr, int (*function)(uint8_t *, void *), void *userdata) | 84 | void set_filter_function(Friend_Requests *fr, int (*function)(const uint8_t *, void *), void *userdata) |
85 | { | 85 | { |
86 | fr->filter_function = function; | 86 | fr->filter_function = function; |
87 | fr->filter_function_userdata = userdata; | 87 | fr->filter_function_userdata = userdata; |
88 | } | 88 | } |
89 | 89 | ||
90 | /* Add to list of received friend requests. */ | 90 | /* Add to list of received friend requests. */ |
91 | static void addto_receivedlist(Friend_Requests *fr, uint8_t *client_id) | 91 | static void addto_receivedlist(Friend_Requests *fr, const uint8_t *client_id) |
92 | { | 92 | { |
93 | if (fr->received_requests_index >= MAX_RECEIVED_STORED) | 93 | if (fr->received_requests_index >= MAX_RECEIVED_STORED) |
94 | fr->received_requests_index = 0; | 94 | fr->received_requests_index = 0; |
@@ -102,7 +102,7 @@ static void addto_receivedlist(Friend_Requests *fr, uint8_t *client_id) | |||
102 | * return 0 if it did not. | 102 | * return 0 if it did not. |
103 | * return 1 if it did. | 103 | * return 1 if it did. |
104 | */ | 104 | */ |
105 | static int request_received(Friend_Requests *fr, uint8_t *client_id) | 105 | static int request_received(Friend_Requests *fr, const uint8_t *client_id) |
106 | { | 106 | { |
107 | uint32_t i; | 107 | uint32_t i; |
108 | 108 | ||
@@ -133,7 +133,7 @@ int remove_request_received(Friend_Requests *fr, uint8_t *client_id) | |||
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | static int friendreq_handlepacket(void *object, uint8_t *source_pubkey, uint8_t *packet, uint32_t length) | 136 | static int friendreq_handlepacket(void *object, const uint8_t *source_pubkey, const uint8_t *packet, uint32_t length) |
137 | { | 137 | { |
138 | Friend_Requests *fr = object; | 138 | Friend_Requests *fr = object; |
139 | 139 | ||
diff --git a/toxcore/friend_requests.h b/toxcore/friend_requests.h index 429ffbad..58ff91ce 100644 --- a/toxcore/friend_requests.h +++ b/toxcore/friend_requests.h | |||
@@ -30,12 +30,12 @@ | |||
30 | 30 | ||
31 | typedef struct { | 31 | typedef struct { |
32 | uint32_t nospam; | 32 | uint32_t nospam; |
33 | void (*handle_friendrequest)(void *, uint8_t *, uint8_t *, uint16_t, void *); | 33 | void (*handle_friendrequest)(void *, const uint8_t *, const uint8_t *, uint16_t, void *); |
34 | uint8_t handle_friendrequest_isset; | 34 | uint8_t handle_friendrequest_isset; |
35 | void *handle_friendrequest_object; | 35 | void *handle_friendrequest_object; |
36 | void *handle_friendrequest_userdata; | 36 | void *handle_friendrequest_userdata; |
37 | 37 | ||
38 | int (*filter_function)(uint8_t *, void *); | 38 | int (*filter_function)(const uint8_t *, void *); |
39 | void *filter_function_userdata; | 39 | void *filter_function_userdata; |
40 | /* NOTE: The following is just a temporary fix for the multiple friend requests received at the same time problem. | 40 | /* NOTE: The following is just a temporary fix for the multiple friend requests received at the same time problem. |
41 | * TODO: Make this better (This will most likely tie in with the way we will handle spam.) | 41 | * TODO: Make this better (This will most likely tie in with the way we will handle spam.) |
@@ -66,14 +66,14 @@ int remove_request_received(Friend_Requests *fr, uint8_t *client_id); | |||
66 | /* Set the function that will be executed when a friend request for us is received. | 66 | /* Set the function that will be executed when a friend request for us is received. |
67 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length, void * userdata) | 67 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length, void * userdata) |
68 | */ | 68 | */ |
69 | void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, uint8_t *, uint8_t *, uint16_t, void *), | 69 | void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, const uint8_t *, const uint8_t *, uint16_t, void *), |
70 | void *object, void *userdata); | 70 | void *object, void *userdata); |
71 | 71 | ||
72 | /* Set the function used to check if a friend request should be displayed to the user or not. | 72 | /* Set the function used to check if a friend request should be displayed to the user or not. |
73 | * Function format is int function(uint8_t * public_key, void * userdata) | 73 | * Function format is int function(uint8_t * public_key, void * userdata) |
74 | * It must return 0 if the request is ok (anything else if it is bad.) | 74 | * It must return 0 if the request is ok (anything else if it is bad.) |
75 | */ | 75 | */ |
76 | void set_filter_function(Friend_Requests *fr, int (*function)(uint8_t *, void *), void *userdata); | 76 | void set_filter_function(Friend_Requests *fr, int (*function)(const uint8_t *, void *), void *userdata); |
77 | 77 | ||
78 | /* Sets up friendreq packet handlers. */ | 78 | /* Sets up friendreq packet handlers. */ |
79 | void friendreq_init(Friend_Requests *fr, Onion_Client *onion_c); | 79 | void friendreq_init(Friend_Requests *fr, Onion_Client *onion_c); |
diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index fbe76d16..85928436 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c | |||
@@ -675,7 +675,7 @@ static uint32_t group_send_nick(Group_Chat *chat, uint8_t *nick, uint16_t nick_l | |||
675 | return send_data(chat, nick, nick_len, GROUP_CHAT_PEER_NICK); | 675 | return send_data(chat, nick, nick_len, GROUP_CHAT_PEER_NICK); |
676 | } | 676 | } |
677 | 677 | ||
678 | int set_nick(Group_Chat *chat, uint8_t *nick, uint16_t nick_len) | 678 | int set_nick(Group_Chat *chat, const uint8_t *nick, uint16_t nick_len) |
679 | { | 679 | { |
680 | if (nick_len > MAX_NICK_BYTES || nick_len == 0) | 680 | if (nick_len > MAX_NICK_BYTES || nick_len == 0) |
681 | return -1; | 681 | return -1; |
diff --git a/toxcore/group_chats.h b/toxcore/group_chats.h index d9da54a5..49b83c81 100644 --- a/toxcore/group_chats.h +++ b/toxcore/group_chats.h | |||
@@ -144,7 +144,7 @@ uint32_t group_sendaction(Group_Chat *chat, uint8_t *action, uint32_t length); | |||
144 | * | 144 | * |
145 | * returns -1 on failure, 0 on success. | 145 | * returns -1 on failure, 0 on success. |
146 | */ | 146 | */ |
147 | int set_nick(Group_Chat *chat, uint8_t *nick, uint16_t nick_len); | 147 | int set_nick(Group_Chat *chat, const uint8_t *nick, uint16_t nick_len); |
148 | 148 | ||
149 | /* | 149 | /* |
150 | * Tell everyone about a new peer (a person we are inviting for example.) | 150 | * Tell everyone about a new peer (a person we are inviting for example.) |
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 47b23d54..bb38af26 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -2466,7 +2466,7 @@ void save_keys(Net_Crypto *c, uint8_t *keys) | |||
2466 | /* Load the public and private keys from the keys array. | 2466 | /* Load the public and private keys from the keys array. |
2467 | * Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES. | 2467 | * Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES. |
2468 | */ | 2468 | */ |
2469 | void load_keys(Net_Crypto *c, uint8_t *keys) | 2469 | void load_keys(Net_Crypto *c, const uint8_t *keys) |
2470 | { | 2470 | { |
2471 | memcpy(c->self_public_key, keys, crypto_box_PUBLICKEYBYTES); | 2471 | memcpy(c->self_public_key, keys, crypto_box_PUBLICKEYBYTES); |
2472 | memcpy(c->self_secret_key, keys + crypto_box_PUBLICKEYBYTES, crypto_box_SECRETKEYBYTES); | 2472 | memcpy(c->self_secret_key, keys + crypto_box_PUBLICKEYBYTES, crypto_box_SECRETKEYBYTES); |
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index a3c7e7db..b1108ae1 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -347,7 +347,7 @@ void save_keys(Net_Crypto *c, uint8_t *keys); | |||
347 | /* Load the public and private keys from the keys array. | 347 | /* Load the public and private keys from 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 | */ |
350 | void load_keys(Net_Crypto *c, uint8_t *keys); | 350 | void load_keys(Net_Crypto *c, const uint8_t *keys); |
351 | 351 | ||
352 | /* Create new instance of Net_Crypto. | 352 | /* Create new instance of Net_Crypto. |
353 | * Sets all the global connection variables to their default values. | 353 | * Sets all the global connection variables to their default values. |
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index dfdb1638..8e28eae5 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -467,7 +467,7 @@ static int handle_data_response(void *object, IP_Port source, uint8_t *packet, u | |||
467 | #define FAKEID_DATA_ID 156 | 467 | #define FAKEID_DATA_ID 156 |
468 | #define FAKEID_DATA_MIN_LENGTH (1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES) | 468 | #define FAKEID_DATA_MIN_LENGTH (1 + sizeof(uint64_t) + crypto_box_PUBLICKEYBYTES) |
469 | #define FAKEID_DATA_MAX_LENGTH (FAKEID_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES) | 469 | #define FAKEID_DATA_MAX_LENGTH (FAKEID_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES) |
470 | static int handle_fakeid_announce(void *object, uint8_t *source_pubkey, uint8_t *data, uint32_t length) | 470 | static int handle_fakeid_announce(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint32_t length) |
471 | { | 471 | { |
472 | Onion_Client *onion_c = object; | 472 | Onion_Client *onion_c = object; |
473 | 473 | ||
@@ -483,8 +483,8 @@ static int handle_fakeid_announce(void *object, uint8_t *source_pubkey, uint8_t | |||
483 | return 1; | 483 | return 1; |
484 | 484 | ||
485 | uint64_t no_replay; | 485 | uint64_t no_replay; |
486 | net_to_host(data + 1, sizeof(no_replay)); | ||
487 | memcpy(&no_replay, data + 1, sizeof(uint64_t)); | 486 | memcpy(&no_replay, data + 1, sizeof(uint64_t)); |
487 | net_to_host((uint8_t *) &no_replay, sizeof(no_replay)); | ||
488 | 488 | ||
489 | if (no_replay <= onion_c->friends_list[friend_num].last_noreplay) | 489 | if (no_replay <= onion_c->friends_list[friend_num].last_noreplay) |
490 | return 1; | 490 | return 1; |
@@ -623,7 +623,7 @@ static int send_dht_fakeid(Onion_Client *onion_c, int friend_num, uint8_t *data, | |||
623 | return route_tofriend(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id, packet, len); | 623 | return route_tofriend(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id, packet, len); |
624 | } | 624 | } |
625 | 625 | ||
626 | static int handle_dht_fakeid(void *object, IP_Port source, uint8_t *source_pubkey, uint8_t *packet, uint32_t length) | 626 | static int handle_dht_fakeid(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, uint32_t length) |
627 | { | 627 | { |
628 | Onion_Client *onion_c = object; | 628 | Onion_Client *onion_c = object; |
629 | 629 | ||
@@ -702,7 +702,7 @@ static int send_fakeid_announce(Onion_Client *onion_c, uint16_t friend_num, uint | |||
702 | * return -1 on failure. | 702 | * return -1 on failure. |
703 | * return friend number on success. | 703 | * return friend number on success. |
704 | */ | 704 | */ |
705 | int onion_friend_num(Onion_Client *onion_c, uint8_t *client_id) | 705 | int onion_friend_num(const Onion_Client *onion_c, const uint8_t *client_id) |
706 | { | 706 | { |
707 | uint32_t i; | 707 | uint32_t i; |
708 | 708 | ||
@@ -744,7 +744,7 @@ static int realloc_onion_friends(Onion_Client *onion_c, uint32_t num) | |||
744 | * return -1 on failure. | 744 | * return -1 on failure. |
745 | * return the friend number on success or if the friend was already added. | 745 | * return the friend number on success or if the friend was already added. |
746 | */ | 746 | */ |
747 | int onion_addfriend(Onion_Client *onion_c, uint8_t *client_id) | 747 | int onion_addfriend(Onion_Client *onion_c, const uint8_t *client_id) |
748 | { | 748 | { |
749 | int num = onion_friend_num(onion_c, client_id); | 749 | int num = onion_friend_num(onion_c, client_id); |
750 | 750 | ||
@@ -831,7 +831,7 @@ int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_rela | |||
831 | * return -1 on failure. | 831 | * return -1 on failure. |
832 | * return 0 on success. | 832 | * return 0 on success. |
833 | */ | 833 | */ |
834 | int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, uint8_t *dht_key, uint64_t timestamp) | 834 | int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key, uint64_t timestamp) |
835 | { | 835 | { |
836 | if ((uint32_t)friend_num >= onion_c->num_friends) | 836 | if ((uint32_t)friend_num >= onion_c->num_friends) |
837 | return -1; | 837 | return -1; |
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index 9cf6cf3e..7995fa3a 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h | |||
@@ -102,7 +102,7 @@ typedef struct { | |||
102 | uint32_t tcp_relay_node_callback_number; | 102 | uint32_t tcp_relay_node_callback_number; |
103 | } Onion_Friend; | 103 | } Onion_Friend; |
104 | 104 | ||
105 | typedef int (*oniondata_handler_callback)(void *object, uint8_t *source_pubkey, uint8_t *data, uint32_t len); | 105 | typedef int (*oniondata_handler_callback)(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint32_t len); |
106 | 106 | ||
107 | typedef struct { | 107 | typedef struct { |
108 | DHT *dht; | 108 | DHT *dht; |
@@ -136,14 +136,14 @@ typedef struct { | |||
136 | * return -1 on failure. | 136 | * return -1 on failure. |
137 | * return the friend number on success or if the friend was already added. | 137 | * return the friend number on success or if the friend was already added. |
138 | */ | 138 | */ |
139 | int onion_friend_num(Onion_Client *onion_c, uint8_t *client_id); | 139 | int onion_friend_num(const Onion_Client *onion_c, const uint8_t *client_id); |
140 | 140 | ||
141 | /* Add a friend who we want to connect to. | 141 | /* Add a friend who we want to connect to. |
142 | * | 142 | * |
143 | * return -1 on failure. | 143 | * return -1 on failure. |
144 | * return the friend number on success. | 144 | * return the friend number on success. |
145 | */ | 145 | */ |
146 | int onion_addfriend(Onion_Client *onion_c, uint8_t *client_id); | 146 | int onion_addfriend(Onion_Client *onion_c, const uint8_t *client_id); |
147 | 147 | ||
148 | /* Delete a friend. | 148 | /* Delete a friend. |
149 | * | 149 | * |
@@ -190,7 +190,7 @@ int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_rela | |||
190 | * return -1 on failure. | 190 | * return -1 on failure. |
191 | * return 0 on success. | 191 | * return 0 on success. |
192 | */ | 192 | */ |
193 | int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, uint8_t *dht_key, uint64_t timestamp); | 193 | int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uint8_t *dht_key, uint64_t timestamp); |
194 | 194 | ||
195 | /* Copy friends DHT public key into dht_key. | 195 | /* Copy friends DHT public key into dht_key. |
196 | * | 196 | * |
diff --git a/toxcore/ping.c b/toxcore/ping.c index c01170ab..ea8fd04d 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c | |||
@@ -58,7 +58,7 @@ struct PING { | |||
58 | #define DHT_PING_SIZE (1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + PING_PLAIN_SIZE + crypto_box_MACBYTES) | 58 | #define DHT_PING_SIZE (1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + PING_PLAIN_SIZE + crypto_box_MACBYTES) |
59 | #define PING_DATA_SIZE (CLIENT_ID_SIZE + sizeof(IP_Port)) | 59 | #define PING_DATA_SIZE (CLIENT_ID_SIZE + sizeof(IP_Port)) |
60 | 60 | ||
61 | int send_ping_request(PING *ping, IP_Port ipp, uint8_t *client_id) | 61 | int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *client_id) |
62 | { | 62 | { |
63 | uint8_t pk[DHT_PING_SIZE]; | 63 | uint8_t pk[DHT_PING_SIZE]; |
64 | int rc; | 64 | int rc; |
@@ -100,7 +100,7 @@ int send_ping_request(PING *ping, IP_Port ipp, uint8_t *client_id) | |||
100 | return sendpacket(ping->dht->net, ipp, pk, sizeof(pk)); | 100 | return sendpacket(ping->dht->net, ipp, pk, sizeof(pk)); |
101 | } | 101 | } |
102 | 102 | ||
103 | static int send_ping_response(PING *ping, IP_Port ipp, uint8_t *client_id, uint64_t ping_id, | 103 | static int send_ping_response(PING *ping, IP_Port ipp, const uint8_t *client_id, uint64_t ping_id, |
104 | uint8_t *shared_encryption_key) | 104 | uint8_t *shared_encryption_key) |
105 | { | 105 | { |
106 | uint8_t pk[DHT_PING_SIZE]; | 106 | uint8_t pk[DHT_PING_SIZE]; |
@@ -225,13 +225,13 @@ static int handle_ping_response(void *_dht, IP_Port source, uint8_t *packet, uin | |||
225 | * return 1 if it is. | 225 | * return 1 if it is. |
226 | * return 0 if it isn't. | 226 | * return 0 if it isn't. |
227 | */ | 227 | */ |
228 | static int in_list(Client_data *list, uint32_t length, uint8_t *client_id, IP_Port ip_port) | 228 | static int in_list(const Client_data *list, uint32_t length, const uint8_t *client_id, IP_Port ip_port) |
229 | { | 229 | { |
230 | uint32_t i; | 230 | uint32_t i; |
231 | 231 | ||
232 | for (i = 0; i < length; ++i) { | 232 | for (i = 0; i < length; ++i) { |
233 | if (id_equal(list[i].client_id, client_id)) { | 233 | if (id_equal(list[i].client_id, client_id)) { |
234 | IPPTsPng *ipptp; | 234 | const IPPTsPng *ipptp; |
235 | 235 | ||
236 | if (ip_port.ip.family == AF_INET) { | 236 | if (ip_port.ip.family == AF_INET) { |
237 | ipptp = &list[i].assoc4; | 237 | ipptp = &list[i].assoc4; |
@@ -257,7 +257,7 @@ static int in_list(Client_data *list, uint32_t length, uint8_t *client_id, IP_Po | |||
257 | * return 0 if node was added. | 257 | * return 0 if node was added. |
258 | * return -1 if node was not added. | 258 | * return -1 if node was not added. |
259 | */ | 259 | */ |
260 | int add_to_ping(PING *ping, uint8_t *client_id, IP_Port ip_port) | 260 | int add_to_ping(PING *ping, const uint8_t *client_id, IP_Port ip_port) |
261 | { | 261 | { |
262 | if (!ip_isset(&ip_port.ip)) | 262 | if (!ip_isset(&ip_port.ip)) |
263 | return -1; | 263 | return -1; |
diff --git a/toxcore/ping.h b/toxcore/ping.h index 168870d7..c19c912a 100644 --- a/toxcore/ping.h +++ b/toxcore/ping.h | |||
@@ -36,12 +36,12 @@ typedef struct PING PING; | |||
36 | * return 0 if node was added. | 36 | * return 0 if node was added. |
37 | * return -1 if node was not added. | 37 | * return -1 if node was not added. |
38 | */ | 38 | */ |
39 | int add_to_ping(PING *ping, uint8_t *client_id, IP_Port ip_port); | 39 | int add_to_ping(PING *ping, const uint8_t *client_id, IP_Port ip_port); |
40 | void do_to_ping(PING *ping); | 40 | void do_to_ping(PING *ping); |
41 | 41 | ||
42 | PING *new_ping(DHT *dht); | 42 | PING *new_ping(DHT *dht); |
43 | void kill_ping(PING *ping); | 43 | void kill_ping(PING *ping); |
44 | 44 | ||
45 | int send_ping_request(PING *ping, IP_Port ipp, uint8_t *client_id); | 45 | int send_ping_request(PING *ping, IP_Port ipp, const uint8_t *client_id); |
46 | 46 | ||
47 | #endif /* __PING_H__ */ | 47 | #endif /* __PING_H__ */ |
diff --git a/toxcore/ping_array.c b/toxcore/ping_array.c index e6f684ef..5c92527e 100644 --- a/toxcore/ping_array.c +++ b/toxcore/ping_array.c | |||
@@ -59,7 +59,7 @@ static void ping_array_clear_timedout(Ping_Array *array) | |||
59 | * return ping_id on success. | 59 | * return ping_id on success. |
60 | * return 0 on failure. | 60 | * return 0 on failure. |
61 | */ | 61 | */ |
62 | uint64_t ping_array_add(Ping_Array *array, uint8_t *data, uint32_t length) | 62 | uint64_t ping_array_add(Ping_Array *array, const uint8_t *data, uint32_t length) |
63 | { | 63 | { |
64 | ping_array_clear_timedout(array); | 64 | ping_array_clear_timedout(array); |
65 | uint32_t index = array->last_added % array->total_size; | 65 | uint32_t index = array->last_added % array->total_size; |
diff --git a/toxcore/ping_array.h b/toxcore/ping_array.h index c5811b16..364ad833 100644 --- a/toxcore/ping_array.h +++ b/toxcore/ping_array.h | |||
@@ -48,7 +48,7 @@ typedef struct { | |||
48 | * return ping_id on success. | 48 | * return ping_id on success. |
49 | * return 0 on failure. | 49 | * return 0 on failure. |
50 | */ | 50 | */ |
51 | uint64_t ping_array_add(Ping_Array *array, uint8_t *data, uint32_t length); | 51 | uint64_t ping_array_add(Ping_Array *array, const uint8_t *data, uint32_t length); |
52 | 52 | ||
53 | /* Check if ping_id is valid and not timed out. | 53 | /* Check if ping_id is valid and not timed out. |
54 | * | 54 | * |
diff --git a/toxcore/tox.c b/toxcore/tox.c index 12bee911..7cb7d692 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -138,7 +138,7 @@ int tox_friend_exists(Tox *tox, int32_t friendnumber) | |||
138 | * m_sendmessage_withid will send a message with the id of your choosing, | 138 | * m_sendmessage_withid will send a message with the id of your choosing, |
139 | * however we can generate an id for you by calling plain m_sendmessage. | 139 | * however we can generate an id for you by calling plain m_sendmessage. |
140 | */ | 140 | */ |
141 | uint32_t tox_send_message(Tox *tox, int32_t friendnumber, uint8_t *message, uint32_t length) | 141 | uint32_t tox_send_message(Tox *tox, int32_t friendnumber, const uint8_t *message, uint32_t length) |
142 | { | 142 | { |
143 | Messenger *m = tox; | 143 | Messenger *m = tox; |
144 | return m_sendmessage(m, friendnumber, message, length); | 144 | return m_sendmessage(m, friendnumber, message, length); |
@@ -362,7 +362,7 @@ uint32_t tox_get_friendlist(Tox *tox, int32_t *out_list, uint32_t list_size) | |||
362 | /* Set the function that will be executed when a friend request is received. | 362 | /* Set the function that will be executed when a friend request is received. |
363 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) | 363 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) |
364 | */ | 364 | */ |
365 | void tox_callback_friend_request(Tox *tox, void (*function)(Tox *tox, uint8_t *, uint8_t *, uint16_t, void *), | 365 | void tox_callback_friend_request(Tox *tox, void (*function)(Tox *tox, const uint8_t *, const uint8_t *, uint16_t, void *), |
366 | void *userdata) | 366 | void *userdata) |
367 | { | 367 | { |
368 | Messenger *m = tox; | 368 | Messenger *m = tox; |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 5a63063f..c217e1a1 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -156,7 +156,7 @@ int tox_friend_exists(Tox *tox, int32_t friendnumber); | |||
156 | * m_sendmessage_withid will send a message with the id of your choosing, | 156 | * m_sendmessage_withid will send a message with the id of your choosing, |
157 | * however we can generate an id for you by calling plain m_sendmessage. | 157 | * however we can generate an id for you by calling plain m_sendmessage. |
158 | */ | 158 | */ |
159 | uint32_t tox_send_message(Tox *tox, int32_t friendnumber, uint8_t *message, uint32_t length); | 159 | uint32_t tox_send_message(Tox *tox, int32_t friendnumber, const uint8_t *message, uint32_t length); |
160 | uint32_t tox_send_message_withid(Tox *tox, int32_t friendnumber, uint32_t theid, uint8_t *message, uint32_t length); | 160 | uint32_t tox_send_message_withid(Tox *tox, int32_t friendnumber, uint32_t theid, uint8_t *message, uint32_t length); |
161 | 161 | ||
162 | /* Send an action to an online friend. | 162 | /* Send an action to an online friend. |
@@ -289,7 +289,7 @@ uint32_t tox_get_friendlist(Tox *tox, int32_t *out_list, uint32_t list_size); | |||
289 | /* Set the function that will be executed when a friend request is received. | 289 | /* Set the function that will be executed when a friend request is received. |
290 | * Function format is function(Tox *tox, uint8_t * public_key, uint8_t * data, uint16_t length, void *userdata) | 290 | * Function format is function(Tox *tox, uint8_t * public_key, uint8_t * data, uint16_t length, void *userdata) |
291 | */ | 291 | */ |
292 | void tox_callback_friend_request(Tox *tox, void (*function)(Tox *tox, uint8_t *, uint8_t *, uint16_t, void *), | 292 | void tox_callback_friend_request(Tox *tox, void (*function)(Tox *tox, const uint8_t *, const uint8_t *, uint16_t, void *), |
293 | void *userdata); | 293 | void *userdata); |
294 | 294 | ||
295 | /* Set the function that will be executed when a message from a friend is received. | 295 | /* Set the function that will be executed when a message from a friend is received. |
diff --git a/toxcore/util.c b/toxcore/util.c index e3bfac4c..969ee704 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -86,7 +86,7 @@ void host_to_net(uint8_t *num, uint16_t numbytes) | |||
86 | 86 | ||
87 | /* state load/save */ | 87 | /* state load/save */ |
88 | int load_state(load_state_callback_func load_state_callback, void *outer, | 88 | int load_state(load_state_callback_func load_state_callback, void *outer, |
89 | uint8_t *data, uint32_t length, uint16_t cookie_inner) | 89 | const uint8_t *data, uint32_t length, uint16_t cookie_inner) |
90 | { | 90 | { |
91 | if (!load_state_callback || !data) { | 91 | if (!load_state_callback || !data) { |
92 | #ifdef DEBUG | 92 | #ifdef DEBUG |
diff --git a/toxcore/util.h b/toxcore/util.h index 74348c11..955ce8c4 100644 --- a/toxcore/util.h +++ b/toxcore/util.h | |||
@@ -43,9 +43,9 @@ void host_to_net(uint8_t *num, uint16_t numbytes); | |||
43 | #define net_to_host(x, y) host_to_net(x, y) | 43 | #define net_to_host(x, y) host_to_net(x, y) |
44 | 44 | ||
45 | /* state load/save */ | 45 | /* state load/save */ |
46 | typedef int (*load_state_callback_func)(void *outer, uint8_t *data, uint32_t len, uint16_t type); | 46 | typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type); |
47 | int load_state(load_state_callback_func load_state_callback, void *outer, | 47 | int load_state(load_state_callback_func load_state_callback, void *outer, |
48 | uint8_t *data, uint32_t length, uint16_t cookie_inner); | 48 | const uint8_t *data, uint32_t length, uint16_t cookie_inner); |
49 | 49 | ||
50 | /* Converts 4 bytes to uint32_t */ | 50 | /* Converts 4 bytes to uint32_t */ |
51 | void bytes_to_U32(uint32_t *dest, const uint8_t *bytes); | 51 | void bytes_to_U32(uint32_t *dest, const uint8_t *bytes); |