Squashed 'external/toxcore/c-toxcore/' changes from d9b8fa6098d..81b1e4f6348

81b1e4f6348 chore: Release v0.2.21-rc.1
9303e2e49a1 chore: Update the pkgsrc versions in the update-versions tool
71ec4b3b1e9 chore: Update the version-sync script to work in a post-tox.api.h world
66da842f753 chore: Add version update script compatible with ci-tools.
199878f7660 chore: Use new bazel script for circle ci.
8278e9cda46 chore: Add release issue template and workflow.
a9bb3a1c4d1 chore: Fix alpine-s390x build.
6e0a641272e chore: Add a source tarball deploy workflow.
4adebe4d8b1 chore: Don't upload ios/macos variants in deploy workflows.
18f1d858ccb chore: Move one of the 3 freebsd builds to post-submit.
432ab60c002 feat: Add a Makefile for the single file deploy build.
a86c0011fd5 chore: Add deploy job for single C file library.
2e7495e8f2a docs: Update changelog format to use the new clog-compatible way.
a682da99e84 chore: Export wasmExports from the wasm binary.
12f34cdff27 chore: Add wasm to the nightly binary deploys.
1451029613f chore: Add strict-abi support for macOS/iOS.
c53c30e09d9 chore: Add time option to manual fuzz trigger.
2ccecdc2a1a chore: Add remaining fuzz tests to cflite.
4626c2e230e test: Add a Net_Crypto fuzz test.
b4a0e617c48 refactor: Use IP string length from ip_ntoa instead of strlen.
b85b91f22f6 cleanup: rename getnodes/sendnodes to nodes request/response This change alignes the naming to be closer to the spec and make it less ambiguous. This change also changes the naming of some private/experimental marked APIs. - tox_callback_dht_nodes_response() - tox_dht_nodes_request() - Tox_Event_Dht_Get_Nodes_Response
f1991aaa029 perf: Use stack allocation for strerror rendering.
3984211ccbf cleanup: remove kicked peers from saved peers list
26a991ed2be fix: ip to string function not accepting tcp families
712861f2e6d cleanup: Make websockify output qtox-compatible logging.
01932ea2f73 chore: Add opus and vpx to the toxcore wasm build.
d29c42ef631 refactor: don't fully discard received DHT nodes. This is mostly forward thinking, where we might introduce other ip families, in addition to ipv4, ipv6, tcp_ipv4 etc.
21e2325934f chore: Fix xcframework tarball creation.
b10c8b766ba chore: Fix xcframework checksum creation.
93787a9322e chore: Add ios/macos framework build.
9f723f891d3 fix: run do_gca also in bootstrap nodes
496cc703556 chore: Support arm64 iphone simulator.
aa0e2a8e928 chore: Add support for more iOS architectures.
13ad8e81cbf chore: Add binary deploy workflows.
c8344726378 refactor: Move tox_log_level out into its own file.
8799bea76c3 cleanup: Mark events/dispatch headers as experimental.
d4164edb548 refactor: Remove tox_types.h; use `struct` tags instead.
d408c982090 refactor: Move `Tox_Options` to `tox_options.h`.
5ab42d41209 chore: Move most cirrus jobs to circleci.
463eeae1144 cleanup: Avoid clashing with global define `DEBUG`.
92cc1e91747 refactor: Make Tox_Options own the passed proxy host and savedata.
f276b397226 test: Add some more asserts for I/O and alloc to succeed.
edb4dfc4869 fix: Don't crash on malloc failures in bin_unpack.
be457d5d0b2 cleanup: Use tox memory for bin_unpack and net_strerror.

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: 81b1e4f6348124784088591c4fe9ab41e273031d
This commit is contained in:
Green Sky
2025-03-12 19:16:50 +01:00
parent 3b6bb15e86
commit 3105cc20ef
130 changed files with 3604 additions and 1776 deletions

View File

@ -48,7 +48,7 @@ auto_test(conference_simple)
auto_test(conference_two)
auto_test(crypto)
#auto_test(dht) # Doesn't work with UNITY_BUILD.
auto_test(dht_getnodes_api)
auto_test(dht_nodes_response_api)
auto_test(encryptsave)
auto_test(file_saving)
auto_test(file_streaming)

View File

