Commit Graph

361 Commits

Author SHA1 Message Date
iphydf
b4d8826228
cleanup: Remove old type-ordered event getters.
These are quite expensive, because they go through all events to index
in a typed array that no longer exists. Clients should index in the
union array and find the event they want themselves, or use dispatch.
2024-01-15 17:29:43 +00:00
Green Sky
001d00ab30
fix: dont resolve to ipv6 addresses when its disabled 2024-01-15 15:29:01 +01:00
iphydf
4cea4f9ca4
fix: Make all the fuzzers work again, and add a test for protodump.
fuzz_select_target wasn't selecting anything, so fuzzers using that
function either did nothing or would only ever select one of the
functions.
2024-01-13 15:06:30 +00:00
iphydf
c4e209ea1d
refactor: Factor out malloc+memcpy into memdup.
Only applied in one place, but perhaps later we can implement a pattern
in tokstyle to find more opportunities for using memdup.
2024-01-13 11:57:21 +00:00
jfreegman
87bcc4322d
fix: Remove fatal error for non-erroneous case
We allow non-null data pointers to be passed to functions
alongside 0-length data. For example when creating a data
buffer that has room for the entire packet, including ignored
header data.

This error broke a rare but legitimate case where we miss
packets during a handshake attempt and need to store empty
handshake packets in the packet array.
2024-01-12 20:06:43 -05:00
jfreegman
072e3beb3f
fix: issues with packet broadcast error reporting
commit 5b9c420c introduced some undesirable behaviour with packet send
functions returning error when they shouldn't. We now only return an
error if the packet fails to be added to the send queue or cannot
be wrapped/encrypted. We no longer error if we fail to send the packet
over the wire, because toxcore will keep trying to re-send the packet
until the connection times out.

Additionally, we now make sure that our packet broadcast functions
aren't returning an error when failing to send packets to peers
that we have not successfully handshaked with yet, since this is
expected behaviour.
2024-01-11 14:54:58 -05:00
jfreegman
6b6718e4d2
cleanup: Make group packet entry creation less error-prone
We always assumed that create_array_entry() would only be called
with an empty array entry and wouldn't modify entries on error.
We now explicitly require both conditions, and also give an
error in the case of a non-null data pointer with a zero
length field, as this indicates a logic error.

Checks for an empty array entry that precede a call to
create_array_entry() are now redundant. It should be noted that
a non-empty entry doesn't necessarily indicate an error. This
condition can be triggered if packets are being sent or
received faster than they can be processed/acknowledged,
which is common when spamming messages on poor connections.
2024-01-11 11:02:29 -05:00
jfreegman
5b9c420ce1
refactor: packet broadcast functions now return errors
We now return an error if our broadcast packets fail to
send for every peer in the group
2024-01-11 10:06:46 -05:00
iphydf
c66e10fb7a
refactor: Minor refactoring of get_close_nodes functions.
Avoiding passing down the entire DHT struct pointer to the inner
functions makes it possible in the future to write unit tests without
having to construct a full DHT object.
2024-01-10 20:12:04 +00:00
jfreegman
ebc9643862
fix: don't pass garbage data buffer to packet send functions
This garbage data was never looked at due to passing
a zero length along with it, but it's still undesirable.
2024-01-10 12:37:21 -05:00
iphydf
0426624dcb
refactor: Assign malloc return to a local variable first. 2024-01-10 11:46:41 +00:00
iphydf
afc38f2458
test: Add more unit tests for add_to_list. 2024-01-10 02:58:13 +00:00
iphydf
05ce5c1ab9
test: Add "infer" CI check to github, remove from circle.
This now uses our own built image with the current master of infer.
2024-01-09 10:59:53 +00:00
iphydf
b148a2afff
chore: Simplify msvc build using vcpkg. 2024-01-06 12:27:31 +00:00
iphydf
c9ca4007e3
refactor: Align group message sending with other send functions.
None of the others use out parameters. Also no toxcore function uses out
parameters for anything other than arrays and errors. This would be a
first, for no good reason.
2024-01-05 19:20:01 +00:00
iphydf
cac074c57f
chore: Add fetch-sha256 script to update bootstrap node hash.
This fetches it from github, so we don't need to build it locally.

