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:
@@ -56,8 +56,8 @@
|
||||
#define KEYS_TIMEOUT 600
|
||||
|
||||
typedef struct DHT_Friend_Callback {
|
||||
dht_ip_cb *ip_callback;
|
||||
void *data;
|
||||
dht_ip_cb *_Nullable ip_callback;
|
||||
void *_Nullable data;
|
||||
int32_t number;
|
||||
} DHT_Friend_Callback;
|
||||
|
||||
@@ -87,17 +87,17 @@ const Node_format empty_node_format = {{0}};
|
||||
static_assert(sizeof(empty_dht_friend.lock_flags) * 8 == DHT_FRIEND_MAX_LOCKS, "Bitfield size and number of locks don't match");
|
||||
|
||||
typedef struct Cryptopacket_Handler {
|
||||
cryptopacket_handler_cb *function;
|
||||
void *object;
|
||||
cryptopacket_handler_cb *_Nullable function;
|
||||
void *_Nullable object;
|
||||
} Cryptopacket_Handler;
|
||||
|
||||
struct DHT {
|
||||
const Logger *log;
|
||||
const Network *ns;
|
||||
Mono_Time *mono_time;
|
||||
const Memory *mem;
|
||||
const Random *rng;
|
||||
Networking_Core *net;
|
||||
const Logger *_Nonnull log;
|
||||
const Network *_Nonnull ns;
|
||||
Mono_Time *_Nonnull mono_time;
|
||||
const Memory *_Nonnull mem;
|
||||
const Random *_Nonnull rng;
|
||||
Networking_Core *_Nonnull net;
|
||||
|
||||
bool hole_punching_enabled;
|
||||
bool lan_discovery_enabled;
|
||||
@@ -110,18 +110,18 @@ struct DHT {
|
||||
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||
|
||||
DHT_Friend *friends_list;
|
||||
DHT_Friend *_Nullable friends_list;
|
||||
uint16_t num_friends;
|
||||
|
||||
Node_format *loaded_nodes_list;
|
||||
Node_format *_Nullable loaded_nodes_list;
|
||||
uint32_t loaded_num_nodes;
|
||||
unsigned int loaded_nodes_index;
|
||||
|
||||
Shared_Key_Cache *shared_keys_recv;
|
||||
Shared_Key_Cache *shared_keys_sent;
|
||||
Shared_Key_Cache *_Nonnull shared_keys_recv;
|
||||
Shared_Key_Cache *_Nonnull shared_keys_sent;
|
||||
|
||||
struct Ping *ping;
|
||||
Ping_Array *dht_ping_array;
|
||||
struct Ping *_Nonnull ping;
|
||||
Ping_Array *_Nonnull dht_ping_array;
|
||||
uint64_t cur_time;
|
||||
|
||||
Cryptopacket_Handler cryptopackethandlers[256];
|
||||
@@ -129,7 +129,7 @@ struct DHT {
|
||||
Node_format to_bootstrap[MAX_CLOSE_TO_BOOTSTRAP_NODES];
|
||||
unsigned int num_to_bootstrap;
|
||||
|
||||
dht_nodes_response_cb *nodes_response_callback;
|
||||
dht_nodes_response_cb *_Nullable nodes_response_callback;
|
||||
};
|
||||
|
||||
const uint8_t *dht_friend_public_key(const DHT_Friend *dht_friend)
|
||||
@@ -855,9 +855,9 @@ static bool store_node_ok(const Client_data *_Nonnull client, uint64_t cur_time,
|
||||
}
|
||||
|
||||
typedef struct Client_data_Cmp {
|
||||
const Memory *mem;
|
||||
const Memory *_Nonnull mem;
|
||||
uint64_t cur_time;
|
||||
const uint8_t *comp_public_key;
|
||||
const uint8_t *_Nonnull comp_public_key;
|
||||
} Client_data_Cmp;
|
||||
|
||||
static int client_data_cmp(const Client_data_Cmp *_Nonnull cmp, const Client_data *_Nonnull entry1, const Client_data *_Nonnull entry2)
|
||||
@@ -2019,7 +2019,7 @@ static uint32_t foreach_ip_port(const DHT *_Nonnull dht, const DHT_Friend *_Nonn
|
||||
|
||||
static bool send_packet_to_friend(const DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, uint32_t *_Nonnull n, void *_Nonnull userdata)
|
||||
{
|
||||
const Packet *packet = (const Packet *)userdata;
|
||||
const Net_Packet *packet = (const Net_Packet *)userdata;
|
||||
const int retval = net_send_packet(dht->net, ip_port, *packet);
|
||||
|
||||
if ((uint32_t)retval == packet->length) {
|
||||
@@ -2037,7 +2037,7 @@ static bool send_packet_to_friend(const DHT *_Nonnull dht, const IP_Port *_Nonnu
|
||||
* @return ip for friend.
|
||||
* @return number of nodes the packet was sent to. (Only works if more than (MAX_FRIEND_CLIENTS / 4).
|
||||
*/
|
||||
uint32_t route_to_friend(const DHT *dht, const uint8_t *friend_id, const Packet *packet)
|
||||
uint32_t route_to_friend(const DHT *dht, const uint8_t *friend_id, const Net_Packet *packet)
|
||||
{
|
||||
const uint32_t num = index_of_friend_pk(dht->friends_list, dht->num_friends, friend_id);
|
||||
|
||||
@@ -2053,7 +2053,7 @@ uint32_t route_to_friend(const DHT *dht, const uint8_t *friend_id, const Packet
|
||||
}
|
||||
|
||||
const DHT_Friend *const dht_friend = &dht->friends_list[num];
|
||||
Packet packet_userdata = *packet; // Copy because it needs to be non-const.
|
||||
Net_Packet packet_userdata = *packet; // Copy because it needs to be non-const.
|
||||
|
||||
return foreach_ip_port(dht, dht_friend, send_packet_to_friend, &packet_userdata);
|
||||
}
|
||||
@@ -2070,7 +2070,7 @@ static bool get_ip_port(const DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port
|
||||
*
|
||||
* @return number of nodes the packet was sent to.
|
||||
*/
|
||||
static uint32_t routeone_to_friend(const DHT *_Nonnull dht, const uint8_t *_Nonnull friend_id, const Packet *_Nonnull packet)
|
||||
static uint32_t routeone_to_friend(const DHT *_Nonnull dht, const uint8_t *_Nonnull friend_id, const Net_Packet *_Nonnull packet)
|
||||
{
|
||||
const uint32_t num = index_of_friend_pk(dht->friends_list, dht->num_friends, friend_id);
|
||||
|
||||
@@ -2119,7 +2119,7 @@ static int send_nat_ping(const DHT *_Nonnull dht, const uint8_t *_Nonnull public
|
||||
|
||||
assert(len <= UINT16_MAX);
|
||||
uint32_t num = 0;
|
||||
const Packet packet = {packet_data, (uint16_t)len};
|
||||
const Net_Packet packet = {packet_data, (uint16_t)len};
|
||||
|
||||
if (type == 0) { /* If packet is request use many people to route it. */
|
||||
num = route_to_friend(dht, public_key, &packet);
|
||||
@@ -2515,14 +2515,16 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw
|
||||
dht->hole_punching_enabled = hole_punching_enabled;
|
||||
dht->lan_discovery_enabled = lan_discovery_enabled;
|
||||
|
||||
dht->ping = ping_new(mem, mono_time, rng, dht, net);
|
||||
struct Ping *temp_ping = ping_new(mem, mono_time, rng, dht, net);
|
||||
|
||||
if (dht->ping == nullptr) {
|
||||
if (temp_ping == nullptr) {
|
||||
LOGGER_ERROR(log, "failed to initialise ping");
|
||||
kill_dht(dht);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
dht->ping = temp_ping;
|
||||
|
||||
networking_registerhandler(dht->net, NET_PACKET_NODES_REQUEST, &handle_nodes_request, dht);
|
||||
networking_registerhandler(dht->net, NET_PACKET_NODES_RESPONSE, &handle_nodes_response, dht);
|
||||
networking_registerhandler(dht->net, NET_PACKET_CRYPTO, &cryptopacket_handle, dht);
|
||||
@@ -2535,23 +2537,36 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw
|
||||
|
||||
crypto_new_keypair(rng, dht->self_public_key, dht->self_secret_key);
|
||||
|
||||
dht->shared_keys_recv = shared_key_cache_new(log, mono_time, mem, dht->self_secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
||||
dht->shared_keys_sent = shared_key_cache_new(log, mono_time, mem, dht->self_secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
||||
Shared_Key_Cache *const temp_shared_keys_recv = shared_key_cache_new(log, mono_time, mem, dht->self_secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
||||
|
||||
if (dht->shared_keys_recv == nullptr || dht->shared_keys_sent == nullptr) {
|
||||
if (temp_shared_keys_recv == nullptr) {
|
||||
LOGGER_ERROR(log, "failed to initialise shared key cache");
|
||||
kill_dht(dht);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
dht->dht_ping_array = ping_array_new(mem, DHT_PING_ARRAY_SIZE, PING_TIMEOUT);
|
||||
dht->shared_keys_recv = temp_shared_keys_recv;
|
||||
|
||||
if (dht->dht_ping_array == nullptr) {
|
||||
Shared_Key_Cache *const temp_shared_keys_sent = shared_key_cache_new(log, mono_time, mem, dht->self_secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
||||
|
||||
if (temp_shared_keys_sent == nullptr) {
|
||||
LOGGER_ERROR(log, "failed to initialise shared key cache");
|
||||
kill_dht(dht);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
dht->shared_keys_sent = temp_shared_keys_sent;
|
||||
|
||||
Ping_Array *const temp_ping_array = ping_array_new(mem, DHT_PING_ARRAY_SIZE, PING_TIMEOUT);
|
||||
|
||||
if (temp_ping_array == nullptr) {
|
||||
LOGGER_ERROR(log, "failed to initialise ping array");
|
||||
kill_dht(dht);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
dht->dht_ping_array = temp_ping_array;
|
||||
|
||||
for (uint32_t i = 0; i < DHT_FAKE_FRIEND_NUMBER; ++i) {
|
||||
uint8_t random_public_key_bytes[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
uint8_t random_secret_key_bytes[CRYPTO_SECRET_KEY_SIZE];
|
||||
|
||||
Reference in New Issue
Block a user