Commit Graph

5633 Commits

Author SHA1 Message Date
iphydf ad054511e6 refactor: Internalize DHT structs and add debug helpers.
- Move `struct NAT` from `toxcore/DHT.h` to `toxcore/DHT.c` to improve
  encapsulation.
- Add `tcp_packet_type_to_string` and `tcp_packet_from_int` to
  `toxcore/TCP_common` for better debug logs.
- Add `net_family_to_string` to `toxcore/net` for the same reason.
2026-01-17 17:25:19 +00:00
iphydf 8b467cc963 fix: Prevent potential integer overflow in group chat handshake.
- Change length from `uint16_t` to `uint32_t` in `make_gc_handshake_packet`.
- Add explicit cast to `uint16_t` when calling `wrap_group_handshake_packet`.

This is a hardening measure. Currently, `MAX_SENT_GC_NODES` is 1, so the
length variable (`uint16_t`) cannot overflow. However, if this constant
were increased significantly in the future, the addition `length +=
nodes_size` could wrap around. This change eliminates that latent risk.
2026-01-17 16:03:19 +00:00
iphydf 4962bdbb80 test: Improve TCP simulation and add tests
- `FakeTcpSocket` handles basic TCP state machine (SYN, ACK, RST, buffering).
- `NetworkUniverse` handles TCP routing and loopback.
- Add `TcpRelayChaining` test.
- Add LogFilter to Simulation.
2026-01-17 14:35:20 +00:00
iphydf 5f0227093c refactor: Allow nullable data in group chat handlers.
Removed the workaround in process_recv_array_entry where we replaced
nullptr data with empty_data.
2026-01-17 12:38:18 +00:00
iphydf e97b18ea99 chore: Improve Windows Docker support.
- Add `run` helper script and `.dockerignore` files.
- Update `build_dependencies.sh` to include GTest so we can run unit
  tests on Windows.
2026-01-17 03:50:47 +00:00
iphydf b14943bbdd refactor: Move Logger out of Messenger into Tox.
So it can be used across other pieces we plug together in `tox_new`.
2026-01-15 18:08:29 +00:00
iphydf dd31362509 cleanup: Apply nullability qualifiers to C++ codebase. 2026-01-15 12:19:00 +00:00
iphydf 1849f70fca refactor: Extract low-level networking code to net and os_network.
Move core networking types and the Network interface to net, and the
standard OS socket implementation to os_network. Update network to use
these new abstractions.
2026-01-14 23:44:18 +00:00
iphydf 8fec754218 refactor: Delete tox_random, align on rng and os_random. 2026-01-14 15:15:40 +00:00
iphydf a03ae8051e refactor: Delete tox_memory, align on mem and os_memory.
os_memory will be os_mem later.
2026-01-14 10:19:05 +00:00
iphydf 4c88fed2c9 refactor: Use std:: prefixes more consistently in C++ code. 2026-01-14 02:10:10 +00:00
iphydf 72452f2aeb test: Add some more tests for onion and shared key cache.
Also some other cleanups.
2026-01-13 23:43:56 +00:00
iphydf d5a51b09a2 cleanup: Use tox_attributes.h in tox_private.h and install it.
Only when using experimental APIs.
2026-01-13 23:24:29 +00:00
iphydf b6f5b9fc56 test: Add some benchmarks for various high level things. 2026-01-12 14:37:27 +00:00
iphydf 8a8d02785e test(support): Introduce threaded Tox runner and simulation barrier
- Add `MpscQueue` for thread-safe task scheduling.
- Add `ToxRunner` to execute Tox instances in dedicated threads.
- Update `Simulation` to coordinate time steps across multiple runners using a synchronization barrier.
- Refactor `FakeMemory` and `FakeClock` to be thread-safe.
- Update `tox_network` helpers and tests to utilize the threaded runner infrastructure.
2026-01-11 22:51:59 +00:00
Green Sky d68d1d0950 perf(toxav): optimize audio and video intermediate buffers
by keeping them around
2026-01-11 18:02:08 +01:00
iphydf 4f6d4546b2 test: Improve the fake network library.
Some bugfixes, and getting ready for benchmark support code.
2026-01-11 12:32:44 +00:00
iphydf a2581e700d refactor(toxcore): generate Friend_Request and Dht_Nodes_Response
Update `generate_event_c.cpp` to support `EventTypeByteArray` and custom C
types for byte ranges.
2026-01-10 01:59:15 +00:00
iphydf 2aaa11770e refactor(toxcore): use Tox_Memory in generated events
Update event generator to use mem_balloc/mem_delete for byte arrays in
events, ensuring consistency with Tox memory management. Also fix struct
initialization to use compound literals compliant with tokstyle.
2026-01-09 23:05:37 +00:00
iphydf 5c367452b9 test(toxcore): fix incorrect mutex in tox_scenario_get_time
Fixes CID 1668103 and CID 1668102 by protecting `s->virtual_clock` with
`s->clock_mutex` instead of `s->mutex`, consistent with other usages.
2026-01-09 15:48:58 +00:00
iphydf 8f92e710f3 perf: Add a timed limit of number of cookie requests.
Avoids being spammed by cookie requests and spending a lot of CPU on it.
2026-01-09 15:05:43 +00:00
iphydf 695b6417aa test: Add some more simulated network support.
We'll need this for future tests (coming soon).
2026-01-08 18:50:34 +00:00
iphydf 815ae9ce9d test(toxcore): fix thread-safety in scenario framework
Properly lock virtual clock access and snapshot synchronization to
address Coverity CIDs 1668069, 1668068, 1668067, 1668066. Use a separate
clock_mutex to avoid the need for recursive mutexes and ensure
portability.
2026-01-08 12:59:31 +00:00
iphydf 6d85c754e7 test(toxcore): add unit tests for net_crypto
Also:
- Add NULL checks for shared key retrieval in cookie handling.
- Add warning logs for handshake failures.
2026-01-07 20:40:31 +00:00
iphydf 9c22e79cc8 test(support): add SimulatedEnvironment for deterministic testing
Introduces a new testing support library 'testing/support' that provides
a clean, modular, and fully deterministic environment for testing
toxcore components.
2026-01-07 13:06:18 +00:00
iphydf f34fcb1956 chore: Update windows Dockerfile to debian stable (trixie). 2026-01-06 17:44:49 +00:00
iphydf ece0e89801 fix(group_moderation): allow validating unsorted sanction list signatures
Some clients might send the sanctions list signatures unsorted, which
causes the credentials hash validation to fail because the hash is
sensitive to the order of signatures.