Not super ideal, because devs are supposed to build it locally to prove
reproducibility, but we can keep that diligence on the dev to do once
when actually merging the PR.
2024-01-03 23:01:55 +00:00
Maxim Biro
32576656bb
Make the comment capitalization uniform 2024-01-02 19:07:39 -05:00
Maxim Biro
aff4dda17c
Spellcheck tox-bootstrapd 2024-01-02 19:07:37 -05:00
iphydf
0e42752f0f
cleanup: Move all vptr-to-ptr casts to the beginning of a function.
These casts are effectively part of the function type, so it makes sense
to have them at the beginning.
2023-12-30 01:45:23 +00:00
iphydf
bd930cc80a
cleanup: Make TCP connection failures a warning instead of error.
It's not really bad, unless all connections fail. This is currently
erroring on FreeBSD tests, making them fail needlessly.
2023-12-27 02:08:09 +00:00
iphydf
fad6e4e173
cleanup: Make all .c files include the headers they need. 2023-12-27 01:21:47 +00:00
iphydf
ef4897a898
cleanup: Upgrade to clang-tidy-17 and fix some warnings. 2023-12-27 01:05:47 +00:00
iphydf
b7f9367f6f
test: Upgrade cppcheck, fix some warnings.
Also started teaching it about toxcore's alloc/dealloc functions in
hopes of it catching some errors (it doesn't seem to be very good at
this, but maybe better than nothing?).
2023-12-27 00:00:10 +00:00
iphydf
766e62bc89
chore: Use pkg_search_module directly in cmake.
The `pkg_use_module` was doing magic we used to use, but no longer need.
2023-12-26 01:14:50 +00:00
iphydf
00ff078f91
cleanup: Use target_link_libraries directly in cmake.
Instead of using `target_link_modules`, which does magic that we no
longer need, because we only have 1 library we install, and all binaries
we build link statically because they need access to internal symbols.
2023-12-26 00:24:08 +00:00
iphydf
895a6af122
cleanup: Remove NaCl support.
We now depend on libsodium unconditionally. Future work will require
functions from libsodium, and nobody we're aware of uses the nacl build
for anything other than making sure it still works on CI.
2023-12-25 00:36:38 +00:00
iphydf
415cb78f5e
cleanup: Some portability/warning fixes for Windows builds. 2023-12-21 19:02:20 +00:00
iphydf
425216d9ec
fix: Correct a use-after-free and fix some memory leaks.
Also: use `find_package` to find gtest. This fixes the coverage build to
include unit tests.
2023-12-21 17:17:51 +00:00
iphydf
4e603bb613
refactor: Use enum-from-int rule from tokstyle.
These functions are a bit clearer and don't need to change if enum
values change.

See https://github.com/TokTok/hs-tokstyle/pull/212 for the relevant
linter implementation.
2023-12-19 20:53:15 +00:00
Green Sky
2b0dc0f46b
add ngc related unpack functions 2023-12-19 19:18:28 +01:00
jfreegman
b2315c50e0
Add groupchat API function that returns an IP address string for a peer
This function will return an IP address string associated with a peer.
If the peer is not accepting direct connections a placeholder value
will be returned, indicating that their real IP address is unknown.
We do not return TCP relay IP addresses because a TCP connection
with a peer may use multiple relays simultaneously.
2023-12-19 11:07:03 -05:00
iphydf
5f863a5492
feat: Add to_string functions for all public enums.
Generated by tokstyle: https://github.com/TokTok/hs-tokstyle/pull/214
2023-12-19 15:38:10 +00:00
iphydf
028b017d79
perf: Slightly reduce bandwidth usage when there are few nodes.
This mainly saves spam in test logs, but may save some packets here and
there, if nodes are randomly selected twice for GET_NODES and onion
routing packets.
2023-12-18 16:23:45 +00:00
iphydf
90f7496819
feat: Enable ubsan on bootstrap nodes.
Not all sanitizers are enabled, but the cheap ones are, making the
bootstrap node quite a bit more secure at a small runtime cost.
2023-12-16 10:47:14 +00:00
Green Sky
01e7950c67
increase lossy custom packet size in ngc to the toxcore common max of 1373 2023-12-15 00:57:33 +01:00
jfreegman
9b3c1089f1
Make group saving/loading more forgiving with data errors
Rather than aborting the process on invalid group save data we
either try to continue if possible, or abort the saving/loading
instead of the entire process
2023-12-14 10:21:21 -05:00
Maxim Biro
55a76003b0
Replace memset(int32_t*, -1, _) with a for-loop
memset() treats the passed buffer as a char* array, assigning to every
1-byte of the array the value. So for a single 4-byte int32_t element,
it is assigning bytes 0, 1, 2 and 3 of it to -1. It happens that -1 is
0xFF, so in the end the uint32_t is set to 0xFFFFFFFF, which is -1 in
the two's complement, so the memset() actually produces the correct
result in the end, assuming the platform uses two's complement integers.

