Squashed 'external/toxcore/c-toxcore/' changes from 1828c5356..c9cdae001

c9cdae001 fix(toxav): remove extra copy of video frame on encode
4f6d4546b test: Improve the fake network library.
a2581e700 refactor(toxcore): generate `Friend_Request` and `Dht_Nodes_Response`
2aaa11770 refactor(toxcore): use Tox_Memory in generated events
5c367452b test(toxcore): fix incorrect mutex in tox_scenario_get_time
8f92e710f perf: Add a timed limit of number of cookie requests.
695b6417a test: Add some more simulated network support.
815ae9ce9 test(toxcore): fix thread-safety in scenario framework
6d85c754e test(toxcore): add unit tests for net_crypto
9c22e79cc test(support): add SimulatedEnvironment for deterministic testing
f34fcb195 chore: Update windows Dockerfile to debian stable (trixie).
ece0e8980 fix(group_moderation): allow validating unsorted sanction list signatures
a4fa754d7 refactor: rename struct Packet to struct Net_Packet
d6f330f85 cleanup: Fix some warnings from coverity.
e206bffa2 fix(group_chats): fix sync packets reverting topics
0e4715598 test: Add new scenario testing framework.
668291f44 refactor(toxcore): decouple Network_Funcs from sockaddr via IP_Port
fc4396cef fix: potential division by zero in toxav and unsafe hex parsing
8e8b352ab refactor: Add nullable annotations to struct members.
7740bb421 refactor: decouple net_crypto from DHT
1936d4296 test: add benchmark for toxav audio and video
46bfdc2df fix: correct printf format specifiers for unsigned integers
REVERT: 1828c5356 fix(toxav): remove extra copy of video frame on encode

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: c9cdae001341e701fca980c9bb9febfeb95d2902
This commit is contained in:
Green Sky
2026-01-11 14:42:31 +01:00
parent e95f2cbb1c
commit 565efa4f39
328 changed files with 19057 additions and 13982 deletions

View File

