summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxcore/DHT.c6
-rw-r--r--toxcore/LAN_discovery.c4
-rw-r--r--toxcore/Messenger.c6
-rw-r--r--toxcore/TCP_server.c2
-rw-r--r--toxcore/assoc.c43
-rw-r--r--toxcore/assoc.h18
-rw-r--r--toxcore/friend_requests.c6
-rw-r--r--toxcore/friend_requests.h6
-rw-r--r--toxcore/group_chats.c52
-rw-r--r--toxcore/group_chats.h26
-rw-r--r--toxcore/net_crypto.c22
-rw-r--r--toxcore/network.h2
-rw-r--r--toxcore/onion.c18
-rw-r--r--toxcore/onion.h8
-rw-r--r--toxcore/onion_announce.c14
-rw-r--r--toxcore/onion_client.c8
-rw-r--r--toxcore/onion_client.h2
-rw-r--r--toxcore/ping.c4
18 files changed, 124 insertions, 123 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 1055ddcd..ae61d988 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -1067,7 +1067,7 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
1067 return sendpacket(dht->net, ip_port, data, 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + len); 1067 return sendpacket(dht->net, ip_port, data, 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + len);
1068} 1068}
1069 1069
1070static int handle_getnodes(void *object, IP_Port source, uint8_t *packet, uint32_t length) 1070static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
1071{ 1071{
1072 uint32_t cmp_len = 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + CLIENT_ID_SIZE + crypto_box_MACBYTES; 1072 uint32_t cmp_len = 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + CLIENT_ID_SIZE + crypto_box_MACBYTES;
1073 1073
@@ -1194,7 +1194,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa
1194 return 0; 1194 return 0;
1195} 1195}
1196 1196
1197static int handle_sendnodes_ipv6(void *object, IP_Port source, uint8_t *packet, uint32_t length) 1197static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
1198{ 1198{
1199 DHT *dht = object; 1199 DHT *dht = object;
1200 Node_format plain_nodes[MAX_SENT_NODES]; 1200 Node_format plain_nodes[MAX_SENT_NODES];
@@ -2296,7 +2296,7 @@ void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_c
2296 dht->cryptopackethandlers[byte].object = object; 2296 dht->cryptopackethandlers[byte].object = object;
2297} 2297}
2298 2298
2299static int cryptopacket_handle(void *object, IP_Port source, uint8_t *packet, uint32_t length) 2299static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
2300{ 2300{
2301 DHT *dht = object; 2301 DHT *dht = object;
2302 2302
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c
index 2deeadfd..e1b8534c 100644
--- a/toxcore/LAN_discovery.c
+++ b/toxcore/LAN_discovery.c
@@ -98,7 +98,7 @@ static void fetch_broadcast_info(uint16_t port)
98 * return 1 if sent to at least one broadcast target. 98 * return 1 if sent to at least one broadcast target.
99 * return 0 on failure to find any valid broadcast target. 99 * return 0 on failure to find any valid broadcast target.
100 */ 100 */
101static uint32_t send_broadcasts(Networking_Core *net, uint16_t port, uint8_t *data, uint16_t length) 101static uint32_t send_broadcasts(Networking_Core *net, uint16_t port, const uint8_t *data, uint16_t length)
102{ 102{
103 /* fetch only once? on every packet? every X seconds? 103 /* fetch only once? on every packet? every X seconds?
104 * old: every packet, new: once */ 104 * old: every packet, new: once */
@@ -207,7 +207,7 @@ int LAN_ip(IP ip)
207 return -1; 207 return -1;
208} 208}
209 209
210static int handle_LANdiscovery(void *object, IP_Port source, uint8_t *packet, uint32_t length) 210static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
211{ 211{
212 DHT *dht = object; 212 DHT *dht = object;
213 213
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index b07b6012..dc8db8b3 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -959,7 +959,7 @@ static int get_chat_num(Messenger *m, Group_Chat *chat)
959 return -1; 959 return -1;
960} 960}
961 961
962static void group_message_function(Group_Chat *chat, int peer_number, uint8_t *message, uint16_t length, void *userdata) 962static void group_message_function(Group_Chat *chat, int peer_number, const uint8_t *message, uint16_t length, void *userdata)
963{ 963{
964 Messenger *m = userdata; 964 Messenger *m = userdata;
965 int i = get_chat_num(m, chat); 965 int i = get_chat_num(m, chat);
@@ -975,7 +975,7 @@ static void group_message_function(Group_Chat *chat, int peer_number, uint8_t *m
975 (*m->group_message)(m, i, peer_number, message_terminated, length, m->group_message_userdata); 975 (*m->group_message)(m, i, peer_number, message_terminated, length, m->group_message_userdata);
976} 976}
977 977
978static void group_action_function(Group_Chat *chat, int peer_number, uint8_t *action, uint16_t length, void *userdata) 978static void group_action_function(Group_Chat *chat, int peer_number, const uint8_t *action, uint16_t length, void *userdata)
979{ 979{
980 Messenger *m = userdata; 980 Messenger *m = userdata;
981 int i = get_chat_num(m, chat); 981 int i = get_chat_num(m, chat);
@@ -1261,7 +1261,7 @@ int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES],
1261 return group_client_names(m->chats[groupnumber], names, lengths, length); 1261 return group_client_names(m->chats[groupnumber], names, lengths, length);
1262} 1262}
1263 1263
1264static int handle_group(void *object, IP_Port source, uint8_t *packet, uint32_t length) 1264static int handle_group(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
1265{ 1265{
1266 Messenger *m = object; 1266 Messenger *m = object;
1267 1267
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c
index d055215e..b900db6b 100644
--- a/toxcore/TCP_server.c
+++ b/toxcore/TCP_server.c
@@ -619,7 +619,7 @@ static int rm_connection_index(TCP_Server *TCP_server, TCP_Secure_Connection *co
619 } 619 }
620} 620}
621 621
622static int handle_onion_recv_1(void *object, IP_Port dest, uint8_t *data, uint16_t length) 622static int handle_onion_recv_1(void *object, IP_Port dest, const uint8_t *data, uint16_t length)
623{ 623{
624 TCP_Server *TCP_server = object; 624 TCP_Server *TCP_server = object;
625 uint32_t index = dest.ip.ip6.uint32[0]; 625 uint32_t index = dest.ip.ip6.uint32[0];
diff --git a/toxcore/assoc.c b/toxcore/assoc.c
index 736f246e..4bacde0e 100644
--- a/toxcore/assoc.c
+++ b/toxcore/assoc.c
@@ -103,7 +103,7 @@ struct Assoc {
103 103
104/* the complete distance would be CLIENT_ID_SIZE long... 104/* the complete distance would be CLIENT_ID_SIZE long...
105 * returns DISTANCE_INDEX_DISTANCE_BITS valid bits */ 105 * returns DISTANCE_INDEX_DISTANCE_BITS valid bits */
106static uint64_t id_distance(Assoc *assoc, void *callback_data, uint8_t *id_ref, uint8_t *id_test) 106static uint64_t id_distance(const Assoc *assoc, void *callback_data, const uint8_t *id_ref, const uint8_t *id_test)
107{ 107{
108 /* with BIG_ENDIAN, this would be a one-liner... */ 108 /* with BIG_ENDIAN, this would be a one-liner... */
109 uint64_t retval = 0; 109 uint64_t retval = 0;
@@ -196,7 +196,7 @@ static void dist_index_bubble(Assoc *assoc, uint64_t *dist_list, size_t first, s
196 * 196 *
197 * Result is NOT MAPPED to CANDIDATES_TO_KEEP range, i.e. map before using 197 * Result is NOT MAPPED to CANDIDATES_TO_KEEP range, i.e. map before using
198 * it for list access. */ 198 * it for list access. */
199static hash_t id_hash(Assoc *assoc, uint8_t *id) 199static hash_t id_hash(const Assoc *assoc, const uint8_t *id)
200{ 200{
201 uint32_t i, res = 0x19a64e82; 201 uint32_t i, res = 0x19a64e82;
202 202
@@ -213,7 +213,7 @@ static hash_t id_hash(Assoc *assoc, uint8_t *id)
213 213
214/* up to HASH_COLLIDE_COUNT calls to different spots, 214/* up to HASH_COLLIDE_COUNT calls to different spots,
215 * result IS mapped to CANDIDATES_TO_KEEP range */ 215 * result IS mapped to CANDIDATES_TO_KEEP range */
216static hash_t hash_collide(Assoc *assoc, hash_t hash) 216static hash_t hash_collide(const Assoc *assoc, hash_t hash)
217{ 217{
218 uint64_t hash64 = hash % assoc->candidates_bucket_size; 218 uint64_t hash64 = hash % assoc->candidates_bucket_size;
219 hash64 = (hash64 * HASH_COLLIDE_PRIME) % assoc->candidates_bucket_size; 219 hash64 = (hash64 * HASH_COLLIDE_PRIME) % assoc->candidates_bucket_size;
@@ -241,7 +241,7 @@ static hash_t hash_collide(Assoc *assoc, hash_t hash)
241} 241}
242 242
243/* returns the "seen" assoc related to the ipp */ 243/* returns the "seen" assoc related to the ipp */
244static IPPTsPng *entry_assoc(Client_entry *cl_entry, IP_Port *ipp) 244static IPPTsPng *entry_assoc(Client_entry *cl_entry, const IP_Port *ipp)
245{ 245{
246 if (!cl_entry) 246 if (!cl_entry)
247 return NULL; 247 return NULL;
@@ -256,7 +256,7 @@ static IPPTsPng *entry_assoc(Client_entry *cl_entry, IP_Port *ipp)
256} 256}
257 257
258/* returns the "heard" assoc related to the ipp */ 258/* returns the "heard" assoc related to the ipp */
259static IP_Port *entry_heard_get(Client_entry *entry, IP_Port *ipp) 259static IP_Port *entry_heard_get(Client_entry *entry, const IP_Port *ipp)
260{ 260{
261 if (ipp->ip.family == AF_INET) 261 if (ipp->ip.family == AF_INET)
262 return &entry->assoc_heard4; 262 return &entry->assoc_heard4;
@@ -271,7 +271,7 @@ static IP_Port *entry_heard_get(Client_entry *entry, IP_Port *ipp)
271 * LAN ip 271 * LAN ip
272 * 272 *
273 * returns 1 if the entry did change */ 273 * returns 1 if the entry did change */
274static int entry_heard_store(Client_entry *entry, IPPTs *ippts) 274static int entry_heard_store(Client_entry *entry, const IPPTs *ippts)
275{ 275{
276 if (!entry || !ippts) 276 if (!entry || !ippts)
277 return 0; 277 return 0;
@@ -279,7 +279,8 @@ static int entry_heard_store(Client_entry *entry, IPPTs *ippts)
279 if (!ipport_isset(&ippts->ip_port)) 279 if (!ipport_isset(&ippts->ip_port))
280 return 0; 280 return 0;
281 281
282 IP_Port *heard, *ipp = &ippts->ip_port; 282 IP_Port *heard;
283 const IP_Port *ipp = &ippts->ip_port;
283 284
284 if (ipp->ip.family == AF_INET) 285 if (ipp->ip.family == AF_INET)
285 heard = &entry->assoc_heard4; 286 heard = &entry->assoc_heard4;
@@ -314,13 +315,13 @@ static int entry_heard_store(Client_entry *entry, IPPTs *ippts)
314} 315}
315 316
316/* maps Assoc callback signature to id_closest() */ 317/* maps Assoc callback signature to id_closest() */
317static int assoc_id_closest(Assoc *assoc, void *callback_data, uint8_t *client_id, uint8_t *client_id1, 318static int assoc_id_closest(const Assoc *assoc, void *callback_data, const uint8_t *client_id, const uint8_t *client_id1,
318 uint8_t *client_id2) 319 const uint8_t *client_id2)
319{ 320{
320 return id_closest(client_id, client_id1, client_id2); 321 return id_closest(client_id, client_id1, client_id2);
321} 322}
322 323
323static bucket_t id_bucket(uint8_t *id, uint8_t bits) 324static bucket_t id_bucket(const uint8_t *id, uint8_t bits)
324{ 325{
325 /* return the first "bits" bits of id */ 326 /* return the first "bits" bits of id */
326 bucket_t retval = 0; 327 bucket_t retval = 0;
@@ -340,12 +341,12 @@ static bucket_t id_bucket(uint8_t *id, uint8_t bits)
340/*****************************************************************************/ 341/*****************************************************************************/
341 342
342 343
343static bucket_t candidates_id_bucket(Assoc *assoc, uint8_t *id) 344static bucket_t candidates_id_bucket(const Assoc *assoc, const uint8_t *id)
344{ 345{
345 return id_bucket(id, assoc->candidates_bucket_bits); 346 return id_bucket(id, assoc->candidates_bucket_bits);
346} 347}
347 348
348static uint8_t candidates_search(Assoc *assoc, uint8_t *id, hash_t hash, Client_entry **entryptr) 349static uint8_t candidates_search(const Assoc *assoc, const uint8_t *id, hash_t hash, Client_entry **entryptr)
349{ 350{
350 bucket_t bucket = candidates_id_bucket(assoc, id); 351 bucket_t bucket = candidates_id_bucket(assoc, id);
351 candidates_bucket *cnd_bckt = &assoc->candidates[bucket]; 352 candidates_bucket *cnd_bckt = &assoc->candidates[bucket];
@@ -365,8 +366,8 @@ static uint8_t candidates_search(Assoc *assoc, uint8_t *id, hash_t hash, Client_
365 return 0; 366 return 0;
366} 367}
367 368
368static void candidates_update_assoc(Assoc *assoc, Client_entry *entry, uint8_t used, IPPTs *ippts_send, 369static void candidates_update_assoc(const Assoc *assoc, Client_entry *entry, uint8_t used, const IPPTs *ippts_send,
369 IP_Port *ipp_recv) 370 const IP_Port *ipp_recv)
370{ 371{
371 if (!assoc || !entry || !ippts_send) 372 if (!assoc || !entry || !ippts_send)
372 return; 373 return;
@@ -397,7 +398,7 @@ static void candidates_update_assoc(Assoc *assoc, Client_entry *entry, uint8_t u
397 entry_heard_store(entry, ippts_send); 398 entry_heard_store(entry, ippts_send);
398} 399}
399 400
400static uint8_t candidates_create_internal(Assoc *assoc, hash_t hash, uint8_t *id, uint8_t seen, 401static uint8_t candidates_create_internal(const Assoc *assoc, hash_t const hash, const uint8_t *id, uint8_t seen,
401 uint8_t used, bucket_t *bucketptr, size_t *posptr) 402 uint8_t used, bucket_t *bucketptr, size_t *posptr)
402{ 403{
403 if (!assoc || !id || !bucketptr || !posptr) 404 if (!assoc || !id || !bucketptr || !posptr)
@@ -454,8 +455,8 @@ static uint8_t candidates_create_internal(Assoc *assoc, hash_t hash, uint8_t *id
454 return 0; 455 return 0;
455} 456}
456 457
457static uint8_t candidates_create_new(Assoc *assoc, hash_t hash, uint8_t *id, uint8_t used, 458static uint8_t candidates_create_new(const Assoc *assoc, hash_t hash, const uint8_t *id, uint8_t used,
458 IPPTs *ippts_send, IP_Port *ipp_recv) 459 const IPPTs *ippts_send, const IP_Port *ipp_recv)
459{ 460{
460 if (!assoc || !id || !ippts_send) 461 if (!assoc || !id || !ippts_send)
461 return 0; 462 return 0;
@@ -550,7 +551,7 @@ static void client_id_self_update(Assoc *assoc)
550 * seen should be 0 (zero), if the candidate was announced by someone else, 551 * seen should be 0 (zero), if the candidate was announced by someone else,
551 * seen should be 1 (one), if there is confirmed connectivity (a definite response) 552 * seen should be 1 (one), if there is confirmed connectivity (a definite response)
552 */ 553 */
553uint8_t Assoc_add_entry(Assoc *assoc, uint8_t *id, IPPTs *ippts_send, IP_Port *ipp_recv, uint8_t used) 554uint8_t Assoc_add_entry(Assoc *assoc, const uint8_t *id, const IPPTs *ippts_send, const IP_Port *ipp_recv, uint8_t used)
554{ 555{
555 if (!assoc || !id || !ippts_send) 556 if (!assoc || !id || !ippts_send)
556 return 0; 557 return 0;
@@ -777,7 +778,7 @@ static size_t prime_upto_min9(size_t limit)
777} 778}
778 779
779/* create */ 780/* create */
780Assoc *new_Assoc(size_t bits, size_t entries, uint8_t *public_id) 781Assoc *new_Assoc(size_t bits, size_t entries, const uint8_t *public_id)
781{ 782{
782 if (!public_id) 783 if (!public_id)
783 return NULL; 784 return NULL;
@@ -850,7 +851,7 @@ Assoc *new_Assoc(size_t bits, size_t entries, uint8_t *public_id)
850 return assoc; 851 return assoc;
851} 852}
852 853
853Assoc *new_Assoc_default(uint8_t *public_id) 854Assoc *new_Assoc_default(const uint8_t *public_id)
854{ 855{
855 /* original 8, 251 averages to ~32k entries... probably the whole DHT :D 856 /* original 8, 251 averages to ~32k entries... probably the whole DHT :D
856 * 320 entries is fine, hopefully */ 857 * 320 entries is fine, hopefully */
@@ -858,7 +859,7 @@ Assoc *new_Assoc_default(uint8_t *public_id)
858} 859}
859 860
860/* own client_id, assocs for this have to be ignored */ 861/* own client_id, assocs for this have to be ignored */
861void Assoc_self_client_id_changed(Assoc *assoc, uint8_t *id) 862void Assoc_self_client_id_changed(Assoc *assoc, const uint8_t *id)
862{ 863{
863 if (assoc && id) { 864 if (assoc && id) {
864 assoc->self_hash = 0; 865 assoc->self_hash = 0;
diff --git a/toxcore/assoc.h b/toxcore/assoc.h
index 0fdff4fe..bc27e62c 100644
--- a/toxcore/assoc.h
+++ b/toxcore/assoc.h
@@ -21,21 +21,21 @@ typedef struct Assoc Assoc;
21 21
22/* custom distance handler, if it's not ID-distance based 22/* custom distance handler, if it's not ID-distance based
23 * return values exactly like id_closest() */ 23 * return values exactly like id_closest() */
24typedef int (*Assoc_distance_relative_callback)(Assoc *assoc, void *callback_data, uint8_t *client_id, 24typedef int (*Assoc_distance_relative_callback)(const Assoc *assoc, void *callback_data, const uint8_t *client_id,
25 uint8_t *client_id1, uint8_t *client_id2); 25 const uint8_t *client_id1, const uint8_t *client_id2);
26 26
27#define DISTANCE_INDEX_DISTANCE_BITS 44 27#define DISTANCE_INDEX_DISTANCE_BITS 44
28 28
29/* absolute distance: can be same for different client_id_check values 29/* absolute distance: can be same for different client_id_check values
30 * return value should have DISTANCE_INDEX_DISTANCE_BITS valid bits */ 30 * return value should have DISTANCE_INDEX_DISTANCE_BITS valid bits */
31typedef uint64_t (*Assoc_distance_absolute_callback)(Assoc *assoc, void *callback_data, 31typedef uint64_t (*Assoc_distance_absolute_callback)(const Assoc *assoc, void *callback_data,
32 uint8_t *client_id_ref, uint8_t *client_id_check); 32 const uint8_t *client_id_ref, const uint8_t *client_id_check);
33 33
34/*****************************************************************************/ 34/*****************************************************************************/
35 35
36/* Central entry point for new associations: add a new candidate to the cache 36/* Central entry point for new associations: add a new candidate to the cache
37 * returns 1 if entry is stored, 2 if existing entry was updated, 0 else */ 37 * returns 1 if entry is stored, 2 if existing entry was updated, 0 else */
38uint8_t Assoc_add_entry(Assoc *assoc, uint8_t *id, IPPTs *ippts_send, IP_Port *ipp_recv, uint8_t used); 38uint8_t Assoc_add_entry(Assoc *assoc, const uint8_t *id, const IPPTs *ippts_send, const IP_Port *ipp_recv, uint8_t used);
39 39
40/*****************************************************************************/ 40/*****************************************************************************/
41 41
@@ -72,7 +72,7 @@ uint8_t Assoc_get_close_entries(Assoc *assoc, Assoc_close_entries *close_entries
72/*****************************************************************************/ 72/*****************************************************************************/
73 73
74/* create: default sizes (6, 5 => 320 entries) */ 74/* create: default sizes (6, 5 => 320 entries) */
75Assoc *new_Assoc_default(uint8_t *public_id); 75Assoc *new_Assoc_default(const uint8_t *public_id);
76 76
77/* create: customized sizes 77/* create: customized sizes
78 * total is (2^bits) * entries 78 * total is (2^bits) * entries
@@ -81,10 +81,10 @@ Assoc *new_Assoc_default(uint8_t *public_id);
81 * 81 *
82 * preferably bits should be large and entries small to ensure spread 82 * preferably bits should be large and entries small to ensure spread
83 * in the search space (e. g. 5, 5 is preferable to 2, 41) */ 83 * in the search space (e. g. 5, 5 is preferable to 2, 41) */
84Assoc *new_Assoc(size_t bits, size_t entries, uint8_t *public_id); 84Assoc *new_Assoc(size_t bits, size_t entries, const uint8_t *public_id);
85 85
86/* public_id changed (loaded), update which entry isn't stored */ 86/* public_id changed (loaded), update which entry isn't stored */
87void Assoc_self_client_id_changed(Assoc *assoc, uint8_t *public_id); 87void Assoc_self_client_id_changed(Assoc *assoc, const uint8_t *public_id);
88 88
89/* every 45s send out a getnodes() for a "random" bucket */ 89/* every 45s send out a getnodes() for a "random" bucket */
90#define ASSOC_BUCKET_REFRESH 45 90#define ASSOC_BUCKET_REFRESH 45
@@ -97,7 +97,7 @@ void do_Assoc(Assoc *assoc, DHT *dht);
97void kill_Assoc(Assoc *assoc); 97void kill_Assoc(Assoc *assoc);
98 98
99#ifdef LOGGING 99#ifdef LOGGING
100void Assoc_status(Assoc *assoc); 100void Assoc_status(const Assoc *assoc);
101#endif /* LOGGING */ 101#endif /* LOGGING */
102 102
103#endif /* !__ASSOC_H__ */ 103#endif /* !__ASSOC_H__ */
diff --git a/toxcore/friend_requests.c b/toxcore/friend_requests.c
index 9b05cc51..8366a8cb 100644
--- a/toxcore/friend_requests.c
+++ b/toxcore/friend_requests.c
@@ -35,7 +35,7 @@
35 * return 0 if it sent the friend request directly to the friend. 35 * return 0 if it sent the friend request directly to the friend.
36 * return the number of peers it was routed through if it did not send it directly. 36 * return the number of peers it was routed through if it did not send it directly.
37 */ 37 */
38int send_friendrequest(Onion_Client *onion_c, uint8_t *public_key, uint32_t nospam_num, uint8_t *data, uint32_t length) 38int send_friendrequest(const Onion_Client *onion_c, const uint8_t *public_key, uint32_t nospam_num, const uint8_t *data, uint32_t length)
39{ 39{
40 if (1 + sizeof(nospam_num) + length > ONION_CLIENT_MAX_DATA_SIZE || length == 0) 40 if (1 + sizeof(nospam_num) + length > ONION_CLIENT_MAX_DATA_SIZE || length == 0)
41 return -1; 41 return -1;
@@ -65,7 +65,7 @@ void set_nospam(Friend_Requests *fr, uint32_t num)
65 fr->nospam = num; 65 fr->nospam = num;
66} 66}
67 67
68uint32_t get_nospam(Friend_Requests *fr) 68uint32_t get_nospam(const Friend_Requests *fr)
69{ 69{
70 return fr->nospam; 70 return fr->nospam;
71} 71}
@@ -118,7 +118,7 @@ static int request_received(Friend_Requests *fr, const uint8_t *client_id)
118 * return 0 if it removed it successfully. 118 * return 0 if it removed it successfully.
119 * return -1 if it didn't find it. 119 * return -1 if it didn't find it.
120 */ 120 */
121int remove_request_received(Friend_Requests *fr, uint8_t *client_id) 121int remove_request_received(Friend_Requests *fr, const uint8_t *client_id)
122{ 122{
123 uint32_t i; 123 uint32_t i;
124 124
diff --git a/toxcore/friend_requests.h b/toxcore/friend_requests.h
index 8d429a7e..e669607b 100644
--- a/toxcore/friend_requests.h
+++ b/toxcore/friend_requests.h
@@ -51,17 +51,17 @@ typedef struct {
51 * data is the data in the request and length is the length. 51 * data is the data in the request and length is the length.
52 * Maximum length of data is MAX_FRIEND_REQUEST_DATA_SIZE. 52 * Maximum length of data is MAX_FRIEND_REQUEST_DATA_SIZE.
53 */ 53 */
54int send_friendrequest(Onion_Client *onion_c, uint8_t *public_key, uint32_t nospam_num, uint8_t *data, uint32_t length); 54int send_friendrequest(const Onion_Client *onion_c, const uint8_t *public_key, uint32_t nospam_num, const uint8_t *data, uint32_t length);
55/* Set and get the nospam variable used to prevent one type of friend request spam. */ 55/* Set and get the nospam variable used to prevent one type of friend request spam. */
56void set_nospam(Friend_Requests *fr, uint32_t num); 56void set_nospam(Friend_Requests *fr, uint32_t num);
57uint32_t get_nospam(Friend_Requests *fr); 57uint32_t get_nospam(const Friend_Requests *fr);
58 58
59/* Remove client id from received_requests list. 59/* Remove client id from received_requests list.
60 * 60 *
61 * return 0 if it removed it successfully. 61 * return 0 if it removed it successfully.
62 * return -1 if it didn't find it. 62 * return -1 if it didn't find it.
63 */ 63 */
64int remove_request_received(Friend_Requests *fr, uint8_t *client_id); 64int remove_request_received(Friend_Requests *fr, const uint8_t *client_id);
65 65
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)
diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c
index 85928436..882b3f42 100644
--- a/toxcore/group_chats.c
+++ b/toxcore/group_chats.c
@@ -65,7 +65,7 @@ typedef struct {
65 * TODO: make this more efficient. 65 * TODO: make this more efficient.
66 */ 66 */
67 67
68static int peer_in_chat(Group_Chat *chat, uint8_t *client_id) 68static int peer_in_chat(const Group_Chat *chat, const uint8_t *client_id)
69{ 69{
70 uint32_t i; 70 uint32_t i;
71 71
@@ -82,7 +82,7 @@ static int peer_in_chat(Group_Chat *chat, uint8_t *client_id)
82 * return 1 if client_id1 is closer. 82 * return 1 if client_id1 is closer.
83 * return 2 if client_id2 is closer. 83 * return 2 if client_id2 is closer.
84 */ 84 */
85static int id_closest_groupchats(uint8_t *id, uint8_t *id1, uint8_t *id2) 85static int id_closest_groupchats(const uint8_t *id, const uint8_t *id1, const uint8_t *id2)
86{ 86{
87 size_t i; 87 size_t i;
88 uint8_t distance1, distance2; 88 uint8_t distance1, distance2;
@@ -110,7 +110,7 @@ static int id_closest_groupchats(uint8_t *id, uint8_t *id1, uint8_t *id2)
110 * Return -1 if the peer is in the closelist. 110 * Return -1 if the peer is in the closelist.
111 */ 111 */
112 112
113static int peer_okping(Group_Chat *chat, uint8_t *client_id) 113static int peer_okping(const Group_Chat *chat, const uint8_t *client_id)
114{ 114{
115 uint32_t i, j = 0; 115 uint32_t i, j = 0;
116 116
@@ -143,7 +143,7 @@ static int peer_okping(Group_Chat *chat, uint8_t *client_id)
143 * Return 0 if success. 143 * Return 0 if success.
144 * Return -1 if peer was not put in list/updated. 144 * Return -1 if peer was not put in list/updated.
145 */ 145 */
146static int add_closepeer(Group_Chat *chat, uint8_t *client_id, IP_Port ip_port) 146static int add_closepeer(Group_Chat *chat, const uint8_t *client_id, IP_Port ip_port)
147{ 147{
148 uint32_t i; 148 uint32_t i;
149 149
@@ -175,7 +175,7 @@ static int add_closepeer(Group_Chat *chat, uint8_t *client_id, IP_Port ip_port)
175 return -1; 175 return -1;
176} 176}
177 177
178static int send_groupchatpacket(Group_Chat *chat, IP_Port ip_port, uint8_t *public_key, uint8_t *data, uint32_t length, 178static int send_groupchatpacket(const Group_Chat *chat, IP_Port ip_port, const uint8_t *public_key, const uint8_t *data, uint32_t length,
179 uint8_t request_id) 179 uint8_t request_id)
180{ 180{
181 if (id_equal(chat->self_public_key, public_key)) 181 if (id_equal(chat->self_public_key, public_key))
@@ -200,7 +200,7 @@ static int send_groupchatpacket(Group_Chat *chat, IP_Port ip_port, uint8_t *publ
200 * 200 *
201 * return the number of peers the packet was sent to. 201 * return the number of peers the packet was sent to.
202 */ 202 */
203static uint8_t sendto_allpeers(Group_Chat *chat, uint8_t *data, uint16_t length, uint8_t request_id) 203static uint8_t sendto_allpeers(const Group_Chat *chat, const uint8_t *data, uint16_t length, uint8_t request_id)
204{ 204{
205 uint16_t sent = 0; 205 uint16_t sent = 0;
206 uint32_t i; 206 uint32_t i;
@@ -224,7 +224,7 @@ static uint8_t sendto_allpeers(Group_Chat *chat, uint8_t *data, uint16_t length,
224 * return peernum if success or peer already in chat. 224 * return peernum if success or peer already in chat.
225 * return -1 if error. 225 * return -1 if error.
226 */ 226 */
227static int addpeer(Group_Chat *chat, uint8_t *client_id) 227static int addpeer(Group_Chat *chat, const uint8_t *client_id)
228{ 228{
229 int peernum = peer_in_chat(chat, client_id); 229 int peernum = peer_in_chat(chat, client_id);
230 230
@@ -319,7 +319,7 @@ static int delpeer(Group_Chat *chat, int peernum)
319 * return length of name if success 319 * return length of name if success
320 * return -1 if failure 320 * return -1 if failure
321 */ 321 */
322int group_peername(Group_Chat *chat, int peernum, uint8_t *name) 322int group_peername(const Group_Chat *chat, int peernum, uint8_t *name)
323{ 323{
324 if ((uint32_t)peernum >= chat->numpeers) 324 if ((uint32_t)peernum >= chat->numpeers)
325 return -1; 325 return -1;
@@ -334,7 +334,7 @@ int group_peername(Group_Chat *chat, int peernum, uint8_t *name)
334 return chat->group[peernum].nick_len; 334 return chat->group[peernum].nick_len;
335} 335}
336 336
337static void setnick(Group_Chat *chat, int peernum, uint8_t *contents, uint16_t contents_len) 337static void setnick(Group_Chat *chat, int peernum, const uint8_t *contents, uint16_t contents_len)
338{ 338{
339 if (contents_len > MAX_NICK_BYTES || contents_len == 0) 339 if (contents_len > MAX_NICK_BYTES || contents_len == 0)
340 return; 340 return;
@@ -355,7 +355,7 @@ static void setnick(Group_Chat *chat, int peernum, uint8_t *contents, uint16_t c
355/* TODO: move this to global section */ 355/* TODO: move this to global section */
356#define GROUP_PING_TIMEOUT 5 356#define GROUP_PING_TIMEOUT 5
357 357
358static int send_getnodes(Group_Chat *chat, IP_Port ip_port, int peernum) 358static int send_getnodes(const Group_Chat *chat, IP_Port ip_port, int peernum)
359{ 359{
360 if ((uint32_t)peernum >= chat->numpeers) 360 if ((uint32_t)peernum >= chat->numpeers)
361 return -1; 361 return -1;
@@ -382,7 +382,7 @@ static int send_getnodes(Group_Chat *chat, IP_Port ip_port, int peernum)
382 CRYPTO_PACKET_GROUP_CHAT_GET_NODES); 382 CRYPTO_PACKET_GROUP_CHAT_GET_NODES);
383} 383}
384 384
385static int send_sendnodes(Group_Chat *chat, IP_Port ip_port, int peernum, uint64_t pingid) 385static int send_sendnodes(const Group_Chat *chat, IP_Port ip_port, int peernum, uint64_t pingid)
386{ 386{
387 if ((uint32_t)peernum >= chat->numpeers) 387 if ((uint32_t)peernum >= chat->numpeers)
388 return -1; 388 return -1;
@@ -404,7 +404,7 @@ static int send_sendnodes(Group_Chat *chat, IP_Port ip_port, int peernum, uint64
404 sizeof(contents.pingid) + sizeof(groupchat_nodes) * j, CRYPTO_PACKET_GROUP_CHAT_SEND_NODES); 404 sizeof(contents.pingid) + sizeof(groupchat_nodes) * j, CRYPTO_PACKET_GROUP_CHAT_SEND_NODES);
405} 405}
406 406
407static int handle_getnodes(Group_Chat *chat, IP_Port source, int peernum, uint8_t *data, uint32_t len) 407static int handle_getnodes(const Group_Chat *chat, IP_Port source, int peernum, const uint8_t *data, uint32_t len)
408{ 408{
409 if (len != sizeof(getnodes_data)) 409 if (len != sizeof(getnodes_data))
410 return 1; 410 return 1;
@@ -422,7 +422,7 @@ static int handle_getnodes(Group_Chat *chat, IP_Port source, int peernum, uint8_
422 return 0; 422 return 0;
423} 423}
424 424
425static int handle_sendnodes(Group_Chat *chat, IP_Port source, int peernum, uint8_t *data, uint32_t len) 425static int handle_sendnodes(Group_Chat *chat, IP_Port source, int peernum, const uint8_t *data, uint32_t len)
426{ 426{
427 if ((uint32_t)peernum >= chat->numpeers) 427 if ((uint32_t)peernum >= chat->numpeers)
428 return 1; 428 return 1;
@@ -487,7 +487,7 @@ static int handle_sendnodes(Group_Chat *chat, IP_Port source, int peernum, uint8
487#define GROUP_DATA_MIN_SIZE (crypto_box_PUBLICKEYBYTES + sizeof(uint32_t) + 1) 487#define GROUP_DATA_MIN_SIZE (crypto_box_PUBLICKEYBYTES + sizeof(uint32_t) + 1)
488static void send_names_new_peer(Group_Chat *chat); 488static void send_names_new_peer(Group_Chat *chat);
489 489
490static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len) 490static int handle_data(Group_Chat *chat, const uint8_t *data, uint32_t len)
491{ 491{
492 if (len < GROUP_DATA_MIN_SIZE) 492 if (len < GROUP_DATA_MIN_SIZE)
493 return 1; 493 return 1;
@@ -526,7 +526,7 @@ static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len)
526 chat->group[peernum].last_message_number = message_num; 526 chat->group[peernum].last_message_number = message_num;
527 527
528 int handled = 1; 528 int handled = 1;
529 uint8_t *contents = data + GROUP_DATA_MIN_SIZE; 529 const uint8_t *contents = data + GROUP_DATA_MIN_SIZE;
530 uint16_t contents_len = len - GROUP_DATA_MIN_SIZE; 530 uint16_t contents_len = len - GROUP_DATA_MIN_SIZE;
531 531
532 switch (data[crypto_box_PUBLICKEYBYTES + sizeof(message_num)]) { 532 switch (data[crypto_box_PUBLICKEYBYTES + sizeof(message_num)]) {
@@ -585,7 +585,7 @@ static int handle_data(Group_Chat *chat, uint8_t *data, uint32_t len)
585 return 1; 585 return 1;
586} 586}
587 587
588static uint8_t send_data(Group_Chat *chat, uint8_t *data, uint32_t len, uint8_t message_id) 588static uint8_t send_data(Group_Chat *chat, const uint8_t *data, uint32_t len, uint8_t message_id)
589{ 589{
590 if (len + GROUP_DATA_MIN_SIZE > MAX_CRYPTO_REQUEST_SIZE) /*NOTE: not the real maximum len.*/ 590 if (len + GROUP_DATA_MIN_SIZE > MAX_CRYPTO_REQUEST_SIZE) /*NOTE: not the real maximum len.*/
591 return 1; 591 return 1;
@@ -614,7 +614,7 @@ static uint8_t send_data(Group_Chat *chat, uint8_t *data, uint32_t len, uint8_t
614 * return 1 if error. 614 * return 1 if error.
615 */ 615 */
616 616
617int handle_groupchatpacket(Group_Chat *chat, IP_Port source, uint8_t *packet, uint32_t length) 617int handle_groupchatpacket(Group_Chat *chat, IP_Port source, const uint8_t *packet, uint32_t length)
618{ 618{
619 if (length > MAX_CRYPTO_REQUEST_SIZE) 619 if (length > MAX_CRYPTO_REQUEST_SIZE)
620 return 1; 620 return 1;
@@ -652,12 +652,12 @@ int handle_groupchatpacket(Group_Chat *chat, IP_Port source, uint8_t *packet, ui
652 return 1; 652 return 1;
653} 653}
654 654
655uint32_t group_sendmessage(Group_Chat *chat, uint8_t *message, uint32_t length) 655uint32_t group_sendmessage(Group_Chat *chat, const uint8_t *message, uint32_t length)
656{ 656{
657 return send_data(chat, message, length, GROUP_CHAT_CHAT_MESSAGE); //TODO: better return values? 657 return send_data(chat, message, length, GROUP_CHAT_CHAT_MESSAGE); //TODO: better return values?
658} 658}
659 659
660uint32_t group_sendaction(Group_Chat *chat, uint8_t *action, uint32_t length) 660uint32_t group_sendaction(Group_Chat *chat, const uint8_t *action, uint32_t length)
661{ 661{
662 return send_data(chat, action, length, GROUP_CHAT_ACTION); 662 return send_data(chat, action, length, GROUP_CHAT_ACTION);
663} 663}
@@ -686,20 +686,20 @@ int set_nick(Group_Chat *chat, const uint8_t *nick, uint16_t nick_len)
686 return 0; 686 return 0;
687} 687}
688 688
689uint32_t group_newpeer(Group_Chat *chat, uint8_t *client_id) 689uint32_t group_newpeer(Group_Chat *chat, const uint8_t *client_id)
690{ 690{
691 addpeer(chat, client_id); 691 addpeer(chat, client_id);
692 return send_data(chat, client_id, crypto_box_PUBLICKEYBYTES, GROUP_CHAT_NEW_PEER); //TODO: better return values? 692 return send_data(chat, client_id, crypto_box_PUBLICKEYBYTES, GROUP_CHAT_NEW_PEER); //TODO: better return values?
693} 693}
694 694
695void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat, int, uint8_t *, uint16_t, void *), 695void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat, int, const uint8_t *, uint16_t, void *),
696 void *userdata) 696 void *userdata)
697{ 697{
698 chat->group_message = function; 698 chat->group_message = function;
699 chat->group_message_userdata = userdata; 699 chat->group_message_userdata = userdata;
700} 700}
701 701
702void callback_groupaction(Group_Chat *chat, void (*function)(Group_Chat *chat, int, uint8_t *, uint16_t, void *), 702void callback_groupaction(Group_Chat *chat, void (*function)(Group_Chat *chat, int, const uint8_t *, uint16_t, void *),
703 void *userdata) 703 void *userdata)
704{ 704{
705 chat->group_action = function; 705 chat->group_action = function;
@@ -713,12 +713,12 @@ void callback_namelistchange(Group_Chat *chat, void (*function)(Group_Chat *chat
713 chat->group_namelistchange_userdata = userdata; 713 chat->group_namelistchange_userdata = userdata;
714} 714}
715 715
716uint32_t group_numpeers(Group_Chat *chat) 716uint32_t group_numpeers(const Group_Chat *chat)
717{ 717{
718 return chat->numpeers; 718 return chat->numpeers;
719} 719}
720 720
721uint32_t group_client_names(Group_Chat *chat, uint8_t names[][MAX_NICK_BYTES], uint16_t lengths[], uint16_t length) 721uint32_t group_client_names(const Group_Chat *chat, uint8_t names[][MAX_NICK_BYTES], uint16_t lengths[], uint16_t length)
722{ 722{
723 uint32_t i; 723 uint32_t i;
724 724
@@ -833,12 +833,12 @@ void kill_groupchat(Group_Chat *chat)
833 free(chat); 833 free(chat);
834} 834}
835 835
836void chat_bootstrap(Group_Chat *chat, IP_Port ip_port, uint8_t *client_id) 836void chat_bootstrap(Group_Chat *chat, IP_Port ip_port, const uint8_t *client_id)
837{ 837{
838 send_getnodes(chat, ip_port, addpeer(chat, client_id)); 838 send_getnodes(chat, ip_port, addpeer(chat, client_id));
839} 839}
840 840
841void chat_bootstrap_nonlazy(Group_Chat *chat, IP_Port ip_port, uint8_t *client_id) 841void chat_bootstrap_nonlazy(Group_Chat *chat, IP_Port ip_port, const uint8_t *client_id)
842{ 842{
843 send_getnodes(chat, ip_port, addpeer(chat, client_id)); 843 send_getnodes(chat, ip_port, addpeer(chat, client_id));
844 add_closepeer(chat, client_id, ip_port); 844 add_closepeer(chat, client_id, ip_port);
diff --git a/toxcore/group_chats.h b/toxcore/group_chats.h
index 49b83c81..802d345b 100644
--- a/toxcore/group_chats.h
+++ b/toxcore/group_chats.h
@@ -62,9 +62,9 @@ typedef struct Group_Chat {
62 uint32_t numpeers; 62 uint32_t numpeers;
63 63
64 uint32_t message_number; 64 uint32_t message_number;
65 void (*group_message)(struct Group_Chat *m, int, uint8_t *, uint16_t, void *); 65 void (*group_message)(struct Group_Chat *m, int, const uint8_t *, uint16_t, void *);
66 void *group_message_userdata; 66 void *group_message_userdata;
67 void (*group_action)(struct Group_Chat *m, int, uint8_t *, uint16_t, void *); 67 void (*group_action)(struct Group_Chat *m, int, const uint8_t *, uint16_t, void *);
68 void *group_action_userdata; 68 void *group_action_userdata;
69 void (*peer_namelistchange)(struct Group_Chat *m, int peer, uint8_t change, void *); 69 void (*peer_namelistchange)(struct Group_Chat *m, int peer, uint8_t change, void *);
70 void *group_namelistchange_userdata; 70 void *group_namelistchange_userdata;
@@ -91,14 +91,14 @@ typedef struct Group_Chat {
91 * return length of name if success 91 * return length of name if success
92 * return -1 if failure 92 * return -1 if failure
93 */ 93 */
94int group_peername(Group_Chat *chat, int peernum, uint8_t *name); 94int group_peername(const Group_Chat *chat, int peernum, uint8_t *name);
95 95
96/* 96/*
97 * Set callback function for chat messages. 97 * Set callback function for chat messages.
98 * 98 *
99 * format of function is: function(Group_Chat *chat, peer number, message, message length, userdata) 99 * format of function is: function(Group_Chat *chat, peer number, message, message length, userdata)
100 */ 100 */
101void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat, int, uint8_t *, uint16_t, void *), 101void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat, int, const uint8_t *, uint16_t, void *),
102 void *userdata); 102 void *userdata);
103 103
104/* 104/*
@@ -106,7 +106,7 @@ void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat,
106 * 106 *
107 * format of function is: function(Group_Chat *chat, peer number, action, action length, userdata) 107 * format of function is: function(Group_Chat *chat, peer number, action, action length, userdata)
108 */ 108 */
109void callback_groupaction(Group_Chat *chat, void (*function)(Group_Chat *chat, int, uint8_t *, uint16_t, void *), 109void callback_groupaction(Group_Chat *chat, void (*function)(Group_Chat *chat, int, const uint8_t *, uint16_t, void *),
110 void *userdata); 110 void *userdata);
111 111
112/* 112/*
@@ -130,14 +130,14 @@ void callback_namelistchange(Group_Chat *chat, void (*function)(Group_Chat *chat
130 * 130 *
131 * returns the number of peers it has sent it to. 131 * returns the number of peers it has sent it to.
132 */ 132 */
133uint32_t group_sendmessage(Group_Chat *chat, uint8_t *message, uint32_t length); 133uint32_t group_sendmessage(Group_Chat *chat, const uint8_t *message, uint32_t length);
134 134
135/* 135/*
136 * Send an action to the group. 136 * Send an action to the group.
137 * 137 *
138 * returns the number of peers it has sent it to. 138 * returns the number of peers it has sent it to.
139 */ 139 */
140uint32_t group_sendaction(Group_Chat *chat, uint8_t *action, uint32_t length); 140uint32_t group_sendaction(Group_Chat *chat, const uint8_t *action, uint32_t length);
141 141
142/* 142/*
143 * Set our nick for this group. 143 * Set our nick for this group.
@@ -150,7 +150,7 @@ int set_nick(Group_Chat *chat, const uint8_t *nick, uint16_t nick_len);
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.)
151 * 151 *
152 */ 152 */
153uint32_t group_newpeer(Group_Chat *chat, uint8_t *client_id); 153uint32_t group_newpeer(Group_Chat *chat, const uint8_t *client_id);
154 154
155 155
156/* Create a new group chat. 156/* Create a new group chat.
@@ -164,7 +164,7 @@ Group_Chat *new_groupchat(Networking_Core *net);
164 164
165/* Return the number of peers in the group chat. 165/* Return the number of peers in the group chat.
166 */ 166 */
167uint32_t group_numpeers(Group_Chat *chat); 167uint32_t group_numpeers(const Group_Chat *chat);
168 168
169/* List all the peers in the group chat. 169/* List all the peers in the group chat.
170 * 170 *
@@ -172,7 +172,7 @@ uint32_t group_numpeers(Group_Chat *chat);
172 * 172 *
173 * returns the number of peers. 173 * returns the number of peers.
174 */ 174 */
175uint32_t group_client_names(Group_Chat *chat, uint8_t names[][MAX_NICK_BYTES], uint16_t lengths[], uint16_t length); 175uint32_t group_client_names(const Group_Chat *chat, uint8_t names[][MAX_NICK_BYTES], uint16_t lengths[], uint16_t length);
176 176
177/* Kill a group chat 177/* Kill a group chat
178 * 178 *
@@ -188,11 +188,11 @@ void do_groupchat(Group_Chat *chat);
188/* if we receive a group chat packet we call this function so it can be handled. 188/* if we receive a group chat packet we call this function so it can be handled.
189 return 0 if packet is handled correctly. 189 return 0 if packet is handled correctly.
190 return 1 if it didn't handle the packet or if the packet was shit. */ 190 return 1 if it didn't handle the packet or if the packet was shit. */
191int handle_groupchatpacket(Group_Chat *chat, IP_Port source, uint8_t *packet, uint32_t length); 191int handle_groupchatpacket(Group_Chat *chat, IP_Port source, const uint8_t *packet, uint32_t length);
192 192
193 193
194void chat_bootstrap(Group_Chat *chat, IP_Port ip_port, uint8_t *client_id); 194void chat_bootstrap(Group_Chat *chat, IP_Port ip_port, const uint8_t *client_id);
195void chat_bootstrap_nonlazy(Group_Chat *chat, IP_Port ip_port, uint8_t *client_id); 195void chat_bootstrap_nonlazy(Group_Chat *chat, IP_Port ip_port, const uint8_t *client_id);
196 196
197 197
198#endif 198#endif
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 78a6121c..c34c24d7 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -120,7 +120,7 @@ static int create_cookie(uint8_t *cookie, uint8_t *bytes, uint8_t *encryption_ke
120 * return -1 on failure. 120 * return -1 on failure.
121 * return 0 on success. 121 * return 0 on success.
122 */ 122 */
123static int open_cookie(uint8_t *bytes, uint8_t *cookie, uint8_t *encryption_key) 123static int open_cookie(uint8_t *bytes, const uint8_t *cookie, const uint8_t *encryption_key)
124{ 124{
125 uint8_t contents[COOKIE_CONTENTS_LENGTH]; 125 uint8_t contents[COOKIE_CONTENTS_LENGTH];
126 int len = decrypt_data_symmetric(encryption_key, cookie, cookie + crypto_box_NONCEBYTES, 126 int len = decrypt_data_symmetric(encryption_key, cookie, cookie + crypto_box_NONCEBYTES,
@@ -178,7 +178,7 @@ static int create_cookie_response(Net_Crypto *c, uint8_t *packet, uint8_t *reque
178 * return 0 on success. 178 * return 0 on success.
179 */ 179 */
180static int handle_cookie_request(Net_Crypto *c, uint8_t *request_plain, uint8_t *shared_key, uint8_t *dht_public_key, 180static int handle_cookie_request(Net_Crypto *c, uint8_t *request_plain, uint8_t *shared_key, uint8_t *dht_public_key,
181 uint8_t *packet, uint16_t length) 181 const uint8_t *packet, uint16_t length)
182{ 182{
183 if (length != COOKIE_REQUEST_LENGTH) 183 if (length != COOKIE_REQUEST_LENGTH)
184 return -1; 184 return -1;
@@ -197,7 +197,7 @@ static int handle_cookie_request(Net_Crypto *c, uint8_t *request_plain, uint8_t
197 197
198/* Handle the cookie request packet (for raw UDP) 198/* Handle the cookie request packet (for raw UDP)
199 */ 199 */
200static int udp_handle_cookie_request(void *object, IP_Port source, uint8_t *packet, uint32_t length) 200static int udp_handle_cookie_request(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
201{ 201{
202 Net_Crypto *c = object; 202 Net_Crypto *c = object;
203 uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH]; 203 uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH];
@@ -275,8 +275,8 @@ static int tcp_oob_handle_cookie_request(Net_Crypto *c, TCP_Client_Connection *T
275 * return -1 on failure. 275 * return -1 on failure.
276 * return COOKIE_LENGTH on success. 276 * return COOKIE_LENGTH on success.
277 */ 277 */
278static int handle_cookie_response(uint8_t *cookie, uint64_t *number, uint8_t *packet, uint32_t length, 278static int handle_cookie_response(uint8_t *cookie, uint64_t *number, const uint8_t *packet, uint32_t length,
279 uint8_t *shared_key) 279 const uint8_t *shared_key)
280{ 280{
281 if (length != COOKIE_RESPONSE_LENGTH) 281 if (length != COOKIE_RESPONSE_LENGTH)
282 return -1; 282 return -1;
@@ -349,7 +349,7 @@ static int create_crypto_handshake(Net_Crypto *c, uint8_t *packet, uint8_t *cook
349 * return 0 on success. 349 * return 0 on success.
350 */ 350 */
351static int handle_crypto_handshake(Net_Crypto *c, uint8_t *nonce, uint8_t *session_pk, uint8_t *peer_real_pk, 351static int handle_crypto_handshake(Net_Crypto *c, uint8_t *nonce, uint8_t *session_pk, uint8_t *peer_real_pk,
352 uint8_t *dht_public_key, uint8_t *cookie, uint8_t *packet, uint32_t length, uint8_t *expected_real_pk) 352 uint8_t *dht_public_key, uint8_t *cookie, const uint8_t *packet, uint32_t length, uint8_t *expected_real_pk)
353{ 353{
354 if (length != HANDSHAKE_PACKET_LENGTH) 354 if (length != HANDSHAKE_PACKET_LENGTH)
355 return -1; 355 return -1;
@@ -815,7 +815,7 @@ static uint16_t get_nonce_uint16(uint8_t *nonce)
815 * return -1 on failure. 815 * return -1 on failure.
816 * return length of data on success. 816 * return length of data on success.
817 */ 817 */
818static int handle_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint8_t *packet, uint16_t length) 818static int handle_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *data, const uint8_t *packet, uint16_t length)
819{ 819{
820 if (length <= (1 + sizeof(uint16_t) + crypto_box_MACBYTES) || length > MAX_CRYPTO_PACKET_SIZE) 820 if (length <= (1 + sizeof(uint16_t) + crypto_box_MACBYTES) || length > MAX_CRYPTO_PACKET_SIZE)
821 return -1; 821 return -1;
@@ -1039,7 +1039,7 @@ static int send_kill_packet(Net_Crypto *c, int crypt_connection_id)
1039 * return -1 on failure. 1039 * return -1 on failure.
1040 * return 0 on success. 1040 * return 0 on success.
1041 */ 1041 */
1042static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint8_t *packet, uint16_t length) 1042static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length)
1043{ 1043{
1044 if (length > MAX_CRYPTO_PACKET_SIZE || length <= CRYPTO_DATA_PACKET_MIN_SIZE) 1044 if (length > MAX_CRYPTO_PACKET_SIZE || length <= CRYPTO_DATA_PACKET_MIN_SIZE)
1045 return -1; 1045 return -1;
@@ -1133,7 +1133,7 @@ static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uin
1133 * return -1 on failure. 1133 * return -1 on failure.
1134 * return 0 on success. 1134 * return 0 on success.
1135 */ 1135 */
1136static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, uint8_t *packet, uint16_t length) 1136static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length)
1137{ 1137{
1138 if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) 1138 if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE)
1139 return -1; 1139 return -1;
@@ -1370,7 +1370,7 @@ void new_connection_handler(Net_Crypto *c, int (*new_connection_callback)(void *
1370 * return -1 on failure. 1370 * return -1 on failure.
1371 * return 0 on success. 1371 * return 0 on success.
1372 */ 1372 */
1373static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, uint8_t *data, uint16_t length) 1373static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const uint8_t *data, uint16_t length)
1374{ 1374{
1375 New_Connection n_c; 1375 New_Connection n_c;
1376 n_c.cookie = malloc(COOKIE_LENGTH); 1376 n_c.cookie = malloc(COOKIE_LENGTH);
@@ -2123,7 +2123,7 @@ static int crypto_id_ip_port(Net_Crypto *c, IP_Port ip_port)
2123 * Crypto data packets. 2123 * Crypto data packets.
2124 * 2124 *
2125 */ 2125 */
2126static int udp_handle_packet(void *object, IP_Port source, uint8_t *packet, uint32_t length) 2126static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
2127{ 2127{
2128 if (length <= CRYPTO_MIN_PACKET_SIZE || length > MAX_CRYPTO_PACKET_SIZE) 2128 if (length <= CRYPTO_MIN_PACKET_SIZE || length > MAX_CRYPTO_PACKET_SIZE)
2129 return 1; 2129 return 1;
diff --git a/toxcore/network.h b/toxcore/network.h
index e5c24a2d..359d26c8 100644
--- a/toxcore/network.h
+++ b/toxcore/network.h
@@ -270,7 +270,7 @@ int addr_resolve_or_parse_ip(const char *address, IP *to, IP *extra);
270 * Packet data is put into data. 270 * Packet data is put into data.
271 * Packet length is put into length. 271 * Packet length is put into length.
272 */ 272 */
273typedef int (*packet_handler_callback)(void *object, IP_Port ip_port, uint8_t *data, uint32_t len); 273typedef int (*packet_handler_callback)(void *object, IP_Port ip_port, const uint8_t *data, uint32_t len);
274 274
275typedef struct { 275typedef struct {
276 packet_handler_callback function; 276 packet_handler_callback function;
diff --git a/toxcore/onion.c b/toxcore/onion.c
index 479c6209..194178f3 100644
--- a/toxcore/onion.c
+++ b/toxcore/onion.c
@@ -149,7 +149,7 @@ int send_onion_packet(Networking_Core *net, Onion_Path *path, IP_Port dest, uint
149 * return -1 on failure. 149 * return -1 on failure.
150 * return 0 on success. 150 * return 0 on success.
151 */ 151 */
152int send_onion_response(Networking_Core *net, IP_Port dest, uint8_t *data, uint32_t length, uint8_t *ret) 152int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data, uint32_t length, const uint8_t *ret)
153{ 153{
154 if (length > ONION_RESPONSE_MAX_DATA_SIZE || length == 0) 154 if (length > ONION_RESPONSE_MAX_DATA_SIZE || length == 0)
155 return -1; 155 return -1;
@@ -165,7 +165,7 @@ int send_onion_response(Networking_Core *net, IP_Port dest, uint8_t *data, uint3
165 return 0; 165 return 0;
166} 166}
167 167
168static int handle_send_initial(void *object, IP_Port source, uint8_t *packet, uint32_t length) 168static int handle_send_initial(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
169{ 169{
170 Onion *onion = object; 170 Onion *onion = object;
171 171
@@ -189,7 +189,7 @@ static int handle_send_initial(void *object, IP_Port source, uint8_t *packet, ui
189 return onion_send_1(onion, plain, len, source, packet + 1); 189 return onion_send_1(onion, plain, len, source, packet + 1);
190} 190}
191 191
192int onion_send_1(Onion *onion, uint8_t *plain, uint32_t len, IP_Port source, uint8_t *nonce) 192int onion_send_1(Onion *onion, uint8_t *plain, uint32_t len, IP_Port source, const uint8_t *nonce)
193{ 193{
194 IP_Port send_to; 194 IP_Port send_to;
195 ipport_unpack(&send_to, plain); 195 ipport_unpack(&send_to, plain);
@@ -219,7 +219,7 @@ int onion_send_1(Onion *onion, uint8_t *plain, uint32_t len, IP_Port source, uin
219 return 0; 219 return 0;
220} 220}
221 221
222static int handle_send_1(void *object, IP_Port source, uint8_t *packet, uint32_t length) 222static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
223{ 223{
224 Onion *onion = object; 224 Onion *onion = object;
225 225
@@ -268,7 +268,7 @@ static int handle_send_1(void *object, IP_Port source, uint8_t *packet, uint32_t
268 return 0; 268 return 0;
269} 269}
270 270
271static int handle_send_2(void *object, IP_Port source, uint8_t *packet, uint32_t length) 271static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
272{ 272{
273 Onion *onion = object; 273 Onion *onion = object;
274 274
@@ -316,7 +316,7 @@ static int handle_send_2(void *object, IP_Port source, uint8_t *packet, uint32_t
316} 316}
317 317
318 318
319static int handle_recv_3(void *object, IP_Port source, uint8_t *packet, uint32_t length) 319static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
320{ 320{
321 Onion *onion = object; 321 Onion *onion = object;
322 322
@@ -350,7 +350,7 @@ static int handle_recv_3(void *object, IP_Port source, uint8_t *packet, uint32_t
350 return 0; 350 return 0;
351} 351}
352 352
353static int handle_recv_2(void *object, IP_Port source, uint8_t *packet, uint32_t length) 353static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
354{ 354{
355 Onion *onion = object; 355 Onion *onion = object;
356 356
@@ -384,7 +384,7 @@ static int handle_recv_2(void *object, IP_Port source, uint8_t *packet, uint32_t
384 return 0; 384 return 0;
385} 385}
386 386
387static int handle_recv_1(void *object, IP_Port source, uint8_t *packet, uint32_t length) 387static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
388{ 388{
389 Onion *onion = object; 389 Onion *onion = object;
390 390
@@ -417,7 +417,7 @@ static int handle_recv_1(void *object, IP_Port source, uint8_t *packet, uint32_t
417 return 0; 417 return 0;
418} 418}
419 419
420void set_callback_handle_recv_1(Onion *onion, int (*function)(void *, IP_Port, uint8_t *, uint16_t), void *object) 420void set_callback_handle_recv_1(Onion *onion, int (*function)(void *, IP_Port, const uint8_t *, uint16_t), void *object)
421{ 421{
422 onion->recv_1_function = function; 422 onion->recv_1_function = function;
423 onion->callback_object = object; 423 onion->callback_object = object;
diff --git a/toxcore/onion.h b/toxcore/onion.h
index 13dc8f52..07d5b6d9 100644
--- a/toxcore/onion.h
+++ b/toxcore/onion.h
@@ -35,7 +35,7 @@ typedef struct {
35 Shared_Keys shared_keys_2; 35 Shared_Keys shared_keys_2;
36 Shared_Keys shared_keys_3; 36 Shared_Keys shared_keys_3;
37 37
38 int (*recv_1_function)(void *, IP_Port, uint8_t *, uint16_t); 38 int (*recv_1_function)(void *, IP_Port, const uint8_t *, uint16_t);
39 void *callback_object; 39 void *callback_object;
40} Onion; 40} Onion;
41 41
@@ -94,7 +94,7 @@ int send_onion_packet(Networking_Core *net, Onion_Path *path, IP_Port dest, uint
94 * return -1 on failure. 94 * return -1 on failure.
95 * return 0 on success. 95 * return 0 on success.
96 */ 96 */
97int send_onion_response(Networking_Core *net, IP_Port dest, uint8_t *data, uint32_t length, uint8_t *ret); 97int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data, uint32_t length, const uint8_t *ret);
98 98
99/* Function to handle/send received decrypted versions of the packet sent with send_onion_packet. 99/* Function to handle/send received decrypted versions of the packet sent with send_onion_packet.
100 * 100 *
@@ -106,13 +106,13 @@ int send_onion_response(Networking_Core *net, IP_Port dest, uint8_t *data, uint3
106 * Source family must be set to something else than AF_INET6 or AF_INET so that the callback gets called 106 * Source family must be set to something else than AF_INET6 or AF_INET so that the callback gets called
107 * when the response is received. 107 * when the response is received.
108 */ 108 */
109int onion_send_1(Onion *onion, uint8_t *plain, uint32_t len, IP_Port source, uint8_t *nonce); 109int onion_send_1(Onion *onion, uint8_t *plain, uint32_t len, IP_Port source, const uint8_t *nonce);
110 110
111/* Set the callback to be called when the dest ip_port doesn't have AF_INET6 or AF_INET as the family. 111/* Set the callback to be called when the dest ip_port doesn't have AF_INET6 or AF_INET as the family.
112 * 112 *
113 * Format: function(void *object, IP_Port dest, uint8_t *data, uint32_t length) 113 * Format: function(void *object, IP_Port dest, uint8_t *data, uint32_t length)
114 */ 114 */
115void set_callback_handle_recv_1(Onion *onion, int (*function)(void *, IP_Port, uint8_t *, uint16_t), void *object); 115void set_callback_handle_recv_1(Onion *onion, int (*function)(void *, IP_Port, const uint8_t *, uint16_t), void *object);
116 116
117Onion *new_onion(DHT *dht); 117Onion *new_onion(DHT *dht);
118 118
diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c
index a9891b9c..a8f71a4e 100644
--- a/toxcore/onion_announce.c
+++ b/toxcore/onion_announce.c
@@ -115,7 +115,7 @@ int send_data_request(Networking_Core *net, Onion_Path *path, IP_Port dest, uint
115} 115}
116 116
117/* Generate a ping_id and put it in ping_id */ 117/* Generate a ping_id and put it in ping_id */
118static void generate_ping_id(Onion_Announce *onion_a, uint64_t time, uint8_t *public_key, IP_Port ret_ip_port, 118static void generate_ping_id(Onion_Announce *onion_a, uint64_t time, const uint8_t *public_key, IP_Port ret_ip_port,
119 uint8_t *ping_id) 119 uint8_t *ping_id)
120{ 120{
121 time /= PING_ID_TIMEOUT; 121 time /= PING_ID_TIMEOUT;
@@ -132,7 +132,7 @@ static void generate_ping_id(Onion_Announce *onion_a, uint64_t time, uint8_t *pu
132 * return -1 if no 132 * return -1 if no
133 * return position in list if yes 133 * return position in list if yes
134 */ 134 */
135static int in_entries(Onion_Announce *onion_a, uint8_t *public_key) 135static int in_entries(const Onion_Announce *onion_a, const uint8_t *public_key)
136{ 136{
137 uint32_t i; 137 uint32_t i;
138 138
@@ -179,8 +179,8 @@ static int cmp_entry(const void *a, const void *b)
179 * return -1 if failure 179 * return -1 if failure
180 * return position if added 180 * return position if added
181 */ 181 */
182static int add_to_entries(Onion_Announce *onion_a, IP_Port ret_ip_port, uint8_t *public_key, uint8_t *data_public_key, 182static int add_to_entries(Onion_Announce *onion_a, IP_Port ret_ip_port, const uint8_t *public_key, const uint8_t *data_public_key,
183 uint8_t *ret) 183 const uint8_t *ret)
184{ 184{
185 185
186 int pos = in_entries(onion_a, public_key); 186 int pos = in_entries(onion_a, public_key);
@@ -213,14 +213,14 @@ static int add_to_entries(Onion_Announce *onion_a, IP_Port ret_ip_port, uint8_t
213 return in_entries(onion_a, public_key); 213 return in_entries(onion_a, public_key);
214} 214}
215 215
216static int handle_announce_request(void *object, IP_Port source, uint8_t *packet, uint32_t length) 216static int handle_announce_request(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
217{ 217{
218 Onion_Announce *onion_a = object; 218 Onion_Announce *onion_a = object;
219 219
220 if (length != ANNOUNCE_REQUEST_SIZE_RECV) 220 if (length != ANNOUNCE_REQUEST_SIZE_RECV)
221 return 1; 221 return 1;
222 222
223 uint8_t *packet_public_key = packet + 1 + crypto_box_NONCEBYTES; 223 const uint8_t *packet_public_key = packet + 1 + crypto_box_NONCEBYTES;
224 uint8_t shared_key[crypto_box_BEFORENMBYTES]; 224 uint8_t shared_key[crypto_box_BEFORENMBYTES];
225 get_shared_key(&onion_a->shared_keys_recv, shared_key, onion_a->dht->self_secret_key, packet_public_key); 225 get_shared_key(&onion_a->shared_keys_recv, shared_key, onion_a->dht->self_secret_key, packet_public_key);
226 226
@@ -302,7 +302,7 @@ static int handle_announce_request(void *object, IP_Port source, uint8_t *packet
302 return 0; 302 return 0;
303} 303}
304 304
305static int handle_data_request(void *object, IP_Port source, uint8_t *packet, uint32_t length) 305static int handle_data_request(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
306{ 306{
307 Onion_Announce *onion_a = object; 307 Onion_Announce *onion_a = object;
308 308
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index 1fe54d85..ae5e8810 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -164,7 +164,7 @@ static int new_sendback(Onion_Client *onion_c, uint32_t num, uint8_t *public_key
164 * return ~0 on failure 164 * return ~0 on failure
165 * return num (see new_sendback(...)) on success 165 * return num (see new_sendback(...)) on success
166 */ 166 */
167static uint32_t check_sendback(Onion_Client *onion_c, uint8_t *sendback, uint8_t *ret_pubkey, IP_Port *ret_ip_port) 167static uint32_t check_sendback(Onion_Client *onion_c, const uint8_t *sendback, uint8_t *ret_pubkey, IP_Port *ret_ip_port)
168{ 168{
169 uint64_t sback; 169 uint64_t sback;
170 memcpy(&sback, sendback, sizeof(uint64_t)); 170 memcpy(&sback, sendback, sizeof(uint64_t));
@@ -377,7 +377,7 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, Node_format *n
377 return 0; 377 return 0;
378} 378}
379 379
380static int handle_announce_response(void *object, IP_Port source, uint8_t *packet, uint32_t length) 380static int handle_announce_response(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
381{ 381{
382 Onion_Client *onion_c = object; 382 Onion_Client *onion_c = object;
383 383
@@ -432,7 +432,7 @@ static int handle_announce_response(void *object, IP_Port source, uint8_t *packe
432 432
433#define DATA_IN_RESPONSE_MIN_SIZE ONION_DATA_IN_RESPONSE_MIN_SIZE 433#define DATA_IN_RESPONSE_MIN_SIZE ONION_DATA_IN_RESPONSE_MIN_SIZE
434 434
435static int handle_data_response(void *object, IP_Port source, uint8_t *packet, uint32_t length) 435static int handle_data_response(void *object, IP_Port source, const uint8_t *packet, uint32_t length)
436{ 436{
437 Onion_Client *onion_c = object; 437 Onion_Client *onion_c = object;
438 438
@@ -530,7 +530,7 @@ static int handle_fakeid_announce(void *object, const uint8_t *source_pubkey, co
530 * return the number of packets sent on success 530 * return the number of packets sent on success
531 * return -1 on failure. 531 * return -1 on failure.
532 */ 532 */
533int send_onion_data(Onion_Client *onion_c, int friend_num, uint8_t *data, uint32_t length) 533int send_onion_data(const Onion_Client *onion_c, int friend_num, const uint8_t *data, uint32_t length)
534{ 534{
535 if ((uint32_t)friend_num >= onion_c->num_friends) 535 if ((uint32_t)friend_num >= onion_c->num_friends)
536 return -1; 536 return -1;
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h
index df7be2ef..a74783f6 100644
--- a/toxcore/onion_client.h
+++ b/toxcore/onion_client.h
@@ -212,7 +212,7 @@ uint64_t onion_getfriend_DHT_pubkey(Onion_Client *onion_c, int friend_num, uint8
212 * return the number of packets sent on success 212 * return the number of packets sent on success
213 * return -1 on failure. 213 * return -1 on failure.
214 */ 214 */
215int send_onion_data(Onion_Client *onion_c, int friend_num, uint8_t *data, uint32_t length); 215int send_onion_data(const Onion_Client *onion_c, int friend_num, const uint8_t *data, uint32_t length);
216 216
217/* Function to call when onion data packet with contents beginning with byte is received. */ 217/* Function to call when onion data packet with contents beginning with byte is received. */
218void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_handler_callback cb, void *object); 218void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_handler_callback cb, void *object);
diff --git a/toxcore/ping.c b/toxcore/ping.c
index ea8fd04d..e00036af 100644
--- a/toxcore/ping.c
+++ b/toxcore/ping.c
@@ -129,7 +129,7 @@ static int send_ping_response(PING *ping, IP_Port ipp, const uint8_t *client_id,
129 return sendpacket(ping->dht->net, ipp, pk, sizeof(pk)); 129 return sendpacket(ping->dht->net, ipp, pk, sizeof(pk));
130} 130}
131 131
132static int handle_ping_request(void *_dht, IP_Port source, uint8_t *packet, uint32_t length) 132static int handle_ping_request(void *_dht, IP_Port source, const uint8_t *packet, uint32_t length)
133{ 133{
134 DHT *dht = _dht; 134 DHT *dht = _dht;
135 int rc; 135 int rc;
@@ -168,7 +168,7 @@ static int handle_ping_request(void *_dht, IP_Port source, uint8_t *packet, uint
168 return 0; 168 return 0;
169} 169}
170 170
171static int handle_ping_response(void *_dht, IP_Port source, uint8_t *packet, uint32_t length) 171static int handle_ping_response(void *_dht, IP_Port source, const uint8_t *packet, uint32_t length)
172{ 172{
173 DHT *dht = _dht; 173 DHT *dht = _dht;
174 int rc; 174 int rc;