This updates the validation logic to verify the credentials hash against
both the sorted (default) and unsorted signature list. If the sorted
check fails but the unsorted check succeeds, the credentials are
accepted.
2026-01-06 15:38:19 +00:00
iphydf a4fa754d7b refactor: rename struct Packet to struct Net_Packet
Better namespacing.
2026-01-06 14:36:31 +00:00
iphydf d6f330f859 cleanup: Fix some warnings from coverity.
It complained about locking and type casts.
2026-01-06 13:39:41 +00:00
iphydf e206bffa2d fix(group_chats): fix sync packets reverting topics
When a peer processes a topic packet that matches the current topic lock
version, it typically accepts it. However, if this packet is a delayed
sync packet containing the *previous* topic, it causes the topic to
revert.

This commit adds a check in `handle_gc_topic_validate`. If the incoming
topic checksum matches the `topic_prev_checksum` (the checksum of the
topic before the current one) and the current topic was set recently
(within `GC_CONFIRMED_PEER_TIMEOUT`), we reject the update as a probable
sync error.

Added `auto_tests/scenarios/scenario_group_topic_revert_test.c` to
reproduce and verify the fix.
2026-01-06 04:30:50 +00:00
iphydf 0e4715598f test: Add new scenario testing framework. 2026-01-05 21:45:47 +00:00
iphydf 668291f441 refactor(toxcore): decouple Network_Funcs from sockaddr via IP_Port
Replaces the use of the platform-specific `Network_Addr` in the public
`Network_Funcs` interface with the platform-independent `IP_Port`
struct, allowing higher-level abstractions (like simulated networks for
testing) to interact with the network layer without needing to depend on
or mock low-level OS socket headers.
2026-01-05 18:58:33 +00:00
iphydf fc4396cef6 fix: potential division by zero in toxav and unsafe hex parsing
- Fix a potential division by zero crash in `toxav/audio.c` when
  `lp_sampling_rate` is 0.
- Fix unsafe hex string parsing in `bootstrap_daemon/config.c` that
  could leave variables uninitialized (replacing `sscanf` with a safe
  helper).

Also address various clang-tidy findings:
- Enforce const correctness and fix implicit bool conversions in
  `toxav`.
- Sort includes in `toxav`.
2026-01-05 16:08:32 +00:00
iphydf 8e8b352abc refactor: Add nullable annotations to struct members.
Also add a bunch of casts where needed. I've tried to model everything
in such a way that it minimises casts. The casts *should* be safe, but
it's not always obvious. In the obvious cases, we should have a linter
that validates it. In the non-obvious cases, that linter should warn and
require that we add a null check. I've added some null checks in some
cases but not all.

Also, refactored some of the constructor functions to never assign a
maybe-null value to a non-null struct member, instead using a temporary
local variable to check if construction/allocation succeeded.
2026-01-04 23:38:38 +00:00
iphydf 7740bb421f refactor: decouple net_crypto from DHT
This introduces a vtable interface for the DHT dependency in net_crypto,
allowing us to break the dependency and make testing/mocking/fuzzing easier.
2026-01-04 20:59:26 +00:00
iphydf 1936d42965 test: add benchmark for toxav audio and video
This includes RTP, but no networking.
2026-01-02 01:58:07 +00:00
iphydf 46bfdc2df7 fix: correct printf format specifiers for unsigned integers 2026-01-01 16:01:12 +00:00
iphydf b66b8ded66 refactor: improve group stability, moderation determinism, and DHT dual-stack handling
* DHT Routing: Fixed dual-stack handling to clear stale IPv4/IPv6 associations when a node's address updates.
* Performance: Switched to memcmp for public key/hash comparisons (safe for non-secrets).
* Group Chat Reliability:
    * Added logic to use friend connection IPs as a fallback if DHT discovery is slow, with a fix to prevent overwriting existing valid IPs.
    * Increased handshake connection limits and fixed full-group sync behavior.
    * Enforced list sorting and fixed timestamps to ensure consistent moderation state hashes across all peers.
