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

@@ -29,11 +29,11 @@
#define PORTS_PER_DISCOVERY 10
typedef struct Friend_Conn_Callbacks {
fc_status_cb *status_callback;
fc_data_cb *data_callback;
fc_lossy_data_cb *lossy_data_callback;
fc_status_cb *_Nullable status_callback;
fc_data_cb *_Nullable data_callback;
fc_lossy_data_cb *_Nullable lossy_data_callback;
void *callback_object;
void *_Nullable callback_object;
int callback_id;
} Friend_Conn_Callbacks;
@@ -68,23 +68,23 @@ struct Friend_Conn {
static const Friend_Conn empty_friend_conn = {0};
struct Friend_Connections {
const Mono_Time *mono_time;
const Memory *mem;
const Logger *logger;
Networking_Core *net;
Net_Crypto *net_crypto;
DHT *dht;
Broadcast_Info *broadcast;
Onion_Client *onion_c;
const Mono_Time *_Nonnull mono_time;
const Memory *_Nonnull mem;
const Logger *_Nonnull logger;
Networking_Core *_Nonnull net;
Net_Crypto *_Nonnull net_crypto;
DHT *_Nonnull dht;
Broadcast_Info *_Nullable broadcast;
Onion_Client *_Nonnull onion_c;
Friend_Conn *conns;
Friend_Conn *_Nullable conns;
uint32_t num_cons;
fr_request_cb *fr_request_callback;
void *fr_request_object;
fr_request_cb *_Nullable fr_request_callback;
void *_Nullable fr_request_object;
global_status_cb *global_status_callback;
void *global_status_callback_object;
global_status_cb *_Nullable global_status_callback;
void *_Nullable global_status_callback_object;
uint64_t last_lan_discovery;
uint16_t next_lan_port;
@@ -351,10 +351,6 @@ static void dht_ip_callback(void *_Nonnull object, int32_t number, const IP_Port
return;
}
if (friend_con->crypt_connection_id == -1) {
friend_new_connection(fr_c, number);
}
set_direct_ip_port(fr_c->net_crypto, friend_con->crypt_connection_id, ip_port, true);
friend_con->dht_ip_port = *ip_port;
friend_con->dht_ip_port_lastrecv = mono_time_get(fr_c->mono_time);
@@ -387,7 +383,7 @@ static void change_dht_pk(Friend_Connections *_Nonnull fr_c, int friendcon_id, c
memcpy(friend_con->dht_temp_pk, dht_public_key, CRYPTO_PUBLIC_KEY_SIZE);
}
static int handle_status(void *_Nonnull object, int id, bool status, void *_Nonnull userdata)
static int handle_status(void *_Nonnull object, int id, bool status, void *_Nullable userdata)
{
Friend_Connections *const fr_c = (Friend_Connections *)object;
Friend_Conn *const friend_con = get_conn(fr_c, id);
@@ -434,7 +430,7 @@ static int handle_status(void *_Nonnull object, int id, bool status, void *_Nonn
}
/** Callback for dht public key changes. */
static void dht_pk_callback(void *_Nonnull object, int32_t number, const uint8_t *_Nonnull dht_public_key, void *_Nonnull userdata)
static void dht_pk_callback(void *_Nonnull object, int32_t number, const uint8_t *_Nonnull dht_public_key, void *_Nullable userdata)
{
Friend_Connections *const fr_c = (Friend_Connections *)object;
Friend_Conn *const friend_con = get_conn(fr_c, number);
@@ -456,7 +452,6 @@ static void dht_pk_callback(void *_Nonnull object, int32_t number, const uint8_t
handle_status(object, number, false, userdata); /* Going offline. */
}
friend_new_connection(fr_c, number);
onion_set_friend_dht_pubkey(fr_c->onion_c, friend_con->onion_friendnum, dht_public_key);
}
@@ -940,6 +935,9 @@ Friend_Connections *new_friend_connections(
static void lan_discovery(Friend_Connections *_Nonnull fr_c)
{
if (fr_c->last_lan_discovery + LAN_DISCOVERY_INTERVAL < mono_time_get(fr_c->mono_time)) {
if (fr_c->broadcast == nullptr) {
return;
}
const uint16_t first = fr_c->next_lan_port;
uint16_t last = first + PORTS_PER_DISCOVERY;
last = last > TOX_PORTRANGE_TO ? TOX_PORTRANGE_TO : last;