Commit Graph

661 Commits

Author SHA1 Message Date
Robin Linden
290b1a7716
test: Improve the stability of the save_load test
We were leaving a self_connection_status callback attached to tox1 while
reloading tox2 and 3, the only other toxes in the network. This lead to
tox1 occasionally going offline, triggering the "Tox went offline"
assert and failing the test.
2022-03-19 13:09:07 +01:00
iphydf
faccbe3943
test: Speed up toxav_many_test by using fake mono_time. 2022-03-17 18:20:40 +00:00
iphydf
2f10cb1730
cleanup: Count re-adding an existing bootstrap node as success.
It does nothing in the onion, but we shouldn't be reporting failure for
it. Also added a bit more information to the `tox_bootstrap` logging.
2022-03-07 17:42:16 +00:00
iphydf
3275bb8fea
cleanup: Add explicit callback setters for MSI callbacks.
Instead of a callback ID and a `switch`.
2022-03-04 10:33:23 +00:00
iphydf
cff9a18e39
cleanup: Split util.c out of the network library.
Also, don't include ccompat.h in header files. Instead, explicitly
include it in .c files.
2022-03-04 10:33:11 +00:00
iphydf
f19524cb21
cleanup: Remove dependency from LAN_discovery onto DHT.
As a side-effect, DHT now always accepts LAN discovery packets, even
when LAN discovery is disabled. When LAN discovery is disabled, those
packets are ignored.
2022-03-04 10:19:05 +00:00
iphydf
21688d1d34
cleanup: Move test-only functions into tests.
Also inlined `new_networking` in most places.
2022-03-03 23:58:43 +00:00
iphydf
2cc8dafd4c
cleanup: Remove redundant Messenger and DHT tests.
These don't test anything that isn't covered by higher level tox tests.
These are also not unit tests and have never found any bug that wasn't
also caught by other tests. This makes them a pure maintenance burden.
2022-03-03 21:17:03 +00:00
iphydf
6c2014d719
cleanup: Remove port from Broadcast_Info.
This is added later when we actually send the broadcasts.
2022-03-03 15:21:34 +00:00
iphydf
fe4da6a541
cleanup: Log at ERROR level when connect() fails.
Failure is defined as either being passed an invalid IP/Port, or some
unexpected error code.
2022-02-28 14:01:01 +00:00
iphydf
163e9c3b03
cleanup: Remove more boolean conversions (and a bugfix).
These were found by the new stronger type check in cimple. The one
bugfix is in `crypto_sha512_cmp`, which used to think `crypto_verify_32`
returns bool while actually it's -1/0/1.
2022-02-26 00:03:56 +00:00
iphydf
093927ba4f
test: Add mallocfail and proxy test to our coverage runs. 2022-02-25 01:55:28 +00:00
iphydf
aa72c47125
test: Add test coverage docker build for local tests.
This uses mallocfail to further increase coverage using the existing
tests. Also:
* Moved the non-auto "tox_one_test" to gtest. This should be
  split into smaller tests later.
* Changed `hole_punching` to `bool`.
2022-02-24 16:24:28 +00:00
iphydf
2ce6f5b169
fix: Report failure to DHT bootstrap back to the client.
Also reduce log verbosity a bit.
2022-02-24 11:37:47 +00:00
iphydf
f98137d697
refactor: Move tox_new_log to auto_test_support.
This is only used in auto tests.
2022-02-21 17:39:10 +00:00
iphydf
e7bc611dac
cleanup: Enable most cppcheck warnings as errors.
Cleaned up some of the warnings it gives. Disabled the ones that are
less useful for us at this time.
2022-02-21 17:17:36 +00:00
iphydf
84a03bc2ed
cleanup: Enable tokstyle's -Wlarge-struct-params. 2022-02-18 10:49:46 +00:00
iphydf
7b2f6c34c6
cleanup: Apply stronger type checks and fix errors.
Found a bug, too: file recv and chunk events were intermittently
converting to `uint32_t`, losing precision.
2022-02-17 22:34:56 +00:00
Rodrigo Martins
96843fbae4
Take advantage of fast networks for file transfers
- Make sender send more data per iteration.
- Make receiver iterate more often while receiving.

