From f96d0dd19d176c1fbc10a3d5b3c992b307919384 Mon Sep 17 00:00:00 2001 From: iphydf Date: Wed, 15 Jan 2025 12:27:57 +0000 Subject: [PATCH] cleanup: Some random cleanups, mostly related to mem. --- auto_tests/proxy_test.c | 2 +- toxav/audio.c | 2 +- toxav/audio.h | 2 +- toxav/rtp.c | 2 +- toxav/rtp.h | 2 +- toxav/toxav.c | 5 ++--- toxav/video.c | 4 +--- toxav/video.h | 2 +- toxcore/Messenger.c | 4 ++-- toxcore/group.c | 14 +++++++------- toxcore/group.h | 3 ++- toxcore/group_chats.c | 6 +++--- toxcore/group_moderation.c | 1 - toxcore/group_onion_announce.h | 8 ++++---- toxcore/list.c | 2 +- toxcore/logger.c | 2 ++ toxcore/mem.c | 6 ++++++ toxcore/mem.h | 8 ++++++++ toxcore/mono_time.c | 2 +- toxcore/mono_time.h | 2 +- toxcore/net_crypto.c | 33 +++++++++++++++++---------------- toxcore/net_crypto.h | 9 +++------ toxcore/tox.c | 2 +- 23 files changed, 67 insertions(+), 56 deletions(-) diff --git a/auto_tests/proxy_test.c b/auto_tests/proxy_test.c index d20c14f237..66d6bc9b26 100644 --- a/auto_tests/proxy_test.c +++ b/auto_tests/proxy_test.c @@ -1,9 +1,9 @@ /* Tests that we can send messages to friends. */ +#include #include #include -#include #include "auto_test_support.h" diff --git a/toxav/audio.c b/toxav/audio.c index 083fc7e52d..59c8a71d26 100644 --- a/toxav/audio.c +++ b/toxav/audio.c @@ -195,7 +195,7 @@ void ac_iterate(ACSession *ac) free(temp_audio_buffer); } -int ac_queue_message(Mono_Time *mono_time, void *cs, struct RTPMessage *msg) +int ac_queue_message(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg) { ACSession *ac = (ACSession *)cs; diff --git a/toxav/audio.h b/toxav/audio.h index 284cd82590..ce8b3aff80 100644 --- a/toxav/audio.h +++ b/toxav/audio.h @@ -67,7 +67,7 @@ ACSession *ac_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t f toxav_audio_receive_frame_cb *cb, void *cb_data); void ac_kill(ACSession *ac); void ac_iterate(ACSession *ac); -int ac_queue_message(Mono_Time *mono_time, void *cs, struct RTPMessage *msg); +int ac_queue_message(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg); int ac_reconfigure_encoder(ACSession *ac, uint32_t bit_rate, uint32_t sampling_rate, uint8_t channels); #endif /* C_TOXCORE_TOXAV_AUDIO_H */ diff --git a/toxav/rtp.c b/toxav/rtp.c index ef7efaa654..dd955d0586 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c @@ -823,7 +823,7 @@ static struct RTPHeader rtp_default_header(const RTPSession *session, uint32_t l header.ma = 0; header.pt = session->payload_type % 128; header.sequnum = session->sequnum; - Mono_Time *mt = toxav_get_av_mono_time(session->toxav); + const Mono_Time *mt = toxav_get_av_mono_time(session->toxav); if (mt != nullptr) { header.timestamp = current_time_monotonic(mt); } else { diff --git a/toxav/rtp.h b/toxav/rtp.h index 74676c28eb..1668a54aeb 100644 --- a/toxav/rtp.h +++ b/toxav/rtp.h @@ -147,7 +147,7 @@ struct RTPWorkBufferList { #define DISMISS_FIRST_LOST_VIDEO_PACKET_COUNT 10 -typedef int rtp_m_cb(Mono_Time *mono_time, void *cs, struct RTPMessage *msg); +typedef int rtp_m_cb(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg); /** * RTP control session. diff --git a/toxav/toxav.c b/toxav/toxav.c index 18af5745bc..b69ce151f3 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -5,7 +5,6 @@ #include "toxav.h" #include -#include #include #include #include @@ -21,7 +20,7 @@ #include "../toxcore/network.h" #include "../toxcore/tox.h" #include "../toxcore/tox_private.h" -#include "../toxcore/tox_struct.h" +#include "../toxcore/tox_struct.h" // IWYU pragma: keep #include "../toxcore/util.h" // TODO(zoff99): don't hardcode this, let the application choose it @@ -342,7 +341,7 @@ uint32_t toxav_iteration_interval(const ToxAV *av) * @param frame_time the duration of the current frame in ms * @param start_time the timestamp when decoding of this frame started */ -static void calc_interval(ToxAV *av, DecodeTimeStats *stats, int32_t frame_time, uint64_t start_time) +static void calc_interval(const ToxAV *av, DecodeTimeStats *stats, int32_t frame_time, uint64_t start_time) { stats->interval = frame_time < stats->average ? 0 : (frame_time - stats->average); stats->total += current_time_monotonic(av->toxav_mono_time) - start_time; diff --git a/toxav/video.c b/toxav/video.c index 66fa037d70..4544873a05 100644 --- a/toxav/video.c +++ b/toxav/video.c @@ -8,14 +8,12 @@ #include #include -#include "msi.h" #include "ring_buffer.h" #include "rtp.h" #include "../toxcore/ccompat.h" #include "../toxcore/logger.h" #include "../toxcore/mono_time.h" -#include "../toxcore/network.h" /** * Soft deadline the decoder should attempt to meet, in "us" (microseconds). @@ -346,7 +344,7 @@ void vc_iterate(VCSession *vc) } } -int vc_queue_message(Mono_Time *mono_time, void *cs, struct RTPMessage *msg) +int vc_queue_message(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg) { VCSession *vc = (VCSession *)cs; diff --git a/toxav/video.h b/toxav/video.h index 7e30a626f7..26e5ed6280 100644 --- a/toxav/video.h +++ b/toxav/video.h @@ -48,7 +48,7 @@ VCSession *vc_new(const Logger *log, Mono_Time *mono_time, ToxAV *av, uint32_t f toxav_video_receive_frame_cb *cb, void *cb_data); void vc_kill(VCSession *vc); void vc_iterate(VCSession *vc); -int vc_queue_message(Mono_Time *mono_time, void *cs, struct RTPMessage *msg); +int vc_queue_message(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg); int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uint16_t height, int16_t kf_max_dist); #endif /* C_TOXCORE_TOXAV_VIDEO_H */ diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 788147b5f0..e7f8ee9cee 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -137,7 +137,7 @@ void getaddress(const Messenger *m, uint8_t *address) } non_null() -static bool send_online_packet(Messenger *m, int friendcon_id) +static bool send_online_packet(const Messenger *m, int friendcon_id) { const uint8_t packet[1] = {PACKET_ID_ONLINE}; return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet, @@ -145,7 +145,7 @@ static bool send_online_packet(Messenger *m, int friendcon_id) } non_null() -static bool send_offline_packet(Messenger *m, int friendcon_id) +static bool send_offline_packet(const Messenger *m, int friendcon_id) { const uint8_t packet[1] = {PACKET_ID_OFFLINE}; return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet, diff --git a/toxcore/group.c b/toxcore/group.c index 67189ceef6..dbc3876403 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -248,7 +248,7 @@ static bool is_groupnumber_valid(const Group_Chats *g_c, uint32_t groupnumber) /** @brief Set the size of the groupchat list to num. * - * @retval false if realloc fails. + * @retval false if mem_vrealloc fails. * @retval true if it succeeds. */ non_null() @@ -1067,7 +1067,7 @@ static bool freeze_peer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, return false; } - Group_Peer *temp = (Group_Peer *)mem_vrealloc(g_c->m->mem, g->frozen, g->numfrozen + 1, sizeof(Group_Peer)); + Group_Peer *temp = (Group_Peer *)mem_vrealloc(g_c->mem, g->frozen, g->numfrozen + 1, sizeof(Group_Peer)); if (temp == nullptr) { return false; @@ -1085,7 +1085,7 @@ static bool freeze_peer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, ++g->numfrozen; - delete_old_frozen(g, g_c->m->mem); + delete_old_frozen(g, g_c->mem); return true; } @@ -1572,7 +1572,7 @@ int group_set_max_frozen(const Group_Chats *g_c, uint32_t groupnumber, uint32_t } g->maxfrozen = maxfrozen; - delete_old_frozen(g, g_c->m->mem); + delete_old_frozen(g, g_c->mem); return 0; } @@ -3805,19 +3805,19 @@ bool conferences_load_state_section(Group_Chats *g_c, const uint8_t *data, uint3 } /** Create new groupchat instance. */ -Group_Chats *new_groupchats(const Mono_Time *mono_time, Messenger *m) +Group_Chats *new_groupchats(const Mono_Time *mono_time, const Memory *mem, Messenger *m) { if (m == nullptr) { return nullptr; } - Group_Chats *temp = (Group_Chats *)mem_alloc(m->mem, sizeof(Group_Chats)); + Group_Chats *temp = (Group_Chats *)mem_alloc(mem, sizeof(Group_Chats)); if (temp == nullptr) { return nullptr; } - temp->mem = m->mem; + temp->mem = mem; temp->mono_time = mono_time; temp->m = m; temp->fr_c = m->fr_c; diff --git a/toxcore/group.h b/toxcore/group.h index f21ac09b51..706428fdda 100644 --- a/toxcore/group.h +++ b/toxcore/group.h @@ -15,6 +15,7 @@ #include "Messenger.h" #include "attributes.h" #include "crypto_core.h" +#include "mem.h" #include "mono_time.h" #include "state.h" @@ -390,7 +391,7 @@ bool conferences_load_state_section( /** Create new groupchat instance. */ non_null() -Group_Chats *new_groupchats(const Mono_Time *mono_time, Messenger *m); +Group_Chats *new_groupchats(const Mono_Time *mono_time, const Memory *mem, Messenger *m); /** main groupchats loop. */ non_null(1) nullable(2) diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index 6b0271644f..a364ac938c 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c @@ -2736,7 +2736,7 @@ static bool send_gc_peer_exchange(const GC_Chat *chat, GC_Connection *gconn) * Return -5 if supplied group password is invalid. * Return -6 if we fail to add the peer to the peer list. * Return -7 if peer's role cannot be validated. - * Return -8 if malloc fails. + * Return -8 if memory allocation fails. */ non_null(1, 2, 4) nullable(6) static int handle_gc_peer_info_response(const GC_Session *c, GC_Chat *chat, uint32_t peer_number, @@ -5534,7 +5534,7 @@ static int unwrap_group_handshake_packet(const Logger *log, const Memory *mem, c * * Return length of encrypted packet on success. * Return -1 if packet size is invalid. - * Return -2 on malloc failure. + * Return -2 on memory allocation failure. * Return -3 if encryption fails. */ non_null() @@ -6825,7 +6825,7 @@ int peer_add(GC_Chat *chat, const IP_Port *ipp, const uint8_t *public_key) GC_Peer *tmp_group = (GC_Peer *)mem_vrealloc(chat->mem, chat->group, chat->numpeers + 1, sizeof(GC_Peer)); if (tmp_group == nullptr) { - LOGGER_ERROR(chat->log, "Failed to allocate memory for group realloc"); + LOGGER_ERROR(chat->log, "Failed to allocate memory for group mem_vrealloc"); if (tcp_connection_num != -1) { kill_tcp_connection_to(chat->tcp_conn, tcp_connection_num); diff --git a/toxcore/group_moderation.c b/toxcore/group_moderation.c index 6c79da44b7..acc17bd570 100644 --- a/toxcore/group_moderation.c +++ b/toxcore/group_moderation.c @@ -11,7 +11,6 @@ #include - #include #include diff --git a/toxcore/group_onion_announce.h b/toxcore/group_onion_announce.h index bc9edb109a..8abff63795 100644 --- a/toxcore/group_onion_announce.h +++ b/toxcore/group_onion_announce.h @@ -17,9 +17,9 @@ void gca_onion_init(GC_Announces_List *group_announce, Onion_Announce *onion_a); non_null() int create_gca_announce_request( - const Memory *mem, const Random *rng, uint8_t *packet, uint16_t max_packet_length, const uint8_t *dest_client_id, - const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *ping_id, - const uint8_t *client_id, const uint8_t *data_public_key, uint64_t sendback_data, - const uint8_t *gc_data, uint16_t gc_data_length); + const Memory *mem, const Random *rng, uint8_t *packet, uint16_t max_packet_length, + const uint8_t *dest_client_id, const uint8_t *public_key, const uint8_t *secret_key, + const uint8_t *ping_id, const uint8_t *client_id, const uint8_t *data_public_key, + uint64_t sendback_data, const uint8_t *gc_data, uint16_t gc_data_length); #endif /* C_TOXCORE_TOXCORE_GROUP_ONION_ANNOUNCE_H */ diff --git a/toxcore/list.c b/toxcore/list.c index fd83825c2e..689ad0a614 100644 --- a/toxcore/list.c +++ b/toxcore/list.c @@ -115,7 +115,7 @@ static bool resize(BS_List *list, uint32_t new_size) return true; } - uint8_t *data = (uint8_t *)mem_vrealloc(list->mem, list->data, list->element_size, new_size); + uint8_t *data = (uint8_t *)mem_brealloc(list->mem, list->data, new_size * list->element_size); if (data == nullptr) { return false; diff --git a/toxcore/logger.c b/toxcore/logger.c index 376058c49c..b97ef8e184 100644 --- a/toxcore/logger.c +++ b/toxcore/logger.c @@ -8,6 +8,7 @@ */ #include "logger.h" +#include #include #include #include @@ -52,6 +53,7 @@ void logger_kill(Logger *log) void logger_callback_log(Logger *log, logger_cb *function, void *context, void *userdata) { + assert(log != nullptr); log->callback = function; log->context = context; log->userdata = userdata; diff --git a/toxcore/mem.c b/toxcore/mem.c index 0edc2469fc..32e7eec07c 100644 --- a/toxcore/mem.c +++ b/toxcore/mem.c @@ -53,6 +53,12 @@ void *mem_balloc(const Memory *mem, uint32_t size) return ptr; } +void *mem_brealloc(const Memory *mem, void *ptr, uint32_t size) +{ + void *const new_ptr = mem->funcs->realloc(mem->obj, ptr, size); + return new_ptr; +} + void *mem_alloc(const Memory *mem, uint32_t size) { void *const ptr = mem->funcs->calloc(mem->obj, 1, size); diff --git a/toxcore/mem.h b/toxcore/mem.h index e843477395..6c36027ce7 100644 --- a/toxcore/mem.h +++ b/toxcore/mem.h @@ -45,6 +45,14 @@ const Memory *os_memory(void); */ non_null() void *mem_balloc(const Memory *mem, uint32_t size); +/** + * @brief Resize an array of a given size for built-in types. + * + * If used for a type other than byte-sized types, `size` needs to be manually + * multiplied by the element size. + */ +non_null(1) nullable(2) void *mem_brealloc(const Memory *mem, void *ptr, uint32_t size); + /** * @brief Allocate a single object. * diff --git a/toxcore/mono_time.c b/toxcore/mono_time.c index 4314e1790e..8a3044c6f0 100644 --- a/toxcore/mono_time.c +++ b/toxcore/mono_time.c @@ -218,7 +218,7 @@ void mono_time_set_current_time_callback(Mono_Time *mono_time, * The starting point is unspecified and in particular is likely not comparable * to the return value of `mono_time_get_ms()`. */ -uint64_t current_time_monotonic(Mono_Time *mono_time) +uint64_t current_time_monotonic(const Mono_Time *mono_time) { return mono_time->current_time_callback(mono_time->user_data); } diff --git a/toxcore/mono_time.h b/toxcore/mono_time.h index d0f2b7a6d3..e23c1ba0df 100644 --- a/toxcore/mono_time.h +++ b/toxcore/mono_time.h @@ -87,7 +87,7 @@ bool mono_time_is_timeout(const Mono_Time *mono_time, uint64_t timestamp, uint64 * to the return value of `mono_time_get_ms()`. */ non_null() -uint64_t current_time_monotonic(Mono_Time *mono_time); +uint64_t current_time_monotonic(const Mono_Time *mono_time); /** * Override implementation of `current_time_monotonic()` (for tests). diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 0ed1ed3f2c..b957c03b31 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -10,6 +10,7 @@ */ #include "net_crypto.h" +#include #include #include "DHT.h" @@ -673,7 +674,7 @@ static IP_Port return_ip_port_connection(const Net_Crypto *c, int crypt_connecti * @retval 0 on success. */ non_null() -static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length) +static int send_packet_to(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length) { // TODO(irungentoo): TCP, etc... Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); @@ -981,7 +982,7 @@ static int generate_request_packet(uint8_t *data, uint16_t length, const Packets * @return number of requested packets on success. */ non_null() -static int handle_request_packet(const Memory *mem, Mono_Time *mono_time, Packets_Array *send_array, +static int handle_request_packet(const Memory *mem, const Mono_Time *mono_time, Packets_Array *send_array, const uint8_t *data, uint16_t length, uint64_t *latest_send_time, uint64_t rtt_time) { @@ -1064,7 +1065,7 @@ static int handle_request_packet(const Memory *mem, Mono_Time *mono_time, Packet * @retval 0 on success. */ non_null() -static int send_data_packet(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length) +static int send_data_packet(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length) { const uint16_t max_length = MAX_CRYPTO_PACKET_SIZE - (1 + sizeof(uint16_t) + CRYPTO_MAC_SIZE); @@ -1102,7 +1103,7 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, const uint8_ * @retval 0 on success. */ non_null() -static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint32_t buffer_start, uint32_t num, +static int send_data_packet_helper(const Net_Crypto *c, int crypt_connection_id, uint32_t buffer_start, uint32_t num, const uint8_t *data, uint16_t length) { if (length == 0 || length > MAX_CRYPTO_DATA_SIZE) { @@ -1124,7 +1125,7 @@ static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint3 } non_null() -static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id) +static int reset_max_speed_reached(const Net_Crypto *c, int crypt_connection_id) { Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); @@ -1159,7 +1160,7 @@ static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id) * @return positive packet number if data was put into the queue. */ non_null() -static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length, +static int64_t send_lossless_packet(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length, bool congestion_control) { if (length == 0 || length > MAX_CRYPTO_DATA_SIZE) { @@ -1275,7 +1276,7 @@ static int handle_data_packet(const Net_Crypto *c, int crypt_connection_id, uint * @retval 0 on success. */ non_null() -static int send_request_packet(Net_Crypto *c, int crypt_connection_id) +static int send_request_packet(const Net_Crypto *c, int crypt_connection_id) { const Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); @@ -1300,7 +1301,7 @@ static int send_request_packet(Net_Crypto *c, int crypt_connection_id) * @return number of packets sent on success. */ non_null() -static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32_t max_num) +static int send_requested_packets(const Net_Crypto *c, int crypt_connection_id, uint32_t max_num) { if (max_num == 0) { return -1; @@ -1414,7 +1415,7 @@ static int clear_temp_packet(const Net_Crypto *c, int crypt_connection_id) * @retval 0 on success. */ non_null() -static int send_temp_packet(Net_Crypto *c, int crypt_connection_id) +static int send_temp_packet(const Net_Crypto *c, int crypt_connection_id) { Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); @@ -1442,7 +1443,7 @@ static int send_temp_packet(Net_Crypto *c, int crypt_connection_id) * @retval 0 on success. */ non_null() -static int create_send_handshake(Net_Crypto *c, int crypt_connection_id, const uint8_t *cookie, +static int create_send_handshake(const Net_Crypto *c, int crypt_connection_id, const uint8_t *cookie, const uint8_t *dht_public_key) { const Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); @@ -1472,7 +1473,7 @@ static int create_send_handshake(Net_Crypto *c, int crypt_connection_id, const u * @retval 0 on success. */ non_null() -static int send_kill_packet(Net_Crypto *c, int crypt_connection_id) +static int send_kill_packet(const Net_Crypto *c, int crypt_connection_id) { const Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); @@ -1647,7 +1648,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const } non_null() -static int handle_packet_cookie_response(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length) +static int handle_packet_cookie_response(const Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length) { Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); @@ -1679,7 +1680,7 @@ static int handle_packet_cookie_response(Net_Crypto *c, int crypt_connection_id, } non_null(1, 3) nullable(5) -static int handle_packet_crypto_hs(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length, +static int handle_packet_crypto_hs(const Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length, void *userdata) { Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); @@ -2757,7 +2758,7 @@ static void send_crypto_packets(Net_Crypto *c) * @retval 1 if max speed was reached for this connection (no more data can be physically through the pipe). * @retval 0 if it wasn't reached. */ -bool max_speed_reached(Net_Crypto *c, int crypt_connection_id) +bool max_speed_reached(const Net_Crypto *c, int crypt_connection_id) { return reset_max_speed_reached(c, crypt_connection_id) != 0; } @@ -2792,7 +2793,7 @@ uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connecti * * congestion_control: should congestion control apply to this packet? */ -int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length, +int64_t write_cryptpacket(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length, bool congestion_control) { if (length == 0) { @@ -2878,7 +2879,7 @@ int cryptpacket_received(const Net_Crypto *c, int crypt_connection_id, uint32_t * * The first byte of data must be in the PACKET_ID_RANGE_LOSSY. */ -int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length) +int send_lossy_cryptpacket(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length) { if (length == 0 || length > MAX_CRYPTO_DATA_SIZE) { return -1; diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index 5fcb67d90e..9f4cbf06d2 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h @@ -9,10 +9,7 @@ #ifndef C_TOXCORE_TOXCORE_NET_CRYPTO_H #define C_TOXCORE_TOXCORE_NET_CRYPTO_H -#include - #include "DHT.h" -#include "LAN_discovery.h" #include "TCP_client.h" #include "TCP_connection.h" #include "attributes.h" @@ -242,7 +239,7 @@ uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connecti * @retval 0 if it wasn't reached. */ non_null() -bool max_speed_reached(Net_Crypto *c, int crypt_connection_id); +bool max_speed_reached(const Net_Crypto *c, int crypt_connection_id); /** @brief Sends a lossless cryptopacket. * @@ -254,7 +251,7 @@ bool max_speed_reached(Net_Crypto *c, int crypt_connection_id); * congestion_control: should congestion control apply to this packet? */ non_null() -int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, +int64_t write_cryptpacket(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length, bool congestion_control); /** @brief Check if packet_number was received by the other side. @@ -282,7 +279,7 @@ int cryptpacket_received(const Net_Crypto *c, int crypt_connection_id, uint32_t * The first byte of data must be in the PACKET_ID_RANGE_LOSSY. */ non_null() -int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length); +int send_lossy_cryptpacket(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length); /** @brief Add a tcp relay, associating it to a crypt_connection_id. * diff --git a/toxcore/tox.c b/toxcore/tox.c index ff2fa47358..7349928e4d 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -929,7 +929,7 @@ static Tox *tox_new_system(const struct Tox_Options *options, Tox_Err_New *error return nullptr; } - tox->m->conferences_object = new_groupchats(tox->mono_time, tox->m); + tox->m->conferences_object = new_groupchats(tox->mono_time, sys->mem, tox->m); if (tox->m->conferences_object == nullptr) { kill_messenger(tox->m);