@@ -47,6 +47,30 @@ static_assert(MAX_CONCURRENT_FILE_PIPES <= UINT8_MAX + 1,
static const Friend empty_friend = {{0}};
static const uint8_t *_Nullable nc_dht_get_shared_key_sent_wrapper(void *_Nonnull obj, const uint8_t *_Nonnull public_key)
{
DHT *dht = (DHT *)obj;
return dht_get_shared_key_sent(dht, public_key);
}
static const uint8_t *_Nonnull nc_dht_get_self_public_key_wrapper(const void *_Nonnull obj)
{
const DHT *dht = (const DHT *)obj;
return dht_get_self_public_key(dht);
}
static const uint8_t *_Nonnull nc_dht_get_self_secret_key_wrapper(const void *_Nonnull obj)
{
const DHT *dht = (const DHT *)obj;
return dht_get_self_secret_key(dht);
}
static const Net_Crypto_DHT_Funcs m_dht_funcs = {
nc_dht_get_shared_key_sent_wrapper,
nc_dht_get_self_public_key_wrapper,
nc_dht_get_self_secret_key_wrapper,
};
/**
* Determines if the friendnumber passed is valid in the Messenger object.
*
@@ -1555,7 +1579,7 @@ int send_file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber
* @return true if there's still work to do, false otherwise.
*
*/
static bool do_all_filetransfers(Messenger *_Nonnull m, int32_t friendnumber, void *_Nonnull userdata, uint32_t *_Nonnull free_slots)
static bool do_all_filetransfers(Messenger *_Nonnull m, int32_t friendnumber, void *_Nullable userdata, uint32_t *_Nonnull free_slots)
{
Friend *const friendcon = &m->friendlist[friendnumber];
@@ -3374,21 +3398,24 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
m->mem = mem;
m->rng = rng;
m->ns = ns;
m->forwarding = nullptr;
m->announce = nullptr;
m->tcp_server = nullptr;
m->fr = friendreq_new(mem);
if (m->fr == nullptr) {
Friend_Requests *fr = friendreq_new(mem);
if (fr == nullptr) {
mem_delete(mem, m);
return nullptr;
}
m->fr = fr;
m->log = logger_new(mem);
if (m->log == nullptr) {
Logger *log = logger_new(mem);
if (log == nullptr) {
friendreq_kill(m->fr);
mem_delete(mem, m);
return nullptr;
}
m->log = log;
logger_callback_log(m->log, options->log_callback, options->log_context, options->log_user_data);
@@ -3400,15 +3427,16 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
options->udp_disabled = true;
}
Networking_Core *net;
if (options->udp_disabled) {
m->net = new_networking_no_udp(m->log, m->mem, m->ns);
net = new_networking_no_udp(m->log, m->mem, m->ns);
} else {
IP ip;
ip_init(&ip, options->ipv6enabled);
m->net = new_networking_ex(m->log, m->mem, m->ns, &ip, options->port_range[0], options->port_range[1], &net_err);
net = new_networking_ex(m->log, m->mem, m->ns, &ip, options->port_range[0], options->port_range[1], &net_err);
}
if (m->net == nullptr) {
if (net == nullptr) {
friendreq_kill(m->fr);
if (error != nullptr && net_err == 1) {
@@ -3420,20 +3448,20 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
mem_delete(mem, m);
return nullptr;
}
m->net = net;
m->dht = new_dht(m->log, m->mem, m->rng, m->ns, m->mono_time, m->net, options->hole_punching_enabled, options->local_discovery_enabled);
if (m->dht == nullptr) {
DHT *dht = new_dht(m->log, m->mem, m->rng, m->ns, m->mono_time, m->net, options->hole_punching_enabled, options->local_discovery_enabled);
if (dht == nullptr) {
kill_networking(m->net);
friendreq_kill(m->fr);
logger_kill(m->log);
mem_delete(mem, m);
return nullptr;
}
m->dht = dht;
m->tcp_np = netprof_new(m->log, mem);
if (m->tcp_np == nullptr) {
Net_Profile *tcp_np = netprof_new(m->log, mem);
if (tcp_np == nullptr) {
LOGGER_WARNING(m->log, "TCP netprof initialisation failed");
kill_dht(m->dht);
kill_networking(m->net);
@@ -3442,10 +3470,11 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
mem_delete(mem, m);
return nullptr;
}
m->tcp_np = tcp_np;
m->net_crypto = new_net_crypto(m->log, m->mem, m->rng, m->ns, m->mono_time, m->net, m->dht, &options->proxy_info, m->tcp_np);
Net_Crypto *net_crypto = new_net_crypto(m->log, m->mem, m->rng, m->ns, m->mono_time, m->net, m->dht, &m_dht_funcs, &options->proxy_info, m->tcp_np);
if (m->net_crypto == nullptr) {
if (net_crypto == nullptr) {
LOGGER_WARNING(m->log, "net_crypto initialisation failed");
netprof_kill(mem, m->tcp_np);
@@ -3456,10 +3485,10 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
mem_delete(mem, m);
return nullptr;
}
m->net_crypto = net_crypto;
m->group_announce = new_gca_list(m->mem);
if (m->group_announce == nullptr) {
GC_Announces_List *group_announce = new_gca_list(m->mem);
if (group_announce == nullptr) {
LOGGER_WARNING(m->log, "DHT group chats initialisation failed");
kill_net_crypto(m->net_crypto);
@@ -3471,35 +3500,33 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
mem_delete(mem, m);
return nullptr;
}
m->group_announce = group_announce;
if (options->dht_announcements_enabled) {
m->forwarding = new_forwarding(m->log, m->mem, m->rng, m->mono_time, m->dht, m->net);
if (m->forwarding != nullptr) {
m->announce = new_announcements(m->log, m->mem, m->rng, m->mono_time, m->forwarding, m->dht, m->net);
} else {
m->announce = nullptr;
}
} else {
m->forwarding = nullptr;
m->announce = nullptr;
}
m->onion = new_onion(m->log, m->mem, m->mono_time, m->rng, m->dht, m->net);
m->onion_a = new_onion_announce(m->log, m->mem, m->rng, m->mono_time, m->dht, m->net);
m->onion_c = new_onion_client(m->log, m->mem, m->rng, m->mono_time, m->net_crypto, m->dht, m->net);
if (m->onion_c != nullptr) {
m->fr_c = new_friend_connections(m->log, m->mem, m->mono_time, m->ns, m->onion_c, m->dht, m->net_crypto, m->net, options->local_discovery_enabled);
Onion *onion = new_onion(m->log, m->mem, m->mono_time, m->rng, m->dht, m->net);
Onion_Announce *onion_a = new_onion_announce(m->log, m->mem, m->rng, m->mono_time, m->dht, m->net);
Onion_Client *onion_c = new_onion_client(m->log, m->mem, m->rng, m->mono_time, m->net_crypto, m->dht, m->net);
Friend_Connections *fr_c = nullptr;
if (onion_c != nullptr) {
fr_c = new_friend_connections(m->log, m->mem, m->mono_time, m->ns, onion_c, m->dht, m->net_crypto, m->net, options->local_discovery_enabled);
}
if ((options->dht_announcements_enabled && (m->forwarding == nullptr || m->announce == nullptr)) ||
m->onion == nullptr || m->onion_a == nullptr || m->onion_c == nullptr || m->fr_c == nullptr) {
onion == nullptr || onion_a == nullptr || onion_c == nullptr || fr_c == nullptr) {
LOGGER_WARNING(m->log, "onion initialisation failed");
kill_onion(m->onion);
kill_onion_announce(m->onion_a);
kill_onion_client(m->onion_c);
kill_onion(onion);
kill_onion_announce(onion_a);
kill_onion_client(onion_c);
kill_gca(m->group_announce);
kill_friend_connections(m->fr_c);
kill_friend_connections(fr_c);
kill_announcements(m->announce);
kill_forwarding(m->forwarding);
kill_net_crypto(m->net_crypto);
@@ -3511,12 +3538,15 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
mem_delete(mem, m);
return nullptr;
}
m->onion = onion;
m->onion_a = onion_a;
m->onion_c = onion_c;
m->fr_c = fr_c;
gca_onion_init(m->group_announce, m->onion_a);
m->group_handler = new_dht_groupchats(m);
if (m->group_handler == nullptr) {
GC_Session *group_handler = new_dht_groupchats(m);
if (group_handler == nullptr) {
LOGGER_WARNING(m->log, "conferences initialisation failed");
kill_onion(m->onion);
@@ -3535,6 +3565,7 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
mem_delete(mem, m);
return nullptr;
}
m->group_handler = group_handler;
if (options->tcp_server_port != 0) {
m->tcp_server = new_tcp_server(m->log, m->mem, m->rng, m->ns, options->ipv6enabled, 1,