Squashed 'external/toxcore/c-toxcore/' changes from 11ab1d2a723..d9b8fa6098d
d9b8fa6098d fix: Fake broadcast address for 127.x.x.x aa649165a57 chore: Add code for future netprof TCP testing 9e5693de5ac chore: add to_string functions for netprof enums 52d915e6a90 cleanup: Heap allocate network profile objects 80fabd4a729 feat: Implement Tox network profiler 05abe083cb6 cleanup: Some random cleanups, mostly related to mem. 5cca24513b8 cleanup: Check that onion IP/Port packing worked. e092ecd1244 cleanup: Use tox memory allocator in some more places. 3cfe41c7587 fix: Avoid `memcpy`-ing structs into onion ping id data. e32ac001938 fix: Add more information on why the frame was not sent. ab887003687 fix: Allow TCP connections to fail `connect` calls. 7603170e663 refactor: Use tox memory in group connection allocations. 5bd8a85eb89 cleanup: Align internal logger with external on type of source line. e9bf524d9e1 cleanup: Add missing `#include` to sort_test.cc. d10c966b998 feat: Add `to_string` functions for toxencryptsave errors. 7bfd0dc8003 docs: Update the docs for group join functions 380dde9f2ae test: Add more logging to TCP connection constructor. 0f12f384c8c cleanup: Reduce stack frame sizes to below 4096 bytes. bc43cec0626 chore: Happy new year! fbe78f1702e cleanup: Add a `TOX_HIDE_DEPRECATED` check to hide deprecated symbols. 44d9da07e77 refactor: Use tox memory for group moderation/pack allocations. 7f26d520168 refactor: Use tox memory in group chats allocations. 2f62f3d0e77 refactor: Use tox Memory for group allocations. 8a968162041 chore: Add dispatch/events headers to bazel export. 2bbfb35abf6 docs: Output the error code string instead of int. in toxav logging d55d0e4eaef cleanup: Remove redundant code for checking if group exists 2a6dc643338 chore: Upgrade dependencies for websockify. fc0650601c1 fix: Allow peers to reconnect to group chats using a password git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: d9b8fa6098de6c074038b6664d2572627540b148
This commit is contained in:
@ -4,6 +4,8 @@ load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test")
|
||||
exports_files(
|
||||
srcs = [
|
||||
"tox.h",
|
||||
"tox_dispatch.h",
|
||||
"tox_events.h",
|
||||
"tox_private.h",
|
||||
],
|
||||
visibility = ["//c-toxcore:__subpackages__"],
|
||||
@ -268,6 +270,7 @@ cc_library(
|
||||
deps = [
|
||||
":attributes",
|
||||
":ccompat",
|
||||
":mem",
|
||||
],
|
||||
)
|
||||
|
||||
@ -277,6 +280,7 @@ cc_test(
|
||||
srcs = ["list_test.cc"],
|
||||
deps = [
|
||||
":list",
|
||||
":mem",
|
||||
"@com_google_googletest//:gtest",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
@ -346,6 +350,18 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "net_profile",
|
||||
srcs = ["net_profile.c"],
|
||||
hdrs = ["net_profile.h"],
|
||||
deps = [
|
||||
":attributes",
|
||||
":ccompat",
|
||||
":logger",
|
||||
":mem",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "network",
|
||||
srcs = ["network.c"],
|
||||
@ -365,6 +381,7 @@ cc_library(
|
||||
":logger",
|
||||
":mem",
|
||||
":mono_time",
|
||||
":net_profile",
|
||||
":util",
|
||||
"@libsodium",
|
||||
"@psocket",
|
||||
@ -450,6 +467,7 @@ cc_library(
|
||||
":attributes",
|
||||
":ccompat",
|
||||
":crypto_core",
|
||||
":mem",
|
||||
":network",
|
||||
":util",
|
||||
"@psocket",
|
||||
@ -575,6 +593,7 @@ cc_library(
|
||||
":ccompat",
|
||||
":crypto_core",
|
||||
":logger",
|
||||
":mem",
|
||||
":mono_time",
|
||||
":network",
|
||||
":timed_auth",
|
||||
@ -629,6 +648,7 @@ cc_library(
|
||||
":crypto_core",
|
||||
":logger",
|
||||
":mem",
|
||||
":net_profile",
|
||||
":network",
|
||||
],
|
||||
)
|
||||
@ -656,6 +676,7 @@ cc_library(
|
||||
":logger",
|
||||
":mem",
|
||||
":mono_time",
|
||||
":net_profile",
|
||||
":network",
|
||||
":onion",
|
||||
":util",
|
||||
@ -677,6 +698,7 @@ cc_library(
|
||||
":logger",
|
||||
":mem",
|
||||
":mono_time",
|
||||
":net_profile",
|
||||
":network",
|
||||
":util",
|
||||
],
|
||||
@ -699,6 +721,7 @@ cc_library(
|
||||
":logger",
|
||||
":mem",
|
||||
":mono_time",
|
||||
":net_profile",
|
||||
":network",
|
||||
":onion",
|
||||
":util",
|
||||
@ -736,6 +759,7 @@ cc_library(
|
||||
":logger",
|
||||
":mem",
|
||||
":mono_time",
|
||||
":net_profile",
|
||||
":network",
|
||||
":util",
|
||||
"@pthread",
|
||||
@ -785,6 +809,7 @@ cc_library(
|
||||
":ccompat",
|
||||
":crypto_core",
|
||||
":logger",
|
||||
":mem",
|
||||
":mono_time",
|
||||
":network",
|
||||
":util",
|
||||
@ -886,6 +911,7 @@ cc_library(
|
||||
":ccompat",
|
||||
":crypto_core",
|
||||
":logger",
|
||||
":mem",
|
||||
":mono_time",
|
||||
":net_crypto",
|
||||
":network",
|
||||
@ -910,6 +936,7 @@ cc_library(
|
||||
":ccompat",
|
||||
":crypto_core",
|
||||
":friend_connection",
|
||||
":mem",
|
||||
":network",
|
||||
":onion",
|
||||
":onion_announce",
|
||||
@ -1060,6 +1087,7 @@ cc_library(
|
||||
":DHT",
|
||||
":Messenger",
|
||||
":TCP_client",
|
||||
":TCP_server",
|
||||
":attributes",
|
||||
":ccompat",
|
||||
":crypto_core",
|
||||
@ -1070,6 +1098,7 @@ cc_library(
|
||||
":mem",
|
||||
":mono_time",
|
||||
":net_crypto",
|
||||
":net_profile",
|
||||
":network",
|
||||
":onion_client",
|
||||
":state",
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
@ -8,8 +8,6 @@
|
||||
*/
|
||||
#include "LAN_discovery.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
||||
// The mingw32/64 Windows library warns about including winsock2.h after
|
||||
// windows.h even though with the above it's a valid thing to do. So, to make
|
||||
@ -41,11 +39,14 @@
|
||||
#include "attributes.h"
|
||||
#include "ccompat.h"
|
||||
#include "crypto_core.h"
|
||||
#include "mem.h"
|
||||
#include "network.h"
|
||||
|
||||
#define MAX_INTERFACES 16
|
||||
|
||||
struct Broadcast_Info {
|
||||
const Memory *mem;
|
||||
|
||||
uint32_t count;
|
||||
IP ips[MAX_INTERFACES];
|
||||
};
|
||||
@ -53,29 +54,31 @@ struct Broadcast_Info {
|
||||
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
||||
|
||||
non_null()
|
||||
static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
||||
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
|
||||
{
|
||||
Broadcast_Info *broadcast = (Broadcast_Info *)calloc(1, sizeof(Broadcast_Info));
|
||||
Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info));
|
||||
|
||||
if (broadcast == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IP_ADAPTER_INFO *adapter_info = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
|
||||
broadcast->mem = mem;
|
||||
|
||||
IP_ADAPTER_INFO *adapter_info = (IP_ADAPTER_INFO *)mem_balloc(mem, sizeof(IP_ADAPTER_INFO));
|
||||
|
||||
if (adapter_info == nullptr) {
|
||||
free(broadcast);
|
||||
mem_delete(mem, broadcast);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
unsigned long out_buf_len = sizeof(IP_ADAPTER_INFO);
|
||||
|
||||
if (GetAdaptersInfo(adapter_info, &out_buf_len) == ERROR_BUFFER_OVERFLOW) {
|
||||
free(adapter_info);
|
||||
IP_ADAPTER_INFO *new_adapter_info = (IP_ADAPTER_INFO *)malloc(out_buf_len);
|
||||
mem_delete(mem, adapter_info);
|
||||
IP_ADAPTER_INFO *new_adapter_info = (IP_ADAPTER_INFO *)mem_balloc(mem, out_buf_len);
|
||||
|
||||
if (new_adapter_info == nullptr) {
|
||||
free(broadcast);
|
||||
mem_delete(mem, broadcast);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -113,7 +116,7 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
||||
}
|
||||
|
||||
if (adapter_info != nullptr) {
|
||||
free(adapter_info);
|
||||
mem_delete(mem, adapter_info);
|
||||
}
|
||||
|
||||
return broadcast;
|
||||
@ -122,14 +125,19 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
||||
#elif !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && (defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__))
|
||||
|
||||
non_null()
|
||||
static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
||||
static bool ip4_is_local(const IP4 *ip4);
|
||||
|
||||
non_null()
|
||||
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
|
||||
{
|
||||
Broadcast_Info *broadcast = (Broadcast_Info *)calloc(1, sizeof(Broadcast_Info));
|
||||
Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info));
|
||||
|
||||
if (broadcast == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
broadcast->mem = mem;
|
||||
|
||||
/* Not sure how many platforms this will run on,
|
||||
* so it's wrapped in `__linux__` for now.
|
||||
* Definitely won't work like this on Windows...
|
||||
@ -137,7 +145,7 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
||||
const Socket sock = net_socket(ns, net_family_ipv4(), TOX_SOCK_STREAM, 0);
|
||||
|
||||
if (!sock_valid(sock)) {
|
||||
free(broadcast);
|
||||
mem_delete(mem, broadcast);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -150,7 +158,7 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
||||
|
||||
if (ioctl(net_socket_to_native(sock), SIOCGIFCONF, &ifc) < 0) {
|
||||
kill_sock(ns, sock);
|
||||
free(broadcast);
|
||||
mem_delete(mem, broadcast);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -162,7 +170,8 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
||||
const int n = ifc.ifc_len / sizeof(struct ifreq);
|
||||
|
||||
for (int i = 0; i < n; ++i) {
|
||||
/* there are interfaces with are incapable of broadcast */
|
||||
/* there are interfaces with are incapable of broadcast
|
||||
* on Linux, `lo` has no broadcast address, but this function returns `>=0` */
|
||||
if (ioctl(net_socket_to_native(sock), SIOCGIFBRDADDR, &i_faces[i]) < 0) {
|
||||
continue;
|
||||
}
|
||||
@ -172,7 +181,7 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
||||
continue;
|
||||
}
|
||||
|
||||
const struct sockaddr_in *sock4 = (const struct sockaddr_in *)(void *)&i_faces[i].ifr_broadaddr;
|
||||
const struct sockaddr_in *broadaddr4 = (const struct sockaddr_in *)(void *)&i_faces[i].ifr_broadaddr;
|
||||
|
||||
if (broadcast->count >= MAX_INTERFACES) {
|
||||
break;
|
||||
@ -180,10 +189,27 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
||||
|
||||
IP *ip = &broadcast->ips[broadcast->count];
|
||||
ip->family = net_family_ipv4();
|
||||
ip->ip.v4.uint32 = sock4->sin_addr.s_addr;
|
||||
ip->ip.v4.uint32 = broadaddr4->sin_addr.s_addr;
|
||||
|
||||
// if no broadcast address
|
||||
if (ip->ip.v4.uint32 == 0) {
|
||||
continue;
|
||||
if (ioctl(net_socket_to_native(sock), SIOCGIFADDR, &i_faces[i]) < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const struct sockaddr_in *addr4 = (const struct sockaddr_in *)(void *)&i_faces[i].ifr_addr;
|
||||
|
||||
|
||||
IP4 ip4_staging;
|
||||
ip4_staging.uint32 = addr4->sin_addr.s_addr;
|
||||
|
||||
if (ip4_is_local(&ip4_staging)) {
|
||||
// this is 127.x.x.x
|
||||
ip->ip.v4.uint32 = ip4_staging.uint32;
|
||||
} else {
|
||||
// give up.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
++broadcast->count;
|
||||
@ -197,9 +223,17 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
||||
#else // TODO(irungentoo): Other platforms?
|
||||
|
||||
non_null()
|
||||
static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
||||
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
|
||||
{
|
||||
return (Broadcast_Info *)calloc(1, sizeof(Broadcast_Info));
|
||||
Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info));
|
||||
|
||||
if (broadcast == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
broadcast->mem = mem;
|
||||
|
||||
return broadcast;
|
||||
}
|
||||
|
||||
#endif /* platforms */
|
||||
@ -375,12 +409,16 @@ bool lan_discovery_send(const Networking_Core *net, const Broadcast_Info *broadc
|
||||
return res;
|
||||
}
|
||||
|
||||
Broadcast_Info *lan_discovery_init(const Network *ns)
|
||||
Broadcast_Info *lan_discovery_init(const Memory *mem, const Network *ns)
|
||||
{
|
||||
return fetch_broadcast_info(ns);
|
||||
return fetch_broadcast_info(mem, ns);
|
||||
}
|
||||
|
||||
void lan_discovery_kill(Broadcast_Info *broadcast)
|
||||
{
|
||||
free(broadcast);
|
||||
if (broadcast == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
mem_delete(broadcast->mem, broadcast);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#define C_TOXCORE_TOXCORE_LAN_DISCOVERY_H
|
||||
|
||||
#include "attributes.h"
|
||||
#include "mem.h"
|
||||
#include "network.h"
|
||||
|
||||
/**
|
||||
@ -32,7 +33,7 @@ bool lan_discovery_send(const Networking_Core *net, const Broadcast_Info *broadc
|
||||
* Discovers broadcast devices and IP addresses.
|
||||
*/
|
||||
non_null()
|
||||
Broadcast_Info *lan_discovery_init(const Network *ns);
|
||||
Broadcast_Info *lan_discovery_init(const Memory *mem, const Network *ns);
|
||||
|
||||
/**
|
||||
* Free all resources associated with the broadcast info.
|
||||
|
@ -74,6 +74,8 @@ libtoxcore_la_SOURCES = ../third_party/cmp/cmp.c \
|
||||
../toxcore/ping_array.c \
|
||||
../toxcore/net_crypto.h \
|
||||
../toxcore/net_crypto.c \
|
||||
../toxcore/net_profile.c \
|
||||
../toxcore/net_profile.h \
|
||||
../toxcore/friend_requests.h \
|
||||
../toxcore/friend_requests.c \
|
||||
../toxcore/LAN_discovery.h \
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
@ -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,
|
||||
@ -2515,7 +2515,7 @@ static bool self_announce_group(const Messenger *m, GC_Chat *chat, Onion_Friend
|
||||
return false;
|
||||
}
|
||||
|
||||
if (gca_add_announce(m->mono_time, m->group_announce, &announce) == nullptr) {
|
||||
if (gca_add_announce(m->mem, m->mono_time, m->group_announce, &announce) == nullptr) {
|
||||
onion_friend_set_gc_data(onion_friend, nullptr, 0);
|
||||
return false;
|
||||
}
|
||||
@ -3475,7 +3475,7 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
||||
m->rng = rng;
|
||||
m->ns = ns;
|
||||
|
||||
m->fr = friendreq_new();
|
||||
m->fr = friendreq_new(mem);
|
||||
|
||||
if (m->fr == nullptr) {
|
||||
mem_delete(mem, m);
|
||||
@ -3544,7 +3544,7 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
m->group_announce = new_gca_list();
|
||||
m->group_announce = new_gca_list(m->mem);
|
||||
|
||||
if (m->group_announce == nullptr) {
|
||||
LOGGER_WARNING(m->log, "DHT group chats initialisation failed");
|
||||
@ -3559,7 +3559,7 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
||||
}
|
||||
|
||||
if (options->dht_announcements_enabled) {
|
||||
m->forwarding = new_forwarding(m->log, m->rng, m->mono_time, m->dht);
|
||||
m->forwarding = new_forwarding(m->log, m->mem, m->rng, m->mono_time, m->dht);
|
||||
if (m->forwarding != nullptr) {
|
||||
m->announce = new_announcements(m->log, m->mem, m->rng, m->mono_time, m->forwarding);
|
||||
} else {
|
||||
@ -3574,7 +3574,7 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
||||
m->onion_a = new_onion_announce(m->log, m->mem, m->rng, m->mono_time, m->dht);
|
||||
m->onion_c = new_onion_client(m->log, m->mem, m->rng, m->mono_time, m->net_crypto);
|
||||
if (m->onion_c != nullptr) {
|
||||
m->fr_c = new_friend_connections(m->log, m->mono_time, m->ns, m->onion_c, options->local_discovery_enabled);
|
||||
m->fr_c = new_friend_connections(m->log, m->mem, m->mono_time, m->ns, m->onion_c, options->local_discovery_enabled);
|
||||
}
|
||||
|
||||
if ((options->dht_announcements_enabled && (m->forwarding == nullptr || m->announce == nullptr)) ||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "net_profile.h"
|
||||
#include "network.h"
|
||||
#include "util.h"
|
||||
|
||||
@ -109,11 +110,23 @@ void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value)
|
||||
non_null()
|
||||
static bool connect_sock_to(const Network *ns, const Logger *logger, const Memory *mem, Socket sock, const IP_Port *ip_port, const TCP_Proxy_Info *proxy_info)
|
||||
{
|
||||
Net_Err_Connect err;
|
||||
if (proxy_info->proxy_type != TCP_PROXY_NONE) {
|
||||
return net_connect(ns, mem, logger, sock, &proxy_info->ip_port);
|
||||
net_connect(ns, mem, logger, sock, &proxy_info->ip_port, &err);
|
||||
} else {
|
||||
return net_connect(ns, mem, logger, sock, ip_port);
|
||||
net_connect(ns, mem, logger, sock, ip_port, &err);
|
||||
}
|
||||
switch (err) {
|
||||
case NET_ERR_CONNECT_OK:
|
||||
case NET_ERR_CONNECT_FAILED: {
|
||||
/* nonblocking socket, connect will never return success */
|
||||
return true;
|
||||
}
|
||||
case NET_ERR_CONNECT_INVALID_FAMILY:
|
||||
return false;
|
||||
}
|
||||
LOGGER_ERROR(logger, "unexpected error code %s from net_connect", net_err_connect_to_string(err));
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -582,7 +595,7 @@ void forwarding_handler(TCP_Client_Connection *con, forwarded_response_cb *forwa
|
||||
TCP_Client_Connection *new_tcp_connection(
|
||||
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns,
|
||||
const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key,
|
||||
const TCP_Proxy_Info *proxy_info)
|
||||
const TCP_Proxy_Info *proxy_info, Net_Profile *net_profile)
|
||||
{
|
||||
assert(logger != nullptr);
|
||||
assert(mem != nullptr);
|
||||
@ -591,6 +604,7 @@ TCP_Client_Connection *new_tcp_connection(
|
||||
assert(ns != nullptr);
|
||||
|
||||
if (!net_family_is_ipv4(ip_port->ip.family) && !net_family_is_ipv6(ip_port->ip.family)) {
|
||||
LOGGER_ERROR(logger, "Invalid IP family: %d", ip_port->ip.family.value);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -609,15 +623,26 @@ TCP_Client_Connection *new_tcp_connection(
|
||||
const Socket sock = net_socket(ns, family, TOX_SOCK_STREAM, TOX_PROTO_TCP);
|
||||
|
||||
if (!sock_valid(sock)) {
|
||||
LOGGER_ERROR(logger, "Failed to create TCP socket with family %d", family.value);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!set_socket_nosigpipe(ns, sock)) {
|
||||
LOGGER_ERROR(logger, "Failed to set TCP socket to ignore SIGPIPE");
|
||||
kill_sock(ns, sock);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!(set_socket_nonblock(ns, sock) && connect_sock_to(ns, logger, mem, sock, ip_port, proxy_info))) {
|
||||
if (!set_socket_nonblock(ns, sock)) {
|
||||
LOGGER_ERROR(logger, "Failed to set TCP socket to non-blocking");
|
||||
kill_sock(ns, sock);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!connect_sock_to(ns, logger, mem, sock, ip_port, proxy_info)) {
|
||||
Ip_Ntoa ip_ntoa;
|
||||
LOGGER_WARNING(logger, "Failed to connect TCP socket to %s:%u",
|
||||
net_ip_ntoa(&ip_port->ip, &ip_ntoa), net_ntohs(ip_port->port));
|
||||
kill_sock(ns, sock);
|
||||
return nullptr;
|
||||
}
|
||||
@ -625,6 +650,7 @@ TCP_Client_Connection *new_tcp_connection(
|
||||
TCP_Client_Connection *temp = (TCP_Client_Connection *)mem_alloc(mem, sizeof(TCP_Client_Connection));
|
||||
|
||||
if (temp == nullptr) {
|
||||
LOGGER_ERROR(logger, "Failed to allocate memory for TCP_Client_Connection");
|
||||
kill_sock(ns, sock);
|
||||
return nullptr;
|
||||
}
|
||||
@ -634,6 +660,7 @@ TCP_Client_Connection *new_tcp_connection(
|
||||
temp->con.rng = rng;
|
||||
temp->con.sock = sock;
|
||||
temp->con.ip_port = *ip_port;
|
||||
temp->con.net_profile = net_profile;
|
||||
memcpy(temp->public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
memcpy(temp->self_public_key, self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
encrypt_precompute(temp->public_key, self_secret_key, temp->con.shared_key);
|
||||
@ -657,6 +684,7 @@ TCP_Client_Connection *new_tcp_connection(
|
||||
temp->status = TCP_CLIENT_CONNECTING;
|
||||
|
||||
if (generate_handshake(temp) == -1) {
|
||||
LOGGER_ERROR(logger, "Failed to generate handshake");
|
||||
kill_sock(ns, sock);
|
||||
mem_delete(mem, temp);
|
||||
return nullptr;
|
||||
@ -819,6 +847,8 @@ static int handle_tcp_client_packet(const Logger *logger, TCP_Client_Connection
|
||||
return -1;
|
||||
}
|
||||
|
||||
netprof_record_packet(conn->con.net_profile, data[0], length, PACKET_DIRECTION_RECV);
|
||||
|
||||
switch (data[0]) {
|
||||
case TCP_PACKET_ROUTING_RESPONSE:
|
||||
return handle_tcp_client_routing_response(conn, data, length);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "net_profile.h"
|
||||
#include "network.h"
|
||||
|
||||
#define TCP_CONNECTION_TIMEOUT 10
|
||||
@ -60,11 +61,11 @@ non_null()
|
||||
void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value);
|
||||
|
||||
/** Create new TCP connection to ip_port/public_key */
|
||||
non_null(1, 2, 3, 4, 5, 6, 7, 8, 9) nullable(10)
|
||||
non_null(1, 2, 3, 4, 5, 6, 7, 8, 9) nullable(10, 11)
|
||||
TCP_Client_Connection *new_tcp_connection(
|
||||
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns,
|
||||
const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key,
|
||||
const TCP_Proxy_Info *proxy_info);
|
||||
const TCP_Proxy_Info *proxy_info, Net_Profile *net_profile);
|
||||
|
||||
/** Run the TCP connection */
|
||||
non_null(1, 2, 3) nullable(4)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -35,7 +35,8 @@ int send_pending_data_nonpriority(const Logger *logger, TCP_Connection *con)
|
||||
}
|
||||
|
||||
const uint16_t left = con->last_packet_length - con->last_packet_sent;
|
||||
const int len = net_send(con->ns, logger, con->sock, con->last_packet + con->last_packet_sent, left, &con->ip_port);
|
||||
const int len = net_send(con->ns, logger, con->sock, con->last_packet + con->last_packet_sent, left, &con->ip_port,
|
||||
con->net_profile);
|
||||
|
||||
if (len <= 0) {
|
||||
return -1;
|
||||
@ -66,7 +67,7 @@ int send_pending_data(const Logger *logger, TCP_Connection *con)
|
||||
|
||||
while (p != nullptr) {
|
||||
const uint16_t left = p->size - p->sent;
|
||||
const int len = net_send(con->ns, logger, con->sock, p->data + p->sent, left, &con->ip_port);
|
||||
const int len = net_send(con->ns, logger, con->sock, p->data + p->sent, left, &con->ip_port, con->net_profile);
|
||||
|
||||
if (len != left) {
|
||||
if (len > 0) {
|
||||
@ -164,7 +165,8 @@ int write_packet_tcp_secure_connection(const Logger *logger, TCP_Connection *con
|
||||
}
|
||||
|
||||
if (priority) {
|
||||
len = sendpriority ? net_send(con->ns, logger, con->sock, packet, packet_size, &con->ip_port) : 0;
|
||||
len = sendpriority ? net_send(con->ns, logger, con->sock, packet, packet_size, &con->ip_port,
|
||||
con->net_profile) : 0;
|
||||
|
||||
if (len <= 0) {
|
||||
len = 0;
|
||||
@ -179,7 +181,7 @@ int write_packet_tcp_secure_connection(const Logger *logger, TCP_Connection *con
|
||||
return add_priority(con, packet, packet_size, len) ? 1 : 0;
|
||||
}
|
||||
|
||||
len = net_send(con->ns, logger, con->sock, packet, packet_size, &con->ip_port);
|
||||
len = net_send(con->ns, logger, con->sock, packet, packet_size, &con->ip_port, con->net_profile);
|
||||
|
||||
if (len <= 0) {
|
||||
return 0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include "crypto_core.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "net_profile.h"
|
||||
#include "network.h"
|
||||
|
||||
typedef struct TCP_Priority_List TCP_Priority_List;
|
||||
@ -66,6 +67,10 @@ typedef struct TCP_Connection {
|
||||
|
||||
TCP_Priority_List *priority_queue_start;
|
||||
TCP_Priority_List *priority_queue_end;
|
||||
|
||||
// This is a shared pointer to the parent's respective Net_Profile object
|
||||
// (either TCP_Server for TCP server packets or TCP_Connections for TCP client packets).
|
||||
Net_Profile *net_profile;
|
||||
} TCP_Connection;
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2015 Tox project.
|
||||
*/
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "net_profile.h"
|
||||
#include "network.h"
|
||||
#include "util.h"
|
||||
|
||||
@ -56,6 +57,9 @@ struct TCP_Connections {
|
||||
|
||||
bool onion_status;
|
||||
uint16_t onion_num_conns;
|
||||
|
||||
/* Network profile for all TCP client packets. */
|
||||
Net_Profile *net_profile;
|
||||
};
|
||||
|
||||
static const TCP_Connection_to empty_tcp_connection_to = {0};
|
||||
@ -928,7 +932,8 @@ static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connec
|
||||
uint8_t relay_pk[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
memcpy(relay_pk, tcp_con_public_key(tcp_con->connection), CRYPTO_PUBLIC_KEY_SIZE);
|
||||
kill_tcp_connection(tcp_con->connection);
|
||||
tcp_con->connection = new_tcp_connection(tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &ip_port, relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info);
|
||||
tcp_con->connection = new_tcp_connection(tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &ip_port, relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info,
|
||||
tcp_c->net_profile);
|
||||
|
||||
if (tcp_con->connection == nullptr) {
|
||||
kill_tcp_relay_connection(tcp_c, tcp_connections_number);
|
||||
@ -1017,7 +1022,7 @@ static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connecti
|
||||
|
||||
tcp_con->connection = new_tcp_connection(
|
||||
tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &tcp_con->ip_port,
|
||||
tcp_con->relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info);
|
||||
tcp_con->relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info, tcp_c->net_profile);
|
||||
|
||||
if (tcp_con->connection == nullptr) {
|
||||
kill_tcp_relay_connection(tcp_c, tcp_connections_number);
|
||||
@ -1315,7 +1320,7 @@ static int add_tcp_relay_instance(TCP_Connections *tcp_c, const IP_Port *ip_port
|
||||
|
||||
tcp_con->connection = new_tcp_connection(
|
||||
tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &ipp_copy,
|
||||
relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info);
|
||||
relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info, tcp_c->net_profile);
|
||||
|
||||
if (tcp_con->connection == nullptr) {
|
||||
return -1;
|
||||
@ -1609,6 +1614,14 @@ TCP_Connections *new_tcp_connections(const Logger *logger, const Memory *mem, co
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Net_Profile *np = netprof_new(logger, mem);
|
||||
|
||||
if (np == nullptr) {
|
||||
mem_delete(mem, temp);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
temp->net_profile = np;
|
||||
temp->logger = logger;
|
||||
temp->mem = mem;
|
||||
temp->rng = rng;
|
||||
@ -1723,7 +1736,17 @@ void kill_tcp_connections(TCP_Connections *tcp_c)
|
||||
|
||||
crypto_memzero(tcp_c->self_secret_key, sizeof(tcp_c->self_secret_key));
|
||||
|
||||
netprof_kill(tcp_c->mem, tcp_c->net_profile);
|
||||
mem_delete(tcp_c->mem, tcp_c->tcp_connections);
|
||||
mem_delete(tcp_c->mem, tcp_c->connections);
|
||||
mem_delete(tcp_c->mem, tcp_c);
|
||||
}
|
||||
|
||||
const Net_Profile *tcp_connection_get_client_net_profile(const TCP_Connections *tcp_c)
|
||||
{
|
||||
if (tcp_c == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return tcp_c->net_profile;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2015 Tox project.
|
||||
*/
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "net_profile.h"
|
||||
#include "network.h"
|
||||
|
||||
#define TCP_CONN_NONE 0
|
||||
@ -317,4 +318,11 @@ void do_tcp_connections(const Logger *logger, TCP_Connections *tcp_c, void *user
|
||||
nullable(1)
|
||||
void kill_tcp_connections(TCP_Connections *tcp_c);
|
||||
|
||||
/** @brief a pointer to the tcp client net profile associated with tcp_c.
|
||||
*
|
||||
* @retval null if tcp_c is null.
|
||||
*/
|
||||
non_null()
|
||||
const Net_Profile *tcp_connection_get_client_net_profile(const TCP_Connections *tcp_c);
|
||||
|
||||
#endif /* C_TOXCORE_TOXCORE_TCP_CONNECTION_H */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "net_profile.h"
|
||||
#include "network.h"
|
||||
#include "onion.h"
|
||||
|
||||
@ -91,6 +92,9 @@ struct TCP_Server {
|
||||
uint64_t counter;
|
||||
|
||||
BS_List accepted_key_list;
|
||||
|
||||
/* Network profile for all TCP server packets. */
|
||||
Net_Profile *net_profile;
|
||||
};
|
||||
|
||||
static_assert(sizeof(TCP_Server) < 7 * 1024 * 1024,
|
||||
@ -236,6 +240,7 @@ static int add_accepted(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_
|
||||
tcp_server->accepted_connection_array[index].identifier = ++tcp_server->counter;
|
||||
tcp_server->accepted_connection_array[index].last_pinged = mono_time_get(mono_time);
|
||||
tcp_server->accepted_connection_array[index].ping_id = 0;
|
||||
tcp_server->accepted_connection_array[index].con.net_profile = tcp_server->net_profile;
|
||||
|
||||
return index;
|
||||
}
|
||||
@ -357,7 +362,7 @@ static int handle_tcp_handshake(const Logger *logger, TCP_Secure_Connection *con
|
||||
|
||||
const IP_Port ipp = {{{0}}};
|
||||
|
||||
if (TCP_SERVER_HANDSHAKE_SIZE != net_send(con->con.ns, logger, con->con.sock, response, TCP_SERVER_HANDSHAKE_SIZE, &ipp)) {
|
||||
if (TCP_SERVER_HANDSHAKE_SIZE != net_send(con->con.ns, logger, con->con.sock, response, TCP_SERVER_HANDSHAKE_SIZE, &ipp, con->con.net_profile)) {
|
||||
crypto_memzero(shared_key, sizeof(shared_key));
|
||||
return -1;
|
||||
}
|
||||
@ -680,6 +685,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
|
||||
}
|
||||
|
||||
TCP_Secure_Connection *const con = &tcp_server->accepted_connection_array[con_id];
|
||||
netprof_record_packet(con->con.net_profile, data[0], length, PACKET_DIRECTION_RECV);
|
||||
|
||||
switch (data[0]) {
|
||||
case TCP_PACKET_ROUTING_REQUEST: {
|
||||
@ -969,6 +975,14 @@ TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Net_Profile *np = netprof_new(logger, mem);
|
||||
|
||||
if (np == nullptr) {
|
||||
mem_delete(mem, temp);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
temp->net_profile = np;
|
||||
temp->logger = logger;
|
||||
temp->mem = mem;
|
||||
temp->ns = ns;
|
||||
@ -978,6 +992,7 @@ TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random
|
||||
|
||||
if (socks_listening == nullptr) {
|
||||
LOGGER_ERROR(logger, "socket allocation failed");
|
||||
netprof_kill(mem, temp->net_profile);
|
||||
mem_delete(mem, temp);
|
||||
return nullptr;
|
||||
}
|
||||
@ -989,6 +1004,7 @@ TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random
|
||||
|
||||
if (temp->efd == -1) {
|
||||
LOGGER_ERROR(logger, "epoll initialisation failed");
|
||||
netprof_kill(mem, temp->net_profile);
|
||||
mem_delete(mem, socks_listening);
|
||||
mem_delete(mem, temp);
|
||||
return nullptr;
|
||||
@ -1022,6 +1038,7 @@ TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random
|
||||
}
|
||||
|
||||
if (temp->num_listening_socks == 0) {
|
||||
netprof_kill(mem, temp->net_profile);
|
||||
mem_delete(mem, temp->socks_listening);
|
||||
mem_delete(mem, temp);
|
||||
return nullptr;
|
||||
@ -1040,7 +1057,7 @@ TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random
|
||||
memcpy(temp->secret_key, secret_key, CRYPTO_SECRET_KEY_SIZE);
|
||||
crypto_derive_public_key(temp->public_key, temp->secret_key);
|
||||
|
||||
bs_list_init(&temp->accepted_key_list, CRYPTO_PUBLIC_KEY_SIZE, 8, memcmp);
|
||||
bs_list_init(&temp->accepted_key_list, mem, CRYPTO_PUBLIC_KEY_SIZE, 8, memcmp);
|
||||
|
||||
return temp;
|
||||
}
|
||||
@ -1422,6 +1439,16 @@ void kill_tcp_server(TCP_Server *tcp_server)
|
||||
|
||||
crypto_memzero(tcp_server->secret_key, sizeof(tcp_server->secret_key));
|
||||
|
||||
netprof_kill(tcp_server->mem, tcp_server->net_profile);
|
||||
mem_delete(tcp_server->mem, tcp_server->socks_listening);
|
||||
mem_delete(tcp_server->mem, tcp_server);
|
||||
}
|
||||
|
||||
const Net_Profile *tcp_server_get_net_profile(const TCP_Server *tcp_server)
|
||||
{
|
||||
if (tcp_server == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return tcp_server->net_profile;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "net_profile.h"
|
||||
#include "network.h"
|
||||
#include "onion.h"
|
||||
|
||||
@ -52,4 +53,11 @@ void do_tcp_server(TCP_Server *tcp_server, const Mono_Time *mono_time);
|
||||
nullable(1)
|
||||
void kill_tcp_server(TCP_Server *tcp_server);
|
||||
|
||||
/** @brief Returns a pointer to the net profile associated with `tcp_server`.
|
||||
*
|
||||
* Returns null if `tcp_server` is null.
|
||||
*/
|
||||
nullable(1)
|
||||
const Net_Profile *tcp_server_get_net_profile(const TCP_Server *tcp_server);
|
||||
|
||||
#endif /* C_TOXCORE_TOXCORE_TCP_SERVER_H */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2020-2021 The TokTok team.
|
||||
* Copyright © 2020-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -9,7 +9,6 @@
|
||||
#include "announce.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "DHT.h"
|
||||
@ -239,9 +238,9 @@ bool announce_store_data(Announcements *announce, const uint8_t *data_public_key
|
||||
if (length > 0) {
|
||||
assert(data != nullptr);
|
||||
|
||||
free(entry->data);
|
||||
mem_delete(announce->mem, entry->data);
|
||||
|
||||
uint8_t *entry_data = (uint8_t *)malloc(length);
|
||||
uint8_t *entry_data = (uint8_t *)mem_balloc(announce->mem, length);
|
||||
|
||||
if (entry_data == nullptr) {
|
||||
entry->data = nullptr; // TODO(iphydf): Is this necessary?
|
||||
@ -651,7 +650,7 @@ Announcements *new_announcements(const Logger *log, const Memory *mem, const Ran
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Announcements *announce = (Announcements *)calloc(1, sizeof(Announcements));
|
||||
Announcements *announce = (Announcements *)mem_alloc(mem, sizeof(Announcements));
|
||||
|
||||
if (announce == nullptr) {
|
||||
return nullptr;
|
||||
@ -669,7 +668,7 @@ Announcements *new_announcements(const Logger *log, const Memory *mem, const Ran
|
||||
new_hmac_key(announce->rng, announce->hmac_key);
|
||||
announce->shared_keys = shared_key_cache_new(log, mono_time, mem, announce->secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
||||
if (announce->shared_keys == nullptr) {
|
||||
free(announce);
|
||||
mem_delete(announce->mem, announce);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -700,8 +699,8 @@ void kill_announcements(Announcements *announce)
|
||||
shared_key_cache_free(announce->shared_keys);
|
||||
|
||||
for (uint32_t i = 0; i < ANNOUNCE_BUCKETS * ANNOUNCE_BUCKET_SIZE; ++i) {
|
||||
free(announce->entries[i].data);
|
||||
mem_delete(announce->mem, announce->entries[i].data);
|
||||
}
|
||||
|
||||
free(announce);
|
||||
mem_delete(announce->mem, announce);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2020-2021 The TokTok team.
|
||||
* Copyright © 2020-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#ifndef C_TOXCORE_TOXCORE_ANNOUNCE_H
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2022 The TokTok team.
|
||||
* Copyright © 2022-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2022 The TokTok team.
|
||||
* Copyright © 2022-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "bin_pack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2022 The TokTok team.
|
||||
* Copyright © 2022-2025 The TokTok team.
|
||||
*/
|
||||
#ifndef C_TOXCORE_TOXCORE_BIN_PACK_H
|
||||
#define C_TOXCORE_TOXCORE_BIN_PACK_H
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2022 The TokTok team.
|
||||
* Copyright © 2022-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "bin_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2022 The TokTok team.
|
||||
* Copyright © 2022-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#ifndef C_TOXCORE_TOXCORE_BIN_UNPACK_H
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2022 The TokTok team.
|
||||
* Copyright © 2022-2025 The TokTok team.
|
||||
*/
|
||||
#include "ccompat.h"
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2021 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -1,12 +1,11 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2024 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
#include "crypto_core.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sodium.h>
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2024 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2024 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2024 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include "crypto_core_test_util.hh"
|
||||
#include "mem_test_util.hh"
|
||||
#include "util.h"
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2022 The TokTok team.
|
||||
* Copyright © 2022-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -13,6 +13,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_private.h"
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2022 The TokTok team.
|
||||
* Copyright © 2022-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
|
@ -1,16 +1,13 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2022 The TokTok team.
|
||||
* Copyright © 2022-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#ifndef C_TOXCORE_TOXCORE_EVENTS_EVENTS_ALLOC_H
|
||||
#define C_TOXCORE_TOXCORE_EVENTS_EVENTS_ALLOC_H
|
||||
|
||||
#include "../attributes.h"
|
||||
#include "../bin_pack.h"
|
||||
#include "../bin_unpack.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_private.h"
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2022 The TokTok team.
|
||||
* Copyright © 2022-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -13,6 +13,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_private.h"
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -14,6 +14,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
|
||||
/*****************************************************
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2023-2024 The TokTok team.
|
||||
* Copyright © 2023-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "events_alloc.h"
|
||||
@ -12,6 +12,7 @@
|
||||
#include "../ccompat.h"
|
||||
#include "../mem.h"
|
||||
#include "../tox.h"
|
||||
#include "../tox_event.h"
|
||||
#include "../tox_events.h"
|
||||
#include "../tox_pack.h"
|
||||
#include "../tox_unpack.h"
|
||||
|
@ -1,11 +1,10 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2019-2022 The TokTok team.
|
||||
* Copyright © 2019-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#include "forwarding.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "DHT.h"
|
||||
@ -13,12 +12,14 @@
|
||||
#include "ccompat.h"
|
||||
#include "crypto_core.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "network.h"
|
||||
#include "timed_auth.h"
|
||||
|
||||
struct Forwarding {
|
||||
const Logger *log;
|
||||
const Memory *mem;
|
||||
const Random *rng;
|
||||
DHT *dht;
|
||||
const Mono_Time *mono_time;
|
||||
@ -357,19 +358,20 @@ void set_callback_forward_reply(Forwarding *forwarding, forward_reply_cb *functi
|
||||
forwarding->forward_reply_callback_object = object;
|
||||
}
|
||||
|
||||
Forwarding *new_forwarding(const Logger *log, const Random *rng, const Mono_Time *mono_time, DHT *dht)
|
||||
Forwarding *new_forwarding(const Logger *log, const Memory *mem, const Random *rng, const Mono_Time *mono_time, DHT *dht)
|
||||
{
|
||||
if (log == nullptr || mono_time == nullptr || dht == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Forwarding *forwarding = (Forwarding *)calloc(1, sizeof(Forwarding));
|
||||
Forwarding *forwarding = (Forwarding *)mem_alloc(mem, sizeof(Forwarding));
|
||||
|
||||
if (forwarding == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
forwarding->log = log;
|
||||
forwarding->mem = mem;
|
||||
forwarding->rng = rng;
|
||||
forwarding->mono_time = mono_time;
|
||||
forwarding->dht = dht;
|
||||
@ -396,5 +398,5 @@ void kill_forwarding(Forwarding *forwarding)
|
||||
|
||||
crypto_memzero(forwarding->hmac_key, CRYPTO_HMAC_KEY_SIZE);
|
||||
|
||||
free(forwarding);
|
||||
mem_delete(forwarding->mem, forwarding);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2019-2022 The TokTok team.
|
||||
* Copyright © 2019-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
#ifndef C_TOXCORE_TOXCORE_FORWARDING_H
|
||||
@ -9,6 +9,7 @@
|
||||
#include "attributes.h"
|
||||
#include "crypto_core.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "network.h"
|
||||
|
||||
@ -116,7 +117,7 @@ non_null(1) nullable(2, 3)
|
||||
void set_callback_forward_reply(Forwarding *forwarding, forward_reply_cb *function, void *object);
|
||||
|
||||
non_null()
|
||||
Forwarding *new_forwarding(const Logger *log, const Random *rng, const Mono_Time *mono_time, DHT *dht);
|
||||
Forwarding *new_forwarding(const Logger *log, const Memory *mem, const Random *rng, const Mono_Time *mono_time, DHT *dht);
|
||||
|
||||
nullable(1)
|
||||
void kill_forwarding(Forwarding *forwarding);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
*/
|
||||
#include "friend_connection.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "DHT.h"
|
||||
@ -18,6 +17,7 @@
|
||||
#include "ccompat.h"
|
||||
#include "crypto_core.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "net_crypto.h"
|
||||
#include "network.h"
|
||||
@ -69,6 +69,7 @@ static const Friend_Conn empty_friend_conn = {0};
|
||||
|
||||
struct Friend_Connections {
|
||||
const Mono_Time *mono_time;
|
||||
const Memory *mem;
|
||||
const Logger *logger;
|
||||
Net_Crypto *net_crypto;
|
||||
DHT *dht;
|
||||
@ -126,12 +127,12 @@ non_null()
|
||||
static bool realloc_friendconns(Friend_Connections *fr_c, uint32_t num)
|
||||
{
|
||||
if (num == 0) {
|
||||
free(fr_c->conns);
|
||||
mem_delete(fr_c->mem, fr_c->conns);
|
||||
fr_c->conns = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
Friend_Conn *newgroup_cons = (Friend_Conn *)realloc(fr_c->conns, num * sizeof(Friend_Conn));
|
||||
Friend_Conn *newgroup_cons = (Friend_Conn *)mem_vrealloc(fr_c->mem, fr_c->conns, num, sizeof(Friend_Conn));
|
||||
|
||||
if (newgroup_cons == nullptr) {
|
||||
return false;
|
||||
@ -912,14 +913,14 @@ int send_friend_request_packet(Friend_Connections *fr_c, int friendcon_id, uint3
|
||||
|
||||
/** Create new friend_connections instance. */
|
||||
Friend_Connections *new_friend_connections(
|
||||
const Logger *logger, const Mono_Time *mono_time, const Network *ns,
|
||||
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Network *ns,
|
||||
Onion_Client *onion_c, bool local_discovery_enabled)
|
||||
{
|
||||
if (onion_c == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Friend_Connections *const temp = (Friend_Connections *)calloc(1, sizeof(Friend_Connections));
|
||||
Friend_Connections *const temp = (Friend_Connections *)mem_alloc(mem, sizeof(Friend_Connections));
|
||||
|
||||
if (temp == nullptr) {
|
||||
return nullptr;
|
||||
@ -928,7 +929,7 @@ Friend_Connections *new_friend_connections(
|
||||
temp->local_discovery_enabled = local_discovery_enabled;
|
||||
|
||||
if (temp->local_discovery_enabled) {
|
||||
temp->broadcast = lan_discovery_init(ns);
|
||||
temp->broadcast = lan_discovery_init(mem, ns);
|
||||
|
||||
if (temp->broadcast == nullptr) {
|
||||
LOGGER_ERROR(logger, "could not initialise LAN discovery");
|
||||
@ -937,6 +938,7 @@ Friend_Connections *new_friend_connections(
|
||||
}
|
||||
|
||||
temp->mono_time = mono_time;
|
||||
temp->mem = mem;
|
||||
temp->logger = logger;
|
||||
temp->dht = onion_get_dht(onion_c);
|
||||
temp->net_crypto = onion_get_net_crypto(onion_c);
|
||||
@ -1038,9 +1040,9 @@ void kill_friend_connections(Friend_Connections *fr_c)
|
||||
|
||||
// there might be allocated NONE connections
|
||||
if (fr_c->conns != nullptr) {
|
||||
free(fr_c->conns);
|
||||
mem_delete(fr_c->mem, fr_c->conns);
|
||||
}
|
||||
|
||||
lan_discovery_kill(fr_c->broadcast);
|
||||
free(fr_c);
|
||||
mem_delete(fr_c->mem, fr_c);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -12,9 +12,9 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "DHT.h"
|
||||
#include "LAN_discovery.h"
|
||||
#include "attributes.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "net_crypto.h"
|
||||
#include "network.h"
|
||||
@ -161,7 +161,7 @@ void set_friend_request_callback(Friend_Connections *fr_c, fr_request_cb *fr_req
|
||||
/** Create new friend_connections instance. */
|
||||
non_null()
|
||||
Friend_Connections *new_friend_connections(
|
||||
const Logger *logger, const Mono_Time *mono_time, const Network *ns,
|
||||
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Network *ns,
|
||||
Onion_Client *onion_c, bool local_discovery_enabled);
|
||||
|
||||
/** main friend_connections loop. */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
@ -8,18 +8,22 @@
|
||||
*/
|
||||
#include "friend_requests.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "attributes.h"
|
||||
#include "ccompat.h"
|
||||
#include "crypto_core.h"
|
||||
#include "friend_connection.h"
|
||||
#include "mem.h"
|
||||
#include "network.h"
|
||||
#include "onion.h"
|
||||
#include "onion_announce.h"
|
||||
#include "onion_client.h"
|
||||
|
||||
static_assert(ONION_CLIENT_MAX_DATA_SIZE <= MAX_DATA_REQUEST_SIZE, "ONION_CLIENT_MAX_DATA_SIZE is too big");
|
||||
static_assert(MAX_DATA_REQUEST_SIZE <= ONION_MAX_DATA_SIZE, "MAX_DATA_REQUEST_SIZE is too big");
|
||||
static_assert(SIZE_IPPORT <= ONION_SEND_BASE, "IP_Port does not fit in the onion packet");
|
||||
|
||||
/**
|
||||
* NOTE: The following is just a temporary fix for the multiple friend requests received at the same time problem.
|
||||
* TODO(irungentoo): Make this better (This will most likely tie in with the way we will handle spam).
|
||||
@ -32,6 +36,8 @@ struct Received_Requests {
|
||||
};
|
||||
|
||||
struct Friend_Requests {
|
||||
const Memory *mem;
|
||||
|
||||
uint32_t nospam;
|
||||
fr_friend_request_cb *handle_friendrequest;
|
||||
uint8_t handle_friendrequest_isset;
|
||||
@ -164,12 +170,24 @@ void friendreq_init(Friend_Requests *fr, Friend_Connections *fr_c)
|
||||
set_friend_request_callback(fr_c, &friendreq_handlepacket, fr);
|
||||
}
|
||||
|
||||
Friend_Requests *friendreq_new(void)
|
||||
Friend_Requests *friendreq_new(const Memory *mem)
|
||||
{
|
||||
return (Friend_Requests *)calloc(1, sizeof(Friend_Requests));
|
||||
Friend_Requests *fr = (Friend_Requests *)mem_alloc(mem, sizeof(Friend_Requests));
|
||||
|
||||
if (fr == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
fr->mem = mem;
|
||||
|
||||
return fr;
|
||||
}
|
||||
|
||||
void friendreq_kill(Friend_Requests *fr)
|
||||
{
|
||||
free(fr);
|
||||
if (fr == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
mem_delete(fr->mem, fr);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
|
||||
#include "attributes.h"
|
||||
#include "friend_connection.h"
|
||||
#include "mem.h"
|
||||
|
||||
// TODO(Jfreegman): This should be the maximum size that an onion client can handle.
|
||||
#define MAX_FRIEND_REQUEST_DATA_SIZE (ONION_CLIENT_MAX_DATA_SIZE - 100)
|
||||
@ -50,7 +51,8 @@ void set_filter_function(Friend_Requests *fr, filter_function_cb *function, void
|
||||
non_null()
|
||||
void friendreq_init(Friend_Requests *fr, Friend_Connections *fr_c);
|
||||
|
||||
Friend_Requests *friendreq_new(void);
|
||||
non_null()
|
||||
Friend_Requests *friendreq_new(const Memory *mem);
|
||||
|
||||
nullable(1)
|
||||
void friendreq_kill(Friend_Requests *fr);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
#include "group.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h> // calloc, free
|
||||
#include <string.h>
|
||||
|
||||
#include "DHT.h"
|
||||
@ -149,6 +148,7 @@ typedef struct Group_c {
|
||||
} Group_c;
|
||||
|
||||
struct Group_Chats {
|
||||
const Memory *mem;
|
||||
const Mono_Time *mono_time;
|
||||
|
||||
Messenger *m;
|
||||
@ -248,19 +248,19 @@ 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()
|
||||
static bool realloc_conferences(Group_Chats *g_c, uint16_t num)
|
||||
{
|
||||
if (num == 0) {
|
||||
free(g_c->chats);
|
||||
mem_delete(g_c->mem, g_c->chats);
|
||||
g_c->chats = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
Group_c *newgroup_chats = (Group_c *)realloc(g_c->chats, num * sizeof(Group_c));
|
||||
Group_c *newgroup_chats = (Group_c *)mem_vrealloc(g_c->mem, g_c->chats, num, sizeof(Group_c));
|
||||
|
||||
if (newgroup_chats == nullptr) {
|
||||
return false;
|
||||
@ -302,10 +302,10 @@ static int32_t create_group_chat(Group_Chats *g_c)
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void wipe_group_c(Group_c *g)
|
||||
static void wipe_group_c(const Memory *mem, Group_c *g)
|
||||
{
|
||||
free(g->frozen);
|
||||
free(g->group);
|
||||
mem_delete(mem, g->frozen);
|
||||
mem_delete(mem, g->group);
|
||||
crypto_memzero(g, sizeof(Group_c));
|
||||
}
|
||||
|
||||
@ -320,7 +320,7 @@ static bool wipe_group_chat(Group_Chats *g_c, uint32_t groupnumber)
|
||||
return false;
|
||||
}
|
||||
|
||||
wipe_group_c(&g_c->chats[groupnumber]);
|
||||
wipe_group_c(g_c->mem, &g_c->chats[groupnumber]);
|
||||
|
||||
uint16_t i;
|
||||
|
||||
@ -669,7 +669,7 @@ static int get_frozen_index(const Group_c *g, uint16_t peer_number)
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool delete_frozen(Group_c *g, uint32_t frozen_index)
|
||||
static bool delete_frozen(const Memory *mem, Group_c *g, uint32_t frozen_index)
|
||||
{
|
||||
if (frozen_index >= g->numfrozen) {
|
||||
return false;
|
||||
@ -678,14 +678,14 @@ static bool delete_frozen(Group_c *g, uint32_t frozen_index)
|
||||
--g->numfrozen;
|
||||
|
||||
if (g->numfrozen == 0) {
|
||||
free(g->frozen);
|
||||
mem_delete(mem, g->frozen);
|
||||
g->frozen = nullptr;
|
||||
} else {
|
||||
if (g->numfrozen != frozen_index) {
|
||||
g->frozen[frozen_index] = g->frozen[g->numfrozen];
|
||||
}
|
||||
|
||||
Group_Peer *const frozen_temp = (Group_Peer *)realloc(g->frozen, g->numfrozen * sizeof(Group_Peer));
|
||||
Group_Peer *const frozen_temp = (Group_Peer *)mem_vrealloc(mem, g->frozen, g->numfrozen, sizeof(Group_Peer));
|
||||
|
||||
if (frozen_temp == nullptr) {
|
||||
return false;
|
||||
@ -726,7 +726,7 @@ static int note_peer_active(Group_Chats *g_c, uint32_t groupnumber, uint16_t pee
|
||||
|
||||
/* Now thaw the peer */
|
||||
|
||||
Group_Peer *temp = (Group_Peer *)realloc(g->group, (g->numpeers + 1) * sizeof(Group_Peer));
|
||||
Group_Peer *temp = (Group_Peer *)mem_vrealloc(g_c->mem, g->group, g->numpeers + 1, sizeof(Group_Peer));
|
||||
|
||||
if (temp == nullptr) {
|
||||
return -1;
|
||||
@ -743,7 +743,7 @@ static int note_peer_active(Group_Chats *g_c, uint32_t groupnumber, uint16_t pee
|
||||
|
||||
++g->numpeers;
|
||||
|
||||
delete_frozen(g, frozen_index);
|
||||
delete_frozen(g_c->mem, g, frozen_index);
|
||||
|
||||
if (g_c->peer_list_changed_callback != nullptr) {
|
||||
g_c->peer_list_changed_callback(g_c->m, groupnumber, userdata);
|
||||
@ -779,7 +779,7 @@ static void delete_any_peer_with_pk(Group_Chats *g_c, uint32_t groupnumber, cons
|
||||
const int frozen_index = frozen_in_group(g, real_pk);
|
||||
|
||||
if (frozen_index >= 0) {
|
||||
delete_frozen(g, frozen_index);
|
||||
delete_frozen(g_c->mem, g, frozen_index);
|
||||
}
|
||||
}
|
||||
|
||||
@ -839,7 +839,7 @@ static int addpeer(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_p
|
||||
|
||||
delete_any_peer_with_pk(g_c, groupnumber, real_pk, userdata);
|
||||
|
||||
Group_Peer *temp = (Group_Peer *)realloc(g->group, (g->numpeers + 1) * sizeof(Group_Peer));
|
||||
Group_Peer *temp = (Group_Peer *)mem_vrealloc(g_c->mem, g->group, g->numpeers + 1, sizeof(Group_Peer));
|
||||
|
||||
if (temp == nullptr) {
|
||||
return -1;
|
||||
@ -930,14 +930,14 @@ static bool delpeer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, void
|
||||
void *peer_object = g->group[peer_index].object;
|
||||
|
||||
if (g->numpeers == 0) {
|
||||
free(g->group);
|
||||
mem_delete(g_c->mem, g->group);
|
||||
g->group = nullptr;
|
||||
} else {
|
||||
if (g->numpeers != (uint32_t)peer_index) {
|
||||
g->group[peer_index] = g->group[g->numpeers];
|
||||
}
|
||||
|
||||
Group_Peer *temp = (Group_Peer *)realloc(g->group, g->numpeers * sizeof(Group_Peer));
|
||||
Group_Peer *temp = (Group_Peer *)mem_vrealloc(g_c->mem, g->group, g->numpeers, sizeof(Group_Peer));
|
||||
|
||||
if (temp == nullptr) {
|
||||
return false;
|
||||
@ -1034,7 +1034,7 @@ static bool delete_old_frozen(Group_c *g, const Memory *mem)
|
||||
}
|
||||
|
||||
if (g->maxfrozen == 0) {
|
||||
free(g->frozen);
|
||||
mem_delete(mem, g->frozen);
|
||||
g->frozen = nullptr;
|
||||
g->numfrozen = 0;
|
||||
return true;
|
||||
@ -1042,7 +1042,7 @@ static bool delete_old_frozen(Group_c *g, const Memory *mem)
|
||||
|
||||
merge_sort(g->frozen, g->numfrozen, mem, &group_peer_cmp_funcs);
|
||||
|
||||
Group_Peer *temp = (Group_Peer *)realloc(g->frozen, g->maxfrozen * sizeof(Group_Peer));
|
||||
Group_Peer *temp = (Group_Peer *)mem_vrealloc(mem, g->frozen, g->maxfrozen, sizeof(Group_Peer));
|
||||
|
||||
if (temp == nullptr) {
|
||||
return false;
|
||||
@ -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 *)realloc(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;
|
||||
}
|
||||
|
||||
@ -3665,7 +3665,7 @@ static uint32_t load_group(Group_c *g, const Group_Chats *g_c, const uint8_t *da
|
||||
}
|
||||
|
||||
// This is inefficient, but allows us to check data consistency before allocating memory
|
||||
Group_Peer *tmp_frozen = (Group_Peer *)realloc(g->frozen, (j + 1) * sizeof(Group_Peer));
|
||||
Group_Peer *tmp_frozen = (Group_Peer *)mem_vrealloc(g_c->mem, g->frozen, j + 1, sizeof(Group_Peer));
|
||||
|
||||
if (tmp_frozen == nullptr) {
|
||||
// Memory allocation failure
|
||||
@ -3805,18 +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 *)calloc(1, sizeof(Group_Chats));
|
||||
Group_Chats *temp = (Group_Chats *)mem_alloc(mem, sizeof(Group_Chats));
|
||||
|
||||
if (temp == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
temp->mem = mem;
|
||||
temp->mono_time = mono_time;
|
||||
temp->m = m;
|
||||
temp->fr_c = m->fr_c;
|
||||
@ -3867,7 +3868,7 @@ void kill_groupchats(Group_Chats *g_c)
|
||||
m_callback_conference_invite(g_c->m, nullptr);
|
||||
set_global_status_callback(g_c->m->fr_c, nullptr, nullptr);
|
||||
g_c->m->conferences_object = nullptr;
|
||||
free(g_c);
|
||||
mem_delete(g_c->mem, g_c);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -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)
|
||||
|
@ -5,7 +5,6 @@
|
||||
|
||||
#include "group_announce.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "DHT.h"
|
||||
@ -13,6 +12,7 @@
|
||||
#include "ccompat.h"
|
||||
#include "crypto_core.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "network.h"
|
||||
|
||||
@ -36,7 +36,7 @@ static void remove_announces(GC_Announces_List *gc_announces_list, GC_Announces
|
||||
announces->next_announce->prev_announce = announces->prev_announce;
|
||||
}
|
||||
|
||||
free(announces);
|
||||
mem_delete(gc_announces_list->mem, announces);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -343,10 +343,11 @@ int gca_unpack_announces_list(const Logger *log, const uint8_t *data, uint16_t l
|
||||
|
||||
non_null()
|
||||
static GC_Announces *gca_new_announces(
|
||||
const Memory *mem,
|
||||
GC_Announces_List *gc_announces_list,
|
||||
const GC_Public_Announce *public_announce)
|
||||
{
|
||||
GC_Announces *announces = (GC_Announces *)calloc(1, sizeof(GC_Announces));
|
||||
GC_Announces *announces = (GC_Announces *)mem_alloc(mem, sizeof(GC_Announces));
|
||||
|
||||
if (announces == nullptr) {
|
||||
return nullptr;
|
||||
@ -366,7 +367,7 @@ static GC_Announces *gca_new_announces(
|
||||
return announces;
|
||||
}
|
||||
|
||||
GC_Peer_Announce *gca_add_announce(const Mono_Time *mono_time, GC_Announces_List *gc_announces_list,
|
||||
GC_Peer_Announce *gca_add_announce(const Memory *mem, const Mono_Time *mono_time, GC_Announces_List *gc_announces_list,
|
||||
const GC_Public_Announce *public_announce)
|
||||
{
|
||||
if (gc_announces_list == nullptr || public_announce == nullptr) {
|
||||
@ -377,7 +378,7 @@ GC_Peer_Announce *gca_add_announce(const Mono_Time *mono_time, GC_Announces_List
|
||||
|
||||
// No entry for this chat_id exists so we create one
|
||||
if (announces == nullptr) {
|
||||
announces = gca_new_announces(gc_announces_list, public_announce);
|
||||
announces = gca_new_announces(mem, gc_announces_list, public_announce);
|
||||
|
||||
if (announces == nullptr) {
|
||||
return nullptr;
|
||||
@ -410,9 +411,17 @@ bool gca_is_valid_announce(const GC_Announce *announce)
|
||||
return announce->tcp_relays_count > 0 || announce->ip_port_is_set;
|
||||
}
|
||||
|
||||
GC_Announces_List *new_gca_list(void)
|
||||
GC_Announces_List *new_gca_list(const Memory *mem)
|
||||
{
|
||||
return (GC_Announces_List *)calloc(1, sizeof(GC_Announces_List));
|
||||
GC_Announces_List *announces_list = (GC_Announces_List *)mem_alloc(mem, sizeof(GC_Announces_List));
|
||||
|
||||
if (announces_list == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
announces_list->mem = mem;
|
||||
|
||||
return announces_list;
|
||||
}
|
||||
|
||||
void kill_gca(GC_Announces_List *announces_list)
|
||||
@ -425,11 +434,11 @@ void kill_gca(GC_Announces_List *announces_list)
|
||||
|
||||
while (root != nullptr) {
|
||||
GC_Announces *next = root->next_announce;
|
||||
free(root);
|
||||
mem_delete(announces_list->mem, root);
|
||||
root = next;
|
||||
}
|
||||
|
||||
free(announces_list);
|
||||
mem_delete(announces_list->mem, announces_list);
|
||||
}
|
||||
|
||||
/* How long we save a peer's announce before we consider it stale and remove it. */
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "attributes.h"
|
||||
#include "crypto_core.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "network.h"
|
||||
|
||||
@ -79,6 +80,8 @@ struct GC_Announces {
|
||||
|
||||
/* A list of all announces. */
|
||||
struct GC_Announces_List {
|
||||
const Memory *mem;
|
||||
|
||||
GC_Announces *root_announces;
|
||||
uint64_t last_timeout_check;
|
||||
};
|
||||
@ -87,7 +90,8 @@ struct GC_Announces_List {
|
||||
*
|
||||
* The caller is responsible for freeing the memory with `kill_gca`.
|
||||
*/
|
||||
GC_Announces_List *new_gca_list(void);
|
||||
non_null()
|
||||
GC_Announces_List *new_gca_list(const Memory *mem);
|
||||
|
||||
/** @brief Frees all dynamically allocated memory associated with `announces_list`. */
|
||||
nullable(1)
|
||||
@ -135,7 +139,7 @@ int gca_get_announces(const GC_Announces_List *gc_announces_list, GC_Announce *g
|
||||
* @retval null on failure.
|
||||
*/
|
||||
non_null()
|
||||
GC_Peer_Announce *gca_add_announce(const Mono_Time *mono_time, GC_Announces_List *gc_announces_list,
|
||||
GC_Peer_Announce *gca_add_announce(const Memory *mem, const Mono_Time *mono_time, GC_Announces_List *gc_announces_list,
|
||||
const GC_Public_Announce *public_announce);
|
||||
|
||||
/** @brief Packs an announce into a data buffer.
|
||||
|
@ -60,7 +60,8 @@ void TestDoGca(Fuzz_Data &input)
|
||||
mem, [](void *user_data) { return *static_cast<uint64_t *>(user_data); }, &clock),
|
||||
[mem](Mono_Time *ptr) { mono_time_free(mem, ptr); });
|
||||
assert(mono_time != nullptr);
|
||||
std::unique_ptr<GC_Announces_List, void (*)(GC_Announces_List *)> gca(new_gca_list(), kill_gca);
|
||||
std::unique_ptr<GC_Announces_List, void (*)(GC_Announces_List *)> gca(
|
||||
new_gca_list(mem), kill_gca);
|
||||
assert(gca != nullptr);
|
||||
|
||||
while (!input.empty()) {
|
||||
@ -72,7 +73,7 @@ void TestDoGca(Fuzz_Data &input)
|
||||
CONSUME_OR_RETURN(const uint8_t *data, input, length);
|
||||
GC_Public_Announce public_announce;
|
||||
if (gca_unpack_public_announce(logger.get(), data, length, &public_announce) != -1) {
|
||||
gca_add_announce(mono_time.get(), gca.get(), &public_announce);
|
||||
gca_add_announce(mem, mono_time.get(), gca.get(), &public_announce);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ protected:
|
||||
mono_time_set_current_time_callback(
|
||||
mono_time_, [](void *user_data) { return *static_cast<uint64_t *>(user_data); },
|
||||
&clock_);
|
||||
gca_ = new_gca_list();
|
||||
gca_ = new_gca_list(mem_);
|
||||
ASSERT_NE(gca_, nullptr);
|
||||
}
|
||||
|
||||
@ -54,10 +54,10 @@ TEST_F(Announces, CanBeCreatedAndDeleted)
|
||||
{
|
||||
GC_Public_Announce ann{};
|
||||
ann.chat_public_key[0] = 0x88;
|
||||
ASSERT_NE(gca_add_announce(mono_time_, gca_, &ann), nullptr);
|
||||
ASSERT_NE(gca_add_announce(mem_, mono_time_, gca_, &ann), nullptr);
|
||||
#ifndef _DEBUG
|
||||
ASSERT_EQ(gca_add_announce(mono_time_, gca_, nullptr), nullptr);
|
||||
ASSERT_EQ(gca_add_announce(mono_time_, nullptr, &ann), nullptr);
|
||||
ASSERT_EQ(gca_add_announce(mem_, mono_time_, gca_, nullptr), nullptr);
|
||||
ASSERT_EQ(gca_add_announce(mem_, mono_time_, nullptr, &ann), nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ TEST_F(Announces, AnnouncesCanTimeOut)
|
||||
ASSERT_EQ(gca_->root_announces, nullptr);
|
||||
GC_Public_Announce ann{};
|
||||
ann.chat_public_key[0] = 0xae;
|
||||
ASSERT_NE(gca_add_announce(mono_time_, gca_, &ann), nullptr);
|
||||
ASSERT_NE(gca_add_announce(mem_, mono_time_, gca_, &ann), nullptr);
|
||||
ASSERT_NE(gca_->root_announces, nullptr);
|
||||
ASSERT_EQ(gca_->root_announces->chat_id[0], 0xae);
|
||||
|
||||
@ -95,9 +95,9 @@ TEST_F(Announces, AnnouncesGetAndCleanup)
|
||||
ann2.chat_public_key[0] = 0x92;
|
||||
ann2.base_announce.peer_public_key[0] = 0x7c;
|
||||
|
||||
ASSERT_NE(gca_add_announce(mono_time_, gca_, &ann1), nullptr);
|
||||
ASSERT_NE(gca_add_announce(mono_time_, gca_, &ann2), nullptr);
|
||||
ASSERT_NE(gca_add_announce(mono_time_, gca_, &ann2), nullptr);
|
||||
ASSERT_NE(gca_add_announce(mem_, mono_time_, gca_, &ann1), nullptr);
|
||||
ASSERT_NE(gca_add_announce(mem_, mono_time_, gca_, &ann2), nullptr);
|
||||
ASSERT_NE(gca_add_announce(mem_, mono_time_, gca_, &ann2), nullptr);
|
||||
|
||||
uint8_t empty_pk[ENC_PUBLIC_KEY_SIZE] = {0};
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -650,7 +650,7 @@ int gc_group_add(GC_Session *c, Group_Privacy_State privacy_state, const uint8_t
|
||||
*
|
||||
* Return group_number on success.
|
||||
* Return -1 if the group object fails to initialize.
|
||||
* Return -2 if chat_id is NULL or a group with chat_id already exists in the chats array.
|
||||
* Return -2 if chat_id is NULL.
|
||||
* Return -3 if nick is too long.
|
||||
* Return -4 if nick is empty or nick length is zero.
|
||||
* Return -5 if there is an error setting the group password.
|
||||
@ -676,8 +676,8 @@ bool gc_disconnect_from_group(const GC_Session *c, GC_Chat *chat);
|
||||
* Returns -1 if the group handler object or chat object is null.
|
||||
* Returns -2 if the Messenger friend connection fails to initialize.
|
||||
*/
|
||||
non_null()
|
||||
int gc_rejoin_group(GC_Session *c, GC_Chat *chat);
|
||||
non_null(1, 2) nullable(3)
|
||||
int gc_rejoin_group(GC_Session *c, GC_Chat *chat, const uint8_t *passwd, uint16_t passwd_len);
|
||||
|
||||
/** @brief Joins a group using the invite data received in a friend's group invite.
|
||||
*
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2022 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "DHT.h"
|
||||
@ -22,6 +21,7 @@
|
||||
#include "group_chats.h"
|
||||
#include "group_common.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "network.h"
|
||||
#include "util.h"
|
||||
@ -39,9 +39,9 @@ static bool array_entry_is_empty(const GC_Message_Array_Entry *array_entry)
|
||||
|
||||
/** @brief Clears an array entry. */
|
||||
non_null()
|
||||
static void clear_array_entry(GC_Message_Array_Entry *const array_entry)
|
||||
static void clear_array_entry(const Memory *mem, GC_Message_Array_Entry *const array_entry)
|
||||
{
|
||||
free(array_entry->data);
|
||||
mem_delete(mem, array_entry->data);
|
||||
|
||||
*array_entry = (GC_Message_Array_Entry) {
|
||||
nullptr
|
||||
@ -54,14 +54,14 @@ static void clear_array_entry(GC_Message_Array_Entry *const array_entry)
|
||||
* to `start_id`.
|
||||
*/
|
||||
non_null()
|
||||
static void clear_send_queue_id_range(GC_Connection *gconn, uint64_t start_id, uint64_t end_id)
|
||||
static void clear_send_queue_id_range(const Memory *mem, GC_Connection *gconn, uint64_t start_id, uint64_t end_id)
|
||||
{
|
||||
const uint16_t start_idx = gcc_get_array_index(start_id);
|
||||
const uint16_t end_idx = gcc_get_array_index(end_id);
|
||||
|
||||
for (uint16_t i = start_idx; i != end_idx; i = (i + 1) % GCC_BUFFER_SIZE) {
|
||||
GC_Message_Array_Entry *entry = &gconn->send_array[i];
|
||||
clear_array_entry(entry);
|
||||
clear_array_entry(mem, entry);
|
||||
}
|
||||
|
||||
gconn->send_message_id = start_id;
|
||||
@ -90,8 +90,8 @@ void gcc_set_recv_message_id(GC_Connection *gconn, uint64_t id)
|
||||
*
|
||||
* Return true on success.
|
||||
*/
|
||||
non_null(1, 2, 3) nullable(4)
|
||||
static bool create_array_entry(const Logger *log, const Mono_Time *mono_time, GC_Message_Array_Entry *array_entry,
|
||||
non_null(1, 2, 3, 4) nullable(5)
|
||||
static bool create_array_entry(const Logger *log, const Memory *mem, const Mono_Time *mono_time, GC_Message_Array_Entry *array_entry,
|
||||
const uint8_t *data, uint16_t length, uint8_t packet_type, uint64_t message_id)
|
||||
{
|
||||
if (!array_entry_is_empty(array_entry)) {
|
||||
@ -109,7 +109,7 @@ static bool create_array_entry(const Logger *log, const Mono_Time *mono_time, GC
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t *entry_data = (uint8_t *)malloc(length);
|
||||
uint8_t *entry_data = (uint8_t *)mem_balloc(mem, length);
|
||||
|
||||
if (entry_data == nullptr) {
|
||||
return false;
|
||||
@ -134,9 +134,9 @@ static bool create_array_entry(const Logger *log, const Mono_Time *mono_time, GC
|
||||
*
|
||||
* Returns true and increments gconn's send_message_id on success.
|
||||
*/
|
||||
non_null(1, 2, 3) nullable(4)
|
||||
static bool add_to_send_array(const Logger *log, const Mono_Time *mono_time, GC_Connection *gconn, const uint8_t *data,
|
||||
uint16_t length, uint8_t packet_type)
|
||||
non_null(1, 2, 3, 4) nullable(5)
|
||||
static bool add_to_send_array(const Logger *log, const Memory *mem, const Mono_Time *mono_time, GC_Connection *gconn,
|
||||
const uint8_t *data, uint16_t length, uint8_t packet_type)
|
||||
{
|
||||
/* check if send_array is full */
|
||||
if ((gconn->send_message_id % GCC_BUFFER_SIZE) == (uint16_t)(gconn->send_array_start - 1)) {
|
||||
@ -147,7 +147,7 @@ static bool add_to_send_array(const Logger *log, const Mono_Time *mono_time, GC_
|
||||
const uint16_t idx = gcc_get_array_index(gconn->send_message_id);
|
||||
GC_Message_Array_Entry *array_entry = &gconn->send_array[idx];
|
||||
|
||||
if (!create_array_entry(log, mono_time, array_entry, data, length, packet_type, gconn->send_message_id)) {
|
||||
if (!create_array_entry(log, mem, mono_time, array_entry, data, length, packet_type, gconn->send_message_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ int gcc_send_lossless_packet(const GC_Chat *chat, GC_Connection *gconn, const ui
|
||||
{
|
||||
const uint64_t message_id = gconn->send_message_id;
|
||||
|
||||
if (!add_to_send_array(chat->log, chat->mono_time, gconn, data, length, packet_type)) {
|
||||
if (!add_to_send_array(chat->log, chat->mem, chat->mono_time, gconn, data, length, packet_type)) {
|
||||
LOGGER_WARNING(chat->log, "Failed to add payload to send array: (type: 0x%02x, length: %d)", packet_type, length);
|
||||
return -1;
|
||||
}
|
||||
@ -172,7 +172,7 @@ int gcc_send_lossless_packet(const GC_Chat *chat, GC_Connection *gconn, const ui
|
||||
if (gcc_encrypt_and_send_lossless_packet(chat, gconn, data, length, message_id, packet_type) == -1) {
|
||||
const uint16_t idx = gcc_get_array_index(message_id);
|
||||
GC_Message_Array_Entry *array_entry = &gconn->send_array[idx];
|
||||
clear_array_entry(array_entry);
|
||||
clear_array_entry(chat->mem, array_entry);
|
||||
gconn->send_message_id = message_id;
|
||||
LOGGER_ERROR(chat->log, "Failed to encrypt payload: (type: 0x%02x, length: %d)", packet_type, length);
|
||||
return -2;
|
||||
@ -196,7 +196,7 @@ bool gcc_send_lossless_packet_fragments(const GC_Chat *chat, GC_Connection *gcon
|
||||
chunk[0] = packet_type;
|
||||
memcpy(chunk + 1, data, MAX_GC_PACKET_CHUNK_SIZE - 1);
|
||||
|
||||
if (!add_to_send_array(chat->log, chat->mono_time, gconn, chunk, MAX_GC_PACKET_CHUNK_SIZE, GP_FRAGMENT)) {
|
||||
if (!add_to_send_array(chat->log, chat->mem, chat->mono_time, gconn, chunk, MAX_GC_PACKET_CHUNK_SIZE, GP_FRAGMENT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -209,15 +209,15 @@ bool gcc_send_lossless_packet_fragments(const GC_Chat *chat, GC_Connection *gcon
|
||||
memcpy(chunk, data + processed, chunk_len);
|
||||
processed += chunk_len;
|
||||
|
||||
if (!add_to_send_array(chat->log, chat->mono_time, gconn, chunk, chunk_len, GP_FRAGMENT)) {
|
||||
clear_send_queue_id_range(gconn, start_id, gconn->send_message_id);
|
||||
if (!add_to_send_array(chat->log, chat->mem, chat->mono_time, gconn, chunk, chunk_len, GP_FRAGMENT)) {
|
||||
clear_send_queue_id_range(chat->mem, gconn, start_id, gconn->send_message_id);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// empty packet signals the end of the sequence
|
||||
if (!add_to_send_array(chat->log, chat->mono_time, gconn, nullptr, 0, GP_FRAGMENT)) {
|
||||
clear_send_queue_id_range(gconn, start_id, gconn->send_message_id);
|
||||
if (!add_to_send_array(chat->log, chat->mem, chat->mono_time, gconn, nullptr, 0, GP_FRAGMENT)) {
|
||||
clear_send_queue_id_range(chat->mem, gconn, start_id, gconn->send_message_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ bool gcc_send_lossless_packet_fragments(const GC_Chat *chat, GC_Connection *gcon
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gcc_handle_ack(const Logger *log, GC_Connection *gconn, uint64_t message_id)
|
||||
bool gcc_handle_ack(const Logger *log, const Memory *mem, GC_Connection *gconn, uint64_t message_id)
|
||||
{
|
||||
uint16_t idx = gcc_get_array_index(message_id);
|
||||
GC_Message_Array_Entry *array_entry = &gconn->send_array[idx];
|
||||
@ -255,7 +255,7 @@ bool gcc_handle_ack(const Logger *log, GC_Connection *gconn, uint64_t message_id
|
||||
return false;
|
||||
}
|
||||
|
||||
clear_array_entry(array_entry);
|
||||
clear_array_entry(mem, array_entry);
|
||||
|
||||
/* Put send_array_start in proper position */
|
||||
if (idx == gconn->send_array_start) {
|
||||
@ -336,15 +336,15 @@ int gcc_save_tcp_relay(const Random *rng, GC_Connection *gconn, const Node_forma
|
||||
*
|
||||
* Return true on success.
|
||||
*/
|
||||
non_null(1, 2, 3) nullable(4)
|
||||
static bool store_in_recv_array(const Logger *log, const Mono_Time *mono_time, GC_Connection *gconn,
|
||||
const uint8_t *data,
|
||||
non_null(1, 2, 3, 4) nullable(5)
|
||||
static bool store_in_recv_array(const Logger *log, const Memory *mem, const Mono_Time *mono_time,
|
||||
GC_Connection *gconn, const uint8_t *data,
|
||||
uint16_t length, uint8_t packet_type, uint64_t message_id)
|
||||
{
|
||||
const uint16_t idx = gcc_get_array_index(message_id);
|
||||
GC_Message_Array_Entry *ary_entry = &gconn->recv_array[idx];
|
||||
|
||||
return create_array_entry(log, mono_time, ary_entry, data, length, packet_type, message_id);
|
||||
return create_array_entry(log, mem, mono_time, ary_entry, data, length, packet_type, message_id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -358,8 +358,8 @@ static bool store_in_recv_array(const Logger *log, const Mono_Time *mono_time, G
|
||||
* Return the length of the fully reassembled packet on success.
|
||||
* Return 0 on failure.
|
||||
*/
|
||||
non_null(1, 3) nullable(2)
|
||||
static uint16_t reassemble_packet(const Logger *log, GC_Connection *gconn, uint8_t **payload, uint64_t message_id)
|
||||
non_null(1, 2, 4) nullable(3)
|
||||
static uint16_t reassemble_packet(const Logger *log, const Memory *mem, GC_Connection *gconn, uint8_t **payload, uint64_t message_id)
|
||||
{
|
||||
uint16_t end_idx = gcc_get_array_index(message_id - 1);
|
||||
uint16_t start_idx = end_idx;
|
||||
@ -395,7 +395,7 @@ static uint16_t reassemble_packet(const Logger *log, GC_Connection *gconn, uint8
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t *tmp_payload = (uint8_t *)malloc(packet_length);
|
||||
uint8_t *tmp_payload = (uint8_t *)mem_balloc(mem, packet_length);
|
||||
|
||||
if (tmp_payload == nullptr) {
|
||||
LOGGER_ERROR(log, "Failed to allocate %u bytes for payload buffer", packet_length);
|
||||
@ -414,7 +414,7 @@ static uint16_t reassemble_packet(const Logger *log, GC_Connection *gconn, uint8
|
||||
memcpy(tmp_payload + processed, entry->data, entry->data_length);
|
||||
processed += entry->data_length;
|
||||
|
||||
clear_array_entry(entry);
|
||||
clear_array_entry(mem, entry);
|
||||
}
|
||||
|
||||
assert(*payload == nullptr);
|
||||
@ -428,7 +428,7 @@ int gcc_handle_packet_fragment(const GC_Session *c, GC_Chat *chat, uint32_t peer
|
||||
uint64_t message_id, void *userdata)
|
||||
{
|
||||
if (length > 0) {
|
||||
if (!store_in_recv_array(chat->log, chat->mono_time, gconn, chunk, length, packet_type, message_id)) {
|
||||
if (!store_in_recv_array(chat->log, chat->mem, chat->mono_time, gconn, chunk, length, packet_type, message_id)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -442,15 +442,15 @@ int gcc_handle_packet_fragment(const GC_Session *c, GC_Chat *chat, uint32_t peer
|
||||
memcpy(sender_pk, get_enc_key(&gconn->addr.public_key), ENC_PUBLIC_KEY_SIZE);
|
||||
|
||||
uint8_t *payload = nullptr;
|
||||
const uint16_t processed_len = reassemble_packet(chat->log, gconn, &payload, message_id);
|
||||
const uint16_t processed_len = reassemble_packet(chat->log, chat->mem, gconn, &payload, message_id);
|
||||
|
||||
if (processed_len == 0) {
|
||||
free(payload);
|
||||
mem_delete(chat->mem, payload);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!handle_gc_lossless_helper(c, chat, peer_number, payload + 1, processed_len - 1, payload[0], userdata)) {
|
||||
free(payload);
|
||||
mem_delete(chat->mem, payload);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -459,19 +459,19 @@ int gcc_handle_packet_fragment(const GC_Session *c, GC_Chat *chat, uint32_t peer
|
||||
gconn = get_gc_connection(chat, peer_number);
|
||||
|
||||
if (gconn == nullptr) {
|
||||
free(payload);
|
||||
mem_delete(chat->mem, payload);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gcc_set_recv_message_id(gconn, gconn->received_message_id + 1);
|
||||
gconn->last_chunk_id = 0;
|
||||
|
||||
free(payload);
|
||||
mem_delete(chat->mem, payload);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gcc_handle_received_message(const Logger *log, const Mono_Time *mono_time, GC_Connection *gconn,
|
||||
int gcc_handle_received_message(const Logger *log, const Memory *mem, const Mono_Time *mono_time, GC_Connection *gconn,
|
||||
const uint8_t *data, uint16_t length, uint8_t packet_type, uint64_t message_id,
|
||||
bool direct_conn)
|
||||
{
|
||||
@ -490,7 +490,7 @@ int gcc_handle_received_message(const Logger *log, const Mono_Time *mono_time, G
|
||||
|
||||
/* we're missing an older message from this peer so we store it in recv_array */
|
||||
if (message_id > gconn->received_message_id + 1) {
|
||||
if (!store_in_recv_array(log, mono_time, gconn, data, length, packet_type, message_id)) {
|
||||
if (!store_in_recv_array(log, mem, mono_time, gconn, data, length, packet_type, message_id)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -522,7 +522,7 @@ static bool process_recv_array_entry(const GC_Session *c, GC_Chat *chat, GC_Conn
|
||||
peer_number = get_peer_number_of_enc_pk(chat, sender_pk, false);
|
||||
gconn = get_gc_connection(chat, peer_number);
|
||||
|
||||
clear_array_entry(array_entry);
|
||||
clear_array_entry(chat->mem, array_entry);
|
||||
|
||||
if (gconn == nullptr) {
|
||||
return true;
|
||||
@ -621,7 +621,7 @@ int gcc_encrypt_and_send_lossless_packet(const GC_Chat *chat, const GC_Connectio
|
||||
uint16_t length, uint64_t message_id, uint8_t packet_type)
|
||||
{
|
||||
const uint16_t packet_size = gc_get_wrapped_packet_size(length, NET_PACKET_GC_LOSSLESS);
|
||||
uint8_t *packet = (uint8_t *)malloc(packet_size);
|
||||
uint8_t *packet = (uint8_t *)mem_balloc(chat->mem, packet_size);
|
||||
|
||||
if (packet == nullptr) {
|
||||
LOGGER_ERROR(chat->log, "Failed to allocate memory for packet buffer");
|
||||
@ -634,17 +634,17 @@ int gcc_encrypt_and_send_lossless_packet(const GC_Chat *chat, const GC_Connectio
|
||||
|
||||
if (enc_len < 0) {
|
||||
LOGGER_ERROR(chat->log, "Failed to wrap packet (type: 0x%02x, error: %d)", packet_type, enc_len);
|
||||
free(packet);
|
||||
mem_delete(chat->mem, packet);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!gcc_send_packet(chat, gconn, packet, (uint16_t)enc_len)) {
|
||||
LOGGER_DEBUG(chat->log, "Failed to send packet (type: 0x%02x, enc_len: %d)", packet_type, enc_len);
|
||||
free(packet);
|
||||
mem_delete(chat->mem, packet);
|
||||
return -2;
|
||||
}
|
||||
|
||||
free(packet);
|
||||
mem_delete(chat->mem, packet);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -686,15 +686,15 @@ void gcc_mark_for_deletion(GC_Connection *gconn, TCP_Connections *tcp_conn, Grou
|
||||
}
|
||||
}
|
||||
|
||||
void gcc_peer_cleanup(GC_Connection *gconn)
|
||||
void gcc_peer_cleanup(const Memory *mem, GC_Connection *gconn)
|
||||
{
|
||||
for (size_t i = 0; i < GCC_BUFFER_SIZE; ++i) {
|
||||
free(gconn->send_array[i].data);
|
||||
free(gconn->recv_array[i].data);
|
||||
mem_delete(mem, gconn->send_array[i].data);
|
||||
mem_delete(mem, gconn->recv_array[i].data);
|
||||
}
|
||||
|
||||
free(gconn->recv_array);
|
||||
free(gconn->send_array);
|
||||
mem_delete(mem, gconn->recv_array);
|
||||
mem_delete(mem, gconn->send_array);
|
||||
|
||||
crypto_memunlock(gconn->session_secret_key, sizeof(gconn->session_secret_key));
|
||||
crypto_memunlock(gconn->session_shared_key, sizeof(gconn->session_shared_key));
|
||||
@ -707,6 +707,6 @@ void gcc_cleanup(const GC_Chat *chat)
|
||||
GC_Connection *gconn = get_gc_connection(chat, i);
|
||||
assert(gconn != nullptr);
|
||||
|
||||
gcc_peer_cleanup(gconn);
|
||||
gcc_peer_cleanup(chat->mem, gconn);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "crypto_core.h"
|
||||
#include "group_common.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "mono_time.h"
|
||||
#include "network.h"
|
||||
|
||||
@ -35,8 +36,8 @@ void gcc_mark_for_deletion(GC_Connection *gconn, TCP_Connections *tcp_conn, Grou
|
||||
* Return 0 if message is a duplicate.
|
||||
* Return -1 on failure
|
||||
*/
|
||||
non_null(1, 2, 3) nullable(4)
|
||||
int gcc_handle_received_message(const Logger *log, const Mono_Time *mono_time, GC_Connection *gconn,
|
||||
non_null(1, 2, 3, 4) nullable(5)
|
||||
int gcc_handle_received_message(const Logger *log, const Memory *mem, const Mono_Time *mono_time, GC_Connection *gconn,
|
||||
const uint8_t *data, uint16_t length, uint8_t packet_type, uint64_t message_id,
|
||||
bool direct_conn);
|
||||
|
||||
@ -63,7 +64,7 @@ uint16_t gcc_get_array_index(uint64_t message_id);
|
||||
* Return true on success.
|
||||
*/
|
||||
non_null()
|
||||
bool gcc_handle_ack(const Logger *log, GC_Connection *gconn, uint64_t message_id);
|
||||
bool gcc_handle_ack(const Logger *log, const Memory *mem, GC_Connection *gconn, uint64_t message_id);
|
||||
|
||||
/** @brief Sets the send_message_id and send_array_start for `gconn` to `id`.
|
||||
*
|
||||
@ -188,7 +189,7 @@ int gcc_encrypt_and_send_lossless_packet(const GC_Chat *chat, const GC_Connectio
|
||||
|
||||
/** @brief Called when a peer leaves the group. */
|
||||
non_null()
|
||||
void gcc_peer_cleanup(GC_Connection *gconn);
|
||||
void gcc_peer_cleanup(const Memory *mem, GC_Connection *gconn);
|
||||
|
||||
/** @brief Called on group exit. */
|
||||
non_null()
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
@ -20,6 +19,7 @@
|
||||
#include "ccompat.h"
|
||||
#include "crypto_core.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "network.h"
|
||||
#include "util.h"
|
||||
|
||||
@ -51,7 +51,7 @@ int mod_list_unpack(Moderation *moderation, const uint8_t *data, uint16_t length
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t **tmp_list = (uint8_t **)calloc(num_mods, sizeof(uint8_t *));
|
||||
uint8_t **tmp_list = (uint8_t **)mem_valloc(moderation->mem, num_mods, sizeof(uint8_t *));
|
||||
|
||||
if (tmp_list == nullptr) {
|
||||
return -1;
|
||||
@ -60,7 +60,7 @@ int mod_list_unpack(Moderation *moderation, const uint8_t *data, uint16_t length
|
||||
uint16_t unpacked_len = 0;
|
||||
|
||||
for (uint16_t i = 0; i < num_mods; ++i) {
|
||||
uint8_t *entry = (uint8_t *)malloc(MOD_LIST_ENTRY_SIZE);
|
||||
uint8_t *entry = (uint8_t *)mem_balloc(moderation->mem, MOD_LIST_ENTRY_SIZE);
|
||||
|
||||
if (entry == nullptr) {
|
||||
free_uint8_t_pointer_array(moderation->mem, tmp_list, i);
|
||||
@ -102,7 +102,7 @@ bool mod_list_make_hash(const Moderation *moderation, uint8_t *hash)
|
||||
|
||||
assert(data_buf_size > 0);
|
||||
|
||||
uint8_t *data = (uint8_t *)malloc(data_buf_size);
|
||||
uint8_t *data = (uint8_t *)mem_balloc(moderation->mem, data_buf_size);
|
||||
|
||||
if (data == nullptr) {
|
||||
return false;
|
||||
@ -112,7 +112,7 @@ bool mod_list_make_hash(const Moderation *moderation, uint8_t *hash)
|
||||
|
||||
mod_list_get_data_hash(hash, data, data_buf_size);
|
||||
|
||||
free(data);
|
||||
mem_delete(moderation->mem, data);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -166,10 +166,10 @@ bool mod_list_remove_index(Moderation *moderation, uint16_t index)
|
||||
MOD_LIST_ENTRY_SIZE);
|
||||
}
|
||||
|
||||
free(moderation->mod_list[moderation->num_mods]);
|
||||
mem_delete(moderation->mem, moderation->mod_list[moderation->num_mods]);
|
||||
moderation->mod_list[moderation->num_mods] = nullptr;
|
||||
|
||||
uint8_t **tmp_list = (uint8_t **)realloc(moderation->mod_list, moderation->num_mods * sizeof(uint8_t *));
|
||||
uint8_t **tmp_list = (uint8_t **)mem_vrealloc(moderation->mem, moderation->mod_list, moderation->num_mods, sizeof(uint8_t *));
|
||||
|
||||
if (tmp_list == nullptr) {
|
||||
return false;
|
||||
@ -203,7 +203,7 @@ bool mod_list_add_entry(Moderation *moderation, const uint8_t *mod_data)
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t **tmp_list = (uint8_t **)realloc(moderation->mod_list, (moderation->num_mods + 1) * sizeof(uint8_t *));
|
||||
uint8_t **tmp_list = (uint8_t **)mem_vrealloc(moderation->mem, moderation->mod_list, moderation->num_mods + 1, sizeof(uint8_t *));
|
||||
|
||||
if (tmp_list == nullptr) {
|
||||
return false;
|
||||
@ -211,7 +211,7 @@ bool mod_list_add_entry(Moderation *moderation, const uint8_t *mod_data)
|
||||
|
||||
moderation->mod_list = tmp_list;
|
||||
|
||||
uint8_t *entry = (uint8_t *)malloc(MOD_LIST_ENTRY_SIZE);
|
||||
uint8_t *entry = (uint8_t *)mem_balloc(moderation->mem, MOD_LIST_ENTRY_SIZE);
|
||||
|
||||
if (entry == nullptr) {
|
||||
return false;
|
||||
@ -405,8 +405,8 @@ int sanctions_list_unpack(Mod_Sanction *sanctions, Mod_Sanction_Creds *creds, ui
|
||||
*
|
||||
* Return true on success.
|
||||
*/
|
||||
non_null(4) nullable(1)
|
||||
static bool sanctions_list_make_hash(const Mod_Sanction *sanctions, uint32_t new_version, uint16_t num_sanctions,
|
||||
non_null(1, 5) nullable(2)
|
||||
static bool sanctions_list_make_hash(const Memory *mem, const Mod_Sanction *sanctions, uint32_t new_version, uint16_t num_sanctions,
|
||||
uint8_t *hash)
|
||||
{
|
||||
if (num_sanctions == 0 || sanctions == nullptr) {
|
||||
@ -422,7 +422,7 @@ static bool sanctions_list_make_hash(const Mod_Sanction *sanctions, uint32_t new
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t *data = (uint8_t *)malloc(data_buf_size);
|
||||
uint8_t *data = (uint8_t *)mem_balloc(mem, data_buf_size);
|
||||
|
||||
if (data == nullptr) {
|
||||
return false;
|
||||
@ -435,7 +435,7 @@ static bool sanctions_list_make_hash(const Mod_Sanction *sanctions, uint32_t new
|
||||
memcpy(&data[sig_data_size], &new_version, sizeof(uint32_t));
|
||||
crypto_sha256(hash, data, data_buf_size);
|
||||
|
||||
free(data);
|
||||
mem_delete(mem, data);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -492,7 +492,7 @@ bool sanctions_list_make_creds(Moderation *moderation)
|
||||
|
||||
uint8_t hash[MOD_SANCTION_HASH_SIZE];
|
||||
|
||||
if (!sanctions_list_make_hash(moderation->sanctions, moderation->sanctions_creds.version,
|
||||
if (!sanctions_list_make_hash(moderation->mem, moderation->sanctions, moderation->sanctions_creds.version,
|
||||
moderation->num_sanctions, hash)) {
|
||||
moderation->sanctions_creds = old_creds;
|
||||
return false;
|
||||
@ -533,7 +533,7 @@ static bool sanctions_creds_validate(const Moderation *moderation, const Mod_San
|
||||
|
||||
uint8_t hash[MOD_SANCTION_HASH_SIZE];
|
||||
|
||||
if (!sanctions_list_make_hash(sanctions, creds->version, num_sanctions, hash)) {
|
||||
if (!sanctions_list_make_hash(moderation->mem, sanctions, creds->version, num_sanctions, hash)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -612,9 +612,9 @@ static bool sanctions_apply_new(Moderation *moderation, Mod_Sanction *new_sancti
|
||||
* memory returned by this function.
|
||||
*/
|
||||
non_null()
|
||||
static Mod_Sanction *sanctions_list_copy(const Mod_Sanction *sanctions, uint16_t num_sanctions)
|
||||
static Mod_Sanction *sanctions_list_copy(const Memory *mem, const Mod_Sanction *sanctions, uint16_t num_sanctions)
|
||||
{
|
||||
Mod_Sanction *copy = (Mod_Sanction *)calloc(num_sanctions, sizeof(Mod_Sanction));
|
||||
Mod_Sanction *copy = (Mod_Sanction *)mem_valloc(mem, num_sanctions, sizeof(Mod_Sanction));
|
||||
|
||||
if (copy == nullptr) {
|
||||
return nullptr;
|
||||
@ -655,7 +655,7 @@ static bool sanctions_list_remove_index(Moderation *moderation, uint16_t index,
|
||||
}
|
||||
|
||||
/* Operate on a copy of the list in case something goes wrong. */
|
||||
Mod_Sanction *sanctions_copy = sanctions_list_copy(moderation->sanctions, moderation->num_sanctions);
|
||||
Mod_Sanction *sanctions_copy = sanctions_list_copy(moderation->mem, moderation->sanctions, moderation->num_sanctions);
|
||||
|
||||
if (sanctions_copy == nullptr) {
|
||||
return false;
|
||||
@ -665,15 +665,15 @@ static bool sanctions_list_remove_index(Moderation *moderation, uint16_t index,
|
||||
sanctions_copy[index] = sanctions_copy[new_num];
|
||||
}
|
||||
|
||||
Mod_Sanction *new_list = (Mod_Sanction *)realloc(sanctions_copy, new_num * sizeof(Mod_Sanction));
|
||||
Mod_Sanction *new_list = (Mod_Sanction *)mem_vrealloc(moderation->mem, sanctions_copy, new_num, sizeof(Mod_Sanction));
|
||||
|
||||
if (new_list == nullptr) {
|
||||
free(sanctions_copy);
|
||||
mem_delete(moderation->mem, sanctions_copy);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sanctions_apply_new(moderation, new_list, creds, new_num)) {
|
||||
free(new_list);
|
||||
mem_delete(moderation->mem, new_list);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -753,7 +753,7 @@ bool sanctions_list_add_entry(Moderation *moderation, const Mod_Sanction *sancti
|
||||
Mod_Sanction *sanctions_copy = nullptr;
|
||||
|
||||
if (moderation->num_sanctions > 0) {
|
||||
sanctions_copy = sanctions_list_copy(moderation->sanctions, moderation->num_sanctions);
|
||||
sanctions_copy = sanctions_list_copy(moderation->mem, moderation->sanctions, moderation->num_sanctions);
|
||||
|
||||
if (sanctions_copy == nullptr) {
|
||||
return false;
|
||||
@ -761,17 +761,17 @@ bool sanctions_list_add_entry(Moderation *moderation, const Mod_Sanction *sancti
|
||||
}
|
||||
|
||||
const uint16_t index = moderation->num_sanctions;
|
||||
Mod_Sanction *new_list = (Mod_Sanction *)realloc(sanctions_copy, (index + 1) * sizeof(Mod_Sanction));
|
||||
Mod_Sanction *new_list = (Mod_Sanction *)mem_vrealloc(moderation->mem, sanctions_copy, index + 1, sizeof(Mod_Sanction));
|
||||
|
||||
if (new_list == nullptr) {
|
||||
free(sanctions_copy);
|
||||
mem_delete(moderation->mem, sanctions_copy);
|
||||
return false;
|
||||
}
|
||||
|
||||
new_list[index] = *sanction;
|
||||
|
||||
if (!sanctions_apply_new(moderation, new_list, creds, index + 1)) {
|
||||
free(new_list);
|
||||
mem_delete(moderation->mem, new_list);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -864,7 +864,7 @@ uint16_t sanctions_list_replace_sig(Moderation *moderation, const uint8_t *publi
|
||||
|
||||
void sanctions_list_cleanup(Moderation *moderation)
|
||||
{
|
||||
free(moderation->sanctions);
|
||||
mem_delete(moderation->mem, moderation->sanctions);
|
||||
|
||||
moderation->sanctions = nullptr;
|
||||
moderation->num_sanctions = 0;
|
||||
|
@ -20,12 +20,16 @@
|
||||
#include "onion_announce.h"
|
||||
#include "timed_auth.h"
|
||||
|
||||
static_assert(TIMED_AUTH_SIZE <= ONION_ANNOUNCE_REQUEST_MAX_SIZE,
|
||||
"Timed auth does not fit into the onion packet");
|
||||
static_assert(PACKED_NODE_SIZE_IP6 <= GCA_ANNOUNCE_MAX_SIZE,
|
||||
"IP6 does not fit into the GC_Announce");
|
||||
static_assert(GCA_ANNOUNCE_MAX_SIZE <= ONION_MAX_EXTRA_DATA_SIZE,
|
||||
"GC_Announce does not fit into the onion packet extra data");
|
||||
|
||||
static pack_extra_data_cb pack_group_announces;
|
||||
non_null()
|
||||
static int pack_group_announces(void *object, const Logger *logger, const Mono_Time *mono_time,
|
||||
static int pack_group_announces(void *object, const Logger *logger, const Memory *mem, const Mono_Time *mono_time,
|
||||
uint8_t num_nodes, uint8_t *plain, uint16_t plain_size,
|
||||
uint8_t *response, uint16_t response_size, uint16_t offset)
|
||||
{
|
||||
@ -38,7 +42,7 @@ static int pack_group_announces(void *object, const Logger *logger, const Mono_T
|
||||
return -1;
|
||||
}
|
||||
|
||||
const GC_Peer_Announce *new_announce = gca_add_announce(mono_time, gc_announces_list, &public_announce);
|
||||
const GC_Peer_Announce *new_announce = gca_add_announce(mem, mono_time, gc_announces_list, &public_announce);
|
||||
|
||||
if (new_announce == nullptr) {
|
||||
LOGGER_ERROR(logger, "Failed to add group announce");
|
||||
|
@ -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 */
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "group_pack.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "DHT.h"
|
||||
@ -23,9 +22,13 @@
|
||||
#include "group_common.h"
|
||||
#include "group_moderation.h"
|
||||
#include "logger.h"
|
||||
#include "mem.h"
|
||||
#include "network.h"
|
||||
#include "util.h"
|
||||
|
||||
static_assert(GC_SAVED_PEER_SIZE >= sizeof(IP_Port),
|
||||
"GC_SAVED_PEER_SIZE cannot contain IP_Port");
|
||||
|
||||
bool group_privacy_state_from_int(uint8_t value, Group_Privacy_State *out_enum)
|
||||
{
|
||||
switch (value) {
|
||||
@ -180,7 +183,7 @@ static bool load_unpack_mod_list(GC_Chat *chat, Bin_Unpack *bu)
|
||||
chat->moderation.num_mods = MOD_MAX_NUM_MODERATORS;
|
||||
}
|
||||
|
||||
uint8_t *packed_mod_list = (uint8_t *)malloc(chat->moderation.num_mods * MOD_LIST_ENTRY_SIZE);
|
||||
uint8_t *packed_mod_list = (uint8_t *)mem_balloc(chat->mem, chat->moderation.num_mods * MOD_LIST_ENTRY_SIZE);
|
||||
|
||||
if (packed_mod_list == nullptr) {
|
||||
LOGGER_ERROR(chat->log, "Failed to allocate memory for packed mod list");
|
||||
@ -191,17 +194,17 @@ static bool load_unpack_mod_list(GC_Chat *chat, Bin_Unpack *bu)
|
||||
|
||||
if (!bin_unpack_bin_fixed(bu, packed_mod_list, packed_size)) {
|
||||
LOGGER_ERROR(chat->log, "Failed to unpack mod list binary data");
|
||||
free(packed_mod_list);
|
||||
mem_delete(chat->mem, packed_mod_list);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mod_list_unpack(&chat->moderation, packed_mod_list, packed_size, chat->moderation.num_mods) == -1) {
|
||||
LOGGER_ERROR(chat->log, "Failed to unpack mod list info");
|
||||
free(packed_mod_list);
|
||||
mem_delete(chat->mem, packed_mod_list);
|
||||
return false;
|
||||
}
|
||||
|
||||
free(packed_mod_list);
|
||||
mem_delete(chat->mem, packed_mod_list);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -299,7 +302,7 @@ static bool load_unpack_saved_peers(GC_Chat *chat, Bin_Unpack *bu)
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *saved_peers = (uint8_t *)malloc(saved_peers_size * GC_SAVED_PEER_SIZE);
|
||||
uint8_t *saved_peers = (uint8_t *)mem_balloc(chat->mem, saved_peers_size * GC_SAVED_PEER_SIZE);
|
||||
|
||||
if (saved_peers == nullptr) {
|
||||
LOGGER_ERROR(chat->log, "Failed to allocate memory for saved peer list");
|
||||
@ -308,7 +311,7 @@ static bool load_unpack_saved_peers(GC_Chat *chat, Bin_Unpack *bu)
|
||||
|
||||
if (!bin_unpack_bin_fixed(bu, saved_peers, saved_peers_size)) {
|
||||
LOGGER_ERROR(chat->log, "Failed to unpack saved peers binary data");
|
||||
free(saved_peers);
|
||||
mem_delete(chat->mem, saved_peers);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -316,7 +319,7 @@ static bool load_unpack_saved_peers(GC_Chat *chat, Bin_Unpack *bu)
|
||||
LOGGER_ERROR(chat->log, "Failed to unpack saved peers"); // recoverable error
|
||||
}
|
||||
|
||||
free(saved_peers);
|
||||
mem_delete(chat->mem, saved_peers);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -390,7 +393,7 @@ static void save_pack_mod_list(const GC_Chat *chat, Bin_Pack *bp)
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *packed_mod_list = (uint8_t *)malloc(num_mods * MOD_LIST_ENTRY_SIZE);
|
||||
uint8_t *packed_mod_list = (uint8_t *)mem_balloc(chat->mem, num_mods * MOD_LIST_ENTRY_SIZE);
|
||||
|
||||
// we can still recover without the mod list
|
||||
if (packed_mod_list == nullptr) {
|
||||
@ -408,7 +411,7 @@ static void save_pack_mod_list(const GC_Chat *chat, Bin_Pack *bp)
|
||||
|
||||
bin_pack_bin(bp, packed_mod_list, packed_size); // 2
|
||||
|
||||
free(packed_mod_list);
|
||||
mem_delete(chat->mem, packed_mod_list);
|
||||
}
|
||||
|
||||
non_null()
|
||||
@ -445,7 +448,7 @@ static void save_pack_saved_peers(const GC_Chat *chat, Bin_Pack *bp)
|
||||
{
|
||||
bin_pack_array(bp, 2);
|
||||
|
||||
uint8_t *saved_peers = (uint8_t *)malloc(GC_MAX_SAVED_PEERS * GC_SAVED_PEER_SIZE);
|
||||
uint8_t *saved_peers = (uint8_t *)mem_balloc(chat->mem, GC_MAX_SAVED_PEERS * GC_SAVED_PEER_SIZE);
|
||||
|
||||
// we can still recover without the saved peers list
|
||||
if (saved_peers == nullptr) {
|
||||
@ -466,13 +469,13 @@ static void save_pack_saved_peers(const GC_Chat *chat, Bin_Pack *bp)
|
||||
|
||||
if (packed_size == 0) {
|
||||
bin_pack_nil(bp); // 2
|
||||
free(saved_peers);
|
||||
mem_delete(chat->mem, saved_peers);
|
||||
return;
|
||||
}
|
||||
|
||||
bin_pack_bin(bp, saved_peers, packed_size); // 2
|
||||
|
||||
free(saved_peers);
|
||||
mem_delete(chat->mem, saved_peers);
|
||||
}
|
||||
|
||||
void gc_save_pack_group(const GC_Chat *chat, Bin_Pack *bp)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -12,11 +12,11 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "attributes.h"
|
||||
#include "ccompat.h"
|
||||
#include "mem.h"
|
||||
|
||||
/**
|
||||
* Basically, the elements in the list are placed in order so that they can be searched for easily
|
||||
@ -115,7 +115,7 @@ static bool resize(BS_List *list, uint32_t new_size)
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *data = (uint8_t *)realloc(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;
|
||||
@ -123,7 +123,7 @@ static bool resize(BS_List *list, uint32_t new_size)
|
||||
|
||||
list->data = data;
|
||||
|
||||
int *ids = (int *)realloc(list->ids, new_size * sizeof(int));
|
||||
int *ids = (int *)mem_vrealloc(list->mem, list->ids, new_size, sizeof(int));
|
||||
|
||||
if (ids == nullptr) {
|
||||
return false;
|
||||
@ -134,8 +134,10 @@ static bool resize(BS_List *list, uint32_t new_size)
|
||||
return true;
|
||||
}
|
||||
|
||||
int bs_list_init(BS_List *list, uint32_t element_size, uint32_t initial_capacity, bs_list_cmp_cb *cmp_callback)
|
||||
int bs_list_init(BS_List *list, const Memory *mem, uint32_t element_size, uint32_t initial_capacity, bs_list_cmp_cb *cmp_callback)
|
||||
{
|
||||
list->mem = mem;
|
||||
|
||||
// set initial values
|
||||
list->n = 0;
|
||||
list->element_size = element_size;
|
||||
@ -162,10 +164,10 @@ void bs_list_free(BS_List *list)
|
||||
}
|
||||
|
||||
// free both arrays
|
||||
free(list->data);
|
||||
mem_delete(list->mem, list->data);
|
||||
list->data = nullptr;
|
||||
|
||||
free(list->ids);
|
||||
mem_delete(list->mem, list->ids);
|
||||
list->ids = nullptr;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2014 Tox project.
|
||||
*/
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "attributes.h"
|
||||
#include "mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -24,6 +25,8 @@ extern "C" {
|
||||
typedef int bs_list_cmp_cb(const void *a, const void *b, size_t size);
|
||||
|
||||
typedef struct BS_List {
|
||||
const Memory *mem;
|
||||
|
||||
uint32_t n; // number of elements
|
||||
uint32_t capacity; // number of elements memory is allocated for
|
||||
uint32_t element_size; // size of the elements
|
||||
@ -41,7 +44,7 @@ typedef struct BS_List {
|
||||
* @retval 0 failure
|
||||
*/
|
||||
non_null()
|
||||
int bs_list_init(BS_List *list, uint32_t element_size, uint32_t initial_capacity, bs_list_cmp_cb *cmp_callback);
|
||||
int bs_list_init(BS_List *list, const Memory *mem, uint32_t element_size, uint32_t initial_capacity, bs_list_cmp_cb *cmp_callback);
|
||||
|
||||
/** Free a list initiated with list_init */
|
||||
nullable(1)
|
||||
|
@ -2,26 +2,31 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "mem.h"
|
||||
|
||||
namespace {
|
||||
|
||||
TEST(List, CreateAndDestroyWithNonZeroSize)
|
||||
{
|
||||
const Memory *mem = os_memory();
|
||||
BS_List list;
|
||||
bs_list_init(&list, sizeof(int), 10, memcmp);
|
||||
bs_list_init(&list, mem, sizeof(int), 10, memcmp);
|
||||
bs_list_free(&list);
|
||||
}
|
||||
|
||||
TEST(List, CreateAndDestroyWithZeroSize)
|
||||
{
|
||||
const Memory *mem = os_memory();
|
||||
BS_List list;
|
||||
bs_list_init(&list, sizeof(int), 0, memcmp);
|
||||
bs_list_init(&list, mem, sizeof(int), 0, memcmp);
|
||||
bs_list_free(&list);
|
||||
}
|
||||
|
||||
TEST(List, DeleteFromEmptyList)
|
||||
{
|
||||
const Memory *mem = os_memory();
|
||||
BS_List list;
|
||||
bs_list_init(&list, sizeof(int), 0, memcmp);
|
||||
bs_list_init(&list, mem, sizeof(int), 0, memcmp);
|
||||
const uint8_t data[sizeof(int)] = {0};
|
||||
bs_list_remove(&list, data, 0);
|
||||
bs_list_free(&list);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013-2015 Tox project.
|
||||
*/
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
*/
|
||||
#include "logger.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -52,12 +53,13 @@ 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;
|
||||
}
|
||||
|
||||
void logger_write(const Logger *log, Logger_Level level, const char *file, int line, const char *func,
|
||||
void logger_write(const Logger *log, Logger_Level level, const char *file, uint32_t line, const char *func,
|
||||
const char *format, ...)
|
||||
{
|
||||
if (log == nullptr) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
@ -33,7 +33,7 @@ typedef enum Logger_Level {
|
||||
|
||||
typedef struct Logger Logger;
|
||||
|
||||
typedef void logger_cb(void *context, Logger_Level level, const char *file, int line,
|
||||
typedef void logger_cb(void *context, Logger_Level level, const char *file, uint32_t line,
|
||||
const char *func, const char *message, void *userdata);
|
||||
|
||||
/**
|
||||
@ -66,7 +66,7 @@ void logger_callback_log(Logger *log, logger_cb *function, void *context, void *
|
||||
*/
|
||||
non_null(3, 5, 6) nullable(1) GNU_PRINTF(6, 7)
|
||||
void logger_write(
|
||||
const Logger *log, Logger_Level level, const char *file, int line, const char *func,
|
||||
const Logger *log, Logger_Level level, const char *file, uint32_t line, const char *func,
|
||||
const char *format, ...);
|
||||
|
||||
/* @brief Terminate the program with a signal. */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
@ -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);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
* Copyright © 2016-2018 The TokTok team.
|
||||
* Copyright © 2016-2025 The TokTok team.
|
||||
* Copyright © 2013 Tox project.
|
||||
*/
|
||||
|
||||
@ -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.
|
||||
*
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user