diff options
-rw-r--r-- | toxav/audio.c | 19 | ||||
-rw-r--r-- | toxav/audio.h | 5 | ||||
-rw-r--r-- | toxav/groupav.c | 20 | ||||
-rw-r--r-- | toxav/groupav.h | 4 | ||||
-rw-r--r-- | toxav/msi.c | 6 | ||||
-rw-r--r-- | toxav/msi.h | 2 | ||||
-rw-r--r-- | toxav/rtp.c | 15 | ||||
-rw-r--r-- | toxav/rtp.h | 2 | ||||
-rw-r--r-- | toxav/video.c | 4 | ||||
-rw-r--r-- | toxav/video.h | 5 | ||||
-rw-r--r-- | toxcore/DHT.c | 8 | ||||
-rw-r--r-- | toxcore/DHT.h | 2 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 63 | ||||
-rw-r--r-- | toxcore/net_crypto.h | 2 | ||||
-rw-r--r-- | toxcore/network.c | 12 | ||||
-rw-r--r-- | toxcore/network.h | 6 | ||||
-rw-r--r-- | toxcore/util.c | 2 | ||||
-rw-r--r-- | toxcore/util.h | 2 |
18 files changed, 91 insertions, 88 deletions
diff --git a/toxav/audio.c b/toxav/audio.c index 85639f16..3b46d1d5 100644 --- a/toxav/audio.c +++ b/toxav/audio.c | |||
@@ -33,16 +33,17 @@ | |||
33 | static struct JitterBuffer *jbuf_new(uint32_t capacity); | 33 | static struct JitterBuffer *jbuf_new(uint32_t capacity); |
34 | static void jbuf_clear(struct JitterBuffer *q); | 34 | static void jbuf_clear(struct JitterBuffer *q); |
35 | static void jbuf_free(struct JitterBuffer *q); | 35 | static void jbuf_free(struct JitterBuffer *q); |
36 | static int jbuf_write(Logger *log, struct JitterBuffer *q, struct RTPMessage *m); | 36 | static int jbuf_write(const Logger *log, struct JitterBuffer *q, struct RTPMessage *m); |
37 | static struct RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success); | 37 | static struct RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success); |
38 | OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t sampling_rate, int32_t channel_count); | 38 | static OpusEncoder *create_audio_encoder(const Logger *log, int32_t bit_rate, int32_t sampling_rate, |
39 | bool reconfigure_audio_encoder(Logger *log, OpusEncoder **e, int32_t new_br, int32_t new_sr, uint8_t new_ch, | 39 | int32_t channel_count); |
40 | int32_t *old_br, int32_t *old_sr, int32_t *old_ch); | 40 | static bool reconfigure_audio_encoder(const Logger *log, OpusEncoder **e, int32_t new_br, int32_t new_sr, |
41 | bool reconfigure_audio_decoder(ACSession *ac, int32_t sampling_rate, int8_t channels); | 41 | uint8_t new_ch, int32_t *old_br, int32_t *old_sr, int32_t *old_ch); |
42 | static bool reconfigure_audio_decoder(ACSession *ac, int32_t sampling_rate, int8_t channels); | ||
42 | 43 | ||
43 | 44 | ||
44 | 45 | ||
45 | ACSession *ac_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_receive_frame_cb *cb, void *cb_data) | 46 | ACSession *ac_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_receive_frame_cb *cb, void *cb_data) |
46 | { | 47 | { |
47 | ACSession *ac = (ACSession *)calloc(sizeof(ACSession), 1); | 48 | ACSession *ac = (ACSession *)calloc(sizeof(ACSession), 1); |
48 | 49 | ||
@@ -309,7 +310,7 @@ static void jbuf_free(struct JitterBuffer *q) | |||
309 | free(q->queue); | 310 | free(q->queue); |
310 | free(q); | 311 | free(q); |
311 | } | 312 | } |
312 | static int jbuf_write(Logger *log, struct JitterBuffer *q, struct RTPMessage *m) | 313 | static int jbuf_write(const Logger *log, struct JitterBuffer *q, struct RTPMessage *m) |
313 | { | 314 | { |
314 | uint16_t sequnum = m->header.sequnum; | 315 | uint16_t sequnum = m->header.sequnum; |
315 | 316 | ||
@@ -363,7 +364,7 @@ static struct RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success) | |||
363 | *success = 0; | 364 | *success = 0; |
364 | return nullptr; | 365 | return nullptr; |
365 | } | 366 | } |
366 | OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t sampling_rate, int32_t channel_count) | 367 | OpusEncoder *create_audio_encoder(const Logger *log, int32_t bit_rate, int32_t sampling_rate, int32_t channel_count) |
367 | { | 368 | { |
368 | int status = OPUS_OK; | 369 | int status = OPUS_OK; |
369 | /* | 370 | /* |
@@ -456,7 +457,7 @@ FAILURE: | |||
456 | return nullptr; | 457 | return nullptr; |
457 | } | 458 | } |
458 | 459 | ||
459 | bool reconfigure_audio_encoder(Logger *log, OpusEncoder **e, int32_t new_br, int32_t new_sr, uint8_t new_ch, | 460 | bool reconfigure_audio_encoder(const Logger *log, OpusEncoder **e, int32_t new_br, int32_t new_sr, uint8_t new_ch, |
460 | int32_t *old_br, int32_t *old_sr, int32_t *old_ch) | 461 | int32_t *old_br, int32_t *old_sr, int32_t *old_ch) |
461 | { | 462 | { |
462 | /* Values are checked in toxav.c */ | 463 | /* Values are checked in toxav.c */ |
diff --git a/toxav/audio.h b/toxav/audio.h index 73f1b19e..64aa2f12 100644 --- a/toxav/audio.h +++ b/toxav/audio.h | |||
@@ -51,7 +51,7 @@ | |||
51 | struct RTPMessage; | 51 | struct RTPMessage; |
52 | 52 | ||
53 | typedef struct ACSession_s { | 53 | typedef struct ACSession_s { |
54 | Logger *log; | 54 | const Logger *log; |
55 | 55 | ||
56 | /* encoding */ | 56 | /* encoding */ |
57 | OpusEncoder *encoder; | 57 | OpusEncoder *encoder; |
@@ -76,7 +76,8 @@ typedef struct ACSession_s { | |||
76 | PAIR(toxav_audio_receive_frame_cb *, void *) acb; /* Audio frame receive callback */ | 76 | PAIR(toxav_audio_receive_frame_cb *, void *) acb; /* Audio frame receive callback */ |
77 | } ACSession; | 77 | } ACSession; |
78 | 78 | ||
79 | ACSession *ac_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_receive_frame_cb *cb, void *cb_data); | 79 | ACSession *ac_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_receive_frame_cb *cb, |
80 | void *cb_data); | ||
80 | void ac_kill(ACSession *ac); | 81 | void ac_kill(ACSession *ac); |
81 | void ac_iterate(ACSession *ac); | 82 | void ac_iterate(ACSession *ac); |
82 | int ac_queue_message(void *acp, struct RTPMessage *msg); | 83 | int ac_queue_message(void *acp, struct RTPMessage *msg); |
diff --git a/toxav/groupav.c b/toxav/groupav.c index f0cb3a5b..97baac39 100644 --- a/toxav/groupav.c +++ b/toxav/groupav.c | |||
@@ -159,7 +159,7 @@ static Group_Audio_Packet *dequeue(Group_JitterBuffer *q, int *success) | |||
159 | } | 159 | } |
160 | 160 | ||
161 | typedef struct { | 161 | typedef struct { |
162 | Logger *log; | 162 | const Logger *log; |
163 | Group_Chats *g_c; | 163 | Group_Chats *g_c; |
164 | OpusEncoder *audio_encoder; | 164 | OpusEncoder *audio_encoder; |
165 | 165 | ||
@@ -227,8 +227,8 @@ static int recreate_encoder(Group_AV *group_av) | |||
227 | return 0; | 227 | return 0; |
228 | } | 228 | } |
229 | 229 | ||
230 | static Group_AV *new_group_av(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, uint32_t, uint32_t, | 230 | static Group_AV *new_group_av(const Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, uint32_t, |
231 | const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata) | 231 | uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata) |
232 | { | 232 | { |
233 | if (!g_c) { | 233 | if (!g_c) { |
234 | return nullptr; | 234 | return nullptr; |
@@ -429,9 +429,9 @@ static int handle_group_audio_packet(void *object, uint32_t groupnumber, uint32_ | |||
429 | * return 0 on success. | 429 | * return 0 on success. |
430 | * return -1 on failure. | 430 | * return -1 on failure. |
431 | */ | 431 | */ |
432 | static int groupchat_enable_av(Logger *log, Group_Chats *g_c, uint32_t groupnumber, void (*audio_callback)(Messenger *, | 432 | static int groupchat_enable_av(const Logger *log, Group_Chats *g_c, uint32_t groupnumber, |
433 | uint32_t, | 433 | void (*audio_callback)(Messenger *, |
434 | uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata) | 434 | uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata) |
435 | { | 435 | { |
436 | Group_AV *group_av = new_group_av(log, g_c, audio_callback, userdata); | 436 | Group_AV *group_av = new_group_av(log, g_c, audio_callback, userdata); |
437 | 437 | ||
@@ -456,10 +456,8 @@ static int groupchat_enable_av(Logger *log, Group_Chats *g_c, uint32_t groupnumb | |||
456 | * return group number on success. | 456 | * return group number on success. |
457 | * return -1 on failure. | 457 | * return -1 on failure. |
458 | */ | 458 | */ |
459 | int add_av_groupchat(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, uint32_t, uint32_t, | 459 | int add_av_groupchat(const Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, uint32_t, uint32_t, |
460 | const int16_t *, | 460 | const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata) |
461 | unsigned int, | ||
462 | uint8_t, uint32_t, void *), void *userdata) | ||
463 | { | 461 | { |
464 | int groupnumber = add_groupchat(g_c, GROUPCHAT_TYPE_AV); | 462 | int groupnumber = add_groupchat(g_c, GROUPCHAT_TYPE_AV); |
465 | 463 | ||
@@ -480,7 +478,7 @@ int add_av_groupchat(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messe | |||
480 | * returns group number on success | 478 | * returns group number on success |
481 | * returns -1 on failure. | 479 | * returns -1 on failure. |
482 | */ | 480 | */ |
483 | int join_av_groupchat(Logger *log, Group_Chats *g_c, uint32_t friendnumber, const uint8_t *data, uint16_t length, | 481 | int join_av_groupchat(const Logger *log, Group_Chats *g_c, uint32_t friendnumber, const uint8_t *data, uint16_t length, |
484 | void (*audio_callback)(Messenger *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), | 482 | void (*audio_callback)(Messenger *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), |
485 | void *userdata) | 483 | void *userdata) |
486 | { | 484 | { |
diff --git a/toxav/groupav.h b/toxav/groupav.h index 142edb0e..ca30a51b 100644 --- a/toxav/groupav.h +++ b/toxav/groupav.h | |||
@@ -29,7 +29,7 @@ | |||
29 | * return group number on success. | 29 | * return group number on success. |
30 | * return -1 on failure. | 30 | * return -1 on failure. |
31 | */ | 31 | */ |
32 | int add_av_groupchat(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, uint32_t, uint32_t, | 32 | int add_av_groupchat(const Logger *log, Group_Chats *g_c, void (*audio_callback)(Messenger *, uint32_t, uint32_t, |
33 | const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata); | 33 | const int16_t *, unsigned int, uint8_t, uint32_t, void *), void *userdata); |
34 | 34 | ||
35 | /* Join a AV group (you need to have been invited first.) | 35 | /* Join a AV group (you need to have been invited first.) |
@@ -37,7 +37,7 @@ int add_av_groupchat(Logger *log, Group_Chats *g_c, void (*audio_callback)(Messe | |||
37 | * returns group number on success | 37 | * returns group number on success |
38 | * returns -1 on failure. | 38 | * returns -1 on failure. |
39 | */ | 39 | */ |
40 | int join_av_groupchat(Logger *log, Group_Chats *g_c, uint32_t friendnumber, const uint8_t *data, uint16_t length, | 40 | int join_av_groupchat(const Logger *log, Group_Chats *g_c, uint32_t friendnumber, const uint8_t *data, uint16_t length, |
41 | void (*audio_callback)(Messenger *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), | 41 | void (*audio_callback)(Messenger *, uint32_t, uint32_t, const int16_t *, unsigned int, uint8_t, uint32_t, void *), |
42 | void *userdata); | 42 | void *userdata); |
43 | 43 | ||
diff --git a/toxav/msi.c b/toxav/msi.c index 47f76fb7..f00ccfdf 100644 --- a/toxav/msi.c +++ b/toxav/msi.c | |||
@@ -74,7 +74,7 @@ typedef struct { | |||
74 | 74 | ||
75 | 75 | ||
76 | void msg_init(MSIMessage *dest, MSIRequest request); | 76 | void msg_init(MSIMessage *dest, MSIRequest request); |
77 | int msg_parse_in(Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t length); | 77 | int msg_parse_in(const Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t length); |
78 | uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const void *value, uint8_t value_len, uint16_t *length); | 78 | uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const void *value, uint8_t value_len, uint16_t *length); |
79 | static int send_message(Messenger *m, uint32_t friend_number, const MSIMessage *msg); | 79 | static int send_message(Messenger *m, uint32_t friend_number, const MSIMessage *msg); |
80 | int send_error(Messenger *m, uint32_t friend_number, MSIError error); | 80 | int send_error(Messenger *m, uint32_t friend_number, MSIError error); |
@@ -131,7 +131,7 @@ MSISession *msi_new(Messenger *m) | |||
131 | LOGGER_DEBUG(m->log, "New msi session: %p ", (void *)retu); | 131 | LOGGER_DEBUG(m->log, "New msi session: %p ", (void *)retu); |
132 | return retu; | 132 | return retu; |
133 | } | 133 | } |
134 | int msi_kill(MSISession *session, Logger *log) | 134 | int msi_kill(MSISession *session, const Logger *log) |
135 | { | 135 | { |
136 | if (session == nullptr) { | 136 | if (session == nullptr) { |
137 | LOGGER_ERROR(log, "Tried to terminate non-existing session"); | 137 | LOGGER_ERROR(log, "Tried to terminate non-existing session"); |
@@ -324,7 +324,7 @@ void msg_init(MSIMessage *dest, MSIRequest request) | |||
324 | dest->request.exists = true; | 324 | dest->request.exists = true; |
325 | dest->request.value = request; | 325 | dest->request.value = request; |
326 | } | 326 | } |
327 | int msg_parse_in(Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t length) | 327 | int msg_parse_in(const Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t length) |
328 | { | 328 | { |
329 | /* Parse raw data received from socket into MSIMessage struct */ | 329 | /* Parse raw data received from socket into MSIMessage struct */ |
330 | 330 | ||
diff --git a/toxav/msi.h b/toxav/msi.h index 43ff46d5..b2c15567 100644 --- a/toxav/msi.h +++ b/toxav/msi.h | |||
@@ -126,7 +126,7 @@ MSISession *msi_new(Messenger *m); | |||
126 | /** | 126 | /** |
127 | * Terminate control session. NOTE: all calls will be freed | 127 | * Terminate control session. NOTE: all calls will be freed |
128 | */ | 128 | */ |
129 | int msi_kill(MSISession *session, Logger *log); | 129 | int msi_kill(MSISession *session, const Logger *log); |
130 | /** | 130 | /** |
131 | * Callback setter. | 131 | * Callback setter. |
132 | */ | 132 | */ |
diff --git a/toxav/rtp.c b/toxav/rtp.c index bc968de4..1e178720 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c | |||
@@ -82,7 +82,7 @@ enum { | |||
82 | * do not kick it out right away if all slots are full instead kick out the new | 82 | * do not kick it out right away if all slots are full instead kick out the new |
83 | * incoming interframe. | 83 | * incoming interframe. |
84 | */ | 84 | */ |
85 | static int8_t get_slot(Logger *log, struct RTPWorkBufferList *wkbl, bool is_keyframe, | 85 | static int8_t get_slot(const Logger *log, struct RTPWorkBufferList *wkbl, bool is_keyframe, |
86 | const struct RTPHeader *header, bool is_multipart) | 86 | const struct RTPHeader *header, bool is_multipart) |
87 | { | 87 | { |
88 | if (is_multipart) { | 88 | if (is_multipart) { |
@@ -198,7 +198,7 @@ static int8_t get_slot(Logger *log, struct RTPWorkBufferList *wkbl, bool is_keyf | |||
198 | * non-NULL, it transfers ownership of the message to the caller, i.e. the | 198 | * non-NULL, it transfers ownership of the message to the caller, i.e. the |
199 | * caller is responsible for storing it elsewhere or calling free(). | 199 | * caller is responsible for storing it elsewhere or calling free(). |
200 | */ | 200 | */ |
201 | static struct RTPMessage *process_frame(Logger *log, struct RTPWorkBufferList *wkbl, uint8_t slot_id) | 201 | static struct RTPMessage *process_frame(const Logger *log, struct RTPWorkBufferList *wkbl, uint8_t slot_id) |
202 | { | 202 | { |
203 | assert(wkbl->next_free_entry >= 0); | 203 | assert(wkbl->next_free_entry >= 0); |
204 | 204 | ||
@@ -253,8 +253,9 @@ static struct RTPMessage *process_frame(Logger *log, struct RTPWorkBufferList *w | |||
253 | * @param incoming_data The pure payload without header. | 253 | * @param incoming_data The pure payload without header. |
254 | * @param incoming_data_length The length in bytes of the incoming data payload. | 254 | * @param incoming_data_length The length in bytes of the incoming data payload. |
255 | */ | 255 | */ |
256 | static bool fill_data_into_slot(Logger *log, struct RTPWorkBufferList *wkbl, const uint8_t slot_id, bool is_keyframe, | 256 | static bool fill_data_into_slot(const Logger *log, struct RTPWorkBufferList *wkbl, const uint8_t slot_id, |
257 | const struct RTPHeader *header, const uint8_t *incoming_data, uint16_t incoming_data_length) | 257 | bool is_keyframe, const struct RTPHeader *header, |
258 | const uint8_t *incoming_data, uint16_t incoming_data_length) | ||
258 | { | 259 | { |
259 | // We're either filling the data into an existing slot, or in a new one that | 260 | // We're either filling the data into an existing slot, or in a new one that |
260 | // is the next free entry. | 261 | // is the next free entry. |
@@ -312,7 +313,7 @@ static bool fill_data_into_slot(Logger *log, struct RTPWorkBufferList *wkbl, con | |||
312 | return slot->received_len == header->data_length_full; | 313 | return slot->received_len == header->data_length_full; |
313 | } | 314 | } |
314 | 315 | ||
315 | static void update_bwc_values(Logger *log, RTPSession *session, const struct RTPMessage *msg) | 316 | static void update_bwc_values(const Logger *log, RTPSession *session, const struct RTPMessage *msg) |
316 | { | 317 | { |
317 | if (session->first_packets_counter < DISMISS_FIRST_LOST_VIDEO_PACKET_COUNT) { | 318 | if (session->first_packets_counter < DISMISS_FIRST_LOST_VIDEO_PACKET_COUNT) { |
318 | session->first_packets_counter++; | 319 | session->first_packets_counter++; |
@@ -348,7 +349,7 @@ static void update_bwc_values(Logger *log, RTPSession *session, const struct RTP | |||
348 | * @return -1 on error, 0 on success. | 349 | * @return -1 on error, 0 on success. |
349 | */ | 350 | */ |
350 | static int handle_video_packet(RTPSession *session, const struct RTPHeader *header, | 351 | static int handle_video_packet(RTPSession *session, const struct RTPHeader *header, |
351 | const uint8_t *incoming_data, uint16_t incoming_data_length, Logger *log) | 352 | const uint8_t *incoming_data, uint16_t incoming_data_length, const Logger *log) |
352 | { | 353 | { |
353 | // Full frame length in bytes. The frame may be split into multiple packets, | 354 | // Full frame length in bytes. The frame may be split into multiple packets, |
354 | // but this value is the complete assembled frame size. | 355 | // but this value is the complete assembled frame size. |
@@ -738,7 +739,7 @@ int rtp_stop_receiving(RTPSession *session) | |||
738 | * @param length is the length of the raw data. | 739 | * @param length is the length of the raw data. |
739 | */ | 740 | */ |
740 | int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length, | 741 | int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length, |
741 | bool is_keyframe, Logger *log) | 742 | bool is_keyframe, const Logger *log) |
742 | { | 743 | { |
743 | if (!session) { | 744 | if (!session) { |
744 | LOGGER_ERROR(log, "No session!"); | 745 | LOGGER_ERROR(log, "No session!"); |
diff --git a/toxav/rtp.h b/toxav/rtp.h index a310d58a..d7fc5560 100644 --- a/toxav/rtp.h +++ b/toxav/rtp.h | |||
@@ -213,7 +213,7 @@ int rtp_stop_receiving(RTPSession *session); | |||
213 | * audio frame, this parameter is ignored. | 213 | * audio frame, this parameter is ignored. |
214 | */ | 214 | */ |
215 | int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length, | 215 | int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length, |
216 | bool is_keyframe, Logger *log); | 216 | bool is_keyframe, const Logger *log); |
217 | 217 | ||
218 | #ifdef __cplusplus | 218 | #ifdef __cplusplus |
219 | } // extern "C" | 219 | } // extern "C" |
diff --git a/toxav/video.c b/toxav/video.c index 8c31cf75..1126b8e6 100644 --- a/toxav/video.c +++ b/toxav/video.c | |||
@@ -83,7 +83,7 @@ | |||
83 | #define VPX_MAX_DECODER_THREADS 4 | 83 | #define VPX_MAX_DECODER_THREADS 4 |
84 | #define VIDEO__VP8_DECODER_POST_PROCESSING_ENABLED 0 | 84 | #define VIDEO__VP8_DECODER_POST_PROCESSING_ENABLED 0 |
85 | 85 | ||
86 | static void vc_init_encoder_cfg(Logger *log, vpx_codec_enc_cfg_t *cfg, int16_t kf_max_dist) | 86 | static void vc_init_encoder_cfg(const Logger *log, vpx_codec_enc_cfg_t *cfg, int16_t kf_max_dist) |
87 | { | 87 | { |
88 | vpx_codec_err_t rc = vpx_codec_enc_config_default(VIDEO_CODEC_ENCODER_INTERFACE, cfg, 0); | 88 | vpx_codec_err_t rc = vpx_codec_enc_config_default(VIDEO_CODEC_ENCODER_INTERFACE, cfg, 0); |
89 | 89 | ||
@@ -152,7 +152,7 @@ static void vc_init_encoder_cfg(Logger *log, vpx_codec_enc_cfg_t *cfg, int16_t k | |||
152 | #endif | 152 | #endif |
153 | } | 153 | } |
154 | 154 | ||
155 | VCSession *vc_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_cb *cb, void *cb_data) | 155 | VCSession *vc_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_cb *cb, void *cb_data) |
156 | { | 156 | { |
157 | VCSession *vc = (VCSession *)calloc(sizeof(VCSession), 1); | 157 | VCSession *vc = (VCSession *)calloc(sizeof(VCSession), 1); |
158 | vpx_codec_err_t rc; | 158 | vpx_codec_err_t rc; |
diff --git a/toxav/video.h b/toxav/video.h index 85ad3129..616a866a 100644 --- a/toxav/video.h +++ b/toxav/video.h | |||
@@ -50,7 +50,7 @@ typedef struct VCSession_s { | |||
50 | uint64_t linfts; /* Last received frame time stamp */ | 50 | uint64_t linfts; /* Last received frame time stamp */ |
51 | uint32_t lcfd; /* Last calculated frame duration for incoming video payload */ | 51 | uint32_t lcfd; /* Last calculated frame duration for incoming video payload */ |
52 | 52 | ||
53 | Logger *log; | 53 | const Logger *log; |
54 | ToxAV *av; | 54 | ToxAV *av; |
55 | uint32_t friend_number; | 55 | uint32_t friend_number; |
56 | 56 | ||
@@ -59,7 +59,8 @@ typedef struct VCSession_s { | |||
59 | pthread_mutex_t queue_mutex[1]; | 59 | pthread_mutex_t queue_mutex[1]; |
60 | } VCSession; | 60 | } VCSession; |
61 | 61 | ||
62 | VCSession *vc_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_cb *cb, void *cb_data); | 62 | VCSession *vc_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_cb *cb, |
63 | void *cb_data); | ||
63 | void vc_kill(VCSession *vc); | 64 | void vc_kill(VCSession *vc); |
64 | void vc_iterate(VCSession *vc); | 65 | void vc_iterate(VCSession *vc); |
65 | int vc_queue_message(void *vcp, struct RTPMessage *msg); | 66 | int vc_queue_message(void *vcp, struct RTPMessage *msg); |
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 6134f59b..bb996e2d 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -85,7 +85,7 @@ struct DHT_Friend { | |||
85 | }; | 85 | }; |
86 | 86 | ||
87 | struct DHT { | 87 | struct DHT { |
88 | Logger *log; | 88 | const Logger *log; |
89 | Networking_Core *net; | 89 | Networking_Core *net; |
90 | 90 | ||
91 | bool hole_punching_enabled; | 91 | bool hole_punching_enabled; |
@@ -658,7 +658,7 @@ static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size, | |||
658 | 658 | ||
659 | /* Update ip_port of client if it's needed. | 659 | /* Update ip_port of client if it's needed. |
660 | */ | 660 | */ |
661 | static void update_client(Logger *log, int index, Client_data *client, IP_Port ip_port) | 661 | static void update_client(const Logger *log, int index, Client_data *client, IP_Port ip_port) |
662 | { | 662 | { |
663 | IPPTsPng *assoc; | 663 | IPPTsPng *assoc; |
664 | int ip_version; | 664 | int ip_version; |
@@ -698,7 +698,7 @@ static void update_client(Logger *log, int index, Client_data *client, IP_Port i | |||
698 | * | 698 | * |
699 | * return True(1) or False(0) | 699 | * return True(1) or False(0) |
700 | */ | 700 | */ |
701 | static int client_or_ip_port_in_list(Logger *log, Client_data *list, uint16_t length, const uint8_t *public_key, | 701 | static int client_or_ip_port_in_list(const Logger *log, Client_data *list, uint16_t length, const uint8_t *public_key, |
702 | IP_Port ip_port) | 702 | IP_Port ip_port) |
703 | { | 703 | { |
704 | const uint64_t temp_time = unix_time(); | 704 | const uint64_t temp_time = unix_time(); |
@@ -2673,7 +2673,7 @@ static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *pack | |||
2673 | 2673 | ||
2674 | /*----------------------------------------------------------------------------------*/ | 2674 | /*----------------------------------------------------------------------------------*/ |
2675 | 2675 | ||
2676 | DHT *new_DHT(Logger *log, Networking_Core *net, bool holepunching_enabled) | 2676 | DHT *new_DHT(const Logger *log, Networking_Core *net, bool holepunching_enabled) |
2677 | { | 2677 | { |
2678 | /* init time */ | 2678 | /* init time */ |
2679 | unix_time_update(); | 2679 | unix_time_update(); |
diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 3ad28d8c..bbfeb307 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h | |||
@@ -405,7 +405,7 @@ void DHT_save(const DHT *dht, uint8_t *data); | |||
405 | int DHT_load(DHT *dht, const uint8_t *data, uint32_t length); | 405 | int DHT_load(DHT *dht, const uint8_t *data, uint32_t length); |
406 | 406 | ||
407 | /* Initialize DHT. */ | 407 | /* Initialize DHT. */ |
408 | DHT *new_DHT(Logger *log, Networking_Core *net, bool holepunching_enabled); | 408 | DHT *new_DHT(const Logger *log, Networking_Core *net, bool holepunching_enabled); |
409 | 409 | ||
410 | void kill_DHT(DHT *dht); | 410 | void kill_DHT(DHT *dht); |
411 | 411 | ||
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index fbf41552..f82cef69 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -130,7 +130,7 @@ typedef struct { | |||
130 | } Crypto_Connection; | 130 | } Crypto_Connection; |
131 | 131 | ||
132 | struct Net_Crypto { | 132 | struct Net_Crypto { |
133 | Logger *log; | 133 | const Logger *log; |
134 | 134 | ||
135 | DHT *dht; | 135 | DHT *dht; |
136 | TCP_Connections *tcp_c; | 136 | TCP_Connections *tcp_c; |
@@ -245,7 +245,7 @@ static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, uint8_t * | |||
245 | * return -1 on failure. | 245 | * return -1 on failure. |
246 | * return 0 on success. | 246 | * return 0 on success. |
247 | */ | 247 | */ |
248 | static int create_cookie(uint8_t *cookie, const uint8_t *bytes, const uint8_t *encryption_key) | 248 | static int create_cookie(const Logger *log, uint8_t *cookie, const uint8_t *bytes, const uint8_t *encryption_key) |
249 | { | 249 | { |
250 | uint8_t contents[COOKIE_CONTENTS_LENGTH]; | 250 | uint8_t contents[COOKIE_CONTENTS_LENGTH]; |
251 | uint64_t temp_time = unix_time(); | 251 | uint64_t temp_time = unix_time(); |
@@ -266,7 +266,7 @@ static int create_cookie(uint8_t *cookie, const uint8_t *bytes, const uint8_t *e | |||
266 | * return -1 on failure. | 266 | * return -1 on failure. |
267 | * return 0 on success. | 267 | * return 0 on success. |
268 | */ | 268 | */ |
269 | static int open_cookie(uint8_t *bytes, const uint8_t *cookie, const uint8_t *encryption_key) | 269 | static int open_cookie(const Logger *log, uint8_t *bytes, const uint8_t *cookie, const uint8_t *encryption_key) |
270 | { | 270 | { |
271 | uint8_t contents[COOKIE_CONTENTS_LENGTH]; | 271 | uint8_t contents[COOKIE_CONTENTS_LENGTH]; |
272 | int len = decrypt_data_symmetric(encryption_key, cookie, cookie + CRYPTO_NONCE_SIZE, | 272 | int len = decrypt_data_symmetric(encryption_key, cookie, cookie + CRYPTO_NONCE_SIZE, |
@@ -304,7 +304,7 @@ static int create_cookie_response(const Net_Crypto *c, uint8_t *packet, const ui | |||
304 | memcpy(cookie_plain + CRYPTO_PUBLIC_KEY_SIZE, dht_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 304 | memcpy(cookie_plain + CRYPTO_PUBLIC_KEY_SIZE, dht_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
305 | uint8_t plain[COOKIE_LENGTH + sizeof(uint64_t)]; | 305 | uint8_t plain[COOKIE_LENGTH + sizeof(uint64_t)]; |
306 | 306 | ||
307 | if (create_cookie(plain, cookie_plain, c->secret_symmetric_key) != 0) { | 307 | if (create_cookie(c->log, plain, cookie_plain, c->secret_symmetric_key) != 0) { |
308 | return -1; | 308 | return -1; |
309 | } | 309 | } |
310 | 310 | ||
@@ -431,7 +431,8 @@ static int tcp_oob_handle_cookie_request(const Net_Crypto *c, unsigned int tcp_c | |||
431 | * return -1 on failure. | 431 | * return -1 on failure. |
432 | * return COOKIE_LENGTH on success. | 432 | * return COOKIE_LENGTH on success. |
433 | */ | 433 | */ |
434 | static int handle_cookie_response(uint8_t *cookie, uint64_t *number, const uint8_t *packet, uint16_t length, | 434 | static int handle_cookie_response(const Logger *log, uint8_t *cookie, uint64_t *number, |
435 | const uint8_t *packet, uint16_t length, | ||
435 | const uint8_t *shared_key) | 436 | const uint8_t *shared_key) |
436 | { | 437 | { |
437 | if (length != COOKIE_RESPONSE_LENGTH) { | 438 | if (length != COOKIE_RESPONSE_LENGTH) { |
@@ -471,7 +472,7 @@ static int create_crypto_handshake(const Net_Crypto *c, uint8_t *packet, const u | |||
471 | memcpy(cookie_plain, peer_real_pk, CRYPTO_PUBLIC_KEY_SIZE); | 472 | memcpy(cookie_plain, peer_real_pk, CRYPTO_PUBLIC_KEY_SIZE); |
472 | memcpy(cookie_plain + CRYPTO_PUBLIC_KEY_SIZE, peer_dht_pubkey, CRYPTO_PUBLIC_KEY_SIZE); | 473 | memcpy(cookie_plain + CRYPTO_PUBLIC_KEY_SIZE, peer_dht_pubkey, CRYPTO_PUBLIC_KEY_SIZE); |
473 | 474 | ||
474 | if (create_cookie(plain + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SHA512_SIZE, cookie_plain, | 475 | if (create_cookie(c->log, plain + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SHA512_SIZE, cookie_plain, |
475 | c->secret_symmetric_key) != 0) { | 476 | c->secret_symmetric_key) != 0) { |
476 | return -1; | 477 | return -1; |
477 | } | 478 | } |
@@ -517,7 +518,7 @@ static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t | |||
517 | 518 | ||
518 | uint8_t cookie_plain[COOKIE_DATA_LENGTH]; | 519 | uint8_t cookie_plain[COOKIE_DATA_LENGTH]; |
519 | 520 | ||
520 | if (open_cookie(cookie_plain, packet + 1, c->secret_symmetric_key) != 0) { | 521 | if (open_cookie(c->log, cookie_plain, packet + 1, c->secret_symmetric_key) != 0) { |
521 | return -1; | 522 | return -1; |
522 | } | 523 | } |
523 | 524 | ||
@@ -724,7 +725,7 @@ static uint32_t num_packets_array(const Packets_Array *array) | |||
724 | * return -1 on failure. | 725 | * return -1 on failure. |
725 | * return 0 on success. | 726 | * return 0 on success. |
726 | */ | 727 | */ |
727 | static int add_data_to_buffer(Packets_Array *array, uint32_t number, const Packet_Data *data) | 728 | static int add_data_to_buffer(const Logger *log, Packets_Array *array, uint32_t number, const Packet_Data *data) |
728 | { | 729 | { |
729 | if (number - array->buffer_start > CRYPTO_PACKET_BUFFER_SIZE) { | 730 | if (number - array->buffer_start > CRYPTO_PACKET_BUFFER_SIZE) { |
730 | return -1; | 731 | return -1; |
@@ -758,7 +759,7 @@ static int add_data_to_buffer(Packets_Array *array, uint32_t number, const Packe | |||
758 | * return 0 if data at number is empty. | 759 | * return 0 if data at number is empty. |
759 | * return 1 if data pointer was put in data. | 760 | * return 1 if data pointer was put in data. |
760 | */ | 761 | */ |
761 | static int get_data_pointer(const Packets_Array *array, Packet_Data **data, uint32_t number) | 762 | static int get_data_pointer(const Logger *log, const Packets_Array *array, Packet_Data **data, uint32_t number) |
762 | { | 763 | { |
763 | uint32_t num_spots = array->buffer_end - array->buffer_start; | 764 | uint32_t num_spots = array->buffer_end - array->buffer_start; |
764 | 765 | ||
@@ -781,7 +782,7 @@ static int get_data_pointer(const Packets_Array *array, Packet_Data **data, uint | |||
781 | * return -1 on failure. | 782 | * return -1 on failure. |
782 | * return packet number on success. | 783 | * return packet number on success. |
783 | */ | 784 | */ |
784 | static int64_t add_data_end_of_buffer(Packets_Array *array, const Packet_Data *data) | 785 | static int64_t add_data_end_of_buffer(const Logger *log, Packets_Array *array, const Packet_Data *data) |
785 | { | 786 | { |
786 | if (num_packets_array(array) >= CRYPTO_PACKET_BUFFER_SIZE) { | 787 | if (num_packets_array(array) >= CRYPTO_PACKET_BUFFER_SIZE) { |
787 | return -1; | 788 | return -1; |
@@ -800,12 +801,12 @@ static int64_t add_data_end_of_buffer(Packets_Array *array, const Packet_Data *d | |||
800 | return id; | 801 | return id; |
801 | } | 802 | } |
802 | 803 | ||
803 | /* Read data from begginning of array. | 804 | /* Read data from beginning of array. |
804 | * | 805 | * |
805 | * return -1 on failure. | 806 | * return -1 on failure. |
806 | * return packet number on success. | 807 | * return packet number on success. |
807 | */ | 808 | */ |
808 | static int64_t read_data_beg_buffer(Packets_Array *array, Packet_Data *data) | 809 | static int64_t read_data_beg_buffer(const Logger *log, Packets_Array *array, Packet_Data *data) |
809 | { | 810 | { |
810 | if (array->buffer_end == array->buffer_start) { | 811 | if (array->buffer_end == array->buffer_start) { |
811 | return -1; | 812 | return -1; |
@@ -830,7 +831,7 @@ static int64_t read_data_beg_buffer(Packets_Array *array, Packet_Data *data) | |||
830 | * return -1 on failure. | 831 | * return -1 on failure. |
831 | * return 0 on success | 832 | * return 0 on success |
832 | */ | 833 | */ |
833 | static int clear_buffer_until(Packets_Array *array, uint32_t number) | 834 | static int clear_buffer_until(const Logger *log, Packets_Array *array, uint32_t number) |
834 | { | 835 | { |
835 | uint32_t num_spots = array->buffer_end - array->buffer_start; | 836 | uint32_t num_spots = array->buffer_end - array->buffer_start; |
836 | 837 | ||
@@ -875,7 +876,7 @@ static int clear_buffer(Packets_Array *array) | |||
875 | * return -1 on failure. | 876 | * return -1 on failure. |
876 | * return 0 on success. | 877 | * return 0 on success. |
877 | */ | 878 | */ |
878 | static int set_buffer_end(Packets_Array *array, uint32_t number) | 879 | static int set_buffer_end(const Logger *log, Packets_Array *array, uint32_t number) |
879 | { | 880 | { |
880 | if ((number - array->buffer_start) > CRYPTO_PACKET_BUFFER_SIZE) { | 881 | if ((number - array->buffer_start) > CRYPTO_PACKET_BUFFER_SIZE) { |
881 | return -1; | 882 | return -1; |
@@ -895,7 +896,7 @@ static int set_buffer_end(Packets_Array *array, uint32_t number) | |||
895 | * return -1 on failure. | 896 | * return -1 on failure. |
896 | * return length of packet on success. | 897 | * return length of packet on success. |
897 | */ | 898 | */ |
898 | static int generate_request_packet(uint8_t *data, uint16_t length, const Packets_Array *recv_array) | 899 | static int generate_request_packet(const Logger *log, uint8_t *data, uint16_t length, const Packets_Array *recv_array) |
899 | { | 900 | { |
900 | if (length == 0) { | 901 | if (length == 0) { |
901 | return -1; | 902 | return -1; |
@@ -948,7 +949,7 @@ static int generate_request_packet(uint8_t *data, uint16_t length, const Packets | |||
948 | * return -1 on failure. | 949 | * return -1 on failure. |
949 | * return number of requested packets on success. | 950 | * return number of requested packets on success. |
950 | */ | 951 | */ |
951 | static int handle_request_packet(Packets_Array *send_array, const uint8_t *data, uint16_t length, | 952 | static int handle_request_packet(const Logger *log, Packets_Array *send_array, const uint8_t *data, uint16_t length, |
952 | uint64_t *latest_send_time, uint64_t rtt_time) | 953 | uint64_t *latest_send_time, uint64_t rtt_time) |
953 | { | 954 | { |
954 | if (length < 1) { | 955 | if (length < 1) { |
@@ -1101,7 +1102,7 @@ static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id) | |||
1101 | if (conn->maximum_speed_reached) { | 1102 | if (conn->maximum_speed_reached) { |
1102 | Packet_Data *dt = nullptr; | 1103 | Packet_Data *dt = nullptr; |
1103 | uint32_t packet_num = conn->send_array.buffer_end - 1; | 1104 | uint32_t packet_num = conn->send_array.buffer_end - 1; |
1104 | int ret = get_data_pointer(&conn->send_array, &dt, packet_num); | 1105 | int ret = get_data_pointer(c->log, &conn->send_array, &dt, packet_num); |
1105 | 1106 | ||
1106 | uint8_t send_failed = 0; | 1107 | uint8_t send_failed = 0; |
1107 | 1108 | ||
@@ -1155,7 +1156,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons | |||
1155 | dt.length = length; | 1156 | dt.length = length; |
1156 | memcpy(dt.data, data, length); | 1157 | memcpy(dt.data, data, length); |
1157 | pthread_mutex_lock(&conn->mutex); | 1158 | pthread_mutex_lock(&conn->mutex); |
1158 | int64_t packet_num = add_data_end_of_buffer(&conn->send_array, &dt); | 1159 | int64_t packet_num = add_data_end_of_buffer(c->log, &conn->send_array, &dt); |
1159 | pthread_mutex_unlock(&conn->mutex); | 1160 | pthread_mutex_unlock(&conn->mutex); |
1160 | 1161 | ||
1161 | if (packet_num == -1) { | 1162 | if (packet_num == -1) { |
@@ -1169,7 +1170,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons | |||
1169 | if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, data, length) == 0) { | 1170 | if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, data, length) == 0) { |
1170 | Packet_Data *dt1 = nullptr; | 1171 | Packet_Data *dt1 = nullptr; |
1171 | 1172 | ||
1172 | if (get_data_pointer(&conn->send_array, &dt1, packet_num) == 1) { | 1173 | if (get_data_pointer(c->log, &conn->send_array, &dt1, packet_num) == 1) { |
1173 | dt1->sent_time = current_time_monotonic(); | 1174 | dt1->sent_time = current_time_monotonic(); |
1174 | } | 1175 | } |
1175 | } else { | 1176 | } else { |
@@ -1248,7 +1249,7 @@ static int send_request_packet(Net_Crypto *c, int crypt_connection_id) | |||
1248 | } | 1249 | } |
1249 | 1250 | ||
1250 | uint8_t data[MAX_CRYPTO_DATA_SIZE]; | 1251 | uint8_t data[MAX_CRYPTO_DATA_SIZE]; |
1251 | int len = generate_request_packet(data, sizeof(data), &conn->recv_array); | 1252 | int len = generate_request_packet(c->log, data, sizeof(data), &conn->recv_array); |
1252 | 1253 | ||
1253 | if (len == -1) { | 1254 | if (len == -1) { |
1254 | return -1; | 1255 | return -1; |
@@ -1281,7 +1282,7 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32 | |||
1281 | for (i = 0; i < array_size; ++i) { | 1282 | for (i = 0; i < array_size; ++i) { |
1282 | Packet_Data *dt; | 1283 | Packet_Data *dt; |
1283 | uint32_t packet_num = (i + conn->send_array.buffer_start); | 1284 | uint32_t packet_num = (i + conn->send_array.buffer_start); |
1284 | int ret = get_data_pointer(&conn->send_array, &dt, packet_num); | 1285 | int ret = get_data_pointer(c->log, &conn->send_array, &dt, packet_num); |
1285 | 1286 | ||
1286 | if (ret == -1) { | 1287 | if (ret == -1) { |
1287 | return -1; | 1288 | return -1; |
@@ -1496,11 +1497,11 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const | |||
1496 | if (buffer_start != conn->send_array.buffer_start) { | 1497 | if (buffer_start != conn->send_array.buffer_start) { |
1497 | Packet_Data *packet_time; | 1498 | Packet_Data *packet_time; |
1498 | 1499 | ||
1499 | if (get_data_pointer(&conn->send_array, &packet_time, conn->send_array.buffer_start) == 1) { | 1500 | if (get_data_pointer(c->log, &conn->send_array, &packet_time, conn->send_array.buffer_start) == 1) { |
1500 | rtt_calc_time = packet_time->sent_time; | 1501 | rtt_calc_time = packet_time->sent_time; |
1501 | } | 1502 | } |
1502 | 1503 | ||
1503 | if (clear_buffer_until(&conn->send_array, buffer_start) != 0) { | 1504 | if (clear_buffer_until(c->log, &conn->send_array, buffer_start) != 0) { |
1504 | return -1; | 1505 | return -1; |
1505 | } | 1506 | } |
1506 | } | 1507 | } |
@@ -1541,25 +1542,25 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const | |||
1541 | rtt_time = DEFAULT_TCP_PING_CONNECTION; | 1542 | rtt_time = DEFAULT_TCP_PING_CONNECTION; |
1542 | } | 1543 | } |
1543 | 1544 | ||
1544 | int requested = handle_request_packet(&conn->send_array, real_data, real_length, &rtt_calc_time, rtt_time); | 1545 | int requested = handle_request_packet(c->log, &conn->send_array, real_data, real_length, &rtt_calc_time, rtt_time); |
1545 | 1546 | ||
1546 | if (requested == -1) { | 1547 | if (requested == -1) { |
1547 | return -1; | 1548 | return -1; |
1548 | } | 1549 | } |
1549 | 1550 | ||
1550 | set_buffer_end(&conn->recv_array, num); | 1551 | set_buffer_end(c->log, &conn->recv_array, num); |
1551 | } else if (real_data[0] >= CRYPTO_RESERVED_PACKETS && real_data[0] < PACKET_ID_LOSSY_RANGE_START) { | 1552 | } else if (real_data[0] >= CRYPTO_RESERVED_PACKETS && real_data[0] < PACKET_ID_LOSSY_RANGE_START) { |
1552 | Packet_Data dt; | 1553 | Packet_Data dt = {0}; |
1553 | dt.length = real_length; | 1554 | dt.length = real_length; |
1554 | memcpy(dt.data, real_data, real_length); | 1555 | memcpy(dt.data, real_data, real_length); |
1555 | 1556 | ||
1556 | if (add_data_to_buffer(&conn->recv_array, num, &dt) != 0) { | 1557 | if (add_data_to_buffer(c->log, &conn->recv_array, num, &dt) != 0) { |
1557 | return -1; | 1558 | return -1; |
1558 | } | 1559 | } |
1559 | 1560 | ||
1560 | while (1) { | 1561 | while (1) { |
1561 | pthread_mutex_lock(&conn->mutex); | 1562 | pthread_mutex_lock(&conn->mutex); |
1562 | int ret = read_data_beg_buffer(&conn->recv_array, &dt); | 1563 | int ret = read_data_beg_buffer(c->log, &conn->recv_array, &dt); |
1563 | pthread_mutex_unlock(&conn->mutex); | 1564 | pthread_mutex_unlock(&conn->mutex); |
1564 | 1565 | ||
1565 | if (ret == -1) { | 1566 | if (ret == -1) { |
@@ -1584,7 +1585,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const | |||
1584 | } else if (real_data[0] >= PACKET_ID_LOSSY_RANGE_START && | 1585 | } else if (real_data[0] >= PACKET_ID_LOSSY_RANGE_START && |
1585 | real_data[0] < (PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE)) { | 1586 | real_data[0] < (PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE)) { |
1586 | 1587 | ||
1587 | set_buffer_end(&conn->recv_array, num); | 1588 | set_buffer_end(c->log, &conn->recv_array, num); |
1588 | 1589 | ||
1589 | if (conn->connection_lossy_data_callback) { | 1590 | if (conn->connection_lossy_data_callback) { |
1590 | conn->connection_lossy_data_callback(conn->connection_lossy_data_callback_object, | 1591 | conn->connection_lossy_data_callback(conn->connection_lossy_data_callback_object, |
@@ -1632,7 +1633,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons | |||
1632 | uint8_t cookie[COOKIE_LENGTH]; | 1633 | uint8_t cookie[COOKIE_LENGTH]; |
1633 | uint64_t number; | 1634 | uint64_t number; |
1634 | 1635 | ||
1635 | if (handle_cookie_response(cookie, &number, packet, length, conn->shared_key) != sizeof(cookie)) { | 1636 | if (handle_cookie_response(c->log, cookie, &number, packet, length, conn->shared_key) != sizeof(cookie)) { |
1636 | return -1; | 1637 | return -1; |
1637 | } | 1638 | } |
1638 | 1639 | ||
@@ -2928,7 +2929,7 @@ void load_secret_key(Net_Crypto *c, const uint8_t *sk) | |||
2928 | /* Run this to (re)initialize net_crypto. | 2929 | /* Run this to (re)initialize net_crypto. |
2929 | * Sets all the global connection variables to their default values. | 2930 | * Sets all the global connection variables to their default values. |
2930 | */ | 2931 | */ |
2931 | Net_Crypto *new_net_crypto(Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info) | 2932 | Net_Crypto *new_net_crypto(const Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info) |
2932 | { | 2933 | { |
2933 | unix_time_update(); | 2934 | unix_time_update(); |
2934 | 2935 | ||
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index f6b2648e..2a76013e 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h | |||
@@ -299,7 +299,7 @@ void load_secret_key(Net_Crypto *c, const uint8_t *sk); | |||
299 | /* Create new instance of Net_Crypto. | 299 | /* Create new instance of Net_Crypto. |
300 | * Sets all the global connection variables to their default values. | 300 | * Sets all the global connection variables to their default values. |
301 | */ | 301 | */ |
302 | Net_Crypto *new_net_crypto(Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info); | 302 | Net_Crypto *new_net_crypto(const Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info); |
303 | 303 | ||
304 | /* return the optimal interval in ms for running do_net_crypto. | 304 | /* return the optimal interval in ms for running do_net_crypto. |
305 | */ | 305 | */ |
diff --git a/toxcore/network.c b/toxcore/network.c index 44ca2dee..30c3bb6c 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -495,7 +495,7 @@ static uint32_t data_1(uint16_t buflen, const uint8_t *buffer) | |||
495 | return buflen > 7 ? net_ntohl(*(const uint32_t *)&buffer[5]) : 0; | 495 | return buflen > 7 ? net_ntohl(*(const uint32_t *)&buffer[5]) : 0; |
496 | } | 496 | } |
497 | 497 | ||
498 | static void loglogdata(Logger *log, const char *message, const uint8_t *buffer, | 498 | static void loglogdata(const Logger *log, const char *message, const uint8_t *buffer, |
499 | uint16_t buflen, IP_Port ip_port, int res) | 499 | uint16_t buflen, IP_Port ip_port, int res) |
500 | { | 500 | { |
501 | char ip_str[IP_NTOA_LEN]; | 501 | char ip_str[IP_NTOA_LEN]; |
@@ -527,7 +527,7 @@ typedef struct { | |||
527 | } Packet_Handler; | 527 | } Packet_Handler; |
528 | 528 | ||
529 | struct Networking_Core { | 529 | struct Networking_Core { |
530 | Logger *log; | 530 | const Logger *log; |
531 | Packet_Handler packethandlers[256]; | 531 | Packet_Handler packethandlers[256]; |
532 | 532 | ||
533 | Family family; | 533 | Family family; |
@@ -616,7 +616,7 @@ int sendpacket(Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint1 | |||
616 | * Packet data is put into data. | 616 | * Packet data is put into data. |
617 | * Packet length is put into length. | 617 | * Packet length is put into length. |
618 | */ | 618 | */ |
619 | static int receivepacket(Logger *log, Socket sock, IP_Port *ip_port, uint8_t *data, uint32_t *length) | 619 | static int receivepacket(const Logger *log, Socket sock, IP_Port *ip_port, uint8_t *data, uint32_t *length) |
620 | { | 620 | { |
621 | memset(ip_port, 0, sizeof(IP_Port)); | 621 | memset(ip_port, 0, sizeof(IP_Port)); |
622 | struct sockaddr_storage addr; | 622 | struct sockaddr_storage addr; |
@@ -766,7 +766,7 @@ static void at_shutdown(void) | |||
766 | /* Initialize networking. | 766 | /* Initialize networking. |
767 | * Added for reverse compatibility with old new_networking calls. | 767 | * Added for reverse compatibility with old new_networking calls. |
768 | */ | 768 | */ |
769 | Networking_Core *new_networking(Logger *log, IP ip, uint16_t port) | 769 | Networking_Core *new_networking(const Logger *log, IP ip, uint16_t port) |
770 | { | 770 | { |
771 | return new_networking_ex(log, ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), nullptr); | 771 | return new_networking_ex(log, ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), nullptr); |
772 | } | 772 | } |
@@ -781,7 +781,7 @@ Networking_Core *new_networking(Logger *log, IP ip, uint16_t port) | |||
781 | * | 781 | * |
782 | * If error is non NULL it is set to 0 if no issues, 1 if socket related error, 2 if other. | 782 | * If error is non NULL it is set to 0 if no issues, 1 if socket related error, 2 if other. |
783 | */ | 783 | */ |
784 | Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint16_t port_to, unsigned int *error) | 784 | Networking_Core *new_networking_ex(const Logger *log, IP ip, uint16_t port_from, uint16_t port_to, unsigned int *error) |
785 | { | 785 | { |
786 | /* If both from and to are 0, use default port range | 786 | /* If both from and to are 0, use default port range |
787 | * If one is 0 and the other is non-0, use the non-0 value as only port | 787 | * If one is 0 and the other is non-0, use the non-0 value as only port |
@@ -996,7 +996,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1 | |||
996 | return nullptr; | 996 | return nullptr; |
997 | } | 997 | } |
998 | 998 | ||
999 | Networking_Core *new_networking_no_udp(Logger *log) | 999 | Networking_Core *new_networking_no_udp(const Logger *log) |
1000 | { | 1000 | { |
1001 | /* this is the easiest way to completely disable UDP without changing too much code. */ | 1001 | /* this is the easiest way to completely disable UDP without changing too much code. */ |
1002 | Networking_Core *net = (Networking_Core *)calloc(1, sizeof(Networking_Core)); | 1002 | Networking_Core *net = (Networking_Core *)calloc(1, sizeof(Networking_Core)); |
diff --git a/toxcore/network.h b/toxcore/network.h index 8071375b..fbd12bb7 100644 --- a/toxcore/network.h +++ b/toxcore/network.h | |||
@@ -458,9 +458,9 @@ void net_kill_strerror(const char *strerror); | |||
458 | * | 458 | * |
459 | * If error is non NULL it is set to 0 if no issues, 1 if socket related error, 2 if other. | 459 | * If error is non NULL it is set to 0 if no issues, 1 if socket related error, 2 if other. |
460 | */ | 460 | */ |
461 | Networking_Core *new_networking(Logger *log, IP ip, uint16_t port); | 461 | Networking_Core *new_networking(const Logger *log, IP ip, uint16_t port); |
462 | Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint16_t port_to, unsigned int *error); | 462 | Networking_Core *new_networking_ex(const Logger *log, IP ip, uint16_t port_from, uint16_t port_to, unsigned int *error); |
463 | Networking_Core *new_networking_no_udp(Logger *log); | 463 | Networking_Core *new_networking_no_udp(const Logger *log); |
464 | 464 | ||
465 | /* Function to cleanup networking stuff (doesn't do much right now). */ | 465 | /* Function to cleanup networking stuff (doesn't do much right now). */ |
466 | void kill_networking(Networking_Core *net); | 466 | void kill_networking(Networking_Core *net); |
diff --git a/toxcore/util.c b/toxcore/util.c index 082e453f..57d1762e 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -122,7 +122,7 @@ void lendian_to_host32(uint32_t *dest, const uint8_t *lendian) | |||
122 | } | 122 | } |
123 | 123 | ||
124 | /* state load/save */ | 124 | /* state load/save */ |
125 | int load_state(load_state_callback_func load_state_callback, Logger *log, void *outer, | 125 | int load_state(load_state_callback_func load_state_callback, const Logger *log, void *outer, |
126 | const uint8_t *data, uint32_t length, uint16_t cookie_inner) | 126 | const uint8_t *data, uint32_t length, uint16_t cookie_inner) |
127 | { | 127 | { |
128 | if (!load_state_callback || !data) { | 128 | if (!load_state_callback || !data) { |
diff --git a/toxcore/util.h b/toxcore/util.h index a9faa863..3979cefe 100644 --- a/toxcore/util.h +++ b/toxcore/util.h | |||
@@ -59,7 +59,7 @@ void lendian_to_host32(uint32_t *dest, const uint8_t *lendian); | |||
59 | 59 | ||
60 | /* state load/save */ | 60 | /* state load/save */ |
61 | typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type); | 61 | typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type); |
62 | int load_state(load_state_callback_func load_state_callback, Logger *log, void *outer, | 62 | int load_state(load_state_callback_func load_state_callback, const Logger *log, void *outer, |
63 | const uint8_t *data, uint32_t length, uint16_t cookie_inner); | 63 | const uint8_t *data, uint32_t length, uint16_t cookie_inner); |
64 | 64 | ||
65 | /* Returns -1 if failed or 0 if success */ | 65 | /* Returns -1 if failed or 0 if success */ |