Assigning it in the loop is less error-prone, as using memset() on
non-1-byte wide arrays with a non-zero value is fishy, and it is more
portable as we don't have to assume the use of two's complement.

It looks like in a future version of the C standard, C23, two's
complement is the only integer format in C23 (thanks to @robinlinden on
IRC for pointing that out), so perhaps we shouldn't be as concerned with
the portability here? Though @iphydf says that it's still a good idea to
use a for-loop for this case.
2023-12-13 18:40:12 -05:00
iphydf
3983369103
fix: Enable debug flag for ubsan.
Otherwise the nullability annotations are compiled out in attributes.h.
2023-12-09 01:14:53 +00:00
Maxim Biro
4d1db21102
Update tox-boostrapd hash 2023-12-08 03:31:14 -05:00
Maxim Biro
d0400df13d
Fix memory leak in tox-bootstrapd 2023-12-08 03:31:04 -05:00
Maxim Biro
26d41fc604
Replace DEFAULT_TCP_RELAY_PORTS_COUNT with a compile-time calculation
That way we don't have to rely on a human to remember to keep
DEFAULT_TCP_RELAY_PORTS_COUNT in sync with DEFAULT_TCP_RELAY_PORTS.
2023-12-05 09:56:46 -05:00
iphydf
65b3375b98
refactor: Use Bin_Pack for packing Node_format. 2023-12-04 17:36:09 +00:00
jfreegman
84ba154f6a
group connection queries now return our own connection type 2023-12-04 10:35:50 -05:00
Maxim Biro
a4df2862ed
Replace tabs with spaces 2023-12-03 04:09:43 -05:00
Maxim Biro
1b6dee7594
Update tox-bootstrapd's base Docker images 2023-12-02 01:49:55 -05:00
Maxim Biro
a030cdee5c
Fix Docker tox-bootstrapd hash update failing when using BuildKit
Docker is defaulting to using BuildKit for building images since version
23.0 (2023-02-01), which is not compatible with this script. The script
was fishing the hash of the intermediate build container in which the
build has failed, in order to run the sha256sum in that image, however
with BuildKit there are no longer any intermediate build containers,
which breaks the script.

The legacy builder is supposedly getting removed in a future version of
Docker, which is why we embrace BuildKit instead of reverting to the
legacy builder via DOCKER_BUILDKIT=0:

  $ DOCKER_BUILDKIT=0 docker build ...
  DEPRECATED: The legacy builder is deprecated and will be removed in a
              future release. BuildKit is currently disabled; enable it
              by removing the DOCKER_BUILDKIT=0 environment-variable.

While DOCKER_BUILDKIT=1 is unnecessary on Docker >= 23.0, it's needed
for anyone running older Docker, so it makes sense to have it in for
now, while everyone transitions.
2023-12-02 01:49:53 -05:00
iphydf
7cfe35dff2
cleanup: Remove explicit layering_check feature.
It's default in .bazelrc now.
2023-11-23 23:55:57 +00:00
iphydf
d1e850c56c
fix: Add missing htons call when adding configured TCP relay. 2023-11-23 00:13:16 +00:00
iphydf
7155f7f60e
test: Add an s390x build (on alpine) for CI.
It doesn't work at all, because we're missing something in the net code
to do with endian conversions. I haven't investigated, yet, but at least
now we have a failing test that can be investigated.

Also moved to cmake 3.5 at minimum. CMake will stop supporting lower
versions than that, soon.

Also moved to C11 from C99 to get `static_assert`.

Also made a network ERROR into a WARNING. It triggers on FreeBSD.
2023-11-22 18:29:26 +00:00
iphydf
e726b197b0
refactor: Store time in Mono_Time in milliseconds.
Conversion to seconds happens in `mono_time_get`, and a new function
`mono_time_get_ms` allows code to retrieve monotonic time in
milliseconds.
2023-11-17 05:20:29 +00:00