Squashed 'external/toxcore/c-toxcore/' changes from e2c01e457b..b03b571272

b03b571272 fix: flaky tcp test This only fixes the symptoms, not the real problem. Sometimes or consistently on some platforms a socket might need a moment before it can be written to.
32e67ab4c2 cleanup: use typedef for private message ID's in callback
7b1db6adc1 feat: add message IDs to private group messages
99e0bcc27d refactor: Observers/ignored peers can now send and receive custom packets
b3c3c49d26 fix: Disable IPv6 in Windows cross-compilation tests
e742deddff feat: Check hashes of Windows dependencies when cross-compiling
dfb9a0b02b fix: Test the current Windows Dockerfile, not an old Dockerhub image
14de93ccec chore: Use WineHQ's Wine as Debian Bookworm's crashes
ed37616249 docs: Update the Windows cross-compilation section
9bb79c174f cleanup: Remove a couple of unnecessary misc_tools dependencies
19475adb70 chore: Statically link OpenMP into the cracker fun util on Windows
1be311e51f feat: Build the fun utils when cross-compiling to Windows
88133f8446 chore: Strip Windows binaries
3cc0ae7535 refactor: Copy over all of the required static dependencies
c4fa8f7fb1 feat: Generate .def, .exp and .lib files when building for Windows
74bbac5363 feat: Let CMake create the dll instead of doing so ourselves
246642e9ae feat: Harden Windows cross-compilation
8d431c0d11 chore: Bump Windows build dependency versions
e519f7998b fix: Remove unnecessary wsock32 dependency on Windows
ed2b60c217 chore: Use a specific non-broken slimcc version.
d7f21010a1 chore: Update github actions.
e71a68b7f2 docs: Update the list of CMake options
77e08876ff chore: Remove mod and founder from group API naming scheme
12bc042767 docs: add the experimental api build option to INSTALL.md
e1fa5cae96 refactor: Rename Queries to Query to align with other enums.
be82a3ea30 fix: Correct type for conference offline peer numbers.
0627c36716 test: Add pkgsrc build.
92578afe4b test: Add FreeBSD VM action on GitHub.
52ece0f57b test: Build toxcore on NetBSD (VM).
3fe8ee2c11 chore: Only install tox_private.h on request.
9a8dfa06ab fix: save_compatibility_test failing on big-endian systems
86f5e55578 fix: Don't serve files from websockify.
710eb674a5 fix: Correctly pass extended public keys to group moderation code.
021db7031c refactor: Use `struct`s for extended public/secret keys.
a1e999fd80 chore: Compile libsodium reference implementation with compcert.
fbe3c19cf5 cleanup: correct a few nullable annotations
623e3ee5c3 cleanup: Don't use `memcpy` to cast arbitrary `struct`s to `uint8_t[]`.
c71567dc18 fix: Pass array, not array pointer, to `memcmp`.
9b46a08144 cleanup: Never pass `void*` directly to `memcpy`.
5d7b7a7bbc refactor: Use tox rng to seed the keypair generation.
961891d568 cleanup: Small improvements found by PVS Studio.
8201019f0d chore: Disable NGC saving by default, enable through Tox_Options.
5dd9ee3f65 cleanup: Replace pointer arithmetic with explicit `&arr[i]`.
ca4606d49d refactor: Use strong typedef for NGC peer id.
442213b722 cleanup: Simplify custom packet length check in NGC.
08d3393def fix: Correct a few potential null derefs in bootstrap daemon.
b9877b32b0 fix: Add missing memunlock of local variable when it goes out of scope.
dab5fe44b9 fix: Zero out stack-allocated secret key before return.
f058103299 refactor: Make prune_gc_sanctions_list more obviously correct.
3ba7a0dec9 docs: Add static analysis tool list to README.
8d0811a0f3 docs: Run prettier-markdown on markdown files.
969e3a2bfc refactor: Fix network test not using the strong typedef
93c83fbc7c refactor: Use strong typedef instead of struct for `Socket`.
9fe18b176f fix: Fix some false positive from PVS Studio.
7c44379ccb cleanup: Check that WINXP macro exists before comparing it.
5c93231bef refactor: Make tox mutex non-recursive.
aacff73939 docs: Fix up doxyfile.
d55fc85ff5 docs: Add more documentation to crypto_core.
5bdaaaedb6 refactor: Remove `Tox *` from `tox_dispatch`.
e202341e76 refactor: Don't rely on tox_dispatch passing tox in tests.
34df938f52 chore: Use C++ mode for clang-tidy.
8b05296a78 chore: Check that both gtest and gmock exist for tests.
42010660e1 test: Add slimcc compiler compatibility test.
b473630321 chore: Add some comments to the astyle config.
b7404f24f6 cleanup: Remove implicit bool conversions.
4e2dba4d9f chore: Reformat sources with astyle.
4359e3a6bc chore: Rename C++ headers to .hh suffixes.
0c05566e58 cleanup: Further `#include` cleanups.
8d29935b7a chore: Only check the bootstrap daemon checksum on release.
f70e588bc6 cleanup: Add more `const` where possible.
511bfe39c8 cleanup: Use Bazel modules to enforce proper `#include` hygiene.
1710a0d091 refactor: Move pack/unpack `IP_Port` from DHT into network module.
a975943564 chore: Really fix coverage docker image build.
c08409390f chore: Fix post-submit coverage image.
39aadf8922 fix: Don't use `memcmp` to compare `IP_Port`s.
d94246a906 fix: partially fix a bug that prevented group part messages from sending.
eeaa039222 chore: Fix rpm build; add a CI check for it.
8328449c1a chore: Speed up docker builds a bit by reducing layer count.
d6d67d56f3 cleanup: Add `const` where possible in auto tests.
6aa9e6850d cleanup: Minor cleanup of event unpack code.
bdf460a3a9 refactor: Rename `system_{memory,...}` to `os_{memory,...}`.
203e1af81e fix: a few off by one errors in group autotests
5c093c4888 cleanup: Remove all uses of `SIZEOF_VLA`.
662c2140f3 test: Add goblint static analyser.
8f07755834 cleanup: Use `memzero(x, s)` instead of `memset(x, 0, s)`.
a7258e40cf cleanup: Use explicit 0 instead of `PACKET_ID_PADDING`.
6370d0f15d cleanup: Expand the `Tox_Options` accessor macros.
14a1a0b9bd cleanup: Remove plan9 support.
a05dccad13 test: Add a simple new/delete test for Tox.
1cdcf938b9 cleanup: Add comment after every `#endif`.
ba99d4dc4b test: Fix comment I broke in the events test PR.
e07248debb refactor: Migrate auto_tests to new events API.
bdd42b5452 refactor: Add common msgpack array packer with callback.
3c659f5288 cleanup: Rename group to conference in groupav documentation.
89957be230 cleanup: Ensure handler params are named after callback params.
c650d9d345 refactor: Pass `this` pointer as first param to s11n callbacks.
e7fb91ddb8 refactor: Allow NULL pointers for byte arrays in events.
5e2c8cabc1 cleanup: make some improvements to group moderation test
259de4867e cleanup: Remove `bin_pack_{new,free}`.
21a8ff5895 cleanup: skip a do_gc iteration before removing peers marked for deletion
16809dc36e feat: Add dht_get_nodes_response event to the events system.

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: b03b5712720de9a9901ea12fd741f177327a7021
This commit is contained in:
2024-03-07 23:12:55 +01:00
parent 61accfe184
commit aae086cc65
358 changed files with 8093 additions and 5229 deletions