Before this commit tox would send at maximum around 4MiB/s. With this
patch sustained speeds of up to 100MiB/s were observed on a
low-latency, high-bandwidth network.

As a consequence of iterating more frequently the receiver's CPU usage
is increased for the duration of the transfer. The data structures
used to represent friends and file transfers cause the sender code use
costly loops that do little real work. This patch makes this problem
more visible: the sender uses more CPU while sending.

Poor network conditions were simulated using the netem kernel
facility: $ tc qdisc add dev lo root netem delay 100ms 50ms \
loss 1% duplicate 1% corrupt 1% reorder 25% 50%
and no adverse behavior was encountered. Tests were conducted
using toxic using both UDP and TCP.
2022-02-15 12:22:11 +00:00
iphydf
a3cd1102f7
perf: Reduce minimal encoding size of packed events.
We're using a union-like encoding now with an enum telling which union
member to set.
2022-02-12 17:44:44 +00:00
iphydf
33588c1aad
cleanup: Don't use VLAs for huge allocations.
One of these was creating a single 262144 byte stack frame. We now have
a way to check and limit the allocation size of a VLA. The `Cmp_Data`
ones were also fairly large. Now, no allocation is larger than 2KiB
(though rtp.c allocates close to that much).
2022-02-11 03:05:30 +00:00
jfreegman
73ba0504b0
Add autotest for dht getnodes API
The test creates a small DHT and makes sure that each
peer is able to crawl the full network
2022-02-10 10:33:34 -05:00
Maxim Biro
bab4949433
Get skeletons out of the closet
The test was removed in c7ecee7c15 but
the entries in the build system remained, causing autotools to spit out
warnings.
2022-02-10 08:16:10 -05:00
Maxim Biro
6e8ea97c06
Fix shared toxcore autotools build failing
Turns out libtoxcore.so wasn't being linked against libmsgpackc.
2022-02-10 05:28:03 -05:00
iphydf
10f86f6c00
cleanup: Add more nonnull and nullable annotations. 2022-02-09 20:03:34 +00:00
iphydf
cb8b9bbabf
feat: Add unpacker functions for events structures. 2022-02-08 00:02:51 +00:00
iphydf
0a2190f28c
feat: Add binary packing functions for tox events. 2022-02-07 02:43:24 +00:00
iphydf
de4af4c270
feat: Add async event handling (callbacks) code.
Instead of synchronously handling events as they happen in
`tox_iterate`, this first collects all events in a structure and then
lets the client process them. This allows clients to process events in
parallel, since the data structure returned is mostly immutable.

This also makes toxcore compatible with languages that don't (easily)
support callbacks from C into the non-C language.

If we remove the callbacks, this allows us to add fields to the events
without breaking the API.
2022-02-06 17:28:28 +00:00
jfreegman
5619b5e056
Make more functions take const pointers to IP_Port
We additionally now make local copies of the IP_Port param instead
of modifying the passed argument
2022-02-03 11:17:29 -05:00
jfreegman
5880971af8
Make functions take const pointer to IP_Port wherever possible
An IP_Port is a fairly large data structure, and copying them down
the call stack creates a lot of unnecessary overhead.
2022-02-03 10:54:48 -05:00
iphydf
727982d2f9
fix: Fix bootstrap on emscripten/wasm.
Also added a whole bunch of logging that I needed while debugging the
issue. The solution in the end is that bootstrap needs to resolve IPs,
and getaddrinfo fails in the browser. Most of the time we bootstrap
against IPs anyway, so trying to parse as IP address first will shortcut
that.
2022-02-01 21:00:09 +00:00
Robin Linden
2cfa872818
Add a Bazel Buildifier CI job 2022-01-28 00:55:07 +01:00
jfreegman
d2f98b83c2
Fix some minor issues with autotests
- Do null check on autotox pointer for all public functions
- Reverse argument order: autotoxes -> count instead of opposite
2022-01-26 10:27:41 -05:00
zugz (tox)
1157e4e68c
Separate run_auto_tests into a library 2022-01-25 14:25:36 -05:00
jfreegman
10d59d610b
Refactor autotest live network bootstrapping
- Use one node list and public bootstrap function for all autotests
- Use ifdefs for testnet/mainnet nodes
- Replace a few broken nodes with working ones
2022-01-22 11:24:28 -05:00
iphydf
4ce02c0af9
refactor: Deduplicate a bunch of code in TCP client/server.
Also generally a bit of cleanup and better layering.
2022-01-16 09:41:08 +00:00
iphydf
c7ecee7c15
cleanup: Remove old check Suite compat layer.
This doesn't do anything useful for us. It was there so we don't need to
rewrite the tests (which I just did). Finally this is now cleaned up.
2022-01-16 01:37:37 +00:00
iphydf
6823fcbae1
cleanup: Stop using strerror directly.
We have a more portable wrapper that is now also thread-safe. Also
stopped using sprintf in the one place we used it. This doesn't really
help much, but it allows us to forbid sprintf globally.
2022-01-15 01:25:56 +00:00
jfreegman
62cbd5f667
Add a couple more bootstrap nodes to autotests
A little more redundancy can save a lot of pain debugging non-existent
problems
2022-01-14 14:40:14 -05:00
iphydf
d23222c92f
chore: Run static analysers in multiple variants.
Currently: 1) libsodium and 2) nacl.