@ -271,7 +271,7 @@ static void kill_tcp_con(struct sec_TCP_con *con)
free(con);
}
static int write_packet_tcp_test_connection(const Logger *logger, struct sec_TCP_con *con, const uint8_t *data,
static int write_packet_tcp_test_connection(const Logger *logger, const Memory *mem, struct sec_TCP_con *con, const uint8_t *data,
uint16_t length)
{
const uint16_t packet_size = sizeof(uint16_t) + length + CRYPTO_MAC_SIZE;
@ -338,9 +338,9 @@ static void test_some(void)
// Sending wrong public keys to test server response.
memcpy(requ_p + 1, con3->public_key, CRYPTO_PUBLIC_KEY_SIZE);
write_packet_tcp_test_connection(logger, con1, requ_p, sizeof(requ_p));
write_packet_tcp_test_connection(logger, mem, con1, requ_p, sizeof(requ_p));
memcpy(requ_p + 1, con1->public_key, CRYPTO_PUBLIC_KEY_SIZE);
write_packet_tcp_test_connection(logger, con3, requ_p, sizeof(requ_p));
write_packet_tcp_test_connection(logger, mem, con3, requ_p, sizeof(requ_p));
do_tcp_server_delay(tcp_s, mono_time, 50);
@ -362,9 +362,9 @@ static void test_some(void)
const uint8_t test_packet[512] = {16, 17, 16, 86, 99, 127, 255, 189, 78}; // What is this packet????
write_packet_tcp_test_connection(logger, con3, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, con3, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, con3, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, mem, con3, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, mem, con3, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, mem, con3, test_packet, sizeof(test_packet));
do_tcp_server_delay(tcp_s, mono_time, 50);
@ -388,9 +388,9 @@ static void test_some(void)
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
write_packet_tcp_test_connection(logger, con1, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, con1, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, con1, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, mem, con1, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, mem, con1, test_packet, sizeof(test_packet));
write_packet_tcp_test_connection(logger, mem, con1, test_packet, sizeof(test_packet));
do_tcp_server_delay(tcp_s, mono_time, 50);
len = read_packet_sec_tcp(logger, con3, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
@ -405,8 +405,8 @@ static void test_some(void)
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);
uint8_t ping_packet[1 + sizeof(uint64_t)] = {TCP_PACKET_PING, 8, 6, 9, 67};
write_packet_tcp_test_connection(logger, con1, ping_packet, sizeof(ping_packet));
const uint8_t ping_packet[1 + sizeof(uint64_t)] = {TCP_PACKET_PING, 8, 6, 9, 67};
write_packet_tcp_test_connection(logger, mem, con1, ping_packet, sizeof(ping_packet));
do_tcp_server_delay(tcp_s, mono_time, 50);

View File

@ -1,12 +1,11 @@
/**
* This autotest creates a small local DHT and makes sure that each peer can crawl
* the entire DHT using the DHT getnodes api functions.
* the entire DHT using the DHT nodes request/response api functions.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "../toxcore/tox.h"
#include "../toxcore/tox_private.h"
@ -72,16 +71,16 @@ static bool all_nodes_crawled(const AutoTox *autotoxes, uint32_t num_toxes, uint
return true;
}
static void getnodes_response_cb(const Tox_Event_Dht_Get_Nodes_Response *event, void *user_data)
static void nodes_response_cb(const Tox_Event_Dht_Nodes_Response *event, void *user_data)
{
ck_assert(user_data != nullptr);
AutoTox *autotox = (AutoTox *)user_data;
State *state = (State *)autotox->state;
const uint8_t *public_key = tox_event_dht_get_nodes_response_get_public_key(event);
const char *ip = (const char *)tox_event_dht_get_nodes_response_get_ip(event);
const uint16_t port = tox_event_dht_get_nodes_response_get_port(event);
const uint8_t *public_key = tox_event_dht_nodes_response_get_public_key(event);
const char *ip = (const char *)tox_event_dht_nodes_response_get_ip(event);
const uint16_t port = tox_event_dht_nodes_response_get_port(event);
if (node_crawled(state->nodes, state->num_nodes, public_key)) {
return;
@ -101,11 +100,11 @@ static void getnodes_response_cb(const Tox_Event_Dht_Get_Nodes_Response *event,
// ask new node to give us their close nodes to every public key
for (size_t i = 0; i < NUM_TOXES; ++i) {
tox_dht_get_nodes(autotox->tox, public_key, ip, port, state->public_key_list[i], nullptr);
tox_dht_send_nodes_request(autotox->tox, public_key, ip, port, state->public_key_list[i], nullptr);
}
}
static void test_dht_getnodes(AutoTox *autotoxes)
static void test_dht_nodes_request(AutoTox *autotoxes)
{
ck_assert(NUM_TOXES >= 2);
@ -125,7 +124,7 @@ static void test_dht_getnodes(AutoTox *autotoxes)
ck_assert(public_key_list[i] != nullptr);
tox_self_get_dht_id(autotoxes[i].tox, public_key_list[i]);
tox_events_callback_dht_get_nodes_response(autotoxes[i].dispatch, getnodes_response_cb);
tox_events_callback_dht_nodes_response(autotoxes[i].dispatch, nodes_response_cb);
printf("Peer %zu dht closenode count total/announce-capable: %d/%d\n",
i,
@ -153,7 +152,7 @@ int main(void)
Run_Auto_Options options = default_run_auto_options();
options.graph = GRAPH_LINEAR;
run_auto_test(nullptr, NUM_TOXES, test_dht_getnodes, sizeof(State), &options);
run_auto_test(nullptr, NUM_TOXES, test_dht_nodes_request, sizeof(State), &options);
return 0;
}

View File

@ -13,11 +13,13 @@
#include <stdlib.h>
#include <string.h>
#include "../testing/misc_tools.h"
#include "../toxcore/ccompat.h"
#include "../toxcore/tox.h"
#include "auto_test_support.h"
#include "check_compat.h"
#include "../toxcore/ccompat.h"
#include "../toxcore/tox.h"
#include "../toxencryptsave/toxencryptsave.h"
static const char *pphrase = "bar";
@ -27,21 +29,26 @@ static const char *savefile = "./save";
static void save_data_encrypted(void)
{
struct Tox_Options *options = tox_options_new(nullptr);
ck_assert(options != nullptr);
Tox *t = tox_new_log(options, nullptr, nullptr);
ck_assert(t != nullptr);
tox_options_free(options);
tox_self_set_name(t, (const uint8_t *)name, strlen(name), nullptr);
FILE *f = fopen(savefile, "wb");
ck_assert(f != nullptr);
size_t size = tox_get_savedata_size(t);
uint8_t *clear = (uint8_t *)malloc(size);
ck_assert(clear != nullptr);
/*this function does not write any data at all*/
tox_get_savedata(t, clear);
size += TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
uint8_t *cipher = (uint8_t *)malloc(size);
ck_assert(cipher != nullptr);
Tox_Err_Encryption eerr;
@ -66,11 +73,12 @@ static void load_data_decrypted(void)
int64_t size = ftell(f);
fseek(f, 0, SEEK_SET);
ck_assert_msg(0 <= size && size <= UINT_MAX, "file size out of range");
ck_assert_msg(TOX_PASS_ENCRYPTION_EXTRA_LENGTH <= size && size <= UINT_MAX, "file size out of range");
uint8_t *cipher = (uint8_t *)malloc(size);
ck_assert(cipher != nullptr);
uint8_t *clear = (uint8_t *)malloc(size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH);
const size_t clear_size = size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
uint8_t *clear = (uint8_t *)malloc(clear_size);
ck_assert(clear != nullptr);
size_t read_value = fread(cipher, sizeof(*cipher), size, f);
printf("Read read_value = %u of %u\n", (unsigned)read_value, (unsigned)size);
@ -78,23 +86,23 @@ static void load_data_decrypted(void)
Tox_Err_Decryption derr;
ck_assert_msg(tox_pass_decrypt(cipher, size, (const uint8_t *)pphrase, strlen(pphrase), clear, &derr),
"Could not decrypt, error code %d.", derr);
"Could not decrypt, error code %s.", tox_err_decryption_to_string(derr));
struct Tox_Options *options = tox_options_new(nullptr);
ck_assert(options != nullptr);
tox_options_set_experimental_owned_data(options, true);
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
tox_options_set_savedata_data(options, clear, size);
ck_assert(tox_options_set_savedata_data(options, clear, clear_size));
free(clear);
Tox_Err_New err;
Tox *t = tox_new_log(options, &err, nullptr);
ck_assert_msg(t != nullptr, "tox_new returned the error value %s", tox_err_new_to_string(err));
tox_options_free(options);
ck_assert_msg(t != nullptr, "tox_new returned the error value %d", err);
uint8_t *readname = (uint8_t *)malloc(tox_self_get_name_size(t));
ck_assert(readname != nullptr);
tox_self_get_name(t, readname);
@ -103,7 +111,6 @@ static void load_data_decrypted(void)
"name returned by tox_self_get_name does not match expected result");
tox_kill(t);
free(clear);
free(cipher);
free(readname);
fclose(f);