View File

@ -14,6 +14,7 @@
#include "DHT.h"
#include "Messenger.h"
#include "attributes.h"
#include "ccompat.h"
#include "crypto_core.h"
#include "friend_connection.h"
@ -243,7 +244,6 @@ static bool is_groupnumber_valid(const Group_Chats *g_c, uint32_t groupnumber)
&& g_c->chats[groupnumber].status != GROUPCHAT_STATUS_NONE;
}
/** @brief Set the size of the groupchat list to num.
*
* @retval false if realloc fails.
@ -429,7 +429,6 @@ static int get_peer_index(const Group_c *g, uint16_t peer_number)
return -1;
}
non_null()
static uint64_t calculate_comp_value(const uint8_t *pk1, const uint8_t *pk2)
{
@ -488,7 +487,7 @@ static bool add_to_closest(Group_c *g, const uint8_t *real_pk, const uint8_t *te
comp_val = calculate_comp_value(real_pk, g->real_pk);
for (unsigned int i = DESIRED_CLOSEST / 2; i < DESIRED_CLOSEST; ++i) {
uint64_t comp = calculate_comp_value(g->closest_peers[i].real_pk, g->real_pk);
const uint64_t comp = calculate_comp_value(g->closest_peers[i].real_pk, g->real_pk);
if (comp > comp_val && comp > comp_d) {
index = i;
@ -956,11 +955,6 @@ static bool delpeer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, void
return true;
}
static int cmp_u64(uint64_t a, uint64_t b)
{
return (a > b ? 1 : 0) - (a < b ? 1 : 0);
}
/** Order peers with friends first and with more recently active earlier */
non_null()
static int cmp_frozen(const void *a, const void *b)
@ -972,7 +966,7 @@ static int cmp_frozen(const void *a, const void *b)
return pa->is_friend ? -1 : 1;
}
return cmp_u64(pb->last_active, pa->last_active);
return cmp_uint(pb->last_active, pa->last_active);
}
/** @brief Delete frozen peers as necessary to ensure at most `g->maxfrozen` remain.
@ -1043,7 +1037,6 @@ static bool freeze_peer(Group_Chats *g_c, uint32_t groupnumber, int peer_index,
return true;
}
/** @brief Set the nick for a peer.
*
* do_gc_callback indicates whether we want to trigger callbacks set by the client
@ -1405,7 +1398,6 @@ static const Group_Peer *peer_in_list(const Group_c *g, uint32_t peernumber, boo
return &list[peernumber];
}
/**
* @brief Copy the public key of (frozen, if frozen is true) peernumber who is in
* groupnumber to pk.
@ -1622,12 +1614,13 @@ static bool send_packet_group_peer(const Friend_Connections *fr_c, int friendcon
}
group_num = net_htons(group_num);
VLA(uint8_t, packet, 1 + sizeof(uint16_t) + length);
const uint32_t packet_size = 1 + sizeof(uint16_t) + length;
VLA(uint8_t, packet, packet_size);
packet[0] = packet_id;
memcpy(packet + 1, &group_num, sizeof(uint16_t));
memcpy(packet + 1 + sizeof(uint16_t), data, length);
return write_cryptpacket(friendconn_net_crypto(fr_c), friend_connection_crypt_connection_id(fr_c, friendcon_id), packet,
SIZEOF_VLA(packet), false) != -1;
return write_cryptpacket(friendconn_net_crypto(fr_c), friend_connection_crypt_connection_id(fr_c, friendcon_id),
packet, packet_size, false) != -1;
}
/** @brief Send a group lossy packet to friendcon_id.
@ -1644,12 +1637,13 @@ static bool send_lossy_group_peer(const Friend_Connections *fr_c, int friendcon_
}
group_num = net_htons(group_num);
VLA(uint8_t, packet, 1 + sizeof(uint16_t) + length);
const uint32_t packet_size = 1 + sizeof(uint16_t) + length;
VLA(uint8_t, packet, packet_size);
packet[0] = packet_id;
memcpy(packet + 1, &group_num, sizeof(uint16_t));
memcpy(packet + 1 + sizeof(uint16_t), data, length);
return send_lossy_cryptpacket(friendconn_net_crypto(fr_c), friend_connection_crypt_connection_id(fr_c, friendcon_id),
packet, SIZEOF_VLA(packet)) != -1;
packet, packet_size) != -1;
}
/** @brief invite friendnumber to groupnumber.
@ -1782,7 +1776,8 @@ static bool send_invite_response(Group_Chats *g_c, int groupnumber, uint32_t fri
const bool member = g->status == GROUPCHAT_STATUS_CONNECTED;
VLA(uint8_t, response, member ? INVITE_MEMBER_PACKET_SIZE : INVITE_ACCEPT_PACKET_SIZE);
const uint32_t response_size = member ? INVITE_MEMBER_PACKET_SIZE : INVITE_ACCEPT_PACKET_SIZE;
VLA(uint8_t, response, response_size);
response[0] = member ? INVITE_MEMBER_ID : INVITE_ACCEPT_ID;
net_pack_u16(response + 1, groupnumber);
memcpy(response + 1 + sizeof(uint16_t), data, length);
@ -1791,7 +1786,7 @@ static bool send_invite_response(Group_Chats *g_c, int groupnumber, uint32_t fri
net_pack_u16(response + 1 + sizeof(uint16_t) + length, g->peer_number);
}
if (!send_conference_invite_packet(g_c->m, friendnumber, response, SIZEOF_VLA(response))) {
if (!send_conference_invite_packet(g_c->m, friendnumber, response, response_size)) {
return false;
}
@ -2013,7 +2008,6 @@ static bool group_leave(const Group_Chats *g_c, uint32_t groupnumber, bool perma
}
}
/** @brief set the group's title, limited to MAX_NAME_LENGTH.
* @retval 0 on success
* @retval -1 if groupnumber is invalid.
@ -2115,8 +2109,8 @@ static bool get_peer_number(const Group_c *g, const uint8_t *real_pk, uint16_t *
}
non_null(1, 3) nullable(5)
static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length,
void *userdata)
static void handle_friend_invite_packet(Messenger *m, uint32_t friend_number, const uint8_t *cookie, uint16_t length,
void *user_data)
{
Group_Chats *g_c = m->conferences_object;
@ -2124,20 +2118,20 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con
return;
}
switch (data[0]) {
switch (cookie[0]) {
case INVITE_ID: {
if (length != INVITE_PACKET_SIZE) {
return;
}
const int groupnumber = get_group_num(g_c, data[1 + sizeof(uint16_t)], data + 1 + sizeof(uint16_t) + 1);
const int groupnumber = get_group_num(g_c, cookie[1 + sizeof(uint16_t)], cookie + 1 + sizeof(uint16_t) + 1);
const uint8_t *invite_data = data + 1;
const uint8_t *invite_data = cookie + 1;
const uint16_t invite_length = length - 1;
if (groupnumber == -1) {
if (g_c->invite_callback != nullptr) {
g_c->invite_callback(m, friendnumber, invite_data[sizeof(uint16_t)], invite_data, invite_length, userdata);
g_c->invite_callback(m, friend_number, invite_data[sizeof(uint16_t)], invite_data, invite_length, user_data);
}
return;
@ -2145,7 +2139,7 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con
const Group_c *g = get_group_c(g_c, groupnumber);
if (g != nullptr && g->status == GROUPCHAT_STATUS_CONNECTED) {
send_invite_response(g_c, groupnumber, friendnumber, invite_data, invite_length);
send_invite_response(g_c, groupnumber, friend_number, invite_data, invite_length);
}
}
@ -2154,7 +2148,7 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con
case INVITE_ACCEPT_ID:
case INVITE_MEMBER_ID: {
const bool member = data[0] == INVITE_MEMBER_ID;
const bool member = cookie[0] == INVITE_MEMBER_ID;
if (length != (member ? INVITE_MEMBER_PACKET_SIZE : INVITE_ACCEPT_PACKET_SIZE)) {
return;
@ -2162,8 +2156,8 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con
uint16_t other_groupnum;
uint16_t groupnum;
net_unpack_u16(data + 1, &other_groupnum);
net_unpack_u16(data + 1 + sizeof(uint16_t), &groupnum);
net_unpack_u16(cookie + 1, &other_groupnum);
net_unpack_u16(cookie + 1 + sizeof(uint16_t), &groupnum);
Group_c *g = get_group_c(g_c, groupnum);
@ -2171,18 +2165,18 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con
return;
}
if (data[1 + sizeof(uint16_t) * 2] != g->type) {
if (cookie[1 + sizeof(uint16_t) * 2] != g->type) {
return;
}
if (!group_id_eq(data + 1 + sizeof(uint16_t) * 2 + 1, g->id)) {
if (!group_id_eq(cookie + 1 + sizeof(uint16_t) * 2 + 1, g->id)) {
return;
}
uint16_t peer_number;
if (member) {
net_unpack_u16(data + 1 + sizeof(uint16_t) * 2 + 1 + GROUP_ID_LENGTH, &peer_number);
net_unpack_u16(cookie + 1 + sizeof(uint16_t) * 2 + 1 + GROUP_ID_LENGTH, &peer_number);
} else {
/* TODO(irungentoo): what if two people enter the group at the
* same time and are given the same peer_number by different
@ -2201,7 +2195,7 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con
}
}
const int friendcon_id = getfriendcon_id(m, friendnumber);
const int friendcon_id = getfriendcon_id(m, friend_number);
if (friendcon_id == -1) {
// TODO(iphydf): Log something?
@ -2212,7 +2206,7 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con
uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE];
get_friendcon_public_keys(real_pk, temp_pk, g_c->fr_c, friendcon_id);
addpeer(g_c, groupnum, real_pk, temp_pk, peer_number, userdata, true, true);
addpeer(g_c, groupnum, real_pk, temp_pk, peer_number, user_data, true, true);
const int connection_index = add_conn_to_groupchat(g_c, friendcon_id, g,
GROUPCHAT_CONNECTION_REASON_INTRODUCING, true);
@ -2386,7 +2380,6 @@ static int handle_packet_rejoin(Group_Chats *g_c, int friendcon_id, const uint8_
return 0;
}
// we could send title with invite, but then if it changes between sending and accepting inv, joinee won't see it
/**
@ -2400,7 +2393,6 @@ static bool send_peer_introduced(const Group_Chats *g_c, int friendcon_id, uint1
return send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, packet, sizeof(packet));
}
/**
* @retval true on success.
* @retval false on failure
@ -2457,11 +2449,12 @@ static unsigned int send_peers(const Group_Chats *g_c, const Group_c *g, int fri
}
if (g->title_len > 0) {
VLA(uint8_t, title_packet, 1 + g->title_len);
const uint32_t title_packet_size = 1 + g->title_len;
VLA(uint8_t, title_packet, title_packet_size);
title_packet[0] = PEER_TITLE_ID;
memcpy(title_packet + 1, g->title, g->title_len);
send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num, title_packet,
SIZEOF_VLA(title_packet));
send_packet_group_peer(g_c->fr_c, friendcon_id, PACKET_ID_DIRECT_CONFERENCE, group_num,
title_packet, title_packet_size);
}
return sent;
@ -2554,13 +2547,11 @@ static void handle_direct_packet(Group_Chats *g_c, uint32_t groupnumber, const u
break;
}
case PEER_RESPONSE_ID: {
handle_send_peers(g_c, groupnumber, data + 1, length - 1, userdata);
break;
}
case PEER_TITLE_ID: {
if (!g->title_fresh) {
settitle(g_c, groupnumber, -1, data + 1, length - 1, userdata);
@ -2696,7 +2687,8 @@ static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint
return -3;
}
VLA(uint8_t, packet, sizeof(uint16_t) + sizeof(uint32_t) + 1 + len);
const uint16_t packet_size = sizeof(uint16_t) + sizeof(uint32_t) + 1 + len;
VLA(uint8_t, packet, packet_size);
const uint16_t peer_num = net_htons(g->peer_number);
memcpy(packet, &peer_num, sizeof(peer_num));
@ -2715,7 +2707,7 @@ static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint
memcpy(packet + sizeof(uint16_t) + sizeof(uint32_t) + 1, data, len);
}
const unsigned int ret = send_message_all_connections(g_c, g, packet, SIZEOF_VLA(packet), -1);
const unsigned int ret = send_message_all_connections(g_c, g, packet, packet_size, -1);
if (ret == 0) {
return -4;
@ -2768,14 +2760,15 @@ int send_group_lossy_packet(const Group_Chats *g_c, uint32_t groupnumber, const
return -1;
}
VLA(uint8_t, packet, sizeof(uint16_t) * 2 + length);
const uint16_t packet_size = sizeof(uint16_t) * 2 + length;
VLA(uint8_t, packet, packet_size);
const uint16_t peer_number = net_htons(g->peer_number);
memcpy(packet, &peer_number, sizeof(uint16_t));
const uint16_t message_num = net_htons(g->lossy_message_number);
memcpy(packet + sizeof(uint16_t), &message_num, sizeof(uint16_t));
memcpy(packet + sizeof(uint16_t) * 2, data, length);
if (send_lossy_all_connections(g_c, g, packet, SIZEOF_VLA(packet), -1) == 0) {
if (send_lossy_all_connections(g_c, g, packet, packet_size, -1) == 0) {
return -1;
}
@ -3758,7 +3751,6 @@ bool conferences_load_state_section(Group_Chats *g_c, const uint8_t *data, uint3
return true;
}
/** Create new groupchat instance. */
Group_Chats *new_groupchats(const Mono_Time *mono_time, Messenger *m)
{