Note that the "nacl" variant is actually libsodium. We just want to make
sure the static analysers see the `VANILLA_NACL` code paths.
2022-01-14 10:45:11 +00:00
iphydf
28b5e512a2
fix: Fix toxav_basic_test buffer overflow.
We should pass the number of samples, not the byte size of `PCM`.
2022-01-13 22:36:53 +00:00
iphydf
4a2cb37e4b
fix: Fix some uninitialised memory errors found by valgrind and msan.
Also added a valgrind build to run it on every pull request. I've had to
disable a few tests because valgrind makes those run infinitely slowly,
consistently timing them out.
2022-01-13 20:15:21 +00:00
iphydf
f5f22a5c76
chore: Enable layering check in all c-toxcore build files. 2022-01-12 18:33:13 +00:00
sudden6
d2bf72479c
fix: use correct sample size in toxav_basic_test 2022-01-04 21:12:57 +01:00
jfreegman
e6d671eeab
Add ability for autotests to use TCP connections
This also allows us to set other tox options
2022-01-01 15:43:59 -05:00
zugz (tox)
64a48c0e78
cleanup: Remove hardening code from DHT 2021-12-30 00:00:01 +00:00
iphydf
eb4dc4326a
refactor: Extract some functions from the big run_auto_test function.
This reduces complexity of the single function. Also reduced duplication
a bit.
2021-12-29 00:50:12 +00:00
iphydf
d9ab91970d
cleanup: Remove apidsl for everything except the public API.
Apidsl is not powerful enough to express all the things we need and
doesn't know how `#include` works. The generated headers are more complex
than they should be.
2021-12-15 17:36:29 +00:00
iphydf
f49ea44daa
cleanup: Remove crypto_pwhash import.
Vanilla nacl builds won't have toxencryptsave.
2021-12-15 17:16:35 +00:00
iphydf
6b75f8b889
chore: Remove config.h.
This aligns the autotools build with the cmake build, which doesn't have
a config.h file. It also removes the ambiguity of config.h and
other/bootstrap_daemon/src/config.h.
2021-12-15 10:26:50 +00:00
iphydf
5c1796d3c4
chore: Use docker for the autotools ci build.
This makes it easier to run it locally for testing and ensures the
dockerfile continues to work.
2021-12-14 15:51:51 +00:00
iphydf
5c53e6a30f
chore: Add autotools build; exempt crypto_pwhash from tokstyle. 2021-12-13 18:47:45 +00:00
iphydf
fa359091c7
chore: Minor cleanups of warnings given by cppcheck. 2021-12-09 11:08:03 +00:00
jfreegman
edf9d66717
Add logger to onion and onion announce objects
This will be used in the future
2021-12-07 13:01:15 -05:00
iphydf
cdc0286050
cleanup: Minor fixes in test code.
* Buffer overrun in auto test.
* Resource leak in AFL test code.
2021-12-07 17:13:58 +00:00
iphydf
101e235131
cleanup: Fix last instance of -Wcast-align and enable the warning.
We used to have lots of these in the code, but now that all the endian
stuff is no longer dependent on host byte order, we can re-enable the
warning flag and catch any future violations.
2021-12-07 14:51:31 +00:00
Robin Linden
713ce6108c
Improve Tox creation logging in save_load test 2021-12-06 23:28:53 +01:00
jfreegman
b66165977e
fix issue with save_load autotest
The test explicitly wanted a UDP connection when a TCP connection would suffice. This
was a remnant of back when the test was part of a multi-purpose autotest that
didn't attempt to connect to TCP relays and needed a UDP connection specifically.
2021-11-25 15:32:29 -05:00
Robin Linden
a71ddc7eac
Fix tests involving reading/writing files failing on Windows
The issue was that r and w without the b flag on Windows does LF and CR
translations when reading and writing. Not good for binary files.
2020-11-21 13:02:31 +01:00
iphydf
fe8e0fb8fa
Fix tcp_relay_test by adding a second bootstrap node.
This is a non-hermetic network test. initramfs node is down, so let's
have a second one for redundancy.
2020-05-17 12:41:00 +01:00
iphydf
cc99ecd43a
Stop hard-coding packet IDs in tests. 2020-05-04 02:14:56 +01:00
iphydf
02a5bdc60c
Add logging to TCP and onion client. 2020-05-04 01:27:36 +01:00
iphydf
88b90c8225
Fix a bug in savedata loading when malloc fails.
Also added a bunch of asserts to tests where they don't check allocs.
2020-05-03 14:13:48 +00:00
iphydf
2570ddcb17
Fix errors on error paths found by oomer.
* Use-after-free because we free network before dht in one case.
* Various unchecked allocs in tests (not so important).
* We used to not check whether ping arrays were actually allocated in DHT.
* `ping_kill` and `ping_array_kill` used to crash when passing NULL.