View File

@ -1,7 +1,5 @@
#include <stdlib.h>
#include <string.h>
#include "../testing/misc_tools.h"
#include "../toxcore/network.h"
#include "check_compat.h"
@ -34,9 +32,8 @@ static void test_addr_resolv_localhost(void)
bool res = addr_resolve_or_parse_ip(ns, mem, localhost, &ip, nullptr, true);
int error = net_error();
char *strerror = net_new_strerror(error);
ck_assert_msg(res, "Resolver failed: %d, %s", error, strerror);
net_kill_strerror(strerror);
Net_Strerror error_str;
ck_assert_msg(res, "Resolver failed: %d, %s", error, net_strerror(error, &error_str));
Ip_Ntoa ip_str;
ck_assert_msg(net_family_is_ipv4(ip.family), "Expected family TOX_AF_INET, got %u.", ip.family.value);
@ -57,9 +54,7 @@ static void test_addr_resolv_localhost(void)
}
error = net_error();
strerror = net_new_strerror(error);
ck_assert_msg(res, "Resolver failed: %d, %s", error, strerror);
net_kill_strerror(strerror);
ck_assert_msg(res, "Resolver failed: %d, %s", error, net_strerror(error, &error_str));
ck_assert_msg(net_family_is_ipv6(ip.family), "Expected family TOX_AF_INET6 (%d), got %u.", TOX_AF_INET6,
ip.family.value);
@ -80,9 +75,7 @@ static void test_addr_resolv_localhost(void)
ip_reset(&extra);
res = addr_resolve_or_parse_ip(ns, mem, localhost, &ip, &extra, true);
error = net_error();
strerror = net_new_strerror(error);
ck_assert_msg(res, "Resolver failed: %d, %s", error, strerror);
net_kill_strerror(strerror);
ck_assert_msg(res, "Resolver failed: %d, %s", error, net_strerror(error, &error_str));
#if USE_IPV6
ck_assert_msg(net_family_is_ipv6(ip.family), "Expected family TOX_AF_INET6 (%d), got %u.", TOX_AF_INET6,

View File

@ -60,7 +60,7 @@ int main(int argc, char **argv)
c_sleep(100);
}
const uint16_t tcp_port = 8082;
const uint16_t tcp_port = 7082;
uint32_t index[] = { 1, 2, 3, 4 };
struct Tox_Options *tox_options = tox_options_new(nullptr);
@ -92,7 +92,7 @@ int main(int argc, char **argv)
// tox3 has UDP disabled and connects to tox1 via an HTTP proxy
tox_options_set_udp_enabled(tox_options, false);
tox_options_set_proxy_host(tox_options, "127.0.0.1");
tox_options_set_proxy_port(tox_options, 8080);
tox_options_set_proxy_port(tox_options, 7080);
tox_options_set_proxy_type(tox_options, TOX_PROXY_TYPE_HTTP);
Tox *tox3 = tox_new_log(tox_options, nullptr, &index[2]);
@ -101,7 +101,7 @@ int main(int argc, char **argv)
// tox4 has UDP disabled and connects to tox1 via a SOCKS5 proxy
tox_options_set_udp_enabled(tox_options, false);
tox_options_set_proxy_host(tox_options, "127.0.0.1");
tox_options_set_proxy_port(tox_options, 8081);
tox_options_set_proxy_port(tox_options, 7081);
tox_options_set_proxy_type(tox_options, TOX_PROXY_TYPE_SOCKS5);
Tox *tox4 = tox_new_log(tox_options, nullptr, &index[3]);