Compare commits

..

11 Commits

Author SHA1 Message Date
fd4c16d090 Squashed 'external/toxcore/c-toxcore/' changes from da438763d5b..671b1f92332
671b1f92332 fix: toxav rtp temp buffer allocation size was too large and cast from 32bit to 16bit, causing a overflow and making the allocated size too small
258148bd4e1 chore(ci): new minimum for all android versions is 21
d369c93c489 chore: Fix Emscripten build failing with no host specified
51b24d1c239 chore: Run CompCert on the stable branch of libsodium
cab1f7d522b chore: Update WineHQ's apt key hash
102a1fa9b82 chore: Fix -Werror=maybe-uninitialized in a test
cc9515da9c7 chore: Fix cpplint failing to install
3485b5feef3 chore: Disable -Wswitch-default and -Wunsafe-buffer-usage
719041e04b6 chore: Fix Circle CI failing on a missing clang lib
5344d7f84d0 fix: Memory leak in the bootstrap daemon
fa201681e18 cleanup: Remove useless if clause
7572888a218 chore: Fix GitHub actions deprecation warnings

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: 671b1f92332a8314dccf76d5df93c0b6c1230636
2024-09-19 13:45:12 +02:00
47ad96e2b6 Squashed 'external/toxcore/c-toxcore/' changes from 3e05824b80..da438763d5
da438763d5 chore: Release 0.2.19
f90417987c chore: Add cmake flag to disable unit tests.
7df3f99417 docs: Document that group topic lock is default on.
9e9ed77390 docs: Add missing param docs for callbacks.
0ec4978de5 refactor: Don't expose Tox_System in the public API
a3d1b8595c docs: Public headers, Core/toxcore -> Tox/the Tox library
f78d0f3f39 docs: Public headers, events_alloc -> internal
817518949e docs: Public headers, NULL-terminated -> NUL-terminated
be085db191 docs: Public headers, spellcheck
4c902955f3 docs: Public headers, 80 column width comments
be8a82a818 docs: Public headers, null -> NULL
419d783d95 docs: Public headers, tox -> Tox
5c8aa65e41 docs: Update user data API explanation
ad4921dbaa cleanup: A more descriptive error for group invite accept function

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: da438763d5b8e071de6e061a1dcaddd2177dff7d
2024-03-28 16:13:51 +01:00
a5093c4aa3 Squashed 'external/toxcore/c-toxcore/' changes from b03b571272..3e05824b80
3e05824b80 refactor: Rename `out` parameters to `out_$something`.
0199c0f17f cleanup: apply the same scheme to types
aebbfabe26 cleanup: event length naming inconsistencies
2457125aa8 cleanup: align group send err enum order

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: 3e05824b80eb9bee33e8254cba0780d84c522182
2024-03-11 11:34:13 +01:00
aae086cc65 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
2024-03-07 23:12:55 +01:00
61accfe184 Squashed 'external/toxcore/c-toxcore/' changes from 73d9b845a3..e2c01e457b
e2c01e457b refactor: Use enum-specific pack functions for enum values.
afc472402b refactor: Factor out union pack switch from event packer.
6caa7ce4b1 cleanup: Move the 2-element array pack out of individual events.
687af81f20 cleanup: Remove empty test doing nothing.
fcf5882428 test: Add printf log statement to group_moderation_test.
b4d8826228 cleanup: Remove old type-ordered event getters.
8c35e0fefb feat: add ngc events
97bdd83937 refactor: Make event dispatch ordered by receive time.
001d00ab30 fix: dont resolve to ipv6 addresses when its disabled
d3b935f63f fix(test): tests use ipv6 by default, even with USE_IPV6 set to 0
29fc5ea1f7 chore: add clangd files to .gitignore
d30c81acbc refactor: Move file streaming test to its own file.
acdc67387b fix(ci): window builds now build in parallel
REVERT: 73d9b845a3 cleanup: Remove old type-ordered event getters.
REVERT: b0840cc02d feat: add ngc events
REVERT: 7df9a51349 refactor: Make event dispatch ordered by receive time.

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: e2c01e457bfb8a59537175c8fe17ca9ab1c9e3e1
2024-01-15 23:32:23 +01:00
b1fe064484 Squashed 'external/toxcore/c-toxcore/' changes from 6d634674a9..73d9b845a3
73d9b845a3 cleanup: Remove old type-ordered event getters.
b0840cc02d feat: add ngc events
7df9a51349 refactor: Make event dispatch ordered by receive time.
bcb6592af5 test: Add C++ classes wrapping system interfaces.
4cea4f9ca4 fix: Make all the fuzzers work again, and add a test for protodump.
c4e209ea1d refactor: Factor out malloc+memcpy into memdup.
87bcc4322d fix: Remove fatal error for non-erroneous case
REVERT: 6d634674a9 cleanup: Remove old type-ordered event getters.
REVERT: d1d48d1dfc feat: add ngc events
REVERT: 994ffecc6b refactor: Make event dispatch ordered by receive time.

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: 73d9b845a310c3f56d2d6d77ed56b93d84256d6e
2024-01-14 21:51:01 +01:00
8eb4892b49 Squashed 'external/toxcore/c-toxcore/' changes from 8f0d505f9a..6d634674a9
6d634674a9 cleanup: Remove old type-ordered event getters.
d1d48d1dfc feat: add ngc events
994ffecc6b refactor: Make event dispatch ordered by receive time.
812f931d5f fix: Make sure there's enough space for CONSUME1 in fuzzers.
50f1b30fa9 test: Add fuzz tests to the coverage run.
df76f5cf47 chore: Move from gcov to llvm source-based coverage.
072e3beb3f fix: issues with packet broadcast error reporting
6b6718e4d2 cleanup: Make group packet entry creation less error-prone
5b9c420ce1 refactor: packet broadcast functions now return errors
af4cb31028 refactor: Use `operator==` for equality tests of `Node_format`.
9592d590cf refactor(test): Slightly nicer C++ interface to tox Random.
c66e10fb7a refactor: Minor refactoring of get_close_nodes functions.
ebc9643862 fix: don't pass garbage data buffer to packet send functions
32b68cffca cleanup: Some more test cleanups, removing overly smart code.
0426624dcb refactor: Assign malloc return to a local variable first.
afc38f2458 test: Add more unit tests for `add_to_list`.
05ce5c1ab9 test: Add "infer" CI check to github, remove from circle.
REVERT: 8f0d505f9a feat: add ngc events
REVERT: 9b8216e70c refactor: Make event dispatch ordered by receive time.

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: 6d634674a929edb0ab70689dcbcb195b3547be13
2024-01-12 21:30:48 +01:00
9ace11a0e2 Squashed 'external/toxcore/c-toxcore/' changes from f1df709b87..8f0d505f9a
8f0d505f9a feat: add ngc events
9b8216e70c refactor: Make event dispatch ordered by receive time.
814c12a6f4 cleanup: Add dynamically derived array sizes to the API.
226b23be12 cleanup: Add explicit array sizes to toxencryptsave.
ef33cb4de0 cleanup: Add Toxav alias for ToxAV.
1da723b34d cleanup: Make Tox_Options a typedef.
b148a2afff chore: Simplify msvc build using vcpkg.
5cac6d7eb1 cleanup: Move `tox_get_system` out of the public API.
c9ca4007e3 refactor: Align group message sending with other send functions.
6c6c0b1b1b cleanup: Make setters take non-const `Tox *`.
a76f758d70 cleanup: Mark arrays in the tox API as `[]` instead of `*`.
baf6d1f6cf cleanup: Make array params in toxav `[]` instead of `*`.
79f55bd06a cleanup: Put the size of fixed arrays into the API types.
1e73698db2 cleanup: Add typedefs for public API int identifiers.
cac074c57f chore: Add fetch-sha256 script to update bootstrap node hash.
32576656bb Make the comment capitalization uniform
aff4dda17c Spellcheck tox-bootstrapd
40b5fbbe9d chore: Remove settings.yml in favour of hs-github-tools.
ebafd51be7 chore: Use GPL license with https.
0e42752f0f cleanup: Move all vptr-to-ptr casts to the beginning of a function.
5407384211 cleanup: Use github actions matrix to simplify CI.
82d8265688 fix: Use QueryPerformanceCounter on windows for monotonic time.
1224e656e3 chore: Add `net_(new|kill)_strerror` to cppcheck's allocators.
6a90ddfe4e cleanup: Run clang-tidy on headers, as well.
bd930cc80a cleanup: Make TCP connection failures a warning instead of error.
fad6e4e173 cleanup: Make all .c files include the headers they need.
ef4897a898 cleanup: Upgrade to clang-tidy-17 and fix some warnings.
REVERT: f1df709b87 feat: add ngc events
REVERT: 1b6c907235 refactor: Make event dispatch ordered by receive time.

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: 8f0d505f9a598cc41c682178e1589bcc01efe9cb
2024-01-09 16:39:05 +01:00
b2ae9530a4 Squashed 'external/toxcore/c-toxcore/' changes from e29e185c03..f1df709b87
f1df709b87 feat: add ngc events
1b6c907235 refactor: Make event dispatch ordered by receive time.
b7f9367f6f test: Upgrade cppcheck, fix some warnings.
766e62bc89 chore: Use `pkg_search_module` directly in cmake.
00ff078f91 cleanup: Use target_link_libraries directly in cmake.
c58928cc89 chore: Add `IMPORTED_TARGET` to pkg-config packages.
895a6af122 cleanup: Remove NaCl support.
41dfb1c1c0 fix: unpack enum function names in event impl generator
447666d1a1 chore: Disable targets for cross-compilation.
572924e924 chore: Build a docker image with coverage info in it.
415cb78f5e cleanup: Some portability/warning fixes for Windows builds.
425216d9ec fix: Correct a use-after-free and fix some memory leaks.
4b1cfa3e08 refactor: Change all enum-like `#define` sequences into enums.
d3c2704fa9 chore: Fix make_single_file to support core-only.
0ce46b644e refactor: Change the `TCP_PACKET_*` defines into an enum.
22cd38ad50 adopt event impl generation tool to #2392
f31ea1088a add the event impl generation tool
4e603bb613 refactor: Use `enum-from-int` rule from tokstyle.
19d8f180d6 chore: Update github actions `uses`.
6a895be0c7 test: Make esp32 build actually try to instantiate tox.
65d09c9bfb cleanup: Remove test net support.
REVERT: e29e185c03 feat: add ngc events

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: f1df709b8792da4c0e946d826b11df77d565064d
2023-12-27 12:37:22 +01:00
83e200df43 Squashed 'external/toxcore/c-toxcore/' changes from adbd5b32d8..e29e185c03
e29e185c03 feat: add ngc events
2b0dc0f46b add ngc related unpack functions
b2315c50e0 Add groupchat API function that returns an IP address string for a peer
5f863a5492 feat: Add `to_string` functions for all public enums.
0c998a7598 add real timeout test
68c827609a chore: Move s390x build to post-merge.
028b017d79 perf: Slightly reduce bandwidth usage when there are few nodes.
90f7496819 feat: Enable ubsan on bootstrap nodes.
89b6450d66 test: Add check-c run to bazel build.
REVERT: adbd5b32d8 feat: add ngc events

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: e29e185c03fea7337036e5ef4d1d9080a6cee721
2023-12-24 12:21:34 +01:00
9ddeea3d06 Squashed 'external/toxcore/c-toxcore/' changes from d4b06edc2a..adbd5b32d8
adbd5b32d8 feat: add ngc events
15ee46d431 add simple test for max sized lossy custom group packet
01e7950c67 increase lossy custom packet size in ngc to the toxcore common max of 1373
9b3c1089f1 Make group saving/loading more forgiving with data errors
55a76003b0 Replace memset(int32_t*, -1, _) with a for-loop
66453439ac fix: also Install header for private/experimental API functions with autotools
3983369103 fix: Enable debug flag for ubsan.
4d1db21102 Update tox-boostrapd hash
e700c31b70 Fix memory leak in group connection
2994441d9c Fix memory leak in save-generator
d0400df13d Fix memory leak in tox-bootstrapd
7a6d50ebe3 Install header for private/experimental API functions
d89677fb5f Remove defunct IRC channel from README.md
26d41fc604 Replace DEFAULT_TCP_RELAY_PORTS_COUNT with a compile-time calculation
63fb2941ca Clarify disabling of static assert checks
65b3375b98 refactor: Use Bin_Pack for packing Node_format.
84ba154f6a group connection queries now return our own connection type
a4df2862ed Replace tabs with spaces
1b6dee7594 Update tox-bootstrapd's base Docker images
a030cdee5c Fix Docker tox-bootstrapd hash update failing when using BuildKit
7cfe35dff2 cleanup: Remove explicit layering_check feature.
d390947245 chore: Upgrade sonar-scan jvm to java 17.
d1e850c56c fix: Add missing `htons` call when adding configured TCP relay.
814090f2b8 chore: Cancel old PR builds on docker and sonar-scan workflows.
83efb17367 perf: Add a KVM FreeBSD build on cirrus ci.
a927183233 test: Add a test for encrypting 100MB of data.
28f39049f6 chore: Retry freebsd tests 2 times.
47e77d1bb0 chore: Use C99 on MSVC instead of C11.
7155f7f60e test: Add an s390x build (on alpine) for CI.
6c35cef63f chore: Add a compcert docker run script.
41e6ea865e cleanup: Use tcc docker image for CI.
e726b197b0 refactor: Store time in Mono_Time in milliseconds.
REVERT: d4b06edc2a feat: add ngc events

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: adbd5b32d85d9c13800f5ece17c0a9dce99faacd
2023-12-15 15:21:40 +01:00
3580 changed files with 26560 additions and 1113604 deletions

View File

@ -6,6 +6,7 @@ CACHEDIR="$HOME/cache"
. ".github/scripts/flags-$CC.sh"
add_flag -Werror
add_flag -D_DEBUG
add_flag -fdiagnostics-color=always
add_flag -fno-omit-frame-pointer
add_flag -fno-sanitize-recover=all

View File

@ -15,9 +15,7 @@ workflows:
- ubsan
# Static analysis
- clang-analyze
- clang-tidy
- cpplint
- infer
- static-analysis
jobs:
@ -64,12 +62,13 @@ jobs:
- run: &apt_install
apt-get update &&
DEBIAN_FRONTEND=noninteractive
apt-get install -y --no-install-recommends
apt-get install -y
ca-certificates
clang
cmake
git
libconfig-dev
libgmock-dev
libgtest-dev
libopus-dev
libsodium-dev
@ -103,27 +102,6 @@ jobs:
- run: git submodule update --init --recursive
- run: CC=clang .circleci/cmake-ubsan
infer:
working_directory: ~/work
docker:
- image: toxchat/infer
steps:
- run: *apt_install
- checkout
- run: git submodule update --init --recursive
- run: infer --no-progress-bar -- cc
auto_tests/auto_test_support.c
auto_tests/lossless_packet_test.c
testing/misc_tools.c
toxav/*.c
toxcore/*.c
toxcore/*/*.c
toxencryptsave/*.c
third_party/cmp/*.c
-lpthread
$(pkg-config --cflags --libs libsodium opus vpx)
static-analysis:
working_directory: ~/work
docker:
@ -134,7 +112,6 @@ jobs:
- run:
apt-get install -y --no-install-recommends
ca-certificates
cppcheck
g++
llvm-dev
- checkout
@ -142,7 +119,6 @@ jobs:
- run: other/analysis/check_includes
- run: other/analysis/check_logger_levels
- run: other/analysis/run-clang
- run: other/analysis/run-cppcheck
- run: other/analysis/run-gcc
clang-analyze:
@ -156,24 +132,6 @@ jobs:
- run: git submodule update --init --recursive
- run: other/analysis/run-clang-analyze
clang-tidy:
working_directory: ~/work
docker:
- image: ubuntu
steps:
- run: *apt_install
- run:
apt-get install -y --no-install-recommends
ca-certificates
clang-tidy-14
- checkout
- run: git submodule update --init --recursive
- run:
other/analysis/run-clang-tidy ||
other/analysis/run-clang-tidy ||
other/analysis/run-clang-tidy
cpplint:
working_directory: ~/work
docker:
@ -183,9 +141,7 @@ jobs:
- run: *apt_install
- run:
apt-get install -y --no-install-recommends
ca-certificates
python3-pip
cpplint
- checkout
- run: git submodule update --init --recursive
- run: pip install cpplint
- run: other/analysis/run-cpplint

79
.cirrus.yml Normal file
View File

@ -0,0 +1,79 @@
---
bazel-opt_task:
container:
image: toxchat/toktok-stack:latest-release
cpu: 2
memory: 2G
configure_script:
- git submodule update --init --recursive
- /src/workspace/tools/inject-repo c-toxcore
- sed -i -e 's/build --config=remote/#&/' /src/workspace/.bazelrc.local
test_all_script:
- cd /src/workspace && bazel test -k
--build_tag_filters=-haskell
--test_tag_filters=-haskell
--
//c-toxcore/...
-//c-toxcore/auto_tests:tcp_relay_test # Cirrus doesn't allow external network connections.
bazel-dbg_task:
container:
image: toxchat/toktok-stack:latest-debug
cpu: 2
memory: 2G
configure_script:
- git submodule update --init --recursive
- /src/workspace/tools/inject-repo c-toxcore
test_all_script:
- cd /src/workspace && bazel test -k
--build_tag_filters=-haskell
--test_tag_filters=-haskell
--remote_http_cache=http://$CIRRUS_HTTP_CACHE_HOST
--
//c-toxcore/...
-//c-toxcore/auto_tests:tcp_relay_test # Cirrus doesn't allow external network connections.
cimple_task:
container:
image: toxchat/toktok-stack:latest-release
cpu: 2
memory: 4G
configure_script:
- git submodule update --init --recursive
- /src/workspace/tools/inject-repo c-toxcore
- sed -i -e 's/build --config=remote/#&/' /src/workspace/.bazelrc.local
test_all_script:
- cd /src/workspace && bazel test -k
--build_tag_filters=haskell
--test_tag_filters=haskell
--
//c-toxcore/...
freebsd_task:
freebsd_instance:
image_family: freebsd-14-0
configure_script:
- PAGER=cat ASSUME_ALWAYS_YES=YES pkg install
cmake
git
gmake
googletest
libconfig
libsodium
libvpx
opus
pkgconf
- git submodule update --init --recursive
test_all_script:
- |
# TODO(iphydf): Investigate FreeBSD failures on these tests.
sed -Ei -e '/\(dht_getnodes_api\)/s/^/#/' auto_tests/CMakeLists.txt
cmake . \
-DMIN_LOGGER_LEVEL=TRACE \
-DMUST_BUILD_TOXAV=ON \
-DNON_HERMETIC_TESTS=OFF \
-DTEST_TIMEOUT_SECONDS=50 \
-DUSE_IPV6=OFF \
-DAUTOTEST=ON
cmake --build . --target install
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6

View File

@ -1,4 +1,5 @@
# vim:ft=yaml
HeaderFilterRegex: "/c-toxcore/[^/]+/[^.].+"
CheckOptions:
- key: readability-identifier-naming.ClassCase
value: Camel_Snake_Case
@ -20,7 +21,7 @@ CheckOptions:
- key: readability-identifier-naming.MacroDefinitionCase
value: UPPER_CASE
- key: readability-identifier-naming.MacroDefinitionIgnoredRegexp
value: "^_.*|nullable|non_null|nullptr|static_assert|ck_.*"
value: "^_.*|bitwise|force|nullable|non_null|nullptr|static_assert|ck_.*"
- key: readability-identifier-naming.ParameterCase
value: lower_case
- key: readability-identifier-naming.StructCase
@ -35,6 +36,14 @@ CheckOptions:
value: lower_case
- key: llvmlibc-restrict-system-libc-headers.Includes
value: "arpa/inet.h,assert.h,ctype.h,errno.h,fcntl.h,getopt.h,libconfig.h,linux/netdevice.h,math.h,netdb.h,netinet/in.h,opus.h,pthread.h,signal.h,sodium/crypto_scalarmult_curve25519.h,sodium.h,sodium/randombytes.h,stdio.h,stdlib.h,string.h,sys/ioctl.h,syslog.h,sys/resource.h,sys/socket.h,sys/stat.h,sys/time.h,sys/types.h,time.h,unistd.h,vpx/vp8cx.h,vpx/vp8dx.h,vpx/vpx_decoder.h,vpx/vpx_encoder.h,vpx/vpx_image.h"
value: "alloca.h,arpa/inet.h,assert.h,ctype.h,errno.h,fcntl.h,getopt.h,libconfig.h,limits.h,linux/if.h,math.h,netdb.h,netinet/in.h,opus.h,pthread.h,signal.h,sodium/crypto_scalarmult_curve25519.h,sodium.h,sodium/randombytes.h,stdarg.h,stdbool.h,stddef.h,stdint.h,stdio.h,stdlib.h,string.h,sys/ioctl.h,syslog.h,sys/resource.h,sys/socket.h,sys/stat.h,sys/time.h,sys/types.h,time.h,unistd.h,vpx/vp8cx.h,vpx/vp8dx.h,vpx/vpx_decoder.h,vpx/vpx_encoder.h,vpx/vpx_image.h"
- key: hicpp-signed-bitwise.IgnorePositiveIntegerLiterals
value: true
- key: concurrency-mt-unsafe.FunctionSet
value: posix
- key: readability-function-cognitive-complexity.Threshold
value: 153 # TODO(iphydf): Decrease. tox_new is the highest at the moment.
- key: cppcoreguidelines-avoid-do-while.IgnoreMacros
value: true
- key: readability-simplify-boolean-expr.SimplifyDeMorgan
value: false

View File

@ -1,6 +1,6 @@
#!/bin/bash -eu
FUZZ_TARGETS="bootstrap_fuzzer toxsave_fuzzer"
FUZZ_TARGETS="bootstrap_fuzz_test toxsave_fuzz_test"
# out of tree build
cd "$WORK"

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
/_build
/_install

1
.github/FUNDING.yml vendored
View File

@ -1 +0,0 @@
github: Green-Sky

View File

@ -11,10 +11,7 @@ add_ld_flag -Wl,-z,defs
# Make compilation error on a warning
add_flag -Werror
add_config_flag --with-nacl-libs="$CACHEDIR/lib/amd64"
add_config_flag --with-nacl-headers="$CACHEDIR/include/amd64"
add_config_flag --disable-ipv6
add_config_flag --enable-nacl
add_config_flag --enable-daemon
add_config_flag --with-log-level=TRACE

55
.github/scripts/cmake-alpine-s390x vendored Executable file
View File

@ -0,0 +1,55 @@
#!/bin/bash
# Copyright (C) 2018-2023 nurupo
# Toxcore building
set -eux
cd .. # /work
. cmake-alpine-run.sh
# === Get VM ready to build the code ===
start_vm
RUN apk add cmake g++ ninja
mv c-toxcore /
# Copy over toxcore code from host to qemu
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P "$SSH_PORT" -r /c-toxcore root@localhost:~
cd /c-toxcore
. ".github/scripts/flags-gcc.sh"
# Make compilation error on a warning
add_flag -Werror
# - disabling toxav because vpx doesn't work on s390x.
# - disabling bootstrap daemons because we don't need them for testing (saving time).
# - disabling shared libraries because it saves a lot of time on building PIC objects.
# - enable unity build because it saves a lot of time as well (fewer objects to build).
RUN "cmake -B_build -Hc-toxcore -GNinja \
-DCMAKE_C_FLAGS='$C_FLAGS' \
-DCMAKE_CXX_FLAGS='$CXX_FLAGS' \
-DCMAKE_EXE_LINKER_FLAGS='$LD_FLAGS' \
-DCMAKE_SHARED_LINKER_FLAGS='$LD_FLAGS' \
-DCMAKE_INSTALL_PREFIX:PATH='_install' \
-DCMAKE_UNITY_BUILD=ON \
-DMIN_LOGGER_LEVEL=TRACE \
-DNON_HERMETIC_TESTS=ON \
-DENABLE_SHARED=OFF \
-DBUILD_TOXAV=OFF \
-DDHT_BOOTSTRAP=OFF \
-DBOOTSTRAP_DAEMON=OFF \
-DSTRICT_ABI=ON \
-DTEST_TIMEOUT_SECONDS=90 \
-DUSE_IPV6=OFF \
-DAUTOTEST=ON"
RUN 'cmake --build _build --parallel 2 --target install -- -k 0'
RUN 'cd _build && ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:1 --timeout 90 || true' &
# Give the tests 5 minutes to run. Sometimes, the per-test timeout doesn't
# work, so we put a global timeout here for everything.
sleep 300

View File

@ -10,7 +10,7 @@ ABI=${1:-"armeabi-v7a"}
case $ABI in
armeabi-v7a)
TARGET=armv7a-linux-androideabi
NDK_API=19
NDK_API=21
;;
arm64-v8a)
TARGET=aarch64-linux-android
@ -18,7 +18,7 @@ case $ABI in
;;
x86)
TARGET=i686-linux-android
NDK_API=19
NDK_API=21
;;
x86_64)
TARGET=x86_64-linux-android

58
.github/scripts/cmake-freebsd vendored Executable file
View File

@ -0,0 +1,58 @@
#!/bin/bash
# Copyright (C) 2018-2023 nurupo
# Toxcore building
set -eux
cd .. # /work
. cmake-freebsd-run.sh
# === Get VM ready to build the code ===
# Unpack image only if it's compressed.
if [ -f "$IMAGE_NAME.gz" ]; then
gunzip "$IMAGE_NAME.gz"
fi
mv c-toxcore /
start_vm
# Copy over toxcore code from host to qemu
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P "$SSH_PORT" -r /c-toxcore root@localhost:~
RUN ls -lh
cd /c-toxcore
. '.github/scripts/flags-clang.sh'
add_ld_flag -Wl,-z,defs
# Make compilation error on a warning.
add_flag -Werror
# This triggers on FreeBSD's clang.
add_flag -Wno-format
add_flag -Wno-unsafe-buffer-usage
RUN "cmake -B_build -Hc-toxcore \
-DCMAKE_C_FLAGS='$C_FLAGS' \
-DCMAKE_CXX_FLAGS='$CXX_FLAGS' \
-DCMAKE_EXE_LINKER_FLAGS='$LD_FLAGS' \
-DCMAKE_SHARED_LINKER_FLAGS='$LD_FLAGS' \
-DCMAKE_INSTALL_PREFIX:PATH='_install' \
-DMIN_LOGGER_LEVEL=TRACE \
-DMUST_BUILD_TOXAV=ON \
-DNON_HERMETIC_TESTS=ON \
-DSTRICT_ABI=ON \
-DTEST_TIMEOUT_SECONDS=120 \
-DUSE_IPV6=OFF \
-DAUTOTEST=ON"
# We created the VM with the same number of cores as the host, so the host-ran `nproc` here is fine.
RUN 'cmake --build _build --parallel "$NPROC" --target install -- -k'
RUN 'cd _build && ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:2 --timeout 120 || true'
# Gracefully shut down the VM.
stop_vm

View File

@ -18,7 +18,7 @@ docker run \
-e ENABLE_ARCH_i686="$i686" \
-e ENABLE_ARCH_x86_64="$x86_64" \
-e ENABLE_TEST=true \
-e EXTRA_CMAKE_FLAGS="-DBOOTSTRAP_DAEMON=OFF -DMIN_LOGGER_LEVEL=DEBUG -DTEST_TIMEOUT_SECONDS=90 -DAUTOTEST=ON" \
-e EXTRA_CMAKE_FLAGS="-DBOOTSTRAP_DAEMON=OFF -DMIN_LOGGER_LEVEL=DEBUG -DTEST_TIMEOUT_SECONDS=90 -DAUTOTEST=ON -DUSE_IPV6=OFF" \
-e CMAKE_C_FLAGS="$C_FLAGS" \
-e CMAKE_CXX_FLAGS="$CXX_FLAGS" \
-e CMAKE_EXE_LINKER_FLAGS="$LD_FLAGS" \
@ -26,4 +26,6 @@ docker run \
-v "$PWD:/toxcore" \
-v "$PWD/result:/prefix" \
--rm \
-t \
--pull never \
"toxchat/windows:$WINDOWS_ARCH"

View File

@ -39,12 +39,17 @@ add_flag -Wno-reserved-id-macro
# TODO(iphydf): Clean these up. They are likely not bugs, but still
# potential issues and probably confusing.
add_flag -Wno-sign-compare
# We don't want to have default cases, we want to explicitly define all cases
add_flag -Wno-switch-default
# __attribute__((nonnull)) causes this warning on defensive null checks.
add_flag -Wno-tautological-pointer-compare
# Our use of mutexes results in a false positive, see 1bbe446.
add_flag -Wno-thread-safety-analysis
# File transfer code has this.
add_flag -Wno-type-limits
# Generates false positives in toxcore similar to
# https://github.com/llvm/llvm-project/issues/64646
add_flag -Wno-unsafe-buffer-usage
# Callbacks often don't use all their parameters.
add_flag -Wno-unused-parameter
# cimple does this better
@ -65,6 +70,8 @@ add_cxx_flag -Wno-c++98-compat-pedantic
add_cxx_flag -Wno-c99-extensions
# We're C-compatible, so use C style casts.
add_cxx_flag -Wno-old-style-cast
# GTest does this.
add_cxx_flag -Wno-global-constructors
# Downgrade to warning so we still see it.
add_flag -Wno-error=unreachable-code

View File

@ -5,16 +5,16 @@
add_ld_flag -Wl,-z,defs
# Make compilation error on a warning
add_flag -Werror
add_flag -Werror -Wno-unsafe-buffer-usage
# Coverage flags.
add_flag --coverage
add_flag -fprofile-instr-generate -fcoverage-mapping
# Optimisation, but keep stack traces useful.
add_c_flag -fno-inline -fno-omit-frame-pointer
# Show useful stack traces on crash.
add_flag -fsanitize=undefined -fno-sanitize-recover=all
add_flag -fsanitize=undefined -fno-sanitize-recover=all -D_DEBUG
# In test code (_test.cc and libgtest), throw away all debug information.
# We only care about stack frames inside toxcore (which is C). Without this,

View File

@ -28,8 +28,6 @@ add_flag -O3 -march=native
# Warn on non-ISO C.
add_c_flag -pedantic
add_c_flag -std=c99
add_cxx_flag -std=c++11
add_flag -g3
add_flag -ftrapv

View File

@ -1,12 +1,16 @@
#!/bin/bash
set -exu
set -exu -o pipefail
LOCAL="${1:-}"
CHECK="${2:-}"
readarray -t FILES <<<"$(git ls-files)"
tar c "${FILES[@]}" | docker build -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node -
if ! tar c "${FILES[@]}" | docker build --build-arg="CHECK=$CHECK" -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node - 2>&1 | tee docker-build.log; then
grep -o "::error.*::[a-f0-9]* /usr/local/bin/tox-bootstrapd" docker-build.log
false
fi
docker tag toxchat/bootstrap-node:latest toxchat/bootstrap-node:"$(other/print-version)"
sudo useradd \

View File

@ -1,43 +0,0 @@
name: ContinuousDelivery
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
BUILD_TYPE: Release
jobs:
windows:
timeout-minutes: 15
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Dependencies
run: vcpkg install libsodium:x64-windows-static pthreads:x64-windows-static
# setup vs env
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64
- name: Configure CMake
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
- uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}-windows-msvc-x86_64
# TODO: do propper packing
path: |
${{github.workspace}}/build/bin/

View File

@ -1,74 +1,200 @@
name: ContinuousIntegration
name: ci
on:
push:
branches: [ master ]
pull_request:
branches: [master]
env:
BUILD_TYPE: Debug
# Cancel old PR builds when pushing new commits.
concurrency:
group: build-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
linux:
timeout-minutes: 10
common:
uses: TokTok/ci-tools/.github/workflows/common-ci.yml@master
analysis:
strategy:
fail-fast: false
matrix:
tool: [autotools, clang-tidy, compcert, cppcheck, doxygen, goblint, infer, freebsd, misra, modules, pkgsrc, rpm, slimcc, sparse, tcc, tokstyle]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker
- name: Build toxchat/c-toxcore:sources
uses: docker/build-push-action@v5
with:
file: other/docker/sources/sources.Dockerfile
tags: toxchat/c-toxcore:sources
- name: Docker Build
uses: docker/build-push-action@v5
with:
file: other/docker/${{ matrix.tool }}/${{ matrix.tool }}.Dockerfile
coverage-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Build, test, and upload coverage
run: other/docker/coverage/run
- name: Install Dependencies
run: sudo apt update && sudo apt -y install libsodium-dev
generate-events:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Run generate_event_c
run: |
other/event_tooling/run
git diff --exit-code
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
cimplefmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Run cimplefmt
run: other/docker/cimplefmt/run -u $(find tox* -name "*.[ch]")
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
macos:
timeout-minutes: 10
build-android:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- run: .github/scripts/cmake-android armeabi-v7a
- run: .github/scripts/cmake-android arm64-v8a
- run: .github/scripts/cmake-android x86
- run: .github/scripts/cmake-android x86_64
build-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Build and test
run: .github/scripts/cmake-osx
- name: Install Dependencies
run: brew install libsodium
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
windows:
timeout-minutes: 10
runs-on: windows-latest
build-windows-msvc:
strategy:
matrix:
version: [2019, 2022]
runs-on: windows-${{ matrix.version }}
env:
VCPKG_ROOT: "C:/vcpkg"
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Dependencies
run: vcpkg install libsodium:x64-windows-static pthreads:x64-windows-static
# setup vs env
- uses: ilammy/msvc-dev-cmd@v1
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
arch: amd64
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Configure CMake
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
run: cmake --preset windows-default
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
run: cmake --build _build -j $([int]$env:NUMBER_OF_PROCESSORS+2)
- name: Test
run: |
cd _build
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6 --build-config Debug
build-netbsd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Test in NetBSD
id: test
uses: vmactions/netbsd-vm@v1
with:
usesh: true
copyback: false
prepare:
/usr/sbin/pkg_add
cmake
googletest
libconfig
libopus
libsodium
libvpx
pkg-config
run: |
# TODO(iphydf): Investigate NetBSD failures on these tests.
sed -Ei -e '/\((TCP|dht_getnodes_api)\)/s/^/#/' auto_tests/CMakeLists.txt
cmake . \
-DMIN_LOGGER_LEVEL=TRACE \
-DMUST_BUILD_TOXAV=ON \
-DNON_HERMETIC_TESTS=ON \
-DTEST_TIMEOUT_SECONDS=90 \
-DUSE_IPV6=OFF \
-DAUTOTEST=ON
cmake --build . --target install
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6
build-freebsd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Test in FreeBSD
id: test
uses: vmactions/freebsd-vm@v1
with:
usesh: true
copyback: false
prepare:
PAGER=cat ASSUME_ALWAYS_YES=YES pkg install
cmake
git
gmake
googletest
libconfig
libsodium
libvpx
opus
pkgconf
run: |
# TODO(iphydf): Investigate FreeBSD failures on these tests.
sed -Ei -e '/\(dht_getnodes_api\)/s/^/#/' auto_tests/CMakeLists.txt
cmake . \
-DMIN_LOGGER_LEVEL=TRACE \
-DMUST_BUILD_TOXAV=ON \
-DNON_HERMETIC_TESTS=ON \
-DTEST_TIMEOUT_SECONDS=50 \
-DUSE_IPV6=OFF \
-DAUTOTEST=ON
cmake --build . --target install
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install mypy
run: pip install mypy
- name: Run mypy
run: |
(find . -name "*.py" -and -not -name "conanfile.py"; grep -lR '^#!.*python') \
| xargs -n1 -P8 mypy --strict

View File

@ -8,7 +8,7 @@ jobs:
latest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install libraries

View File

@ -6,21 +6,28 @@ on:
pull_request:
branches: [master]
# Cancel old PR builds when pushing new commits.
concurrency:
group: docker-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
docker-bootstrap-node:
runs-on: ubuntu-latest
steps:
- name: Login to DockerHub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Docker Build
run: .github/scripts/tox-bootstrapd-docker local
run: .github/scripts/tox-bootstrapd-docker local "$CHECK"
env:
CHECK: "${{ contains(github.event.pull_request.title, 'chore: Release ') && 'sha256sum' || 'echo' }}"
- name: Push latest image to DockerHub
if: ${{ github.event_name == 'push' }}
run: docker push toxchat/bootstrap-node:latest
@ -33,15 +40,15 @@ jobs:
needs: [docker-bootstrap-node]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:other/bootstrap_daemon/websocket"
push: ${{ github.event_name == 'push' }}
@ -52,17 +59,17 @@ jobs:
docker-clusterfuzz:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: "."
file: .clusterfuzzlite/Dockerfile
@ -75,15 +82,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
file: testing/Dockerfile
push: ${{ github.event_name == 'push' }}
@ -95,15 +102,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
file: other/emscripten/Dockerfile
push: ${{ github.event_name == 'push' }}
@ -115,22 +122,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver: docker
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build toxchat/c-toxcore:sources
uses: docker/build-push-action@v2
with:
file: other/docker/sources/Dockerfile
tags: toxchat/c-toxcore:sources
- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
file: other/docker/esp32/Dockerfile
push: ${{ github.event_name == 'push' }}
@ -138,50 +138,44 @@ jobs:
cache-from: type=registry,ref=toxchat/c-toxcore:esp32
cache-to: type=inline
docker-win32:
docker-windows-mingw:
strategy:
matrix:
bits: [32, 64]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
- name: Build and store to local Docker daemon
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:other/docker/windows"
push: ${{ github.event_name == 'push' }}
tags: toxchat/windows:win32
cache-from: type=registry,ref=toxchat/windows:win32
cache-to: type=inline
context: other/docker/windows
load: true
tags: toxchat/windows:win${{ matrix.bits }}
cache-from: type=registry,ref=toxchat/windows:win${{ matrix.bits }}
build-args: |
SUPPORT_ARCH_i686=true
SUPPORT_ARCH_x86_64=false
SUPPORT_ARCH_i686=${{ matrix.bits == '32' }}
SUPPORT_ARCH_x86_64=${{ matrix.bits == '64' }}
SUPPORT_TEST=true
docker-win64:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
- name: Push the stored image to Dockerhub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v1
uses: docker/build-push-action@v5
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: "{{defaultContext}}:other/docker/windows"
context: other/docker/windows
push: ${{ github.event_name == 'push' }}
tags: toxchat/windows:win64
cache-from: type=registry,ref=toxchat/windows:win64
cache-to: type=inline
tags: toxchat/windows:win${{ matrix.bits }}
build-args: |
SUPPORT_ARCH_i686=false
SUPPORT_ARCH_x86_64=true
SUPPORT_ARCH_i686=${{ matrix.bits == '32' }}
SUPPORT_ARCH_x86_64=${{ matrix.bits == '64' }}
SUPPORT_TEST=true
- name: Cross-compile
run: .github/scripts/cmake-win${{ matrix.bits }} script

43
.github/workflows/post-submit.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: post-submit
on:
push:
branches: [master]
jobs:
build-alpine-s390x:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker Build
uses: docker/build-push-action@v5
with:
file: other/docker/alpine-s390x/Dockerfile
docker-coverage:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker
- name: Login to DockerHub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build toxchat/c-toxcore:sources
uses: docker/build-push-action@v5
with:
file: other/docker/sources/sources.Dockerfile
tags: toxchat/c-toxcore:sources
- name: Build and push
uses: docker/build-push-action@v5
with:
file: other/docker/coverage/coverage.Dockerfile
push: ${{ github.event_name == 'push' }}
tags: toxchat/c-toxcore:coverage
cache-from: type=registry,ref=toxchat/c-toxcore:coverage
cache-to: type=inline

View File

@ -6,22 +6,28 @@ on:
pull_request:
branches: [master]
# Cancel old PR builds when pushing new commits.
concurrency:
group: scan-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
sonar-scan:
runs-on: ubuntu-latest
env:
SONAR_SCANNER_VERSION: 4.4.0.2170
SONAR_SCANNER_VERSION: 5.0.1.3006
SONAR_SERVER_URL: "https://sonarcloud.io"
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
submodules: recursive
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: 11
distribution: "zulu"
java-version: 17
- name: Download and set up sonar-scanner
env:
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip

119
.gitignore vendored
View File

@ -1,26 +1,101 @@
.vs/
*.o
*.swp
~*
*~
.idea/
cmake-build-debug/
cmake-build-debugandtest/
cmake-build-release/
*.stackdump
*.coredump
compile_commands.json
/build*
/result*
.clangd
.cache
# OS files
.DS_Store
.AppleDouble
.LSOverride
.DS_Store?
._*
.mypy_cache
.Spotlight-V100
.Trash*
Icon?
ethumbs.db
Thumbs.db
*.tmp
CMakeLists.txt.user*
# Make
/_build
/_install
/tox-0.0.0*
/.vs
/CppProperties.json
CMakeCache.txt
CMakeFiles
Makefile
!/other/rpm/Makefile
cmake_install.cmake
install_manifest.txt
tags
Makefile.in
CMakeLists.txt.user
DartConfiguration.tcl
CTestTestfile.cmake
*.pc
*.tox
imgui.ini
# Testing
/amalgamation.*
testing/data
*~
# Vim
*.swp
# Object files
*.o
*.lo
*.a
# Executables
*.exe
*.out
*.app
*.la
# Libraries
*.so
# Misc (?)
m4/*
configure
configure_aux
!m4/pkg.m4
aclocal.m4
config.h*
config.log
config.status
stamp-h1
autom4te.cache
libtool
.deps
.libs
.dirstamp
build/
*.nvim*
*.vim*
# kdevelop
.kdev/
*.kdev*
# VScode
.vscode/
# Netbeans
nbproject
# astyle
*.orig
# Android buildscript
android-toolchain-*
toxcore-android-*
# cscope files list
cscope.files
# rpm
tox.spec
# clangd
.cache/
compile_commands.json
/infer
.idea/

25
.gitmodules vendored
View File

@ -1,22 +1,3 @@
[submodule "external/toxcore/c-toxcore/third_party/cmp"]
path = external/toxcore/c-toxcore/third_party/cmp
url = https://github.com/camgunz/cmp.git
shallow = true
[submodule "external/solanaceae_toxcore"]
path = external/solanaceae_toxcore
url = https://github.com/Green-Sky/solanaceae_toxcore.git
[submodule "external/solanaceae_util"]
path = external/solanaceae_util
url = https://github.com/Green-Sky/solanaceae_util.git
[submodule "external/solanaceae_contact"]
path = external/solanaceae_contact
url = https://github.com/Green-Sky/solanaceae_contact.git
[submodule "external/solanaceae_message3"]
path = external/solanaceae_message3
url = https://github.com/Green-Sky/solanaceae_message3.git
[submodule "external/solanaceae_tox"]
path = external/solanaceae_tox
url = https://github.com/Green-Sky/solanaceae_tox.git
[submodule "external/solanaceae_plugin"]
path = external/solanaceae_plugin
url = https://github.com/Green-Sky/solanaceae_plugin.git
[submodule "third_party/cmp"]
path = third_party/cmp
url = https://github.com/camgunz/cmp

View File

@ -1,20 +1,25 @@
---
exclude:
- "**/*.api.h"
# shfmt doesn't support this file
# shfmt doesn't support this file.
- "other/analysis/run-clang-tidy"
# Generated file.
- "CHANGELOG.md"
restylers:
- astyle:
image: restyled/restyler-astyle:d7967bcb8b622a98524b7df1da1b02652114cf9a
arguments: ["--options=other/astyle/astylerc"]
include:
- "!**/*.cc"
- "**/*.c"
- "**/*.h"
- autopep8
- black
- clang-format:
image: restyled/restyler-clang-format:13.0.1
image: restyled/restyler-clang-format:v16.0.6
include:
- "**/*.cc"
- "**/*.hh"
- prettier-markdown
- prettier-yaml
- reorder-python-imports
- shellharden

View File

@ -1,25 +1,26 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//tools/project:build_defs.bzl", "project")
package(features = ["layering_check"])
project()
project(license = "gpl3-https")
genrule(
name = "public_headers",
srcs = [
"//c-toxcore/toxav:toxav.h",
"//c-toxcore/toxcore:tox.h",
"//c-toxcore/toxcore:tox_private.h",
"//c-toxcore/toxencryptsave:toxencryptsave.h",
],
outs = [
"tox/toxav.h",
"tox/tox.h",
"tox/tox_private.h",
"tox/toxencryptsave.h",
],
cmd = """
cp $(location //c-toxcore/toxav:toxav.h) $(GENDIR)/c-toxcore/tox/toxav.h
cp $(location //c-toxcore/toxcore:tox.h) $(GENDIR)/c-toxcore/tox/tox.h
cp $(location //c-toxcore/toxcore:tox_private.h) $(GENDIR)/c-toxcore/tox/tox_private.h
cp $(location //c-toxcore/toxencryptsave:toxencryptsave.h) $(GENDIR)/c-toxcore/tox/toxencryptsave.h
""",
visibility = ["//visibility:public"],

View File

@ -1,9 +1,274 @@
## v0.2.19
### Merged PRs:
- [#2744](https://github.com/TokTok/c-toxcore/pull/2744) docs: Document that group topic lock is default on.
- [#2743](https://github.com/TokTok/c-toxcore/pull/2743) docs: Add missing param docs for callbacks.
- [#2742](https://github.com/TokTok/c-toxcore/pull/2742) chore: Add cmake flag to disable unit tests.
- [#2741](https://github.com/TokTok/c-toxcore/pull/2741) refactor: Don't expose Tox_System in the public API
- [#2736](https://github.com/TokTok/c-toxcore/pull/2736) cleanup: A more descriptive error for group invite accept function
- [#2735](https://github.com/TokTok/c-toxcore/pull/2735) chore: Small API doc fixes
- [#2732](https://github.com/TokTok/c-toxcore/pull/2732) cleanup: event length naming inconsistencies
- [#2731](https://github.com/TokTok/c-toxcore/pull/2731) cleanup: align group send err enum order
- [#2729](https://github.com/TokTok/c-toxcore/pull/2729) cleanup: use typedef for private message ID's in callback
- [#2728](https://github.com/TokTok/c-toxcore/pull/2728) refactor: Observers/ignored peers can now send and receive custom packets
- [#2727](https://github.com/TokTok/c-toxcore/pull/2727) feat: add message IDs to private group messages
- [#2726](https://github.com/TokTok/c-toxcore/pull/2726) refactor: Rename `out` parameters to `out_$something`.
- [#2718](https://github.com/TokTok/c-toxcore/pull/2718) chore: Use a specific non-broken slimcc version.
- [#2713](https://github.com/TokTok/c-toxcore/pull/2713) feat: Update and improve the Windows cross-compilation
- [#2712](https://github.com/TokTok/c-toxcore/pull/2712) chore: Update github actions.
- [#2710](https://github.com/TokTok/c-toxcore/pull/2710) docs: Update the list of CMake options
- [#2709](https://github.com/TokTok/c-toxcore/pull/2709) refactor: Remove "mod" and "founder" from group API naming scheme
- [#2708](https://github.com/TokTok/c-toxcore/pull/2708) docs: add the experimental api build option to INSTALL.md
- [#2705](https://github.com/TokTok/c-toxcore/pull/2705) refactor: Rename Queries to Query to align with other enums.
- [#2704](https://github.com/TokTok/c-toxcore/pull/2704) fix: Correct type for conference offline peer numbers.
- [#2700](https://github.com/TokTok/c-toxcore/pull/2700) test: Add FreeBSD VM action on GitHub.
- [#2699](https://github.com/TokTok/c-toxcore/pull/2699) test: Add pkgsrc build.
- [#2698](https://github.com/TokTok/c-toxcore/pull/2698) chore: Only install tox_private.h on request.
- [#2697](https://github.com/TokTok/c-toxcore/pull/2697) test: Build toxcore on NetBSD (VM).
- [#2696](https://github.com/TokTok/c-toxcore/pull/2696) fix: save_compatibility_test failing on big-endian systems
- [#2695](https://github.com/TokTok/c-toxcore/pull/2695) fix: Don't serve files from websockify.
- [#2689](https://github.com/TokTok/c-toxcore/pull/2689) fix: Correctly pass extended public keys to group moderation code.
- [#2686](https://github.com/TokTok/c-toxcore/pull/2686) chore: Compile libsodium reference implementation with compcert.
- [#2685](https://github.com/TokTok/c-toxcore/pull/2685) cleanup: correct a few nullable annotations
- [#2684](https://github.com/TokTok/c-toxcore/pull/2684) cleanup: Don't use `memcpy` to cast arbitrary `struct`s to `uint8_t[]`.
- [#2683](https://github.com/TokTok/c-toxcore/pull/2683) fix: Pass array, not array pointer, to `memcmp`.
- [#2682](https://github.com/TokTok/c-toxcore/pull/2682) cleanup: Never pass `void*` directly to `memcpy`.
- [#2678](https://github.com/TokTok/c-toxcore/pull/2678) chore: Disable NGC saving by default, enable through Tox_Options.
- [#2675](https://github.com/TokTok/c-toxcore/pull/2675) cleanup: Replace pointer arithmetic with explicit `&arr[i]`.
- [#2672](https://github.com/TokTok/c-toxcore/pull/2672) refactor: Use `structs` for extended public/secret keys.
- [#2671](https://github.com/TokTok/c-toxcore/pull/2671) refactor: Use tox rng to seed the keypair generation.
- [#2666](https://github.com/TokTok/c-toxcore/pull/2666) cleanup: Small improvements found by PVS Studio.
- [#2664](https://github.com/TokTok/c-toxcore/pull/2664) docs: Run prettier-markdown on markdown files.
- [#2662](https://github.com/TokTok/c-toxcore/pull/2662) fix: Correct a few potential null derefs in bootstrap daemon.
- [#2661](https://github.com/TokTok/c-toxcore/pull/2661) fix: Zero out stack-allocated secret key before return.
- [#2660](https://github.com/TokTok/c-toxcore/pull/2660) fix: Add missing memunlock of local variable when it goes out of scope.
- [#2659](https://github.com/TokTok/c-toxcore/pull/2659) cleanup: Simplify custom packet length check in NGC.
- [#2658](https://github.com/TokTok/c-toxcore/pull/2658) refactor: Make prune_gc_sanctions_list more obviously correct.
- [#2657](https://github.com/TokTok/c-toxcore/pull/2657) fix: Fix some false positive from PVS Studio.
- [#2656](https://github.com/TokTok/c-toxcore/pull/2656) docs: Add static analysis tool list to README.
- [#2655](https://github.com/TokTok/c-toxcore/pull/2655) cleanup: Check that WINXP macro exists before comparing it.
- [#2652](https://github.com/TokTok/c-toxcore/pull/2652) refactor: Make tox mutex non-recursive.
- [#2648](https://github.com/TokTok/c-toxcore/pull/2648) docs: Add more documentation to crypto_core.
- [#2647](https://github.com/TokTok/c-toxcore/pull/2647) docs: Fix up doxyfile.
- [#2645](https://github.com/TokTok/c-toxcore/pull/2645) refactor: Remove `Tox *` from `tox_dispatch`.
- [#2644](https://github.com/TokTok/c-toxcore/pull/2644) refactor: Don't rely on tox_dispatch passing tox in tests.
- [#2643](https://github.com/TokTok/c-toxcore/pull/2643) refactor: Use strong typedef for NGC peer id.
- [#2642](https://github.com/TokTok/c-toxcore/pull/2642) chore: Use C++ mode for clang-tidy.
- [#2640](https://github.com/TokTok/c-toxcore/pull/2640) refactor: Use strong `typedef` instead of `struct` for `Socket`.
- [#2637](https://github.com/TokTok/c-toxcore/pull/2637) chore: Check that both gtest and gmock exist for tests.
- [#2634](https://github.com/TokTok/c-toxcore/pull/2634) chore: Add some comments to the astyle config.
- [#2629](https://github.com/TokTok/c-toxcore/pull/2629) chore: Reformat sources with astyle.
- [#2626](https://github.com/TokTok/c-toxcore/pull/2626) chore: Rename C++ headers to .hh suffixes.
- [#2624](https://github.com/TokTok/c-toxcore/pull/2624) test: Add slimcc compiler compatibility test.
- [#2622](https://github.com/TokTok/c-toxcore/pull/2622) cleanup: Add more `const` where possible.
- [#2621](https://github.com/TokTok/c-toxcore/pull/2621) cleanup: Remove implicit bool conversions.
- [#2620](https://github.com/TokTok/c-toxcore/pull/2620) chore: Only check the bootstrap daemon checksum on release.
- [#2617](https://github.com/TokTok/c-toxcore/pull/2617) cleanup: Further `#include` cleanups.
- [#2614](https://github.com/TokTok/c-toxcore/pull/2614) cleanup: Use Bazel modules to enforce proper `#include` hygiene.
- [#2612](https://github.com/TokTok/c-toxcore/pull/2612) refactor: Move pack/unpack `IP_Port` from DHT into network module.
- [#2611](https://github.com/TokTok/c-toxcore/pull/2611) chore: Really fix coverage docker image build.
- [#2610](https://github.com/TokTok/c-toxcore/pull/2610) chore: Fix post-submit coverage image.
- [#2609](https://github.com/TokTok/c-toxcore/pull/2609) fix: partially fix a bug that prevented group part messages from sending
- [#2605](https://github.com/TokTok/c-toxcore/pull/2605) fix: Don't use `memcmp` to compare `IP_Port`s.
- [#2604](https://github.com/TokTok/c-toxcore/pull/2604) chore: Fix rpm build; add a CI check for it.
- [#2603](https://github.com/TokTok/c-toxcore/pull/2603) chore: Speed up docker builds a bit by reducing layer count.
- [#2602](https://github.com/TokTok/c-toxcore/pull/2602) cleanup: Add `const` where possible in auto tests.
- [#2601](https://github.com/TokTok/c-toxcore/pull/2601) fix: a few off by one errors in group autotests
- [#2598](https://github.com/TokTok/c-toxcore/pull/2598) refactor: Rename `system_{memory,...}` to `os_{memory,...}`.
- [#2597](https://github.com/TokTok/c-toxcore/pull/2597) test: Add goblint static analyser.
- [#2594](https://github.com/TokTok/c-toxcore/pull/2594) cleanup: Use `memzero(x, s)` instead of `memset(x, 0, s)`.
- [#2593](https://github.com/TokTok/c-toxcore/pull/2593) cleanup: Use explicit 0 instead of `PACKET_ID_PADDING`.
- [#2592](https://github.com/TokTok/c-toxcore/pull/2592) cleanup: Remove all uses of `SIZEOF_VLA`.
- [#2591](https://github.com/TokTok/c-toxcore/pull/2591) cleanup: Expand the `Tox_Options` accessor macros.
- [#2590](https://github.com/TokTok/c-toxcore/pull/2590) test: Add a simple new/delete test for Tox.
- [#2588](https://github.com/TokTok/c-toxcore/pull/2588) cleanup: Remove plan9 support.
- [#2587](https://github.com/TokTok/c-toxcore/pull/2587) cleanup: Add comment after every `#endif`.
- [#2583](https://github.com/TokTok/c-toxcore/pull/2583) test: Fix comment I broke in the events test PR.
- [#2582](https://github.com/TokTok/c-toxcore/pull/2582) cleanup: Rename group to conference in groupav documentation.
- [#2581](https://github.com/TokTok/c-toxcore/pull/2581) cleanup: Ensure handler params are named after callback params.
- [#2580](https://github.com/TokTok/c-toxcore/pull/2580) cleanup: Minor cleanup of event unpack code.
- [#2578](https://github.com/TokTok/c-toxcore/pull/2578) refactor: Allow NULL pointers for byte arrays in events.
- [#2577](https://github.com/TokTok/c-toxcore/pull/2577) refactor: Add common msgpack array packer with callback.
- [#2576](https://github.com/TokTok/c-toxcore/pull/2576) cleanup: make some improvements to group moderation test
- [#2575](https://github.com/TokTok/c-toxcore/pull/2575) refactor: Pass `this` pointer as first param to s11n callbacks.
- [#2573](https://github.com/TokTok/c-toxcore/pull/2573) cleanup: skip a do_gc iteration before removing peers marked for deletion
- [#2572](https://github.com/TokTok/c-toxcore/pull/2572) cleanup: Remove `bin_pack_{new,free}`.
- [#2568](https://github.com/TokTok/c-toxcore/pull/2568) feat: Add dht_get_nodes_response event to the events system.
- [#2567](https://github.com/TokTok/c-toxcore/pull/2567) refactor: Use enum-specific pack functions for enum values.
- [#2566](https://github.com/TokTok/c-toxcore/pull/2566) cleanup: Remove empty test doing nothing.
- [#2565](https://github.com/TokTok/c-toxcore/pull/2565) refactor: Factor out union pack switch from event packer.
- [#2564](https://github.com/TokTok/c-toxcore/pull/2564) cleanup: Move the 2-element array pack out of individual events.
- [#2563](https://github.com/TokTok/c-toxcore/pull/2563) test: Add printf log statement to group_moderation_test.
- [#2562](https://github.com/TokTok/c-toxcore/pull/2562) chore: add clangd files to .gitignore
- [#2561](https://github.com/TokTok/c-toxcore/pull/2561) refactor: Move file streaming test to its own file.
- [#2560](https://github.com/TokTok/c-toxcore/pull/2560) fix(ci): window builds now build in parallel
- [#2559](https://github.com/TokTok/c-toxcore/pull/2559) refactor: Migrate auto_tests to new events API.
- [#2557](https://github.com/TokTok/c-toxcore/pull/2557) test: Add C++ classes wrapping system interfaces.
- [#2555](https://github.com/TokTok/c-toxcore/pull/2555) fix: Remove fatal error for non-erroneous case
- [#2554](https://github.com/TokTok/c-toxcore/pull/2554) fix: Make all the fuzzers work again, and add a test for protodump.
- [#2552](https://github.com/TokTok/c-toxcore/pull/2552) fix: Make sure there's enough space for CONSUME1 in fuzzers.
- [#2551](https://github.com/TokTok/c-toxcore/pull/2551) chore: Move from gcov to llvm source-based coverage.
- [#2549](https://github.com/TokTok/c-toxcore/pull/2549) fix: issues with packet broadcast error reporting
- [#2547](https://github.com/TokTok/c-toxcore/pull/2547) test: Add fuzz tests to the coverage run.
- [#2545](https://github.com/TokTok/c-toxcore/pull/2545) refactor: Use `operator==` for equality tests of `Node_format`.
- [#2543](https://github.com/TokTok/c-toxcore/pull/2543) refactor(test): Slightly nicer C++ interface to tox Random.
- [#2542](https://github.com/TokTok/c-toxcore/pull/2542) refactor: packet broadcast functions now return errors
- [#2541](https://github.com/TokTok/c-toxcore/pull/2541) fix: don't pass garbage data buffer to packet send functions
- [#2540](https://github.com/TokTok/c-toxcore/pull/2540) cleanup: Make group packet entry creation less error-prone
- [#2539](https://github.com/TokTok/c-toxcore/pull/2539) refactor: Minor refactoring of get_close_nodes functions.
- [#2538](https://github.com/TokTok/c-toxcore/pull/2538) refactor: Factor out malloc+memcpy into memdup.
- [#2536](https://github.com/TokTok/c-toxcore/pull/2536) cleanup: Some more test cleanups, removing overly smart code.
- [#2531](https://github.com/TokTok/c-toxcore/pull/2531) test: Add more unit tests for `add_to_list`.
- [#2530](https://github.com/TokTok/c-toxcore/pull/2530) refactor: Assign malloc return to a local variable first.
- [#2529](https://github.com/TokTok/c-toxcore/pull/2529) test: Add "infer" CI check to github, remove from circle.
- [#2527](https://github.com/TokTok/c-toxcore/pull/2527) cleanup: Add Toxav alias for ToxAV.
- [#2526](https://github.com/TokTok/c-toxcore/pull/2526) cleanup: Make Tox_Options a typedef.
- [#2525](https://github.com/TokTok/c-toxcore/pull/2525) cleanup: Add dynamically derived array sizes to the API.
- [#2524](https://github.com/TokTok/c-toxcore/pull/2524) cleanup: Add explicit array sizes to toxencryptsave.
- [#2523](https://github.com/TokTok/c-toxcore/pull/2523) cleanup: Move `tox_get_system` out of the public API.
- [#2522](https://github.com/TokTok/c-toxcore/pull/2522) cleanup: Make setters take non-const `Tox *`.
- [#2521](https://github.com/TokTok/c-toxcore/pull/2521) cleanup: Make array params in toxav `[]` instead of `*`.
- [#2520](https://github.com/TokTok/c-toxcore/pull/2520) cleanup: Mark arrays in the tox API as `[]` instead of `*`.
- [#2519](https://github.com/TokTok/c-toxcore/pull/2519) refactor: Align group message sending with other send functions.
- [#2518](https://github.com/TokTok/c-toxcore/pull/2518) cleanup: Add typedefs for public API int identifiers.
- [#2517](https://github.com/TokTok/c-toxcore/pull/2517) chore: Spellcheck tox-bootstrapd
- [#2516](https://github.com/TokTok/c-toxcore/pull/2516) chore: Remove settings.yml in favour of hs-github-tools.
- [#2515](https://github.com/TokTok/c-toxcore/pull/2515) chore: Use GPL license with https.
- [#2513](https://github.com/TokTok/c-toxcore/pull/2513) chore: Add fetch-sha256 script to update bootstrap node hash.
- [#2512](https://github.com/TokTok/c-toxcore/pull/2512) cleanup: Move all vptr-to-ptr casts to the beginning of a function.
- [#2510](https://github.com/TokTok/c-toxcore/pull/2510) cleanup: Use github actions matrix to simplify CI.
- [#2509](https://github.com/TokTok/c-toxcore/pull/2509) fix: Use QueryPerformanceCounter on windows for monotonic time.
- [#2508](https://github.com/TokTok/c-toxcore/pull/2508) chore: Add `net_(new|kill)_strerror` to cppcheck's allocators.
- [#2507](https://github.com/TokTok/c-toxcore/pull/2507) cleanup: Run clang-tidy on headers, as well.
- [#2506](https://github.com/TokTok/c-toxcore/pull/2506) cleanup: Make TCP connection failures a warning instead of error.
- [#2505](https://github.com/TokTok/c-toxcore/pull/2505) cleanup: Make all .c files include the headers they need.
- [#2504](https://github.com/TokTok/c-toxcore/pull/2504) cleanup: Upgrade cppcheck, fix some warnings.
- [#2503](https://github.com/TokTok/c-toxcore/pull/2503) cleanup: Upgrade to clang-tidy-17 and fix some warnings.
- [#2502](https://github.com/TokTok/c-toxcore/pull/2502) chore: Use `pkg_search_module` directly in cmake.
- [#2501](https://github.com/TokTok/c-toxcore/pull/2501) chore: Add `IMPORTED_TARGET` to pkg-config packages.
- [#2499](https://github.com/TokTok/c-toxcore/pull/2499) cleanup: Use target_link_libraries directly in cmake.
- [#2498](https://github.com/TokTok/c-toxcore/pull/2498) chore: Simplify msvc build using vcpkg.
- [#2497](https://github.com/TokTok/c-toxcore/pull/2497) cleanup: Remove NaCl support.
- [#2494](https://github.com/TokTok/c-toxcore/pull/2494) fix: unpack enum function names in event impl generator
- [#2493](https://github.com/TokTok/c-toxcore/pull/2493) chore: Disable targets for cross-compilation.
- [#2491](https://github.com/TokTok/c-toxcore/pull/2491) chore: Build a docker image with coverage info in it.
- [#2490](https://github.com/TokTok/c-toxcore/pull/2490) cleanup: Some portability/warning fixes for Windows builds.
- [#2488](https://github.com/TokTok/c-toxcore/pull/2488) fix: Correct a use-after-free and fix some memory leaks.
- [#2487](https://github.com/TokTok/c-toxcore/pull/2487) refactor: Change all enum-like `#define` sequences into enums.
- [#2486](https://github.com/TokTok/c-toxcore/pull/2486) refactor: Change the `TCP_PACKET_*` defines into an enum.
- [#2485](https://github.com/TokTok/c-toxcore/pull/2485) refactor: event generation tool for reorder pr
- [#2484](https://github.com/TokTok/c-toxcore/pull/2484) chore: Fix make_single_file to support core-only.
- [#2481](https://github.com/TokTok/c-toxcore/pull/2481) chore: Update github actions `uses`.
- [#2480](https://github.com/TokTok/c-toxcore/pull/2480) feat: add ngc related unpack functions
- [#2479](https://github.com/TokTok/c-toxcore/pull/2479) feat: Add `to_string` functions for all public enums.
- [#2477](https://github.com/TokTok/c-toxcore/pull/2477) test: add real timeout test
- [#2476](https://github.com/TokTok/c-toxcore/pull/2476) chore: Move s390x build to post-merge.
- [#2475](https://github.com/TokTok/c-toxcore/pull/2475) refactor: Give `enum-from-int` functions the ability to report errors.
- [#2474](https://github.com/TokTok/c-toxcore/pull/2474) cleanup: Remove test net support.
- [#2472](https://github.com/TokTok/c-toxcore/pull/2472) feat: Enable ubsan on bootstrap nodes.
- [#2470](https://github.com/TokTok/c-toxcore/pull/2470) test: Add check-c run to bazel build.
- [#2468](https://github.com/TokTok/c-toxcore/pull/2468) fix(test): tests use ipv6 by default, even with USE_IPV6 set to 0
- [#2466](https://github.com/TokTok/c-toxcore/pull/2466) cleanup: Make group saving/loading more forgiving with data errors
- [#2465](https://github.com/TokTok/c-toxcore/pull/2465) refactor: replace memset with a loop
- [#2459](https://github.com/TokTok/c-toxcore/pull/2459) fix: Enable debug flag for ubsan.
- [#2458](https://github.com/TokTok/c-toxcore/pull/2458) fix: also Install header for private/experimental API functions with autotools
- [#2456](https://github.com/TokTok/c-toxcore/pull/2456) docs: Remove defunct IRC channel from README.md
- [#2454](https://github.com/TokTok/c-toxcore/pull/2454) fix: memory leaks
- [#2453](https://github.com/TokTok/c-toxcore/pull/2453) refactor: Install header for private/experimental API functions
- [#2452](https://github.com/TokTok/c-toxcore/pull/2452) refactor: replace DEFAULT_TCP_RELAY_PORTS_COUNT with a compile-time calculation
- [#2451](https://github.com/TokTok/c-toxcore/pull/2451) cleanup: clarify disabling of static assert checks
- [#2449](https://github.com/TokTok/c-toxcore/pull/2449) cleanup: replace tabs with spaces
- [#2448](https://github.com/TokTok/c-toxcore/pull/2448) feat: group connection queries now return our own connection type
- [#2447](https://github.com/TokTok/c-toxcore/pull/2447) fix: Docker tox-bootstrapd hash update failing when using BuildKit
- [#2446](https://github.com/TokTok/c-toxcore/pull/2446) feat: Add groupchat API function that returns an IP address string for a peer
- [#2442](https://github.com/TokTok/c-toxcore/pull/2442) perf: Slightly reduce bandwidth usage when there are few nodes.
- [#2439](https://github.com/TokTok/c-toxcore/pull/2439) test: Make esp32 build actually try to instantiate tox.
- [#2438](https://github.com/TokTok/c-toxcore/pull/2438) cleanup: Remove explicit layering_check feature.
- [#2437](https://github.com/TokTok/c-toxcore/pull/2437) chore: Upgrade sonar-scan jvm to java 17.
- [#2436](https://github.com/TokTok/c-toxcore/pull/2436) fix: Add missing `htons` call when adding configured TCP relay.
- [#2434](https://github.com/TokTok/c-toxcore/pull/2434) chore: Cancel old PR builds on docker and sonar-scan workflows.
- [#2432](https://github.com/TokTok/c-toxcore/pull/2432) chore: Use C99 on MSVC instead of C11.
- [#2430](https://github.com/TokTok/c-toxcore/pull/2430) chore: Retry freebsd tests 2 times.
- [#2429](https://github.com/TokTok/c-toxcore/pull/2429) test: Add an s390x build (on alpine) for CI.
- [#2428](https://github.com/TokTok/c-toxcore/pull/2428) chore: Add a compcert docker run script.
- [#2427](https://github.com/TokTok/c-toxcore/pull/2427) cleanup: Use tcc docker image for CI.
- [#2424](https://github.com/TokTok/c-toxcore/pull/2424) fix: Fix memory leak in the error path of loading savedata.
- [#2420](https://github.com/TokTok/c-toxcore/pull/2420) refactor: Use Bin_Pack for packing Node_format.
- [#2416](https://github.com/TokTok/c-toxcore/pull/2416) chore: Add more logging to loading conferences from savedata.
- [#2415](https://github.com/TokTok/c-toxcore/pull/2415) refactor: Add a `bin_unpack_bin_max` for max-length arrays.
- [#2414](https://github.com/TokTok/c-toxcore/pull/2414) fix: inversed return values
- [#2413](https://github.com/TokTok/c-toxcore/pull/2413) cleanup: Fix GCC compatibility.
- [#2408](https://github.com/TokTok/c-toxcore/pull/2408) fix: Ensure we have allocators available for the error paths.
- [#2407](https://github.com/TokTok/c-toxcore/pull/2407) cleanup: Remove redundant `-DSODIUM_EXPORT` from definitions.
- [#2406](https://github.com/TokTok/c-toxcore/pull/2406) cleanup: Fix a few more clang-tidy warnings.
- [#2405](https://github.com/TokTok/c-toxcore/pull/2405) cleanup: Fix a few more clang-tidy warnings.
- [#2404](https://github.com/TokTok/c-toxcore/pull/2404) cleanup: Enforce stricter identifier naming using clang-tidy.
- [#2396](https://github.com/TokTok/c-toxcore/pull/2396) chore: Add devcontainer setup for codespaces.
- [#2393](https://github.com/TokTok/c-toxcore/pull/2393) refactor: Add `mem` module to allow tests to override allocators.
- [#2392](https://github.com/TokTok/c-toxcore/pull/2392) refactor: Make event dispatch ordered by receive time.
- [#2391](https://github.com/TokTok/c-toxcore/pull/2391) docs: Fix doxygen config and remove some redundant comments.
- [#2390](https://github.com/TokTok/c-toxcore/pull/2390) chore: Fix the Android CI job
- [#2389](https://github.com/TokTok/c-toxcore/pull/2389) fix: Add missing `#include <array>`.
- [#2388](https://github.com/TokTok/c-toxcore/pull/2388) chore: Add missing module dependencies.
- [#2384](https://github.com/TokTok/c-toxcore/pull/2384) feat: increase NGC lossy custom packet size
- [#2383](https://github.com/TokTok/c-toxcore/pull/2383) fix: add missing ngc constants getter declarations and definitions
- [#2381](https://github.com/TokTok/c-toxcore/pull/2381) fix: incorrect documentation
- [#2380](https://github.com/TokTok/c-toxcore/pull/2380) feat: allow for larger incoming NGC packets
- [#2371](https://github.com/TokTok/c-toxcore/pull/2371) docs: fix group_peer_exit_cb
- [#2370](https://github.com/TokTok/c-toxcore/pull/2370) fix: behaviour of group api function
- [#2369](https://github.com/TokTok/c-toxcore/pull/2369) fix: flaky tcp test
- [#2367](https://github.com/TokTok/c-toxcore/pull/2367) fix: fuzz support for TCP server
- [#2364](https://github.com/TokTok/c-toxcore/pull/2364) fix: potential endless loop under extremely high load
- [#2362](https://github.com/TokTok/c-toxcore/pull/2362) test: enable tcp relay for bootstrap fuzzing
- [#2361](https://github.com/TokTok/c-toxcore/pull/2361) fix: resolve_bootstrap_node() not checking net_getipport() returned count correctly
- [#2357](https://github.com/TokTok/c-toxcore/pull/2357) feat: get the number of close dht nodes with announce/store support
- [#2355](https://github.com/TokTok/c-toxcore/pull/2355) fix: group custom packet size limits
- [#2354](https://github.com/TokTok/c-toxcore/pull/2354) fix: DHTBootstrap should always respond to version packets with toxcore version
- [#2351](https://github.com/TokTok/c-toxcore/pull/2351) fix: Increase max group message length by four bytes
- [#2348](https://github.com/TokTok/c-toxcore/pull/2348) refactor: Make some improvements to how often/when we announce a group
- [#2341](https://github.com/TokTok/c-toxcore/pull/2341) fix: #1144 by forcing misc_tools to be a static lib
- [#2340](https://github.com/TokTok/c-toxcore/pull/2340) fix: missing net to host conversion of port in logging in group_chat.c
- [#2339](https://github.com/TokTok/c-toxcore/pull/2339) fix: missing net to host conversion of port in logging
- [#2338](https://github.com/TokTok/c-toxcore/pull/2338) fix: bug causing friend group invites to sometimes fail & improve logging
- [#2333](https://github.com/TokTok/c-toxcore/pull/2333) docs: Update README for bootstrap node docker
- [#2329](https://github.com/TokTok/c-toxcore/pull/2329) refactor: extract each case in handle packet in messenger
- [#2327](https://github.com/TokTok/c-toxcore/pull/2327) fix: unlock correct dht_friend
- [#2325](https://github.com/TokTok/c-toxcore/pull/2325) fix: Remove cmake cache files after copying to container build directory
- [#2323](https://github.com/TokTok/c-toxcore/pull/2323) docs: Update README.md to include cmp submodule info
- [#2318](https://github.com/TokTok/c-toxcore/pull/2318) chore: disable warning about pre C99 code
- [#2317](https://github.com/TokTok/c-toxcore/pull/2317) Refactor: Extract shared key cache into separate file
- [#2311](https://github.com/TokTok/c-toxcore/pull/2311) cleanup: make it more clear that assert and uint32_t increment both only exist if NDEBUG is not defined
- [#2291](https://github.com/TokTok/c-toxcore/pull/2291) test: Add a protocol dump test to generate initial fuzzer input.
- [#2271](https://github.com/TokTok/c-toxcore/pull/2271) chore: Migrate from Appveyor to Azure Pipelines
- [#2269](https://github.com/TokTok/c-toxcore/pull/2269) feat: Merge the remainder of the new groupchats implementation
- [#2203](https://github.com/TokTok/c-toxcore/pull/2203) refactor: Store time in Mono_Time in milliseconds.
- [#1944](https://github.com/TokTok/c-toxcore/pull/1944) chore: tox_new() should return null when savedata loading fails
### Closed issues:
- [#2739](https://github.com/TokTok/c-toxcore/issues/2739) Tox_Options.operating_system is not clear about it being an experimental option
- [#2734](https://github.com/TokTok/c-toxcore/issues/2734) error compiling on fedora
- [#2649](https://github.com/TokTok/c-toxcore/issues/2649) create_extended_keypair should use Random and be made deterministic for fuzzing
- [#2358](https://github.com/TokTok/c-toxcore/issues/2358) resolve_bootstrap_node assert hit
- [#2352](https://github.com/TokTok/c-toxcore/issues/2352) SEGV after infinite loop retrying proxy_socks5_read_connection_response
- [#2335](https://github.com/TokTok/c-toxcore/issues/2335) ipv6 disabled on kernel cmdline disrupts Tox = most tests fail
- [#2303](https://github.com/TokTok/c-toxcore/issues/2303) Add new group chats events to tox_events and tox_dispatch modules.
- [#2302](https://github.com/TokTok/c-toxcore/issues/2302) Run strong fuzz tests against NGC
- [#2301](https://github.com/TokTok/c-toxcore/issues/2301) Implement NGC save/load in hs-toxcore and run round-trip tests against c-toxcore
- [#2192](https://github.com/TokTok/c-toxcore/issues/2192) Provide official signed release tarballs
- [#2118](https://github.com/TokTok/c-toxcore/issues/2118) Add a private "get mono_time" API to `tox_private.h` and use it in auto_tests.
- [#2029](https://github.com/TokTok/c-toxcore/issues/2029) Migrate all auto tests to the events API.
- [#2014](https://github.com/TokTok/c-toxcore/issues/2014) Add sodium autotools CI build
- [#1144](https://github.com/TokTok/c-toxcore/issues/1144) DHT_bootstrap should not link against misc_tools
## v0.2.18
### Merged PRs:
- [#2300](https://github.com/TokTok/c-toxcore/pull/2300) chore: Release 0.2.18
- [#2299](https://github.com/TokTok/c-toxcore/pull/2299) fix: remove the assert because buffer can be larger than UINT16_MAX.
- [#2297](https://github.com/TokTok/c-toxcore/pull/2297) cleanup: remove unused field last_seen from Onion_Friend
- [#2289](https://github.com/TokTok/c-toxcore/pull/2289) test: Add a Null_System used in toxsave_harness.
@ -107,6 +372,7 @@
### Closed issues:
- [#2298](https://github.com/TokTok/c-toxcore/issues/2298) assert makes incorrect assumption
- [#2256](https://github.com/TokTok/c-toxcore/issues/2256) New Defects reported by Coverity Scan for TokTok/c-toxcore
- [#2109](https://github.com/TokTok/c-toxcore/issues/2109) Assimilate `messenger_test.c`: replace with public API test
- [#2012](https://github.com/TokTok/c-toxcore/issues/2012) Support building a DLL on Windows

View File

@ -1,52 +1,610 @@
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
################################################################################
#
# The main toxcore CMake build file.
#
# This file when processed with cmake produces:
# - A number of small libraries (.a/.so/...) containing independent components
# of toxcore. E.g. the DHT has its own library, and the system/network
# abstractions are in their own library as well. These libraries are not
# installed on `make install`. The toxav, and toxencryptsave libraries are
# also not installed.
# - A number of small programs, statically linked if possible.
# - One big library containing all of the toxcore, toxav, and toxencryptsave
# code.
#
################################################################################
# cmake setup begin
project(tomato)
cmake_minimum_required(VERSION 3.16)
cmake_policy(VERSION 3.16)
project(toxcore)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
list(APPEND CMAKE_MODULE_PATH ${toxcore_SOURCE_DIR}/cmake)
# defaulting to debug mode, if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
option(FLAT_OUTPUT_STRUCTURE "Whether to produce output artifacts in ${CMAKE_BINARY_DIR}/{bin,lib}" OFF)
if(FLAT_OUTPUT_STRUCTURE)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()
# setup my vim ycm :D
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set_source_files_properties(
toxcore/mono_time.c
toxcore/network.c
toxcore/tox.c
toxcore/util.c
PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE)
# more paths
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
################################################################################
#
# :: Version management
#
################################################################################
# external libs
add_subdirectory(./external) # before increasing warn levels, sad :(
# This version is for the entire project. All libraries (core, av, ...) move in
# versions in a synchronised way.
set(PROJECT_VERSION_MAJOR "0")
set(PROJECT_VERSION_MINOR "2")
set(PROJECT_VERSION_PATCH "19")
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
# set .so library version / following libtool scheme
# https://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
file(STRINGS ${toxcore_SOURCE_DIR}/so.version SOVERSION_CURRENT REGEX "^CURRENT=[0-9]+$")
string(SUBSTRING "${SOVERSION_CURRENT}" 8 -1 SOVERSION_CURRENT)
file(STRINGS ${toxcore_SOURCE_DIR}/so.version SOVERSION_REVISION REGEX "^REVISION=[0-9]+$")
string(SUBSTRING "${SOVERSION_REVISION}" 9 -1 SOVERSION_REVISION)
file(STRINGS ${toxcore_SOURCE_DIR}/so.version SOVERSION_AGE REGEX "^AGE=[0-9]+$")
string(SUBSTRING "${SOVERSION_AGE}" 4 -1 SOVERSION_AGE)
# account for some libtool magic, see other/version-sync script for details
math(EXPR SOVERSION_MAJOR ${SOVERSION_CURRENT}-${SOVERSION_AGE})
set(SOVERSION "${SOVERSION_MAJOR}.${SOVERSION_AGE}.${SOVERSION_REVISION}")
message("SOVERSION: ${SOVERSION}")
################################################################################
#
# :: Dependencies and configuration
#
################################################################################
include(CTest)
include(ModulePackage)
include(StrictAbi)
include(GNUInstallDirs)
if(APPLE)
include(MacRpath)
endif()
enable_testing()
find_package(GTest)
set(CMAKE_MACOSX_RPATH ON)
# Set standard version for compiler.
if(MSVC AND MSVC_TOOLSET_VERSION LESS 143)
# https://developercommunity.visualstudio.com/t/older-winsdk-headers-are-incompatible-with-zcprepr/1593479
set(CMAKE_C_STANDARD 99)
else()
set(CMAKE_C_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_EXTENSIONS OFF)
# bump up warning levels appropriately for clang, gcc & msvc
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
add_compile_options(
-Wall -Wextra # Reasonable and standard
-Wpedantic # Warn if non-standard C++ is used
-Wunused # Warn on anything being unused
#-Wconversion # Warn on type conversions that may lose data
#-Wsign-conversion # Warn on sign conversions
-Wshadow # Warn if a variable declaration shadows one from a parent context
)
message(STATUS "Supported C compiler features = ${CMAKE_C_COMPILE_FEATURES}")
message(STATUS "Supported C++ compiler features = ${CMAKE_CXX_COMPILE_FEATURES}")
if (NOT WIN32)
#link_libraries(-fsanitize=address,undefined)
#link_libraries(-fsanitize=undefined)
# Enable some warnings if we know the compiler.
if(MSVC)
add_compile_options(/W4 /analyze)
add_compile_options(/wd4100) # unreferenced formal parameter
add_compile_options(/wd4267) # narrowing conversion
add_compile_options(/wd4244) # narrowing conversion
add_compile_options(/wd4127) # conditional expression is constant
add_compile_options(/wd4995) # #pragma deprecated
add_compile_options(/wd4018) # signed/unsigned compare
add_compile_options(/wd4310) # cast truncates constant value
add_compile_options(/wd4389) # signed/unsigned compare
add_compile_options(/wd4245) # signed/unsigned assign/return/function call
add_compile_options(/wd4200) # nonstandard extension used: zero-sized array in struct/union
add_compile_options(/wd4702) # unreachable code
add_compile_options(/wd6340) # unsigned int passed to signed parameter
add_compile_options(/wd6326) # potential comparison of a constant with another constant
# TODO(iphydf): Look into these
add_compile_options(/wd4996) # use WSAAddressToStringW() instead of WSAAddressToStringA()
add_compile_options(/wd6255) # don't use alloca
add_compile_options(/wd6385) # reading invalid data
add_compile_options(/wd6001) # using uninitialized memory
add_compile_options(/wd6101) # returning uninitialized memory
add_compile_options(/wd6386) # buffer overrun
add_compile_options(/wd6011) # NULL dereference
add_compile_options(/wd6031) # sscanf return value ignored
add_compile_options(/wd6387) # passing NULL to fwrite
endif()
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(MIN_LOGGER_LEVEL "" CACHE STRING "Logging level to use (TRACE, DEBUG, INFO, WARNING, ERROR)")
if(MIN_LOGGER_LEVEL)
if(("${MIN_LOGGER_LEVEL}" STREQUAL "TRACE") OR
("${MIN_LOGGER_LEVEL}" STREQUAL "DEBUG") OR
("${MIN_LOGGER_LEVEL}" STREQUAL "INFO") OR
("${MIN_LOGGER_LEVEL}" STREQUAL "WARNING") OR
("${MIN_LOGGER_LEVEL}" STREQUAL "ERROR"))
add_definitions(-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_${MIN_LOGGER_LEVEL})
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
message(FATAL_ERROR "Unknown value provided for MIN_LOGGER_LEVEL: \"${MIN_LOGGER_LEVEL}\", must be one of TRACE, DEBUG, INFO, WARNING or ERROR")
endif()
endif()
# cmake setup end
option(EXPERIMENTAL_API "Install experimental header file with unstable API" OFF)
add_subdirectory(./src)
option(USE_IPV6 "Use IPv6 in tests" ON)
if(NOT USE_IPV6)
add_definitions(-DUSE_IPV6=0)
endif()
option(BUILD_MISC_TESTS "Build additional tests" OFF)
option(BUILD_FUN_UTILS "Build additional just for fun utilities" OFF)
option(UNITTEST "Enable unit tests (disable if you don't have a working gmock or gtest)" ON)
option(AUTOTEST "Enable autotests (mainly for CI)" OFF)
if(AUTOTEST)
option(NON_HERMETIC_TESTS "Whether to build and run tests that depend on an internet connection" OFF)
option(PROXY_TEST "Enable proxy test (requires other/proxy/proxy_server.go to be running)" OFF)
endif()
option(BUILD_TOXAV "Whether to build the tox AV library" ON)
option(MUST_BUILD_TOXAV "Fail the build if toxav cannot be built" OFF)
option(DHT_BOOTSTRAP "Enable building of DHT_bootstrap" ON)
option(BOOTSTRAP_DAEMON "Enable building of tox-bootstrapd" ON)
if(BOOTSTRAP_DAEMON AND WIN32)
message(WARNING "Building tox-bootstrapd for Windows is not supported, disabling")
set(BOOTSTRAP_DAEMON OFF)
endif()
option(BUILD_FUZZ_TESTS "Build fuzzing harnesses" OFF)
if(MSVC)
option(MSVC_STATIC_SODIUM "Whether to link libsodium statically for MSVC" OFF)
if(MSVC_STATIC_SODIUM)
add_definitions(-DSODIUM_STATIC=1)
endif()
endif()
include(Dependencies)
if(MUST_BUILD_TOXAV)
set(NO_TOXAV_ERROR_TYPE SEND_ERROR)
else()
set(NO_TOXAV_ERROR_TYPE WARNING)
endif()
if(BUILD_TOXAV)
if(NOT OPUS_FOUND)
message(${NO_TOXAV_ERROR_TYPE} "Option BUILD_TOXAV is enabled but required library OPUS was not found.")
set(BUILD_TOXAV OFF)
endif()
if(NOT VPX_FOUND)
message(${NO_TOXAV_ERROR_TYPE} "Option BUILD_TOXAV is enabled but required library VPX was not found.")
set(BUILD_TOXAV OFF)
endif()
endif()
# Disable float/double packing in CMP (C MessagePack library).
# We don't transfer floats over the network, so we disable this functionality.
add_definitions(-DCMP_NO_FLOAT=1)
################################################################################
#
# :: Tox Core Library
#
################################################################################
# toxcore_PKGCONFIG_LIBS is what's added to the Libs: line in toxcore.pc. It
# needs to contain all the libraries a program using toxcore should link against
# if it's statically linked. If it's dynamically linked, there is no need to
# explicitly link against all the dependencies, but it doesn't harm much(*)
# either.
#
# (*) It allows client code to use symbols from our dependencies without
# explicitly linking against them.
set(toxcore_PKGCONFIG_LIBS)
# Requires: in pkg-config file.
set(toxcore_PKGCONFIG_REQUIRES)
set(toxcore_SOURCES
third_party/cmp/cmp.c
third_party/cmp/cmp.h
toxcore/announce.c
toxcore/announce.h
toxcore/bin_pack.c
toxcore/bin_pack.h
toxcore/bin_unpack.c
toxcore/bin_unpack.h
toxcore/ccompat.c
toxcore/ccompat.h
toxcore/crypto_core.c
toxcore/crypto_core.h
toxcore/crypto_core_pack.c
toxcore/crypto_core_pack.h
toxcore/DHT.c
toxcore/DHT.h
toxcore/events/conference_connected.c
toxcore/events/conference_invite.c
toxcore/events/conference_message.c
toxcore/events/conference_peer_list_changed.c
toxcore/events/conference_peer_name.c
toxcore/events/conference_title.c
toxcore/events/dht_get_nodes_response.c
toxcore/events/events_alloc.c
toxcore/events/events_alloc.h
toxcore/events/file_chunk_request.c
toxcore/events/file_recv.c
toxcore/events/file_recv_chunk.c
toxcore/events/file_recv_control.c
toxcore/events/friend_connection_status.c
toxcore/events/friend_lossless_packet.c
toxcore/events/friend_lossy_packet.c
toxcore/events/friend_message.c
toxcore/events/friend_name.c
toxcore/events/friend_read_receipt.c
toxcore/events/friend_request.c
toxcore/events/friend_status.c
toxcore/events/friend_status_message.c
toxcore/events/friend_typing.c
toxcore/events/self_connection_status.c
toxcore/events/group_custom_packet.c
toxcore/events/group_custom_private_packet.c
toxcore/events/group_invite.c
toxcore/events/group_join_fail.c
toxcore/events/group_message.c
toxcore/events/group_moderation.c
toxcore/events/group_password.c
toxcore/events/group_peer_exit.c
toxcore/events/group_peer_join.c
toxcore/events/group_peer_limit.c
toxcore/events/group_peer_name.c
toxcore/events/group_peer_status.c
toxcore/events/group_privacy_state.c
toxcore/events/group_private_message.c
toxcore/events/group_self_join.c
toxcore/events/group_topic.c
toxcore/events/group_topic_lock.c
toxcore/events/group_voice_state.c
toxcore/forwarding.c
toxcore/forwarding.h
toxcore/friend_connection.c
toxcore/friend_connection.h
toxcore/friend_requests.c
toxcore/friend_requests.h
toxcore/group.c
toxcore/group_chats.c
toxcore/group_chats.h
toxcore/group_common.h
toxcore/group_connection.c
toxcore/group_connection.h
toxcore/group.h
toxcore/group_announce.c
toxcore/group_announce.h
toxcore/group_moderation.c
toxcore/group_moderation.h
toxcore/group_onion_announce.c
toxcore/group_onion_announce.h
toxcore/group_pack.c
toxcore/group_pack.h
toxcore/LAN_discovery.c
toxcore/LAN_discovery.h
toxcore/list.c
toxcore/list.h
toxcore/logger.c
toxcore/logger.h
toxcore/Messenger.c
toxcore/Messenger.h
toxcore/mem.c
toxcore/mem.h
toxcore/mono_time.c
toxcore/mono_time.h
toxcore/net_crypto.c
toxcore/net_crypto.h
toxcore/network.c
toxcore/network.h
toxcore/onion_announce.c
toxcore/onion_announce.h
toxcore/onion.c
toxcore/onion_client.c
toxcore/onion_client.h
toxcore/onion.h
toxcore/ping_array.c
toxcore/ping_array.h
toxcore/ping.c
toxcore/ping.h
toxcore/shared_key_cache.c
toxcore/shared_key_cache.h
toxcore/state.c
toxcore/state.h
toxcore/TCP_client.c
toxcore/TCP_client.h
toxcore/TCP_common.c
toxcore/TCP_common.h
toxcore/TCP_connection.c
toxcore/TCP_connection.h
toxcore/TCP_server.c
toxcore/TCP_server.h
toxcore/timed_auth.c
toxcore/timed_auth.h
toxcore/tox_api.c
toxcore/tox.c
toxcore/tox_dispatch.c
toxcore/tox_dispatch.h
toxcore/tox_event.c
toxcore/tox_event.h
toxcore/tox_events.c
toxcore/tox_events.h
toxcore/tox.h
toxcore/tox_private.c
toxcore/tox_private.h
toxcore/tox_pack.c
toxcore/tox_pack.h
toxcore/tox_unpack.c
toxcore/tox_unpack.h
toxcore/util.c
toxcore/util.h)
if(TARGET unofficial-sodium::sodium)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} unofficial-sodium::sodium)
else()
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${LIBSODIUM_LIBRARIES})
set(toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${LIBSODIUM_LIBRARY_DIRS})
set(toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${LIBSODIUM_INCLUDE_DIRS})
set(toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${LIBSODIUM_CFLAGS_OTHER})
endif()
set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium)
set(toxcore_API_HEADERS
${toxcore_SOURCE_DIR}/toxcore/tox.h^tox
${toxcore_SOURCE_DIR}/toxcore/tox_events.h^tox
${toxcore_SOURCE_DIR}/toxcore/tox_dispatch.h^tox)
if(EXPERIMENTAL_API)
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
${toxcore_SOURCE_DIR}/toxcore/tox_private.h^tox)
endif()
################################################################################
#
# :: Audio/Video Library
#
################################################################################
if(BUILD_TOXAV)
set(toxcore_SOURCES ${toxcore_SOURCES}
toxav/audio.c
toxav/audio.h
toxav/bwcontroller.c
toxav/bwcontroller.h
toxav/groupav.c
toxav/groupav.h
toxav/msi.c
toxav/msi.h
toxav/ring_buffer.c
toxav/ring_buffer.h
toxav/rtp.c
toxav/rtp.h
toxav/toxav.c
toxav/toxav.h
toxav/toxav_old.c
toxav/video.c
toxav/video.h)
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav)
if(MSVC)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} PkgConfig::OPUS PkgConfig::VPX)
else()
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${OPUS_LIBRARIES} ${VPX_LIBRARIES})
set(toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${OPUS_LIBRARY_DIRS} ${VPX_LIBRARY_DIRS})
set(toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${OPUS_INCLUDE_DIRS} ${VPX_INCLUDE_DIRS})
set(toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${OPUS_CFLAGS_OTHER} ${VPX_CFLAGS_OTHER})
endif()
set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} opus vpx)
endif()
################################################################################
#
# :: Block encryption libraries
#
################################################################################
set(toxcore_SOURCES ${toxcore_SOURCES}
toxencryptsave/toxencryptsave.c
toxencryptsave/toxencryptsave.h)
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
${toxcore_SOURCE_DIR}/toxencryptsave/toxencryptsave.h^tox)
################################################################################
#
# :: System dependencies
#
################################################################################
# These need to come after other dependencies, since e.g. libvpx may depend on
# pthread, but doesn't list it in VPX_LIBRARIES. We're adding it here, after
# any potential libvpx linking.
message("CMAKE_THREAD_LIBS_INIT: ${CMAKE_THREAD_LIBS_INIT}")
if(CMAKE_THREAD_LIBS_INIT)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()
if(NSL_LIBRARIES)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${NSL_LIBRARIES})
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lnsl)
endif()
if(RT_LIBRARIES)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${RT_LIBRARIES})
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lrt)
endif()
if(SOCKET_LIBRARIES)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${SOCKET_LIBRARIES})
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lsocket)
endif()
if(TARGET PThreads4W::PThreads4W)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} PThreads4W::PThreads4W)
elseif(TARGET Threads::Threads)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} Threads::Threads)
endif()
if(WIN32)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} iphlpapi ws2_32)
endif()
################################################################################
#
# :: All layers together in one library for ease of use
#
################################################################################
# Create combined library from all the sources.
if(ENABLE_SHARED)
add_library(toxcore_shared SHARED ${toxcore_SOURCES})
set_target_properties(toxcore_shared PROPERTIES OUTPUT_NAME toxcore)
target_link_libraries(toxcore_shared PRIVATE ${toxcore_LINK_LIBRARIES})
target_link_directories(toxcore_shared PUBLIC ${toxcore_LINK_DIRECTORIES})
target_include_directories(toxcore_shared SYSTEM PRIVATE ${toxcore_INCLUDE_DIRECTORIES})
target_compile_options(toxcore_shared PRIVATE ${toxcore_COMPILE_OPTIONS})
endif()
if(ENABLE_STATIC)
add_library(toxcore_static STATIC ${toxcore_SOURCES})
if(NOT MSVC)
set_target_properties(toxcore_static PROPERTIES OUTPUT_NAME toxcore)
endif()
target_link_libraries(toxcore_static PRIVATE ${toxcore_LINK_LIBRARIES})
target_link_directories(toxcore_static PUBLIC ${toxcore_LINK_DIRECTORIES})
target_include_directories(toxcore_static SYSTEM PRIVATE ${toxcore_INCLUDE_DIRECTORIES})
target_compile_options(toxcore_static PRIVATE ${toxcore_COMPILE_OPTIONS})
endif()
if(BUILD_FUZZ_TESTS)
add_library(toxcore_fuzz STATIC ${toxcore_SOURCES})
target_link_libraries(toxcore_fuzz PRIVATE ${toxcore_LINK_LIBRARIES})
target_link_directories(toxcore_fuzz PUBLIC ${toxcore_LINK_DIRECTORIES})
target_include_directories(toxcore_fuzz SYSTEM PRIVATE ${toxcore_INCLUDE_DIRECTORIES})
target_compile_options(toxcore_fuzz PRIVATE ${toxcore_COMPILE_OPTIONS})
target_compile_definitions(toxcore_fuzz PUBLIC "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION")
endif()
# Make version script (on systems that support it) to limit symbol visibility.
make_version_script(toxcore ${toxcore_API_HEADERS})
# Generate pkg-config file, install library to "${CMAKE_INSTALL_LIBDIR}" and install headers to
# "${CMAKE_INSTALL_INCLUDEDIR}/tox".
install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox)
################################################################################
#
# :: Unit tests: no networking, just pure function calls.
#
################################################################################
add_library(test_util STATIC
toxcore/DHT_test_util.cc
toxcore/DHT_test_util.hh
toxcore/crypto_core_test_util.cc
toxcore/crypto_core_test_util.hh
toxcore/mem_test_util.cc
toxcore/mem_test_util.hh
toxcore/network_test_util.cc
toxcore/network_test_util.hh
toxcore/test_util.cc
toxcore/test_util.hh)
function(unit_test subdir target)
add_executable(unit_${target}_test ${subdir}/${target}_test.cc)
target_link_libraries(unit_${target}_test PRIVATE test_util)
if(TARGET toxcore_static)
target_link_libraries(unit_${target}_test PRIVATE toxcore_static)
else()
target_link_libraries(unit_${target}_test PRIVATE toxcore_shared)
endif()
target_link_libraries(unit_${target}_test PRIVATE GTest::gtest GTest::gtest_main GTest::gmock)
set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${TEST_CXX_FLAGS}")
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
set_property(TEST ${target} PROPERTY ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw")
endfunction()
# The actual unit tests follow.
#
if(UNITTEST AND TARGET GTest::gtest AND TARGET GTest::gmock)
unit_test(toxav ring_buffer)
unit_test(toxav rtp)
unit_test(toxcore DHT)
unit_test(toxcore bin_pack)
unit_test(toxcore crypto_core)
unit_test(toxcore group_announce)
unit_test(toxcore group_moderation)
unit_test(toxcore list)
unit_test(toxcore mem)
unit_test(toxcore mono_time)
unit_test(toxcore ping_array)
unit_test(toxcore test_util)
unit_test(toxcore tox)
unit_test(toxcore util)
endif()
add_subdirectory(testing)
################################################################################
#
# :: Automated regression tests: create a tox network and run integration tests
#
################################################################################
if(AUTOTEST)
add_subdirectory(auto_tests)
endif()
################################################################################
#
# :: Bootstrap daemon
#
################################################################################
if(DHT_BOOTSTRAP)
add_executable(DHT_bootstrap
other/DHT_bootstrap.c
other/bootstrap_node_packets.c)
if(TARGET toxcore_static)
target_link_libraries(DHT_bootstrap PRIVATE toxcore_static)
else()
target_link_libraries(DHT_bootstrap PRIVATE toxcore_shared)
endif()
target_link_libraries(DHT_bootstrap PRIVATE misc_tools)
if(TARGET unofficial-sodium::sodium)
target_link_libraries(DHT_bootstrap PRIVATE unofficial-sodium::sodium)
endif()
if(TARGET PThreads4W::PThreads4W)
target_link_libraries(DHT_bootstrap PRIVATE PThreads4W::PThreads4W)
elseif(TARGET Threads::Threads)
target_link_libraries(DHT_bootstrap PRIVATE Threads::Threads)
endif()
install(TARGETS DHT_bootstrap RUNTIME DESTINATION bin)
endif()
if(BOOTSTRAP_DAEMON)
if(LIBCONFIG_FOUND)
add_subdirectory(other/bootstrap_daemon)
else()
message(WARNING "Option BOOTSTRAP_DAEMON is enabled but required library LIBCONFIG was not found.")
set(BOOTSTRAP_DAEMON OFF)
endif()
endif()
if(BUILD_FUN_UTILS)
add_subdirectory(other/fun)
endif()
if (BUILD_FUZZ_TESTS)
add_subdirectory(testing/fuzzing)
endif()

21
CMakePresets.json Normal file
View File

@ -0,0 +1,21 @@
{
"version": 3,
"configurePresets": [
{
"name": "windows-default",
"binaryDir": "${sourceDir}/_build",
"cacheVariables": {
"ENABLE_SHARED": true,
"ENABLE_STATIC": true,
"AUTOTEST": true,
"BUILD_MISC_TESTS": true,
"BOOTSTRAP_DAEMON": false,
"MUST_BUILD_TOXAV": true,
"TEST_TIMEOUT_SECONDS": "60",
"CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS": true,
"CMAKE_COMPILE_WARNING_AS_ERROR": true,
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
}
]
}

455
INSTALL.md Normal file
View File

@ -0,0 +1,455 @@
# Installation instructions
These instructions will guide you through the process of building and installing
the toxcore library and its components, as well as getting already pre-built
binaries.
## Table of contents
- [Overview](#overview)
- [Components](#components)
- [Main](#main)
- [Secondary](#secondary)
- [Building](#building)
- [Requirements](#requirements)
- [Library dependencies](#library-dependencies)
- [Compiler requirements](#compiler-requirements)
- [Build system requirements](#build-system-requirements)
- [CMake options](#cmake-options)
- [Build process](#build-process)
- [Unix-like](#unix-like)
- [Windows](#windows)
- [Building on Windows host](#building-on-windows-host)
- [Microsoft Visual Studio's Developer Command Prompt](#microsoft-visual-studios-developer-command-prompt)
- [MSYS/Cygwin](#msyscygwin)
- [Cross-compiling from Linux](#cross-compiling-from-linux)
- [Pre-built binaries](#pre-built-binaries)
- [Linux](#linux)
## Overview
### Components
#### Main
This repository, although called `toxcore`, in fact contains several libraries
besides `toxcore` which complement it, as well as several executables. However,
note that although these are separate libraries, at the moment, when building
the libraries, they are all merged into a single `toxcore` library. Here is the
full list of the main components that can be built using the CMake, their
dependencies and descriptions.
| Name | Type | Dependencies | Platform | Description |
| ---------------- | ---------- | ---------------------------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `toxcore` | Library | libsodium, libm, libpthread, librt | Cross-platform | The main Tox library that provides the messenger functionality. |
| `toxav` | Library | libtoxcore, libopus, libvpx | Cross-platform | Provides audio/video functionality. |
| `toxencryptsave` | Library | libtoxcore, libsodium | Cross-platform | Provides encryption of Tox profiles (savedata), as well as arbitrary data. |
| `DHT_bootstrap` | Executable | libtoxcore | Cross-platform | A simple DHT bootstrap node. |
| `tox-bootstrapd` | Executable | libtoxcore, libconfig | Unix-like | Highly configurable DHT bootstrap node daemon (systemd, SysVinit, Docker). |
| `cmp` | Library | | Cross-platform | C implementation of the MessagePack serialization format. [https://github.com/camgunz/cmp](https://github.com/camgunz/cmp) |
#### Secondary
There are some programs that are not built by default which you might find
interesting. You need to pass `-DBUILD_FUN_UTILS=ON` to cmake to build them.
##### Vanity key generators
Can be used to generate vanity Tox Ids or DHT bootstrap node public keys.
| Name | Type | Dependencies | Platform | Description |
| ---------------- | ---------- | ----------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cracker` | Executable | libsodium, OpenMP | Cross-platform | Tries to find a curve25519 key pair, hex representation of the public key of which starts with a specified byte sequence. Multi-threaded. |
| `cracker_simple` | Executable | libsodium | Cross-platform | Tries to find a curve25519 key pair, hex representation of the public key of which starts with a specified byte sequence. Single-threaded. |
| `strkey` | Executable | libsodium | Cross-platform | Tries to find a curve25519 key pair, hex representation of the public key of which contains a specified byte sequence at a specified or any position at all. Single-threaded. |
##### Key file generators
Useful for generating Tox profiles from the output of the vanity key generators,
as well as generating random Tox profiles.
| Name | Type | Dependencies | Platform | Description |
| ------------------------- | ---------- | --------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `make-funny-savefile` | Script | python | Cross-platform | Generates a Tox profile file (savedata file) with the provided key pair. |
| `create_bootstrap_keys` | Executable | libsodium | Cross-platform | Generates a keys file for tox-bootstrapd with either the provided or a random key pair. |
| `create_minimal_savedata` | Executable | libsodium | Cross-platform | Generates a minimal Tox profile file (savedata file) with either the provided or a random key pair, printing the generated Tox Id and secret & public key information. |
| `create_savedata` | Executable | libsodium, libtoxcore | Cross-platform | Generates a Tox profile file (savedata file) with either the provided or a random key pair using libtoxcore, printing the generated Tox Id and secret & public key information. |
| `save-generator` | Executable | libtoxcore | Cross-platform | Generates a Tox profile file (savedata file) with a random key pair using libtoxcore, setting the specified user name, going online and adding specified Tox Ids as friends. |
##### Other
| Name | Type | Dependencies | Platform | Description |
| --------------------- | ---------- | ------------ | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `bootstrap_node_info` | Script | python3 | Cross-platform | Prints version and Message Of The Day (MOTD) information of the specified DHT bootstrap node, given the node doesn't have those disabled. |
| `sign` | Executable | libsodium | Cross-platform | Signs a file with a ed25519 key. |
## Building
### Requirements
#### Library dependencies
Library dependencies are listed in the [components](#components) table. The
dependencies need to be satisfied for the components to be built. Note that if
you don't have a dependency for some component, e.g. you don't have `libopus`
installed required for building `toxav` component, building of that component is
silently disabled.
Be advised that due to the addition of `cmp` as a submodule, you now also need
to initialize the git submodules required by toxcore. This can be done by
cloning the repo with the addition of `--recurse-submodules` or by running
`git submodule update --init` in the root directory of the repo.
#### Compiler requirements
The supported compilers are GCC, Clang and MinGW.
In theory, any compiler that fully supports C99 and accepts GCC flags should
work.
There is a partial and experimental support of Microsoft Visual C++ compiler. We
welcome any patches that help improve it.
You should have a C99 compatible compiler in order to build the main components.
The secondary components might require the compiler to support GNU extensions.
#### Build system requirements
To build the main components you need to have CMake of at least 2.8.6 version
installed. You also need to have pkg-config installed, the build system uses it
to find dependency libraries.
There is some experimental accommodation for building natively on Windows, i.e.
without having to use MSYS/Cygwin and pkg-config, but it uses exact hardcoded
paths for finding libraries and supports building only of some of toxcore
components, so your mileage might vary.
### CMake options
There are some options that are available to configure the build.
| Name | Description | Expected Value | Default Value |
| ----------------------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ------------------------------------------------- |
| `AUTOTEST` | Enable autotests (mainly for CI). | ON or OFF | OFF |
| `BOOTSTRAP_DAEMON` | Enable building of tox-bootstrapd, the DHT bootstrap node daemon. For Unix-like systems only. | ON or OFF | ON |
| `BUILD_FUN_UTILS` | Build additional just for fun utilities. | ON or OFF | OFF |
| `BUILD_FUZZ_TESTS` | Build fuzzing harnesses. | ON or OFF | OFF |
| `BUILD_MISC_TESTS` | Build additional tests. | ON or OFF | OFF |
| `BUILD_TOXAV` | Whether to build the toxav library. | ON or OFF | ON |
| `CMAKE_BUILD_TYPE` | Specifies the build type on single-configuration generators (e.g. make or ninja). | Debug, Release, RelWithDebInfo, MinSizeRel | Empty string. |
| `CMAKE_INSTALL_PREFIX` | Path to where everything should be installed. | Directory path. | Platform-dependent. Refer to CMake documentation. |
| `DHT_BOOTSTRAP` | Enable building of `DHT_bootstrap`. | ON or OFF | ON |
| `ENABLE_SHARED` | Build shared (dynamic) libraries for all modules. | ON or OFF | ON |
| `ENABLE_STATIC` | Build static libraries for all modules. | ON or OFF | ON |
| `EXPERIMENTAL_API` | Install experimental header file with unstable API. | ON or OFF | OFF |
| `FLAT_OUTPUT_STRUCTURE` | Whether to produce output artifacts in {bin,lib}. | ON or OFF | OFF |
| `FULLY_STATIC` | Build fully static executables. | ON or OFF | OFF |
| `MIN_LOGGER_LEVEL` | Logging level to use. | TRACE, DEBUG, INFO, WARNING, ERROR or nothing (empty string) for default. | Empty string. |
| `MSVC_STATIC_SODIUM` | Whether to link libsodium statically for MSVC. | ON or OFF | OFF |
| `MUST_BUILD_TOXAV` | Fail the build if toxav cannot be built. | ON or OFF | OFF |
| `NON_HERMETIC_TESTS` | Whether to build and run tests that depend on an internet connection. | ON or OFF | OFF |
| `PROXY_TEST` | Enable proxy test (requires `other/proxy/proxy_server.go` to be running). | ON or OFF | OFF |
| `STRICT_ABI` | Enforce strict ABI export in dynamic libraries. | ON or OFF | OFF |
| `TEST_TIMEOUT_SECONDS` | Limit runtime of each test to the number of seconds specified. | Positive number or nothing (empty string). | Empty string. |
| `UNITTEST` | Enable unit tests (disable if you don't have a working gmock or gtest). | ON or OFF | ON |
| `USE_IPV6` | Use IPv6 in tests. | ON or OFF | ON |
You can get this list of option using the following commands
```sh
cmake -B _build -LAH
```
or
```sh
grep "option(" CMakeLists.txt cmake/*
grep "set(.* CACHE" CMakeLists.txt cmake/*
```
Note that some options might be considered only if other options are enabled.
Example of calling cmake with options
```sh
cmake \
-D ENABLE_STATIC=OFF \
-D ENABLE_SHARED=ON \
-D CMAKE_INSTALL_PREFIX="${PWD}/prefix" \
-D CMAKE_BUILD_TYPE=Release \
-D TEST_TIMEOUT_SECONDS=120 \
..
```
### Building tests
In addition to the integration tests ("autotests") and miscellaneous tests
enabled by cmake variables described above, there are unit tests which will be
built if the source distribution of gtest (the Google Unit Test framework) is
found by cmake in `c-toxcore/third_party`. This can be achieved by running 'git
clone https://github.com/google/googletest` from that directory.
### Build process
#### Unix-like
Assuming all the [requirements](#requirements) are met, just run
```sh
mkdir _build
cd _build
cmake ..
make
make install
```
or shorter
```sh
cmake -B _build
cmake -B _build --target install
```
#### Windows
##### Building on Windows host
###### Microsoft Visual Studio's Developer Command Prompt
In addition to meeting the [requirements](#requirements), you need a version of
Visual Studio (the
[community edition](https://www.visualstudio.com/vs/visual-studio-express/) is
enough) and a CMake version that's compatible with the Visual Studio version
you're using.
You must also ensure that the msvc versions of dependencies you're using are
placed in the correct folders.
For libsodium that is `c-toxcore/third_party/libsodium`, and for pthreads-w32,
it's `c-toxcore/third_party/pthreads-win32`
Once all of this is done, from the **Developer Command Prompt for VS**, simply
run
```
mkdir _build
cd _build
cmake ..
msbuild ALL_BUILD.vcxproj
```
###### MSYS/Cygwin
Download Cygwin
([32-bit](https://cygwin.com/setup-x86.exe)/[64-bit](https://cygwin.com/setup-x86_64.exe))
Search and select exactly these packages in Devel category:
- mingw64-i686-gcc-core (32-bit) / mingw64-x86_64-gcc-core (64-bit)
- mingw64-i686-gcc-g++ (32-bit) / mingw64-x86_64-gcc-g++ (64-bit)
- make
- cmake
- libtool
- autoconf
- automake
- tree
- curl
- perl
- yasm
- pkg-config
To handle Windows EOL correctly run the following in the Cygwin Terminal:
```sh
echo '
export SHELLOPTS
set -o igncr
' > ~/.bash_profile
```
Download toxcore source code and extract it to a folder.
Open Cygwin Terminal in the toxcore folder and run
`./other/windows_build_script_toxcore.sh` to start the build process.
Toxcore build result files will appear in `/root/prefix/` relatively to Cygwin
folder (default `C:\cygwin64`).
Dependency versions can be customized in
`./other/windows_build_script_toxcore.sh` and described in the section below.
##### Cross-compiling from Linux
These cross-compilation instructions were tested on and written for 64-bit
Ubuntu 16.04. You could generalize them for any Linux system, the only
requirements are that you have Docker version of >= 1.9.0 and you are running
64-bit system.
The cross-compilation is fully automated by a parameterized
[Dockerfile](/other/docker/windows/Dockerfile).
Install Docker
```sh
apt-get update
apt-get install docker.io
```
Get the toxcore source code and navigate to `other/docker/windows`.
Build the container image based on the Dockerfile. The following options are
available to customize the building of the container image.
| Name | Description | Expected Value | Default Value |
| -------------------------- | ----------------------------------------------------- | ----------------------------------- | ------------- |
| `SUPPORT_ARCH_i686` | Support building 32-bit toxcore. | "true" or "false" (case sensitive). | true |
| `SUPPORT_ARCH_x86_64` | Support building 64-bit toxcore. | "true" or "false" (case sensitive). | true |
| `SUPPORT_TEST` | Support running toxcore automated tests. | "true" or "false" (case sensitive). | false |
| `VERSION_OPUS` | Version of libopus to build toxcore with. | Numeric version number. | 1.4 |
| `VERSION_SODIUM` | Version of libsodium to build toxcore with. | Numeric version number. | 1.0.19 |
| `VERSION_VPX` | Version of libvpx to build toxcore with. | Numeric version number. | 1.14.0 |
| `ENABLE_HASH_VERIFICATION` | Verify the hashes of the default dependency versions. | "true" or "false" (case sensitive). | true |
Example of building a container image with options
```sh
cd other/docker/windows
docker build \
--build-arg SUPPORT_TEST=true \
-t toxcore \
.
```
Run the container to build toxcore. The following options are available to
customize the running of the container image.
| Name | Description | Expected Value | Default Value |
| -------------------- | ------------------------------------------------------------------------------------------ | ----------------------------------- | ------------------------------------------ |
| `ALLOW_TEST_FAILURE` | Don't stop if a test suite fails. | "true" or "false" (case sensitive). | `false` |
| `ENABLE_ARCH_i686` | Build 32-bit toxcore. The image should have been built with `SUPPORT_ARCH_i686` enabled. | "true" or "false" (case sensitive). | `true` |
| `ENABLE_ARCH_x86_64` | Build 64-bit toxcore. The image should have been built with `SUPPORT_ARCH_x86_64` enabled. | "true" or "false" (case sensitive). | `true` |
| `ENABLE_TEST` | Run the test suite. The image should have been built with `SUPPORT_TEST` enabled. | "true" or "false" (case sensitive). | `false` |
| `EXTRA_CMAKE_FLAGS` | Extra arguments to pass to the CMake command when building toxcore. | CMake options. | `-DTEST_TIMEOUT_SECONDS=90 -DUSE_IPV6=OFF` |
Example of running the container with options
```sh
docker run \
-e ENABLE_TEST=true \
-e ALLOW_TEST_FAILURE=true \
-v /path/to/toxcore/sourcecode:/toxcore \
-v /path/to/where/output/build/result:/prefix \
-t \
--rm \
toxcore
```
After the build succeeds, you should see the built toxcore libraries in
`/path/to/where/output/build/result`.
The file structure should look similar to the following
```
result
├── [4.0K] i686
│   ├── [ 36K] bin
│   │   ├── [636K] DHT_bootstrap.exe
│   │   ├── [572K] cracker.exe
│   │   ├── [359K] cracker_simple.exe
│   │   ├── [378K] create_bootstrap_keys.exe
│   │   ├── [378K] create_minimal_savedata.exe
│   │   ├── [958K] create_savedata.exe
│   │   ├── [ 18K] libtoxcore.def
│   │   ├── [2.6M] libtoxcore.dll
│   │   ├── [ 65K] libtoxcore.exp
│   │   ├── [428K] libtoxcore.lib
│   │   ├── [989K] save-generator.exe
│   │   ├── [381K] sign.exe
│   │   └── [408K] strkey.exe
│   ├── [4.0K] include
│   │   └── [4.0K] tox
│   │   ├── [177K] tox.h
│   │   ├── [ 10K] tox_dispatch.h
│   │   ├── [ 26K] tox_events.h
│   │   ├── [6.4K] tox_private.h
│   │   ├── [ 26K] toxav.h
│   │   └── [ 12K] toxencryptsave.h
│   └── [4.0K] lib
│   ├── [577K] libopus.a
│   ├── [660K] libsodium.a
│   ├── [ 10K] libssp.a
│   ├── [1016K] libtoxcore.a
│   ├── [456K] libtoxcore.dll.a
│   ├── [2.7M] libvpx.a
│   ├── [ 72K] libwinpthread.a
│   └── [4.0K] pkgconfig
│   ├── [ 250] libsodium.pc
│   ├── [ 357] opus.pc
│   ├── [ 247] toxcore.pc
│   └── [ 309] vpx.pc
└── [4.0K] x86_64
├── [ 36K] bin
│   ├── [504K] DHT_bootstrap.exe
│   ├── [474K] cracker.exe
│   ├── [277K] cracker_simple.exe
│   ├── [287K] create_bootstrap_keys.exe
│   ├── [288K] create_minimal_savedata.exe
│   ├── [769K] create_savedata.exe
│   ├── [ 18K] libtoxcore.def
│   ├── [2.4M] libtoxcore.dll
│   ├── [ 64K] libtoxcore.exp
│   ├── [420K] libtoxcore.lib
│   ├── [800K] save-generator.exe
│   ├── [289K] sign.exe
│   └── [317K] strkey.exe
├── [4.0K] include
│   └── [4.0K] tox
│   ├── [177K] tox.h
│   ├── [ 10K] tox_dispatch.h
│   ├── [ 26K] tox_events.h
│   ├── [6.4K] tox_private.h
│   ├── [ 26K] toxav.h
│   └── [ 12K] toxencryptsave.h
└── [4.0K] lib
├── [697K] libopus.a
├── [575K] libsodium.a
├── [ 11K] libssp.a
├── [905K] libtoxcore.a
├── [449K] libtoxcore.dll.a
├── [2.9M] libvpx.a
├── [ 68K] libwinpthread.a
└── [4.0K] pkgconfig
├── [ 252] libsodium.pc
├── [ 359] opus.pc
├── [ 249] toxcore.pc
└── [ 311] vpx.pc
12 directories, 60 files
```
- `libtoxcore.dll` is the shared library. It is fully self-contained, with no
additional dependencies aside from the Windows OS dlls, and can be used in
MSVC, MinGW, Clang, etc. projects. Despite its name, it provides toxcore,
toxav, toxencryptsave -- all of Tox.
- `libtoxcore.a` is the static library. In order to use it, it needs to be
linked against the other provided .a libraries (but not the .dll.a!) and
additionally -liphlpapi and -lws2_32 Windows dlls. It similarly provides all
of Tox APIs.
- `libtoxcore.dll.a` is the MinGW import library for `libtoxcore.dll`.
- `libtoxcore.lib` is the MSVC import library for `libtoxcore.dll`.
- `libtoxcore.exp` and `libtoxcore.def` are the exported by `libtoxcore`
symbols.
- `*.exe` are statically compiled executables -- `DHT_bootstrap` and
[the fun utils](#secondary).
## Pre-built binaries
### Linux
Toxcore is packaged by at least by the following distributions: ALT Linux,
[Arch Linux](https://www.archlinux.org/packages/?q=toxcore),
[Fedora](https://apps.fedoraproject.org/packages/toxcore), Mageia, openSUSE,
PCLinuxOS, ROSA and Slackware,
[according to the information from pkgs.org](https://pkgs.org/download/toxcore).
Note that this list might be incomplete and some other distributions might
package it too.

View File

@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
@ -664,12 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.

205
README.md
View File

@ -1,4 +1,205 @@
# Tomato
# ![Project Tox](https://raw.github.com/TokTok/c-toxcore/master/other/tox.png "Project Tox")
![tomato](res/icon/tomato_v1_256.png)
**Current Coverage:**
[![coverage](https://codecov.io/gh/TokTok/c-toxcore/branch/master/graph/badge.svg?token=BRfCKo02De)](https://codecov.io/gh/TokTok/c-toxcore)
[**Website**](https://tox.chat) **|** [**Wiki**](https://wiki.tox.chat/) **|**
[**Blog**](https://blog.tox.chat/) **|**
[**FAQ**](https://wiki.tox.chat/doku.php?id=users:faq) **|**
[**Binaries/Downloads**](https://tox.chat/download.html) **|**
[**Clients**](https://wiki.tox.chat/doku.php?id=clients) **|**
[**Compiling**](/INSTALL.md)
## What is Tox
Tox is a peer to peer (serverless) instant messenger aimed at making security
and privacy easy to obtain for regular users. It uses
[libsodium](https://doc.libsodium.org/) (based on
[NaCl](https://nacl.cr.yp.to/)) for its encryption and authentication.
## IMPORTANT!
### ![Danger: Experimental](other/tox-warning.png)
This is an **experimental** cryptographic network library. It has not been
formally audited by an independent third party that specializes in cryptography
or cryptanalysis. **Use this library at your own risk.**
The underlying crypto library [libsodium](https://doc.libsodium.org/) provides
reliable encryption, but the security model has not yet been fully specified.
See [issue 210](https://github.com/TokTok/c-toxcore/issues/210) for a discussion
on developing a threat model. See other issues for known weaknesses (e.g.
[issue 426](https://github.com/TokTok/c-toxcore/issues/426) describes what can
happen if your secret key is stolen).
## Toxcore Development Roadmap
The roadmap and changelog are generated from GitHub issues. You may view them on
the website, where they are updated at least once every 24 hours:
- Changelog: https://toktok.ltd/changelog/c-toxcore
- Roadmap: https://toktok.ltd/roadmap/c-toxcore
## Installing toxcore
Detailed installation instructions can be found in [INSTALL.md](INSTALL.md).
Be advised that due to the addition of `cmp` as a submodule, you now also need
to initialize the git submodules required by toxcore. This can be done by
cloning the repo with the following command:
`git clone --recurse-submodules https://github.com/Toktok/c-toxcore` or by
running `git submodule update --init` in the root directory of the repo.
In a nutshell, if you have [libsodium](https://github.com/jedisct1/libsodium)
installed, run:
```sh
mkdir _build && cd _build
cmake ..
make
sudo make install
```
If you have [libvpx](https://github.com/webmproject/libvpx) and
[opus](https://github.com/xiph/opus) installed, the above will also build the
A/V library for multimedia chats.
## Using toxcore
The simplest "hello world" example could be an echo bot. Here we will walk
through the implementation of a simple bot.
### Creating the tox instance
All toxcore API functions work with error parameters. They are enums with one
`OK` value and several error codes that describe the different situations in
which the function might fail.
```c
TOX_ERR_NEW err_new;
Tox *tox = tox_new(NULL, &err_new);
if (err_new != TOX_ERR_NEW_OK) {
fprintf(stderr, "tox_new failed with error code %d\n", err_new);
exit(1);
}
```
Here, we simply exit the program, but in a real client you will probably want to
do some error handling and proper error reporting to the user. The `NULL`
argument given to the first parameter of `tox_new` is the `Tox_Options`. It
contains various write-once network settings and allows you to load a previously
serialised instance. See [toxcore/tox.h](tox.h) for details.
### Setting up callbacks
Toxcore works with callbacks that you can register to listen for certain events.
Examples of such events are "friend request received" or "friend sent a
message". Search the API for `tox_callback_*` to find all of them.
Here, we will set up callbacks for receiving friend requests and receiving
messages. We will always accept any friend request (because we're a bot), and
when we receive a message, we send it back to the sender.
```c
tox_callback_friend_request(tox, handle_friend_request);
tox_callback_friend_message(tox, handle_friend_message);
```
These two function calls set up the callbacks. Now we also need to implement
these "handle" functions.
### Handle friend requests
```c
static void handle_friend_request(
Tox *tox, const uint8_t *public_key, const uint8_t *message, size_t length,
void *user_data) {
// Accept the friend request:
TOX_ERR_FRIEND_ADD err_friend_add;
tox_friend_add_norequest(tox, public_key, &err_friend_add);
if (err_friend_add != TOX_ERR_FRIEND_ADD_OK) {
fprintf(stderr, "unable to add friend: %d\n", err_friend_add);
}
}
```
The `tox_friend_add_norequest` function adds the friend without sending them a
friend request. Since we already got a friend request, this is the right thing
to do. If you wanted to send a friend request yourself, you would use
`tox_friend_add`, which has an extra parameter for the message.
### Handle messages
Now, when the friend sends us a message, we want to respond to them by sending
them the same message back. This will be our "echo".
```c
static void handle_friend_message(
Tox *tox, uint32_t friend_number, TOX_MESSAGE_TYPE type,
const uint8_t *message, size_t length,
void *user_data) {
TOX_ERR_FRIEND_SEND_MESSAGE err_send;
tox_friend_send_message(tox, friend_number, type, message, length,
&err_send);
if (err_send != TOX_ERR_FRIEND_SEND_MESSAGE_OK) {
fprintf(stderr, "unable to send message back to friend %d: %d\n",
friend_number, err_send);
}
}
```
That's it for the setup. Now we want to actually run the bot.
### Main event loop
Toxcore works with a main event loop function `tox_iterate` that you need to
call at a certain frequency dictated by `tox_iteration_interval`. This is a
polling function that receives new network messages and processes them.
```c
while (true) {
usleep(1000 * tox_iteration_interval(tox));
tox_iterate(tox, NULL);
}
```
That's it! Now you have a working echo bot. The only problem is that since Tox
works with public keys, and you can't really guess your bot's public key, you
can't add it as a friend in your client. For this, we need to call another API
function: `tox_self_get_address(tox, address)`. This will fill the 38 byte
friend address into the `address` buffer. You can then display that binary
string as hex and input it into your client. Writing a `bin2hex` function is
left as exercise for the reader.
We glossed over a lot of details, such as the user data which we passed to
`tox_iterate` (passing `NULL`), bootstrapping into an actual network (this bot
will work in the LAN, but not on an internet server) and the fact that we now
have no clean way of stopping the bot (`while (true)`). If you want to write a
real bot, you will probably want to read up on all the API functions. Consult
the API documentation in [toxcore/tox.h](toxcore/tox.h) for more information.
### Other resources
- [Another echo bot](https://wiki.tox.chat/developers/client_examples/echo_bot)
- [minitox](https://github.com/hqwrong/minitox) (A minimal tox client)
## SAST Tools
This project uses various tools supporting Static Application Security Testing:
- [clang-tidy](https://clang.llvm.org/extra/clang-tidy/): A clang-based C++
"linter" tool.
- [Coverity](https://scan.coverity.com/): A cloud-based static analyzer service
for Java, C/C++, C#, JavaScript, Ruby, or Python that is free for open source
projects.
- [cppcheck](https://cppcheck.sourceforge.io/): A static analyzer for C/C++
code.
- [cpplint](https://github.com/cpplint/cpplint): Static code checker for C++
- [goblint](https://goblint.in.tum.de/): A static analyzer for multi-threaded C
programs, specializing in finding concurrency bugs.
- [infer](https://github.com/facebook/infer): A static analyzer for Java, C,
C++, and Objective-C.
- [PVS-Studio](https://pvs-studio.com/en/pvs-studio/?utm_source=website&utm_medium=github&utm_campaign=open_source):
A static analyzer for C, C++, C#, and Java code.
- [tokstyle](https://github.com/TokTok/hs-tokstyle): A style checker for TokTok
C projects.

View File

@ -1,7 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
package(features = ["layering_check"])
cc_library(
name = "check_compat",
testonly = True,
@ -19,6 +17,8 @@ cc_library(
"//c-toxcore/toxcore:Messenger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:tox",
"//c-toxcore/toxcore:tox_dispatch",
"//c-toxcore/toxcore:tox_events",
],
)

119
auto_tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,119 @@
set(TEST_TIMEOUT_SECONDS "" CACHE STRING "Limit runtime of each test to the number of seconds specified")
add_library(auto_test_support
auto_test_support.c
auto_test_support.h)
target_link_libraries(auto_test_support PRIVATE misc_tools)
if(TARGET toxcore_static)
target_link_libraries(auto_test_support PRIVATE toxcore_static)
else()
target_link_libraries(auto_test_support PRIVATE toxcore_shared)
endif()
if(TARGET PThreads4W::PThreads4W)
target_link_libraries(auto_test_support PRIVATE PThreads4W::PThreads4W)
elseif(TARGET Threads::Threads)
target_link_libraries(auto_test_support PRIVATE Threads::Threads)
endif()
function(auto_test target)
add_executable(auto_${target}_test ${target}_test.c)
target_link_libraries(auto_${target}_test PRIVATE misc_tools auto_test_support)
if(TARGET toxcore_static)
target_link_libraries(auto_${target}_test PRIVATE toxcore_static)
else()
target_link_libraries(auto_${target}_test PRIVATE toxcore_shared)
endif()
if(TARGET PThreads4W::PThreads4W)
target_link_libraries(auto_${target}_test PRIVATE PThreads4W::PThreads4W)
elseif(TARGET Threads::Threads)
target_link_libraries(auto_${target}_test PRIVATE Threads::Threads)
endif()
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test)
set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
# add the source dir as environment variable, so the testdata can be found
set_tests_properties(${target} PROPERTIES ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw;srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
endfunction()
auto_test(TCP)
auto_test(announce)
auto_test(conference)
auto_test(conference_double_invite)
auto_test(conference_invite_merge)
auto_test(conference_peer_nick)
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(encryptsave)
auto_test(file_saving)
auto_test(file_streaming)
auto_test(file_transfer)
auto_test(forwarding)
auto_test(friend_connection)
auto_test(friend_request)
auto_test(friend_request_spam)
auto_test(group_general)
auto_test(group_invite)
auto_test(group_message)
auto_test(group_moderation)
auto_test(group_save)
auto_test(group_state)
auto_test(group_sync)
auto_test(group_tcp)
auto_test(group_topic)
auto_test(invalid_tcp_proxy)
auto_test(invalid_udp_proxy)
auto_test(lan_discovery)
auto_test(lossless_packet)
auto_test(lossy_packet)
auto_test(network)
auto_test(onion)
auto_test(overflow_recvq)
auto_test(overflow_sendq)
auto_test(reconnect)
auto_test(save_friend)
auto_test(save_load)
auto_test(send_message)
auto_test(set_name)
auto_test(set_status_message)
auto_test(tox_dispatch)
auto_test(tox_events)
auto_test(tox_many)
auto_test(tox_many_tcp)
auto_test(tox_strncasecmp)
auto_test(typing)
auto_test(version)
auto_test(save_compatibility)
target_include_directories(auto_encryptsave_test SYSTEM PRIVATE ${LIBSODIUM_INCLUDE_DIRS})
if(NON_HERMETIC_TESTS)
auto_test(bootstrap)
auto_test(tcp_relay)
endif()
if(BUILD_TOXAV)
auto_test(conference_av)
auto_test(toxav_basic)
auto_test(toxav_many)
if(MSVC)
target_link_libraries(auto_toxav_basic_test PRIVATE PkgConfig::VPX)
target_link_libraries(auto_toxav_many_test PRIVATE PkgConfig::VPX)
else()
target_link_libraries(auto_toxav_basic_test PRIVATE ${VPX_LIBRARIES})
target_link_directories(auto_toxav_basic_test PRIVATE ${VPX_LIBRARY_DIRS})
target_include_directories(auto_toxav_basic_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS})
target_compile_options(auto_toxav_basic_test PRIVATE ${VPX_CFLAGS_OTHER})
target_link_libraries(auto_toxav_many_test PRIVATE ${VPX_LIBRARIES})
target_link_directories(auto_toxav_many_test PRIVATE ${VPX_LIBRARY_DIRS})
target_include_directories(auto_toxav_many_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS})
target_compile_options(auto_toxav_many_test PRIVATE ${VPX_CFLAGS_OTHER})
endif()
endif()
if(PROXY_TEST)
auto_test(proxy)
endif()

View File

@ -13,6 +13,9 @@ TESTS = \
conference_test \
conference_two_test \
crypto_test \
encryptsave_test \
file_saving_test \
file_streaming_test \
file_transfer_test \
forwarding_test \
friend_connection_test \
@ -34,34 +37,24 @@ TESTS = \
set_name_test \
set_status_message_test \
TCP_test \
tox_events_test \
tox_dispatch_test \
tox_events_test \
tox_many_tcp_test \
tox_many_test \
tox_strncasecmp_test \
typing_test \
version_test
if !WITH_NACL
TESTS += \
encryptsave_test \
file_saving_test
endif
AUTOTEST_CFLAGS = \
$(LIBSODIUM_CFLAGS) \
$(NACL_CFLAGS)
$(LIBSODIUM_CFLAGS)
AUTOTEST_LDADD = \
$(LIBSODIUM_LDFLAGS) \
$(NACL_LDFLAGS) \
libmisc_tools.la \
libauto_test_support.la \
libtoxcore.la \
libtoxencryptsave.la \
$(LIBSODIUM_LIBS) \
$(NACL_OBJECTS) \
$(NACL_LIBS)
$(LIBSODIUM_LIBS)
if BUILD_AV
@ -111,6 +104,10 @@ file_saving_test_SOURCES = ../auto_tests/file_saving_test.c
file_saving_test_CFLAGS = $(AUTOTEST_CFLAGS)
file_saving_test_LDADD = $(AUTOTEST_LDADD)
file_streaming_test_SOURCES = ../auto_tests/file_streaming_test.c
file_streaming_test_CFLAGS = $(AUTOTEST_CFLAGS)
file_streaming_test_LDADD = $(AUTOTEST_LDADD)
file_transfer_test_SOURCES = ../auto_tests/file_transfer_test.c
file_transfer_test_CFLAGS = $(AUTOTEST_CFLAGS)
file_transfer_test_LDADD = $(AUTOTEST_LDADD)
@ -195,14 +192,14 @@ TCP_test_SOURCES = ../auto_tests/TCP_test.c
TCP_test_CFLAGS = $(AUTOTEST_CFLAGS)
TCP_test_LDADD = $(AUTOTEST_LDADD)
tox_events_test_SOURCES = ../auto_tests/tox_events_test.c
tox_events_test_CFLAGS = $(AUTOTEST_CFLAGS)
tox_events_test_LDADD = $(AUTOTEST_LDADD)
tox_dispatch_test_SOURCES = ../auto_tests/tox_dispatch_test.c
tox_dispatch_test_CFLAGS = $(AUTOTEST_CFLAGS)
tox_dispatch_test_LDADD = $(AUTOTEST_LDADD)
tox_events_test_SOURCES = ../auto_tests/tox_events_test.c
tox_events_test_CFLAGS = $(AUTOTEST_CFLAGS)
tox_events_test_LDADD = $(AUTOTEST_LDADD)
tox_many_tcp_test_SOURCES = ../auto_tests/tox_many_tcp_test.c
tox_many_tcp_test_CFLAGS = $(AUTOTEST_CFLAGS)
tox_many_tcp_test_LDADD = $(AUTOTEST_LDADD)
@ -243,6 +240,7 @@ endif
EXTRA_DIST += \
$(top_srcdir)/auto_tests/data/save.tox \
$(top_srcdir)/auto_tests/data/save.tox.big \
$(top_srcdir)/auto_tests/data/save.tox.little \
$(top_srcdir)/auto_tests/check_compat.h \
$(top_srcdir)/auto_tests/auto_test_support.h

View File

@ -45,11 +45,11 @@ static uint16_t ports[NUM_PORTS] = {13215, 33445, 25643};
static void test_basic(void)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
const Network *ns = system_network();
const Network *ns = os_network();
ck_assert(ns != nullptr);
const Memory *mem = system_memory();
const Memory *mem = os_memory();
ck_assert(mem != nullptr);
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
@ -266,13 +266,14 @@ static void kill_tcp_con(struct sec_TCP_con *con)
static int write_packet_tcp_test_connection(const Logger *logger, struct sec_TCP_con *con, const uint8_t *data,
uint16_t length)
{
VLA(uint8_t, packet, sizeof(uint16_t) + length + CRYPTO_MAC_SIZE);
const uint16_t packet_size = sizeof(uint16_t) + length + CRYPTO_MAC_SIZE;
VLA(uint8_t, packet, packet_size);
uint16_t c_length = net_htons(length + CRYPTO_MAC_SIZE);
memcpy(packet, &c_length, sizeof(uint16_t));
int len = encrypt_data_symmetric(con->shared_key, con->sent_nonce, data, length, packet + sizeof(uint16_t));
if ((unsigned int)len != (SIZEOF_VLA(packet) - sizeof(uint16_t))) {
if ((unsigned int)len != (packet_size - sizeof(uint16_t))) {
return -1;
}
@ -282,7 +283,7 @@ static int write_packet_tcp_test_connection(const Logger *logger, struct sec_TCP
localhost.ip = get_loopback();
localhost.port = 0;
ck_assert_msg(net_send(con->ns, logger, con->sock, packet, SIZEOF_VLA(packet), &localhost) == SIZEOF_VLA(packet),
ck_assert_msg(net_send(con->ns, logger, con->sock, packet, packet_size, &localhost) == packet_size,
"Failed to send a packet.");
return 0;
}
@ -303,11 +304,11 @@ static int read_packet_sec_tcp(const Logger *logger, struct sec_TCP_con *con, ui
static void test_some(void)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
const Network *ns = system_network();
const Network *ns = os_network();
ck_assert(ns != nullptr);
const Memory *mem = system_memory();
const Memory *mem = os_memory();
ck_assert(mem != nullptr);
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
@ -498,11 +499,11 @@ static int oob_data_callback(void *object, const uint8_t *public_key, const uint
static void test_client(void)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
const Network *ns = system_network();
const Network *ns = os_network();
ck_assert(ns != nullptr);
const Memory *mem = system_memory();
const Memory *mem = os_memory();
ck_assert(mem != nullptr);
Logger *logger = logger_new();
@ -524,8 +525,9 @@ static void test_client(void)
ip_port_tcp_s.ip = get_loopback();
TCP_Client_Connection *conn = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr);
do_tcp_connection(logger, mono_time, conn, nullptr);
// TCP sockets might need a moment before they can be written to.
c_sleep(50);
do_tcp_connection(logger, mono_time, conn, nullptr);
// The connection status should be unconfirmed here because we have finished
// sending our data and are awaiting a response.
@ -559,6 +561,7 @@ static void test_client(void)
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
TCP_Client_Connection *conn2 = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f2_public_key,
f2_secret_key, nullptr);
c_sleep(50);
// The client should call this function (defined earlier) during the routing process.
routing_response_handler(conn, response_callback, (char *)conn + 2);
@ -581,7 +584,7 @@ static void test_client(void)
do_tcp_connection(logger, mono_time, conn2, nullptr);
c_sleep(50);
uint8_t data[5] = {1, 2, 3, 4, 5};
const uint8_t data[5] = {1, 2, 3, 4, 5};
memcpy(oob_pubkey, f2_public_key, CRYPTO_PUBLIC_KEY_SIZE);
send_oob_packet(logger, conn2, f_public_key, data, 5);
send_routing_request(logger, conn, f2_public_key);
@ -632,11 +635,11 @@ static void test_client(void)
// Test how the client handles servers that don't respond.
static void test_client_invalid(void)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
const Network *ns = system_network();
const Network *ns = os_network();
ck_assert(ns != nullptr);
const Memory *mem = system_memory();
const Memory *mem = os_memory();
ck_assert(mem != nullptr);
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
@ -708,14 +711,13 @@ static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t
return 0;
}
static void test_tcp_connection(void)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
const Network *ns = system_network();
const Network *ns = os_network();
ck_assert(ns != nullptr);
const Memory *mem = system_memory();
const Memory *mem = os_memory();
ck_assert(mem != nullptr);
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
@ -824,11 +826,11 @@ static int tcp_oobdata_callback(void *object, const uint8_t *public_key, unsigne
static void test_tcp_connection2(void)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
const Network *ns = system_network();
const Network *ns = os_network();
ck_assert(ns != nullptr);
const Memory *mem = system_memory();
const Memory *mem = os_memory();
ck_assert(mem != nullptr);
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);

View File

@ -13,7 +13,7 @@
static void test_bucketnum(void)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
uint8_t key1[CRYPTO_PUBLIC_KEY_SIZE], key2[CRYPTO_PUBLIC_KEY_SIZE];
random_bytes(rng, key1, sizeof(key1));
@ -50,20 +50,24 @@ static void test_announce_data(void *object, const uint8_t *data, uint16_t lengt
static void test_store_data(void)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
const Network *ns = system_network();
const Network *ns = os_network();
ck_assert(ns != nullptr);
const Memory *mem = system_memory();
const Memory *mem = os_memory();
ck_assert(mem != nullptr);
Logger *log = logger_new();
ck_assert(log != nullptr);
logger_callback_log(log, print_debug_logger, nullptr, nullptr);
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
ck_assert(mono_time != nullptr);
Networking_Core *net = new_networking_no_udp(log, mem, ns);
ck_assert(net != nullptr);
DHT *dht = new_dht(log, mem, rng, ns, mono_time, net, true, true);
ck_assert(dht != nullptr);
Forwarding *forwarding = new_forwarding(log, rng, mono_time, dht);
ck_assert(forwarding != nullptr);
Announcements *announce = new_announcements(log, mem, rng, mono_time, forwarding);
ck_assert(announce != nullptr);
@ -116,7 +120,6 @@ static void basic_announce_tests(void)
test_store_data();
}
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);

View File

@ -5,6 +5,8 @@
#include "../testing/misc_tools.h"
#include "../toxcore/Messenger.h"
#include "../toxcore/mono_time.h"
#include "../toxcore/tox_dispatch.h"
#include "../toxcore/tox_events.h"
#include "../toxcore/tox_struct.h"
#include "auto_test_support.h"
@ -13,12 +15,17 @@
#define ABORT_ON_LOG_ERROR true
#endif
#ifndef USE_IPV6
#define USE_IPV6 1
#endif
Run_Auto_Options default_run_auto_options(void)
{
return (Run_Auto_Options) {
.graph = GRAPH_COMPLETE,
.init_autotox = nullptr,
.tcp_port = 33188,
.events = true,
};
}
@ -28,7 +35,6 @@ static const struct BootstrapNodes {
uint16_t port;
const uint8_t key[32];
} bootstrap_nodes[] = {
#ifndef USE_TEST_NETWORK
{
"tox.abilinski.com", 33445,
0x10, 0xC0, 0x0E, 0xB2, 0x50, 0xC3, 0x23, 0x3E,
@ -57,22 +63,6 @@ static const struct BootstrapNodes {
0x6D, 0xC9, 0xD0, 0xA3, 0x00, 0xE6, 0xC3, 0x57,
0x63, 0x4E, 0xE2, 0xDA, 0x88, 0xC3, 0x54, 0x63,
},
#else
{
"172.93.52.70", 33445,
0x79, 0xCA, 0xDA, 0x49, 0x74, 0xB0, 0x92, 0x6F,
0x28, 0x6F, 0x02, 0x5C, 0xD5, 0xFF, 0xDF, 0x3E,
0x65, 0x4A, 0x37, 0x58, 0xC5, 0x3E, 0x02, 0x73,
0xEC, 0xFC, 0x4D, 0x12, 0xC2, 0x1D, 0xCA, 0x48,
},
{
"tox.plastiras.org", 38445,
0x5E, 0x47, 0xBA, 0x1D, 0xC3, 0x91, 0x3E, 0xB2,
0xCB, 0xF2, 0xD6, 0x4C, 0xE4, 0xF2, 0x3D, 0x8B,
0xFE, 0x53, 0x91, 0xBF, 0xAB, 0xE5, 0xC4, 0x3C,
0x5B, 0xAD, 0x13, 0xF0, 0xA4, 0x14, 0xCD, 0x77,
},
#endif // USE_TEST_NETWORK
{ nullptr, 0, 0 },
};
@ -144,7 +134,15 @@ void iterate_all_wait(AutoTox *autotoxes, uint32_t tox_count, uint32_t wait)
for (uint32_t i = 0; i < tox_count; ++i) {
if (autotoxes[i].alive) {
if (autotoxes[i].events) {
Tox_Err_Events_Iterate err;
Tox_Events *events = tox_events_iterate(autotoxes[i].tox, true, &err);
ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK);
tox_dispatch_invoke(autotoxes[i].dispatch, events, &autotoxes[i]);
tox_events_free(events);
} else {
tox_iterate(autotoxes[i].tox, &autotoxes[i]);
}
autotoxes[i].clock += wait;
}
}
@ -166,6 +164,8 @@ void set_mono_time_callback(AutoTox *autotox)
Mono_Time *mono_time = autotox->tox->mono_time;
autotox->clock = current_time_monotonic(mono_time);
ck_assert_msg(autotox->clock >= 1000,
"clock is too low (not initialised?): %lu", (unsigned long)autotox->clock);
mono_time_set_current_time_callback(mono_time, nullptr, nullptr); // set to default first
mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &autotox->clock);
}
@ -192,6 +192,7 @@ void kill_autotox(AutoTox *autotox)
ck_assert(autotox->alive);
fprintf(stderr, "Killing #%u\n", autotox->index);
autotox->alive = false;
tox_dispatch_free(autotox->dispatch);
tox_kill(autotox->tox);
}
@ -208,10 +209,16 @@ void reload(AutoTox *autotox)
struct Tox_Options *const options = tox_options_new(nullptr);
ck_assert(options != nullptr);
tox_options_set_ipv6_enabled(options, USE_IPV6);
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
tox_options_set_savedata_data(options, autotox->save_state, autotox->save_size);
autotox->tox = tox_new_log(options, nullptr, &autotox->index);
ck_assert(autotox->tox != nullptr);
autotox->dispatch = tox_dispatch_new(nullptr);
ck_assert(autotox->dispatch != nullptr);
if (autotox->events) {
tox_events_init(autotox->tox);
}
tox_options_free(options);
set_mono_time_callback(autotox);
@ -222,6 +229,7 @@ static void initialise_autotox(struct Tox_Options *options, AutoTox *autotox, ui
Run_Auto_Options *autotest_opts)
{
autotox->index = index;
autotox->events = autotest_opts->events;
Tox_Err_New err = TOX_ERR_NEW_OK;
@ -229,6 +237,8 @@ static void initialise_autotox(struct Tox_Options *options, AutoTox *autotox, ui
struct Tox_Options *default_opts = tox_options_new(nullptr);
ck_assert(default_opts != nullptr);
tox_options_set_ipv6_enabled(default_opts, USE_IPV6);
if (options == nullptr) {
options = default_opts;
}
@ -267,6 +277,12 @@ static void initialise_autotox(struct Tox_Options *options, AutoTox *autotox, ui
set_mono_time_callback(autotox);
autotox->dispatch = tox_dispatch_new(nullptr);
ck_assert(autotox->dispatch != nullptr);
if (autotox->events) {
tox_events_init(autotox->tox);
}
autotox->alive = true;
autotox->save_state = nullptr;
@ -319,7 +335,7 @@ static void initialise_friend_graph(Graph_Type graph, uint32_t num_toxes, AutoTo
}
}
static void bootstrap_autotoxes(struct Tox_Options *options, uint32_t tox_count, const Run_Auto_Options *autotest_opts,
static void bootstrap_autotoxes(const Tox_Options *options, uint32_t tox_count, const Run_Auto_Options *autotest_opts,
AutoTox *autotoxes)
{
const bool udp_enabled = options != nullptr ? tox_options_get_udp_enabled(options) : true;
@ -332,7 +348,7 @@ static void bootstrap_autotoxes(struct Tox_Options *options, uint32_t tox_count,
for (uint32_t i = 1; i < tox_count; ++i) {
Tox_Err_Bootstrap err;
tox_bootstrap(autotoxes[i].tox, "localhost", dht_port, dht_key, &err);
ck_assert(err == TOX_ERR_BOOTSTRAP_OK);
ck_assert_msg(err == TOX_ERR_BOOTSTRAP_OK, "bootstrap error for port %d: %d", dht_port, err);
}
if (!udp_enabled) {
@ -347,7 +363,9 @@ static void bootstrap_autotoxes(struct Tox_Options *options, uint32_t tox_count,
}
}
void run_auto_test(struct Tox_Options *options, uint32_t tox_count, void test(AutoTox *autotoxes),
typedef void autotox_test_cb(AutoTox *autotoxes);
void run_auto_test(struct Tox_Options *options, uint32_t tox_count, autotox_test_cb *test,
uint32_t state_size, Run_Auto_Options *autotest_opts)
{
printf("initialising %u toxes\n", tox_count);
@ -379,6 +397,7 @@ void run_auto_test(struct Tox_Options *options, uint32_t tox_count, void test(Au
test(autotoxes);
for (uint32_t i = 0; i < tox_count; ++i) {
tox_dispatch_free(autotoxes[i].dispatch);
tox_kill(autotoxes[i].tox);
free(autotoxes[i].state);
free(autotoxes[i].save_state);
@ -425,7 +444,6 @@ void print_debug_log(Tox *m, Tox_Log_Level level, const char *file, uint32_t lin
}
}
void print_debug_logger(void *context, Logger_Level level, const char *file, int line, const char *func, const char *message, void *userdata)
{
print_debug_log(nullptr, (Tox_Log_Level) level, file, (uint32_t) line, func, message, userdata);
@ -441,6 +459,7 @@ Tox *tox_new_log_lan(struct Tox_Options *options, Tox_Err_New *err, void *log_us
assert(log_options != nullptr);
tox_options_set_ipv6_enabled(log_options, USE_IPV6);
tox_options_set_local_discovery_enabled(log_options, lan_discovery);
// Use a higher start port for non-LAN-discovery tests so it's more likely for the LAN discovery
// test to get the default port 33445.
@ -462,4 +481,3 @@ Tox *tox_new_log(struct Tox_Options *options, Tox_Err_New *err, void *log_user_d
{
return tox_new_log_lan(options, err, log_user_data, false);
}

View File

@ -7,9 +7,11 @@
#include "../testing/misc_tools.h"
#include "../toxcore/Messenger.h"
#include "../toxcore/mono_time.h"
#include "../toxcore/tox_dispatch.h"
typedef struct AutoTox {
Tox *tox;
Tox_Dispatch *dispatch;
uint32_t index;
uint64_t clock;
@ -17,6 +19,7 @@ typedef struct AutoTox {
size_t save_size;
uint8_t *save_state;
bool alive;
bool events;
void *state;
} AutoTox;
@ -42,6 +45,7 @@ typedef struct Run_Auto_Options {
Graph_Type graph;
void (*init_autotox)(AutoTox *autotox, uint32_t n);
uint16_t tcp_port;
bool events;
} Run_Auto_Options;
Run_Auto_Options default_run_auto_options(void);

View File

@ -9,7 +9,7 @@
#define ck_assert(ok) do { \
if (!(ok)) { \
fprintf(stderr, "%s:%d: failed `%s'\n", __FILE__, __LINE__, #ok); \
abort(); \
exit(7); \
} \
} while (0)
@ -18,7 +18,7 @@
fprintf(stderr, "%s:%d: failed `%s': ", __FILE__, __LINE__, #ok); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
abort(); \
exit(7); \
} \
} while (0)
@ -26,7 +26,7 @@
fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
abort(); \
exit(7); \
} while (0)
#endif // C_TOXCORE_AUTO_TESTS_CHECK_COMPAT_H

View File

@ -23,10 +23,11 @@ typedef struct State {
} State;
static void handle_self_connection_status(
Tox *tox, Tox_Connection connection_status, void *user_data)
const Tox_Event_Self_Connection_Status *event, void *user_data)
{
const AutoTox *autotox = (AutoTox *)user_data;
const Tox_Connection connection_status = tox_event_self_connection_status_get_connection_status(event);
if (connection_status != TOX_CONNECTION_NONE) {
printf("tox #%u: is now connected\n", autotox->index);
} else {
@ -35,10 +36,13 @@ static void handle_self_connection_status(
}
static void handle_friend_connection_status(
Tox *tox, uint32_t friendnumber, Tox_Connection connection_status, void *user_data)
const Tox_Event_Friend_Connection_Status *event, void *user_data)
{
const AutoTox *autotox = (AutoTox *)user_data;
const uint32_t friendnumber = tox_event_friend_connection_status_get_friend_number(event);
const Tox_Connection connection_status = tox_event_friend_connection_status_get_connection_status(event);
if (connection_status != TOX_CONNECTION_NONE) {
printf("tox #%u: is now connected to friend %u\n", autotox->index, friendnumber);
} else {
@ -70,28 +74,33 @@ static void audio_callback(void *tox, uint32_t groupnumber, uint32_t peernumber,
}
static void handle_conference_invite(
Tox *tox, uint32_t friendnumber, Tox_Conference_Type type,
const uint8_t *data, size_t length, void *user_data)
const Tox_Event_Conference_Invite *event, void *user_data)
{
const AutoTox *autotox = (AutoTox *)user_data;
const uint32_t friend_number = tox_event_conference_invite_get_friend_number(event);
const Tox_Conference_Type type = tox_event_conference_invite_get_type(event);
const uint8_t *cookie = tox_event_conference_invite_get_cookie(event);
const size_t length = tox_event_conference_invite_get_cookie_length(event);
ck_assert_msg(type == TOX_CONFERENCE_TYPE_AV, "tox #%u: wrong conference type: %d", autotox->index, type);
ck_assert_msg(toxav_join_av_groupchat(tox, friendnumber, data, length, audio_callback, user_data) == 0,
ck_assert_msg(toxav_join_av_groupchat(autotox->tox, friend_number, cookie, length, audio_callback, user_data) == 0,
"tox #%u: failed to join group", autotox->index);
}
static void handle_conference_connected(
Tox *tox, uint32_t conference_number, void *user_data)
const Tox_Event_Conference_Connected *event, void *user_data)
{
const AutoTox *autotox = (AutoTox *)user_data;
State *state = (State *)autotox->state;
if (state->invited_next || tox_self_get_friend_list_size(tox) <= 1) {
if (state->invited_next || tox_self_get_friend_list_size(autotox->tox) <= 1) {
return;
}
Tox_Err_Conference_Invite err;
tox_conference_invite(tox, 1, 0, &err);
tox_conference_invite(autotox->tox, 1, 0, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox #%u failed to invite next friend: err = %d", autotox->index,
err);
printf("tox #%u: invited next friend\n", autotox->index);
@ -99,7 +108,7 @@ static void handle_conference_connected(
}
static bool toxes_are_disconnected_from_group(uint32_t tox_count, AutoTox *autotoxes,
bool *disconnected)
const bool *disconnected)
{
uint32_t num_disconnected = 0;
@ -138,7 +147,10 @@ static void disconnect_toxes(uint32_t tox_count, AutoTox *autotoxes,
do {
for (uint32_t i = 0; i < tox_count; ++i) {
if (!disconnect_now[i]) {
tox_iterate(autotoxes[i].tox, &autotoxes[i]);
Tox_Err_Events_Iterate err;
Tox_Events *events = tox_events_iterate(autotoxes[i].tox, true, &err);
tox_dispatch_invoke(autotoxes[i].dispatch, events, &autotoxes[i]);
tox_events_free(events);
autotoxes[i].clock += 1000;
}
}
@ -165,7 +177,7 @@ static bool all_connected_to_group(uint32_t tox_count, AutoTox *autotoxes)
* returns a random index at which a list of booleans is false
* (some such index is required to exist)
*/
static uint32_t random_false_index(const Random *rng, bool *list, const uint32_t length)
static uint32_t random_false_index(const Random *rng, const bool *list, const uint32_t length)
{
uint32_t index;
@ -185,7 +197,7 @@ static bool all_got_audio(AutoTox *autotoxes, const bool *disabled)
}
for (uint32_t i = 0; i < NUM_AV_GROUP_TOX; ++i) {
State *state = (State *)autotoxes[i].state;
const State *state = (const State *)autotoxes[i].state;
if (disabled[i] ^ (state->received_audio_num
!= NUM_AV_GROUP_TOX - num_disabled - 1)) {
@ -291,7 +303,7 @@ static void do_audio(AutoTox *autotoxes, uint32_t iterations)
static void run_conference_tests(AutoTox *autotoxes)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
bool disabled[NUM_AV_GROUP_TOX] = {0};
@ -402,10 +414,10 @@ static void test_groupav(AutoTox *autotoxes)
const time_t test_start_time = time(nullptr);
for (uint32_t i = 0; i < NUM_AV_GROUP_TOX; ++i) {
tox_callback_self_connection_status(autotoxes[i].tox, &handle_self_connection_status);
tox_callback_friend_connection_status(autotoxes[i].tox, &handle_friend_connection_status);
tox_callback_conference_invite(autotoxes[i].tox, &handle_conference_invite);
tox_callback_conference_connected(autotoxes[i].tox, &handle_conference_connected);
tox_events_callback_self_connection_status(autotoxes[i].dispatch, handle_self_connection_status);
tox_events_callback_friend_connection_status(autotoxes[i].dispatch, handle_friend_connection_status);
tox_events_callback_conference_invite(autotoxes[i].dispatch, handle_conference_invite);
tox_events_callback_conference_connected(autotoxes[i].dispatch, handle_conference_connected);
}
ck_assert_msg(toxav_add_av_groupchat(autotoxes[0].tox, audio_callback, &autotoxes[0]) != UINT32_MAX,
@ -414,7 +426,6 @@ static void test_groupav(AutoTox *autotoxes)
ck_assert_msg(tox_conference_invite(autotoxes[0].tox, 0, 0, nullptr) != 0, "failed to invite friend");
((State *)autotoxes[0].state)->invited_next = true;
printf("waiting for invitations to be made\n");
uint32_t invited_count = 0;

View File

@ -12,12 +12,16 @@ typedef struct State {
#include "auto_test_support.h"
static void handle_conference_invite(
Tox *tox, uint32_t friend_number, Tox_Conference_Type type,
const uint8_t *cookie, size_t length, void *user_data)
const Tox_Event_Conference_Invite *event, void *user_data)
{
const AutoTox *autotox = (AutoTox *)user_data;
State *state = (State *)autotox->state;
const uint32_t friend_number = tox_event_conference_invite_get_friend_number(event);
const Tox_Conference_Type type = tox_event_conference_invite_get_type(event);
const uint8_t *cookie = tox_event_conference_invite_get_cookie(event);
const size_t length = tox_event_conference_invite_get_cookie_length(event);
fprintf(stderr, "handle_conference_invite(#%u, %u, %d, uint8_t[%u], _)\n",
autotox->index, friend_number, type, (unsigned)length);
fprintf(stderr, "tox%u joining conference\n", autotox->index);
@ -26,7 +30,7 @@ static void handle_conference_invite(
if (friend_number != -1) {
Tox_Err_Conference_Join err;
state->conference = tox_conference_join(tox, friend_number, cookie, length, &err);
state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK,
"attempting to join the conference returned with an error: %d", err);
fprintf(stderr, "tox%u joined conference %u\n", autotox->index, state->conference);
@ -37,8 +41,8 @@ static void handle_conference_invite(
static void conference_double_invite_test(AutoTox *autotoxes)
{
// Conference callbacks.
tox_callback_conference_invite(autotoxes[0].tox, handle_conference_invite);
tox_callback_conference_invite(autotoxes[1].tox, handle_conference_invite);
tox_events_callback_conference_invite(autotoxes[0].dispatch, handle_conference_invite);
tox_events_callback_conference_invite(autotoxes[1].dispatch, handle_conference_invite);
State *state[2];
state[0] = (State *)autotoxes[0].state;

View File

@ -12,15 +12,18 @@ typedef struct State {
#include "auto_test_support.h"
static void handle_conference_invite(
Tox *tox, uint32_t friend_number, Tox_Conference_Type type,
const uint8_t *cookie, size_t length, void *user_data)
const Tox_Event_Conference_Invite *event, void *user_data)
{
const AutoTox *autotox = (AutoTox *)user_data;
State *state = (State *)autotox->state;
const uint32_t friend_number = tox_event_conference_invite_get_friend_number(event);
const uint8_t *cookie = tox_event_conference_invite_get_cookie(event);
const size_t length = tox_event_conference_invite_get_cookie_length(event);
if (friend_number != -1) {
Tox_Err_Conference_Join err;
state->conference = tox_conference_join(tox, friend_number, cookie, length, &err);
state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK,
"attempting to join the conference returned with an error: %d", err);
fprintf(stderr, "#%u accepted invite to conference %u\n", autotox->index, state->conference);
@ -28,7 +31,7 @@ static void handle_conference_invite(
}
static void handle_conference_connected(
Tox *tox, uint32_t conference_number, void *user_data)
const Tox_Event_Conference_Connected *event, void *user_data)
{
const AutoTox *autotox = (AutoTox *)user_data;
State *state = (State *)autotox->state;
@ -37,7 +40,7 @@ static void handle_conference_connected(
state->connected = true;
}
static void wait_connected(AutoTox *autotoxes, AutoTox *autotox, uint32_t friendnumber)
static void wait_connected(AutoTox *autotoxes, const AutoTox *autotox, uint32_t friendnumber)
{
do {
iterate_all_wait(autotoxes, NUM_INVITE_MERGE_TOX, ITERATION_INTERVAL);
@ -95,8 +98,8 @@ static void conference_invite_merge_test(AutoTox *autotoxes)
// components will cause a split group to merge
for (int i = 0; i < NUM_INVITE_MERGE_TOX; i++) {
tox_callback_conference_invite(autotoxes[i].tox, &handle_conference_invite);
tox_callback_conference_connected(autotoxes[i].tox, &handle_conference_connected);
tox_events_callback_conference_invite(autotoxes[i].dispatch, handle_conference_invite);
tox_events_callback_conference_connected(autotoxes[i].dispatch, handle_conference_connected);
}
State *state2 = (State *)autotoxes[2].state;

View File

@ -13,34 +13,39 @@ typedef struct State {
#include "auto_test_support.h"
static void handle_conference_invite(
Tox *tox, uint32_t friend_number, Tox_Conference_Type type,
const uint8_t *cookie, size_t length, void *user_data)
const Tox_Event_Conference_Invite *event, void *user_data)
{
const AutoTox *autotox = (AutoTox *)user_data;
State *state = (State *)autotox->state;
const uint32_t friend_number = tox_event_conference_invite_get_friend_number(event);
const Tox_Conference_Type type = tox_event_conference_invite_get_type(event);
const uint8_t *cookie = tox_event_conference_invite_get_cookie(event);
const size_t length = tox_event_conference_invite_get_cookie_length(event);
fprintf(stderr, "handle_conference_invite(#%u, %u, %d, uint8_t[%u], _)\n",
autotox->index, friend_number, type, (unsigned)length);
fprintf(stderr, "tox%u joining conference\n", autotox->index);
Tox_Err_Conference_Join err;
state->conference = tox_conference_join(tox, friend_number, cookie, length, &err);
state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK,
"attempting to join the conference returned with an error: %d", err);
fprintf(stderr, "tox%u joined conference %u\n", autotox->index, state->conference);
state->joined = true;
}
static void handle_peer_list_changed(Tox *tox, uint32_t conference_number, void *user_data)
static void handle_peer_list_changed(const Tox_Event_Conference_Peer_List_Changed *event, void *user_data)
{
const AutoTox *autotox = (AutoTox *)user_data;
State *state = (State *)autotox->state;
const uint32_t conference_number = tox_event_conference_peer_list_changed_get_conference_number(event);
fprintf(stderr, "handle_peer_list_changed(#%u, %u, _)\n",
autotox->index, conference_number);
Tox_Err_Conference_Peer_Query err;
uint32_t const count = tox_conference_peer_count(tox, conference_number, &err);
uint32_t const count = tox_conference_peer_count(autotox->tox, conference_number, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
"failed to get conference peer count: err = %d", err);
printf("tox%u has %u peers\n", autotox->index, count);
@ -75,10 +80,10 @@ static void rebuild_peer_list(Tox *tox)
static void conference_peer_nick_test(AutoTox *autotoxes)
{
// Conference callbacks.
tox_callback_conference_invite(autotoxes[0].tox, handle_conference_invite);
tox_callback_conference_invite(autotoxes[1].tox, handle_conference_invite);
tox_callback_conference_peer_list_changed(autotoxes[0].tox, handle_peer_list_changed);
tox_callback_conference_peer_list_changed(autotoxes[1].tox, handle_peer_list_changed);
tox_events_callback_conference_invite(autotoxes[0].dispatch, handle_conference_invite);
tox_events_callback_conference_invite(autotoxes[1].dispatch, handle_conference_invite);
tox_events_callback_conference_peer_list_changed(autotoxes[0].dispatch, handle_peer_list_changed);
tox_events_callback_conference_peer_list_changed(autotoxes[1].dispatch, handle_peer_list_changed);
// Set the names of the toxes.
tox_self_set_name(autotoxes[0].tox, (const uint8_t *)"test-tox-0", 10, nullptr);

View File

@ -0,0 +1,268 @@
#include <stdio.h>
#include <stdlib.h>
#include "../testing/misc_tools.h"
#include "../toxcore/tox.h"
#include "../toxcore/tox_dispatch.h"
#include "../toxcore/tox_events.h"
#include "auto_test_support.h"
#include "check_compat.h"
typedef struct State {
uint32_t id;
Tox *tox;
bool self_online;
bool friend_online;
bool invited_next;
bool joined;
uint32_t conference;
bool received;
uint32_t peers;
} State;
static void handle_self_connection_status(const Tox_Event_Self_Connection_Status *event, void *user_data)
{
State *state = (State *)user_data;
const Tox_Connection connection_status = tox_event_self_connection_status_get_connection_status(event);
fprintf(stderr, "self_connection_status(#%u, %d, _)\n", state->id, connection_status);
state->self_online = connection_status != TOX_CONNECTION_NONE;
}
static void handle_friend_connection_status(const Tox_Event_Friend_Connection_Status *event,
void *user_data)
{
State *state = (State *)user_data;
const uint32_t friend_number = tox_event_friend_connection_status_get_friend_number(event);
const Tox_Connection connection_status = tox_event_friend_connection_status_get_connection_status(event);
fprintf(stderr, "handle_friend_connection_status(#%u, %u, %d, _)\n", state->id, friend_number, connection_status);
state->friend_online = connection_status != TOX_CONNECTION_NONE;
}
static void handle_conference_invite(const Tox_Event_Conference_Invite *event, void *user_data)
{
State *state = (State *)user_data;
const uint32_t friend_number = tox_event_conference_invite_get_friend_number(event);
const Tox_Conference_Type type = tox_event_conference_invite_get_type(event);
const uint8_t *cookie = tox_event_conference_invite_get_cookie(event);
const size_t length = tox_event_conference_invite_get_cookie_length(event);
fprintf(stderr, "handle_conference_invite(#%u, %u, %d, uint8_t[%u], _)\n",
state->id, friend_number, type, (unsigned)length);
fprintf(stderr, "tox%u joining conference\n", state->id);
{
Tox_Err_Conference_Join err;
state->conference = tox_conference_join(state->tox, friend_number, cookie, length, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "failed to join a conference: err = %d", err);
fprintf(stderr, "tox%u Joined conference %u\n", state->id, state->conference);
state->joined = true;
}
}
static void handle_conference_message(const Tox_Event_Conference_Message *event, void *user_data)
{
State *state = (State *)user_data;
const uint32_t conference_number = tox_event_conference_message_get_conference_number(event);
const uint32_t peer_number = tox_event_conference_message_get_peer_number(event);
const Tox_Message_Type type = tox_event_conference_message_get_type(event);
const uint8_t *message = tox_event_conference_message_get_message(event);
const size_t length = tox_event_conference_message_get_message_length(event);
fprintf(stderr, "handle_conference_message(#%u, %u, %u, %d, uint8_t[%u], _)\n",
state->id, conference_number, peer_number, type, (unsigned)length);
fprintf(stderr, "tox%u got message: %s\n", state->id, (const char *)message);
state->received = true;
}
static void handle_conference_peer_list_changed(const Tox_Event_Conference_Peer_List_Changed *event, void *user_data)
{
State *state = (State *)user_data;
const uint32_t conference_number = tox_event_conference_peer_list_changed_get_conference_number(event);
fprintf(stderr, "handle_conference_peer_list_changed(#%u, %u, _)\n",
state->id, conference_number);
Tox_Err_Conference_Peer_Query err;
uint32_t count = tox_conference_peer_count(state->tox, conference_number, &err);
if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
fprintf(stderr, "ERROR: %d\n", err);
exit(EXIT_FAILURE);
}
fprintf(stderr, "tox%u has %u peers online\n", state->id, count);
state->peers = count;
}
static void handle_conference_connected(const Tox_Event_Conference_Connected *event, void *user_data)
{
State *state = (State *)user_data;
// We're tox2, so now we invite tox3.
if (state->id == 2 && !state->invited_next) {
Tox_Err_Conference_Invite err;
tox_conference_invite(state->tox, 1, state->conference, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox2 failed to invite tox3: err = %d", err);
state->invited_next = true;
fprintf(stderr, "tox2 invited tox3\n");
}
}
static void iterate_one(
Tox *tox, State *state, const Tox_Dispatch *dispatch)
{
Tox_Err_Events_Iterate err;
Tox_Events *events = tox_events_iterate(tox, true, &err);
ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK);
tox_dispatch_invoke(dispatch, events, state);
tox_events_free(events);
}
static void iterate3_wait(
State *state1, State *state2, State *state3,
const Tox_Dispatch *dispatch, int interval)
{
iterate_one(state1->tox, state1, dispatch);
iterate_one(state2->tox, state2, dispatch);
iterate_one(state3->tox, state3, dispatch);
c_sleep(interval);
}
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);
State state1 = {1};
State state2 = {2};
State state3 = {3};
// Create toxes.
state1.tox = tox_new_log(nullptr, nullptr, &state1.id);
state2.tox = tox_new_log(nullptr, nullptr, &state2.id);
state3.tox = tox_new_log(nullptr, nullptr, &state3.id);
tox_events_init(state1.tox);
tox_events_init(state2.tox);
tox_events_init(state3.tox);
// tox1 <-> tox2, tox2 <-> tox3
uint8_t key[TOX_PUBLIC_KEY_SIZE];
tox_self_get_public_key(state2.tox, key);
tox_friend_add_norequest(state1.tox, key, nullptr); // tox1 -> tox2
tox_self_get_public_key(state1.tox, key);
tox_friend_add_norequest(state2.tox, key, nullptr); // tox2 -> tox1
tox_self_get_public_key(state3.tox, key);
tox_friend_add_norequest(state2.tox, key, nullptr); // tox2 -> tox3
tox_self_get_public_key(state2.tox, key);
tox_friend_add_norequest(state3.tox, key, nullptr); // tox3 -> tox2
printf("bootstrapping tox2 and tox3 off tox1\n");
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
tox_self_get_dht_id(state1.tox, dht_key);
const uint16_t dht_port = tox_self_get_udp_port(state1.tox, nullptr);
tox_bootstrap(state2.tox, "localhost", dht_port, dht_key, nullptr);
tox_bootstrap(state3.tox, "localhost", dht_port, dht_key, nullptr);
Tox_Dispatch *dispatch = tox_dispatch_new(nullptr);
ck_assert(dispatch != nullptr);
// Connection callbacks.
tox_events_callback_self_connection_status(dispatch, handle_self_connection_status);
tox_events_callback_friend_connection_status(dispatch, handle_friend_connection_status);
// Conference callbacks.
tox_events_callback_conference_invite(dispatch, handle_conference_invite);
tox_events_callback_conference_connected(dispatch, handle_conference_connected);
tox_events_callback_conference_message(dispatch, handle_conference_message);
tox_events_callback_conference_peer_list_changed(dispatch, handle_conference_peer_list_changed);
// Wait for self connection.
fprintf(stderr, "Waiting for toxes to come online\n");
do {
iterate3_wait(&state1, &state2, &state3, dispatch, 100);
} while (!state1.self_online || !state2.self_online || !state3.self_online);
fprintf(stderr, "Toxes are online\n");
// Wait for friend connection.
fprintf(stderr, "Waiting for friends to connect\n");
do {
iterate3_wait(&state1, &state2, &state3, dispatch, 100);
} while (!state1.friend_online || !state2.friend_online || !state3.friend_online);
fprintf(stderr, "Friends are connected\n");
{
// Create new conference, tox1 is the founder.
Tox_Err_Conference_New err;
state1.conference = tox_conference_new(state1.tox, &err);
state1.joined = true;
ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create a conference: err = %d", err);
fprintf(stderr, "Created conference: id = %u\n", state1.conference);
}
{
// Invite friend.
Tox_Err_Conference_Invite err;
tox_conference_invite(state1.tox, 0, state1.conference, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "failed to invite a friend: err = %d", err);
state1.invited_next = true;
fprintf(stderr, "tox1 invited tox2\n");
}
fprintf(stderr, "Waiting for invitation to arrive\n");
do {
iterate3_wait(&state1, &state2, &state3, dispatch, 100);
} while (!state1.joined || !state2.joined || !state3.joined);
fprintf(stderr, "Invitations accepted\n");
fprintf(stderr, "Waiting for peers to come online\n");
do {
iterate3_wait(&state1, &state2, &state3, dispatch, 100);
} while (state1.peers == 0 || state2.peers == 0 || state3.peers == 0);
fprintf(stderr, "All peers are online\n");
{
fprintf(stderr, "tox1 sends a message to the group: \"hello!\"\n");
Tox_Err_Conference_Send_Message err;
tox_conference_send_message(state1.tox, state1.conference, TOX_MESSAGE_TYPE_NORMAL,
(const uint8_t *)"hello!", 7, &err);
if (err != TOX_ERR_CONFERENCE_SEND_MESSAGE_OK) {
fprintf(stderr, "ERROR: %d\n", err);
exit(EXIT_FAILURE);
}
}
fprintf(stderr, "Waiting for messages to arrive\n");
do {
iterate3_wait(&state1, &state2, &state3, dispatch, 100);
c_sleep(100);
} while (!state2.received || !state3.received);
fprintf(stderr, "Messages received. Test complete.\n");
tox_dispatch_free(dispatch);
tox_kill(state3.tox);
tox_kill(state2.tox);
tox_kill(state1.tox);
return 0;
}

View File

@ -56,13 +56,13 @@ static void handle_conference_invite(
ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%u: wrong conference type: %d", autotox->index, type);
Tox_Err_Conference_Join err;
uint32_t g_num = tox_conference_join(tox, friendnumber, data, length, &err);
uint32_t g_num = tox_conference_join(autotox->tox, friendnumber, data, length, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "tox #%u: error joining group: %d", autotox->index, err);
ck_assert_msg(g_num == 0, "tox #%u: group number was not 0", autotox->index);
// Try joining again. We should only be allowed to join once.
tox_conference_join(tox, friendnumber, data, length, &err);
tox_conference_join(autotox->tox, friendnumber, data, length, &err);
ck_assert_msg(err != TOX_ERR_CONFERENCE_JOIN_OK,
"tox #%u: joining groupchat twice should be impossible.", autotox->index);
}
@ -73,12 +73,12 @@ static void handle_conference_connected(
const AutoTox *autotox = (AutoTox *)user_data;
State *state = (State *)autotox->state;
if (state->invited_next || tox_self_get_friend_list_size(tox) <= 1) {
if (state->invited_next || tox_self_get_friend_list_size(autotox->tox) <= 1) {
return;
}
Tox_Err_Conference_Invite err;
tox_conference_invite(tox, 1, 0, &err);
tox_conference_invite(autotox->tox, 1, 0, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox #%u failed to invite next friend: err = %d", autotox->index,
err);
printf("tox #%u: invited next friend\n", autotox->index);
@ -97,7 +97,7 @@ static void handle_conference_message(
}
static bool toxes_are_disconnected_from_group(uint32_t tox_count, AutoTox *autotoxes,
bool *disconnected)
const bool *disconnected)
{
uint32_t num_disconnected = 0;
@ -174,12 +174,11 @@ static bool names_propagated(uint32_t tox_count, AutoTox *autotoxes)
return true;
}
/**
* returns a random index at which a list of booleans is false
* (some such index is required to exist)
*/
static uint32_t random_false_index(const Random *rng, bool *list, const uint32_t length)
static uint32_t random_false_index(const Random *rng, const bool *list, const uint32_t length)
{
uint32_t index;
@ -192,7 +191,7 @@ static uint32_t random_false_index(const Random *rng, bool *list, const uint32_t
static void run_conference_tests(AutoTox *autotoxes)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
/* disabling name change propagation check for now, as it occasionally
* fails due to disconnections too short to trigger freezing */
@ -357,7 +356,6 @@ static void test_many_group(AutoTox *autotoxes)
nullptr) != 0,
"failed to set group title");
printf("waiting for invitations to be made\n");
uint32_t invited_count = 0;
@ -435,6 +433,7 @@ int main(void)
Run_Auto_Options options = default_run_auto_options();
options.graph = GRAPH_LINEAR;
options.events = false;
run_auto_test(nullptr, NUM_GROUP_TOX, test_many_group, sizeof(State), &options);
return 0;

View File

@ -125,7 +125,7 @@ static void test_fast_known(void)
static void test_endtoend(void)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
// Test 100 random messages and keypairs
@ -192,7 +192,7 @@ static void test_endtoend(void)
static void test_large_data(void)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
uint8_t k[CRYPTO_SHARED_KEY_SIZE];
uint8_t n[CRYPTO_NONCE_SIZE];
@ -236,7 +236,7 @@ static void test_large_data(void)
static void test_large_data_symmetric(void)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
uint8_t k[CRYPTO_SYMMETRIC_KEY_SIZE];
@ -269,6 +269,30 @@ static void test_large_data_symmetric(void)
free(m1);
}
static void test_very_large_data(void)
{
const Random *rng = os_random();
ck_assert(rng != nullptr);
const uint8_t nonce[CRYPTO_NONCE_SIZE] = {0};
uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t sk[CRYPTO_SECRET_KEY_SIZE];
crypto_new_keypair(rng, pk, sk);
// 100 MiB of data (all zeroes, doesn't matter what's inside).
const uint32_t plain_size = 100 * 1024 * 1024;
uint8_t *plain = (uint8_t *)malloc(plain_size);
uint8_t *encrypted = (uint8_t *)malloc(plain_size + CRYPTO_MAC_SIZE);
ck_assert(plain != nullptr);
ck_assert(encrypted != nullptr);
encrypt_data(pk, sk, nonce, plain, plain_size, encrypted);
free(encrypted);
free(plain);
}
static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num)
{
uint32_t num1 = 0;
@ -292,7 +316,7 @@ static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num)
static void test_increment_nonce(void)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
uint8_t n[CRYPTO_NONCE_SIZE];
@ -340,6 +364,7 @@ int main(void)
test_endtoend(); /* waiting up to 15 seconds */
test_large_data();
test_large_data_symmetric();
test_very_large_data();
test_increment_nonce();
test_memzero();

Binary file not shown.

View File

@ -72,12 +72,16 @@ static bool all_nodes_crawled(const AutoTox *autotoxes, uint32_t num_toxes, uint
return true;
}
static void getnodes_response_cb(Tox *tox, const uint8_t *public_key, const char *ip, uint16_t port, void *user_data)
static void getnodes_response_cb(const Tox_Event_Dht_Get_Nodes_Response *event, void *user_data)
{
ck_assert(user_data != nullptr);
AutoTox *autotoxes = (AutoTox *)user_data;
State *state = (State *)autotoxes->state;
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);
if (node_crawled(state->nodes, state->num_nodes, public_key)) {
return;
@ -97,7 +101,7 @@ static void getnodes_response_cb(Tox *tox, const uint8_t *public_key, const char
// 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(tox, public_key, ip, port, state->public_key_list[i], nullptr);
tox_dht_get_nodes(autotox->tox, public_key, ip, port, state->public_key_list[i], nullptr);
}
}
@ -121,13 +125,12 @@ 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_callback_dht_get_nodes_response(autotoxes[i].tox, getnodes_response_cb);
tox_events_callback_dht_get_nodes_response(autotoxes[i].dispatch, getnodes_response_cb);
printf("Peer %zu dht closenode count total/annouce-capable: %d/%d\n",
printf("Peer %zu dht closenode count total/announce-capable: %d/%d\n",
i,
tox_dht_get_num_closelist(autotoxes[i].tox),
tox_dht_get_num_closelist_announce_capable(autotoxes[i].tox)
);
tox_dht_get_num_closelist_announce_capable(autotoxes[i].tox));
}
while (!all_nodes_crawled(autotoxes, NUM_TOXES, public_key_list)) {

View File

@ -3,7 +3,6 @@
#include <string.h>
#include <sys/types.h>
#ifndef VANILLA_NACL
#include <sodium.h>
#include "../testing/misc_tools.h"
@ -169,7 +168,7 @@ static void test_keys(void)
ck_assert(encrypted2a != nullptr);
uint8_t *in_plaintext2a = (uint8_t *)malloc(plaintext_length2a);
ck_assert(in_plaintext2a != nullptr);
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
random_bytes(rng, in_plaintext2a, plaintext_length2a);
ret = tox_pass_encrypt(in_plaintext2a, plaintext_length2a, key_char, 12, encrypted2a, &encerr);
@ -185,7 +184,6 @@ static void test_keys(void)
free(in_plaintext2a);
free(out_plaintext2a);
uint8_t encrypted2[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
ret = tox_pass_encrypt(string, 44, key_char, 12, encrypted2, &encerr);
ck_assert_msg(ret, "generic failure 3: %d", encerr);
@ -232,9 +230,3 @@ int main(void)
return 0;
}
#else // VANILLA_NACL
int main(void)
{
return 0;
}
#endif

View File

@ -0,0 +1,272 @@
/* File transfer test: streaming version (no known size).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "../testing/misc_tools.h"
#include "../toxcore/ccompat.h"
#include "../toxcore/tox.h"
#include "../toxcore/util.h"
#include "auto_test_support.h"
#include "check_compat.h"
#ifndef USE_IPV6
#define USE_IPV6 1
#endif
#ifdef TOX_LOCALHOST
#undef TOX_LOCALHOST
#endif
#if USE_IPV6
#define TOX_LOCALHOST "::1"
#else
#define TOX_LOCALHOST "127.0.0.1"
#endif
static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
{
if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
tox_friend_add_norequest(m, public_key, nullptr);
}
}
static uint64_t size_recv;
static uint64_t sending_pos;
static uint8_t file_cmp_id[TOX_FILE_ID_LENGTH];
static uint32_t file_accepted;
static uint64_t file_size;
static void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t kind, uint64_t filesize,
const uint8_t *filename, size_t filename_length, void *userdata)
{
ck_assert_msg(kind == TOX_FILE_KIND_DATA, "bad kind");
ck_assert_msg(filename_length == sizeof("Gentoo.exe")
&& memcmp(filename, "Gentoo.exe", sizeof("Gentoo.exe")) == 0, "bad filename");
uint8_t file_id[TOX_FILE_ID_LENGTH];
ck_assert_msg(tox_file_get_file_id(tox, friend_number, file_number, file_id, nullptr), "tox_file_get_file_id error");
ck_assert_msg(memcmp(file_id, file_cmp_id, TOX_FILE_ID_LENGTH) == 0, "bad file_id");
const uint8_t empty[TOX_FILE_ID_LENGTH] = {0};
ck_assert_msg(memcmp(empty, file_cmp_id, TOX_FILE_ID_LENGTH) != 0, "empty file_id");
file_size = filesize;
if (filesize) {
sending_pos = size_recv = 1337;
Tox_Err_File_Seek err_s;
ck_assert_msg(tox_file_seek(tox, friend_number, file_number, 1337, &err_s), "tox_file_seek error");
ck_assert_msg(err_s == TOX_ERR_FILE_SEEK_OK, "tox_file_seek wrong error");
} else {
sending_pos = size_recv = 0;
}
Tox_Err_File_Control error;
ck_assert_msg(tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error),
"tox_file_control failed. %i", error);
++file_accepted;
Tox_Err_File_Seek err_s;
ck_assert_msg(!tox_file_seek(tox, friend_number, file_number, 1234, &err_s), "tox_file_seek no error");
ck_assert_msg(err_s == TOX_ERR_FILE_SEEK_DENIED, "tox_file_seek wrong error");
}
static uint32_t sendf_ok;
static void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, Tox_File_Control control,
void *userdata)
{
/* First send file num is 0.*/
if (file_number == 0 && control == TOX_FILE_CONTROL_RESUME) {
sendf_ok = 1;
}
}
static uint64_t max_sending;
static bool m_send_reached;
static uint8_t sending_num;
static bool file_sending_done;
static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position,
size_t length, void *user_data)
{
ck_assert_msg(sendf_ok, "didn't get resume control");
ck_assert_msg(sending_pos == position, "bad position %lu", (unsigned long)position);
if (length == 0) {
ck_assert_msg(!file_sending_done, "file sending already done");
file_sending_done = 1;
return;
}
if (position + length > max_sending) {
ck_assert_msg(!m_send_reached, "requested done file transfer");
length = max_sending - position;
m_send_reached = 1;
}
VLA(uint8_t, f_data, length);
memset(f_data, sending_num, length);
Tox_Err_File_Send_Chunk error;
tox_file_send_chunk(tox, friend_number, file_number, position, f_data, length, &error);
ck_assert_msg(error == TOX_ERR_FILE_SEND_CHUNK_OK,
"could not send chunk, error num=%d pos=%d len=%d", (int)error, (int)position, (int)length);
++sending_num;
sending_pos += length;
}
static uint8_t num;
static bool file_recv;
static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data,
size_t length, void *user_data)
{
ck_assert_msg(size_recv == position, "bad position");
if (length == 0) {
file_recv = 1;
return;
}
VLA(uint8_t, f_data, length);
memset(f_data, num, length);
++num;
ck_assert_msg(memcmp(f_data, data, length) == 0, "FILE_CORRUPTED");
size_recv += length;
}
static void file_transfer_test(void)
{
printf("Starting test: few_clients\n");
uint32_t index[] = { 1, 2, 3 };
long long unsigned int cur_time = time(nullptr);
Tox_Err_New t_n_error;
Tox *tox1 = tox_new_log(nullptr, &t_n_error, &index[0]);
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error");
Tox *tox2 = tox_new_log(nullptr, &t_n_error, &index[1]);
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error");
Tox *tox3 = tox_new_log(nullptr, &t_n_error, &index[2]);
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error");
ck_assert_msg(tox1 && tox2 && tox3, "Failed to create 3 tox instances");
tox_callback_friend_request(tox2, accept_friend_request);
uint8_t address[TOX_ADDRESS_SIZE];
tox_self_get_address(tox2, address);
uint32_t test = tox_friend_add(tox3, address, (const uint8_t *)"Gentoo", 7, nullptr);
ck_assert_msg(test == 0, "Failed to add friend error code: %u", test);
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
tox_self_get_dht_id(tox1, dht_key);
uint16_t dht_port = tox_self_get_udp_port(tox1, nullptr);
tox_bootstrap(tox2, TOX_LOCALHOST, dht_port, dht_key, nullptr);
tox_bootstrap(tox3, TOX_LOCALHOST, dht_port, dht_key, nullptr);
printf("Waiting for toxes to come online\n");
do {
tox_iterate(tox1, nullptr);
tox_iterate(tox2, nullptr);
tox_iterate(tox3, nullptr);
printf("Connections: self (%d, %d, %d), friends (%d, %d)\n",
tox_self_get_connection_status(tox1),
tox_self_get_connection_status(tox2),
tox_self_get_connection_status(tox3),
tox_friend_get_connection_status(tox2, 0, nullptr),
tox_friend_get_connection_status(tox3, 0, nullptr));
c_sleep(ITERATION_INTERVAL);
} while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE ||
tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE ||
tox_self_get_connection_status(tox3) == TOX_CONNECTION_NONE ||
tox_friend_get_connection_status(tox2, 0, nullptr) == TOX_CONNECTION_NONE ||
tox_friend_get_connection_status(tox3, 0, nullptr) == TOX_CONNECTION_NONE);
printf("Starting file transfer test: 100MiB file.\n");
file_accepted = file_size = sendf_ok = size_recv = 0;
file_recv = 0;
max_sending = UINT64_MAX;
printf("Starting file streaming transfer test.\n");
file_sending_done = 0;
file_accepted = 0;
file_size = 0;
sendf_ok = 0;
size_recv = 0;
file_recv = 0;
tox_callback_file_recv_chunk(tox3, write_file);
tox_callback_file_recv_control(tox2, file_print_control);
tox_callback_file_chunk_request(tox2, tox_file_chunk_request);
tox_callback_file_recv_control(tox3, file_print_control);
tox_callback_file_recv(tox3, tox_file_receive);
const uint64_t totalf_size = UINT64_MAX;
Tox_File_Number fnum = tox_file_send(
tox2, 0, TOX_FILE_KIND_DATA, totalf_size, nullptr,
(const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), nullptr);
ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail");
Tox_Err_File_Get gfierr;
ck_assert_msg(!tox_file_get_file_id(tox2, 1, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail");
ck_assert_msg(gfierr == TOX_ERR_FILE_GET_FRIEND_NOT_FOUND, "wrong error");
ck_assert_msg(!tox_file_get_file_id(tox2, 0, fnum + 1, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail");
ck_assert_msg(gfierr == TOX_ERR_FILE_GET_NOT_FOUND, "wrong error");
ck_assert_msg(tox_file_get_file_id(tox2, 0, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id failed");
ck_assert_msg(gfierr == TOX_ERR_FILE_GET_OK, "wrong error");
max_sending = 100 * 1024;
m_send_reached = 0;
do {
tox_iterate(tox1, nullptr);
tox_iterate(tox2, nullptr);
tox_iterate(tox3, nullptr);
uint32_t tox1_interval = tox_iteration_interval(tox1);
uint32_t tox2_interval = tox_iteration_interval(tox2);
uint32_t tox3_interval = tox_iteration_interval(tox3);
c_sleep(min_u32(tox1_interval, min_u32(tox2_interval, tox3_interval)));
} while (!file_sending_done);
ck_assert_msg(sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending
&& sending_pos == size_recv && file_accepted == 1,
"something went wrong in file transfer %u %u %u %u %u %u %u %lu %lu %lu %lu", sendf_ok, file_recv,
m_send_reached, totalf_size == file_size, size_recv == max_sending, sending_pos == size_recv, file_accepted == 1,
(unsigned long)totalf_size, (unsigned long)file_size,
(unsigned long)size_recv, (unsigned long)sending_pos);
printf("file_transfer_test succeeded, took %llu seconds\n", time(nullptr) - cur_time);
tox_kill(tox1);
tox_kill(tox2);
tox_kill(tox3);
}
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);
file_transfer_test();
return 0;
}

View File

@ -13,18 +13,29 @@
#include "auto_test_support.h"
#include "check_compat.h"
/* The Travis-CI container responds poorly to ::1 as a localhost address
* You're encouraged to -D FORCE_TESTS_IPV6 on a local test */
#ifdef FORCE_TESTS_IPV6
#ifndef USE_IPV6
#define USE_IPV6 1
#endif
#ifdef TOX_LOCALHOST
#undef TOX_LOCALHOST
#endif
#if USE_IPV6
#define TOX_LOCALHOST "::1"
#else
#define TOX_LOCALHOST "127.0.0.1"
#endif
static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
static void accept_friend_request(const Tox_Event_Friend_Request *event, void *userdata)
{
Tox *tox = (Tox *)userdata;
const uint8_t *public_key = tox_event_friend_request_get_public_key(event);
const uint8_t *data = tox_event_friend_request_get_message(event);
const size_t length = tox_event_friend_request_get_message_length(event);
if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
tox_friend_add_norequest(m, public_key, nullptr);
tox_friend_add_norequest(tox, public_key, nullptr);
}
}
@ -34,9 +45,17 @@ static uint64_t sending_pos;
static uint8_t file_cmp_id[TOX_FILE_ID_LENGTH];
static uint32_t file_accepted;
static uint64_t file_size;
static void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t kind, uint64_t filesize,
const uint8_t *filename, size_t filename_length, void *userdata)
static void tox_file_receive(const Tox_Event_File_Recv *event, void *userdata)
{
Tox *state_tox = (Tox *)userdata;
const uint32_t friend_number = tox_event_file_recv_get_friend_number(event);
const uint32_t file_number = tox_event_file_recv_get_file_number(event);
const uint32_t kind = tox_event_file_recv_get_kind(event);
const uint64_t filesize = tox_event_file_recv_get_file_size(event);
const uint8_t *filename = tox_event_file_recv_get_filename(event);
const size_t filename_length = tox_event_file_recv_get_filename_length(event);
ck_assert_msg(kind == TOX_FILE_KIND_DATA, "bad kind");
ck_assert_msg(filename_length == sizeof("Gentoo.exe")
@ -44,11 +63,11 @@ static void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_num
uint8_t file_id[TOX_FILE_ID_LENGTH];
ck_assert_msg(tox_file_get_file_id(tox, friend_number, file_number, file_id, nullptr), "tox_file_get_file_id error");
ck_assert_msg(tox_file_get_file_id(state_tox, friend_number, file_number, file_id, nullptr), "tox_file_get_file_id error");
ck_assert_msg(memcmp(file_id, file_cmp_id, TOX_FILE_ID_LENGTH) == 0, "bad file_id");
uint8_t empty[TOX_FILE_ID_LENGTH] = {0};
const uint8_t empty[TOX_FILE_ID_LENGTH] = {0};
ck_assert_msg(memcmp(empty, file_cmp_id, TOX_FILE_ID_LENGTH) != 0, "empty file_id");
@ -59,7 +78,7 @@ static void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_num
Tox_Err_File_Seek err_s;
ck_assert_msg(tox_file_seek(tox, friend_number, file_number, 1337, &err_s), "tox_file_seek error");
ck_assert_msg(tox_file_seek(state_tox, friend_number, file_number, 1337, &err_s), "tox_file_seek error");
ck_assert_msg(err_s == TOX_ERR_FILE_SEEK_OK, "tox_file_seek wrong error");
@ -69,21 +88,24 @@ static void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_num
Tox_Err_File_Control error;
ck_assert_msg(tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error),
ck_assert_msg(tox_file_control(state_tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error),
"tox_file_control failed. %i", error);
++file_accepted;
Tox_Err_File_Seek err_s;
ck_assert_msg(!tox_file_seek(tox, friend_number, file_number, 1234, &err_s), "tox_file_seek no error");
ck_assert_msg(!tox_file_seek(state_tox, friend_number, file_number, 1234, &err_s), "tox_file_seek no error");
ck_assert_msg(err_s == TOX_ERR_FILE_SEEK_DENIED, "tox_file_seek wrong error");
}
static uint32_t sendf_ok;
static void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, Tox_File_Control control,
static void file_print_control(const Tox_Event_File_Recv_Control *event,
void *userdata)
{
const uint32_t file_number = tox_event_file_recv_control_get_file_number(event);
const Tox_File_Control control = tox_event_file_recv_control_get_control(event);
/* First send file num is 0.*/
if (file_number == 0 && control == TOX_FILE_CONTROL_RESUME) {
sendf_ok = 1;
@ -94,12 +116,18 @@ static uint64_t max_sending;
static bool m_send_reached;
static uint8_t sending_num;
static bool file_sending_done;
static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position,
size_t length, void *user_data)
static void tox_file_chunk_request(const Tox_Event_File_Chunk_Request *event, void *user_data)
{
Tox *state_tox = (Tox *)user_data;
const uint32_t friend_number = tox_event_file_chunk_request_get_friend_number(event);
const uint32_t file_number = tox_event_file_chunk_request_get_file_number(event);
const uint64_t position = tox_event_file_chunk_request_get_position(event);
size_t length = tox_event_file_chunk_request_get_length(event);
ck_assert_msg(sendf_ok, "didn't get resume control");
ck_assert_msg(sending_pos == position, "bad position %lu", (unsigned long)position);
ck_assert_msg(sending_pos == position, "bad position %lu (should be %lu)", (unsigned long)position, (unsigned long)sending_pos);
if (length == 0) {
ck_assert_msg(!file_sending_done, "file sending already done");
@ -119,8 +147,7 @@ static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t fi
memset(f_data, sending_num, length);
Tox_Err_File_Send_Chunk error;
tox_file_send_chunk(tox, friend_number, file_number, position, f_data, length, &error);
tox_file_send_chunk(state_tox, friend_number, file_number, position, f_data, length, &error);
ck_assert_msg(error == TOX_ERR_FILE_SEND_CHUNK_OK,
"could not send chunk, error num=%d pos=%d len=%d", (int)error, (int)position, (int)length);
@ -129,12 +156,14 @@ static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t fi
sending_pos += length;
}
static uint8_t num;
static bool file_recv;
static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data,
size_t length, void *user_data)
static void write_file(const Tox_Event_File_Recv_Chunk *event, void *user_data)
{
const uint64_t position = tox_event_file_recv_chunk_get_position(event);
const uint8_t *data = tox_event_file_recv_chunk_get_data(event);
const size_t length = tox_event_file_recv_chunk_get_data_length(event);
ck_assert_msg(size_recv == position, "bad position");
if (length == 0) {
@ -151,6 +180,17 @@ static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uin
size_recv += length;
}
static void iterate_and_dispatch(const Tox_Dispatch *dispatch, Tox *tox)
{
Tox_Err_Events_Iterate err;
Tox_Events *events;
events = tox_events_iterate(tox, true, &err);
ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK);
tox_dispatch_invoke(dispatch, events, tox);
tox_events_free(events);
}
static void file_transfer_test(void)
{
printf("Starting test: few_clients\n");
@ -166,7 +206,19 @@ static void file_transfer_test(void)
ck_assert_msg(tox1 && tox2 && tox3, "Failed to create 3 tox instances");
tox_callback_friend_request(tox2, accept_friend_request);
tox_events_init(tox1);
tox_events_init(tox2);
tox_events_init(tox3);
Tox_Dispatch *dispatch1 = tox_dispatch_new(nullptr);
ck_assert(dispatch1 != nullptr);
Tox_Dispatch *dispatch2 = tox_dispatch_new(nullptr);
ck_assert(dispatch2 != nullptr);
Tox_Dispatch *dispatch3 = tox_dispatch_new(nullptr);
ck_assert(dispatch3 != nullptr);
tox_events_callback_friend_request(dispatch2, accept_friend_request);
uint8_t address[TOX_ADDRESS_SIZE];
tox_self_get_address(tox2, address);
uint32_t test = tox_friend_add(tox3, address, (const uint8_t *)"Gentoo", 7, nullptr);
@ -182,9 +234,9 @@ static void file_transfer_test(void)
printf("Waiting for toxes to come online\n");
do {
tox_iterate(tox1, nullptr);
tox_iterate(tox2, nullptr);
tox_iterate(tox3, nullptr);
iterate_and_dispatch(dispatch1, tox1);
iterate_and_dispatch(dispatch2, tox2);
iterate_and_dispatch(dispatch3, tox3);
printf("Connections: self (%d, %d, %d), friends (%d, %d)\n",
tox_self_get_connection_status(tox1),
@ -205,11 +257,11 @@ static void file_transfer_test(void)
file_recv = 0;
max_sending = UINT64_MAX;
uint64_t f_time = time(nullptr);
tox_callback_file_recv_chunk(tox3, write_file);
tox_callback_file_recv_control(tox2, file_print_control);
tox_callback_file_chunk_request(tox2, tox_file_chunk_request);
tox_callback_file_recv_control(tox3, file_print_control);
tox_callback_file_recv(tox3, tox_file_receive);
tox_events_callback_file_recv_chunk(dispatch3, write_file);
tox_events_callback_file_recv_control(dispatch2, file_print_control);
tox_events_callback_file_chunk_request(dispatch2, tox_file_chunk_request);
tox_events_callback_file_recv_control(dispatch3, file_print_control);
tox_events_callback_file_recv(dispatch3, tox_file_receive);
uint64_t totalf_size = 100 * 1024 * 1024;
uint32_t fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, nullptr, (const uint8_t *)"Gentoo.exe",
sizeof("Gentoo.exe"), nullptr);
@ -226,9 +278,9 @@ static void file_transfer_test(void)
const size_t max_iterations = INT16_MAX;
for (size_t i = 0; i < max_iterations; i++) {
tox_iterate(tox1, nullptr);
tox_iterate(tox2, nullptr);
tox_iterate(tox3, nullptr);
iterate_and_dispatch(dispatch1, tox1);
iterate_and_dispatch(dispatch2, tox2);
iterate_and_dispatch(dispatch3, tox3);
if (file_sending_done) {
ck_assert_msg(sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv
@ -261,53 +313,6 @@ static void file_transfer_test(void)
printf("100MiB file sent in %lu seconds\n", (unsigned long)(time(nullptr) - f_time));
printf("Starting file streaming transfer test.\n");
file_sending_done = 0;
file_accepted = 0;
file_size = 0;
sendf_ok = 0;
size_recv = 0;
file_recv = 0;
tox_callback_file_recv_chunk(tox3, write_file);
tox_callback_file_recv_control(tox2, file_print_control);
tox_callback_file_chunk_request(tox2, tox_file_chunk_request);
tox_callback_file_recv_control(tox3, file_print_control);
tox_callback_file_recv(tox3, tox_file_receive);
totalf_size = UINT64_MAX;
fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, nullptr,
(const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), nullptr);
ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail");
ck_assert_msg(!tox_file_get_file_id(tox2, 1, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail");
ck_assert_msg(gfierr == TOX_ERR_FILE_GET_FRIEND_NOT_FOUND, "wrong error");
ck_assert_msg(!tox_file_get_file_id(tox2, 0, fnum + 1, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail");
ck_assert_msg(gfierr == TOX_ERR_FILE_GET_NOT_FOUND, "wrong error");
ck_assert_msg(tox_file_get_file_id(tox2, 0, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id failed");
ck_assert_msg(gfierr == TOX_ERR_FILE_GET_OK, "wrong error");
max_sending = 100 * 1024;
m_send_reached = 0;
do {
tox_iterate(tox1, nullptr);
tox_iterate(tox2, nullptr);
tox_iterate(tox3, nullptr);
uint32_t tox1_interval = tox_iteration_interval(tox1);
uint32_t tox2_interval = tox_iteration_interval(tox2);
uint32_t tox3_interval = tox_iteration_interval(tox3);
c_sleep(min_u32(tox1_interval, min_u32(tox2_interval, tox3_interval)));
} while (!file_sending_done);
ck_assert_msg(sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending
&& sending_pos == size_recv && file_accepted == 1,
"something went wrong in file transfer %u %u %u %u %u %u %u %lu %lu %lu %lu", sendf_ok, file_recv,
m_send_reached, totalf_size == file_size, size_recv == max_sending, sending_pos == size_recv, file_accepted == 1,
(unsigned long)totalf_size, (unsigned long)file_size,
(unsigned long)size_recv, (unsigned long)sending_pos);
printf("starting file 0 transfer test.\n");
file_sending_done = 0;
@ -316,11 +321,11 @@ static void file_transfer_test(void)
sendf_ok = 0;
size_recv = 0;
file_recv = 0;
tox_callback_file_recv_chunk(tox3, write_file);
tox_callback_file_recv_control(tox2, file_print_control);
tox_callback_file_chunk_request(tox2, tox_file_chunk_request);
tox_callback_file_recv_control(tox3, file_print_control);
tox_callback_file_recv(tox3, tox_file_receive);
tox_events_callback_file_recv_chunk(dispatch3, write_file);
tox_events_callback_file_recv_control(dispatch2, file_print_control);
tox_events_callback_file_chunk_request(dispatch2, tox_file_chunk_request);
tox_events_callback_file_recv_control(dispatch3, file_print_control);
tox_events_callback_file_recv(dispatch3, tox_file_receive);
totalf_size = 0;
fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, nullptr,
(const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), nullptr);
@ -340,9 +345,9 @@ static void file_transfer_test(void)
c_sleep(min_u32(tox1_interval, min_u32(tox2_interval, tox3_interval)));
tox_iterate(tox1, nullptr);
tox_iterate(tox2, nullptr);
tox_iterate(tox3, nullptr);
iterate_and_dispatch(dispatch1, tox1);
iterate_and_dispatch(dispatch2, tox2);
iterate_and_dispatch(dispatch3, tox3);
} while (!file_sending_done);
ck_assert_msg(sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size
@ -354,9 +359,12 @@ static void file_transfer_test(void)
printf("file_transfer_test succeeded, took %llu seconds\n", time(nullptr) - cur_time);
tox_kill(tox1);
tox_kill(tox2);
tox_dispatch_free(dispatch3);
tox_dispatch_free(dispatch2);
tox_dispatch_free(dispatch1);
tox_kill(tox3);
tox_kill(tox2);
tox_kill(tox1);
}
int main(void)

View File

@ -47,8 +47,8 @@ static void test_forwarded_request_cb(void *object, const IP_Port *forwarder,
const uint8_t *sendback, uint16_t sendback_length,
const uint8_t *data, uint16_t length, void *userdata)
{
Test_Data *test_data = (Test_Data *)object;
uint8_t *index = (uint8_t *)userdata;
const Test_Data *test_data = (const Test_Data *)object;
const uint8_t *index = (const uint8_t *)userdata;
if (length != 12 || memcmp("hello: ", data, 8) != 0) {
printf("[%u] got unexpected data of length %d\n", *index, length);
@ -66,7 +66,7 @@ static void test_forwarded_response_cb(void *object,
const uint8_t *data, uint16_t length, void *userdata)
{
Test_Data *test_data = (Test_Data *)object;
uint8_t *index = (uint8_t *)userdata;
const uint8_t *index = (const uint8_t *)userdata;
if (length != 12 || memcmp("reply: ", data, 8) != 0) {
printf("[%u] got unexpected data of length %d\n", *index, length);
@ -104,9 +104,9 @@ typedef struct Forwarding_Subtox {
static Forwarding_Subtox *new_forwarding_subtox(const Memory *mem, bool no_udp, uint32_t *index, uint16_t port)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
const Network *ns = system_network();
const Network *ns = os_network();
ck_assert(ns != nullptr);
Forwarding_Subtox *subtox = (Forwarding_Subtox *)calloc(1, sizeof(Forwarding_Subtox));
@ -152,11 +152,11 @@ static void kill_forwarding_subtox(const Memory *mem, Forwarding_Subtox *subtox)
static void test_forwarding(void)
{
const Memory *mem = system_memory();
const Memory *mem = os_memory();
ck_assert(mem != nullptr);
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
const Network *ns = system_network();
const Network *ns = os_network();
ck_assert(ns != nullptr);
uint32_t index[NUM_FORWARDER];
@ -317,7 +317,6 @@ static void test_forwarding(void)
}
}
for (uint32_t i = 0; i < NUM_FORWARDER; ++i) {
kill_forwarding_subtox(mem, subtoxes[i]);
}
@ -325,7 +324,6 @@ static void test_forwarding(void)
tox_kill(relay);
}
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);

View File

@ -22,12 +22,18 @@ typedef struct State {
bool unused;
} State;
static void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *data, size_t length,
static void accept_friend_request(const Tox_Event_Friend_Request *event,
void *userdata)
{
AutoTox *autotox = (AutoTox *)userdata;
const uint8_t *public_key = tox_event_friend_request_get_public_key(event);
const uint8_t *data = tox_event_friend_request_get_message(event);
const size_t length = tox_event_friend_request_get_message_length(event);
ck_assert_msg(length == sizeof(FR_MESSAGE) && memcmp(FR_MESSAGE, data, sizeof(FR_MESSAGE)) == 0,
"unexpected friend request message");
tox_friend_add_norequest(tox, public_key, nullptr);
tox_friend_add_norequest(autotox->tox, public_key, nullptr);
}
static void test_friend_request(AutoTox *autotoxes)
@ -35,7 +41,7 @@ static void test_friend_request(AutoTox *autotoxes)
const time_t con_time = time(nullptr);
printf("All toxes add tox1 as friend.\n");
tox_callback_friend_request(autotoxes[0].tox, accept_friend_request);
tox_events_callback_friend_request(autotoxes[0].dispatch, accept_friend_request);
uint8_t address[TOX_ADDRESS_SIZE];
tox_self_get_address(autotoxes[0].tox, address);

View File

@ -15,12 +15,36 @@
#define FR_MESSAGE "Gentoo"
static void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *data, size_t length,
static void accept_friend_request(const Tox_Event_Friend_Request *event,
void *userdata)
{
Tox *state_tox = (Tox *)userdata;
const uint8_t *public_key = tox_event_friend_request_get_public_key(event);
const uint8_t *data = tox_event_friend_request_get_message(event);
const size_t length = tox_event_friend_request_get_message_length(event);
ck_assert_msg(length == sizeof(FR_MESSAGE) && memcmp(FR_MESSAGE, data, sizeof(FR_MESSAGE)) == 0,
"unexpected friend request message");
tox_friend_add_norequest(tox, public_key, nullptr);
tox_friend_add_norequest(state_tox, public_key, nullptr);
}
static void iterate2_wait(const Tox_Dispatch *dispatch, Tox *tox1, Tox *tox2)
{
Tox_Err_Events_Iterate err;
Tox_Events *events;
events = tox_events_iterate(tox1, true, &err);
ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK);
tox_dispatch_invoke(dispatch, events, tox1);
tox_events_free(events);
events = tox_events_iterate(tox2, true, &err);
ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK);
tox_dispatch_invoke(dispatch, events, tox2);
tox_events_free(events);
c_sleep(ITERATION_INTERVAL);
}
static void test_friend_request(void)
@ -33,6 +57,9 @@ static void test_friend_request(void)
ck_assert_msg(tox1 && tox2, "failed to create 2 tox instances");
tox_events_init(tox1);
tox_events_init(tox2);
printf("Bootstrapping tox2 off tox1.\n");
uint8_t dht_key[TOX_PUBLIC_KEY_SIZE];
tox_self_get_dht_id(tox1, dht_key);
@ -40,11 +67,11 @@ static void test_friend_request(void)
tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr);
do {
tox_iterate(tox1, nullptr);
tox_iterate(tox2, nullptr);
Tox_Dispatch *dispatch = tox_dispatch_new(nullptr);
ck_assert(dispatch != nullptr);
c_sleep(ITERATION_INTERVAL);
do {
iterate2_wait(dispatch, tox1, tox2);
} while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE ||
tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE);
@ -52,7 +79,7 @@ static void test_friend_request(void)
const time_t con_time = time(nullptr);
printf("Tox1 adds tox2 as friend, tox2 accepts.\n");
tox_callback_friend_request(tox2, accept_friend_request);
tox_events_callback_friend_request(dispatch, accept_friend_request);
uint8_t address[TOX_ADDRESS_SIZE];
tox_self_get_address(tox2, address);
@ -61,16 +88,14 @@ static void test_friend_request(void)
ck_assert_msg(test == 0, "failed to add friend error code: %u", test);
do {
tox_iterate(tox1, nullptr);
tox_iterate(tox2, nullptr);
c_sleep(ITERATION_INTERVAL);
iterate2_wait(dispatch, tox1, tox2);
} while (tox_friend_get_connection_status(tox1, 0, nullptr) != TOX_CONNECTION_UDP ||
tox_friend_get_connection_status(tox2, 0, nullptr) != TOX_CONNECTION_UDP);
printf("Tox clients connected took %lu seconds.\n", (unsigned long)(time(nullptr) - con_time));
printf("friend_request_test succeeded, took %lu seconds.\n", (unsigned long)(time(nullptr) - cur_time));
tox_dispatch_free(dispatch);
tox_kill(tox1);
tox_kill(tox2);
}

View File

@ -9,6 +9,7 @@
#include <string.h>
#include "auto_test_support.h"
#include "../toxcore/tox_private.h"
typedef struct State {
size_t peer_joined_count;
@ -42,6 +43,22 @@ typedef struct State {
#define PEER_LIMIT 20
static void print_ip(const Tox *tox, uint32_t groupnumber, uint32_t peer_id)
{
Tox_Err_Group_Peer_Query err;
size_t length = tox_group_peer_get_ip_address_size(tox, groupnumber, peer_id, &err);
ck_assert_msg(err == TOX_ERR_GROUP_PEER_QUERY_OK, "failed to get ip address size: error %d", err);
uint8_t ip_str[TOX_GROUP_PEER_IP_STRING_MAX_LENGTH];
tox_group_peer_get_ip_address(tox, groupnumber, peer_id, ip_str, &err);
ip_str[length] = '\0';
ck_assert_msg(err == TOX_ERR_GROUP_PEER_QUERY_OK, "failed to get ip address: error %d", err);
fprintf(stderr, "%s\n", ip_str);
}
static bool all_group_peers_connected(AutoTox *autotoxes, uint32_t tox_count, uint32_t groupnumber, size_t name_length)
{
for (size_t i = 0; i < tox_count; ++i) {
@ -64,32 +81,35 @@ static bool all_group_peers_connected(AutoTox *autotoxes, uint32_t tox_count, ui
return true;
}
static void group_peer_join_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, void *user_data)
static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
const uint32_t groupnumber = tox_event_group_peer_join_get_group_number(event);
const uint32_t peer_id = tox_event_group_peer_join_get_peer_id(event);
// we do a connection test here for fun
Tox_Err_Group_Peer_Query pq_err;
TOX_CONNECTION connection_status = tox_group_peer_get_connection_status(tox, groupnumber, peer_id, &pq_err);
Tox_Connection connection_status = tox_group_peer_get_connection_status(autotox->tox, groupnumber, peer_id, &pq_err);
ck_assert(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(connection_status != TOX_CONNECTION_NONE);
Tox_Group_Role role = tox_group_peer_get_role(tox, groupnumber, peer_id, &pq_err);
Tox_Group_Role role = tox_group_peer_get_role(autotox->tox, groupnumber, peer_id, &pq_err);
ck_assert_msg(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK, "%d", pq_err);
Tox_User_Status status = tox_group_peer_get_status(tox, groupnumber, peer_id, &pq_err);
Tox_User_Status status = tox_group_peer_get_status(autotox->tox, groupnumber, peer_id, &pq_err);
ck_assert_msg(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK, "%d", pq_err);
size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &pq_err);
size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, groupnumber, peer_id, &pq_err);
char peer_name[TOX_MAX_NAME_LENGTH + 1];
ck_assert(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH);
tox_group_peer_get_name(tox, groupnumber, peer_id, (uint8_t *) peer_name, &pq_err);
tox_group_peer_get_name(autotox->tox, groupnumber, peer_id, (uint8_t *)peer_name, &pq_err);
ck_assert(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK);
peer_name[peer_name_len] = 0;
@ -119,33 +139,38 @@ static void group_peer_join_handler(Tox *tox, uint32_t groupnumber, uint32_t pee
}
}
fprintf(stderr, "%s joined with IP: ", peer_name);
print_ip(autotox->tox, groupnumber, peer_id);
state->peer_id = peer_id;
++state->peer_joined_count;
}
static void group_peer_self_join_handler(Tox *tox, uint32_t groupnumber, void *user_data)
static void group_peer_self_join_handler(const Tox_Event_Group_Self_Join *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
const uint32_t groupnumber = tox_event_group_self_join_get_group_number(event);
// make sure we see our own correct peer state on join callback
Tox_Err_Group_Self_Query sq_err;
size_t self_length = tox_group_self_get_name_size(tox, groupnumber, &sq_err);
size_t self_length = tox_group_self_get_name_size(autotox->tox, groupnumber, &sq_err);
ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK);
uint8_t self_name[TOX_MAX_NAME_LENGTH];
tox_group_self_get_name(tox, groupnumber, self_name, &sq_err);
tox_group_self_get_name(autotox->tox, groupnumber, self_name, &sq_err);
ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK);
TOX_USER_STATUS self_status = tox_group_self_get_status(tox, groupnumber, &sq_err);
Tox_User_Status self_status = tox_group_self_get_status(autotox->tox, groupnumber, &sq_err);
ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK);
Tox_Group_Role self_role = tox_group_self_get_role(tox, groupnumber, &sq_err);
Tox_Group_Role self_role = tox_group_self_get_role(autotox->tox, groupnumber, &sq_err);
ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK);
if (state->is_founder) {
@ -165,31 +190,37 @@ static void group_peer_self_join_handler(Tox *tox, uint32_t groupnumber, void *u
uint8_t group_name[GROUP_NAME_LEN];
uint8_t topic[TOX_GROUP_MAX_TOPIC_LENGTH];
ck_assert(tox_group_get_peer_limit(tox, groupnumber, nullptr) == PEER_LIMIT);
ck_assert(tox_group_get_name_size(tox, groupnumber, nullptr) == GROUP_NAME_LEN);
ck_assert(tox_group_get_topic_size(tox, groupnumber, nullptr) == TOPIC_LEN);
ck_assert(tox_group_get_peer_limit(autotox->tox, groupnumber, nullptr) == PEER_LIMIT);
ck_assert(tox_group_get_name_size(autotox->tox, groupnumber, nullptr) == GROUP_NAME_LEN);
ck_assert(tox_group_get_topic_size(autotox->tox, groupnumber, nullptr) == TOPIC_LEN);
Tox_Err_Group_State_Queries query_err;
tox_group_get_name(tox, groupnumber, group_name, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "%d", query_err);
Tox_Err_Group_State_Query query_err;
tox_group_get_name(autotox->tox, groupnumber, group_name, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%d", query_err);
ck_assert(memcmp(group_name, GROUP_NAME, GROUP_NAME_LEN) == 0);
tox_group_get_topic(tox, groupnumber, topic, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "%d", query_err);
tox_group_get_topic(autotox->tox, groupnumber, topic, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%d", query_err);
ck_assert(memcmp(topic, TOPIC, TOPIC_LEN) == 0);
uint32_t peer_id = tox_group_self_get_peer_id(autotox->tox, groupnumber, nullptr);
fprintf(stderr, "self joined with IP: ");
print_ip(autotox->tox, groupnumber, peer_id);
++state->self_joined_count;
}
static void group_peer_exit_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, Tox_Group_Exit_Type exit_type,
const uint8_t *name, size_t name_length, const uint8_t *part_message,
size_t length, void *user_data)
static void group_peer_exit_handler(const Tox_Event_Group_Peer_Exit *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
const uint8_t *part_message = tox_event_group_peer_exit_get_part_message(event);
const size_t length = tox_event_group_peer_exit_get_part_message_length(event);
++state->peer_exit_count;
// first exit is a disconnect. second is a real exit with a part message
@ -199,14 +230,16 @@ static void group_peer_exit_handler(Tox *tox, uint32_t groupnumber, uint32_t pee
}
}
static void group_peer_name_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, const uint8_t *name,
size_t length, void *user_data)
static void group_peer_name_handler(const Tox_Event_Group_Peer_Name *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
const uint8_t *name = tox_event_group_peer_name_get_name(event);
const size_t length = tox_event_group_peer_name_get_name_length(event);
// note: we already test the name_get api call elsewhere
ck_assert(length == PEER0_NICK2_LEN);
@ -215,7 +248,7 @@ static void group_peer_name_handler(Tox *tox, uint32_t groupnumber, uint32_t pee
state->peer_nick = true;
}
static void group_peer_status_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, TOX_USER_STATUS status,
static void group_peer_status_handler(const Tox_Event_Group_Peer_Status *event,
void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
@ -223,8 +256,12 @@ static void group_peer_status_handler(Tox *tox, uint32_t groupnumber, uint32_t p
State *state = (State *)autotox->state;
const uint32_t groupnumber = tox_event_group_peer_status_get_group_number(event);
const uint32_t peer_id = tox_event_group_peer_status_get_peer_id(event);
const Tox_User_Status status = tox_event_group_peer_status_get_status(event);
Tox_Err_Group_Peer_Query err;
TOX_USER_STATUS cur_status = tox_group_peer_get_status(tox, groupnumber, peer_id, &err);
Tox_User_Status cur_status = tox_group_peer_get_status(autotox->tox, groupnumber, peer_id, &err);
ck_assert_msg(cur_status == status, "%d, %d", cur_status, status);
ck_assert(status == TOX_USER_STATUS_BUSY);
@ -234,21 +271,20 @@ static void group_peer_status_handler(Tox *tox, uint32_t groupnumber, uint32_t p
static void group_announce_test(AutoTox *autotoxes)
{
#ifndef VANILLA_NACL
ck_assert_msg(NUM_GROUP_TOXES == 2, "NUM_GROUP_TOXES needs to be 2");
Tox *tox0 = autotoxes[0].tox;
Tox *tox1 = autotoxes[1].tox;
State *state0 = (State *)autotoxes[0].state;
State *state1 = (State *)autotoxes[1].state;
const State *state1 = (const State *)autotoxes[1].state;
tox_callback_group_peer_join(tox0, group_peer_join_handler);
tox_callback_group_peer_join(tox1, group_peer_join_handler);
tox_callback_group_self_join(tox0, group_peer_self_join_handler);
tox_callback_group_self_join(tox1, group_peer_self_join_handler);
tox_callback_group_peer_name(tox1, group_peer_name_handler);
tox_callback_group_peer_status(tox1, group_peer_status_handler);
tox_callback_group_peer_exit(tox1, group_peer_exit_handler);
tox_events_callback_group_peer_join(autotoxes[0].dispatch, group_peer_join_handler);
tox_events_callback_group_peer_join(autotoxes[1].dispatch, group_peer_join_handler);
tox_events_callback_group_self_join(autotoxes[0].dispatch, group_peer_self_join_handler);
tox_events_callback_group_self_join(autotoxes[1].dispatch, group_peer_self_join_handler);
tox_events_callback_group_peer_name(autotoxes[1].dispatch, group_peer_name_handler);
tox_events_callback_group_peer_status(autotoxes[1].dispatch, group_peer_status_handler);
tox_events_callback_group_peer_exit(autotoxes[1].dispatch, group_peer_exit_handler);
// tox0 makes new group.
Tox_Err_Group_New err_new;
@ -262,19 +298,19 @@ static void group_announce_test(AutoTox *autotoxes)
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
// changes the state (for sync check purposes)
Tox_Err_Group_Founder_Set_Peer_Limit limit_set_err;
tox_group_founder_set_peer_limit(tox0, groupnumber, PEER_LIMIT, &limit_set_err);
ck_assert_msg(limit_set_err == TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK, "failed to set peer limit: %d", limit_set_err);
Tox_Err_Group_Set_Peer_Limit limit_set_err;
tox_group_set_peer_limit(tox0, groupnumber, PEER_LIMIT, &limit_set_err);
ck_assert_msg(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK, "failed to set peer limit: %d", limit_set_err);
Tox_Err_Group_Topic_Set tp_err;
tox_group_set_topic(tox0, groupnumber, (const uint8_t *)TOPIC, TOPIC_LEN, &tp_err);
ck_assert(tp_err == TOX_ERR_GROUP_TOPIC_SET_OK);
// get the chat id of the new group.
Tox_Err_Group_State_Queries err_id;
Tox_Err_Group_State_Query err_id;
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(tox0, groupnumber, chat_id, &err_id);
ck_assert(err_id == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(err_id == TOX_ERR_GROUP_STATE_QUERY_OK);
// tox1 joins it.
Tox_Err_Group_Join err_join;
@ -319,7 +355,7 @@ static void group_announce_test(AutoTox *autotoxes)
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
TOX_USER_STATUS self_status = tox_group_self_get_status(tox0, groupnumber, &sq_err);
Tox_User_Status self_status = tox_group_self_get_status(tox0, groupnumber, &sq_err);
ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK);
ck_assert(self_status == TOX_USER_STATUS_BUSY);
@ -341,6 +377,7 @@ static void group_announce_test(AutoTox *autotoxes)
ck_assert(memcmp(tox0_pk_query, tox0_self_pk, TOX_GROUP_PEER_PUBLIC_KEY_SIZE) == 0);
fprintf(stderr, "Peer 0 disconnecting...\n");
// tox 0 disconnects then reconnects
Tox_Err_Group_Disconnect d_err;
tox_group_disconnect(tox0, groupnumber, &d_err);
@ -404,13 +441,14 @@ static void group_announce_test(AutoTox *autotoxes)
tox_group_leave(tox1, groupnumber, nullptr, 0, &err_exit);
ck_assert(err_exit == TOX_ERR_GROUP_LEAVE_OK);
while (num_groups1 != 0 || num_groups2 != 0) {
num_groups1 = tox_group_get_number_groups(tox0);
num_groups2 = tox_group_get_number_groups(tox1);
ck_assert(num_groups1 == num_groups2 && num_groups2 == 0);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
}
printf("All tests passed!\n");
#endif // VANILLA_NACL
}
int main(void)

View File

@ -51,13 +51,15 @@ static bool group_has_full_graph(const AutoTox *autotoxes, uint32_t group_number
return true;
}
static void group_join_fail_handler(Tox *tox, uint32_t group_number, Tox_Group_Join_Fail fail_type, void *user_data)
static void group_join_fail_handler(const Tox_Event_Group_Join_Fail *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
const Tox_Group_Join_Fail fail_type = tox_event_group_join_fail_get_fail_type(event);
switch (fail_type) {
case TOX_GROUP_JOIN_FAIL_PEER_LIMIT: {
state->peer_limit_fail = true;
@ -79,7 +81,7 @@ static void group_join_fail_handler(Tox *tox, uint32_t group_number, Tox_Group_J
}
}
static void group_self_join_handler(Tox *tox, uint32_t group_number, void *user_data)
static void group_self_join_handler(const Tox_Event_Group_Self_Join *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
@ -89,7 +91,7 @@ static void group_self_join_handler(Tox *tox, uint32_t group_number, void *user_
state->connected = true;
}
static void group_peer_join_handler(Tox *tox, uint32_t group_number, uint32_t peer_id, void *user_data)
static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
@ -102,13 +104,12 @@ static void group_peer_join_handler(Tox *tox, uint32_t group_number, uint32_t pe
static void group_invite_test(AutoTox *autotoxes)
{
#ifndef VANILLA_NACL
ck_assert_msg(NUM_GROUP_TOXES > 7, "NUM_GROUP_TOXES is too small: %d", NUM_GROUP_TOXES);
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
tox_callback_group_peer_join(autotoxes[i].tox, group_peer_join_handler);
tox_callback_group_join_fail(autotoxes[i].tox, group_join_fail_handler);
tox_callback_group_self_join(autotoxes[i].tox, group_self_join_handler);
tox_events_callback_group_peer_join(autotoxes[i].dispatch, group_peer_join_handler);
tox_events_callback_group_join_fail(autotoxes[i].dispatch, group_join_fail_handler);
tox_events_callback_group_self_join(autotoxes[i].dispatch, group_self_join_handler);
}
Tox *tox0 = autotoxes[0].tox;
@ -119,12 +120,12 @@ static void group_invite_test(AutoTox *autotoxes)
Tox *tox5 = autotoxes[5].tox;
Tox *tox6 = autotoxes[6].tox;
State *state0 = (State *)autotoxes[0].state;
State *state2 = (State *)autotoxes[2].state;
State *state3 = (State *)autotoxes[3].state;
State *state4 = (State *)autotoxes[4].state;
State *state5 = (State *)autotoxes[5].state;
State *state6 = (State *)autotoxes[6].state;
const State *state0 = (const State *)autotoxes[0].state;
const State *state2 = (const State *)autotoxes[2].state;
const State *state3 = (const State *)autotoxes[3].state;
const State *state4 = (const State *)autotoxes[4].state;
const State *state5 = (const State *)autotoxes[5].state;
const State *state6 = (const State *)autotoxes[6].state;
Tox_Err_Group_New new_err;
uint32_t groupnumber = tox_group_new(tox0, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *)"test", 4,
@ -133,11 +134,11 @@ static void group_invite_test(AutoTox *autotoxes)
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
Tox_Err_Group_State_Queries id_err;
Tox_Err_Group_State_Query id_err;
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "%d", id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%d", id_err);
// peer 1 joins public group with no password
Tox_Err_Group_Join join_err;
@ -151,9 +152,9 @@ static void group_invite_test(AutoTox *autotoxes)
printf("Peer 1 joined group\n");
// founder sets a password
Tox_Err_Group_Founder_Set_Password pass_set_err;
tox_group_founder_set_password(tox0, groupnumber, (const uint8_t *)PASSWORD, PASS_LEN, &pass_set_err);
ck_assert_msg(pass_set_err == TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK, "%d", pass_set_err);
Tox_Err_Group_Set_Password pass_set_err;
tox_group_set_password(tox0, groupnumber, (const uint8_t *)PASSWORD, PASS_LEN, &pass_set_err);
ck_assert_msg(pass_set_err == TOX_ERR_GROUP_SET_PASSWORD_OK, "%d", pass_set_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 5000);
@ -178,9 +179,9 @@ static void group_invite_test(AutoTox *autotoxes)
printf("Peer 3 successfully blocked with invalid password\n");
// founder sets peer limit to 1
Tox_Err_Group_Founder_Set_Peer_Limit limit_set_err;
tox_group_founder_set_peer_limit(tox0, groupnumber, 1, &limit_set_err);
ck_assert_msg(limit_set_err == TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK, "%d", limit_set_err);
Tox_Err_Group_Set_Peer_Limit limit_set_err;
tox_group_set_peer_limit(tox0, groupnumber, 1, &limit_set_err);
ck_assert_msg(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK, "%d", limit_set_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 5000);
@ -195,11 +196,11 @@ static void group_invite_test(AutoTox *autotoxes)
printf("Peer 4 successfully blocked from joining full group\n");
// founder removes password and increases peer limit to 100
tox_group_founder_set_password(tox0, groupnumber, nullptr, 0, &pass_set_err);
ck_assert_msg(pass_set_err == TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK, "%d", pass_set_err);
tox_group_set_password(tox0, groupnumber, nullptr, 0, &pass_set_err);
ck_assert_msg(pass_set_err == TOX_ERR_GROUP_SET_PASSWORD_OK, "%d", pass_set_err);
tox_group_founder_set_peer_limit(tox0, groupnumber, 100, &limit_set_err);
ck_assert_msg(limit_set_err == TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK, "%d", limit_set_err);
tox_group_set_peer_limit(tox0, groupnumber, 100, &limit_set_err);
ck_assert_msg(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK, "%d", limit_set_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 5000);
@ -214,9 +215,9 @@ static void group_invite_test(AutoTox *autotoxes)
printf("Peer 5 successfully joined the group\n");
// founder makes group private
Tox_Err_Group_Founder_Set_Privacy_State priv_err;
tox_group_founder_set_privacy_state(tox0, groupnumber, TOX_GROUP_PRIVACY_STATE_PRIVATE, &priv_err);
ck_assert_msg(priv_err == TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK, "%d", priv_err);
Tox_Err_Group_Set_Privacy_State priv_err;
tox_group_set_privacy_state(tox0, groupnumber, TOX_GROUP_PRIVACY_STATE_PRIVATE, &priv_err);
ck_assert_msg(priv_err == TOX_ERR_GROUP_SET_PRIVACY_STATE_OK, "%d", priv_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 5000);
@ -232,8 +233,8 @@ static void group_invite_test(AutoTox *autotoxes)
printf("Peer 6 failed to join private group via chat ID\n");
// founder makes group public again
tox_group_founder_set_privacy_state(tox0, groupnumber, TOX_GROUP_PRIVACY_STATE_PUBLIC, &priv_err);
ck_assert_msg(priv_err == TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK, "%d", priv_err);
tox_group_set_privacy_state(tox0, groupnumber, TOX_GROUP_PRIVACY_STATE_PUBLIC, &priv_err);
ck_assert_msg(priv_err == TOX_ERR_GROUP_SET_PRIVACY_STATE_OK, "%d", priv_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@ -260,8 +261,6 @@ static void group_invite_test(AutoTox *autotoxes)
}
printf("All tests passed!\n");
#endif // VANILLA_NACL
}
int main(void)

View File

@ -19,7 +19,7 @@ typedef struct State {
bool peer_joined;
bool message_sent;
bool message_received;
uint32_t pseudo_msg_id;
Tox_Group_Message_Id pseudo_msg_id;
bool private_message_received;
size_t custom_packets_received;
size_t custom_private_packets_received;
@ -44,6 +44,10 @@ typedef struct State {
#define TEST_CUSTOM_PACKET "Why'd ya spill yer beans?"
#define TEST_CUSTOM_PACKET_LEN (sizeof(TEST_CUSTOM_PACKET) - 1)
#define TEST_CUSTOM_PACKET_LARGE "Where is it I've read that someone condemned to death says or thinks, an hour before his death, that if he had to live on some high rock, on such a narrow ledge that he'd only room to stand, and the ocean, everlasting darkness, everlasting solitude, everlasting tempest around him, if he had to remain standing on a square yard of space all his life, a thousand years, eternity, it were better to live so than to die at once. Only to live, to live and live! Life, whatever it may be! ...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................0123456789"
#define TEST_CUSTOM_PACKET_LARGE_LEN (sizeof(TEST_CUSTOM_PACKET_LARGE) - 1)
static_assert(TEST_CUSTOM_PACKET_LARGE_LEN == TOX_GROUP_MAX_CUSTOM_LOSSY_PACKET_LENGTH, "Should be max");
#define TEST_CUSTOM_PRIVATE_PACKET "This is a custom private packet. Enjoy."
#define TEST_CUSTOM_PRIVATE_PACKET_LEN (sizeof(TEST_CUSTOM_PRIVATE_PACKET) - 1)
@ -67,28 +71,37 @@ static uint16_t get_message_checksum(const uint8_t *message, uint16_t length)
return sum;
}
static void group_invite_handler(Tox *tox, uint32_t friend_number, const uint8_t *invite_data, size_t length,
const uint8_t *group_name, size_t group_name_length, void *user_data)
static void group_invite_handler(const Tox_Event_Group_Invite *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
const uint32_t friend_number = tox_event_group_invite_get_friend_number(event);
const uint8_t *invite_data = tox_event_group_invite_get_invite_data(event);
const size_t length = tox_event_group_invite_get_invite_data_length(event);
printf("invite arrived; accepting\n");
Tox_Err_Group_Invite_Accept err_accept;
tox_group_invite_accept(tox, friend_number, invite_data, length, (const uint8_t *)PEER0_NICK, PEER0_NICK_LEN,
tox_group_invite_accept(autotox->tox, friend_number, invite_data, length, (const uint8_t *)PEER0_NICK, PEER0_NICK_LEN,
nullptr, 0, &err_accept);
ck_assert(err_accept == TOX_ERR_GROUP_INVITE_ACCEPT_OK);
}
static void group_join_fail_handler(Tox *tox, uint32_t groupnumber, Tox_Group_Join_Fail fail_type, void *user_data)
static void group_join_fail_handler(const Tox_Event_Group_Join_Fail *event, void *user_data)
{
const Tox_Group_Join_Fail fail_type = tox_event_group_join_fail_get_fail_type(event);
printf("join failed: %d\n", fail_type);
}
static void group_peer_join_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, void *user_data)
static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
const uint32_t peer_id = tox_event_group_peer_join_get_peer_id(event);
ck_assert_msg(state->peer_joined == false, "Peer timedout");
printf("peer %u joined, sending message\n", peer_id);
@ -96,9 +109,16 @@ static void group_peer_join_handler(Tox *tox, uint32_t groupnumber, uint32_t pee
state->peer_id = peer_id;
}
static void group_custom_private_packet_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, const uint8_t *data,
size_t length, void *user_data)
static void group_custom_private_packet_handler(const Tox_Event_Group_Custom_Private_Packet *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
const uint32_t groupnumber = tox_event_group_custom_private_packet_get_group_number(event);
const uint32_t peer_id = tox_event_group_custom_private_packet_get_peer_id(event);
const uint8_t *data = tox_event_group_custom_private_packet_get_data(event);
const size_t length = tox_event_group_custom_private_packet_get_data_length(event);
ck_assert_msg(length == TEST_CUSTOM_PRIVATE_PACKET_LEN,
"Failed to receive custom private packet. Invalid length: %zu\n", length);
@ -107,25 +127,25 @@ static void group_custom_private_packet_handler(Tox *tox, uint32_t groupnumber,
message_buf[length] = 0;
Tox_Err_Group_Peer_Query q_err;
size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &q_err);
size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, groupnumber, peer_id, &q_err);
ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH);
char peer_name[TOX_MAX_NAME_LENGTH + 1];
tox_group_peer_get_name(tox, groupnumber, peer_id, (uint8_t *) peer_name, &q_err);
tox_group_peer_get_name(autotox->tox, groupnumber, peer_id, (uint8_t *) peer_name, &q_err);
peer_name[peer_name_len] = 0;
ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0);
Tox_Err_Group_Self_Query s_err;
size_t self_name_len = tox_group_self_get_name_size(tox, groupnumber, &s_err);
size_t self_name_len = tox_group_self_get_name_size(autotox->tox, groupnumber, &s_err);
ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK);
ck_assert(self_name_len <= TOX_MAX_NAME_LENGTH);
char self_name[TOX_MAX_NAME_LENGTH + 1];
tox_group_self_get_name(tox, groupnumber, (uint8_t *) self_name, &s_err);
tox_group_self_get_name(autotox->tox, groupnumber, (uint8_t *)self_name, &s_err);
self_name[self_name_len] = 0;
ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK);
@ -134,17 +154,21 @@ static void group_custom_private_packet_handler(Tox *tox, uint32_t groupnumber,
printf("%s sent custom private packet to %s: %s\n", peer_name, self_name, message_buf);
ck_assert(memcmp(message_buf, TEST_CUSTOM_PRIVATE_PACKET, length) == 0);
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
++state->custom_private_packets_received;
}
static void group_custom_packet_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, const uint8_t *data,
size_t length, void *user_data)
static void group_custom_packet_handler(const Tox_Event_Group_Custom_Packet *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
const uint32_t groupnumber = tox_event_group_custom_packet_get_group_number(event);
const uint32_t peer_id = tox_event_group_custom_packet_get_peer_id(event);
const uint8_t *data = tox_event_group_custom_packet_get_data(event);
const size_t length = tox_event_group_custom_packet_get_data_length(event);
ck_assert_msg(length == TEST_CUSTOM_PACKET_LEN, "Failed to receive custom packet. Invalid length: %zu\n", length);
char message_buf[TOX_MAX_CUSTOM_PACKET_SIZE + 1];
@ -152,25 +176,25 @@ static void group_custom_packet_handler(Tox *tox, uint32_t groupnumber, uint32_t
message_buf[length] = 0;
Tox_Err_Group_Peer_Query q_err;
size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &q_err);
size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, groupnumber, peer_id, &q_err);
ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH);
char peer_name[TOX_MAX_NAME_LENGTH + 1];
tox_group_peer_get_name(tox, groupnumber, peer_id, (uint8_t *) peer_name, &q_err);
tox_group_peer_get_name(autotox->tox, groupnumber, peer_id, (uint8_t *)peer_name, &q_err);
peer_name[peer_name_len] = 0;
ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0);
Tox_Err_Group_Self_Query s_err;
size_t self_name_len = tox_group_self_get_name_size(tox, groupnumber, &s_err);
size_t self_name_len = tox_group_self_get_name_size(autotox->tox, groupnumber, &s_err);
ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK);
ck_assert(self_name_len <= TOX_MAX_NAME_LENGTH);
char self_name[TOX_MAX_NAME_LENGTH + 1];
tox_group_self_get_name(tox, groupnumber, (uint8_t *) self_name, &s_err);
tox_group_self_get_name(autotox->tox, groupnumber, (uint8_t *)self_name, &s_err);
self_name[self_name_len] = 0;
ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK);
@ -179,17 +203,39 @@ static void group_custom_packet_handler(Tox *tox, uint32_t groupnumber, uint32_t
printf("%s sent custom packet to %s: %s\n", peer_name, self_name, message_buf);
ck_assert(memcmp(message_buf, TEST_CUSTOM_PACKET, length) == 0);
State *state = (State *)autotox->state;
++state->custom_packets_received;
}
static void group_custom_packet_large_handler(const Tox_Event_Group_Custom_Packet *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
const uint8_t *data = tox_event_group_custom_packet_get_data(event);
const size_t length = tox_event_group_custom_packet_get_data_length(event);
ck_assert_msg(length == TEST_CUSTOM_PACKET_LARGE_LEN, "Failed to receive large custom packet. Invalid length: %zu\n", length);
ck_assert(memcmp(data, TEST_CUSTOM_PACKET_LARGE, length) == 0);
State *state = (State *)autotox->state;
++state->custom_packets_received;
}
static void group_message_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, TOX_MESSAGE_TYPE type,
const uint8_t *message, size_t length, uint32_t pseudo_msg_id, void *user_data)
static void group_message_handler(const Tox_Event_Group_Message *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
const uint32_t groupnumber = tox_event_group_message_get_group_number(event);
const uint32_t peer_id = tox_event_group_message_get_peer_id(event);
const uint8_t *message = tox_event_group_message_get_message(event);
const size_t length = tox_event_group_message_get_message_length(event);
const uint32_t pseudo_msg_id = tox_event_group_message_get_message_id(event);
ck_assert(!(length == IGNORE_MESSAGE_LEN && memcmp(message, IGNORE_MESSAGE, length) == 0));
ck_assert_msg(length == TEST_MESSAGE_LEN, "Failed to receive message. Invalid length: %zu\n", length);
@ -198,25 +244,25 @@ static void group_message_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_
message_buf[length] = 0;
Tox_Err_Group_Peer_Query q_err;
size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &q_err);
size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, groupnumber, peer_id, &q_err);
ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH);
char peer_name[TOX_MAX_NAME_LENGTH + 1];
tox_group_peer_get_name(tox, groupnumber, peer_id, (uint8_t *) peer_name, &q_err);
tox_group_peer_get_name(autotox->tox, groupnumber, peer_id, (uint8_t *)peer_name, &q_err);
peer_name[peer_name_len] = 0;
ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0);
Tox_Err_Group_Self_Query s_err;
size_t self_name_len = tox_group_self_get_name_size(tox, groupnumber, &s_err);
size_t self_name_len = tox_group_self_get_name_size(autotox->tox, groupnumber, &s_err);
ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK);
ck_assert(self_name_len <= TOX_MAX_NAME_LENGTH);
char self_name[TOX_MAX_NAME_LENGTH + 1];
tox_group_self_get_name(tox, groupnumber, (uint8_t *) self_name, &s_err);
tox_group_self_get_name(autotox->tox, groupnumber, (uint8_t *)self_name, &s_err);
self_name[self_name_len] = 0;
ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK);
@ -225,19 +271,24 @@ static void group_message_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_
printf("%s sent message to %s:(id:%u) %s\n", peer_name, self_name, pseudo_msg_id, message_buf);
ck_assert(memcmp(message_buf, TEST_MESSAGE, length) == 0);
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
state->message_received = true;
state->pseudo_msg_id = pseudo_msg_id;
}
static void group_private_message_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, TOX_MESSAGE_TYPE type,
const uint8_t *message, size_t length, void *user_data)
static void group_private_message_handler(const Tox_Event_Group_Private_Message *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
const uint32_t groupnumber = tox_event_group_private_message_get_group_number(event);
const uint32_t peer_id = tox_event_group_private_message_get_peer_id(event);
const Tox_Message_Type type = tox_event_group_private_message_get_message_type(event);
const uint8_t *message = tox_event_group_private_message_get_message(event);
const size_t length = tox_event_group_private_message_get_message_length(event);
const Tox_Group_Message_Id pseudo_msg_id = tox_event_group_private_message_get_message_id(event);
ck_assert_msg(length == TEST_PRIVATE_MESSAGE_LEN, "Failed to receive message. Invalid length: %zu\n", length);
char message_buf[TOX_GROUP_MAX_MESSAGE_LENGTH + 1];
@ -245,46 +296,46 @@ static void group_private_message_handler(Tox *tox, uint32_t groupnumber, uint32
message_buf[length] = 0;
Tox_Err_Group_Peer_Query q_err;
size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &q_err);
size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, groupnumber, peer_id, &q_err);
ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH);
char peer_name[TOX_MAX_NAME_LENGTH + 1];
tox_group_peer_get_name(tox, groupnumber, peer_id, (uint8_t *) peer_name, &q_err);
tox_group_peer_get_name(autotox->tox, groupnumber, peer_id, (uint8_t *)peer_name, &q_err);
peer_name[peer_name_len] = 0;
ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0);
Tox_Err_Group_Self_Query s_err;
size_t self_name_len = tox_group_self_get_name_size(tox, groupnumber, &s_err);
size_t self_name_len = tox_group_self_get_name_size(autotox->tox, groupnumber, &s_err);
ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK);
ck_assert(self_name_len <= TOX_MAX_NAME_LENGTH);
char self_name[TOX_MAX_NAME_LENGTH + 1];
tox_group_self_get_name(tox, groupnumber, (uint8_t *) self_name, &s_err);
tox_group_self_get_name(autotox->tox, groupnumber, (uint8_t *)self_name, &s_err);
self_name[self_name_len] = 0;
ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK);
ck_assert(memcmp(self_name, PEER1_NICK, self_name_len) == 0);
printf("%s sent private action to %s: %s\n", peer_name, self_name, message_buf);
printf("%s sent private action to %s:(id: %u) %s\n", peer_name, self_name, pseudo_msg_id, message_buf);
ck_assert(memcmp(message_buf, TEST_PRIVATE_MESSAGE, length) == 0);
ck_assert(type == TOX_MESSAGE_TYPE_ACTION);
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
state->private_message_received = true;
state->pseudo_msg_id = pseudo_msg_id;
}
static void group_message_handler_lossless_test(Tox *tox, uint32_t groupnumber, uint32_t peer_id, TOX_MESSAGE_TYPE type,
const uint8_t *message, size_t length, uint32_t pseudo_msg_id, void *user_data)
static void group_message_handler_lossless_test(const Tox_Event_Group_Message *event, void *user_data)
{
const uint8_t *message = tox_event_group_message_get_message(event);
const size_t length = tox_event_group_message_get_message_length(event);
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
@ -306,10 +357,11 @@ static void group_message_handler_lossless_test(Tox *tox, uint32_t groupnumber,
state->lossless_check = true;
}
}
static void group_message_handler_wraparound_test(Tox *tox, uint32_t groupnumber, uint32_t peer_id,
TOX_MESSAGE_TYPE type,
const uint8_t *message, size_t length, uint32_t pseudo_msg_id, void *user_data)
static void group_message_handler_wraparound_test(const Tox_Event_Group_Message *event, void *user_data)
{
const uint8_t *message = tox_event_group_message_get_message(event);
const size_t length = tox_event_group_message_get_message_length(event);
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
@ -331,14 +383,13 @@ static void group_message_handler_wraparound_test(Tox *tox, uint32_t groupnumber
static void group_message_test(AutoTox *autotoxes)
{
#ifndef VANILLA_NACL
ck_assert_msg(NUM_GROUP_TOXES >= 2, "NUM_GROUP_TOXES is too small: %d", NUM_GROUP_TOXES);
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
Tox *tox0 = autotoxes[0].tox;
Tox *tox1 = autotoxes[1].tox;
const Tox *tox1 = autotoxes[1].tox;
State *state0 = (State *)autotoxes[0].state;
State *state1 = (State *)autotoxes[1].state;
@ -347,15 +398,15 @@ static void group_message_test(AutoTox *autotoxes)
state0->pseudo_msg_id = 0;
state1->pseudo_msg_id = 1;
tox_callback_group_invite(tox1, group_invite_handler);
tox_callback_group_join_fail(tox1, group_join_fail_handler);
tox_callback_group_peer_join(tox1, group_peer_join_handler);
tox_callback_group_join_fail(tox0, group_join_fail_handler);
tox_callback_group_peer_join(tox0, group_peer_join_handler);
tox_callback_group_message(tox0, group_message_handler);
tox_callback_group_custom_packet(tox0, group_custom_packet_handler);
tox_callback_group_custom_private_packet(tox0, group_custom_private_packet_handler);
tox_callback_group_private_message(tox0, group_private_message_handler);
tox_events_callback_group_invite(autotoxes[1].dispatch, group_invite_handler);
tox_events_callback_group_join_fail(autotoxes[1].dispatch, group_join_fail_handler);
tox_events_callback_group_peer_join(autotoxes[1].dispatch, group_peer_join_handler);
tox_events_callback_group_join_fail(autotoxes[0].dispatch, group_join_fail_handler);
tox_events_callback_group_peer_join(autotoxes[0].dispatch, group_peer_join_handler);
tox_events_callback_group_message(autotoxes[0].dispatch, group_message_handler);
tox_events_callback_group_custom_packet(autotoxes[0].dispatch, group_custom_packet_handler);
tox_events_callback_group_custom_private_packet(autotoxes[0].dispatch, group_custom_private_packet_handler);
tox_events_callback_group_private_message(autotoxes[0].dispatch, group_private_message_handler);
Tox_Err_Group_Send_Message err_send;
@ -377,14 +428,16 @@ static void group_message_test(AutoTox *autotoxes)
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
if (state1->peer_joined && !state1->message_sent) {
tox_group_send_message(tox1, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)TEST_MESSAGE,
TEST_MESSAGE_LEN, &state1->pseudo_msg_id, &err_send);
state1->pseudo_msg_id = tox_group_send_message(
tox1, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)TEST_MESSAGE,
TEST_MESSAGE_LEN, &err_send);
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
state1->message_sent = true;
}
}
ck_assert_msg(state0->pseudo_msg_id == state1->pseudo_msg_id, "id0:%u id1:%u", state0->pseudo_msg_id, state1->pseudo_msg_id);
ck_assert_msg(state0->pseudo_msg_id == state1->pseudo_msg_id, "id0:%u id1:%u",
state0->pseudo_msg_id, state1->pseudo_msg_id);
// Make sure we're still connected to each friend
Tox_Connection conn_1 = tox_friend_get_connection_status(tox0, 0, nullptr);
@ -401,7 +454,7 @@ static void group_message_test(AutoTox *autotoxes)
// tox1 sends group a message which should not be seen by tox0's message handler
tox_group_send_message(tox1, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)IGNORE_MESSAGE,
IGNORE_MESSAGE_LEN, nullptr, &err_send);
IGNORE_MESSAGE_LEN, &err_send);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@ -409,14 +462,23 @@ static void group_message_test(AutoTox *autotoxes)
tox_group_set_ignore(tox0, group_number, state0->peer_id, false, &ig_err);
ck_assert_msg(ig_err == TOX_ERR_GROUP_SET_IGNORE_OK, "%d", ig_err);
fprintf(stderr, "Sending private message...\n");
fprintf(stderr, "Sending private action...\n");
// tox0 sends a private action to tox1
// tox1 sends a private action to tox0
Tox_Err_Group_Send_Private_Message m_err;
tox_group_send_private_message(tox1, group_number, state1->peer_id, TOX_MESSAGE_TYPE_ACTION,
(const uint8_t *)TEST_PRIVATE_MESSAGE, TEST_PRIVATE_MESSAGE_LEN, &m_err);
state1->pseudo_msg_id = tox_group_send_private_message(tox1, group_number, state1->peer_id,
TOX_MESSAGE_TYPE_ACTION, (const uint8_t *)TEST_PRIVATE_MESSAGE,
TEST_PRIVATE_MESSAGE_LEN, &m_err);
ck_assert_msg(m_err == TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_OK, "%d", m_err);
while (!state0->private_message_received) {
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
}
ck_assert_msg(state0->pseudo_msg_id == state1->pseudo_msg_id, "id0:%u id1:%u",
state0->pseudo_msg_id, state1->pseudo_msg_id);
fprintf(stderr, "Sending custom packets...\n");
// tox0 sends a lossless and lossy custom packet to tox1
@ -445,8 +507,20 @@ static void group_message_test(AutoTox *autotoxes)
ck_assert_msg(cperr == TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_OK, "%d", cperr);
while (!state0->private_message_received || state0->custom_packets_received < 2
|| state0->custom_private_packets_received < 2) {
while (state0->custom_packets_received < 2 || state0->custom_private_packets_received < 2) {
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
}
// tox0 sends a large max sized lossy custom packet
// overwrite callback for larger packet
tox_events_callback_group_custom_packet(autotoxes[0].dispatch, group_custom_packet_large_handler);
tox_group_send_custom_packet(tox1, group_number, false, (const uint8_t *)TEST_CUSTOM_PACKET_LARGE, TEST_CUSTOM_PACKET_LARGE_LEN,
&c_err);
ck_assert_msg(c_err == TOX_ERR_GROUP_SEND_CUSTOM_PACKET_OK, "%d", c_err);
while (state0->custom_packets_received < 3) {
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
}
@ -454,7 +528,7 @@ static void group_message_test(AutoTox *autotoxes)
fprintf(stderr, "Doing lossless packet test...\n");
tox_callback_group_message(tox1, group_message_handler_lossless_test);
tox_events_callback_group_message(autotoxes[1].dispatch, group_message_handler_lossless_test);
state1->last_msg_recv = -1;
// lossless and packet splitting/reassembly test
@ -475,7 +549,7 @@ static void group_message_test(AutoTox *autotoxes)
memcpy(m + 2, &checksum, sizeof(uint16_t));
tox_group_send_message(tox0, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)m, message_size, nullptr, &err_send);
tox_group_send_message(tox0, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)m, message_size, &err_send);
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
}
@ -485,7 +559,7 @@ static void group_message_test(AutoTox *autotoxes)
}
state1->last_msg_recv = -1;
tox_callback_group_message(tox1, group_message_handler_wraparound_test);
tox_events_callback_group_message(autotoxes[1].dispatch, group_message_handler_wraparound_test);
fprintf(stderr, "Doing wraparound test...\n");
@ -497,7 +571,7 @@ static void group_message_test(AutoTox *autotoxes)
memcpy(m, &i, sizeof(uint16_t));
tox_group_send_message(tox0, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)m, 2, nullptr, &err_send);
tox_group_send_message(tox0, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)m, 2, &err_send);
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
}
@ -512,7 +586,6 @@ static void group_message_test(AutoTox *autotoxes)
}
fprintf(stderr, "All tests passed!\n");
#endif // VANILLA_NACL
}
int main(void)
@ -538,6 +611,8 @@ int main(void)
#undef TEST_PRIVATE_MESSAGE_LEN
#undef TEST_CUSTOM_PACKET
#undef TEST_CUSTOM_PACKET_LEN
#undef TEST_CUSTOM_PACKET_LARGE
#undef TEST_CUSTOM_PACKET_LARGE_LEN
#undef TEST_CUSTOM_PRIVATE_PACKET
#undef TEST_CUSTOM_PRIVATE_PACKET_LEN
#undef IGNORE_MESSAGE

View File

@ -19,13 +19,13 @@
#define GROUP_NAME_LEN (sizeof(GROUP_NAME) - 1)
typedef struct Peer {
char name[TOX_MAX_NAME_LENGTH];
char name[TOX_MAX_NAME_LENGTH + 1];
size_t name_length;
uint32_t peer_id;
} Peer;
typedef struct State {
char self_name[TOX_MAX_NAME_LENGTH];
char self_name[TOX_MAX_NAME_LENGTH + 1];
size_t self_name_length;
uint32_t group_number;
@ -38,7 +38,6 @@ typedef struct State {
char mod_name1[TOX_MAX_NAME_LENGTH];
char mod_name2[TOX_MAX_NAME_LENGTH];
bool observer_check;
size_t observer_event_count;
char observer_name1[TOX_MAX_NAME_LENGTH];
@ -53,7 +52,7 @@ typedef struct State {
static bool all_peers_connected(AutoTox *autotoxes)
{
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
State *state = (State *)autotoxes[i].state;
const State *state = (const State *)autotoxes[i].state;
if (state->num_peers != NUM_GROUP_TOXES - 1) {
return false;
@ -146,7 +145,7 @@ static size_t get_state_index_by_nick(const AutoTox *autotoxes, size_t num_peers
ck_assert(name != nullptr && name_length <= TOX_MAX_NAME_LENGTH);
for (size_t i = 0; i < num_peers; ++i) {
State *state = (State *)autotoxes[i].state;
const State *state = (const State *)autotoxes[i].state;
if (memcmp(state->self_name, name, name_length) == 0) {
return i;
@ -156,29 +155,33 @@ static size_t get_state_index_by_nick(const AutoTox *autotoxes, size_t num_peers
ck_assert_msg(0, "Failed to find index");
}
static void group_join_fail_handler(Tox *tox, uint32_t group_number, Tox_Group_Join_Fail fail_type, void *user_data)
static void group_join_fail_handler(const Tox_Event_Group_Join_Fail *event, void *user_data)
{
const Tox_Group_Join_Fail fail_type = tox_event_group_join_fail_get_fail_type(event);
fprintf(stderr, "Failed to join group: %d", fail_type);
}
static void group_peer_join_handler(Tox *tox, uint32_t group_number, uint32_t peer_id, void *user_data)
static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
const uint32_t group_number = tox_event_group_peer_join_get_group_number(event);
const uint32_t peer_id = tox_event_group_peer_join_get_peer_id(event);
ck_assert(state->group_number == group_number);
char peer_name[TOX_MAX_NAME_LENGTH + 1];
Tox_Err_Group_Peer_Query q_err;
size_t peer_name_len = tox_group_peer_get_name_size(tox, group_number, peer_id, &q_err);
size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, group_number, peer_id, &q_err);
ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH);
tox_group_peer_get_name(tox, group_number, peer_id, (uint8_t *) peer_name, &q_err);
tox_group_peer_get_name(autotox->tox, group_number, peer_id, (uint8_t *) peer_name, &q_err);
peer_name[peer_name_len] = 0;
ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
@ -193,7 +196,7 @@ static void group_peer_join_handler(Tox *tox, uint32_t group_number, uint32_t pe
ck_assert(state->num_peers < NUM_GROUP_TOXES);
}
static void handle_mod(State *state, const char *peer_name, size_t peer_name_len, Tox_Group_Role role)
static void handle_mod(State *state, const char *peer_name, size_t peer_name_len)
{
if (state->mod_event_count == 0) {
ck_assert(memcmp(peer_name, state->mod_name1, peer_name_len) == 0);
@ -205,10 +208,9 @@ static void handle_mod(State *state, const char *peer_name, size_t peer_name_len
++state->mod_event_count;
state->mod_check = true;
ck_assert(role == TOX_GROUP_ROLE_MODERATOR);
}
static void handle_observer(State *state, const char *peer_name, size_t peer_name_len, Tox_Group_Role role)
static void handle_observer(State *state, const char *peer_name, size_t peer_name_len)
{
if (state->observer_event_count == 0) {
ck_assert(memcmp(peer_name, state->observer_name1, peer_name_len) == 0);
@ -220,10 +222,9 @@ static void handle_observer(State *state, const char *peer_name, size_t peer_nam
++state->observer_event_count;
state->observer_check = true;
ck_assert(role == TOX_GROUP_ROLE_OBSERVER);
}
static void handle_user(State *state, const char *peer_name, size_t peer_name_len, Tox_Group_Role role)
static void handle_user(State *state, const char *peer_name, size_t peer_name_len)
{
// event 1: observer1 gets promoted back to user
// event 2: observer2 gets promoted to moderator
@ -243,23 +244,25 @@ static void handle_user(State *state, const char *peer_name, size_t peer_name_le
++state->user_event_count;
state->user_check = true;
ck_assert(role == TOX_GROUP_ROLE_USER);
}
static void group_mod_event_handler(Tox *tox, uint32_t group_number, uint32_t source_peer_id, uint32_t target_peer_id,
Tox_Group_Mod_Event event, void *user_data)
static void group_mod_event_handler(const Tox_Event_Group_Moderation *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
const uint32_t group_number = tox_event_group_moderation_get_group_number(event);
const uint32_t target_peer_id = tox_event_group_moderation_get_target_peer_id(event);
const Tox_Group_Mod_Event mod_type = tox_event_group_moderation_get_mod_type(event);
ck_assert(state->group_number == group_number);
char peer_name[TOX_MAX_NAME_LENGTH + 1];
Tox_Err_Group_Peer_Query q_err;
size_t peer_name_len = tox_group_peer_get_name_size(tox, group_number, target_peer_id, &q_err);
size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, group_number, target_peer_id, &q_err);
if (q_err == TOX_ERR_GROUP_PEER_QUERY_PEER_NOT_FOUND) { // may occurr on sync attempts
return;
@ -268,26 +271,31 @@ static void group_mod_event_handler(Tox *tox, uint32_t group_number, uint32_t so
ck_assert_msg(q_err == TOX_ERR_GROUP_PEER_QUERY_OK, "error %d", q_err);
ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH);
tox_group_peer_get_name(tox, group_number, target_peer_id, (uint8_t *) peer_name, &q_err);
tox_group_peer_get_name(autotox->tox, group_number, target_peer_id, (uint8_t *) peer_name, &q_err);
peer_name[peer_name_len] = 0;
ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
Tox_Group_Role role = tox_group_peer_get_role(tox, group_number, target_peer_id, &q_err);
Tox_Group_Role role = tox_group_peer_get_role(autotox->tox, group_number, target_peer_id, &q_err);
ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(role <= TOX_GROUP_ROLE_OBSERVER);
switch (event) {
fprintf(stderr, "tox%u: got moderator event %d (%s), role = %s\n",
autotox->index, mod_type, tox_group_mod_event_to_string(mod_type),
tox_group_role_to_string(role));
switch (mod_type) {
case TOX_GROUP_MOD_EVENT_MODERATOR: {
handle_mod(state, peer_name, peer_name_len, role);
handle_mod(state, peer_name, peer_name_len);
break;
}
case TOX_GROUP_MOD_EVENT_OBSERVER: {
handle_observer(state, peer_name, peer_name_len, role);
handle_observer(state, peer_name, peer_name_len);
break;
}
case TOX_GROUP_MOD_EVENT_USER: {
handle_user(state, peer_name, peer_name_len, role);
handle_user(state, peer_name, peer_name_len);
break;
}
@ -298,7 +306,7 @@ static void group_mod_event_handler(Tox *tox, uint32_t group_number, uint32_t so
}
default: {
ck_assert_msg(0, "Got invalid moderator event %d", event);
ck_assert_msg(0, "Got invalid moderator event %d", mod_type);
return;
}
}
@ -310,7 +318,7 @@ static void check_self_role(AutoTox *autotoxes, uint32_t peer_id, Tox_Group_Role
Tox_Err_Group_Self_Query sq_err;
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
State *state = (State *)autotoxes[i].state;
const State *state = (const State *)autotoxes[i].state;
uint32_t self_peer_id = tox_group_self_get_peer_id(autotoxes[i].tox, state->group_number, &sq_err);
ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK);
@ -334,21 +342,21 @@ static void voice_state_message_test(AutoTox *autotox, Tox_Group_Voice_State voi
ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK);
Tox_Err_Group_Send_Message msg_err;
bool send_ret = tox_group_send_message(autotox->tox, state->group_number, TOX_MESSAGE_TYPE_NORMAL,
(const uint8_t *)"test", 4, nullptr, &msg_err);
tox_group_send_message(autotox->tox, state->group_number, TOX_MESSAGE_TYPE_NORMAL,
(const uint8_t *)"test", 4, &msg_err);
switch (self_role) {
case TOX_GROUP_ROLE_OBSERVER: {
ck_assert(!send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
break;
}
case TOX_GROUP_ROLE_USER: {
if (voice_state != TOX_GROUP_VOICE_STATE_ALL) {
ck_assert_msg(!send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS,
"%d, %d", send_ret, msg_err);
ck_assert_msg(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS,
"%d", msg_err);
} else {
ck_assert(send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
}
break;
@ -356,16 +364,16 @@ static void voice_state_message_test(AutoTox *autotox, Tox_Group_Voice_State voi
case TOX_GROUP_ROLE_MODERATOR: {
if (voice_state != TOX_GROUP_VOICE_STATE_FOUNDER) {
ck_assert(send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
} else {
ck_assert(!send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
}
break;
}
case TOX_GROUP_ROLE_FOUNDER: {
ck_assert(send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
break;
}
}
@ -374,13 +382,13 @@ static void voice_state_message_test(AutoTox *autotox, Tox_Group_Voice_State voi
static bool all_peers_got_voice_state_change(AutoTox *autotoxes, uint32_t num_toxes,
Tox_Group_Voice_State expected_voice_state)
{
Tox_Err_Group_State_Queries query_err;
Tox_Err_Group_State_Query query_err;
for (uint32_t i = 0; i < num_toxes; ++i) {
const State *state = (State *)autotoxes[i].state;
Tox_Group_Voice_State voice_state = tox_group_get_voice_state(autotoxes[i].tox, state->group_number, &query_err);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERY_OK);
if (voice_state != expected_voice_state) {
return false;
@ -394,10 +402,10 @@ static void check_voice_state(AutoTox *autotoxes, uint32_t num_toxes)
{
// founder sets voice state to Moderator
const State *state = (State *)autotoxes[0].state;
Tox_Err_Group_Founder_Set_Voice_State voice_set_err;
tox_group_founder_set_voice_state(autotoxes[0].tox, state->group_number, TOX_GROUP_VOICE_STATE_MODERATOR,
Tox_Err_Group_Set_Voice_State voice_set_err;
tox_group_set_voice_state(autotoxes[0].tox, state->group_number, TOX_GROUP_VOICE_STATE_MODERATOR,
&voice_set_err);
ck_assert(voice_set_err == TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_OK);
ck_assert(voice_set_err == TOX_ERR_GROUP_SET_VOICE_STATE_OK);
for (uint32_t i = 0; i < num_toxes; ++i) {
do {
@ -407,8 +415,8 @@ static void check_voice_state(AutoTox *autotoxes, uint32_t num_toxes)
voice_state_message_test(&autotoxes[i], TOX_GROUP_VOICE_STATE_MODERATOR);
}
tox_group_founder_set_voice_state(autotoxes[0].tox, state->group_number, TOX_GROUP_VOICE_STATE_FOUNDER, &voice_set_err);
ck_assert(voice_set_err == TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_OK);
tox_group_set_voice_state(autotoxes[0].tox, state->group_number, TOX_GROUP_VOICE_STATE_FOUNDER, &voice_set_err);
ck_assert(voice_set_err == TOX_ERR_GROUP_SET_VOICE_STATE_OK);
for (uint32_t i = 0; i < num_toxes; ++i) {
do {
@ -418,8 +426,8 @@ static void check_voice_state(AutoTox *autotoxes, uint32_t num_toxes)
voice_state_message_test(&autotoxes[i], TOX_GROUP_VOICE_STATE_FOUNDER);
}
tox_group_founder_set_voice_state(autotoxes[0].tox, state->group_number, TOX_GROUP_VOICE_STATE_ALL, &voice_set_err);
ck_assert(voice_set_err == TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_OK);
tox_group_set_voice_state(autotoxes[0].tox, state->group_number, TOX_GROUP_VOICE_STATE_ALL, &voice_set_err);
ck_assert(voice_set_err == TOX_ERR_GROUP_SET_VOICE_STATE_OK);
for (uint32_t i = 0; i < num_toxes; ++i) {
do {
@ -432,7 +440,6 @@ static void check_voice_state(AutoTox *autotoxes, uint32_t num_toxes)
static void group_moderation_test(AutoTox *autotoxes)
{
#ifndef VANILLA_NACL
ck_assert_msg(NUM_GROUP_TOXES >= 4, "NUM_GROUP_TOXES is too small: %d", NUM_GROUP_TOXES);
ck_assert_msg(NUM_GROUP_TOXES < 10, "NUM_GROUP_TOXES is too big: %d", NUM_GROUP_TOXES);
@ -444,9 +451,9 @@ static void group_moderation_test(AutoTox *autotoxes)
snprintf(state->self_name, sizeof(state->self_name), "peer_%zu", i);
state->self_name[name_length] = 0;
tox_callback_group_join_fail(autotoxes[i].tox, group_join_fail_handler);
tox_callback_group_peer_join(autotoxes[i].tox, group_peer_join_handler);
tox_callback_group_moderation(autotoxes[i].tox, group_mod_event_handler);
tox_events_callback_group_join_fail(autotoxes[i].dispatch, group_join_fail_handler);
tox_events_callback_group_peer_join(autotoxes[i].dispatch, group_peer_join_handler);
tox_events_callback_group_moderation(autotoxes[i].dispatch, group_mod_event_handler);
}
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@ -465,11 +472,11 @@ static void group_moderation_test(AutoTox *autotoxes)
ck_assert_msg(err_new == TOX_ERR_GROUP_NEW_OK, "Failed to create group. error: %d\n", err_new);
/* Founder gets chat ID */
Tox_Err_Group_State_Queries id_err;
Tox_Err_Group_State_Query id_err;
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(tox0, state0->group_number, chat_id, &id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "Failed to get chat ID. error: %d", id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get chat ID. error: %d", id_err);
fprintf(stderr, "Peers attemping to join DHT group via the chat ID\n");
@ -509,7 +516,7 @@ static void group_moderation_test(AutoTox *autotoxes)
/* all peers should be user role except founder */
for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) {
State *state = (State *)autotoxes[i].state;
const State *state = (const State *)autotoxes[i].state;
self_role = tox_group_self_get_role(autotoxes[i].tox, state->group_number, &sq_err);
ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK);
ck_assert(self_role == TOX_GROUP_ROLE_USER);
@ -518,9 +525,9 @@ static void group_moderation_test(AutoTox *autotoxes)
/* founder sets first peer to moderator */
fprintf(stderr, "Founder setting %s to moderator\n", state0->peers[0].name);
Tox_Err_Group_Mod_Set_Role role_err;
tox_group_mod_set_role(tox0, state0->group_number, state0->peers[0].peer_id, TOX_GROUP_ROLE_MODERATOR, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_MOD_SET_ROLE_OK, "Failed to set moderator. error: %d", role_err);
Tox_Err_Group_Set_Role role_err;
tox_group_set_role(tox0, state0->group_number, state0->peers[0].peer_id, TOX_GROUP_ROLE_MODERATOR, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set moderator. error: %d", role_err);
// manually flag the role setter because they don't get a callback
state0->mod_check = true;
@ -534,8 +541,8 @@ static void group_moderation_test(AutoTox *autotoxes)
/* founder sets second and third peer to observer */
fprintf(stderr, "Founder setting %s to observer\n", state0->peers[1].name);
tox_group_mod_set_role(tox0, state0->group_number, state0->peers[1].peer_id, TOX_GROUP_ROLE_OBSERVER, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_MOD_SET_ROLE_OK, "Failed to set observer. error: %d", role_err);
tox_group_set_role(tox0, state0->group_number, state0->peers[1].peer_id, TOX_GROUP_ROLE_OBSERVER, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set observer. error: %d", role_err);
state0->observer_check = true;
++state0->observer_event_count;
@ -545,8 +552,8 @@ static void group_moderation_test(AutoTox *autotoxes)
fprintf(stderr, "Founder setting %s to observer\n", state0->peers[2].name);
tox_group_mod_set_role(tox0, state0->group_number, state0->peers[2].peer_id, TOX_GROUP_ROLE_OBSERVER, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_MOD_SET_ROLE_OK, "Failed to set observer. error: %d", role_err);
tox_group_set_role(tox0, state0->group_number, state0->peers[2].peer_id, TOX_GROUP_ROLE_OBSERVER, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set observer. error: %d", role_err);
state0->observer_check = true;
++state0->observer_event_count;
@ -571,8 +578,8 @@ static void group_moderation_test(AutoTox *autotoxes)
fprintf(stderr, "%s is promoting %s back to user\n", state1->self_name, state0->peers[1].name);
tox_group_mod_set_role(tox1, state1->group_number, obs_peer_id, TOX_GROUP_ROLE_USER, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_MOD_SET_ROLE_OK, "Failed to promote observer back to user. error: %d",
tox_group_set_role(tox1, state1->group_number, obs_peer_id, TOX_GROUP_ROLE_USER, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to promote observer back to user. error: %d",
role_err);
state1->user_check = true;
@ -584,8 +591,8 @@ static void group_moderation_test(AutoTox *autotoxes)
/* founder assigns third peer to moderator (this triggers two events: user and moderator) */
fprintf(stderr, "Founder setting %s to moderator\n", state0->peers[2].name);
tox_group_mod_set_role(tox0, state0->group_number, state0->peers[2].peer_id, TOX_GROUP_ROLE_MODERATOR, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_MOD_SET_ROLE_OK, "Failed to set moderator. error: %d", role_err);
tox_group_set_role(tox0, state0->group_number, state0->peers[2].peer_id, TOX_GROUP_ROLE_MODERATOR, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set moderator. error: %d", role_err);
state0->mod_check = true;
++state0->mod_event_count;
@ -597,18 +604,27 @@ static void group_moderation_test(AutoTox *autotoxes)
/* moderator attempts to demote and kick founder */
uint32_t founder_peer_id = get_peer_id_by_nick(state1->peers, NUM_GROUP_TOXES - 1, state0->self_name);
tox_group_mod_set_role(tox1, state1->group_number, founder_peer_id, TOX_GROUP_ROLE_OBSERVER, &role_err);
ck_assert_msg(role_err != TOX_ERR_GROUP_MOD_SET_ROLE_OK, "Mod set founder to observer");
tox_group_set_role(tox1, state1->group_number, founder_peer_id, TOX_GROUP_ROLE_OBSERVER, &role_err);
ck_assert_msg(role_err != TOX_ERR_GROUP_SET_ROLE_OK, "Mod set founder to observer");
Tox_Err_Group_Mod_Kick_Peer k_err;
tox_group_mod_kick_peer(tox1, state1->group_number, founder_peer_id, &k_err);
ck_assert_msg(k_err != TOX_ERR_GROUP_MOD_KICK_PEER_OK, "Mod kicked founder");
Tox_Err_Group_Kick_Peer k_err;
tox_group_kick_peer(tox1, state1->group_number, founder_peer_id, &k_err);
ck_assert_msg(k_err != TOX_ERR_GROUP_KICK_PEER_OK, "Mod kicked founder");
/* the moderator about to be kicked changes the topic to trigger the founder to
* re-sign and redistribute it after the kick.
*/
const State *state_x = (const State *)autotoxes[idx].state;
Tox *tox_x = autotoxes[idx].tox;
Tox_Err_Group_Topic_Set topic_err;
tox_group_set_topic(tox_x, state_x->group_number, nullptr, 0, &topic_err);
ck_assert(topic_err == TOX_ERR_GROUP_TOPIC_SET_OK);
/* founder kicks moderator (this triggers two events: user and kick) */
fprintf(stderr, "Founder is kicking %s\n", state0->peers[0].name);
tox_group_mod_kick_peer(tox0, state0->group_number, state0->peers[0].peer_id, &k_err);
ck_assert_msg(k_err == TOX_ERR_GROUP_MOD_KICK_PEER_OK, "Failed to kick peer. error: %d", k_err);
tox_group_kick_peer(tox0, state0->group_number, state0->peers[0].peer_id, &k_err);
ck_assert_msg(k_err == TOX_ERR_GROUP_KICK_PEER_OK, "Failed to kick peer. error: %d", k_err);
state0->kick_check = true;
check_mod_event(autotoxes, NUM_GROUP_TOXES, TOX_GROUP_MOD_EVENT_KICK);
@ -616,9 +632,8 @@ static void group_moderation_test(AutoTox *autotoxes)
fprintf(stderr, "All peers successfully received kick event\n");
fprintf(stderr, "Founder is demoting moderator to user\n");
tox_group_mod_set_role(tox0, state0->group_number, state0->peers[2].peer_id, TOX_GROUP_ROLE_USER, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_MOD_SET_ROLE_OK, "Failed to demote peer 3 to User. error: %d", role_err);
tox_group_set_role(tox0, state0->group_number, state0->peers[2].peer_id, TOX_GROUP_ROLE_USER, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to demote peer 3 to User. error: %d", role_err);
state0->user_check = true;
++state0->user_event_count;
@ -634,7 +649,6 @@ static void group_moderation_test(AutoTox *autotoxes)
}
fprintf(stderr, "All tests passed!\n");
#endif // VANILLA_NACL
}
int main(void)

View File

@ -26,17 +26,23 @@ typedef struct State {
#define PEER0_NICK_LEN (sizeof(PEER0_NICK) -1)
#define NEW_USER_STATUS TOX_USER_STATUS_BUSY
static void group_invite_handler(Tox *tox, uint32_t friend_number, const uint8_t *invite_data, size_t length,
const uint8_t *group_name, size_t group_name_length, void *user_data)
static void group_invite_handler(const Tox_Event_Group_Invite *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
const uint32_t friend_number = tox_event_group_invite_get_friend_number(event);
const uint8_t *invite_data = tox_event_group_invite_get_invite_data(event);
const size_t length = tox_event_group_invite_get_invite_data_length(event);
Tox_Err_Group_Invite_Accept err_accept;
tox_group_invite_accept(tox, friend_number, invite_data, length, (const uint8_t *)"test2", 5,
tox_group_invite_accept(autotox->tox, friend_number, invite_data, length, (const uint8_t *)"test2", 5,
nullptr, 0, &err_accept);
ck_assert(err_accept == TOX_ERR_GROUP_INVITE_ACCEPT_OK);
}
static void group_peer_join_handler(Tox *tox, uint32_t group_number, uint32_t peer_id, void *user_data)
static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
@ -52,28 +58,28 @@ static void group_peer_join_handler(Tox *tox, uint32_t group_number, uint32_t pe
*/
static int has_correct_group_state(const Tox *tox, uint32_t group_number, const uint8_t *expected_chat_id)
{
Tox_Err_Group_State_Queries query_err;
Tox_Err_Group_State_Query query_err;
Tox_Group_Privacy_State priv_state = tox_group_get_privacy_state(tox, group_number, &query_err);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERY_OK);
if (priv_state != NEW_PRIV_STATE) {
return -1;
}
size_t pass_len = tox_group_get_password_size(tox, group_number, &query_err);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERY_OK);
uint8_t password[TOX_GROUP_MAX_PASSWORD_SIZE];
tox_group_get_password(tox, group_number, password, &query_err);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERY_OK);
if (pass_len != PASS_LEN || memcmp(password, PASSWORD, pass_len) != 0) {
return -2;
}
size_t gname_len = tox_group_get_name_size(tox, group_number, &query_err);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERY_OK);
uint8_t group_name[TOX_GROUP_MAX_GROUP_NAME_LENGTH];
tox_group_get_name(tox, group_number, group_name, &query_err);
@ -87,17 +93,17 @@ static int has_correct_group_state(const Tox *tox, uint32_t group_number, const
}
Tox_Group_Topic_Lock topic_lock = tox_group_get_topic_lock(tox, group_number, &query_err);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERY_OK);
if (topic_lock != TOX_GROUP_TOPIC_LOCK_DISABLED) {
return -5;
}
Tox_Err_Group_State_Queries id_err;
Tox_Err_Group_State_Query id_err;
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(tox, group_number, chat_id, &id_err);
ck_assert(id_err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(id_err == TOX_ERR_GROUP_STATE_QUERY_OK);
if (memcmp(chat_id, expected_chat_id, TOX_GROUP_CHAT_ID_SIZE) != 0) {
return -6;
@ -120,7 +126,7 @@ static int has_correct_self_state(const Tox *tox, uint32_t group_number, const u
return -1;
}
TOX_USER_STATUS self_status = tox_group_self_get_status(tox, group_number, &sq_err);
Tox_User_Status self_status = tox_group_self_get_status(tox, group_number, &sq_err);
ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK);
if (self_status != NEW_USER_STATUS) {
@ -148,12 +154,11 @@ static int has_correct_self_state(const Tox *tox, uint32_t group_number, const u
static void group_save_test(AutoTox *autotoxes)
{
#ifndef VANILLA_NACL
ck_assert_msg(NUM_GROUP_TOXES > 1, "NUM_GROUP_TOXES is too small: %d", NUM_GROUP_TOXES);
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
tox_callback_group_invite(autotoxes[i].tox, group_invite_handler);
tox_callback_group_peer_join(autotoxes[i].tox, group_peer_join_handler);
tox_events_callback_group_invite(autotoxes[i].dispatch, group_invite_handler);
tox_events_callback_group_peer_join(autotoxes[i].dispatch, group_peer_join_handler);
}
Tox *tox0 = autotoxes[0].tox;
@ -169,9 +174,9 @@ static void group_save_test(AutoTox *autotoxes)
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
Tox_Err_Group_State_Queries id_err;
Tox_Err_Group_State_Query id_err;
tox_group_get_chat_id(tox0, group_number, chat_id, &id_err);
ck_assert(id_err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(id_err == TOX_ERR_GROUP_STATE_QUERY_OK);
uint8_t founder_pk[TOX_GROUP_PEER_PUBLIC_KEY_SIZE];
@ -179,7 +184,6 @@ static void group_save_test(AutoTox *autotoxes)
tox_group_self_get_public_key(tox0, group_number, founder_pk, &sq_err);
ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK);
Tox_Err_Group_Invite_Friend err_invite;
tox_group_invite_friend(tox0, group_number, 0, &err_invite);
@ -196,21 +200,21 @@ static void group_save_test(AutoTox *autotoxes)
tox_group_set_topic(tox0, group_number, (const uint8_t *)TOPIC, TOPIC_LEN, &top_err);
ck_assert(top_err == TOX_ERR_GROUP_TOPIC_SET_OK);
Tox_Err_Group_Founder_Set_Topic_Lock lock_set_err;
tox_group_founder_set_topic_lock(tox0, group_number, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err);
ck_assert(lock_set_err == TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK);
Tox_Err_Group_Set_Topic_Lock lock_set_err;
tox_group_set_topic_lock(tox0, group_number, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err);
ck_assert(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK);
Tox_Err_Group_Founder_Set_Privacy_State priv_err;
tox_group_founder_set_privacy_state(tox0, group_number, NEW_PRIV_STATE, &priv_err);
ck_assert(priv_err == TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK);
Tox_Err_Group_Set_Privacy_State priv_err;
tox_group_set_privacy_state(tox0, group_number, NEW_PRIV_STATE, &priv_err);
ck_assert(priv_err == TOX_ERR_GROUP_SET_PRIVACY_STATE_OK);
Tox_Err_Group_Founder_Set_Password pass_set_err;
tox_group_founder_set_password(tox0, group_number, (const uint8_t *)PASSWORD, PASS_LEN, &pass_set_err);
ck_assert(pass_set_err == TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK);
Tox_Err_Group_Set_Password pass_set_err;
tox_group_set_password(tox0, group_number, (const uint8_t *)PASSWORD, PASS_LEN, &pass_set_err);
ck_assert(pass_set_err == TOX_ERR_GROUP_SET_PASSWORD_OK);
Tox_Err_Group_Founder_Set_Peer_Limit limit_set_err;
tox_group_founder_set_peer_limit(tox0, group_number, PEER_LIMIT, &limit_set_err);
ck_assert(limit_set_err == TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK);
Tox_Err_Group_Set_Peer_Limit limit_set_err;
tox_group_set_peer_limit(tox0, group_number, PEER_LIMIT, &limit_set_err);
ck_assert(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK);
// change self state
Tox_Err_Group_Self_Name_Set n_err;
@ -242,8 +246,8 @@ static void group_save_test(AutoTox *autotoxes)
ck_assert(options != nullptr);
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
tox_options_set_savedata_data(options, save, save_length);
tox_options_set_experimental_groups_persistence(options, true);
Tox *new_tox = tox_new_log(options, nullptr, nullptr);
@ -270,8 +274,6 @@ static void group_save_test(AutoTox *autotoxes)
tox_kill(new_tox);
printf("All tests passed!\n");
#endif // VANILLA_NACL
}
int main(void)
@ -281,7 +283,11 @@ int main(void)
Run_Auto_Options autotest_opts = default_run_auto_options();
autotest_opts.graph = GRAPH_COMPLETE;
run_auto_test(nullptr, NUM_GROUP_TOXES, group_save_test, sizeof(State), &autotest_opts);
Tox_Options *opts = tox_options_new(nullptr);
ck_assert(opts != nullptr);
tox_options_set_experimental_groups_persistence(opts, true);
run_auto_test(opts, NUM_GROUP_TOXES, group_save_test, sizeof(State), &autotest_opts);
tox_options_free(opts);
return 0;
}

View File

@ -60,66 +60,97 @@ static bool all_group_peers_connected(const AutoTox *autotoxes, uint32_t tox_cou
return true;
}
static void group_topic_lock_handler(Tox *tox, uint32_t groupnumber, Tox_Group_Topic_Lock topic_lock,
static void group_topic_lock_handler(const Tox_Event_Group_Topic_Lock *event,
void *user_data)
{
Tox_Err_Group_State_Queries err;
Tox_Group_Topic_Lock current_topic_lock = tox_group_get_topic_lock(tox, groupnumber, &err);
const AutoTox *autotox = (const AutoTox *)user_data;
ck_assert(autotox != nullptr);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK);
const uint32_t groupnumber = tox_event_group_topic_lock_get_group_number(event);
const Tox_Group_Topic_Lock topic_lock = tox_event_group_topic_lock_get_topic_lock(event);
Tox_Err_Group_State_Query err;
Tox_Group_Topic_Lock current_topic_lock = tox_group_get_topic_lock(autotox->tox, groupnumber, &err);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERY_OK);
ck_assert_msg(current_topic_lock == topic_lock, "topic locks don't match in callback: %d %d",
topic_lock, current_topic_lock);
}
static void group_voice_state_handler(Tox *tox, uint32_t groupnumber, Tox_Group_Voice_State voice_state,
static void group_voice_state_handler(const Tox_Event_Group_Voice_State *event,
void *user_data)
{
Tox_Err_Group_State_Queries err;
Tox_Group_Voice_State current_voice_state = tox_group_get_voice_state(tox, groupnumber, &err);
const AutoTox *autotox = (const AutoTox *)user_data;
ck_assert(autotox != nullptr);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK);
const uint32_t groupnumber = tox_event_group_voice_state_get_group_number(event);
const Tox_Group_Voice_State voice_state = tox_event_group_voice_state_get_voice_state(event);
Tox_Err_Group_State_Query err;
Tox_Group_Voice_State current_voice_state = tox_group_get_voice_state(autotox->tox, groupnumber, &err);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERY_OK);
ck_assert_msg(current_voice_state == voice_state, "voice states don't match in callback: %d %d",
voice_state, current_voice_state);
}
static void group_privacy_state_handler(Tox *tox, uint32_t groupnumber, Tox_Group_Privacy_State privacy_state,
static void group_privacy_state_handler(const Tox_Event_Group_Privacy_State *event,
void *user_data)
{
Tox_Err_Group_State_Queries err;
Tox_Group_Privacy_State current_pstate = tox_group_get_privacy_state(tox, groupnumber, &err);
const AutoTox *autotox = (const AutoTox *)user_data;
ck_assert(autotox != nullptr);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK);
const uint32_t groupnumber = tox_event_group_privacy_state_get_group_number(event);
const Tox_Group_Privacy_State privacy_state = tox_event_group_privacy_state_get_privacy_state(event);
Tox_Err_Group_State_Query err;
Tox_Group_Privacy_State current_pstate = tox_group_get_privacy_state(autotox->tox, groupnumber, &err);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERY_OK);
ck_assert_msg(current_pstate == privacy_state, "privacy states don't match in callback");
}
static void group_peer_limit_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_limit, void *user_data)
static void group_peer_limit_handler(const Tox_Event_Group_Peer_Limit *event, void *user_data)
{
Tox_Err_Group_State_Queries err;
uint32_t current_plimit = tox_group_get_peer_limit(tox, groupnumber, &err);
const AutoTox *autotox = (const AutoTox *)user_data;
ck_assert(autotox != nullptr);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK);
const uint32_t groupnumber = tox_event_group_peer_limit_get_group_number(event);
const uint32_t peer_limit = tox_event_group_peer_limit_get_peer_limit(event);
Tox_Err_Group_State_Query err;
uint32_t current_plimit = tox_group_get_peer_limit(autotox->tox, groupnumber, &err);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERY_OK);
ck_assert_msg(peer_limit == current_plimit,
"Peer limits don't match in callback: %u, %u\n", peer_limit, current_plimit);
}
static void group_password_handler(Tox *tox, uint32_t groupnumber, const uint8_t *password, size_t length,
static void group_password_handler(const Tox_Event_Group_Password *event,
void *user_data)
{
Tox_Err_Group_State_Queries err;
size_t curr_pwlength = tox_group_get_password_size(tox, groupnumber, &err);
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK);
const uint32_t groupnumber = tox_event_group_password_get_group_number(event);
const uint8_t *password = tox_event_group_password_get_password(event);
const size_t length = tox_event_group_password_get_password_length(event);
Tox_Err_Group_State_Query err;
size_t curr_pwlength = tox_group_get_password_size(autotox->tox, groupnumber, &err);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERY_OK);
ck_assert(length == curr_pwlength);
uint8_t current_password[TOX_GROUP_MAX_PASSWORD_SIZE];
tox_group_get_password(tox, groupnumber, current_password, &err);
tox_group_get_password(autotox->tox, groupnumber, current_password, &err);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERY_OK);
ck_assert_msg(memcmp(current_password, password, length) == 0,
"Passwords don't match: %s, %s", password, current_password);
}
static void group_peer_join_handler(Tox *tox, uint32_t group_number, uint32_t peer_id, void *user_data)
static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
@ -137,24 +168,24 @@ static int check_group_state(const Tox *tox, uint32_t groupnumber, uint32_t peer
Tox_Group_Privacy_State priv_state, Tox_Group_Voice_State voice_state,
const uint8_t *password, size_t pass_len, Tox_Group_Topic_Lock topic_lock)
{
Tox_Err_Group_State_Queries query_err;
Tox_Err_Group_State_Query query_err;
Tox_Group_Privacy_State my_priv_state = tox_group_get_privacy_state(tox, groupnumber, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "Failed to get privacy state: %d", query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get privacy state: %d", query_err);
if (my_priv_state != priv_state) {
return -1;
}
uint32_t my_peer_limit = tox_group_get_peer_limit(tox, groupnumber, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "Failed to get peer limit: %d", query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get peer limit: %d", query_err);
if (my_peer_limit != peer_limit) {
return -2;
}
size_t my_pass_len = tox_group_get_password_size(tox, groupnumber, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "Failed to get password size: %d", query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get password size: %d", query_err);
if (my_pass_len != pass_len) {
return -5;
@ -163,10 +194,10 @@ static int check_group_state(const Tox *tox, uint32_t groupnumber, uint32_t peer
if (password != nullptr && my_pass_len > 0) {
ck_assert(my_pass_len <= TOX_GROUP_MAX_PASSWORD_SIZE);
uint8_t my_pass[TOX_GROUP_MAX_PASSWORD_SIZE];
uint8_t my_pass[TOX_GROUP_MAX_PASSWORD_SIZE + 1];
tox_group_get_password(tox, groupnumber, my_pass, &query_err);
my_pass[my_pass_len] = 0;
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "Failed to get password: %d", query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get password: %d", query_err);
if (memcmp(my_pass, password, my_pass_len) != 0) {
return -6;
@ -175,7 +206,7 @@ static int check_group_state(const Tox *tox, uint32_t groupnumber, uint32_t peer
/* Group name should never change */
size_t my_gname_len = tox_group_get_name_size(tox, groupnumber, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "Failed to get group name size: %d", query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get group name size: %d", query_err);
if (my_gname_len != GROUP_NAME_LEN) {
return -7;
@ -183,7 +214,7 @@ static int check_group_state(const Tox *tox, uint32_t groupnumber, uint32_t peer
ck_assert(my_gname_len <= TOX_GROUP_MAX_GROUP_NAME_LENGTH);
uint8_t my_gname[TOX_GROUP_MAX_GROUP_NAME_LENGTH];
uint8_t my_gname[TOX_GROUP_MAX_GROUP_NAME_LENGTH + 1];
tox_group_get_name(tox, groupnumber, my_gname, &query_err);
my_gname[my_gname_len] = 0;
@ -192,14 +223,14 @@ static int check_group_state(const Tox *tox, uint32_t groupnumber, uint32_t peer
}
Tox_Group_Topic_Lock current_topic_lock = tox_group_get_topic_lock(tox, groupnumber, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "Failed to get topic lock: %d", query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get topic lock: %d", query_err);
if (current_topic_lock != topic_lock) {
return -9;
}
Tox_Group_Voice_State current_voice_state = tox_group_get_voice_state(tox, groupnumber, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "Failed to get voice state: %d", query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get voice state: %d", query_err);
if (current_voice_state != voice_state) {
return -10;
@ -213,41 +244,40 @@ static void set_group_state(Tox *tox, uint32_t groupnumber, uint32_t peer_limit,
Tox_Group_Topic_Lock topic_lock)
{
Tox_Err_Group_Founder_Set_Peer_Limit limit_set_err;
tox_group_founder_set_peer_limit(tox, groupnumber, peer_limit, &limit_set_err);
ck_assert_msg(limit_set_err == TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK, "failed to set peer limit: %d", limit_set_err);
Tox_Err_Group_Set_Peer_Limit limit_set_err;
tox_group_set_peer_limit(tox, groupnumber, peer_limit, &limit_set_err);
ck_assert_msg(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK, "failed to set peer limit: %d", limit_set_err);
Tox_Err_Group_Founder_Set_Privacy_State priv_err;
tox_group_founder_set_privacy_state(tox, groupnumber, priv_state, &priv_err);
ck_assert_msg(priv_err == TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK, "failed to set privacy state: %d", priv_err);
Tox_Err_Group_Set_Privacy_State priv_err;
tox_group_set_privacy_state(tox, groupnumber, priv_state, &priv_err);
ck_assert_msg(priv_err == TOX_ERR_GROUP_SET_PRIVACY_STATE_OK, "failed to set privacy state: %d", priv_err);
Tox_Err_Group_Founder_Set_Password pass_set_err;
tox_group_founder_set_password(tox, groupnumber, password, pass_len, &pass_set_err);
ck_assert_msg(pass_set_err == TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK, "failed to set password: %d", pass_set_err);
Tox_Err_Group_Set_Password pass_set_err;
tox_group_set_password(tox, groupnumber, password, pass_len, &pass_set_err);
ck_assert_msg(pass_set_err == TOX_ERR_GROUP_SET_PASSWORD_OK, "failed to set password: %d", pass_set_err);
Tox_Err_Group_Founder_Set_Topic_Lock lock_set_err;
tox_group_founder_set_topic_lock(tox, groupnumber, topic_lock, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK, "failed to set topic lock: %d",
Tox_Err_Group_Set_Topic_Lock lock_set_err;
tox_group_set_topic_lock(tox, groupnumber, topic_lock, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to set topic lock: %d",
lock_set_err);
Tox_Err_Group_Founder_Set_Voice_State voice_set_err;
tox_group_founder_set_voice_state(tox, groupnumber, voice_state, &voice_set_err);
ck_assert_msg(voice_set_err == TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_OK, "failed to set voice state: %d",
Tox_Err_Group_Set_Voice_State voice_set_err;
tox_group_set_voice_state(tox, groupnumber, voice_state, &voice_set_err);
ck_assert_msg(voice_set_err == TOX_ERR_GROUP_SET_VOICE_STATE_OK, "failed to set voice state: %d",
voice_set_err);
}
static void group_state_test(AutoTox *autotoxes)
{
#ifndef VANILLA_NACL
ck_assert_msg(NUM_GROUP_TOXES >= 3, "NUM_GROUP_TOXES is too small: %d", NUM_GROUP_TOXES);
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
tox_callback_group_privacy_state(autotoxes[i].tox, group_privacy_state_handler);
tox_callback_group_peer_limit(autotoxes[i].tox, group_peer_limit_handler);
tox_callback_group_password(autotoxes[i].tox, group_password_handler);
tox_callback_group_peer_join(autotoxes[i].tox, group_peer_join_handler);
tox_callback_group_voice_state(autotoxes[i].tox, group_voice_state_handler);
tox_callback_group_topic_lock(autotoxes[i].tox, group_topic_lock_handler);
tox_events_callback_group_privacy_state(autotoxes[i].dispatch, group_privacy_state_handler);
tox_events_callback_group_peer_limit(autotoxes[i].dispatch, group_peer_limit_handler);
tox_events_callback_group_password(autotoxes[i].dispatch, group_password_handler);
tox_events_callback_group_peer_join(autotoxes[i].dispatch, group_peer_join_handler);
tox_events_callback_group_voice_state(autotoxes[i].dispatch, group_voice_state_handler);
tox_events_callback_group_topic_lock(autotoxes[i].dispatch, group_topic_lock_handler);
}
Tox *tox0 = autotoxes[0].tox;
@ -264,11 +294,11 @@ static void group_state_test(AutoTox *autotoxes)
(const uint8_t *)PASSWORD, PASS_LEN, TOX_GROUP_TOPIC_LOCK_ENABLED);
/* Founder gets the Chat ID and implicitly shares it publicly */
Tox_Err_Group_State_Queries id_err;
Tox_Err_Group_State_Query id_err;
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(tox0, groupnum, chat_id, &id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "tox_group_get_chat_id failed %d", id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "tox_group_get_chat_id failed %d", id_err);
/* All other peers join the group using the Chat ID and password */
for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) {
@ -318,8 +348,6 @@ static void group_state_test(AutoTox *autotoxes)
}
fprintf(stderr, "All tests passed!\n");
#endif /* VANILLA_NACL */
}
int main(void)

View File

@ -96,38 +96,42 @@ static void peers_cleanup(Peers *peers)
free(peers);
}
static void group_peer_join_handler(Tox *tox, uint32_t group_number, uint32_t peer_id, void *user_data)
static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
const uint32_t peer_id = tox_event_group_peer_join_get_peer_id(event);
ck_assert(add_peer(state->peers, peer_id) == 0);
}
static void group_peer_exit_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, Tox_Group_Exit_Type exit_type,
const uint8_t *name, size_t name_length, const uint8_t *part_message,
size_t length, void *user_data)
static void group_peer_exit_handler(const Tox_Event_Group_Peer_Exit *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
const uint32_t peer_id = tox_event_group_peer_exit_get_peer_id(event);
ck_assert(del_peer(state->peers, peer_id) == 0);
}
static void group_topic_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, const uint8_t *topic,
size_t length, void *user_data)
static void group_topic_handler(const Tox_Event_Group_Topic *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
const uint8_t *topic = tox_event_group_topic_get_topic(event);
const size_t length = tox_event_group_topic_get_topic_length(event);
ck_assert(length <= TOX_GROUP_MAX_TOPIC_LENGTH);
memcpy(state->callback_topic, (const char *)topic, length);
@ -201,7 +205,7 @@ static void role_spam(const Random *rng, AutoTox *autotoxes, uint32_t num_peers,
int64_t peer_id = state0->peers->peer_ids[idx];
if (peer_id >= 0) {
tox_group_mod_set_role(tox0, groupnumber, (uint32_t)peer_id, f_role, nullptr);
tox_group_set_role(tox0, groupnumber, (uint32_t)peer_id, f_role, nullptr);
}
// mods randomly promote or demote one of the non-mods
@ -218,7 +222,7 @@ static void role_spam(const Random *rng, AutoTox *autotoxes, uint32_t num_peers,
peer_id = state_j->peers->peer_ids[i];
if (peer_id >= 0) {
tox_group_mod_set_role(autotoxes[j].tox, groupnumber, (uint32_t)peer_id, role, nullptr);
tox_group_set_role(autotoxes[j].tox, groupnumber, (uint32_t)peer_id, role, nullptr);
}
}
}
@ -260,14 +264,14 @@ static bool all_peers_have_same_topic(const AutoTox *autotoxes, uint32_t num_pee
{
uint8_t expected_topic[TOX_GROUP_MAX_TOPIC_LENGTH];
Tox_Err_Group_State_Queries query_err;
Tox_Err_Group_State_Query query_err;
size_t expected_topic_length = tox_group_get_topic_size(autotoxes[0].tox, groupnumber, &query_err);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERY_OK);
tox_group_get_topic(autotoxes[0].tox, groupnumber, expected_topic, &query_err);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERY_OK);
const State *state0 = (const State *)autotoxes[0].state;
@ -282,7 +286,7 @@ static bool all_peers_have_same_topic(const AutoTox *autotoxes, uint32_t num_pee
for (size_t i = 1; i < num_peers; ++i) {
size_t topic_length = tox_group_get_topic_size(autotoxes[i].tox, groupnumber, &query_err);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERY_OK);
if (topic_length != expected_topic_length) {
return false;
@ -291,7 +295,7 @@ static bool all_peers_have_same_topic(const AutoTox *autotoxes, uint32_t num_pee
uint8_t topic[TOX_GROUP_MAX_TOPIC_LENGTH];
tox_group_get_topic(autotoxes[i].tox, groupnumber, topic, &query_err);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERY_OK);
if (memcmp(expected_topic, (const char *)topic, topic_length) != 0) {
return false;
@ -330,15 +334,14 @@ static void topic_spam(const Random *rng, AutoTox *autotoxes, uint32_t num_peers
static void group_sync_test(AutoTox *autotoxes)
{
#ifndef VANILLA_NACL
ck_assert(NUM_GROUP_TOXES >= 5);
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
tox_callback_group_peer_join(autotoxes[i].tox, group_peer_join_handler);
tox_callback_group_topic(autotoxes[i].tox, group_topic_handler);
tox_callback_group_peer_exit(autotoxes[i].tox, group_peer_exit_handler);
tox_events_callback_group_peer_join(autotoxes[i].dispatch, group_peer_join_handler);
tox_events_callback_group_topic(autotoxes[i].dispatch, group_topic_handler);
tox_events_callback_group_peer_exit(autotoxes[i].dispatch, group_peer_exit_handler);
State *state = (State *)autotoxes[i].state;
state->peers = (Peers *)calloc(1, sizeof(Peers));
@ -357,11 +360,11 @@ static void group_sync_test(AutoTox *autotoxes)
fprintf(stderr, "tox0 creats new group and invites all his friends");
Tox_Err_Group_State_Queries id_err;
Tox_Err_Group_State_Query id_err;
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "%d", id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%d", id_err);
for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) {
Tox_Err_Group_Join join_err;
@ -376,9 +379,9 @@ static void group_sync_test(AutoTox *autotoxes)
fprintf(stderr, "%d peers joined the group\n", NUM_GROUP_TOXES);
Tox_Err_Group_Founder_Set_Topic_Lock lock_set_err;
tox_group_founder_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK, "failed to disable topic lock: %d",
Tox_Err_Group_Set_Topic_Lock lock_set_err;
tox_group_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to disable topic lock: %d",
lock_set_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@ -389,8 +392,8 @@ static void group_sync_test(AutoTox *autotoxes)
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
tox_group_founder_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_ENABLED, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK, "failed to enable topic lock: %d",
tox_group_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_ENABLED, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to enable topic lock: %d",
lock_set_err);
do {
@ -399,12 +402,12 @@ static void group_sync_test(AutoTox *autotoxes)
&& !all_peers_see_same_roles(autotoxes, NUM_GROUP_TOXES, groupnumber)
&& state0->peers->num_peers != NUM_GROUP_TOXES - 1);
Tox_Err_Group_Mod_Set_Role role_err;
Tox_Err_Group_Set_Role role_err;
for (size_t i = 0; i < state0->peers->num_peers; ++i) {
tox_group_mod_set_role(tox0, groupnumber, (uint32_t)state0->peers->peer_ids[i], TOX_GROUP_ROLE_MODERATOR,
tox_group_set_role(tox0, groupnumber, (uint32_t)state0->peers->peer_ids[i], TOX_GROUP_ROLE_MODERATOR,
&role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_MOD_SET_ROLE_OK, "Failed to set moderator. error: %d", role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set moderator. error: %d", role_err);
}
fprintf(stderr, "founder enabled topic lock and set all peers to moderator role\n");
@ -420,9 +423,9 @@ static void group_sync_test(AutoTox *autotoxes)
fprintf(stderr, "founder demoting %u moderators to user\n", num_demoted);
for (size_t i = 0; i < num_demoted; ++i) {
tox_group_mod_set_role(tox0, groupnumber, (uint32_t)state0->peers->peer_ids[i], TOX_GROUP_ROLE_USER,
tox_group_set_role(tox0, groupnumber, (uint32_t)state0->peers->peer_ids[i], TOX_GROUP_ROLE_USER,
&role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_MOD_SET_ROLE_OK, "Failed to set user. error: %d", role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set user. error: %d", role_err);
}
do {
@ -443,8 +446,6 @@ static void group_sync_test(AutoTox *autotoxes)
}
fprintf(stderr, "All tests passed!\n");
#endif // VANILLA_NACL
}
int main(void)

View File

@ -8,8 +8,6 @@
#include "auto_test_support.h"
#ifdef USE_TEST_NETWORK
#define NUM_GROUP_TOXES 2
#define CODEWORD "RONALD MCDONALD"
#define CODEWORD_LEN (sizeof(CODEWORD) - 1)
@ -21,32 +19,43 @@ typedef struct State {
uint32_t peer_id[NUM_GROUP_TOXES - 1];
} State;
static void group_invite_handler(Tox *tox, uint32_t friend_number, const uint8_t *invite_data, size_t length,
const uint8_t *group_name, size_t group_name_length, void *user_data)
static void group_invite_handler(const Tox_Event_Group_Invite *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
const uint32_t friend_number = tox_event_group_invite_get_friend_number(event);
const uint8_t *invite_data = tox_event_group_invite_get_invite_data(event);
const size_t length = tox_event_group_invite_get_invite_data_length(event);
printf("Accepting friend invite\n");
Tox_Err_Group_Invite_Accept err_accept;
tox_group_invite_accept(tox, friend_number, invite_data, length, (const uint8_t *)"test", 4,
tox_group_invite_accept(autotox->tox, friend_number, invite_data, length, (const uint8_t *)"test", 4,
nullptr, 0, &err_accept);
ck_assert(err_accept == TOX_ERR_GROUP_INVITE_ACCEPT_OK);
}
static void group_peer_join_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, void *user_data)
static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void *user_data)
{
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
State *state = (State *)autotox->state;
const uint32_t peer_id = tox_event_group_peer_join_get_peer_id(event);
fprintf(stderr, "joined: %zu, %u\n", state->num_peers, peer_id);
ck_assert_msg(state->num_peers < NUM_GROUP_TOXES - 1, "%zu", state->num_peers);
state->peer_id[state->num_peers++] = peer_id;
}
static void group_private_message_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, TOX_MESSAGE_TYPE type,
const uint8_t *message, size_t length, void *user_data)
static void group_private_message_handler(const Tox_Event_Group_Private_Message *event, void *user_data)
{
const uint8_t *message = tox_event_group_private_message_get_message(event);
const size_t length = tox_event_group_private_message_get_message_length(event);
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
@ -60,9 +69,11 @@ static void group_private_message_handler(Tox *tox, uint32_t groupnumber, uint32
state->got_code = true;
}
static void group_message_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, TOX_MESSAGE_TYPE type,
const uint8_t *message, size_t length, uint32_t message_id, void *user_data)
static void group_message_handler(const Tox_Event_Group_Message *event, void *user_data)
{
const uint8_t *message = tox_event_group_message_get_message(event);
const size_t length = tox_event_group_message_get_message_length(event);
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
@ -129,19 +140,18 @@ static bool all_peers_got_code(AutoTox *autotoxes)
static void group_tcp_test(AutoTox *autotoxes)
{
#ifndef VANILLA_NACL
ck_assert(NUM_GROUP_TOXES >= 2);
State *state0 = (State *)autotoxes[0].state;
State *state1 = (State *)autotoxes[1].state;
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
tox_callback_group_peer_join(autotoxes[i].tox, group_peer_join_handler);
tox_callback_group_private_message(autotoxes[i].tox, group_private_message_handler);
tox_events_callback_group_peer_join(autotoxes[i].dispatch, group_peer_join_handler);
tox_events_callback_group_private_message(autotoxes[i].dispatch, group_private_message_handler);
}
tox_callback_group_message(autotoxes[1].tox, group_message_handler);
tox_callback_group_invite(autotoxes[1].tox, group_invite_handler);
tox_events_callback_group_message(autotoxes[1].dispatch, group_message_handler);
tox_events_callback_group_invite(autotoxes[1].dispatch, group_invite_handler);
Tox_Err_Group_New new_err;
uint32_t groupnumber = tox_group_new(autotoxes[0].tox, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *)"test", 4,
@ -150,11 +160,11 @@ static void group_tcp_test(AutoTox *autotoxes)
iterate_group(autotoxes, NUM_GROUP_TOXES, GROUP_ITERATION_INTERVAL);
Tox_Err_Group_State_Queries id_err;
Tox_Err_Group_State_Query id_err;
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(autotoxes[0].tox, groupnumber, chat_id, &id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "%d", id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%d", id_err);
printf("Tox 0 created new group...\n");
@ -171,7 +181,6 @@ static void group_tcp_test(AutoTox *autotoxes)
printf("%d peers successfully joined. Waiting for code...\n", NUM_GROUP_TOXES);
printf("Tox 0 sending secret code to all peers\n");
for (size_t i = 0; i < NUM_GROUP_TOXES - 1; ++i) {
Tox_Err_Group_Send_Private_Message perr;
@ -209,7 +218,7 @@ static void group_tcp_test(AutoTox *autotoxes)
Tox_Err_Group_Send_Message merr;
tox_group_send_message(autotoxes[0].tox, groupnumber, TOX_MESSAGE_TYPE_NORMAL,
(const uint8_t *)CODEWORD, CODEWORD_LEN, nullptr, &merr);
(const uint8_t *)CODEWORD, CODEWORD_LEN, &merr);
ck_assert(merr == TOX_ERR_GROUP_SEND_MESSAGE_OK);
while (!state1->got_second_code) {
@ -222,34 +231,29 @@ static void group_tcp_test(AutoTox *autotoxes)
}
printf("Test passed!\n");
#endif // VANILLA_NACL
}
#endif // USE_TEST_NETWORK
int main(void)
int main(int argc, char **argv)
{
#ifdef USE_TEST_NETWORK // TODO(Jfreegman): Enable this test when the mainnet works with DHT groupchats
setvbuf(stdout, nullptr, _IONBF, 0);
struct Tox_Options *options = (struct Tox_Options *)calloc(1, sizeof(struct Tox_Options));
struct Tox_Options *options = tox_options_new(nullptr);
ck_assert(options != nullptr);
tox_options_default(options);
tox_options_set_udp_enabled(options, false);
Run_Auto_Options autotest_opts = default_run_auto_options();
autotest_opts.graph = GRAPH_COMPLETE;
// TODO(JFreegman): Fix this test and remove the "if".
if (argc > 2) {
run_auto_test(options, NUM_GROUP_TOXES, group_tcp_test, sizeof(State), &autotest_opts);
}
tox_options_free(options);
#endif
return 0;
}
#ifdef USE_TEST_NETWORK
#undef NUM_GROUP_TOXES
#undef CODEWORD_LEN
#undef CODEWORD
#endif // USE_TEST_NETWORK
#undef NUM_GROUP_TOXES

View File

@ -55,8 +55,11 @@ static bool all_group_peers_connected(const AutoTox *autotoxes, uint32_t tox_cou
return true;
}
static void group_peer_join_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, void *user_data)
static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void *user_data)
{
//const uint32_t group_number = tox_event_group_peer_join_get_group_number(event);
const uint32_t peer_id = tox_event_group_peer_join_get_peer_id(event);
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
@ -65,28 +68,41 @@ static void group_peer_join_handler(Tox *tox, uint32_t groupnumber, uint32_t pee
state->peer_id = peer_id;
}
static void group_topic_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, const uint8_t *topic,
size_t length, void *user_data)
static void group_topic_handler(const Tox_Event_Group_Topic *event, void *user_data)
{
ck_assert(length <= TOX_GROUP_MAX_TOPIC_LENGTH);
AutoTox *autotox = (AutoTox *)user_data;
ck_assert(autotox != nullptr);
Tox_Err_Group_State_Queries query_err;
const uint32_t group_number = tox_event_group_topic_get_group_number(event);
//const uint32_t peer_id = tox_event_group_topic_get_peer_id(event);
const uint8_t *topic = tox_event_group_topic_get_topic(event);
const uint32_t topic_length = tox_event_group_topic_get_topic_length(event);
ck_assert(topic_length <= TOX_GROUP_MAX_TOPIC_LENGTH);
Tox_Err_Group_State_Query query_err;
uint8_t topic2[TOX_GROUP_MAX_TOPIC_LENGTH];
tox_group_get_topic(tox, groupnumber, topic2, &query_err);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK);
tox_group_get_topic(autotox->tox, group_number, topic2, &query_err);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERY_OK);
size_t topic_length = tox_group_get_topic_size(tox, groupnumber, &query_err);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert_msg(topic_length == length && memcmp(topic, topic2, length) == 0,
size_t topic_length_getter = tox_group_get_topic_size(autotox->tox, group_number, &query_err);
ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERY_OK);
ck_assert_msg(topic_length_getter == topic_length && memcmp(topic, topic2, topic_length) == 0,
"topic differs in callback: %s, %s", topic, topic2);
}
static void group_topic_lock_handler(Tox *tox, uint32_t groupnumber, Tox_Group_Topic_Lock topic_lock, void *user_data)
static void group_topic_lock_handler(const Tox_Event_Group_Topic_Lock *event, void *user_data)
{
Tox_Err_Group_State_Queries err;
Tox_Group_Topic_Lock current_lock = tox_group_get_topic_lock(tox, groupnumber, &err);
const AutoTox *autotox = (const AutoTox *)user_data;
ck_assert(autotox != nullptr);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK);
const uint32_t group_number = tox_event_group_topic_lock_get_group_number(event);
const Tox_Group_Topic_Lock topic_lock = tox_event_group_topic_lock_get_topic_lock(event);
Tox_Err_Group_State_Query err;
Tox_Group_Topic_Lock current_lock = tox_group_get_topic_lock(autotox->tox, group_number, &err);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERY_OK);
ck_assert_msg(topic_lock == current_lock, "topic locks differ in callback");
}
@ -107,10 +123,10 @@ static bool set_topic(Tox *tox, uint32_t groupnumber, const char *topic, size_t
*/
static int check_topic(const Tox *tox, uint32_t groupnumber, const char *expected_topic, size_t expected_length)
{
Tox_Err_Group_State_Queries query_err;
Tox_Err_Group_State_Query query_err;
size_t topic_length = tox_group_get_topic_size(tox, groupnumber, &query_err);
if (query_err != TOX_ERR_GROUP_STATE_QUERIES_OK) {
if (query_err != TOX_ERR_GROUP_STATE_QUERY_OK) {
return -1;
}
@ -121,7 +137,7 @@ static int check_topic(const Tox *tox, uint32_t groupnumber, const char *expecte
uint8_t topic[TOX_GROUP_MAX_TOPIC_LENGTH];
tox_group_get_topic(tox, groupnumber, topic, &query_err);
if (query_err != TOX_ERR_GROUP_STATE_QUERIES_OK) {
if (query_err != TOX_ERR_GROUP_STATE_QUERY_OK) {
return -3;
}
@ -140,9 +156,9 @@ static void wait_topic_lock(AutoTox *autotoxes, uint32_t groupnumber, Tox_Group_
uint32_t count = 0;
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
Tox_Err_Group_State_Queries err;
Tox_Err_Group_State_Query err;
Tox_Group_Topic_Lock topic_lock = tox_group_get_topic_lock(autotoxes[i].tox, groupnumber, &err);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERY_OK);
if (topic_lock == expected_lock) {
++count;
@ -203,20 +219,20 @@ static uint32_t set_topic_all_peers(const Random *rng, AutoTox *autotoxes, size_
static void group_topic_test(AutoTox *autotoxes)
{
#ifndef VANILLA_NACL
ck_assert_msg(NUM_GROUP_TOXES >= 3, "NUM_GROUP_TOXES is too small: %d", NUM_GROUP_TOXES);
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
Tox *tox0 = autotoxes[0].tox;
Tox_Dispatch *dispatch0 = autotoxes[0].dispatch;
const State *state0 = (const State *)autotoxes[0].state;
tox_callback_group_peer_join(tox0, group_peer_join_handler);
tox_events_callback_group_peer_join(dispatch0, group_peer_join_handler);
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
tox_callback_group_topic(autotoxes[i].tox, group_topic_handler);
tox_callback_group_topic_lock(autotoxes[i].tox, group_topic_lock_handler);
tox_events_callback_group_topic(autotoxes[i].dispatch, group_topic_handler);
tox_events_callback_group_topic_lock(autotoxes[i].dispatch, group_topic_lock_handler);
}
/* Tox1 creates a group and is the founder of a newly created group */
@ -234,11 +250,11 @@ static void group_topic_test(AutoTox *autotoxes)
ck_assert_msg(s_ret, "Founder failed to set topic");
/* Founder gets the Chat ID and implicitly shares it publicly */
Tox_Err_Group_State_Queries id_err;
Tox_Err_Group_State_Query id_err;
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "tox_group_get_chat_id failed %d", id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "tox_group_get_chat_id failed %d", id_err);
/* All other peers join the group using the Chat ID */
for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) {
@ -258,9 +274,9 @@ static void group_topic_test(AutoTox *autotoxes)
wait_state_topic(autotoxes, groupnumber, TOPIC, TOPIC_LEN);
/* Founder disables topic lock */
Tox_Err_Group_Founder_Set_Topic_Lock lock_set_err;
tox_group_founder_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK, "failed to disable topic lock: %d",
Tox_Err_Group_Set_Topic_Lock lock_set_err;
tox_group_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to disable topic lock: %d",
lock_set_err);
fprintf(stderr, "Topic lock disabled\n");
@ -274,9 +290,9 @@ static void group_topic_test(AutoTox *autotoxes)
ck_assert_msg(change_count == NUM_GROUP_TOXES, "%u peers changed the topic with topic lock disabled", change_count);
/* founder silences the last peer he saw join */
Tox_Err_Group_Mod_Set_Role merr;
tox_group_mod_set_role(tox0, groupnumber, state0->peer_id, TOX_GROUP_ROLE_OBSERVER, &merr);
ck_assert_msg(merr == TOX_ERR_GROUP_MOD_SET_ROLE_OK, "Failed to set %u to observer role: %d", state0->peer_id, merr);
Tox_Err_Group_Set_Role merr;
tox_group_set_role(tox0, groupnumber, state0->peer_id, TOX_GROUP_ROLE_OBSERVER, &merr);
ck_assert_msg(merr == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set %u to observer role: %d", state0->peer_id, merr);
fprintf(stderr, "Random peer is set to observer\n");
@ -288,8 +304,8 @@ static void group_topic_test(AutoTox *autotoxes)
ck_assert_msg(change_count == NUM_GROUP_TOXES - 1, "%u peers changed the topic with a silenced peer", change_count);
/* Founder enables topic lock and sets topic back to original */
tox_group_founder_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_ENABLED, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK, "failed to enable topic lock: %d",
tox_group_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_ENABLED, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to enable topic lock: %d",
lock_set_err);
fprintf(stderr, "Topic lock enabled\n");
@ -318,8 +334,6 @@ static void group_topic_test(AutoTox *autotoxes)
}
fprintf(stderr, "All tests passed!\n");
#endif /* VANILLA_NACL */
}
int main(void)

View File

@ -7,15 +7,8 @@
#include "auto_test_support.h"
#include "check_compat.h"
static uint8_t const key[] = {
0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
0xDF, 0x0E, 0xBA, 0x05, 0x7D, 0xAB, 0xB4, 0x9F,
0xE1, 0x5F, 0x38, 0x03, 0xB1, 0xBF, 0xF0, 0x65,
0x36, 0xAE, 0x2E, 0x5B, 0xA5, 0xE4, 0x69, 0x0E,
};
// Try to bootstrap for 30 seconds.
#define NUM_ITERATIONS (unsigned)(30.0 / (ITERATION_INTERVAL / 1000.0))
// Try to bootstrap for 20 seconds.
#define NUM_ITERATIONS (unsigned)(20.0 / (ITERATION_INTERVAL / 1000.0))
int main(void)
{
@ -24,13 +17,12 @@ int main(void)
struct Tox_Options *opts = tox_options_new(nullptr);
tox_options_set_udp_enabled(opts, false);
tox_options_set_proxy_type(opts, TOX_PROXY_TYPE_SOCKS5);
tox_options_set_proxy_host(opts, "localhost");
tox_options_set_proxy_host(opts, "127.0.0.1");
tox_options_set_proxy_port(opts, 51724);
Tox *tox = tox_new_log(opts, nullptr, nullptr);
tox_options_free(opts);
tox_add_tcp_relay(tox, "tox.ngc.zone", 33445, key, nullptr);
tox_bootstrap(tox, "tox.ngc.zone", 33445, key, nullptr);
bootstrap_tox_live_network(tox, true);
printf("Waiting for connection...\n");

View File

@ -7,15 +7,8 @@
#include "auto_test_support.h"
#include "check_compat.h"
static uint8_t const key[] = {
0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
0xDF, 0x0E, 0xBA, 0x05, 0x7D, 0xAB, 0xB4, 0x9F,
0xE1, 0x5F, 0x38, 0x03, 0xB1, 0xBF, 0xF0, 0x65,
0x36, 0xAE, 0x2E, 0x5B, 0xA5, 0xE4, 0x69, 0x0E,
};
// Try to bootstrap for 30 seconds.
#define NUM_ITERATIONS (unsigned)(30.0 / (ITERATION_INTERVAL / 1000.0))
// Try to bootstrap for 20 seconds.
#define NUM_ITERATIONS (unsigned)(20.0 / (ITERATION_INTERVAL / 1000.0))
int main(void)
{
@ -24,13 +17,12 @@ int main(void)
struct Tox_Options *opts = tox_options_new(nullptr);
tox_options_set_udp_enabled(opts, true);
tox_options_set_proxy_type(opts, TOX_PROXY_TYPE_SOCKS5);
tox_options_set_proxy_host(opts, "localhost");
tox_options_set_proxy_host(opts, "127.0.0.1");
tox_options_set_proxy_port(opts, 51724);
Tox *tox = tox_new_log(opts, nullptr, nullptr);
tox_options_free(opts);
tox_add_tcp_relay(tox, "tox.ngc.zone", 33445, key, nullptr);
tox_bootstrap(tox, "tox.ngc.zone", 33445, key, nullptr);
bootstrap_tox_live_network(tox, true);
printf("Waiting for connection...");

View File

@ -18,13 +18,17 @@ typedef struct State {
#define LOSSLESS_PACKET_FILLER 160
static void handle_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, void *user_data)
static void handle_lossless_packet(const Tox_Event_Friend_Lossless_Packet *event, void *user_data)
{
//const uint32_t friend_number = tox_event_friend_lossless_packet_get_friend_number(event);
const uint8_t *data = tox_event_friend_lossless_packet_get_data(event);
const uint32_t data_length = tox_event_friend_lossless_packet_get_data_length(event);
uint8_t *cmp_packet = (uint8_t *)malloc(tox_max_custom_packet_size());
ck_assert(cmp_packet != nullptr);
memset(cmp_packet, LOSSLESS_PACKET_FILLER, tox_max_custom_packet_size());
if (length == tox_max_custom_packet_size() && memcmp(data, cmp_packet, tox_max_custom_packet_size()) == 0) {
if (data_length == tox_max_custom_packet_size() && memcmp(data, cmp_packet, tox_max_custom_packet_size()) == 0) {
const AutoTox *autotox = (AutoTox *)user_data;
State *state = (State *)autotox->state;
state->custom_packet_received = true;
@ -35,7 +39,7 @@ static void handle_lossless_packet(Tox *tox, uint32_t friend_number, const uint8
static void test_lossless_packet(AutoTox *autotoxes)
{
tox_callback_friend_lossless_packet(autotoxes[1].tox, &handle_lossless_packet);
tox_events_callback_friend_lossless_packet(autotoxes[1].dispatch, &handle_lossless_packet);
const size_t packet_size = tox_max_custom_packet_size() + 1;
uint8_t *packet = (uint8_t *)malloc(packet_size);
ck_assert(packet != nullptr);

View File

@ -18,13 +18,17 @@ typedef struct State {
#define LOSSY_PACKET_FILLER 200
static void handle_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, void *user_data)
static void handle_lossy_packet(const Tox_Event_Friend_Lossy_Packet *event, void *user_data)
{
//const uint32_t friend_number = tox_event_friend_lossy_packet_get_friend_number(event);
const uint8_t *data = tox_event_friend_lossy_packet_get_data(event);
const uint32_t data_length = tox_event_friend_lossy_packet_get_data_length(event);
uint8_t *cmp_packet = (uint8_t *)malloc(tox_max_custom_packet_size());
ck_assert(cmp_packet != nullptr);
memset(cmp_packet, LOSSY_PACKET_FILLER, tox_max_custom_packet_size());
if (length == tox_max_custom_packet_size() && memcmp(data, cmp_packet, tox_max_custom_packet_size()) == 0) {
if (data_length == tox_max_custom_packet_size() && memcmp(data, cmp_packet, tox_max_custom_packet_size()) == 0) {
const AutoTox *autotox = (AutoTox *)user_data;
State *state = (State *)autotox->state;
state->custom_packet_received = true;
@ -35,7 +39,7 @@ static void handle_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t
static void test_lossy_packet(AutoTox *autotoxes)
{
tox_callback_friend_lossy_packet(autotoxes[1].tox, &handle_lossy_packet);
tox_events_callback_friend_lossy_packet(autotoxes[1].dispatch, &handle_lossy_packet);
const size_t packet_size = tox_max_custom_packet_size() + 1;
uint8_t *packet = (uint8_t *)malloc(packet_size);
ck_assert(packet != nullptr);

View File

@ -20,7 +20,7 @@ static void test_addr_resolv_localhost(void)
errno = 0;
#endif
const Network *ns = system_network();
const Network *ns = os_network();
ck_assert(ns != nullptr);
const char localhost[] = "localhost";

View File

@ -37,7 +37,7 @@ static void do_onion(Mono_Time *mono_time, Onion *onion)
static int handled_test_1;
static int handle_test_1(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
{
Onion *onion = (Onion *)object;
const Onion *onion = (const Onion *)object;
const char req_message[] = "Install Gentoo";
uint8_t req_packet[1 + sizeof(req_message)];
@ -53,7 +53,7 @@ static int handle_test_1(void *object, const IP_Port *source, const uint8_t *pac
res_packet[0] = NET_PACKET_ANNOUNCE_RESPONSE;
memcpy(res_packet + 1, res_message, sizeof(res_message));
if (send_onion_response(onion->net, source, res_packet, sizeof(res_packet),
if (send_onion_response(onion->log, onion->net, source, res_packet, sizeof(res_packet),
packet + sizeof(res_packet)) == -1) {
return 1;
}
@ -99,7 +99,7 @@ static uint8_t test_3_pub_key[CRYPTO_PUBLIC_KEY_SIZE];
static uint8_t test_3_ping_id[CRYPTO_SHA256_SIZE];
static int handle_test_3(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
{
Onion *onion = (Onion *)object;
const Onion *onion = (const Onion *)object;
if (length < ONION_ANNOUNCE_RESPONSE_MIN_SIZE || length > ONION_ANNOUNCE_RESPONSE_MAX_SIZE) {
return 1;
@ -118,7 +118,6 @@ static int handle_test_3(void *object, const IP_Port *source, const uint8_t *pac
return 1;
}
if (memcmp(packet + 1, sb_data, ONION_ANNOUNCE_SENDBACK_DATA_LENGTH) != 0) {
return 1;
}
@ -135,7 +134,7 @@ static int handle_test_3(void *object, const IP_Port *source, const uint8_t *pac
static int handle_test_3_old(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{
Onion *onion = (Onion *)object;
const Onion *onion = (const Onion *)object;
if (length < ONION_ANNOUNCE_RESPONSE_MIN_SIZE || length > ONION_ANNOUNCE_RESPONSE_MAX_SIZE) {
return 1;
@ -154,7 +153,6 @@ static int handle_test_3_old(void *object, const IP_Port *source, const uint8_t
return 1;
}
if (memcmp(packet + 1, sb_data, ONION_ANNOUNCE_SENDBACK_DATA_LENGTH) != 0) {
return 1;
}
@ -171,7 +169,7 @@ static uint8_t nonce[CRYPTO_NONCE_SIZE];
static int handled_test_4;
static int handle_test_4(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
{
Onion *onion = (Onion *)object;
const Onion *onion = (const Onion *)object;
if (length != (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + sizeof("Install gentoo") +
CRYPTO_MAC_SIZE)) {
@ -223,11 +221,11 @@ static Networking_Core *new_networking(const Logger *log, const Memory *mem, con
static void test_basic(void)
{
uint32_t index[] = { 1, 2, 3 };
const Network *ns = system_network();
const Network *ns = os_network();
ck_assert(ns != nullptr);
const Memory *mem = system_memory();
const Memory *mem = os_memory();
ck_assert(mem != nullptr);
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
Logger *log1 = logger_new();
@ -288,12 +286,12 @@ static void test_basic(void)
networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_3, onion1);
networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE_OLD, &handle_test_3_old, onion1);
ck_assert_msg((onion1_a != nullptr) && (onion2_a != nullptr), "Onion_Announce failed initializing.");
uint8_t zeroes[64] = {0};
const uint8_t zeroes[64] = {0};
random_bytes(rng, sb_data, sizeof(sb_data));
uint64_t s;
memcpy(&s, sb_data, sizeof(uint64_t));
memcpy(test_3_pub_key, nodes[3].public_key, CRYPTO_PUBLIC_KEY_SIZE);
int ret = send_announce_request(onion1->net, rng, &path, &nodes[3],
int ret = send_announce_request(log1, onion1->net, rng, &path, &nodes[3],
dht_get_self_public_key(onion1->dht),
dht_get_self_secret_key(onion1->dht),
zeroes,
@ -315,7 +313,7 @@ static void test_basic(void)
memcpy(onion_announce_entry_public_key(onion2_a, 1), dht_get_self_public_key(onion2->dht), CRYPTO_PUBLIC_KEY_SIZE);
onion_announce_entry_set_time(onion2_a, 1, mono_time_get(mono_time2));
networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1);
send_announce_request(onion1->net, rng, &path, &nodes[3],
send_announce_request(log1, onion1->net, rng, &path, &nodes[3],
dht_get_self_public_key(onion1->dht),
dht_get_self_secret_key(onion1->dht),
test_3_ping_id,
@ -340,7 +338,7 @@ static void test_basic(void)
ck_assert_msg((onion3 != nullptr), "Onion failed initializing.");
random_nonce(rng, nonce);
ret = send_data_request(onion3->net, rng, &path, &nodes[3].ip_port,
ret = send_data_request(log3, onion3->net, rng, &path, &nodes[3].ip_port,
dht_get_self_public_key(onion1->dht),
dht_get_self_public_key(onion1->dht),
nonce, (const uint8_t *)"Install gentoo", sizeof("Install gentoo"));
@ -407,7 +405,7 @@ static Onions *new_onions(const Memory *mem, const Random *rng, uint16_t port, u
{
IP ip = get_loopback();
ip.ip.v6.uint8[15] = 1;
const Network *ns = system_network();
const Network *ns = os_network();
Onions *on = (Onions *)malloc(sizeof(Onions));
if (!on) {
@ -576,9 +574,9 @@ static void test_announce(void)
{
uint32_t index[NUM_ONIONS];
Onions *onions[NUM_ONIONS];
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
const Memory *mem = system_memory();
const Memory *mem = os_memory();
ck_assert(mem != nullptr);
for (uint32_t i = 0; i < NUM_ONIONS; ++i) {

View File

@ -11,9 +11,13 @@ typedef struct State {
#define NUM_MSGS 40000
static void handle_friend_message(Tox *tox, uint32_t friend_number, Tox_Message_Type type,
const uint8_t *message, size_t length, void *user_data)
static void handle_friend_message(const Tox_Event_Friend_Message *event, void *user_data)
{
//const uint32_t friend_number = tox_event_friend_message_get_friend_number(event);
//const Tox_Message_Type type = tox_event_friend_message_get_type(event);
//const uint8_t *message = tox_event_friend_message_get_message(event);
//const uint32_t message_length = tox_event_friend_message_get_message_length(event);
const AutoTox *autotox = (AutoTox *)user_data;
State *state = (State *)autotox->state;
state->recv_count++;
@ -21,7 +25,7 @@ static void handle_friend_message(Tox *tox, uint32_t friend_number, Tox_Message_
static void net_crypto_overflow_test(AutoTox *autotoxes)
{
tox_callback_friend_message(autotoxes[0].tox, handle_friend_message);
tox_events_callback_friend_message(autotoxes[0].dispatch, handle_friend_message);
printf("sending many messages to tox0\n");

View File

@ -51,7 +51,7 @@ static bool all_disconnected_from(uint32_t tox_count, AutoTox *autotoxes, uint32
static void test_reconnect(AutoTox *autotoxes)
{
const Random *rng = system_random();
const Random *rng = os_random();
ck_assert(rng != nullptr);
const time_t test_start_time = time(nullptr);
@ -67,7 +67,12 @@ static void test_reconnect(AutoTox *autotoxes)
do {
for (uint16_t i = 0; i < TOX_COUNT; ++i) {
if (i != disconnect) {
tox_iterate(autotoxes[i].tox, &autotoxes[i]);
Tox_Err_Events_Iterate err = TOX_ERR_EVENTS_ITERATE_OK;
Tox_Events *events = tox_events_iterate(autotoxes[i].tox, true, &err);
ck_assert(err == TOX_ERR_EVENTS_ITERATE_OK);
tox_dispatch_invoke(autotoxes[i].dispatch, events, &autotoxes[i]);
tox_events_free(events);
autotoxes[i].clock += 1000;
}
}

Some files were not shown because too many files have changed in this diff Show More