Also:
* Added an assert in all public API functions to ensure tox isn't NULL.
  The error message you get from that is a bit nicer than "Segmentation
  fault" when clients (or our tests) do things wrong.
* Decreased the sleep time in iterate_all_wait from 20ms to 5ms.
  Everything seems to still work with 5ms, and this greatly decreases
  the amount of time spent per test run, making oomer run much faster.
2020-05-02 21:47:08 +01:00
zugz (tox)
8816e50ed7
Skip invalid TCP relays and DHT nodes when loading save data 2020-04-26 00:00:00 +00:00
iphydf
7c0eb5c70b
Enable TCP relay test in Bazel and autotools build.
This test was fixed by @robinlinden, but not enabled in all builds.
2020-04-20 09:28:00 +00:00
Robin Linden
7f9f8045cd
Fix things not being initialized if creating a TCP-only network 2020-04-13 22:43:51 +02:00
iphydf
4b73607b6f
Fixes towards building on MSVC. 2020-03-29 02:56:09 +00:00
iphydf
44e13956ef
Mark conference test as small.
This used to take a long time, but is now very fast.
2020-03-27 14:51:45 +00:00
zugz (tox)
db07bda7f7
Add "member" invite response
This allows invitations to work in the case that the invitee is already
in the group, which can happen if the group becomes split. Such an
invitation is automatically accepted, leading to the peers becoming
connected in the group and sharing peer lists.
2020-03-18 00:00:00 +00:00
iphydf
52696a0686
Add another bootstrap node to the bootstrap test.
Hopefully not both will be down at the same time.
2020-03-15 23:53:59 +00:00
iphydf
11ad5471b9
Use spdx license identifier instead of GPL blurb. 2020-03-14 13:06:19 +00:00
zugz (tox)
c644ef7681
use -1 rather than ~0 in unsigned integer types
Using ~0 involves a bitwise operation on int, so depends on
the internal representation of signed integers.
2020-03-14 00:00:02 +00:00
iphydf
e671490989
Use rules_cc instead of native cc_library rules. 2020-03-12 12:20:54 +00:00
iphydf
0f7138c010
Upgrade bazel to 2.1.1.
Removed av_test, because it depends on an ancient opencv that starts to
really not exist on modern systems anymore.
2020-03-02 14:23:44 +00:00
sudden6
1b7d7b66c5
synchronize call control actions to tox_iterate 2020-01-02 11:58:42 +01:00
Robin Linden
79748dd9e5
Allow Bazel to rerun tests marked as flaky 2019-11-17 01:24:02 +01:00
Robin Linden
f6235b5f8d
Update tests to use a working bootstrap node 2019-11-02 15:35:21 +01:00
zugz (tox)
306dd1f21f
add configurable limit on number of stored frozen peers 2019-05-19 18:51:28 +02:00
sudden6
b3100c977c
add undef guard in tox_many_tcp_test
This fixes an redefinition error when creating amalgamation.cc during
static analysis
2019-05-01 14:24:46 +02:00
zugz (tox)
efff822aef
Disable failing TCP server test
The test's intermittent failure may well be exposing a real bug in the
TCP relay and/or onion systems, but we can't find the bug, and keeping
the test is disrupting our CI.
2019-04-01 19:43:32 +02:00
zugz (tox)
959f468eac
add API function to test whether av is enabled 2019-02-10 00:00:00 +00:00
zugz (tox)
49e2406ffa
Expose api functions for enabling and disabling AV in AV groups
A group loaded from a savefile starts with AV disabled.
2019-02-10 00:00:00 +00:00
zoff99
78bc9e7403
Added test and patch for VLA stack overflow vuln.
Also added and used the new crypto_malloc and crypto_free.