2026-01-01 03:27:34 +00:00
iphydf 4fbd7c10a9 fix(toxav): fix heap buffer overflow in RTP video packet handling
The `rtp_receive_packet` function (via `fill_data_into_slot`) relied on
the `data_length_full` field in the RTP header to allocate the frame
buffer, but failed to verify that the actual payload length of the
incoming packet fit within this allocated size. A malicious peer could
send a packet with a small `data_length_full` but a large payload,
causing `memcpy` to write past the end of the buffer.

This commit adds a bounds check to ensure that the packet offset plus
the payload length does not exceed the total frame length. Tested via
unit tests.
2026-01-01 01:32:23 +00:00
iphydf 809fe8c78c refactor(tox): make the #define consts int literals.
Some language bindings generators don't like doing sizeof math.
2025-12-31 00:32:41 +00:00
iphydf 50d242a370 refactor(toxav): improve MSI safety and testability
- Refactor MSISession to use a mandatory MSICallbacks struct in msi_new.
- Remove individual MSI callback setters to enforce full initialization.
- Fix doubly linked list corruption in new_call when reusing friend numbers.
- Fix missing capability updates and callback triggers during friend recall.
- Remove legacy toxav_hacks.h and clean up build files.
2025-12-31 00:32:39 +00:00
iphydf da1c13a2f9 fix(toxav): harden video processing and fix large frame handling
- Remove invalid vpx_img_free call in vc_iterate.
- Make vc_reconfigure_encoder atomic and add resolution limits.
- Support 32-bit RTPMessage lengths to correctly handle large frames.
- Ensure len is correctly set for assembled video frames.
- Add security checks for incoming frame sizes and resolutions.
- Significantly expand video and rtp unit tests covering security scenarios.
- Clean up VCSession structure and improve internal API consistency.
- Use #define for security constants in video module.
2025-12-30 21:59:14 +00:00
iphydf 4728252888 fix(toxav): fix multiple logic bugs in audio module
- Fix heap-buffer overflow in `ac_iterate` (PLC) by validating sampling rates and channel counts from untrusted RTP packets.
- Fix out-of-bounds read by adding explicit packet length validation (minimum 5 bytes).
- Fix jitter buffer reset bug where late packets caused a full buffer clear due to unsigned wrap-around.
- Fix jitter buffer PLC logic to correctly handle sequence number wrap-around at 16-bit boundaries.
- Refactor `ac_iterate` to process all currently ready packets in a single call, improving throughput.
- Optimize `ac_iterate` by moving the large scratch buffer allocation outside the packet processing loop.
- Add unit tests covering jitter buffer edge cases, wrap-around scenarios, and malicious packet handling.
- Refactor `ACSession` to be opaque and provide accessor for frame duration.
2025-12-30 17:37:05 +00:00
iphydf dc963d9a99 fix(toxav): fix multiple bugs in bandwidth controller and add tests
- Fix rate limiting logic to be wrap-around safe for timestamps.
- Fix potential division-by-zero/sum-overflow in percentage calculation by using double precision.
- Fix NULL callback dereference in send_update.
- Add comprehensive unit tests covering edge cases and bug scenarios.
- Refactor BWController to be more testable by injecting a packet sending callback.
2025-12-30 17:35:51 +00:00
iphydf 3bf5778efb refactor(toxav): split out RTP module and add exhaustive unit tests 2025-12-30 17:11:53 +00:00
Constantin Sunzow b79b7d4365 fix(autotools): add tox_log_level.h to public headers list
The tox_log_level.h header file was added as a public API header in
version 0.2.21, but was not included in the libtoxcore_la_include_HEADERS
variable in toxcore/Makefile.inc. This caused the header to not be
installed when building with autotools, leading to compilation errors
for applications that include tox_options.h (which depends on
tox_log_level.h, like qTox).

This patch adds tox_log_level.h to the list of installed headers,
matching the behavior of the CMake build system.

Commit: c834472637
Fixes: compilation error "tox_log_level.h: No such file or directory"
2025-12-25 14:34:07 +00:00
iphydf ea2e34ff26 chore: Disable cirrus. We're out of quota again. 2025-12-25 10:33:33 +00:00
Green Sky b449ea2ed4 chore(ci): update azure runner image to windows-2022
windows-2019 is EOL
2025-11-24 12:34:36 +01:00
iphydf e115b136d5 refactor: Make add_to_list non-recursive. 2025-11-05 01:18:42 +00:00
iphydf 206ea35304 refactor: Explicitly pass dependencies to constructors.
Instead of transitively loading them from dependencies, we should be
explicit about what each object needs. The downside of this is that it's
not clear whether the object and its dependency use the same common
dependency. The upside is that we don't expose those getters of internal
dependencies.
2025-11-02 23:31:59 +00:00