The latter also zeroes out the memory safely. The former only exists for
symmetry (static analysis can detect asymmetric usages).
2019-01-03 11:13:27 +00:00
zugz (tox)
9770880e97
Implement conferences saving
* add global friend_connection status callback, used for group rejoining
* stop leaving groups on killing tox
2018-11-29 21:52:23 +01:00
zugz (tox)
caca350f43
Avoid format truncation in save compatibility test
(without this, gcc-8.2.0 issues a warning)
2018-11-23 18:09:45 +01:00
zugz (tox)
744dc2f5da
Make saving and loading the responsibility of Tox rather than Messenger 2018-10-20 11:03:10 +02:00
zugz (tox)
4dd86f1f29
ensure save data unchanged after save and load 2018-10-11 00:21:39 +02:00
iphydf
605dfe882c
Consistently use camel case enum names.
Including in tests and implementation files.
2018-10-09 17:33:37 +00:00
iphydf
b2b96b1aa1
Avoid use of IPv6 in tests if not supported (e.g. on Travis). 2018-10-06 21:27:02 +00:00
iphydf
4f266f913d
Use a working DHT node for bootstrap tests.
A lot of bootstrap nodes are down :(.
2018-09-25 21:19:07 +00:00
zugz (tox)
e43b2eadc0
Send rejoin packets on conference disconnection
We were mistakenly not making a rejoin attempt on freezing connections
due to all closest connections going down. This fixes that, and tweaks
the test. I've still only done tens rather than hundreds of tests, but
I'm fairly confident that the conference test now consistently passes.
2018-09-20 22:30:28 +02:00
yangfl
d3d5b701cb
Fix typos 2018-09-19 18:16:13 +00:00
iphydf
49bb43f662
Standardise header guards.
Using the full path including the repo name.
2018-09-14 19:09:10 +00:00
hugbubby
0688877fba
Use run_auto_test fixture in typing_test.c 2018-09-14 13:51:41 +00:00
iphydf
d9541d542c
Use (void) for empty parameter lists in C.
Because `()` means "some unknown number of parameters".
2018-09-08 10:59:30 +00:00
zugz
1b2322284f
Add mechanism for recovering from disconnections in conferences
* add freezing and unfreezing of peers
  * add rejoin packet
  * revise handling of temporary invited connections
  * rename "peer kill" packet to "peer leave" packet
  * test rejoining in conference test
  * use custom clock in conference test
2018-09-05 20:56:26 +02:00
iphydf
6872c14e1a
Avoid use of global mutable state in mono_time on win32.
This uses a trick to get read-write access to `this` from a `const`
member function, similar to C++ `mutable`, but uglier.
2018-09-03 20:03:47 +00:00
zugz (tox)
9764285ab1
Use test clock in run_auto_test tests and dht test 2018-08-31 17:08:35 +02:00
zugz (tox)
66ab386d6f
try ipv6 connections even after udp timeout
Also adds a test (auto_reconnect_test) which fails without this change.
2018-08-27 22:27:01 +02:00