Compare commits
14 Commits
tmp_window
...
565aa4b7eb
Author | SHA1 | Date | |
---|---|---|---|
565aa4b7eb | |||
b117da5ccf | |||
82fe4c3dd7 | |||
8eb4892b49 | |||
78b0e9a77f | |||
7fa6aa7ac2 | |||
20b4cdc5f1 | |||
7c576dd4d0 | |||
f6cda522ca | |||
3d2f5b644b | |||
9ace11a0e2 | |||
6104d3b6d1 | |||
f637c7c942 | |||
afb886ea7c |
2
external/solanaceae_message3
vendored
2
external/solanaceae_message3
vendored
Submodule external/solanaceae_message3 updated: 1a036c2321...60fc0d34eb
2
external/solanaceae_plugin
vendored
2
external/solanaceae_plugin
vendored
Submodule external/solanaceae_plugin updated: 5ae3f07c3a...b502690621
2
external/solanaceae_tox
vendored
2
external/solanaceae_tox
vendored
Submodule external/solanaceae_tox updated: c01d91144c...ce760a800c
2
external/solanaceae_toxcore
vendored
2
external/solanaceae_toxcore
vendored
Submodule external/solanaceae_toxcore updated: 08b3d69c15...3df9125877
2
external/solanaceae_util
vendored
2
external/solanaceae_util
vendored
Submodule external/solanaceae_util updated: 2b20c2d2a4...fa0a09df87
42
external/toxcore/c-toxcore/.circleci/config.yml
vendored
42
external/toxcore/c-toxcore/.circleci/config.yml
vendored
@@ -15,9 +15,7 @@ workflows:
|
|||||||
- ubsan
|
- ubsan
|
||||||
# Static analysis
|
# Static analysis
|
||||||
- clang-analyze
|
- clang-analyze
|
||||||
- clang-tidy
|
|
||||||
- cpplint
|
- cpplint
|
||||||
- infer
|
|
||||||
- static-analysis
|
- static-analysis
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -70,6 +68,7 @@ jobs:
|
|||||||
cmake
|
cmake
|
||||||
git
|
git
|
||||||
libconfig-dev
|
libconfig-dev
|
||||||
|
libgmock-dev
|
||||||
libgtest-dev
|
libgtest-dev
|
||||||
libopus-dev
|
libopus-dev
|
||||||
libsodium-dev
|
libsodium-dev
|
||||||
@@ -103,27 +102,6 @@ jobs:
|
|||||||
- run: git submodule update --init --recursive
|
- run: git submodule update --init --recursive
|
||||||
- run: CC=clang .circleci/cmake-ubsan
|
- 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:
|
static-analysis:
|
||||||
working_directory: ~/work
|
working_directory: ~/work
|
||||||
docker:
|
docker:
|
||||||
@@ -154,24 +132,6 @@ jobs:
|
|||||||
- run: git submodule update --init --recursive
|
- run: git submodule update --init --recursive
|
||||||
- run: other/analysis/run-clang-analyze
|
- 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:
|
cpplint:
|
||||||
working_directory: ~/work
|
working_directory: ~/work
|
||||||
docker:
|
docker:
|
||||||
|
9
external/toxcore/c-toxcore/.clang-tidy
vendored
9
external/toxcore/c-toxcore/.clang-tidy
vendored
@@ -1,4 +1,5 @@
|
|||||||
# vim:ft=yaml
|
# vim:ft=yaml
|
||||||
|
HeaderFilterRegex: "/c-toxcore/[^/]+/[^.].+"
|
||||||
CheckOptions:
|
CheckOptions:
|
||||||
- key: readability-identifier-naming.ClassCase
|
- key: readability-identifier-naming.ClassCase
|
||||||
value: Camel_Snake_Case
|
value: Camel_Snake_Case
|
||||||
@@ -35,6 +36,12 @@ CheckOptions:
|
|||||||
value: lower_case
|
value: lower_case
|
||||||
|
|
||||||
- key: llvmlibc-restrict-system-libc-headers.Includes
|
- 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: "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
|
- key: hicpp-signed-bitwise.IgnorePositiveIntegerLiterals
|
||||||
value: true
|
value: true
|
||||||
|
- key: concurrency-mt-unsafe.FunctionSet
|
||||||
|
value: posix
|
||||||
|
- key: misc-include-cleaner.IgnoreHeaders
|
||||||
|
value: "pthread.h;stdbool.h;stddef.h;stdint.;stdint.h;stdint...;cstdint;sodium.*;sys/.*;unistd.h;opus.*;vpx.*;attributes.h;tox_struct.h"
|
||||||
|
- key: readability-function-cognitive-complexity.Threshold
|
||||||
|
value: 153 # TODO(iphydf): Decrease. tox_new is the highest at the moment.
|
||||||
|
@@ -1,61 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
NPROC=$(nproc)
|
|
||||||
|
|
||||||
sudo apt-get install -y --no-install-recommends \
|
|
||||||
libgtest-dev \
|
|
||||||
libopus-dev \
|
|
||||||
libsodium-dev \
|
|
||||||
libvpx-dev \
|
|
||||||
llvm-14 \
|
|
||||||
ninja-build
|
|
||||||
git clone --depth=1 https://github.com/ralight/mallocfail /tmp/mallocfail
|
|
||||||
cd /tmp/mallocfail # pushd
|
|
||||||
make
|
|
||||||
sudo make install
|
|
||||||
cd - # popd
|
|
||||||
|
|
||||||
export CC=clang
|
|
||||||
export CXX=clang++
|
|
||||||
|
|
||||||
sudo install other/docker/coverage/run_mallocfail /usr/local/bin/run_mallocfail
|
|
||||||
(cd other/proxy && go get && go build)
|
|
||||||
other/proxy/proxy &
|
|
||||||
|
|
||||||
. ".github/scripts/flags-coverage.sh"
|
|
||||||
|
|
||||||
cmake -B_build -H. -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="$PWD/_install" \
|
|
||||||
-DENABLE_SHARED=OFF \
|
|
||||||
-DMIN_LOGGER_LEVEL=TRACE \
|
|
||||||
-DMUST_BUILD_TOXAV=ON \
|
|
||||||
-DNON_HERMETIC_TESTS=OFF \
|
|
||||||
-DSTRICT_ABI=ON \
|
|
||||||
-DTEST_TIMEOUT_SECONDS=120 \
|
|
||||||
-DUSE_IPV6=OFF \
|
|
||||||
-DAUTOTEST=ON \
|
|
||||||
-DPROXY_TEST=ON
|
|
||||||
|
|
||||||
cmake --build _build --parallel "$NPROC" --target install -- -k 0
|
|
||||||
|
|
||||||
cd _build # pushd
|
|
||||||
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6 ||
|
|
||||||
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6
|
|
||||||
|
|
||||||
export PYTHONUNBUFFERED=1
|
|
||||||
run_mallocfail --ctest=2 --jobs=8
|
|
||||||
cd - # popd
|
|
||||||
|
|
||||||
#coveralls \
|
|
||||||
# --exclude auto_tests \
|
|
||||||
# --exclude other \
|
|
||||||
# --exclude testing \
|
|
||||||
# --gcov-options '\-lp'
|
|
||||||
|
|
||||||
bash <(curl -s https://codecov.io/bash) -x "llvm-cov-14 gcov"
|
|
@@ -5,10 +5,10 @@
|
|||||||
add_ld_flag -Wl,-z,defs
|
add_ld_flag -Wl,-z,defs
|
||||||
|
|
||||||
# Make compilation error on a warning
|
# Make compilation error on a warning
|
||||||
add_flag -Werror
|
add_flag -Werror -Wno-unsafe-buffer-usage
|
||||||
|
|
||||||
# Coverage flags.
|
# Coverage flags.
|
||||||
add_flag --coverage
|
add_flag -fprofile-instr-generate -fcoverage-mapping
|
||||||
|
|
||||||
# Optimisation, but keep stack traces useful.
|
# Optimisation, but keep stack traces useful.
|
||||||
add_c_flag -fno-inline -fno-omit-frame-pointer
|
add_c_flag -fno-inline -fno-omit-frame-pointer
|
||||||
|
@@ -1,12 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -exu
|
set -exu -o pipefail
|
||||||
|
|
||||||
LOCAL="${1:-}"
|
LOCAL="${1:-}"
|
||||||
|
|
||||||
readarray -t FILES <<<"$(git ls-files)"
|
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 -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)"
|
docker tag toxchat/bootstrap-node:latest toxchat/bootstrap-node:"$(other/print-version)"
|
||||||
|
|
||||||
sudo useradd \
|
sudo useradd \
|
||||||
|
86
external/toxcore/c-toxcore/.github/settings.yml
vendored
86
external/toxcore/c-toxcore/.github/settings.yml
vendored
@@ -1,86 +0,0 @@
|
|||||||
---
|
|
||||||
_extends: .github
|
|
||||||
|
|
||||||
repository:
|
|
||||||
name: c-toxcore
|
|
||||||
description: The future of online communications.
|
|
||||||
homepage: https://tox.chat/
|
|
||||||
topics: toxcore, network, p2p, security, encryption, cryptography
|
|
||||||
|
|
||||||
branches:
|
|
||||||
- name: "master"
|
|
||||||
protection:
|
|
||||||
required_status_checks:
|
|
||||||
contexts:
|
|
||||||
- "bazel-dbg"
|
|
||||||
- "bazel-opt"
|
|
||||||
- "build-alpine-s390x"
|
|
||||||
- "build-android"
|
|
||||||
- "build-autotools"
|
|
||||||
- "build-compcert"
|
|
||||||
- "build-macos"
|
|
||||||
- "build-tcc"
|
|
||||||
- "build-win32"
|
|
||||||
- "build-win64"
|
|
||||||
- "ci/circleci: asan"
|
|
||||||
- "ci/circleci: bazel-asan"
|
|
||||||
- "ci/circleci: bazel-msan"
|
|
||||||
- "ci/circleci: bazel-tsan"
|
|
||||||
- "ci/circleci: clang-analyze"
|
|
||||||
- "ci/circleci: clang-tidy"
|
|
||||||
- "ci/circleci: cpplint"
|
|
||||||
- "ci/circleci: infer"
|
|
||||||
- "ci/circleci: static-analysis"
|
|
||||||
- "ci/circleci: tsan"
|
|
||||||
- "ci/circleci: ubsan"
|
|
||||||
- "cimple"
|
|
||||||
- "cimplefmt"
|
|
||||||
- "CodeFactor"
|
|
||||||
- "code-review/reviewable"
|
|
||||||
- "common / buildifier"
|
|
||||||
- "coverage-linux"
|
|
||||||
- "docker-bootstrap-node"
|
|
||||||
- "docker-bootstrap-node-websocket"
|
|
||||||
- "docker-clusterfuzz"
|
|
||||||
- "docker-esp32"
|
|
||||||
- "docker-fuzzer"
|
|
||||||
- "docker-toxcore-js"
|
|
||||||
- "docker-win32"
|
|
||||||
- "docker-win64"
|
|
||||||
- "doxygen"
|
|
||||||
- "freebsd"
|
|
||||||
- "Hound"
|
|
||||||
- "misra"
|
|
||||||
- "mypy"
|
|
||||||
- "program-analysis"
|
|
||||||
- "sonar-scan"
|
|
||||||
- "tokstyle"
|
|
||||||
- "TokTok.c-toxcore"
|
|
||||||
- "TokTok.c-toxcore (windows_msvc_conan shared)"
|
|
||||||
- "TokTok.c-toxcore (windows_msvc_conan static)"
|
|
||||||
|
|
||||||
# Labels specific to c-toxcore.
|
|
||||||
labels:
|
|
||||||
- name: "bootstrap"
|
|
||||||
color: "#01707f"
|
|
||||||
description: "Bootstrap"
|
|
||||||
|
|
||||||
- name: "crypto"
|
|
||||||
color: "#1d76db"
|
|
||||||
description: "Crypto"
|
|
||||||
|
|
||||||
- name: "file transfers"
|
|
||||||
color: "#e02abf"
|
|
||||||
description: "File Transfers"
|
|
||||||
|
|
||||||
- name: "messenger"
|
|
||||||
color: "#d93f0b"
|
|
||||||
description: "Messenger"
|
|
||||||
|
|
||||||
- name: "network"
|
|
||||||
color: "#d4c5f9"
|
|
||||||
description: "Network"
|
|
||||||
|
|
||||||
- name: "toxav"
|
|
||||||
color: "#0052cc"
|
|
||||||
description: "Audio/video"
|
|
182
external/toxcore/c-toxcore/.github/workflows/ci.yml
vendored
182
external/toxcore/c-toxcore/.github/workflows/ci.yml
vendored
@@ -13,7 +13,10 @@ jobs:
|
|||||||
common:
|
common:
|
||||||
uses: TokTok/ci-tools/.github/workflows/common-ci.yml@master
|
uses: TokTok/ci-tools/.github/workflows/common-ci.yml@master
|
||||||
|
|
||||||
cppcheck:
|
analysis:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
tool: [autotools, clang-tidy, compcert, cppcheck, doxygen, infer, misra, tcc, tokstyle]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
@@ -21,84 +24,16 @@ jobs:
|
|||||||
- name: Docker Build
|
- name: Docker Build
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v4
|
||||||
with:
|
with:
|
||||||
file: other/docker/cppcheck/Dockerfile
|
file: other/docker/${{ matrix.tool }}/Dockerfile
|
||||||
|
|
||||||
mypy:
|
coverage-linux:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
- name: Set up Python 3.9
|
- name: Build, test, and upload coverage
|
||||||
uses: actions/setup-python@v1
|
run: other/docker/coverage/run
|
||||||
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
|
|
||||||
|
|
||||||
doxygen:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
- name: Docker Build
|
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
|
||||||
file: other/docker/doxygen/Dockerfile
|
|
||||||
|
|
||||||
tokstyle:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
- name: Docker Build
|
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
|
||||||
file: other/docker/tokstyle/Dockerfile
|
|
||||||
|
|
||||||
misra:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
- name: Docker Build
|
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
|
||||||
file: other/docker/misra/Dockerfile
|
|
||||||
|
|
||||||
build-autotools:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
- name: Docker Build
|
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
|
||||||
file: other/docker/autotools/Dockerfile
|
|
||||||
|
|
||||||
build-tcc:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
- name: Docker Build
|
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
|
||||||
file: other/docker/tcc/Dockerfile
|
|
||||||
|
|
||||||
build-compcert:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
- name: Docker Build
|
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
|
||||||
file: other/docker/compcert/Dockerfile
|
|
||||||
|
|
||||||
generate-events:
|
generate-events:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -120,42 +55,6 @@ jobs:
|
|||||||
- name: Run cimplefmt
|
- name: Run cimplefmt
|
||||||
run: other/docker/cimplefmt/run -u $(find tox* -name "*.[ch]")
|
run: other/docker/cimplefmt/run -u $(find tox* -name "*.[ch]")
|
||||||
|
|
||||||
build-win32:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
submodules: recursive
|
|
||||||
- name: Cross compilation
|
|
||||||
run: .github/scripts/cmake-win32 script
|
|
||||||
|
|
||||||
build-win64:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
submodules: recursive
|
|
||||||
- name: Cross compilation
|
|
||||||
run: .github/scripts/cmake-win64 script
|
|
||||||
|
|
||||||
build-macos:
|
|
||||||
runs-on: macos-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
submodules: recursive
|
|
||||||
- name: Build and test
|
|
||||||
run: .github/scripts/cmake-osx
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
build-android:
|
build-android:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -166,3 +65,68 @@ jobs:
|
|||||||
- run: .github/scripts/cmake-android arm64-v8a
|
- run: .github/scripts/cmake-android arm64-v8a
|
||||||
- run: .github/scripts/cmake-android x86
|
- run: .github/scripts/cmake-android x86
|
||||||
- run: .github/scripts/cmake-android x86_64
|
- run: .github/scripts/cmake-android x86_64
|
||||||
|
|
||||||
|
build-macos:
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
- name: Build and test
|
||||||
|
run: .github/scripts/cmake-osx
|
||||||
|
|
||||||
|
build-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@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
- name: Export GitHub Actions cache environment variables
|
||||||
|
uses: actions/github-script@v6
|
||||||
|
with:
|
||||||
|
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 --preset windows-default
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build _build
|
||||||
|
- name: Test
|
||||||
|
run: |
|
||||||
|
cd _build
|
||||||
|
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6 --build-config Debug
|
||||||
|
|
||||||
|
build-windows:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
bits: [32, 64]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
- name: Cross compilation
|
||||||
|
run: .github/scripts/cmake-win${{ matrix.bits }} script
|
||||||
|
|
||||||
|
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
|
||||||
|
3
external/toxcore/c-toxcore/.gitignore
vendored
3
external/toxcore/c-toxcore/.gitignore
vendored
@@ -14,6 +14,8 @@ Thumbs.db
|
|||||||
/_build
|
/_build
|
||||||
/_install
|
/_install
|
||||||
/tox-0.0.0*
|
/tox-0.0.0*
|
||||||
|
/.vs
|
||||||
|
/CppProperties.json
|
||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
CMakeFiles
|
CMakeFiles
|
||||||
Makefile
|
Makefile
|
||||||
@@ -91,4 +93,5 @@ cscope.files
|
|||||||
# rpm
|
# rpm
|
||||||
tox.spec
|
tox.spec
|
||||||
|
|
||||||
|
/infer
|
||||||
.idea/
|
.idea/
|
||||||
|
2
external/toxcore/c-toxcore/BUILD.bazel
vendored
2
external/toxcore/c-toxcore/BUILD.bazel
vendored
@@ -1,7 +1,7 @@
|
|||||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||||
load("//tools/project:build_defs.bzl", "project")
|
load("//tools/project:build_defs.bzl", "project")
|
||||||
|
|
||||||
project()
|
project(license = "gpl3-https")
|
||||||
|
|
||||||
genrule(
|
genrule(
|
||||||
name = "public_headers",
|
name = "public_headers",
|
||||||
|
129
external/toxcore/c-toxcore/CMakeLists.txt
vendored
129
external/toxcore/c-toxcore/CMakeLists.txt
vendored
@@ -81,7 +81,7 @@ find_package(GTest)
|
|||||||
set(CMAKE_MACOSX_RPATH ON)
|
set(CMAKE_MACOSX_RPATH ON)
|
||||||
|
|
||||||
# Set standard version for compiler.
|
# Set standard version for compiler.
|
||||||
if(MSVC)
|
if(MSVC AND MSVC_TOOLSET_VERSION LESS 143)
|
||||||
# https://developercommunity.visualstudio.com/t/older-winsdk-headers-are-incompatible-with-zcprepr/1593479
|
# https://developercommunity.visualstudio.com/t/older-winsdk-headers-are-incompatible-with-zcprepr/1593479
|
||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
else()
|
else()
|
||||||
@@ -94,6 +94,35 @@ set(CMAKE_CXX_EXTENSIONS OFF)
|
|||||||
message(STATUS "Supported C compiler features = ${CMAKE_C_COMPILE_FEATURES}")
|
message(STATUS "Supported C compiler features = ${CMAKE_C_COMPILE_FEATURES}")
|
||||||
message(STATUS "Supported C++ compiler features = ${CMAKE_CXX_COMPILE_FEATURES}")
|
message(STATUS "Supported C++ compiler features = ${CMAKE_CXX_COMPILE_FEATURES}")
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
set(MIN_LOGGER_LEVEL "" CACHE STRING "Logging level to use (TRACE, DEBUG, INFO, WARNING, ERROR)")
|
set(MIN_LOGGER_LEVEL "" CACHE STRING "Logging level to use (TRACE, DEBUG, INFO, WARNING, ERROR)")
|
||||||
if(MIN_LOGGER_LEVEL)
|
if(MIN_LOGGER_LEVEL)
|
||||||
if(("${MIN_LOGGER_LEVEL}" STREQUAL "TRACE") OR
|
if(("${MIN_LOGGER_LEVEL}" STREQUAL "TRACE") OR
|
||||||
@@ -131,21 +160,7 @@ if(BOOTSTRAP_DAEMON AND WIN32)
|
|||||||
set(BOOTSTRAP_DAEMON OFF)
|
set(BOOTSTRAP_DAEMON OFF)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Enabling this breaks all other tests and no network connections will be possible
|
|
||||||
option(BUILD_FUZZ_TESTS "Build fuzzing harnesses" OFF)
|
option(BUILD_FUZZ_TESTS "Build fuzzing harnesses" OFF)
|
||||||
if(BUILD_FUZZ_TESTS)
|
|
||||||
message(STATUS "Building in fuzz testing mode, no network connection will be possible")
|
|
||||||
# Disable everything we can
|
|
||||||
set(AUTOTEST OFF)
|
|
||||||
set(BUILD_MISC_TESTS OFF)
|
|
||||||
set(BUILD_FUN_UTILS OFF)
|
|
||||||
set(ENABLE_SHARED OFF)
|
|
||||||
set(MUST_BUILD_TOXAV OFF)
|
|
||||||
set(BUILD_TOXAV OFF)
|
|
||||||
set(BOOTSTRAP_DAEMON OFF)
|
|
||||||
set(DHT_BOOTSTRAP OFF)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
option(MSVC_STATIC_SODIUM "Whether to link libsodium statically for MSVC" OFF)
|
option(MSVC_STATIC_SODIUM "Whether to link libsodium statically for MSVC" OFF)
|
||||||
@@ -327,10 +342,14 @@ set(toxcore_SOURCES
|
|||||||
toxcore/tox_unpack.h
|
toxcore/tox_unpack.h
|
||||||
toxcore/util.c
|
toxcore/util.c
|
||||||
toxcore/util.h)
|
toxcore/util.h)
|
||||||
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${LIBSODIUM_LIBRARIES})
|
if(TARGET unofficial-sodium::sodium)
|
||||||
set(toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${LIBSODIUM_LIBRARY_DIRS})
|
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} unofficial-sodium::sodium)
|
||||||
set(toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${LIBSODIUM_INCLUDE_DIRS})
|
else()
|
||||||
set(toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${LIBSODIUM_CFLAGS_OTHER})
|
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_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium)
|
||||||
set(toxcore_API_HEADERS
|
set(toxcore_API_HEADERS
|
||||||
${toxcore_SOURCE_DIR}/toxcore/tox.h^tox
|
${toxcore_SOURCE_DIR}/toxcore/tox.h^tox
|
||||||
@@ -366,10 +385,14 @@ if(BUILD_TOXAV)
|
|||||||
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
|
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
|
||||||
${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav)
|
${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav)
|
||||||
|
|
||||||
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${OPUS_LIBRARIES} ${VPX_LIBRARIES})
|
if(MSVC)
|
||||||
set(toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${OPUS_LIBRARY_DIRS} ${VPX_LIBRARY_DIRS})
|
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} PkgConfig::OPUS PkgConfig::VPX)
|
||||||
set(toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${OPUS_INCLUDE_DIRS} ${VPX_INCLUDE_DIRS})
|
else()
|
||||||
set(toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${OPUS_CFLAGS_OTHER} ${VPX_CFLAGS_OTHER})
|
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)
|
set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} opus vpx)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -400,7 +423,6 @@ if(CMAKE_THREAD_LIBS_INIT)
|
|||||||
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
if(NSL_LIBRARIES)
|
if(NSL_LIBRARIES)
|
||||||
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${NSL_LIBRARIES})
|
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${NSL_LIBRARIES})
|
||||||
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lnsl)
|
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lnsl)
|
||||||
@@ -416,9 +438,13 @@ if(SOCKET_LIBRARIES)
|
|||||||
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lsocket)
|
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lsocket)
|
||||||
endif()
|
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)
|
if(WIN32)
|
||||||
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ws2_32 iphlpapi)
|
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} iphlpapi wsock32 ws2_32)
|
||||||
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lws2_32 -liphlpapi)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -428,20 +454,33 @@ endif()
|
|||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# Create combined library from all the sources.
|
# Create combined library from all the sources.
|
||||||
add_module(toxcore ${toxcore_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()
|
||||||
|
|
||||||
# Link it to all dependencies.
|
if(ENABLE_STATIC)
|
||||||
if(TARGET toxcore_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_libraries(toxcore_static PRIVATE ${toxcore_LINK_LIBRARIES})
|
||||||
target_link_directories(toxcore_static PUBLIC ${toxcore_LINK_DIRECTORIES})
|
target_link_directories(toxcore_static PUBLIC ${toxcore_LINK_DIRECTORIES})
|
||||||
target_include_directories(toxcore_static SYSTEM PRIVATE ${toxcore_INCLUDE_DIRECTORIES})
|
target_include_directories(toxcore_static SYSTEM PRIVATE ${toxcore_INCLUDE_DIRECTORIES})
|
||||||
target_compile_options(toxcore_static PRIVATE ${toxcore_COMPILE_OPTIONS})
|
target_compile_options(toxcore_static PRIVATE ${toxcore_COMPILE_OPTIONS})
|
||||||
endif()
|
endif()
|
||||||
if(TARGET toxcore_shared)
|
|
||||||
target_link_libraries(toxcore_shared PRIVATE ${toxcore_LINK_LIBRARIES})
|
if(BUILD_FUZZ_TESTS)
|
||||||
target_link_directories(toxcore_shared PUBLIC ${toxcore_LINK_DIRECTORIES})
|
add_library(toxcore_fuzz STATIC ${toxcore_SOURCES})
|
||||||
target_include_directories(toxcore_shared SYSTEM PRIVATE ${toxcore_INCLUDE_DIRECTORIES})
|
target_link_libraries(toxcore_fuzz PRIVATE ${toxcore_LINK_LIBRARIES})
|
||||||
target_compile_options(toxcore_shared PRIVATE ${toxcore_COMPILE_OPTIONS})
|
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()
|
endif()
|
||||||
|
|
||||||
# Make version script (on systems that support it) to limit symbol visibility.
|
# Make version script (on systems that support it) to limit symbol visibility.
|
||||||
@@ -457,14 +496,25 @@ install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox)
|
|||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
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/network_test_util.cc
|
||||||
|
toxcore/network_test_util.hh
|
||||||
|
toxcore/test_util.cc
|
||||||
|
toxcore/test_util.hh)
|
||||||
|
|
||||||
function(unit_test subdir target)
|
function(unit_test subdir target)
|
||||||
add_executable(unit_${target}_test ${subdir}/${target}_test.cc)
|
add_executable(unit_${target}_test ${subdir}/${target}_test.cc)
|
||||||
|
target_link_libraries(unit_${target}_test PRIVATE test_util)
|
||||||
if(TARGET toxcore_static)
|
if(TARGET toxcore_static)
|
||||||
target_link_libraries(unit_${target}_test PRIVATE toxcore_static)
|
target_link_libraries(unit_${target}_test PRIVATE toxcore_static)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(unit_${target}_test PRIVATE toxcore_shared)
|
target_link_libraries(unit_${target}_test PRIVATE toxcore_shared)
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(unit_${target}_test PRIVATE GTest::GTest GTest::Main)
|
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}")
|
set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${TEST_CXX_FLAGS}")
|
||||||
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
|
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
|
||||||
set_property(TEST ${target} PROPERTY ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw")
|
set_property(TEST ${target} PROPERTY ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw")
|
||||||
@@ -484,6 +534,7 @@ if(GTEST_FOUND)
|
|||||||
unit_test(toxcore mem)
|
unit_test(toxcore mem)
|
||||||
unit_test(toxcore mono_time)
|
unit_test(toxcore mono_time)
|
||||||
unit_test(toxcore ping_array)
|
unit_test(toxcore ping_array)
|
||||||
|
unit_test(toxcore test_util)
|
||||||
unit_test(toxcore tox)
|
unit_test(toxcore tox)
|
||||||
unit_test(toxcore util)
|
unit_test(toxcore util)
|
||||||
endif()
|
endif()
|
||||||
@@ -516,6 +567,14 @@ if(DHT_BOOTSTRAP)
|
|||||||
target_link_libraries(DHT_bootstrap PRIVATE toxcore_shared)
|
target_link_libraries(DHT_bootstrap PRIVATE toxcore_shared)
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(DHT_bootstrap PRIVATE misc_tools)
|
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)
|
install(TARGETS DHT_bootstrap RUNTIME DESTINATION bin)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
21
external/toxcore/c-toxcore/CMakePresets.json
vendored
Normal file
21
external/toxcore/c-toxcore/CMakePresets.json
vendored
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
9
external/toxcore/c-toxcore/LICENSE
vendored
9
external/toxcore/c-toxcore/LICENSE
vendored
@@ -1,7 +1,7 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
Version 3, 29 June 2007
|
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
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
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.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
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.
|
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,
|
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.
|
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
|
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
|
The GNU General Public License does not permit incorporating your program
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
may consider it more useful to permit linking proprietary applications with
|
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
|
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
|
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>.
|
||||||
|
|
||||||
|
@@ -9,6 +9,11 @@ if(TARGET toxcore_static)
|
|||||||
else()
|
else()
|
||||||
target_link_libraries(auto_test_support PRIVATE toxcore_shared)
|
target_link_libraries(auto_test_support PRIVATE toxcore_shared)
|
||||||
endif()
|
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)
|
function(auto_test target)
|
||||||
add_executable(auto_${target}_test ${target}_test.c)
|
add_executable(auto_${target}_test ${target}_test.c)
|
||||||
@@ -18,12 +23,15 @@ function(auto_test target)
|
|||||||
else()
|
else()
|
||||||
target_link_libraries(auto_${target}_test PRIVATE toxcore_shared)
|
target_link_libraries(auto_${target}_test PRIVATE toxcore_shared)
|
||||||
endif()
|
endif()
|
||||||
if(NOT ARGV1 STREQUAL "DONT_RUN")
|
if(TARGET PThreads4W::PThreads4W)
|
||||||
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test)
|
target_link_libraries(auto_${target}_test PRIVATE PThreads4W::PThreads4W)
|
||||||
set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
|
elseif(TARGET Threads::Threads)
|
||||||
# add the source dir as environment variable, so the testdata can be found
|
target_link_libraries(auto_${target}_test PRIVATE Threads::Threads)
|
||||||
set_tests_properties(${target} PROPERTIES ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw;srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
|
||||||
endif()
|
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()
|
endfunction()
|
||||||
|
|
||||||
auto_test(TCP)
|
auto_test(TCP)
|
||||||
@@ -89,15 +97,20 @@ if(BUILD_TOXAV)
|
|||||||
auto_test(toxav_basic)
|
auto_test(toxav_basic)
|
||||||
auto_test(toxav_many)
|
auto_test(toxav_many)
|
||||||
|
|
||||||
target_link_libraries(auto_toxav_basic_test PRIVATE ${VPX_LIBRARIES})
|
if(MSVC)
|
||||||
target_link_directories(auto_toxav_basic_test PRIVATE ${VPX_LIBRARY_DIRS})
|
target_link_libraries(auto_toxav_basic_test PRIVATE PkgConfig::VPX)
|
||||||
target_include_directories(auto_toxav_basic_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS})
|
target_link_libraries(auto_toxav_many_test PRIVATE PkgConfig::VPX)
|
||||||
target_compile_options(auto_toxav_basic_test PRIVATE ${VPX_CFLAGS_OTHER})
|
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_libraries(auto_toxav_many_test PRIVATE ${VPX_LIBRARIES})
|
||||||
target_link_directories(auto_toxav_many_test PRIVATE ${VPX_LIBRARY_DIRS})
|
target_link_directories(auto_toxav_many_test PRIVATE ${VPX_LIBRARY_DIRS})
|
||||||
target_include_directories(auto_toxav_many_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS})
|
target_include_directories(auto_toxav_many_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS})
|
||||||
target_compile_options(auto_toxav_many_test PRIVATE ${VPX_CFLAGS_OTHER})
|
target_compile_options(auto_toxav_many_test PRIVATE ${VPX_CFLAGS_OTHER})
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(PROXY_TEST)
|
if(PROXY_TEST)
|
||||||
|
@@ -187,14 +187,14 @@ TCP_test_SOURCES = ../auto_tests/TCP_test.c
|
|||||||
TCP_test_CFLAGS = $(AUTOTEST_CFLAGS)
|
TCP_test_CFLAGS = $(AUTOTEST_CFLAGS)
|
||||||
TCP_test_LDADD = $(AUTOTEST_LDADD)
|
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_SOURCES = ../auto_tests/tox_dispatch_test.c
|
||||||
tox_dispatch_test_CFLAGS = $(AUTOTEST_CFLAGS)
|
tox_dispatch_test_CFLAGS = $(AUTOTEST_CFLAGS)
|
||||||
tox_dispatch_test_LDADD = $(AUTOTEST_LDADD)
|
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_SOURCES = ../auto_tests/tox_many_tcp_test.c
|
||||||
tox_many_tcp_test_CFLAGS = $(AUTOTEST_CFLAGS)
|
tox_many_tcp_test_CFLAGS = $(AUTOTEST_CFLAGS)
|
||||||
tox_many_tcp_test_LDADD = $(AUTOTEST_LDADD)
|
tox_many_tcp_test_LDADD = $(AUTOTEST_LDADD)
|
||||||
|
@@ -149,6 +149,8 @@ void set_mono_time_callback(AutoTox *autotox)
|
|||||||
Mono_Time *mono_time = autotox->tox->mono_time;
|
Mono_Time *mono_time = autotox->tox->mono_time;
|
||||||
|
|
||||||
autotox->clock = current_time_monotonic(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, nullptr, nullptr); // set to default first
|
||||||
mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &autotox->clock);
|
mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &autotox->clock);
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
#define ck_assert(ok) do { \
|
#define ck_assert(ok) do { \
|
||||||
if (!(ok)) { \
|
if (!(ok)) { \
|
||||||
fprintf(stderr, "%s:%d: failed `%s'\n", __FILE__, __LINE__, #ok); \
|
fprintf(stderr, "%s:%d: failed `%s'\n", __FILE__, __LINE__, #ok); \
|
||||||
abort(); \
|
exit(7); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
fprintf(stderr, "%s:%d: failed `%s': ", __FILE__, __LINE__, #ok); \
|
fprintf(stderr, "%s:%d: failed `%s': ", __FILE__, __LINE__, #ok); \
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
fprintf(stderr, "\n"); \
|
fprintf(stderr, "\n"); \
|
||||||
abort(); \
|
exit(7); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \
|
fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
fprintf(stderr, "\n"); \
|
fprintf(stderr, "\n"); \
|
||||||
abort(); \
|
exit(7); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#endif // C_TOXCORE_AUTO_TESTS_CHECK_COMPAT_H
|
#endif // C_TOXCORE_AUTO_TESTS_CHECK_COMPAT_H
|
||||||
|
@@ -395,8 +395,9 @@ static void group_message_test(AutoTox *autotoxes)
|
|||||||
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
|
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
|
||||||
|
|
||||||
if (state1->peer_joined && !state1->message_sent) {
|
if (state1->peer_joined && !state1->message_sent) {
|
||||||
tox_group_send_message(tox1, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)TEST_MESSAGE,
|
state1->pseudo_msg_id = tox_group_send_message(
|
||||||
TEST_MESSAGE_LEN, &state1->pseudo_msg_id, &err_send);
|
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);
|
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
|
||||||
state1->message_sent = true;
|
state1->message_sent = true;
|
||||||
}
|
}
|
||||||
@@ -419,7 +420,7 @@ static void group_message_test(AutoTox *autotoxes)
|
|||||||
|
|
||||||
// tox1 sends group a message which should not be seen by tox0's message handler
|
// 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,
|
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);
|
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
|
||||||
|
|
||||||
@@ -506,7 +507,7 @@ static void group_message_test(AutoTox *autotoxes)
|
|||||||
|
|
||||||
memcpy(m + 2, &checksum, sizeof(uint16_t));
|
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);
|
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
|
||||||
}
|
}
|
||||||
@@ -528,7 +529,7 @@ static void group_message_test(AutoTox *autotoxes)
|
|||||||
|
|
||||||
memcpy(m, &i, sizeof(uint16_t));
|
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);
|
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -334,21 +334,21 @@ static void voice_state_message_test(AutoTox *autotox, Tox_Group_Voice_State voi
|
|||||||
ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK);
|
ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK);
|
||||||
|
|
||||||
Tox_Err_Group_Send_Message msg_err;
|
Tox_Err_Group_Send_Message msg_err;
|
||||||
bool send_ret = tox_group_send_message(autotox->tox, state->group_number, TOX_MESSAGE_TYPE_NORMAL,
|
tox_group_send_message(autotox->tox, state->group_number, TOX_MESSAGE_TYPE_NORMAL,
|
||||||
(const uint8_t *)"test", 4, nullptr, &msg_err);
|
(const uint8_t *)"test", 4, &msg_err);
|
||||||
|
|
||||||
switch (self_role) {
|
switch (self_role) {
|
||||||
case TOX_GROUP_ROLE_OBSERVER: {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TOX_GROUP_ROLE_USER: {
|
case TOX_GROUP_ROLE_USER: {
|
||||||
if (voice_state != TOX_GROUP_VOICE_STATE_ALL) {
|
if (voice_state != TOX_GROUP_VOICE_STATE_ALL) {
|
||||||
ck_assert_msg(!send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS,
|
ck_assert_msg(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS,
|
||||||
"%d, %d", send_ret, msg_err);
|
"%d", msg_err);
|
||||||
} else {
|
} else {
|
||||||
ck_assert(send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
|
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -356,16 +356,16 @@ static void voice_state_message_test(AutoTox *autotox, Tox_Group_Voice_State voi
|
|||||||
|
|
||||||
case TOX_GROUP_ROLE_MODERATOR: {
|
case TOX_GROUP_ROLE_MODERATOR: {
|
||||||
if (voice_state != TOX_GROUP_VOICE_STATE_FOUNDER) {
|
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 {
|
} else {
|
||||||
ck_assert(!send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
|
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TOX_GROUP_ROLE_FOUNDER: {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -206,7 +206,7 @@ static void group_tcp_test(AutoTox *autotoxes)
|
|||||||
|
|
||||||
Tox_Err_Group_Send_Message merr;
|
Tox_Err_Group_Send_Message merr;
|
||||||
tox_group_send_message(autotoxes[0].tox, groupnumber, TOX_MESSAGE_TYPE_NORMAL,
|
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);
|
ck_assert(merr == TOX_ERR_GROUP_SEND_MESSAGE_OK);
|
||||||
|
|
||||||
while (!state1->got_second_code) {
|
while (!state1->got_second_code) {
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#include "../toxcore/tox.h"
|
#include "../toxcore/tox.h"
|
||||||
#include "../toxcore/tox_dispatch.h"
|
#include "../toxcore/tox_dispatch.h"
|
||||||
#include "../toxcore/tox_events.h"
|
#include "../toxcore/tox_events.h"
|
||||||
|
#include "../toxcore/tox_private.h"
|
||||||
#include "../toxcore/tox_unpack.h"
|
#include "../toxcore/tox_unpack.h"
|
||||||
#include "auto_test_support.h"
|
#include "auto_test_support.h"
|
||||||
#include "check_compat.h"
|
#include "check_compat.h"
|
||||||
|
@@ -22,21 +22,23 @@ static bool await_message(Tox **toxes)
|
|||||||
Tox_Events *events = tox_events_iterate(toxes[1], false, nullptr);
|
Tox_Events *events = tox_events_iterate(toxes[1], false, nullptr);
|
||||||
|
|
||||||
if (events != nullptr) {
|
if (events != nullptr) {
|
||||||
ck_assert(tox_events_get_friend_message_size(events) == 1);
|
uint32_t events_size = tox_events_get_size(events);
|
||||||
const Tox_Event_Friend_Message *msg_event = tox_events_get_friend_message(events, 0);
|
ck_assert(events_size == 1);
|
||||||
|
|
||||||
|
const Tox_Event_Friend_Message *msg_event = nullptr;
|
||||||
|
for (uint32_t j = 0; j < events_size; ++j) {
|
||||||
|
const Tox_Event *ev = tox_events_get(events, j);
|
||||||
|
if (tox_event_get_type(ev) == TOX_EVENT_FRIEND_MESSAGE) {
|
||||||
|
msg_event = tox_event_get_friend_message(ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ck_assert(msg_event != nullptr);
|
||||||
ck_assert(tox_event_friend_message_get_message_length(msg_event) == sizeof("hello"));
|
ck_assert(tox_event_friend_message_get_message_length(msg_event) == sizeof("hello"));
|
||||||
const uint8_t *msg = tox_event_friend_message_get_message(msg_event);
|
const uint8_t *msg = tox_event_friend_message_get_message(msg_event);
|
||||||
ck_assert_msg(memcmp(msg, "hello", sizeof("hello")) == 0,
|
ck_assert_msg(memcmp(msg, "hello", sizeof("hello")) == 0,
|
||||||
"message was not expected 'hello' but '%s'", (const char *)msg);
|
"message was not expected 'hello' but '%s'", (const char *)msg);
|
||||||
|
|
||||||
const uint32_t event_count = tox_events_get_size(events);
|
|
||||||
for (uint32_t j = 0; j < event_count; ++j) {
|
|
||||||
const Tox_Event *event = tox_events_get(events, j);
|
|
||||||
if (tox_event_get_type(event) == TOX_EVENT_FRIEND_MESSAGE) {
|
|
||||||
ck_assert(tox_event_get_friend_message(event) == msg_event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tox_events_free(events);
|
tox_events_free(events);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -1,19 +1,26 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
# :: For UNIX-like systems that have pkg-config.
|
# :: For systems that have pkg-config.
|
||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
include(ModulePackage)
|
find_package(PkgConfig REQUIRED)
|
||||||
|
|
||||||
find_package(Threads REQUIRED)
|
|
||||||
|
|
||||||
find_library(NSL_LIBRARIES nsl )
|
find_library(NSL_LIBRARIES nsl )
|
||||||
find_library(RT_LIBRARIES rt )
|
find_library(RT_LIBRARIES rt )
|
||||||
find_library(SOCKET_LIBRARIES socket)
|
find_library(SOCKET_LIBRARIES socket)
|
||||||
|
|
||||||
|
find_package(pthreads QUIET)
|
||||||
|
if(NOT TARGET PThreads4W::PThreads4W)
|
||||||
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
endif()
|
||||||
|
|
||||||
# For toxcore.
|
# For toxcore.
|
||||||
pkg_search_module(LIBSODIUM libsodium IMPORTED_TARGET)
|
pkg_search_module(LIBSODIUM libsodium IMPORTED_TARGET REQUIRED)
|
||||||
|
if(MSVC)
|
||||||
|
find_package(unofficial-sodium REQUIRED)
|
||||||
|
endif()
|
||||||
|
|
||||||
# For toxav.
|
# For toxav.
|
||||||
pkg_search_module(OPUS opus IMPORTED_TARGET)
|
pkg_search_module(OPUS opus IMPORTED_TARGET)
|
||||||
@@ -27,56 +34,3 @@ endif()
|
|||||||
|
|
||||||
# For tox-bootstrapd.
|
# For tox-bootstrapd.
|
||||||
pkg_search_module(LIBCONFIG libconfig IMPORTED_TARGET)
|
pkg_search_module(LIBCONFIG libconfig IMPORTED_TARGET)
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
#
|
|
||||||
# :: For MSVC Windows builds.
|
|
||||||
#
|
|
||||||
# These require specific installation paths of dependencies:
|
|
||||||
# - libsodium in third-party/libsodium/Win32/Release/v140/dynamic
|
|
||||||
# - pthreads in third-party/pthreads-win32/Pre-built.2
|
|
||||||
#
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
if(MSVC)
|
|
||||||
# libsodium
|
|
||||||
# ---------
|
|
||||||
if(NOT LIBSODIUM_FOUND)
|
|
||||||
find_library(LIBSODIUM_LIBRARIES
|
|
||||||
NAMES sodium libsodium
|
|
||||||
PATHS
|
|
||||||
"third_party/libsodium/Win32/Release/v140/dynamic"
|
|
||||||
"third_party/libsodium/x64/Release/v140/dynamic"
|
|
||||||
)
|
|
||||||
if(LIBSODIUM_LIBRARIES)
|
|
||||||
include_directories("third_party/libsodium/include")
|
|
||||||
set(LIBSODIUM_FOUND TRUE)
|
|
||||||
message("libsodium: ${LIBSODIUM_LIBRARIES}")
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "libsodium libraries not found")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# pthreads
|
|
||||||
# --------
|
|
||||||
if(CMAKE_USE_WIN32_THREADS_INIT)
|
|
||||||
find_library(CMAKE_THREAD_LIBS_INIT
|
|
||||||
NAMES pthreadVC2
|
|
||||||
PATHS
|
|
||||||
"third_party/pthreads-win32/Pre-built.2/lib/x86"
|
|
||||||
"third_party/pthreads-win32/Pre-built.2/lib/x64"
|
|
||||||
)
|
|
||||||
if(CMAKE_THREAD_LIBS_INIT)
|
|
||||||
include_directories("third_party/pthreads-win32/Pre-built.2/include")
|
|
||||||
add_definitions(-DHAVE_STRUCT_TIMESPEC)
|
|
||||||
message("libpthreads: ${CMAKE_THREAD_LIBS_INIT}")
|
|
||||||
else()
|
|
||||||
find_package(pthreads4w)
|
|
||||||
if(NOT pthreads4w_FOUND)
|
|
||||||
message(FATAL_ERROR "libpthreads libraries not found")
|
|
||||||
endif()
|
|
||||||
include_directories(${pthreads4w_INCLUDE_DIR})
|
|
||||||
link_libraries(${pthreads4w_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
@@ -19,21 +19,6 @@ if(FULLY_STATIC)
|
|||||||
set(ENABLE_STATIC ON)
|
set(ENABLE_STATIC ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(PkgConfig)
|
|
||||||
|
|
||||||
function(add_module lib)
|
|
||||||
set(${lib}_SOURCES ${ARGN} PARENT_SCOPE)
|
|
||||||
|
|
||||||
if(ENABLE_SHARED)
|
|
||||||
add_library(${lib}_shared SHARED ${ARGN})
|
|
||||||
set_target_properties(${lib}_shared PROPERTIES OUTPUT_NAME ${lib})
|
|
||||||
endif()
|
|
||||||
if(ENABLE_STATIC)
|
|
||||||
add_library(${lib}_static STATIC ${ARGN})
|
|
||||||
set_target_properties(${lib}_static PROPERTIES OUTPUT_NAME ${lib})
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(install_module lib)
|
function(install_module lib)
|
||||||
if(TARGET ${lib}_shared)
|
if(TARGET ${lib}_shared)
|
||||||
set_target_properties(${lib}_shared PROPERTIES
|
set_target_properties(${lib}_shared PROPERTIES
|
||||||
|
4
external/toxcore/c-toxcore/heroku.yml
vendored
4
external/toxcore/c-toxcore/heroku.yml
vendored
@@ -1,4 +0,0 @@
|
|||||||
---
|
|
||||||
build:
|
|
||||||
docker:
|
|
||||||
web: other/bootstrap_daemon/websocket/Dockerfile
|
|
2
external/toxcore/c-toxcore/other/BUILD.bazel
vendored
2
external/toxcore/c-toxcore/other/BUILD.bazel
vendored
@@ -21,13 +21,11 @@ cc_binary(
|
|||||||
"//c-toxcore/toxcore:Messenger",
|
"//c-toxcore/toxcore:Messenger",
|
||||||
"//c-toxcore/toxcore:TCP_server",
|
"//c-toxcore/toxcore:TCP_server",
|
||||||
"//c-toxcore/toxcore:ccompat",
|
"//c-toxcore/toxcore:ccompat",
|
||||||
"//c-toxcore/toxcore:friend_requests",
|
|
||||||
"//c-toxcore/toxcore:group_onion_announce",
|
"//c-toxcore/toxcore:group_onion_announce",
|
||||||
"//c-toxcore/toxcore:logger",
|
"//c-toxcore/toxcore:logger",
|
||||||
"//c-toxcore/toxcore:mono_time",
|
"//c-toxcore/toxcore:mono_time",
|
||||||
"//c-toxcore/toxcore:network",
|
"//c-toxcore/toxcore:network",
|
||||||
"//c-toxcore/toxcore:onion_announce",
|
"//c-toxcore/toxcore:onion_announce",
|
||||||
"//c-toxcore/toxcore:tox",
|
"//c-toxcore/toxcore:tox",
|
||||||
"//c-toxcore/toxcore:util",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
38
external/toxcore/c-toxcore/other/DHT_bootstrap.c
vendored
38
external/toxcore/c-toxcore/other/DHT_bootstrap.c
vendored
@@ -16,12 +16,17 @@
|
|||||||
#include "../toxcore/DHT.h"
|
#include "../toxcore/DHT.h"
|
||||||
#include "../toxcore/LAN_discovery.h"
|
#include "../toxcore/LAN_discovery.h"
|
||||||
#include "../toxcore/ccompat.h"
|
#include "../toxcore/ccompat.h"
|
||||||
#include "../toxcore/friend_requests.h"
|
#include "../toxcore/crypto_core.h"
|
||||||
|
#include "../toxcore/forwarding.h"
|
||||||
|
#include "../toxcore/group_announce.h"
|
||||||
#include "../toxcore/group_onion_announce.h"
|
#include "../toxcore/group_onion_announce.h"
|
||||||
#include "../toxcore/logger.h"
|
#include "../toxcore/logger.h"
|
||||||
|
#include "../toxcore/mem.h"
|
||||||
#include "../toxcore/mono_time.h"
|
#include "../toxcore/mono_time.h"
|
||||||
|
#include "../toxcore/network.h"
|
||||||
|
#include "../toxcore/onion.h"
|
||||||
|
#include "../toxcore/onion_announce.h"
|
||||||
#include "../toxcore/tox.h"
|
#include "../toxcore/tox.h"
|
||||||
#include "../toxcore/util.h"
|
|
||||||
|
|
||||||
#define TCP_RELAY_ENABLED
|
#define TCP_RELAY_ENABLED
|
||||||
|
|
||||||
@@ -46,7 +51,7 @@ static const char *motd_str = ""; //Change this to anything within 256 bytes(but
|
|||||||
#define PORT 33445
|
#define PORT 33445
|
||||||
|
|
||||||
|
|
||||||
static void manage_keys(DHT *dht)
|
static bool manage_keys(DHT *dht)
|
||||||
{
|
{
|
||||||
enum { KEYS_SIZE = CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE };
|
enum { KEYS_SIZE = CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE };
|
||||||
uint8_t keys[KEYS_SIZE];
|
uint8_t keys[KEYS_SIZE];
|
||||||
@@ -60,7 +65,8 @@ static void manage_keys(DHT *dht)
|
|||||||
|
|
||||||
if (read_size != KEYS_SIZE) {
|
if (read_size != KEYS_SIZE) {
|
||||||
printf("Error while reading the key file\nExiting.\n");
|
printf("Error while reading the key file\nExiting.\n");
|
||||||
exit(1);
|
fclose(keys_file);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dht_set_self_public_key(dht, keys);
|
dht_set_self_public_key(dht, keys);
|
||||||
@@ -73,18 +79,20 @@ static void manage_keys(DHT *dht)
|
|||||||
|
|
||||||
if (keys_file == nullptr) {
|
if (keys_file == nullptr) {
|
||||||
printf("Error opening key file in write mode.\nKeys will not be saved.\n");
|
printf("Error opening key file in write mode.\nKeys will not be saved.\n");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) {
|
if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) {
|
||||||
printf("Error while writing the key file.\nExiting.\n");
|
printf("Error while writing the key file.\nExiting.\n");
|
||||||
exit(1);
|
fclose(keys_file);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Keys saved successfully.\n");
|
printf("Keys saved successfully.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(keys_file);
|
fclose(keys_file);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *strlevel(Logger_Level level)
|
static const char *strlevel(Logger_Level level)
|
||||||
@@ -121,7 +129,7 @@ int main(int argc, char *argv[])
|
|||||||
if (argc == 2 && !tox_strncasecmp(argv[1], "-h", 3)) {
|
if (argc == 2 && !tox_strncasecmp(argv[1], "-h", 3)) {
|
||||||
printf("Usage (connected) : %s [--ipv4|--ipv6] IP PORT KEY\n", argv[0]);
|
printf("Usage (connected) : %s [--ipv4|--ipv6] IP PORT KEY\n", argv[0]);
|
||||||
printf("Usage (unconnected): %s [--ipv4|--ipv6]\n", argv[0]);
|
printf("Usage (unconnected): %s [--ipv4|--ipv6]\n", argv[0]);
|
||||||
exit(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* let user override default by cmdline */
|
/* let user override default by cmdline */
|
||||||
@@ -129,7 +137,7 @@ int main(int argc, char *argv[])
|
|||||||
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
|
||||||
|
|
||||||
if (argvoffset < 0) {
|
if (argvoffset < 0) {
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize networking -
|
/* Initialize networking -
|
||||||
@@ -162,14 +170,16 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (!(onion && forwarding && onion_a)) {
|
if (!(onion && forwarding && onion_a)) {
|
||||||
printf("Something failed to initialize.\n");
|
printf("Something failed to initialize.\n");
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
gca_onion_init(gc_announces_list, onion_a);
|
gca_onion_init(gc_announces_list, onion_a);
|
||||||
|
|
||||||
perror("Initialization");
|
perror("Initialization");
|
||||||
|
|
||||||
manage_keys(dht);
|
if (!manage_keys(dht)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
printf("Public key: ");
|
printf("Public key: ");
|
||||||
|
|
||||||
#ifdef TCP_RELAY_ENABLED
|
#ifdef TCP_RELAY_ENABLED
|
||||||
@@ -179,7 +189,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (tcp_s == nullptr) {
|
if (tcp_s == nullptr) {
|
||||||
printf("TCP server failed to initialize.\n");
|
printf("TCP server failed to initialize.\n");
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -189,7 +199,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (file == nullptr) {
|
if (file == nullptr) {
|
||||||
printf("Could not open file \"%s\" for writing. Exiting...\n", public_id_filename);
|
printf("Could not open file \"%s\" for writing. Exiting...\n", public_id_filename);
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 32; ++i) {
|
for (uint32_t i = 0; i < 32; ++i) {
|
||||||
@@ -210,7 +220,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (port_conv <= 0 || port_conv > UINT16_MAX) {
|
if (port_conv <= 0 || port_conv > UINT16_MAX) {
|
||||||
printf("Failed to convert \"%s\" into a valid port. Exiting...\n", argv[argvoffset + 2]);
|
printf("Failed to convert \"%s\" into a valid port. Exiting...\n", argv[argvoffset + 2]);
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint16_t port = net_htons((uint16_t)port_conv);
|
const uint16_t port = net_htons((uint16_t)port_conv);
|
||||||
@@ -222,7 +232,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
|
printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,8 +31,8 @@ out = (subprocess.run(
|
|||||||
|
|
||||||
errors = 0
|
errors = 0
|
||||||
for line in out.split("\n"):
|
for line in out.split("\n"):
|
||||||
# other/fun can do what it wants.
|
# other/fun and mallocfail can do what they want.
|
||||||
if "/fun/" in line:
|
if "/fun/" in line or "/mallocfail/" in line:
|
||||||
continue
|
continue
|
||||||
filename, include = line.split(":", 1)
|
filename, include = line.split(":", 1)
|
||||||
# We only check headers.
|
# We only check headers.
|
||||||
|
@@ -15,7 +15,7 @@ CPPFLAGS+=("-Itoxav")
|
|||||||
CPPFLAGS+=("-Itoxencryptsave")
|
CPPFLAGS+=("-Itoxencryptsave")
|
||||||
CPPFLAGS+=("-Ithird_party/cmp")
|
CPPFLAGS+=("-Ithird_party/cmp")
|
||||||
|
|
||||||
LDFLAGS=("-lopus" "-lsodium" "-lvpx" "-lpthread" "-lconfig" "-lgtest")
|
LDFLAGS=("-lopus" "-lsodium" "-lvpx" "-lpthread" "-lconfig" "-lgmock" "-lgtest")
|
||||||
LDFLAGS+=("-fuse-ld=gold")
|
LDFLAGS+=("-fuse-ld=gold")
|
||||||
LDFLAGS+=("-Wl,--detect-odr-violations")
|
LDFLAGS+=("-Wl,--detect-odr-violations")
|
||||||
LDFLAGS+=("-Wl,--warn-common")
|
LDFLAGS+=("-Wl,--warn-common")
|
||||||
|
@@ -10,7 +10,7 @@ run() {
|
|||||||
"${CPPFLAGS[@]}" \
|
"${CPPFLAGS[@]}" \
|
||||||
"${LDFLAGS[@]}" \
|
"${LDFLAGS[@]}" \
|
||||||
"$@" \
|
"$@" \
|
||||||
-std=c++11 \
|
-std=c++17 \
|
||||||
-Werror \
|
-Werror \
|
||||||
-Weverything \
|
-Weverything \
|
||||||
-Wno-alloca \
|
-Wno-alloca \
|
||||||
|
@@ -9,7 +9,7 @@ run() {
|
|||||||
clang++ --analyze amalgamation.cc \
|
clang++ --analyze amalgamation.cc \
|
||||||
"${CPPFLAGS[@]}" \
|
"${CPPFLAGS[@]}" \
|
||||||
"$@" \
|
"$@" \
|
||||||
-std=c++11
|
-std=c++20
|
||||||
}
|
}
|
||||||
|
|
||||||
. other/analysis/variants.sh
|
. other/analysis/variants.sh
|
||||||
|
@@ -1,6 +1,64 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
CHECKS="*"
|
CHECKS="*"
|
||||||
|
ERRORS="*"
|
||||||
|
|
||||||
|
# Need to investigate or disable and document these.
|
||||||
|
# =========================================================
|
||||||
|
|
||||||
|
# TODO(iphydf): Fix these.
|
||||||
|
ERRORS="$ERRORS,-cert-err34-c"
|
||||||
|
ERRORS="$ERRORS,-readability-suspicious-call-argument"
|
||||||
|
|
||||||
|
# TODO(iphydf): Fix once cimple 0.0.19 is released.
|
||||||
|
CHECKS="$CHECKS,-google-readability-casting"
|
||||||
|
|
||||||
|
# TODO(iphydf): Fix these.
|
||||||
|
CHECKS="$CHECKS,-bugprone-switch-missing-default-case"
|
||||||
|
|
||||||
|
# TODO(iphydf): We might want some of these. For the ones we don't want, add a
|
||||||
|
# comment explaining why not.
|
||||||
|
CHECKS="$CHECKS,-clang-analyzer-optin.performance.Padding"
|
||||||
|
CHECKS="$CHECKS,-hicpp-signed-bitwise"
|
||||||
|
|
||||||
|
# TODO(iphydf): Maybe fix these?
|
||||||
|
CHECKS="$CHECKS,-bugprone-implicit-widening-of-multiplication-result"
|
||||||
|
CHECKS="$CHECKS,-bugprone-integer-division"
|
||||||
|
CHECKS="$CHECKS,-misc-no-recursion"
|
||||||
|
|
||||||
|
# TODO(iphydf): Only happens in bootstrap_daemon. Fix it.
|
||||||
|
CHECKS="$CHECKS,-cppcoreguidelines-avoid-non-const-global-variables"
|
||||||
|
|
||||||
|
# TODO(iphydf): Probably fix these.
|
||||||
|
CHECKS="$CHECKS,-cert-err33-c"
|
||||||
|
CHECKS="$CHECKS,-cppcoreguidelines-avoid-magic-numbers"
|
||||||
|
CHECKS="$CHECKS,-readability-magic-numbers"
|
||||||
|
|
||||||
|
# TODO(iphydf): We're using a lot of macros for constants. Should we convert
|
||||||
|
# all of them to enum?
|
||||||
|
CHECKS="$CHECKS,-modernize-macro-to-enum"
|
||||||
|
|
||||||
|
# Documented disabled checks. We don't want these for sure.
|
||||||
|
# =========================================================
|
||||||
|
|
||||||
|
# https://stackoverflow.com/questions/58672959/why-does-clang-tidy-say-vsnprintf-has-an-uninitialized-va-list-argument
|
||||||
|
CHECKS="$CHECKS,-clang-analyzer-valist.Uninitialized"
|
||||||
|
|
||||||
|
# We pass a lot of ints around, so many function parameters are some kind of
|
||||||
|
# int type that can be converted from another int type. We won't be getting
|
||||||
|
# away from that anytime soon.
|
||||||
|
CHECKS="$CHECKS,-bugprone-easily-swappable-parameters"
|
||||||
|
|
||||||
|
# Callback handlers often don't use all their parameters. There's
|
||||||
|
# IgnoreVirtual, but that doesn't work for C-style callbacks.
|
||||||
|
CHECKS="$CHECKS,-misc-unused-parameters"
|
||||||
|
|
||||||
|
# We sometimes use #if 0.
|
||||||
|
CHECKS="$CHECKS,-readability-avoid-unconditional-preprocessor-if"
|
||||||
|
|
||||||
|
# We have better macro hygiene checks with tokstyle. We can never pass macro
|
||||||
|
# arguments that require parentheses inside the macro.
|
||||||
|
CHECKS="$CHECKS,-bugprone-macro-parentheses"
|
||||||
|
|
||||||
# We don't use memcpy_s.
|
# We don't use memcpy_s.
|
||||||
CHECKS="$CHECKS,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling"
|
CHECKS="$CHECKS,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling"
|
||||||
@@ -81,62 +139,48 @@ CHECKS="$CHECKS,-cert-dcl03-c"
|
|||||||
CHECKS="$CHECKS,-hicpp-static-assert"
|
CHECKS="$CHECKS,-hicpp-static-assert"
|
||||||
CHECKS="$CHECKS,-misc-static-assert"
|
CHECKS="$CHECKS,-misc-static-assert"
|
||||||
|
|
||||||
# TODO(iphydf): We might want some of these. For the ones we don't want, add a
|
|
||||||
# comment explaining why not.
|
|
||||||
CHECKS="$CHECKS,-clang-analyzer-optin.performance.Padding"
|
|
||||||
CHECKS="$CHECKS,-hicpp-signed-bitwise"
|
|
||||||
CHECKS="$CHECKS,-misc-unused-parameters"
|
|
||||||
CHECKS="$CHECKS,-readability-function-cognitive-complexity"
|
|
||||||
|
|
||||||
# TODO(iphydf): Maybe fix these?
|
|
||||||
CHECKS="$CHECKS,-bugprone-easily-swappable-parameters"
|
|
||||||
CHECKS="$CHECKS,-bugprone-implicit-widening-of-multiplication-result"
|
|
||||||
CHECKS="$CHECKS,-bugprone-integer-division"
|
|
||||||
CHECKS="$CHECKS,-clang-analyzer-core.NullDereference"
|
|
||||||
CHECKS="$CHECKS,-clang-analyzer-valist.Uninitialized"
|
|
||||||
CHECKS="$CHECKS,-concurrency-mt-unsafe"
|
|
||||||
CHECKS="$CHECKS,-cppcoreguidelines-avoid-non-const-global-variables"
|
|
||||||
CHECKS="$CHECKS,-misc-no-recursion"
|
|
||||||
|
|
||||||
# TODO(iphydf): Probably fix these.
|
|
||||||
CHECKS="$CHECKS,-cert-err33-c"
|
|
||||||
CHECKS="$CHECKS,-cppcoreguidelines-avoid-magic-numbers"
|
|
||||||
CHECKS="$CHECKS,-google-readability-casting"
|
|
||||||
CHECKS="$CHECKS,-modernize-macro-to-enum"
|
|
||||||
CHECKS="$CHECKS,-readability-magic-numbers"
|
|
||||||
|
|
||||||
# TODO(iphydf): These two trip on list.c. Investigate why.
|
|
||||||
CHECKS="$CHECKS,-clang-analyzer-core.NonNullParamChecker"
|
|
||||||
CHECKS="$CHECKS,-clang-analyzer-unix.Malloc"
|
|
||||||
|
|
||||||
ERRORS="*"
|
|
||||||
|
|
||||||
# TODO(iphydf): Fix these.
|
|
||||||
ERRORS="$ERRORS,-bugprone-macro-parentheses"
|
|
||||||
ERRORS="$ERRORS,-cert-err34-c"
|
|
||||||
ERRORS="$ERRORS,-cert-str34-c"
|
|
||||||
ERRORS="$ERRORS,-readability-suspicious-call-argument"
|
|
||||||
|
|
||||||
set -eux
|
set -eux
|
||||||
|
|
||||||
|
# TODO(iphydf): Add toxav.
|
||||||
|
DIRS=(
|
||||||
|
other/bootstrap_daemon/src
|
||||||
|
other
|
||||||
|
toxcore
|
||||||
|
toxcore/events
|
||||||
|
toxencryptsave
|
||||||
|
)
|
||||||
|
|
||||||
|
copy_files() {
|
||||||
|
find "${DIRS[@]}" \
|
||||||
|
-maxdepth 1 -type d -exec mkdir -p "$1/{}" \;
|
||||||
|
find "${DIRS[@]}" \
|
||||||
|
-maxdepth 1 -name "*.c" -exec cp "{}" "$1/{}" \;
|
||||||
|
}
|
||||||
|
|
||||||
run() {
|
run() {
|
||||||
echo "Running clang-tidy in variant '$*'"
|
echo "Running clang-tidy in variant '$*'"
|
||||||
EXTRA_ARGS=("$@")
|
EXTRA_ARGS=("$@")
|
||||||
for i in "${!EXTRA_ARGS[@]}"; do
|
for i in "${!EXTRA_ARGS[@]}"; do
|
||||||
EXTRA_ARGS[$i]="--extra-arg=${EXTRA_ARGS[$i]}"
|
EXTRA_ARGS[$i]="--extra-arg=${EXTRA_ARGS[$i]}"
|
||||||
done
|
done
|
||||||
clang-tidy-14 \
|
ls .clang-tidy
|
||||||
-p=_build \
|
copy_files a
|
||||||
--extra-arg=-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE \
|
if ! find "${DIRS[@]}" \
|
||||||
"${EXTRA_ARGS[@]}" \
|
-maxdepth 1 -name "*.c" -print0 \
|
||||||
--checks="$CHECKS" \
|
| xargs -0 -n15 -P"$(nproc)" clang-tidy \
|
||||||
--warnings-as-errors="$ERRORS" \
|
-p="$PWD/_build" \
|
||||||
--use-color \
|
--extra-arg=-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE \
|
||||||
other/bootstrap_daemon/src/*.c \
|
"${EXTRA_ARGS[@]}" \
|
||||||
other/*.c \
|
--fix \
|
||||||
toxav/*.c \
|
--checks="$CHECKS" \
|
||||||
toxcore/*.c \
|
--warnings-as-errors="$ERRORS" \
|
||||||
toxencryptsave/*.c
|
--use-color; then
|
||||||
|
copy_files b
|
||||||
|
colordiff -ru a b
|
||||||
|
rm -rf a b
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
rm -rf a
|
||||||
}
|
}
|
||||||
|
|
||||||
cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||||
|
@@ -34,6 +34,8 @@ CPPCHECK_CXX+=("--suppress=AssignmentAddressToInteger")
|
|||||||
CPPCHECK_CXX+=("--suppress=cstyleCast")
|
CPPCHECK_CXX+=("--suppress=cstyleCast")
|
||||||
# Used in Messenger.c for a static_assert(...)
|
# Used in Messenger.c for a static_assert(...)
|
||||||
CPPCHECK_CXX+=("--suppress=sizeofFunctionCall")
|
CPPCHECK_CXX+=("--suppress=sizeofFunctionCall")
|
||||||
|
# This is outdated. Range-for is a good choice.
|
||||||
|
CPPCHECK_CXX+=("--suppress=useStlAlgorithm")
|
||||||
|
|
||||||
run() {
|
run() {
|
||||||
echo "Running cppcheck in variant '$*'"
|
echo "Running cppcheck in variant '$*'"
|
||||||
|
@@ -11,7 +11,7 @@ run() {
|
|||||||
"${CPPFLAGS[@]}" \
|
"${CPPFLAGS[@]}" \
|
||||||
"${LDFLAGS[@]}" \
|
"${LDFLAGS[@]}" \
|
||||||
"$@" \
|
"$@" \
|
||||||
-std=c++11 \
|
-std=c++17 \
|
||||||
-fdiagnostics-color=always \
|
-fdiagnostics-color=always \
|
||||||
-Wall \
|
-Wall \
|
||||||
-Wextra \
|
-Wextra \
|
||||||
|
@@ -1,25 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# --bufferoverrun \
|
|
||||||
# --pulse \
|
|
||||||
|
|
||||||
read -r -d '' SCRIPT <<'EOF'
|
|
||||||
infer \
|
|
||||||
--report-console-limit 100 \
|
|
||||||
--jobs 8 \
|
|
||||||
--biabduction \
|
|
||||||
--loop-hoisting \
|
|
||||||
--quandary \
|
|
||||||
--racerd \
|
|
||||||
--starvation \
|
|
||||||
--uninit \
|
|
||||||
-- clang++ -fsyntax-only \
|
|
||||||
$(pkg-config --cflags libconfig libsodium opus vpx) \
|
|
||||||
/work/other/bootstrap_daemon/src/*.c \
|
|
||||||
/work/other/bootstrap_node_packets.c \
|
|
||||||
/work/toxav/*.c \
|
|
||||||
/work/toxcore/*.c \
|
|
||||||
/work/toxencryptsave/*.c
|
|
||||||
EOF
|
|
||||||
|
|
||||||
docker run --rm -it -v "$PWD:/work" toxchat/infer bash -c "$SCRIPT"
|
|
@@ -16,7 +16,6 @@
|
|||||||
--align-reference=name
|
--align-reference=name
|
||||||
|
|
||||||
# Formatting Options
|
# Formatting Options
|
||||||
--add-brackets
|
|
||||||
--convert-tabs
|
--convert-tabs
|
||||||
--max-code-length=120
|
--max-code-length=120
|
||||||
|
|
||||||
|
@@ -18,7 +18,6 @@ cc_binary(
|
|||||||
"//c-toxcore/toxcore:mono_time",
|
"//c-toxcore/toxcore:mono_time",
|
||||||
"//c-toxcore/toxcore:onion_announce",
|
"//c-toxcore/toxcore:onion_announce",
|
||||||
"//c-toxcore/toxcore:tox",
|
"//c-toxcore/toxcore:tox",
|
||||||
"//c-toxcore/toxcore:util",
|
|
||||||
"@libconfig",
|
"@libconfig",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@@ -259,7 +259,7 @@ docker run -d --name tox-bootstrapd --restart always \
|
|||||||
toxchat/bootstrap-node
|
toxchat/bootstrap-node
|
||||||
```
|
```
|
||||||
|
|
||||||
We create a new user and protect its home directory in order to mount it in the Docker image, so that the kyepair the daemon uses would be stored on the host system, which makes it less likely that you would loose the keypair while playing with or updating the Docker container.
|
We create a new user and protect its home directory in order to mount it in the Docker image, so that the keypair the daemon uses would be stored on the host system, which makes it less likely that you would loose the keypair while playing with or updating the Docker container.
|
||||||
|
|
||||||
You can check logs for your public key or any errors:
|
You can check logs for your public key or any errors:
|
||||||
```sh
|
```sh
|
||||||
|
@@ -12,8 +12,7 @@ RUN ["apk", "--no-cache", "add",\
|
|||||||
"libsodium-static",\
|
"libsodium-static",\
|
||||||
"musl-dev",\
|
"musl-dev",\
|
||||||
"ninja",\
|
"ninja",\
|
||||||
"python3"\
|
"python3"]
|
||||||
]
|
|
||||||
|
|
||||||
WORKDIR /src/c-toxcore
|
WORKDIR /src/c-toxcore
|
||||||
|
|
||||||
@@ -49,8 +48,10 @@ RUN CC=clang cmake -B_build -H. \
|
|||||||
# Verify checksum from dev-built binary, so we can be sure Docker Hub doesn't
|
# Verify checksum from dev-built binary, so we can be sure Docker Hub doesn't
|
||||||
# mess with your binaries.
|
# mess with your binaries.
|
||||||
COPY other/bootstrap_daemon/docker/tox-bootstrapd.sha256 other/bootstrap_daemon/docker/
|
COPY other/bootstrap_daemon/docker/tox-bootstrapd.sha256 other/bootstrap_daemon/docker/
|
||||||
RUN sha256sum /usr/local/bin/tox-bootstrapd && \
|
RUN SHA256="$(sha256sum /usr/local/bin/tox-bootstrapd)" && \
|
||||||
sha256sum -c other/bootstrap_daemon/docker/tox-bootstrapd.sha256
|
(sha256sum -c other/bootstrap_daemon/docker/tox-bootstrapd.sha256 || \
|
||||||
|
(echo "::error file=other/bootstrap_daemon/docker/tox-bootstrapd.sha256,line=1::$SHA256" && \
|
||||||
|
false))
|
||||||
|
|
||||||
# Remove all the example bootstrap nodes from the config file.
|
# Remove all the example bootstrap nodes from the config file.
|
||||||
COPY other/bootstrap_daemon/tox-bootstrapd.conf other/bootstrap_daemon/
|
COPY other/bootstrap_daemon/tox-bootstrapd.conf other/bootstrap_daemon/
|
||||||
|
46
external/toxcore/c-toxcore/other/bootstrap_daemon/docker/fetch-sha256
vendored
Executable file
46
external/toxcore/c-toxcore/other/bootstrap_daemon/docker/fetch-sha256
vendored
Executable file
@@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import pprint
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import urllib.request
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
SHA256_FILE = "other/bootstrap_daemon/docker/tox-bootstrapd.sha256"
|
||||||
|
|
||||||
|
with open(f"{os.environ['HOME']}/.github-token") as fh:
|
||||||
|
token = fh.read().strip()
|
||||||
|
|
||||||
|
head_sha = (subprocess.run(["git", "rev-parse", "HEAD"],
|
||||||
|
capture_output=True,
|
||||||
|
check=True).stdout.decode("utf-8").strip())
|
||||||
|
|
||||||
|
|
||||||
|
def request(url: str) -> Any:
|
||||||
|
return json.loads(
|
||||||
|
urllib.request.urlopen(
|
||||||
|
urllib.request.Request(
|
||||||
|
url,
|
||||||
|
headers={
|
||||||
|
"Accept": "application/vnd.github+json",
|
||||||
|
"Authorization": "Bearer " + token,
|
||||||
|
"X-GitHub-Api-Version": "2022-11-28",
|
||||||
|
},
|
||||||
|
)).read())
|
||||||
|
|
||||||
|
|
||||||
|
pp = pprint.PrettyPrinter(indent=2, compact=True)
|
||||||
|
annots = [
|
||||||
|
a for r in request(
|
||||||
|
f"https://api.github.com/repos/TokTok/c-toxcore/commits/{head_sha}/check-runs?per_page=100"
|
||||||
|
)["check_runs"] if r["name"] == "docker-bootstrap-node"
|
||||||
|
for a in request(r["output"]["annotations_url"])
|
||||||
|
if a["path"] == SHA256_FILE
|
||||||
|
]
|
||||||
|
if not annots:
|
||||||
|
print("could not find sha256sum output")
|
||||||
|
sys.exit(1)
|
||||||
|
with open(SHA256_FILE, "w") as fh:
|
||||||
|
fh.write(annots[0]["message"] + "\n")
|
||||||
|
print(f"updated {SHA256_FILE}")
|
@@ -1 +1 @@
|
|||||||
b0bd5099f2f77fbd540a5a929a23cece39ff95e3a66702a5381342d01775cbd3 /usr/local/bin/tox-bootstrapd
|
08fe68095b88c142e0c7f3369c5f297f1377e219d0e0f0ff6f30ca94d76fca98 /usr/local/bin/tox-bootstrapd
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2024 The TokTok team.
|
||||||
* Copyright © 2015-2016 Tox project.
|
* Copyright © 2015-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -10,12 +10,12 @@
|
|||||||
#include "command_line_arguments.h"
|
#include "command_line_arguments.h"
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
#include "../../../toxcore/ccompat.h"
|
#include "../../../toxcore/ccompat.h"
|
||||||
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -24,9 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
static void print_help(void)
|
static void print_help(void)
|
||||||
{
|
{
|
||||||
// 2 space ident
|
// 2 space indent
|
||||||
// make sure all lines fit into 80 columns
|
// Make sure all lines fit into 80 columns
|
||||||
// make sure options are listed in alphabetical order
|
// Make sure options are listed in alphabetical order
|
||||||
log_write(LOG_LEVEL_INFO,
|
log_write(LOG_LEVEL_INFO,
|
||||||
"Usage: tox-bootstrapd [OPTION]... --config=FILE_PATH\n"
|
"Usage: tox-bootstrapd [OPTION]... --config=FILE_PATH\n"
|
||||||
"\n"
|
"\n"
|
||||||
@@ -39,7 +39,7 @@ static void print_help(void)
|
|||||||
" (detach from the terminal) and won't use the PID file.\n"
|
" (detach from the terminal) and won't use the PID file.\n"
|
||||||
" --help Print this help message.\n"
|
" --help Print this help message.\n"
|
||||||
" --log-backend=BACKEND Specify which logging backend to use.\n"
|
" --log-backend=BACKEND Specify which logging backend to use.\n"
|
||||||
" Valid BACKEND values (case sensetive):\n"
|
" Valid BACKEND values (case sensitive):\n"
|
||||||
" syslog Writes log messages to syslog.\n"
|
" syslog Writes log messages to syslog.\n"
|
||||||
" Default option when no --log-backend is\n"
|
" Default option when no --log-backend is\n"
|
||||||
" specified.\n"
|
" specified.\n"
|
||||||
@@ -47,13 +47,14 @@ static void print_help(void)
|
|||||||
" --version Print version information.\n");
|
" --version Print version information.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend,
|
Cli_Status handle_command_line_arguments(
|
||||||
bool *run_in_foreground)
|
int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend,
|
||||||
|
bool *run_in_foreground)
|
||||||
{
|
{
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
log_write(LOG_LEVEL_ERROR, "Error: No arguments provided.\n\n");
|
log_write(LOG_LEVEL_ERROR, "Error: No arguments provided.\n\n");
|
||||||
print_help();
|
print_help();
|
||||||
exit(1);
|
return CLI_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
@@ -89,7 +90,7 @@ void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path,
|
|||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
print_help();
|
print_help();
|
||||||
exit(0);
|
return CLI_STATUS_DONE;
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
if (strcmp(optarg, "syslog") == 0) {
|
if (strcmp(optarg, "syslog") == 0) {
|
||||||
@@ -101,24 +102,24 @@ void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path,
|
|||||||
} else {
|
} else {
|
||||||
log_write(LOG_LEVEL_ERROR, "Error: Invalid BACKEND value for --log-backend option passed: %s\n\n", optarg);
|
log_write(LOG_LEVEL_ERROR, "Error: Invalid BACKEND value for --log-backend option passed: %s\n\n", optarg);
|
||||||
print_help();
|
print_help();
|
||||||
exit(1);
|
return CLI_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
log_write(LOG_LEVEL_INFO, "Version: %lu\n", DAEMON_VERSION_NUMBER);
|
log_write(LOG_LEVEL_INFO, "Version: %lu\n", DAEMON_VERSION_NUMBER);
|
||||||
exit(0);
|
return CLI_STATUS_DONE;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
log_write(LOG_LEVEL_ERROR, "Error: Unrecognized option %s\n\n", argv[optind - 1]);
|
log_write(LOG_LEVEL_ERROR, "Error: Unrecognized option %s\n\n", argv[optind - 1]);
|
||||||
print_help();
|
print_help();
|
||||||
exit(1);
|
return CLI_STATUS_ERROR;
|
||||||
|
|
||||||
case ':':
|
case ':':
|
||||||
log_write(LOG_LEVEL_ERROR, "Error: No argument provided for option %s\n\n", argv[optind - 1]);
|
log_write(LOG_LEVEL_ERROR, "Error: No argument provided for option %s\n\n", argv[optind - 1]);
|
||||||
print_help();
|
print_help();
|
||||||
exit(1);
|
return CLI_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,6 +130,8 @@ void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path,
|
|||||||
if (!cfg_file_path_set) {
|
if (!cfg_file_path_set) {
|
||||||
log_write(LOG_LEVEL_ERROR, "Error: The required --config option wasn't specified\n\n");
|
log_write(LOG_LEVEL_ERROR, "Error: The required --config option wasn't specified\n\n");
|
||||||
print_help();
|
print_help();
|
||||||
exit(1);
|
return CLI_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CLI_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,15 @@
|
|||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
typedef enum Cli_Status {
|
||||||
|
/** Continue the program. Command line processing completed. */
|
||||||
|
CLI_STATUS_OK,
|
||||||
|
/** Stop the program with success status. */
|
||||||
|
CLI_STATUS_DONE,
|
||||||
|
/** Stop the program with error status. */
|
||||||
|
CLI_STATUS_ERROR,
|
||||||
|
} Cli_Status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles command line arguments, setting cfg_file_path and log_backend.
|
* Handles command line arguments, setting cfg_file_path and log_backend.
|
||||||
* Terminates the application if incorrect arguments are specified.
|
* Terminates the application if incorrect arguments are specified.
|
||||||
@@ -22,7 +31,8 @@
|
|||||||
* @param log_backend Sets to the provided by the user log backend option.
|
* @param log_backend Sets to the provided by the user log backend option.
|
||||||
* @param run_in_foreground Sets to the provided by the user foreground option.
|
* @param run_in_foreground Sets to the provided by the user foreground option.
|
||||||
*/
|
*/
|
||||||
void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend,
|
Cli_Status handle_command_line_arguments(
|
||||||
bool *run_in_foreground);
|
int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend,
|
||||||
|
bool *run_in_foreground);
|
||||||
|
|
||||||
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_COMMAND_LINE_ARGUMENTS_H
|
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_COMMAND_LINE_ARGUMENTS_H
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2023 The TokTok team.
|
* Copyright © 2016-2024 The TokTok team.
|
||||||
* Copyright © 2014-2016 Tox project.
|
* Copyright © 2014-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "config_defaults.h"
|
#include "config_defaults.h"
|
||||||
|
#include "global.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -18,6 +19,10 @@
|
|||||||
|
|
||||||
#include <libconfig.h>
|
#include <libconfig.h>
|
||||||
|
|
||||||
|
#include "../../../toxcore/DHT.h"
|
||||||
|
#include "../../../toxcore/ccompat.h"
|
||||||
|
#include "../../../toxcore/crypto_core.h"
|
||||||
|
#include "../../../toxcore/network.h"
|
||||||
#include "../../bootstrap_node_packets.h"
|
#include "../../bootstrap_node_packets.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,7 +56,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
|
|||||||
log_write(LOG_LEVEL_INFO, "Port #%zu: %u\n", i, default_ports[i]);
|
log_write(LOG_LEVEL_INFO, "Port #%zu: %u\n", i, default_ports[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// similar procedure to the one of reading config file below
|
// Similar procedure to the one of reading config file below
|
||||||
*tcp_relay_ports = (uint16_t *)malloc(default_ports_count * sizeof(uint16_t));
|
*tcp_relay_ports = (uint16_t *)malloc(default_ports_count * sizeof(uint16_t));
|
||||||
|
|
||||||
for (size_t i = 0; i < default_ports_count; ++i) {
|
for (size_t i = 0; i < default_ports_count; ++i) {
|
||||||
@@ -68,7 +73,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
|
|||||||
++*tcp_relay_port_count;
|
++*tcp_relay_port_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the loop above skips invalid ports, so we adjust the allocated memory size
|
// The loop above skips invalid ports, so we adjust the allocated memory size
|
||||||
if ((*tcp_relay_port_count) > 0) {
|
if ((*tcp_relay_port_count) > 0) {
|
||||||
*tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t));
|
*tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t));
|
||||||
} else {
|
} else {
|
||||||
@@ -98,7 +103,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
|
|||||||
config_setting_t *elem = config_setting_get_elem(ports_array, i);
|
config_setting_t *elem = config_setting_get_elem(ports_array, i);
|
||||||
|
|
||||||
if (elem == nullptr) {
|
if (elem == nullptr) {
|
||||||
// it's NULL if `ports_array` is not an array (we have that check earlier) or if `i` is out of range, which should not be
|
// It's NULL if `ports_array` is not an array (we have that check earlier) or if `i` is out of range, which should not be
|
||||||
log_write(LOG_LEVEL_WARNING, "Port #%d: Something went wrong while parsing the port. Stopping reading ports.\n", i);
|
log_write(LOG_LEVEL_WARNING, "Port #%d: Something went wrong while parsing the port. Stopping reading ports.\n", i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -120,7 +125,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
|
|||||||
++*tcp_relay_port_count;
|
++*tcp_relay_port_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the loop above skips invalid ports, so we adjust the allocated memory size
|
// The loop above skips invalid ports, so we adjust the allocated memory size
|
||||||
if ((*tcp_relay_port_count) > 0) {
|
if ((*tcp_relay_port_count) > 0) {
|
||||||
*tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t));
|
*tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t));
|
||||||
} else {
|
} else {
|
||||||
@@ -260,7 +265,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
|
|||||||
|
|
||||||
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false");
|
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false");
|
||||||
|
|
||||||
// show info about tcp ports only if tcp relay is enabled
|
// Show info about tcp ports only if tcp relay is enabled
|
||||||
if (*enable_tcp_relay) {
|
if (*enable_tcp_relay) {
|
||||||
if (*tcp_relay_port_count == 0) {
|
if (*tcp_relay_port_count == 0) {
|
||||||
log_write(LOG_LEVEL_ERROR, "No TCP ports could be read.\n");
|
log_write(LOG_LEVEL_ERROR, "No TCP ports could be read.\n");
|
||||||
@@ -407,7 +412,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
|
|||||||
log_write(LOG_LEVEL_INFO, "Successfully added bootstrap node #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key);
|
log_write(LOG_LEVEL_INFO, "Successfully added bootstrap node #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key);
|
||||||
|
|
||||||
next:
|
next:
|
||||||
// config_setting_lookup_string() allocates string inside and doesn't allow us to free it direcly
|
// config_setting_lookup_string() allocates string inside and doesn't allow us to free it directly
|
||||||
// though it's freed when the element is removed, so we free it right away in order to keep memory
|
// though it's freed when the element is removed, so we free it right away in order to keep memory
|
||||||
// consumption minimal
|
// consumption minimal
|
||||||
config_setting_remove_elem(node_list, 0);
|
config_setting_remove_elem(node_list, 0);
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2024 The TokTok team.
|
||||||
* Copyright © 2014-2016 Tox project.
|
* Copyright © 2014-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
|
|||||||
* Bootstraps off nodes listed in the config file.
|
* Bootstraps off nodes listed in the config file.
|
||||||
*
|
*
|
||||||
* @return 1 on success, some or no bootstrap nodes were added
|
* @return 1 on success, some or no bootstrap nodes were added
|
||||||
* 0 on failure, a error accured while parsing config file.
|
* 0 on failure, an error occurred while parsing the config file.
|
||||||
*/
|
*/
|
||||||
int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6);
|
int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6);
|
||||||
|
|
||||||
|
@@ -3,6 +3,8 @@
|
|||||||
* Copyright © 2015-2016 Tox project.
|
* Copyright © 2015-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tox DHT bootstrap daemon.
|
* Tox DHT bootstrap daemon.
|
||||||
* Logging utility with support of multiple logging backends.
|
* Logging utility with support of multiple logging backends.
|
||||||
|
@@ -9,8 +9,11 @@
|
|||||||
*/
|
*/
|
||||||
#include "log_backend_stdout.h"
|
#include "log_backend_stdout.h"
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
static FILE *log_backend_stdout_level(LOG_LEVEL level)
|
static FILE *log_backend_stdout_level(LOG_LEVEL level)
|
||||||
{
|
{
|
||||||
switch (level) {
|
switch (level) {
|
||||||
|
@@ -10,10 +10,12 @@
|
|||||||
#include "log_backend_syslog.h"
|
#include "log_backend_syslog.h"
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
#include "../../../toxcore/ccompat.h"
|
#include "../../../toxcore/ccompat.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
@@ -23,17 +23,24 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
// toxcore
|
// toxcore
|
||||||
#include "../../../toxcore/tox.h"
|
#include "../../../toxcore/DHT.h"
|
||||||
#include "../../../toxcore/LAN_discovery.h"
|
#include "../../../toxcore/LAN_discovery.h"
|
||||||
#include "../../../toxcore/TCP_server.h"
|
#include "../../../toxcore/TCP_server.h"
|
||||||
#include "../../../toxcore/announce.h"
|
#include "../../../toxcore/announce.h"
|
||||||
|
#include "../../../toxcore/ccompat.h"
|
||||||
|
#include "../../../toxcore/crypto_core.h"
|
||||||
|
#include "../../../toxcore/forwarding.h"
|
||||||
|
#include "../../../toxcore/group_announce.h"
|
||||||
#include "../../../toxcore/group_onion_announce.h"
|
#include "../../../toxcore/group_onion_announce.h"
|
||||||
#include "../../../toxcore/logger.h"
|
#include "../../../toxcore/logger.h"
|
||||||
|
#include "../../../toxcore/mem.h"
|
||||||
#include "../../../toxcore/mono_time.h"
|
#include "../../../toxcore/mono_time.h"
|
||||||
|
#include "../../../toxcore/network.h"
|
||||||
|
#include "../../../toxcore/onion.h"
|
||||||
#include "../../../toxcore/onion_announce.h"
|
#include "../../../toxcore/onion_announce.h"
|
||||||
#include "../../../toxcore/util.h"
|
|
||||||
|
|
||||||
// misc
|
// misc
|
||||||
#include "../../bootstrap_node_packets.h"
|
#include "../../bootstrap_node_packets.h"
|
||||||
@@ -116,7 +123,7 @@ static void print_public_key(const uint8_t *public_key)
|
|||||||
// Demonizes the process, appending PID to the PID file and closing file descriptors based on log backend
|
// Demonizes the process, appending PID to the PID file and closing file descriptors based on log backend
|
||||||
// Terminates the application if the daemonization fails.
|
// Terminates the application if the daemonization fails.
|
||||||
|
|
||||||
static void daemonize(LOG_BACKEND log_backend, char *pid_file_path)
|
static Cli_Status daemonize(LOG_BACKEND log_backend, char *pid_file_path)
|
||||||
{
|
{
|
||||||
// Check if the PID file exists
|
// Check if the PID file exists
|
||||||
FILE *pid_file = fopen(pid_file_path, "r");
|
FILE *pid_file = fopen(pid_file_path, "r");
|
||||||
@@ -131,7 +138,7 @@ static void daemonize(LOG_BACKEND log_backend, char *pid_file_path)
|
|||||||
|
|
||||||
if (pid_file == nullptr) {
|
if (pid_file == nullptr) {
|
||||||
log_write(LOG_LEVEL_ERROR, "Couldn't open the PID file for writing: %s. Exiting.\n", pid_file_path);
|
log_write(LOG_LEVEL_ERROR, "Couldn't open the PID file for writing: %s. Exiting.\n", pid_file_path);
|
||||||
exit(1);
|
return CLI_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fork off from the parent process
|
// Fork off from the parent process
|
||||||
@@ -141,27 +148,27 @@ static void daemonize(LOG_BACKEND log_backend, char *pid_file_path)
|
|||||||
fprintf(pid_file, "%d", pid);
|
fprintf(pid_file, "%d", pid);
|
||||||
fclose(pid_file);
|
fclose(pid_file);
|
||||||
log_write(LOG_LEVEL_INFO, "Forked successfully: PID: %d.\n", pid);
|
log_write(LOG_LEVEL_INFO, "Forked successfully: PID: %d.\n", pid);
|
||||||
exit(0);
|
return CLI_STATUS_DONE;
|
||||||
} else {
|
} else {
|
||||||
fclose(pid_file);
|
fclose(pid_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
log_write(LOG_LEVEL_ERROR, "Forking failed. Exiting.\n");
|
log_write(LOG_LEVEL_ERROR, "Forking failed. Exiting.\n");
|
||||||
exit(1);
|
return CLI_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new SID for the child process
|
// Create a new SID for the child process
|
||||||
if (setsid() < 0) {
|
if (setsid() < 0) {
|
||||||
log_write(LOG_LEVEL_ERROR, "SID creation failure. Exiting.\n");
|
log_write(LOG_LEVEL_ERROR, "SID creation failure. Exiting.\n");
|
||||||
exit(1);
|
return CLI_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Change the current working directory
|
// Change the current working directory
|
||||||
if ((chdir("/")) < 0) {
|
if ((chdir("/")) < 0) {
|
||||||
log_write(LOG_LEVEL_ERROR, "Couldn't change working directory to '/'. Exiting.\n");
|
log_write(LOG_LEVEL_ERROR, "Couldn't change working directory to '/'. Exiting.\n");
|
||||||
exit(1);
|
return CLI_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go quiet
|
// Go quiet
|
||||||
@@ -170,6 +177,8 @@ static void daemonize(LOG_BACKEND log_backend, char *pid_file_path)
|
|||||||
close(STDIN_FILENO);
|
close(STDIN_FILENO);
|
||||||
close(STDERR_FILENO);
|
close(STDERR_FILENO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CLI_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logs toxcore logger message using our logger facility
|
// Logs toxcore logger message using our logger facility
|
||||||
@@ -212,11 +221,18 @@ int main(int argc, char *argv[])
|
|||||||
char *cfg_file_path = nullptr;
|
char *cfg_file_path = nullptr;
|
||||||
bool run_in_foreground = false;
|
bool run_in_foreground = false;
|
||||||
|
|
||||||
// choose backend for printing command line argument parsing output based on whether the daemon is being run from a terminal
|
// Choose backend for printing command line argument parsing output based on whether the daemon is being run from a terminal
|
||||||
LOG_BACKEND log_backend = isatty(STDOUT_FILENO) ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG;
|
LOG_BACKEND log_backend = isatty(STDOUT_FILENO) ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG;
|
||||||
|
|
||||||
log_open(log_backend);
|
log_open(log_backend);
|
||||||
handle_command_line_arguments(argc, argv, &cfg_file_path, &log_backend, &run_in_foreground);
|
switch (handle_command_line_arguments(argc, argv, &cfg_file_path, &log_backend, &run_in_foreground)) {
|
||||||
|
case CLI_STATUS_OK:
|
||||||
|
break;
|
||||||
|
case CLI_STATUS_DONE:
|
||||||
|
return 0;
|
||||||
|
case CLI_STATUS_ERROR:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
log_close();
|
log_close();
|
||||||
|
|
||||||
log_open(log_backend);
|
log_open(log_backend);
|
||||||
@@ -254,7 +270,14 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!run_in_foreground) {
|
if (!run_in_foreground) {
|
||||||
daemonize(log_backend, pid_file_path);
|
switch (daemonize(log_backend, pid_file_path)) {
|
||||||
|
case CLI_STATUS_OK:
|
||||||
|
break;
|
||||||
|
case CLI_STATUS_DONE:
|
||||||
|
return 0;
|
||||||
|
case CLI_STATUS_ERROR:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(pid_file_path);
|
free(pid_file_path);
|
||||||
|
@@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "../toxcore/network.h"
|
||||||
|
|
||||||
#define INFO_REQUEST_PACKET_LENGTH 78
|
#define INFO_REQUEST_PACKET_LENGTH 78
|
||||||
|
|
||||||
static uint32_t bootstrap_version;
|
static uint32_t bootstrap_version;
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
# autotools-linux
|
# autotools-linux
|
||||||
FROM ubuntu:22.04
|
FROM ubuntu:22.04
|
||||||
|
|
||||||
RUN apt-get update && apt-get install --no-install-recommends -y \
|
RUN apt-get update && \
|
||||||
|
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
|
||||||
autoconf \
|
autoconf \
|
||||||
automake \
|
automake \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
|
@@ -7,6 +7,7 @@ RUN apt-get update && \
|
|||||||
clang \
|
clang \
|
||||||
cmake \
|
cmake \
|
||||||
libconfig-dev \
|
libconfig-dev \
|
||||||
|
libgmock-dev \
|
||||||
libgtest-dev \
|
libgtest-dev \
|
||||||
libopus-dev \
|
libopus-dev \
|
||||||
libsodium-dev \
|
libsodium-dev \
|
||||||
|
21
external/toxcore/c-toxcore/other/docker/clang-tidy/Dockerfile
vendored
Normal file
21
external/toxcore/c-toxcore/other/docker/clang-tidy/Dockerfile
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
FROM alpine:3.19.0
|
||||||
|
|
||||||
|
RUN ["apk", "add", "--no-cache", \
|
||||||
|
"bash", \
|
||||||
|
"clang", \
|
||||||
|
"clang-extra-tools", \
|
||||||
|
"cmake", \
|
||||||
|
"colordiff", \
|
||||||
|
"libconfig-dev", \
|
||||||
|
"libsodium-dev", \
|
||||||
|
"libvpx-dev", \
|
||||||
|
"linux-headers", \
|
||||||
|
"opus-dev", \
|
||||||
|
"pkgconfig", \
|
||||||
|
"samurai"]
|
||||||
|
|
||||||
|
ENV CC=clang CXX=clang++
|
||||||
|
|
||||||
|
COPY . /c-toxcore/
|
||||||
|
WORKDIR /c-toxcore
|
||||||
|
RUN other/analysis/run-clang-tidy
|
5
external/toxcore/c-toxcore/other/docker/clang-tidy/run
vendored
Executable file
5
external/toxcore/c-toxcore/other/docker/clang-tidy/run
vendored
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
BUILD=clang-tidy
|
||||||
|
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
|
@@ -1,50 +1,57 @@
|
|||||||
FROM toxchat/c-toxcore:sources AS src
|
FROM toxchat/c-toxcore:sources AS src
|
||||||
FROM ubuntu:20.04 AS build
|
FROM ubuntu:20.04 AS build
|
||||||
|
|
||||||
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
|
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
clang \
|
|
||||||
cmake \
|
|
||||||
curl \
|
curl \
|
||||||
gcc \
|
&& apt-get clean \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-17 main" >> /etc/apt/sources.list \
|
||||||
|
&& curl -L https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc \
|
||||||
|
&& apt-get update && \
|
||||||
|
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
|
||||||
|
clang-17 \
|
||||||
|
cmake \
|
||||||
git \
|
git \
|
||||||
golang-1.18 \
|
golang-1.18 \
|
||||||
|
libclang-rt-17-dev \
|
||||||
libconfig-dev \
|
libconfig-dev \
|
||||||
|
libgmock-dev \
|
||||||
libgtest-dev \
|
libgtest-dev \
|
||||||
libopus-dev \
|
libopus-dev \
|
||||||
libsodium-dev \
|
libsodium-dev \
|
||||||
|
libunwind-17-dev \
|
||||||
libvpx-dev \
|
libvpx-dev \
|
||||||
llvm-dev \
|
lld-17 \
|
||||||
|
llvm-17-dev \
|
||||||
make \
|
make \
|
||||||
ninja-build \
|
ninja-build \
|
||||||
pkg-config \
|
pkg-config \
|
||||||
python3-pip \
|
|
||||||
python3-pygments \
|
|
||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -rf /var/lib/apt/lists/* \
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
&& pip3 install --no-cache-dir gcovr
|
|
||||||
RUN ["strip", "-g",\
|
|
||||||
"/usr/lib/x86_64-linux-gnu/libgtest.a",\
|
|
||||||
"/usr/lib/x86_64-linux-gnu/libgtest_main.a"]
|
|
||||||
RUN ["curl", "-s", "https://codecov.io/bash", "-o", "/usr/local/bin/codecov"]
|
RUN ["curl", "-s", "https://codecov.io/bash", "-o", "/usr/local/bin/codecov"]
|
||||||
RUN ["chmod", "+x", "/usr/local/bin/codecov"]
|
RUN ["chmod", "+x", "/usr/local/bin/codecov"]
|
||||||
|
|
||||||
ENV CC=clang \
|
ENV CC=clang-17 \
|
||||||
CXX=clang++ \
|
CXX=clang++-17 \
|
||||||
PYTHONUNBUFFERED=1 \
|
PYTHONUNBUFFERED=1 \
|
||||||
PATH=$PATH:/usr/lib/go-1.18/bin
|
PATH=$PATH:/usr/lib/go-1.18/bin
|
||||||
SHELL ["/bin/bash", "-c"]
|
|
||||||
|
COPY --from=src /src/ /work/
|
||||||
|
|
||||||
WORKDIR /work
|
WORKDIR /work
|
||||||
COPY --from=src /src/ /work/
|
RUN git clone --depth=1 https://github.com/TokTok/toktok-fuzzer /work/testing/fuzzing/toktok-fuzzer
|
||||||
RUN source .github/scripts/flags-coverage.sh \
|
RUN source .github/scripts/flags-coverage.sh \
|
||||||
&& go version \
|
&& go version \
|
||||||
&& (cd other/proxy && go get github.com/things-go/go-socks5 && go build proxy_server.go) \
|
&& (cd other/proxy && go get github.com/things-go/go-socks5 && go build proxy_server.go) \
|
||||||
&& cmake -B_build -H. -GNinja \
|
&& cmake -B_build -H. -GNinja \
|
||||||
-DCMAKE_C_FLAGS="$C_FLAGS" \
|
-DCMAKE_C_FLAGS="$C_FLAGS" \
|
||||||
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
|
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
|
||||||
-DCMAKE_EXE_LINKER_FLAGS="$LD_FLAGS" \
|
-DCMAKE_EXE_LINKER_FLAGS="$LD_FLAGS -fuse-ld=lld" \
|
||||||
-DCMAKE_UNITY_BUILD=ON \
|
-DCMAKE_UNITY_BUILD=ON \
|
||||||
-DENABLE_SHARED=OFF \
|
-DENABLE_SHARED=OFF \
|
||||||
-DMIN_LOGGER_LEVEL=TRACE \
|
-DMIN_LOGGER_LEVEL=TRACE \
|
||||||
@@ -53,6 +60,7 @@ RUN source .github/scripts/flags-coverage.sh \
|
|||||||
-DSTRICT_ABI=ON \
|
-DSTRICT_ABI=ON \
|
||||||
-DAUTOTEST=ON \
|
-DAUTOTEST=ON \
|
||||||
-DPROXY_TEST=ON \
|
-DPROXY_TEST=ON \
|
||||||
|
-DBUILD_FUZZ_TESTS=ON \
|
||||||
-DUSE_IPV6=OFF \
|
-DUSE_IPV6=OFF \
|
||||||
-DTEST_TIMEOUT_SECONDS=40 \
|
-DTEST_TIMEOUT_SECONDS=40 \
|
||||||
&& cmake --build _build --parallel 8 --target install
|
&& cmake --build _build --parallel 8 --target install
|
||||||
@@ -63,24 +71,15 @@ RUN /work/other/proxy/proxy_server \
|
|||||||
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6)
|
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6)
|
||||||
|
|
||||||
WORKDIR /work/mallocfail
|
WORKDIR /work/mallocfail
|
||||||
RUN ["git", "clone", "--depth=1", "https://github.com/ralight/mallocfail", "/work/mallocfail"]
|
RUN ["git", "clone", "--depth=1", "https://github.com/TokTok/mallocfail", "/work/mallocfail"]
|
||||||
COPY other/docker/coverage/syscall_funcs.c src/
|
RUN clang-17 -fuse-ld=lld -fPIC -shared -O2 -g3 -Wall -I/usr/lib/llvm-17/include -L/usr/lib/llvm-17/lib -Ideps/uthash -Ideps/sha3 deps/*/*.c src/*.c -o mallocfail.so -ldl -lunwind \
|
||||||
RUN gcc -fPIC -shared -O2 -g3 -Wall -Ideps/uthash -Ideps/sha3 deps/*/*.c src/*.c -o mallocfail.so -ldl -lbacktrace \
|
|
||||||
&& install mallocfail.so /usr/local/lib/mallocfail.so
|
&& install mallocfail.so /usr/local/lib/mallocfail.so
|
||||||
|
|
||||||
WORKDIR /work/_build
|
WORKDIR /work/_build
|
||||||
COPY other/docker/coverage/run_mallocfail /usr/local/bin/
|
COPY other/docker/coverage/run_mallocfail /usr/local/bin/
|
||||||
RUN ["run_mallocfail", "--ctest=2", "--jobs=8"]
|
RUN ["run_mallocfail", "--ctest=1", "--jobs=8"]
|
||||||
RUN ["gcovr", \
|
RUN llvm-profdata-17 merge -sparse $(find . -name "*.profraw") -o toxcore.profdata
|
||||||
"--sort-percentage", \
|
RUN llvm-cov-17 show -format=text -instr-profile=toxcore.profdata -sources $(cmake --build . --target help | grep -o '[^:]*_test:' | grep -o '[^:]*' | xargs -n1 find . -type f -name | awk '{print "-object "$1}') > coverage.txt
|
||||||
"--gcov-executable=llvm-cov gcov", \
|
RUN llvm-cov-17 show -format=html -instr-profile=toxcore.profdata -sources $(cmake --build . --target help | grep -o '[^:]*_test:' | grep -o '[^:]*' | xargs -n1 find . -type f -name | awk '{print "-object "$1}') -output-dir=html
|
||||||
"--html-details=html/", \
|
|
||||||
"--root=..", \
|
|
||||||
"--exclude=CMakeFiles/", \
|
|
||||||
"--exclude=_deps/", \
|
|
||||||
"--exclude=(.+/)?auto_tests/", \
|
|
||||||
"--exclude=.+_test.cc?$", \
|
|
||||||
"--exclude=(.+/)?other/", \
|
|
||||||
"--exclude=(.+/)?testing/"]
|
|
||||||
|
|
||||||
WORKDIR /work
|
WORKDIR /work
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
# vim:ft=dockerfile
|
# vim:ft=dockerfile
|
||||||
FROM toxchat/c-toxcore:coverage AS build
|
FROM toxchat/c-toxcore:coverage AS build
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
COPY --from=build /work/_build/html/coverage_details.html /usr/share/nginx/html/index.html
|
COPY --from=build --chown=nginx:nginx /work/_build/html/ /usr/share/nginx/html/
|
||||||
COPY --from=build /work/_build/html/ /usr/share/nginx/html/
|
|
||||||
|
@@ -6,4 +6,4 @@ read -a ci_env <<<"$(bash <(curl -s https://codecov.io/env))"
|
|||||||
|
|
||||||
docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile .
|
docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile .
|
||||||
docker build -t toxchat/c-toxcore:coverage -f other/docker/coverage/Dockerfile .
|
docker build -t toxchat/c-toxcore:coverage -f other/docker/coverage/Dockerfile .
|
||||||
docker run "${ci_env[@]}" -e CI=true --name toxcore-coverage --rm -t toxchat/c-toxcore:coverage /usr/local/bin/codecov -x "llvm-cov gcov"
|
docker run "${ci_env[@]}" -e CI=true --name toxcore-coverage --rm -t toxchat/c-toxcore:coverage /usr/local/bin/codecov
|
||||||
|
@@ -27,11 +27,12 @@ from typing import NoReturn
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
_PRIMER = "./unit_util_test"
|
_PRIMER = "auto_tests/auto_version_test"
|
||||||
_MALLOCFAIL_SO = "/usr/local/lib/mallocfail.so"
|
_MALLOCFAIL_SO = "/usr/local/lib/mallocfail.so"
|
||||||
_HASHES = "mallocfail_hashes"
|
_HASHES = "mallocfail_hashes"
|
||||||
_HASHES_PREV = "mallocfail_hashes.prev"
|
_HASHES_PREV = "mallocfail_hashes.prev"
|
||||||
_TIMEOUT = 3.0
|
_TIMEOUT = 3.0
|
||||||
|
_BUILD_DIR = os.getcwd()
|
||||||
|
|
||||||
_ENV = {
|
_ENV = {
|
||||||
"LD_PRELOAD": _MALLOCFAIL_SO,
|
"LD_PRELOAD": _MALLOCFAIL_SO,
|
||||||
@@ -45,10 +46,19 @@ def run_mallocfail(tmpdir: str, timeout: float, exe: str, iteration: int,
|
|||||||
print(f"\x1b[1;33mmallocfail '{exe}' run #{iteration}\x1b[0m")
|
print(f"\x1b[1;33mmallocfail '{exe}' run #{iteration}\x1b[0m")
|
||||||
hashes = os.path.join(tmpdir, _HASHES)
|
hashes = os.path.join(tmpdir, _HASHES)
|
||||||
hashes_prev = os.path.join(tmpdir, _HASHES_PREV)
|
hashes_prev = os.path.join(tmpdir, _HASHES_PREV)
|
||||||
|
profraw = os.path.join(_BUILD_DIR, "mallocfail.out", exe, "%p.profraw")
|
||||||
if os.path.exists(hashes):
|
if os.path.exists(hashes):
|
||||||
shutil.copy(hashes, hashes_prev)
|
shutil.copy(hashes, hashes_prev)
|
||||||
try:
|
try:
|
||||||
proc = subprocess.run([exe], timeout=timeout, env=_ENV, cwd=tmpdir)
|
proc = subprocess.run(
|
||||||
|
[exe],
|
||||||
|
timeout=timeout,
|
||||||
|
env={
|
||||||
|
"LLVM_PROFILE_FILE": profraw,
|
||||||
|
**_ENV,
|
||||||
|
},
|
||||||
|
cwd=tmpdir,
|
||||||
|
)
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
print(f"\x1b[1;34mProgram {exe} timed out\x1b[0m")
|
print(f"\x1b[1;34mProgram {exe} timed out\x1b[0m")
|
||||||
return True
|
return True
|
||||||
@@ -65,13 +75,16 @@ def run_mallocfail(tmpdir: str, timeout: float, exe: str, iteration: int,
|
|||||||
# Process exited cleanly (success or failure).
|
# Process exited cleanly (success or failure).
|
||||||
pass
|
pass
|
||||||
elif proc.returncode == -6:
|
elif proc.returncode == -6:
|
||||||
# Assertion failed.
|
# abort(), we allow it.
|
||||||
|
pass
|
||||||
|
elif proc.returncode == 7:
|
||||||
|
# ck_assert failed, also fine for us.
|
||||||
pass
|
pass
|
||||||
elif proc.returncode == -14:
|
elif proc.returncode == -14:
|
||||||
print(f"\x1b[0;34mProgram '{exe}' timed out\x1b[0m")
|
print(f"\x1b[0;34mProgram '{exe}' timed out\x1b[0m")
|
||||||
else:
|
else:
|
||||||
print(
|
print(
|
||||||
f"\x1b[1;32mProgram '{exe}' failed to handle OOM situation cleanly\x1b[0m"
|
f"\x1b[1;32mProgram '{exe}' failed to handle OOM situation cleanly (code {proc.returncode})\x1b[0m"
|
||||||
)
|
)
|
||||||
if not keep_going:
|
if not keep_going:
|
||||||
raise Exception("Aborting test")
|
raise Exception("Aborting test")
|
||||||
@@ -96,8 +109,8 @@ def find_prog(name: str) -> Tuple[Optional[str], ...]:
|
|||||||
return path
|
return path
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return (attempt(f"./unit_{name}_test"),
|
return (attempt(f"auto_tests/auto_{name}_test"),
|
||||||
attempt(f"auto_tests/auto_{name}_test"))
|
) # attempt(f"./unit_{name}_test"),
|
||||||
|
|
||||||
|
|
||||||
def parse_flags(args: List[str]) -> Tuple[Dict[str, str], List[str]]:
|
def parse_flags(args: List[str]) -> Tuple[Dict[str, str], List[str]]:
|
||||||
@@ -128,6 +141,9 @@ def isolated_mallocfail(timeout: int, exe: str) -> None:
|
|||||||
shutil.copy(exe, os.path.join(tmpdir, exe))
|
shutil.copy(exe, os.path.join(tmpdir, exe))
|
||||||
shutil.copy(_HASHES, os.path.join(tmpdir, _HASHES))
|
shutil.copy(_HASHES, os.path.join(tmpdir, _HASHES))
|
||||||
loop_mallocfail(tmpdir, timeout, exe)
|
loop_mallocfail(tmpdir, timeout, exe)
|
||||||
|
profraw = os.path.join(tmpdir, "default.profraw")
|
||||||
|
if os.path.exists(profraw):
|
||||||
|
shutil.copy(profraw, exe + ".mallocfail.profraw")
|
||||||
|
|
||||||
|
|
||||||
def main(args: List[str]) -> None:
|
def main(args: List[str]) -> None:
|
||||||
@@ -150,12 +166,12 @@ def main(args: List[str]) -> None:
|
|||||||
else:
|
else:
|
||||||
jobs = 1
|
jobs = 1
|
||||||
|
|
||||||
# Start by running util_test, which allocates no memory of its own, just
|
# Start by running version_test, which allocates no memory of its own, just
|
||||||
# to prime the mallocfail hashes so it doesn't make global initialisers
|
# to prime the mallocfail hashes so it doesn't make global initialisers
|
||||||
# such as llvm_gcov_init fail.
|
# such as llvm_gcov_init fail.
|
||||||
if os.path.exists(_PRIMER):
|
if os.path.exists(_PRIMER):
|
||||||
print(f"\x1b[1;33mPriming hashes with unit_util_test\x1b[0m")
|
print(f"\x1b[1;33mPriming hashes with {_PRIMER}\x1b[0m")
|
||||||
loop_mallocfail(".", timeout, _PRIMER, keep_going=True)
|
loop_mallocfail(os.getcwd(), timeout, _PRIMER, keep_going=True)
|
||||||
|
|
||||||
print(f"\x1b[1;33m--------------------------------\x1b[0m")
|
print(f"\x1b[1;33m--------------------------------\x1b[0m")
|
||||||
print(f"\x1b[1;33mStarting mallocfail for {len(exes)} programs:\x1b[0m")
|
print(f"\x1b[1;33mStarting mallocfail for {len(exes)} programs:\x1b[0m")
|
||||||
|
@@ -1,149 +0,0 @@
|
|||||||
#define _GNU_SOURCE
|
|
||||||
|
|
||||||
#include "mallocfail.h"
|
|
||||||
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
static int (*libc_ioctl)(int fd, unsigned long request, ...);
|
|
||||||
static int (*libc_bind)(int sockfd, const struct sockaddr *addr,
|
|
||||||
socklen_t addrlen);
|
|
||||||
static int (*libc_getsockopt)(int sockfd, int level, int optname,
|
|
||||||
void *optval, socklen_t *optlen);
|
|
||||||
static int (*libc_setsockopt)(int sockfd, int level, int optname,
|
|
||||||
const void *optval, socklen_t optlen);
|
|
||||||
static ssize_t (*libc_recv)(int sockfd, void *buf, size_t len, int flags);
|
|
||||||
static ssize_t (*libc_recvfrom)(int sockfd, void *buf, size_t len, int flags,
|
|
||||||
struct sockaddr *src_addr, socklen_t *addrlen);
|
|
||||||
static ssize_t (*libc_send)(int sockfd, const void *buf, size_t len, int flags);
|
|
||||||
static ssize_t(*libc_sendto)(int sockfd, const void *buf, size_t len, int flags,
|
|
||||||
const struct sockaddr *dest_addr, socklen_t addrlen);
|
|
||||||
static int (*libc_socket)(int domain, int type, int protocol);
|
|
||||||
static int (*libc_listen)(int sockfd, int backlog);
|
|
||||||
|
|
||||||
__attribute__((__constructor__))
|
|
||||||
static void init(void)
|
|
||||||
{
|
|
||||||
libc_ioctl = dlsym(RTLD_NEXT, "ioctl");
|
|
||||||
libc_bind = dlsym(RTLD_NEXT, "bind");
|
|
||||||
libc_getsockopt = dlsym(RTLD_NEXT, "getsockopt");
|
|
||||||
libc_setsockopt = dlsym(RTLD_NEXT, "setsockopt");
|
|
||||||
libc_recv = dlsym(RTLD_NEXT, "recv");
|
|
||||||
libc_recvfrom = dlsym(RTLD_NEXT, "recvfrom");
|
|
||||||
libc_send = dlsym(RTLD_NEXT, "send");
|
|
||||||
libc_sendto = dlsym(RTLD_NEXT, "sendto");
|
|
||||||
libc_socket = dlsym(RTLD_NEXT, "socket");
|
|
||||||
libc_listen = dlsym(RTLD_NEXT, "listen");
|
|
||||||
}
|
|
||||||
|
|
||||||
int ioctl(int fd, unsigned long request, ...)
|
|
||||||
{
|
|
||||||
if (should_malloc_fail()) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, request);
|
|
||||||
const int ret = libc_ioctl(fd, SIOCGIFCONF, va_arg(ap, void *));
|
|
||||||
va_end(ap);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bind(int sockfd, const struct sockaddr *addr,
|
|
||||||
socklen_t addrlen)
|
|
||||||
{
|
|
||||||
// Unlike all others, if bind should fail once, it should fail always, because in toxcore we try
|
|
||||||
// many ports before giving up. If this only fails once, we'll never reach the code path where
|
|
||||||
// we give up.
|
|
||||||
static int should_fail = -1;
|
|
||||||
if (should_fail == -1) {
|
|
||||||
should_fail = should_malloc_fail();
|
|
||||||
}
|
|
||||||
if (should_fail) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return libc_bind(sockfd, addr, addrlen);
|
|
||||||
}
|
|
||||||
|
|
||||||
int getsockopt(int sockfd, int level, int optname,
|
|
||||||
void *optval, socklen_t *optlen)
|
|
||||||
{
|
|
||||||
if (should_malloc_fail()) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return libc_getsockopt(sockfd, level, optname, optval, optlen);
|
|
||||||
}
|
|
||||||
|
|
||||||
int setsockopt(int sockfd, int level, int optname,
|
|
||||||
const void *optval, socklen_t optlen)
|
|
||||||
{
|
|
||||||
if (should_malloc_fail()) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return libc_setsockopt(sockfd, level, optname, optval, optlen);
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t recv(int sockfd, void *buf, size_t len, int flags)
|
|
||||||
{
|
|
||||||
if (should_malloc_fail()) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return libc_recv(sockfd, buf, len, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
|
|
||||||
struct sockaddr *src_addr, socklen_t *addrlen)
|
|
||||||
{
|
|
||||||
if (should_malloc_fail()) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return libc_recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t send(int sockfd, const void *buf, size_t len, int flags)
|
|
||||||
{
|
|
||||||
if (should_malloc_fail()) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return libc_send(sockfd, buf, len, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
|
|
||||||
const struct sockaddr *dest_addr, socklen_t addrlen)
|
|
||||||
{
|
|
||||||
if (should_malloc_fail()) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return libc_sendto(sockfd, buf, len, flags, dest_addr, addrlen);
|
|
||||||
}
|
|
||||||
|
|
||||||
int socket(int domain, int type, int protocol)
|
|
||||||
{
|
|
||||||
if (should_malloc_fail()) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return libc_socket(domain, type, protocol);
|
|
||||||
}
|
|
||||||
|
|
||||||
int listen(int sockfd, int backlog)
|
|
||||||
{
|
|
||||||
if (should_malloc_fail()) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return libc_listen(sockfd, backlog);
|
|
||||||
}
|
|
@@ -92,6 +92,10 @@
|
|||||||
<alloc init="true">new_networking_no_udp</alloc>
|
<alloc init="true">new_networking_no_udp</alloc>
|
||||||
<dealloc arg="1">kill_networking</dealloc>
|
<dealloc arg="1">kill_networking</dealloc>
|
||||||
</resource>
|
</resource>
|
||||||
|
<resource>
|
||||||
|
<alloc init="true">net_new_strerror</alloc>
|
||||||
|
<dealloc arg="1">net_kill_strerror</dealloc>
|
||||||
|
</resource>
|
||||||
<resource>
|
<resource>
|
||||||
<alloc init="true">new_onion</alloc>
|
<alloc init="true">new_onion</alloc>
|
||||||
<dealloc arg="1">kill_onion</dealloc>
|
<dealloc arg="1">kill_onion</dealloc>
|
||||||
|
@@ -5,7 +5,7 @@ ENV LANG=en_US.UTF-8 \
|
|||||||
LC_CTYPE=en_US.UTF-8 \
|
LC_CTYPE=en_US.UTF-8 \
|
||||||
LC_ALL=en_US.UTF-8
|
LC_ALL=en_US.UTF-8
|
||||||
|
|
||||||
RUN apk add --no-cache doxygen git graphviz \
|
RUN apk add --no-cache doxygen git graphviz texlive \
|
||||||
&& git clone --depth=1 https://github.com/jothepro/doxygen-awesome-css.git /work/doxygen-awesome-css
|
&& git clone --depth=1 https://github.com/jothepro/doxygen-awesome-css.git /work/doxygen-awesome-css
|
||||||
WORKDIR /work
|
WORKDIR /work
|
||||||
COPY . /work/
|
COPY . /work/
|
||||||
|
41
external/toxcore/c-toxcore/other/docker/infer/Dockerfile
vendored
Normal file
41
external/toxcore/c-toxcore/other/docker/infer/Dockerfile
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
FROM toxchat/infer:latest
|
||||||
|
|
||||||
|
COPY toxav/ /work/c-toxcore/toxav/
|
||||||
|
COPY toxcore/ /work/c-toxcore/toxcore/
|
||||||
|
COPY toxencryptsave/ /work/c-toxcore/toxencryptsave/
|
||||||
|
COPY third_party/ /work/c-toxcore/third_party/
|
||||||
|
RUN infer capture -- clang++ -fsyntax-only \
|
||||||
|
$(pkg-config --cflags libconfig libsodium opus vpx) \
|
||||||
|
/work/c-toxcore/toxav/*.c \
|
||||||
|
/work/c-toxcore/toxcore/*.c \
|
||||||
|
/work/c-toxcore/toxcore/*/*.c \
|
||||||
|
/work/c-toxcore/toxencryptsave/*.c
|
||||||
|
RUN ["infer", "analyze",\
|
||||||
|
"--report-console-limit", "100",\
|
||||||
|
"--jobs", "8",\
|
||||||
|
"--no-bufferoverrun",\
|
||||||
|
"--no-datalog",\
|
||||||
|
"--print-active-checkers",\
|
||||||
|
"--loop-hoisting",\
|
||||||
|
"--quandary",\
|
||||||
|
"--racerd",\
|
||||||
|
"--starvation",\
|
||||||
|
"--uninit",\
|
||||||
|
"--disable-issue-type", "BUFFER_OVERRUN_L2",\
|
||||||
|
"--disable-issue-type", "PULSE_UNNECESSARY_COPY",\
|
||||||
|
"--enable-issue-type", "EXPENSIVE_EXECUTION_TIME",\
|
||||||
|
"--enable-issue-type", "INVARIANT_CALL",\
|
||||||
|
"--enable-issue-type", "PULSE_UNINITIALIZED_CONST",\
|
||||||
|
"--enable-issue-type", "SENSITIVE_DATA_FLOW",\
|
||||||
|
"--enable-issue-type", "UNTRUSTED_BUFFER_ACCESS",\
|
||||||
|
"--enable-issue-type", "UNTRUSTED_HEAP_ALLOCATION",\
|
||||||
|
"--disable-issue-type", "USE_AFTER_FREE_LATENT",\
|
||||||
|
"--disable-issue-type", "STACK_VARIABLE_ADDRESS_ESCAPE",\
|
||||||
|
"--disable-issue-type", "INVARIANT_CALL",\
|
||||||
|
"--fail-on-issue"]
|
||||||
|
# In the above, the first 2 are disabled for extreme sensitivity and false
|
||||||
|
# positives, the ones at the end are probably decent, but have some false
|
||||||
|
# positives, so we can't fail-on-issue with them on.
|
||||||
|
# INVARIANT_CALL is pretty fun, but currently wrong, because it can't see
|
||||||
|
# through potential mutations via callbacks. Our code is bad and we should
|
||||||
|
# feel bad, but until that's fixed, the invariant checker doesn't work.
|
5
external/toxcore/c-toxcore/other/docker/infer/run
vendored
Executable file
5
external/toxcore/c-toxcore/other/docker/infer/run
vendored
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
BUILD=infer
|
||||||
|
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
|
@@ -1,6 +1,7 @@
|
|||||||
FROM ubuntu:20.04
|
FROM ubuntu:20.04
|
||||||
|
|
||||||
RUN apt-get update && apt-get install --no-install-recommends -y \
|
RUN apt-get update && \
|
||||||
|
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
cppcheck \
|
cppcheck \
|
||||||
libopus-dev \
|
libopus-dev \
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
FROM toxchat/haskell:hs-tokstyle AS tokstyle
|
FROM toxchat/haskell:hs-tokstyle AS tokstyle
|
||||||
FROM ubuntu:22.04
|
FROM ubuntu:22.04
|
||||||
|
|
||||||
RUN apt-get update && apt-get install --no-install-recommends -y \
|
RUN apt-get update && \
|
||||||
|
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
clang \
|
clang \
|
||||||
git \
|
git \
|
||||||
|
@@ -2,7 +2,7 @@ FROM debian:bullseye-slim
|
|||||||
|
|
||||||
# Build-time environment variables
|
# Build-time environment variables
|
||||||
ARG VERSION_MSGPACK=4.0.0 \
|
ARG VERSION_MSGPACK=4.0.0 \
|
||||||
VERSION_SODIUM=1.0.18 \
|
VERSION_SODIUM=1.0.19 \
|
||||||
VERSION_OPUS=1.3.1 \
|
VERSION_OPUS=1.3.1 \
|
||||||
VERSION_VPX=1.11.0 \
|
VERSION_VPX=1.11.0 \
|
||||||
\
|
\
|
||||||
|
@@ -40,9 +40,9 @@ build() {
|
|||||||
|
|
||||||
echo
|
echo
|
||||||
echo "=== Building Sodium $VERSION_SODIUM $ARCH ==="
|
echo "=== Building Sodium $VERSION_SODIUM $ARCH ==="
|
||||||
curl "${CURL_OPTIONS[@]}" -O "https://download.libsodium.org/libsodium/releases/libsodium-$VERSION_SODIUM.tar.gz"
|
curl "${CURL_OPTIONS[@]}" -O "https://github.com/jedisct1/libsodium/releases/download/$VERSION_SODIUM-RELEASE/libsodium-$VERSION_SODIUM.tar.gz"
|
||||||
tar -xf "libsodium-$VERSION_SODIUM.tar.gz"
|
tar -xf "libsodium-$VERSION_SODIUM.tar.gz"
|
||||||
cd "libsodium-$VERSION_SODIUM"
|
cd "libsodium-stable"
|
||||||
./configure --host="$WINDOWS_TOOLCHAIN" --prefix="$PREFIX_DIR" --disable-shared --enable-static
|
./configure --host="$WINDOWS_TOOLCHAIN" --prefix="$PREFIX_DIR" --disable-shared --enable-static
|
||||||
make
|
make
|
||||||
make install
|
make install
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
// Copyright © 2023 The TokTok team.
|
// Copyright © 2023-2024 The TokTok team.
|
||||||
|
|
||||||
// this file can be used to generate event.c files
|
// this file can be used to generate event.c files
|
||||||
// requires c++17
|
// requires c++17
|
||||||
@@ -119,22 +119,54 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool need_stdlib_h = false;
|
||||||
|
bool need_string_h = false;
|
||||||
|
bool need_tox_unpack_h = false;
|
||||||
|
for (const auto& t : event_types) {
|
||||||
|
std::visit(
|
||||||
|
overloaded{
|
||||||
|
[&](const EventTypeTrivial& t) {
|
||||||
|
if (bin_unpack_name_from_type(t.type).rfind("tox_", 0) == 0) {
|
||||||
|
need_tox_unpack_h = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[&](const EventTypeByteRange&) {
|
||||||
|
need_stdlib_h = true;
|
||||||
|
need_string_h = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
t
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
f << R"(/* SPDX-License-Identifier: GPL-3.0-or-later
|
f << R"(/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2023 The TokTok team.
|
* Copyright © 2023-2024 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "events_alloc.h"
|
#include "events_alloc.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>)";
|
||||||
#include <stdlib.h>
|
if (need_stdlib_h) {
|
||||||
#include <string.h>
|
f << R"(
|
||||||
|
#include <stdlib.h>)";
|
||||||
|
}
|
||||||
|
if (need_string_h) {
|
||||||
|
f << R"(
|
||||||
|
#include <string.h>)";
|
||||||
|
}
|
||||||
|
f << R"(
|
||||||
|
|
||||||
#include "../bin_pack.h"
|
#include "../bin_pack.h"
|
||||||
#include "../bin_unpack.h"
|
#include "../bin_unpack.h"
|
||||||
#include "../ccompat.h"
|
#include "../ccompat.h"
|
||||||
|
#include "../mem.h"
|
||||||
#include "../tox.h"
|
#include "../tox.h"
|
||||||
#include "../tox_events.h"
|
#include "../tox_events.h")";
|
||||||
#include "../tox_unpack.h"
|
if (need_tox_unpack_h) {
|
||||||
|
f << R"(
|
||||||
|
#include "../tox_unpack.h")";
|
||||||
|
}
|
||||||
|
f << R"(
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************
|
/*****************************************************
|
||||||
@@ -205,10 +237,11 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
|
|||||||
f << " " << event_name_l << "->" << t.name_data << " = nullptr;\n";
|
f << " " << event_name_l << "->" << t.name_data << " = nullptr;\n";
|
||||||
f << " " << event_name_l << "->" << t.name_length << " = 0;\n";
|
f << " " << event_name_l << "->" << t.name_length << " = 0;\n";
|
||||||
f << " }\n\n";
|
f << " }\n\n";
|
||||||
f << " " << event_name_l << "->" << t.name_data << " = (uint8_t *)malloc(" << t.name_length << ");\n\n";
|
f << " uint8_t *" << t.name_data << "_copy = (uint8_t *)malloc(" << t.name_length << ");\n\n";
|
||||||
f << " if (" << event_name_l << "->" << t.name_data << " == nullptr) {\n";
|
f << " if (" << t.name_data << "_copy == nullptr) {\n";
|
||||||
f << " return false;\n }\n\n";
|
f << " return false;\n }\n\n";
|
||||||
f << " memcpy(" << event_name_l << "->" << t.name_data << ", " << t.name_data << ", " << t.name_length << ");\n";
|
f << " memcpy(" << t.name_data << "_copy, " << t.name_data << ", " << t.name_length << ");\n";
|
||||||
|
f << " " << event_name_l << "->" << t.name_data << " = " << t.name_data << "_copy;\n";
|
||||||
f << " " << event_name_l << "->" << t.name_length << " = " << t.name_length << ";\n";
|
f << " " << event_name_l << "->" << t.name_length << " = " << t.name_length << ";\n";
|
||||||
f << " return true;\n";
|
f << " return true;\n";
|
||||||
}
|
}
|
||||||
@@ -371,28 +404,6 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
|
|||||||
f << " tox_events_add(events, &event);\n";
|
f << " tox_events_add(events, &event);\n";
|
||||||
f << " return " << event_name_l << ";\n}\n\n";
|
f << " return " << event_name_l << ";\n}\n\n";
|
||||||
|
|
||||||
// get
|
|
||||||
f << "const Tox_Event_" << event_name << " *tox_events_get_" << event_name_l << "(const Tox_Events *events, uint32_t index)\n{\n";
|
|
||||||
f << " uint32_t " << event_name_l << "_index = 0;\n";
|
|
||||||
f << " const uint32_t size = tox_events_get_size(events);\n\n";
|
|
||||||
f << " for (uint32_t i = 0; i < size; ++i) {\n";
|
|
||||||
f << " if (" << event_name_l << "_index > index) {\n";
|
|
||||||
f << " return nullptr;\n }\n\n";
|
|
||||||
f << " if (events->events[i].type == TOX_EVENT_" << str_toupper(event_name) << ") {\n";
|
|
||||||
f << " const Tox_Event_" << event_name << " *" << event_name_l << " = events->events[i].data." << event_name_l << ";\n";
|
|
||||||
f << " if (" << event_name_l << "_index == index) {\n";
|
|
||||||
f << " return " << event_name_l << ";\n }\n";
|
|
||||||
f << " ++" << event_name_l << "_index;\n }\n }\n\n return nullptr;\n}\n\n";
|
|
||||||
|
|
||||||
// get size
|
|
||||||
f << "uint32_t tox_events_get_" << event_name_l << "_size(const Tox_Events *events)\n{\n";
|
|
||||||
f << " uint32_t " << event_name_l << "_size = 0;\n";
|
|
||||||
f << " const uint32_t size = tox_events_get_size(events);\n\n";
|
|
||||||
f << " for (uint32_t i = 0; i < size; ++i) {\n";
|
|
||||||
f << " if (events->events[i].type == TOX_EVENT_" << str_toupper(event_name) << ") {\n";
|
|
||||||
f << " ++" << event_name_l << "_size;\n }\n }\n\n";
|
|
||||||
f << " return " << event_name_l << "_size;\n}\n\n";
|
|
||||||
|
|
||||||
// unpack
|
// unpack
|
||||||
f << "bool tox_event_" << event_name_l << "_unpack(\n";
|
f << "bool tox_event_" << event_name_l << "_unpack(\n";
|
||||||
f << " Tox_Event_" << event_name << " **event, Bin_Unpack *bu, const Memory *mem)\n{\n";
|
f << " Tox_Event_" << event_name << " **event, Bin_Unpack *bu, const Memory *mem)\n{\n";
|
||||||
|
@@ -10,3 +10,6 @@ sonar.sources=.
|
|||||||
|
|
||||||
# Encoding of the source code.
|
# Encoding of the source code.
|
||||||
sonar.sourceEncoding=UTF-8
|
sonar.sourceEncoding=UTF-8
|
||||||
|
|
||||||
|
# More precise Python version.
|
||||||
|
sonar.python.version=3.11
|
||||||
|
@@ -13,7 +13,6 @@ sh_test(
|
|||||||
args = ["$(locations %s)" % f for f in CIMPLE_FILES] + [
|
args = ["$(locations %s)" % f for f in CIMPLE_FILES] + [
|
||||||
"-Wno-boolean-return",
|
"-Wno-boolean-return",
|
||||||
"-Wno-callback-names",
|
"-Wno-callback-names",
|
||||||
"-Wno-enum-names",
|
|
||||||
"+RTS",
|
"+RTS",
|
||||||
"-N4",
|
"-N4",
|
||||||
"-RTS",
|
"-RTS",
|
||||||
|
@@ -8,10 +8,19 @@ if(TARGET toxcore_static)
|
|||||||
else()
|
else()
|
||||||
target_link_libraries(misc_tools PRIVATE toxcore_shared)
|
target_link_libraries(misc_tools PRIVATE toxcore_shared)
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(misc_tools PRIVATE ${LIBSODIUM_LIBRARIES})
|
if(TARGET unofficial-sodium::sodium)
|
||||||
target_link_directories(misc_tools PUBLIC ${LIBSODIUM_LIBRARY_DIRS})
|
target_link_libraries(misc_tools PRIVATE unofficial-sodium::sodium)
|
||||||
target_include_directories(misc_tools SYSTEM PRIVATE ${LIBSODIUM_INCLUDE_DIRS})
|
else()
|
||||||
target_compile_options(misc_tools PRIVATE ${LIBSODIUM_CFLAGS_OTHER})
|
target_link_libraries(misc_tools PRIVATE ${LIBSODIUM_LIBRARIES})
|
||||||
|
target_link_directories(misc_tools PUBLIC ${LIBSODIUM_LIBRARY_DIRS})
|
||||||
|
target_include_directories(misc_tools SYSTEM PRIVATE ${LIBSODIUM_INCLUDE_DIRS})
|
||||||
|
target_compile_options(misc_tools PRIVATE ${LIBSODIUM_CFLAGS_OTHER})
|
||||||
|
endif()
|
||||||
|
if(TARGET PThreads4W::PThreads4W)
|
||||||
|
target_link_libraries(misc_tools PRIVATE PThreads4W::PThreads4W)
|
||||||
|
elseif(TARGET Threads::Threads)
|
||||||
|
target_link_libraries(misc_tools PRIVATE Threads::Threads)
|
||||||
|
endif()
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
@@ -27,4 +36,9 @@ if(BUILD_MISC_TESTS)
|
|||||||
else()
|
else()
|
||||||
target_link_libraries(Messenger_test PRIVATE toxcore_shared)
|
target_link_libraries(Messenger_test PRIVATE toxcore_shared)
|
||||||
endif()
|
endif()
|
||||||
|
if(TARGET PThreads4W::PThreads4W)
|
||||||
|
target_link_libraries(Messenger_test PRIVATE PThreads4W::PThreads4W)
|
||||||
|
elseif(TARGET Threads::Threads)
|
||||||
|
target_link_libraries(Messenger_test PRIVATE Threads::Threads)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
@@ -1,26 +1,33 @@
|
|||||||
# For coverage tests
|
|
||||||
target_compile_definitions(toxcore_static PUBLIC "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION")
|
|
||||||
|
|
||||||
# Override network and random functions
|
# Override network and random functions
|
||||||
add_library(fuzz_support func_conversion.h fuzz_support.cc fuzz_support.h)
|
add_library(fuzz_support func_conversion.h fuzz_support.cc fuzz_support.h)
|
||||||
|
|
||||||
set(LIBFUZZER_LINKER_FLAGS)
|
set(LIBFUZZER_LINKER_FLAGS)
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||||
set(LIBFUZZER_LINKER_FLAGS "-fsanitize=fuzzer")
|
set(LIBFUZZER_LINKER_FLAGS "-fsanitize=fuzzer")
|
||||||
else()
|
else()
|
||||||
message(SEND_ERROR "Compiler must be Clang to build fuzz targets")
|
message(SEND_ERROR "Compiler must be Clang to build fuzz targets")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
function(fuzz_test target source_dir)
|
||||||
|
set(${target}_CORPUS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/toktok-fuzzer/corpus/${target}_fuzz_test)
|
||||||
|
file(GLOB ${target}_fuzz_CORPUS "${${target}_CORPUS_DIR}/*")
|
||||||
|
add_executable(${target}_fuzz_test ${source_dir}/${target}_fuzz_test.cc)
|
||||||
|
target_link_libraries(${target}_fuzz_test PRIVATE toxcore_fuzz fuzz_support ${LIBFUZZER_LINKER_FLAGS})
|
||||||
|
if(${target}_fuzz_CORPUS)
|
||||||
|
add_test(NAME ${target}_fuzz COMMAND ${CROSSCOMPILING_EMULATOR} ${target}_fuzz_test -max_total_time=10 ${${target}_fuzz_CORPUS})
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Fuzzes the toxsave API
|
# Fuzzes the toxsave API
|
||||||
add_executable(toxsave_fuzzer toxsave_harness.cc)
|
add_executable(toxsave_fuzzer toxsave_harness.cc)
|
||||||
target_link_libraries(toxsave_fuzzer PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS})
|
target_link_libraries(toxsave_fuzzer PRIVATE toxcore_fuzz fuzz_support ${LIBFUZZER_LINKER_FLAGS})
|
||||||
|
|
||||||
# Fuzzes the bootstrap process
|
# Fuzzes the bootstrap process
|
||||||
add_executable(bootstrap_fuzzer bootstrap_harness.cc)
|
add_executable(bootstrap_fuzzer bootstrap_harness.cc)
|
||||||
target_link_libraries(bootstrap_fuzzer PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS})
|
target_link_libraries(bootstrap_fuzzer PRIVATE toxcore_fuzz fuzz_support ${LIBFUZZER_LINKER_FLAGS})
|
||||||
|
|
||||||
add_executable(DHT_fuzz_test ../../toxcore/DHT_fuzz_test.cc)
|
fuzz_test(DHT ../../toxcore)
|
||||||
target_link_libraries(DHT_fuzz_test PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS})
|
fuzz_test(forwarding ../../toxcore)
|
||||||
|
fuzz_test(group_announce ../../toxcore)
|
||||||
add_executable(tox_events_fuzz_test ../../toxcore/tox_events_fuzz_test.cc)
|
fuzz_test(group_moderation ../../toxcore)
|
||||||
target_link_libraries(tox_events_fuzz_test PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS})
|
fuzz_test(tox_events ../../toxcore)
|
||||||
|
@@ -126,7 +126,7 @@ void TestBootstrap(Fuzz_Data &input)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
CONSUME1_OR_RETURN(const uint8_t proxy_type, input);
|
CONSUME1_OR_RETURN(const uint8_t, proxy_type, input);
|
||||||
if (proxy_type == 0) {
|
if (proxy_type == 0) {
|
||||||
tox_options_set_proxy_type(opts.get(), TOX_PROXY_TYPE_NONE);
|
tox_options_set_proxy_type(opts.get(), TOX_PROXY_TYPE_NONE);
|
||||||
} else if (proxy_type == 1) {
|
} else if (proxy_type == 1) {
|
||||||
@@ -139,7 +139,7 @@ void TestBootstrap(Fuzz_Data &input)
|
|||||||
tox_options_set_proxy_port(opts.get(), 8080);
|
tox_options_set_proxy_port(opts.get(), 8080);
|
||||||
}
|
}
|
||||||
|
|
||||||
CONSUME1_OR_RETURN(const uint8_t tcp_relay_enabled, input);
|
CONSUME1_OR_RETURN(const uint8_t, tcp_relay_enabled, input);
|
||||||
if (tcp_relay_enabled >= (UINT8_MAX / 2)) {
|
if (tcp_relay_enabled >= (UINT8_MAX / 2)) {
|
||||||
tox_options_set_tcp_port(opts.get(), 33445);
|
tox_options_set_tcp_port(opts.get(), 33445);
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "../../toxcore/crypto_core.h"
|
||||||
#include "../../toxcore/tox.h"
|
#include "../../toxcore/tox.h"
|
||||||
#include "../../toxcore/tox_dispatch.h"
|
#include "../../toxcore/tox_dispatch.h"
|
||||||
#include "../../toxcore/tox_events.h"
|
#include "../../toxcore/tox_events.h"
|
||||||
|
@@ -30,6 +30,16 @@ struct Network_Addr {
|
|||||||
size_t size;
|
size_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
System::System(std::unique_ptr<Tox_System> in_sys, std::unique_ptr<Memory> in_mem,
|
||||||
|
std::unique_ptr<Network> in_ns, std::unique_ptr<Random> in_rng)
|
||||||
|
: sys(std::move(in_sys))
|
||||||
|
, mem(std::move(in_mem))
|
||||||
|
, ns(std::move(in_ns))
|
||||||
|
, rng(std::move(in_rng))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
System::System(System &&) = default;
|
||||||
|
|
||||||
System::~System() { }
|
System::~System() { }
|
||||||
|
|
||||||
static int recv_common(Fuzz_Data &input, uint8_t *buf, size_t buf_len)
|
static int recv_common(Fuzz_Data &input, uint8_t *buf, size_t buf_len)
|
||||||
@@ -67,7 +77,7 @@ static int recv_common(Fuzz_Data &input, uint8_t *buf, size_t buf_len)
|
|||||||
template <typename F>
|
template <typename F>
|
||||||
static void *alloc_common(Fuzz_Data &data, F func)
|
static void *alloc_common(Fuzz_Data &data, F func)
|
||||||
{
|
{
|
||||||
CONSUME1_OR_RETURN_VAL(const uint8_t want_alloc, data, func());
|
CONSUME1_OR_RETURN_VAL(const uint8_t, want_alloc, data, func());
|
||||||
if (!want_alloc) {
|
if (!want_alloc) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@@ -7,11 +7,12 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "../../toxcore/tox.h"
|
#include "../../toxcore/tox.h"
|
||||||
|
|
||||||
@@ -20,19 +21,28 @@ struct Fuzz_Data {
|
|||||||
std::size_t size;
|
std::size_t size;
|
||||||
|
|
||||||
Fuzz_Data(const uint8_t *input_data, std::size_t input_size)
|
Fuzz_Data(const uint8_t *input_data, std::size_t input_size)
|
||||||
: data(input_data), size(input_size)
|
: data(input_data)
|
||||||
{}
|
, size(input_size)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Fuzz_Data &operator=(const Fuzz_Data &rhs) = delete;
|
Fuzz_Data &operator=(const Fuzz_Data &rhs) = delete;
|
||||||
Fuzz_Data(const Fuzz_Data &rhs) = delete;
|
Fuzz_Data(const Fuzz_Data &rhs) = delete;
|
||||||
|
|
||||||
uint8_t consume1()
|
struct Consumer {
|
||||||
{
|
Fuzz_Data &fd;
|
||||||
const uint8_t val = data[0];
|
|
||||||
++data;
|
template <typename T>
|
||||||
--size;
|
operator T()
|
||||||
return val;
|
{
|
||||||
}
|
const uint8_t *bytes = fd.consume(sizeof(T));
|
||||||
|
T val;
|
||||||
|
std::memcpy(&val, bytes, sizeof(T));
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Consumer consume1() { return Consumer{*this}; }
|
||||||
|
|
||||||
const uint8_t *consume(std::size_t count)
|
const uint8_t *consume(std::size_t count)
|
||||||
{
|
{
|
||||||
@@ -50,14 +60,14 @@ struct Fuzz_Data {
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* @code
|
* @code
|
||||||
* CONSUME1_OR_RETURN(const uint8_t one_byte, input);
|
* CONSUME1_OR_RETURN(const uint8_t, one_byte, input);
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
#define CONSUME1_OR_RETURN(DECL, INPUT) \
|
#define CONSUME1_OR_RETURN(TYPE, NAME, INPUT) \
|
||||||
if (INPUT.size < 1) { \
|
if (INPUT.size < sizeof(TYPE)) { \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
DECL = INPUT.consume1()
|
TYPE NAME = INPUT.consume1()
|
||||||
|
|
||||||
/** @brief Consumes 1 byte of the fuzzer input or returns a value if no data
|
/** @brief Consumes 1 byte of the fuzzer input or returns a value if no data
|
||||||
* available.
|
* available.
|
||||||
@@ -70,11 +80,11 @@ struct Fuzz_Data {
|
|||||||
* CONSUME1_OR_RETURN_VAL(const uint8_t one_byte, input, nullptr);
|
* CONSUME1_OR_RETURN_VAL(const uint8_t one_byte, input, nullptr);
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
#define CONSUME1_OR_RETURN_VAL(DECL, INPUT, VAL) \
|
#define CONSUME1_OR_RETURN_VAL(TYPE, NAME, INPUT, VAL) \
|
||||||
if (INPUT.size < 1) { \
|
if (INPUT.size < sizeof(TYPE)) { \
|
||||||
return VAL; \
|
return VAL; \
|
||||||
} \
|
} \
|
||||||
DECL = INPUT.consume1()
|
TYPE NAME = INPUT.consume1()
|
||||||
|
|
||||||
/** @brief Consumes SIZE bytes of the fuzzer input or returns if not enough data available.
|
/** @brief Consumes SIZE bytes of the fuzzer input or returns if not enough data available.
|
||||||
*
|
*
|
||||||
@@ -93,6 +103,12 @@ struct Fuzz_Data {
|
|||||||
} \
|
} \
|
||||||
DECL = INPUT.consume(SIZE)
|
DECL = INPUT.consume(SIZE)
|
||||||
|
|
||||||
|
#define CONSUME_OR_RETURN_VAL(DECL, INPUT, SIZE, VAL) \
|
||||||
|
if (INPUT.size < SIZE) { \
|
||||||
|
return VAL; \
|
||||||
|
} \
|
||||||
|
DECL = INPUT.consume(SIZE)
|
||||||
|
|
||||||
inline void fuzz_select_target(uint8_t selector, Fuzz_Data &input)
|
inline void fuzz_select_target(uint8_t selector, Fuzz_Data &input)
|
||||||
{
|
{
|
||||||
// The selector selected no function, so we do nothing and rely on the
|
// The selector selected no function, so we do nothing and rely on the
|
||||||
@@ -100,7 +116,7 @@ inline void fuzz_select_target(uint8_t selector, Fuzz_Data &input)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Arg, typename... Args>
|
template <typename Arg, typename... Args>
|
||||||
void fuzz_select_target(uint8_t selector, Fuzz_Data &input, Arg &&fn, Args &&... args)
|
void fuzz_select_target(uint8_t selector, Fuzz_Data &input, Arg &&fn, Args &&...args)
|
||||||
{
|
{
|
||||||
if (selector == sizeof...(Args)) {
|
if (selector == sizeof...(Args)) {
|
||||||
return fn(input);
|
return fn(input);
|
||||||
@@ -109,11 +125,11 @@ void fuzz_select_target(uint8_t selector, Fuzz_Data &input, Arg &&fn, Args &&...
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void fuzz_select_target(const uint8_t *data, std::size_t size, Args &&... args)
|
void fuzz_select_target(const uint8_t *data, std::size_t size, Args &&...args)
|
||||||
{
|
{
|
||||||
Fuzz_Data input{data, size};
|
Fuzz_Data input{data, size};
|
||||||
|
|
||||||
CONSUME1_OR_RETURN(uint8_t selector, input);
|
CONSUME1_OR_RETURN(const uint8_t, selector, input);
|
||||||
return fuzz_select_target(selector, input, std::forward<Args>(args)...);
|
return fuzz_select_target(selector, input, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,6 +143,10 @@ struct System {
|
|||||||
std::unique_ptr<Network> ns;
|
std::unique_ptr<Network> ns;
|
||||||
std::unique_ptr<Random> rng;
|
std::unique_ptr<Random> rng;
|
||||||
|
|
||||||
|
System(std::unique_ptr<Tox_System> sys, std::unique_ptr<Memory> mem,
|
||||||
|
std::unique_ptr<Network> ns, std::unique_ptr<Random> rng);
|
||||||
|
System(System &&);
|
||||||
|
|
||||||
// Not inline because sizeof of the above 2 structs is not known everywhere.
|
// Not inline because sizeof of the above 2 structs is not known everywhere.
|
||||||
~System();
|
~System();
|
||||||
|
|
||||||
|
@@ -1,96 +1,17 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2022 The TokTok team.
|
* Copyright © 2022-2024 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef C_TOXCORE_TESTING_FUZZING_FUZZ_TOX_H
|
#ifndef C_TOXCORE_TESTING_FUZZING_FUZZ_TOX_H
|
||||||
#define C_TOXCORE_TESTING_FUZZING_FUZZ_TOX_H
|
#define C_TOXCORE_TESTING_FUZZING_FUZZ_TOX_H
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "../../toxcore/DHT.h"
|
|
||||||
#include "../../toxcore/logger.h"
|
|
||||||
#include "../../toxcore/network.h"
|
#include "../../toxcore/network.h"
|
||||||
#include "fuzz_support.h"
|
|
||||||
|
|
||||||
constexpr uint16_t SIZE_IP_PORT = SIZE_IP6 + sizeof(uint16_t);
|
constexpr uint16_t SIZE_IP_PORT = SIZE_IP6 + sizeof(uint16_t);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using Ptr = std::unique_ptr<T, void (*)(T *)>;
|
using Ptr = std::unique_ptr<T, void (*)(T *)>;
|
||||||
|
|
||||||
/** @brief Construct any Tox resource using fuzzer input data.
|
|
||||||
*
|
|
||||||
* Constructs (or fails by returning) a valid object of type T and passes it to
|
|
||||||
* a function specified on the rhs of `>>`. Takes care of cleaning up the
|
|
||||||
* resource after the specified function returns.
|
|
||||||
*
|
|
||||||
* Some `with` instances require additional inputs such as the `Fuzz_Data`
|
|
||||||
* reference or a logger.
|
|
||||||
*/
|
|
||||||
template <typename T>
|
|
||||||
struct with;
|
|
||||||
|
|
||||||
/** @brief Construct a Logger without logging callback.
|
|
||||||
*/
|
|
||||||
template <>
|
|
||||||
struct with<Logger> {
|
|
||||||
template <typename F>
|
|
||||||
void operator>>(F &&f)
|
|
||||||
{
|
|
||||||
Ptr<Logger> logger(logger_new(), logger_kill);
|
|
||||||
assert(logger != nullptr);
|
|
||||||
f(std::move(logger));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** @brief Construct an IP_Port by unpacking fuzzer input with `unpack_ip_port`.
|
|
||||||
*/
|
|
||||||
template <>
|
|
||||||
struct with<IP_Port> {
|
|
||||||
Fuzz_Data &input_;
|
|
||||||
|
|
||||||
template <typename F>
|
|
||||||
void operator>>(F &&f)
|
|
||||||
{
|
|
||||||
CONSUME_OR_RETURN(const uint8_t *ipp_packed, input_, SIZE_IP_PORT);
|
|
||||||
IP_Port ipp;
|
|
||||||
unpack_ip_port(&ipp, ipp_packed, SIZE_IP6, true);
|
|
||||||
|
|
||||||
f(ipp);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** @brief Construct a Networking_Core object using the Network vtable passed.
|
|
||||||
*
|
|
||||||
* Use `with<Logger>{} >> with<Networking_Core>{input, ns, mem} >> ...` to construct
|
|
||||||
* a logger and pass it to the Networking_Core constructor function.
|
|
||||||
*/
|
|
||||||
template <>
|
|
||||||
struct with<Networking_Core> {
|
|
||||||
Fuzz_Data &input_;
|
|
||||||
const Network *ns_;
|
|
||||||
const Memory *mem_;
|
|
||||||
Ptr<Logger> logger_{nullptr, logger_kill};
|
|
||||||
|
|
||||||
friend with operator>>(with<Logger> f, with self)
|
|
||||||
{
|
|
||||||
f >> [&self](Ptr<Logger> logger) { self.logger_ = std::move(logger); };
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename F>
|
|
||||||
void operator>>(F &&f)
|
|
||||||
{
|
|
||||||
with<IP_Port>{input_} >> [&f, this](const IP_Port &ipp) {
|
|
||||||
Ptr<Networking_Core> net(
|
|
||||||
new_networking_ex(logger_.get(), mem_, ns_, &ipp.ip, ipp.port, ipp.port + 100, nullptr),
|
|
||||||
kill_networking);
|
|
||||||
if (net == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
f(std::move(net));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // C_TOXCORE_TESTING_FUZZING_FUZZ_TOX_H
|
#endif // C_TOXCORE_TESTING_FUZZING_FUZZ_TOX_H
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include "../../toxcore/crypto_core.h"
|
||||||
#include "../../toxcore/tox.h"
|
#include "../../toxcore/tox.h"
|
||||||
#include "../../toxcore/tox_dispatch.h"
|
#include "../../toxcore/tox_dispatch.h"
|
||||||
#include "../../toxcore/tox_events.h"
|
#include "../../toxcore/tox_events.h"
|
||||||
|
#include "../../toxcore/tox_private.h"
|
||||||
#include "fuzz_support.h"
|
#include "fuzz_support.h"
|
||||||
#include "fuzz_tox.h"
|
#include "fuzz_tox.h"
|
||||||
|
|
||||||
|
6
external/toxcore/c-toxcore/toxav/audio.c
vendored
6
external/toxcore/c-toxcore/toxav/audio.c
vendored
@@ -196,13 +196,13 @@ void ac_iterate(ACSession *ac)
|
|||||||
|
|
||||||
int ac_queue_message(Mono_Time *mono_time, void *acp, struct RTPMessage *msg)
|
int ac_queue_message(Mono_Time *mono_time, void *acp, struct RTPMessage *msg)
|
||||||
{
|
{
|
||||||
if (acp == nullptr || msg == nullptr) {
|
ACSession *ac = (ACSession *)acp;
|
||||||
|
|
||||||
|
if (ac == nullptr || msg == nullptr) {
|
||||||
free(msg);
|
free(msg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ACSession *ac = (ACSession *)acp;
|
|
||||||
|
|
||||||
if ((msg->header.pt & 0x7f) == (RTP_TYPE_AUDIO + 2) % 128) {
|
if ((msg->header.pt & 0x7f) == (RTP_TYPE_AUDIO + 2) % 128) {
|
||||||
LOGGER_WARNING(ac->log, "Got dummy!");
|
LOGGER_WARNING(ac->log, "Got dummy!");
|
||||||
free(msg);
|
free(msg);
|
||||||
|
@@ -208,6 +208,8 @@ static int bwc_send_custom_lossy_packet(Tox *tox, int32_t friendnumber, const ui
|
|||||||
|
|
||||||
static int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object)
|
static int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object)
|
||||||
{
|
{
|
||||||
|
BWController *bwc = (BWController *)object;
|
||||||
|
|
||||||
if (length - 1 != sizeof(struct BWCMessage)) {
|
if (length - 1 != sizeof(struct BWCMessage)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -218,5 +220,5 @@ static int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *d
|
|||||||
offset += net_unpack_u32(data + offset, &msg.recv);
|
offset += net_unpack_u32(data + offset, &msg.recv);
|
||||||
assert(offset == length);
|
assert(offset == length);
|
||||||
|
|
||||||
return on_update((BWController *)object, &msg);
|
return on_update(bwc, &msg);
|
||||||
}
|
}
|
||||||
|
14
external/toxcore/c-toxcore/toxav/groupav.c
vendored
14
external/toxcore/c-toxcore/toxav/groupav.c
vendored
@@ -290,8 +290,9 @@ static void group_av_peer_delete(void *object, uint32_t groupnumber, void *peer_
|
|||||||
|
|
||||||
static void group_av_groupchat_delete(void *object, uint32_t groupnumber)
|
static void group_av_groupchat_delete(void *object, uint32_t groupnumber)
|
||||||
{
|
{
|
||||||
if (object != nullptr) {
|
Group_AV *group_av = (Group_AV *)object;
|
||||||
kill_group_av((Group_AV *)object);
|
if (group_av != nullptr) {
|
||||||
|
kill_group_av(group_av);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,12 +405,13 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, uint3
|
|||||||
static int handle_group_audio_packet(void *object, uint32_t groupnumber, uint32_t friendgroupnumber, void *peer_object,
|
static int handle_group_audio_packet(void *object, uint32_t groupnumber, uint32_t friendgroupnumber, void *peer_object,
|
||||||
const uint8_t *packet, uint16_t length)
|
const uint8_t *packet, uint16_t length)
|
||||||
{
|
{
|
||||||
if (peer_object == nullptr || object == nullptr || length <= sizeof(uint16_t)) {
|
Group_AV *group_av = (Group_AV *)object;
|
||||||
|
Group_Peer_AV *peer_av = (Group_Peer_AV *)peer_object;
|
||||||
|
|
||||||
|
if (group_av == nullptr || peer_av == nullptr || length <= sizeof(uint16_t)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Group_Peer_AV *peer_av = (Group_Peer_AV *)peer_object;
|
|
||||||
|
|
||||||
Group_Audio_Packet *pk = (Group_Audio_Packet *)calloc(1, sizeof(Group_Audio_Packet));
|
Group_Audio_Packet *pk = (Group_Audio_Packet *)calloc(1, sizeof(Group_Audio_Packet));
|
||||||
|
|
||||||
if (pk == nullptr) {
|
if (pk == nullptr) {
|
||||||
@@ -433,7 +435,7 @@ static int handle_group_audio_packet(void *object, uint32_t groupnumber, uint32_
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (decode_audio_packet((Group_AV *)object, peer_av, groupnumber, friendgroupnumber) == 0) {
|
while (decode_audio_packet(group_av, peer_av, groupnumber, friendgroupnumber) == 0) {
|
||||||
/* Continue. */
|
/* Continue. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
external/toxcore/c-toxcore/toxav/msi.c
vendored
12
external/toxcore/c-toxcore/toxav/msi.c
vendored
@@ -60,7 +60,7 @@ typedef struct MSIMessage {
|
|||||||
|
|
||||||
static void msg_init(MSIMessage *dest, MSIRequest request);
|
static void msg_init(MSIMessage *dest, MSIRequest request);
|
||||||
static int msg_parse_in(const Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t length);
|
static int msg_parse_in(const Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t length);
|
||||||
static uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const void *value, uint8_t value_len,
|
static uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const uint8_t *value, uint8_t value_len,
|
||||||
uint16_t *length);
|
uint16_t *length);
|
||||||
static int send_message(const Messenger *m, uint32_t friend_number, const MSIMessage *msg);
|
static int send_message(const Messenger *m, uint32_t friend_number, const MSIMessage *msg);
|
||||||
static int send_error(const Messenger *m, uint32_t friend_number, MSIError error);
|
static int send_error(const Messenger *m, uint32_t friend_number, MSIError error);
|
||||||
@@ -425,7 +425,7 @@ static int msg_parse_in(const Logger *log, MSIMessage *dest, const uint8_t *data
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const void *value, uint8_t value_len,
|
static uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const uint8_t *value, uint8_t value_len,
|
||||||
uint16_t *length)
|
uint16_t *length)
|
||||||
{
|
{
|
||||||
/* Parse a single header for sending */
|
/* Parse a single header for sending */
|
||||||
@@ -587,7 +587,7 @@ static MSICall *new_call(MSISession *session, uint32_t friend_number)
|
|||||||
session->calls_tail = friend_number;
|
session->calls_tail = friend_number;
|
||||||
session->calls_head = friend_number;
|
session->calls_head = friend_number;
|
||||||
} else if (session->calls_tail < friend_number) { /* Appending */
|
} else if (session->calls_tail < friend_number) { /* Appending */
|
||||||
MSICall **tmp = (MSICall **)realloc(session->calls, sizeof(MSICall *) * (friend_number + 1));
|
MSICall **tmp = (MSICall **)realloc(session->calls, (friend_number + 1) * sizeof(MSICall *));
|
||||||
|
|
||||||
if (tmp == nullptr) {
|
if (tmp == nullptr) {
|
||||||
free(rc);
|
free(rc);
|
||||||
@@ -657,12 +657,13 @@ CLEAR_CONTAINER:
|
|||||||
}
|
}
|
||||||
static void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *data)
|
static void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *data)
|
||||||
{
|
{
|
||||||
|
MSISession *session = (MSISession *)data;
|
||||||
|
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
// Friend is online.
|
// Friend is online.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MSISession *session = (MSISession *)data;
|
|
||||||
LOGGER_DEBUG(m->log, "Friend %d is now offline", friend_number);
|
LOGGER_DEBUG(m->log, "Friend %d is now offline", friend_number);
|
||||||
|
|
||||||
pthread_mutex_lock(session->mutex);
|
pthread_mutex_lock(session->mutex);
|
||||||
@@ -851,9 +852,10 @@ static void handle_pop(MSICall *call, const MSIMessage *msg)
|
|||||||
}
|
}
|
||||||
static void handle_msi_packet(Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t length, void *object)
|
static void handle_msi_packet(Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t length, void *object)
|
||||||
{
|
{
|
||||||
|
MSISession *session = (MSISession *)object;
|
||||||
|
|
||||||
LOGGER_DEBUG(m->log, "Got msi message");
|
LOGGER_DEBUG(m->log, "Got msi message");
|
||||||
|
|
||||||
MSISession *session = (MSISession *)object;
|
|
||||||
MSIMessage msg;
|
MSIMessage msg;
|
||||||
|
|
||||||
if (msg_parse_in(m->log, &msg, data, length) == -1) {
|
if (msg_parse_in(m->log, &msg, data, length) == -1) {
|
||||||
|
@@ -106,8 +106,9 @@ uint16_t rb_size(const RingBuffer *b)
|
|||||||
uint16_t rb_data(const RingBuffer *b, void **dest)
|
uint16_t rb_data(const RingBuffer *b, void **dest)
|
||||||
{
|
{
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
const uint16_t size = rb_size(b);
|
||||||
|
|
||||||
for (i = 0; i < rb_size(b); ++i) {
|
for (i = 0; i < size; ++i) {
|
||||||
dest[i] = b->data[(b->start + i) % b->size];
|
dest[i] = b->data[(b->start + i) % b->size];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
external/toxcore/c-toxcore/toxav/toxav.c
vendored
2
external/toxcore/c-toxcore/toxav/toxav.c
vendored
@@ -1284,7 +1284,7 @@ static ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, Toxav_Err_Call *er
|
|||||||
av->calls_tail = friend_number;
|
av->calls_tail = friend_number;
|
||||||
av->calls_head = friend_number;
|
av->calls_head = friend_number;
|
||||||
} else if (av->calls_tail < friend_number) { /* Appending */
|
} else if (av->calls_tail < friend_number) { /* Appending */
|
||||||
ToxAVCall **tmp = (ToxAVCall **)realloc(av->calls, sizeof(ToxAVCall *) * (friend_number + 1));
|
ToxAVCall **tmp = (ToxAVCall **)realloc(av->calls, (friend_number + 1) * sizeof(ToxAVCall *));
|
||||||
|
|
||||||
if (tmp == nullptr) {
|
if (tmp == nullptr) {
|
||||||
pthread_mutex_destroy(call->toxav_call_mutex);
|
pthread_mutex_destroy(call->toxav_call_mutex);
|
||||||
|
55
external/toxcore/c-toxcore/toxav/toxav.h
vendored
55
external/toxcore/c-toxcore/toxav/toxav.h
vendored
@@ -65,15 +65,17 @@ extern "C" {
|
|||||||
/**
|
/**
|
||||||
* External Tox type.
|
* External Tox type.
|
||||||
*/
|
*/
|
||||||
|
#ifndef APIGEN_IGNORE
|
||||||
#ifndef TOX_DEFINED
|
#ifndef TOX_DEFINED
|
||||||
#define TOX_DEFINED
|
#define TOX_DEFINED
|
||||||
typedef struct Tox Tox;
|
typedef struct Tox Tox;
|
||||||
#endif /* TOX_DEFINED */
|
#endif /* !TOX_DEFINED */
|
||||||
|
#endif /* !APIGEN_IGNORE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The ToxAV instance type.
|
* @brief The ToxAV instance type.
|
||||||
*
|
*
|
||||||
* Each ToxAV instance can be bound to only one Tox instance, and Tox instance
|
* Each ToxAV instance can be bound to only one Tox instance, and Tox instance
|
||||||
* can have only one ToxAV instance. One must make sure to close ToxAV instance
|
* can have only one ToxAV instance. One must make sure to close ToxAV instance
|
||||||
* prior closing Tox instance otherwise undefined behaviour occurs. Upon
|
* prior closing Tox instance otherwise undefined behaviour occurs. Upon
|
||||||
* closing of ToxAV instance, all active calls will be forcibly terminated
|
* closing of ToxAV instance, all active calls will be forcibly terminated
|
||||||
@@ -605,7 +607,7 @@ typedef enum Toxav_Err_Send_Frame {
|
|||||||
* @param sampling_rate Audio sampling rate used in this frame. Valid sampling
|
* @param sampling_rate Audio sampling rate used in this frame. Valid sampling
|
||||||
* rates are 8000, 12000, 16000, 24000, or 48000.
|
* rates are 8000, 12000, 16000, 24000, or 48000.
|
||||||
*/
|
*/
|
||||||
bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pcm, size_t sample_count,
|
bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t pcm[], size_t sample_count,
|
||||||
uint8_t channels, uint32_t sampling_rate, Toxav_Err_Send_Frame *error);
|
uint8_t channels, uint32_t sampling_rate, Toxav_Err_Send_Frame *error);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -652,8 +654,12 @@ void toxav_callback_audio_bit_rate(ToxAV *av, toxav_audio_bit_rate_cb *callback,
|
|||||||
* @param u U (Chroma) plane data.
|
* @param u U (Chroma) plane data.
|
||||||
* @param v V (Chroma) plane data.
|
* @param v V (Chroma) plane data.
|
||||||
*/
|
*/
|
||||||
bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height, const uint8_t *y,
|
bool toxav_video_send_frame(
|
||||||
const uint8_t *u, const uint8_t *v, Toxav_Err_Send_Frame *error);
|
ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height,
|
||||||
|
const uint8_t y[/*! height * width */],
|
||||||
|
const uint8_t u[/*! height/2 * width/2 */],
|
||||||
|
const uint8_t v[/*! height/2 * width/2 */],
|
||||||
|
Toxav_Err_Send_Frame *error);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the bit rate to be used in subsequent video frames.
|
* Set the bit rate to be used in subsequent video frames.
|
||||||
@@ -703,7 +709,7 @@ void toxav_callback_video_bit_rate(ToxAV *av, toxav_video_bit_rate_cb *callback,
|
|||||||
* @param sampling_rate Sampling rate used in this frame.
|
* @param sampling_rate Sampling rate used in this frame.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef void toxav_audio_receive_frame_cb(ToxAV *av, uint32_t friend_number, const int16_t *pcm, size_t sample_count,
|
typedef void toxav_audio_receive_frame_cb(ToxAV *av, uint32_t friend_number, const int16_t pcm[], size_t sample_count,
|
||||||
uint8_t channels, uint32_t sampling_rate, void *user_data);
|
uint8_t channels, uint32_t sampling_rate, void *user_data);
|
||||||
|
|
||||||
|
|
||||||
@@ -735,8 +741,13 @@ void toxav_callback_audio_receive_frame(ToxAV *av, toxav_audio_receive_frame_cb
|
|||||||
* @param ustride U chroma plane stride.
|
* @param ustride U chroma plane stride.
|
||||||
* @param vstride V chroma plane stride.
|
* @param vstride V chroma plane stride.
|
||||||
*/
|
*/
|
||||||
typedef void toxav_video_receive_frame_cb(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height,
|
typedef void toxav_video_receive_frame_cb(
|
||||||
const uint8_t *y, const uint8_t *u, const uint8_t *v, int32_t ystride, int32_t ustride, int32_t vstride,
|
ToxAV *av, uint32_t friend_number,
|
||||||
|
uint16_t width, uint16_t height,
|
||||||
|
const uint8_t y[/*! max(width, abs(ystride)) * height */],
|
||||||
|
const uint8_t u[/*! max(width/2, abs(ustride)) * (height/2) */],
|
||||||
|
const uint8_t v[/*! max(width/2, abs(vstride)) * (height/2) */],
|
||||||
|
int32_t ystride, int32_t ustride, int32_t vstride,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
|
|
||||||
@@ -746,6 +757,8 @@ typedef void toxav_video_receive_frame_cb(ToxAV *av, uint32_t friend_number, uin
|
|||||||
*/
|
*/
|
||||||
void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb *callback, void *user_data);
|
void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb *callback, void *user_data);
|
||||||
|
|
||||||
|
#ifndef APIGEN_IGNORE
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* NOTE Compatibility with old toxav group calls. TODO(iphydf): remove
|
* NOTE Compatibility with old toxav group calls. TODO(iphydf): remove
|
||||||
*
|
*
|
||||||
@@ -755,10 +768,10 @@ void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO(iphydf): Use this better typed one instead of the void-pointer one below.
|
// TODO(iphydf): Use this better typed one instead of the void-pointer one below.
|
||||||
typedef void toxav_group_audio_cb(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm,
|
typedef void toxav_group_audio_cb(Tox *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t pcm[],
|
||||||
uint32_t samples, uint8_t channels, uint32_t sample_rate, void *user_data);
|
uint32_t samples, uint8_t channels, uint32_t sample_rate, void *user_data);
|
||||||
|
|
||||||
typedef void toxav_audio_data_cb(void *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t *pcm,
|
typedef void toxav_audio_data_cb(void *tox, uint32_t groupnumber, uint32_t peernumber, const int16_t pcm[],
|
||||||
uint32_t samples, uint8_t channels, uint32_t sample_rate, void *userdata);
|
uint32_t samples, uint8_t channels, uint32_t sample_rate, void *userdata);
|
||||||
|
|
||||||
/** @brief Create a new toxav group.
|
/** @brief Create a new toxav group.
|
||||||
@@ -768,7 +781,7 @@ typedef void toxav_audio_data_cb(void *tox, uint32_t groupnumber, uint32_t peern
|
|||||||
*
|
*
|
||||||
* Note that total size of pcm in bytes is equal to `samples * channels * sizeof(int16_t)`.
|
* Note that total size of pcm in bytes is equal to `samples * channels * sizeof(int16_t)`.
|
||||||
*/
|
*/
|
||||||
int toxav_add_av_groupchat(Tox *tox, toxav_audio_data_cb *audio_callback, void *userdata);
|
int32_t toxav_add_av_groupchat(Tox *tox, toxav_audio_data_cb *audio_callback, void *userdata);
|
||||||
|
|
||||||
/** @brief Join a AV group (you need to have been invited first).
|
/** @brief Join a AV group (you need to have been invited first).
|
||||||
*
|
*
|
||||||
@@ -777,8 +790,9 @@ int toxav_add_av_groupchat(Tox *tox, toxav_audio_data_cb *audio_callback, void *
|
|||||||
*
|
*
|
||||||
* Note that total size of pcm in bytes is equal to `samples * channels * sizeof(int16_t)`.
|
* Note that total size of pcm in bytes is equal to `samples * channels * sizeof(int16_t)`.
|
||||||
*/
|
*/
|
||||||
int toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t *data, uint16_t length,
|
int32_t toxav_join_av_groupchat(
|
||||||
toxav_audio_data_cb *audio_callback, void *userdata);
|
Tox *tox, uint32_t friendnumber, const uint8_t data[], uint16_t length,
|
||||||
|
toxav_audio_data_cb *audio_callback, void *userdata);
|
||||||
|
|
||||||
/** @brief Send audio to the group chat.
|
/** @brief Send audio to the group chat.
|
||||||
*
|
*
|
||||||
@@ -794,8 +808,9 @@ int toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t *data
|
|||||||
*
|
*
|
||||||
* Recommended values are: samples = 960, channels = 1, sample_rate = 48000
|
* Recommended values are: samples = 960, channels = 1, sample_rate = 48000
|
||||||
*/
|
*/
|
||||||
int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels,
|
int32_t toxav_group_send_audio(
|
||||||
uint32_t sample_rate);
|
Tox *tox, uint32_t groupnumber, const int16_t pcm[], uint32_t samples, uint8_t channels,
|
||||||
|
uint32_t sample_rate);
|
||||||
|
|
||||||
/** @brief Enable A/V in a groupchat.
|
/** @brief Enable A/V in a groupchat.
|
||||||
*
|
*
|
||||||
@@ -812,19 +827,22 @@ int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, u
|
|||||||
*
|
*
|
||||||
* Note that total size of pcm in bytes is equal to `samples * channels * sizeof(int16_t)`.
|
* Note that total size of pcm in bytes is equal to `samples * channels * sizeof(int16_t)`.
|
||||||
*/
|
*/
|
||||||
int toxav_groupchat_enable_av(Tox *tox, uint32_t groupnumber,
|
int32_t toxav_groupchat_enable_av(
|
||||||
toxav_audio_data_cb *audio_callback, void *userdata);
|
Tox *tox, uint32_t groupnumber,
|
||||||
|
toxav_audio_data_cb *audio_callback, void *userdata);
|
||||||
|
|
||||||
/** @brief Disable A/V in a groupchat.
|
/** @brief Disable A/V in a groupchat.
|
||||||
*
|
*
|
||||||
* @retval 0 on success.
|
* @retval 0 on success.
|
||||||
* @retval -1 on failure.
|
* @retval -1 on failure.
|
||||||
*/
|
*/
|
||||||
int toxav_groupchat_disable_av(Tox *tox, uint32_t groupnumber);
|
int32_t toxav_groupchat_disable_av(Tox *tox, uint32_t groupnumber);
|
||||||
|
|
||||||
/** @brief Return whether A/V is enabled in the groupchat. */
|
/** @brief Return whether A/V is enabled in the groupchat. */
|
||||||
bool toxav_groupchat_av_enabled(Tox *tox, uint32_t groupnumber);
|
bool toxav_groupchat_av_enabled(Tox *tox, uint32_t groupnumber);
|
||||||
|
|
||||||
|
#endif /* !APIGEN_IGNORE */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -834,6 +852,7 @@ bool toxav_groupchat_av_enabled(Tox *tox, uint32_t groupnumber);
|
|||||||
//!TOKSTYLE-
|
//!TOKSTYLE-
|
||||||
#ifndef DOXYGEN_IGNORE
|
#ifndef DOXYGEN_IGNORE
|
||||||
|
|
||||||
|
typedef ToxAV Toxav;
|
||||||
typedef Toxav_Err_Call TOXAV_ERR_CALL;
|
typedef Toxav_Err_Call TOXAV_ERR_CALL;
|
||||||
typedef Toxav_Err_New TOXAV_ERR_NEW;
|
typedef Toxav_Err_New TOXAV_ERR_NEW;
|
||||||
typedef Toxav_Err_Answer TOXAV_ERR_ANSWER;
|
typedef Toxav_Err_Answer TOXAV_ERR_ANSWER;
|
||||||
|
5
external/toxcore/c-toxcore/toxav/video.c
vendored
5
external/toxcore/c-toxcore/toxav/video.c
vendored
@@ -345,17 +345,18 @@ void vc_iterate(VCSession *vc)
|
|||||||
|
|
||||||
int vc_queue_message(Mono_Time *mono_time, void *vcp, struct RTPMessage *msg)
|
int vc_queue_message(Mono_Time *mono_time, void *vcp, struct RTPMessage *msg)
|
||||||
{
|
{
|
||||||
|
VCSession *vc = (VCSession *)vcp;
|
||||||
|
|
||||||
/* This function is called with complete messages
|
/* This function is called with complete messages
|
||||||
* they have already been assembled.
|
* they have already been assembled.
|
||||||
* this function gets called from handle_rtp_packet() and handle_rtp_packet_v3()
|
* this function gets called from handle_rtp_packet() and handle_rtp_packet_v3()
|
||||||
*/
|
*/
|
||||||
if (vcp == nullptr || msg == nullptr) {
|
if (vc == nullptr || msg == nullptr) {
|
||||||
free(msg);
|
free(msg);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VCSession *vc = (VCSession *)vcp;
|
|
||||||
const struct RTPHeader *const header = &msg->header;
|
const struct RTPHeader *const header = &msg->header;
|
||||||
|
|
||||||
if (msg->header.pt == (RTP_TYPE_VIDEO + 2) % 128) {
|
if (msg->header.pt == (RTP_TYPE_VIDEO + 2) % 128) {
|
||||||
|
56
external/toxcore/c-toxcore/toxcore/BUILD.bazel
vendored
56
external/toxcore/c-toxcore/toxcore/BUILD.bazel
vendored
@@ -10,6 +10,23 @@ exports_files(
|
|||||||
visibility = ["//c-toxcore:__pkg__"],
|
visibility = ["//c-toxcore:__pkg__"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "test_util",
|
||||||
|
srcs = ["test_util.cc"],
|
||||||
|
hdrs = ["test_util.hh"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_test(
|
||||||
|
name = "test_util_test",
|
||||||
|
size = "small",
|
||||||
|
srcs = ["test_util_test.cc"],
|
||||||
|
deps = [
|
||||||
|
":crypto_core_test_util",
|
||||||
|
"@com_google_googletest//:gtest",
|
||||||
|
"@com_google_googletest//:gtest_main",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "attributes",
|
name = "attributes",
|
||||||
hdrs = ["attributes.h"],
|
hdrs = ["attributes.h"],
|
||||||
@@ -71,6 +88,7 @@ cc_test(
|
|||||||
srcs = ["util_test.cc"],
|
srcs = ["util_test.cc"],
|
||||||
deps = [
|
deps = [
|
||||||
":crypto_core",
|
":crypto_core",
|
||||||
|
":crypto_core_test_util",
|
||||||
":util",
|
":util",
|
||||||
"@com_google_googletest//:gtest",
|
"@com_google_googletest//:gtest",
|
||||||
"@com_google_googletest//:gtest_main",
|
"@com_google_googletest//:gtest_main",
|
||||||
@@ -142,6 +160,16 @@ cc_library(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "crypto_core_test_util",
|
||||||
|
srcs = ["crypto_core_test_util.cc"],
|
||||||
|
hdrs = ["crypto_core_test_util.hh"],
|
||||||
|
deps = [
|
||||||
|
":crypto_core",
|
||||||
|
":test_util",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
cc_test(
|
cc_test(
|
||||||
name = "crypto_core_test",
|
name = "crypto_core_test",
|
||||||
size = "small",
|
size = "small",
|
||||||
@@ -149,6 +177,7 @@ cc_test(
|
|||||||
flaky = True,
|
flaky = True,
|
||||||
deps = [
|
deps = [
|
||||||
":crypto_core",
|
":crypto_core",
|
||||||
|
":crypto_core_test_util",
|
||||||
":util",
|
":util",
|
||||||
"@com_google_googletest//:gtest",
|
"@com_google_googletest//:gtest",
|
||||||
"@com_google_googletest//:gtest_main",
|
"@com_google_googletest//:gtest_main",
|
||||||
@@ -261,6 +290,17 @@ cc_library(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "network_test_util",
|
||||||
|
srcs = ["network_test_util.cc"],
|
||||||
|
hdrs = ["network_test_util.hh"],
|
||||||
|
deps = [
|
||||||
|
":crypto_core",
|
||||||
|
":network",
|
||||||
|
":test_util",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
cc_test(
|
cc_test(
|
||||||
name = "network_test",
|
name = "network_test",
|
||||||
size = "small",
|
size = "small",
|
||||||
@@ -357,13 +397,28 @@ cc_library(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "DHT_test_util",
|
||||||
|
srcs = ["DHT_test_util.cc"],
|
||||||
|
hdrs = ["DHT_test_util.hh"],
|
||||||
|
deps = [
|
||||||
|
":DHT",
|
||||||
|
":crypto_core",
|
||||||
|
":crypto_core_test_util",
|
||||||
|
":network_test_util",
|
||||||
|
":test_util",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
cc_test(
|
cc_test(
|
||||||
name = "DHT_test",
|
name = "DHT_test",
|
||||||
size = "small",
|
size = "small",
|
||||||
srcs = ["DHT_test.cc"],
|
srcs = ["DHT_test.cc"],
|
||||||
deps = [
|
deps = [
|
||||||
":DHT",
|
":DHT",
|
||||||
|
":DHT_test_util",
|
||||||
":crypto_core",
|
":crypto_core",
|
||||||
|
":network_test_util",
|
||||||
"@com_google_googletest//:gtest",
|
"@com_google_googletest//:gtest",
|
||||||
"@com_google_googletest//:gtest_main",
|
"@com_google_googletest//:gtest_main",
|
||||||
],
|
],
|
||||||
@@ -881,6 +936,7 @@ cc_fuzz_test(
|
|||||||
srcs = ["tox_events_fuzz_test.cc"],
|
srcs = ["tox_events_fuzz_test.cc"],
|
||||||
corpus = ["//tools/toktok-fuzzer/corpus:tox_events_fuzz_test"],
|
corpus = ["//tools/toktok-fuzzer/corpus:tox_events_fuzz_test"],
|
||||||
deps = [
|
deps = [
|
||||||
|
":tox_dispatch",
|
||||||
":tox_events",
|
":tox_events",
|
||||||
"//c-toxcore/testing/fuzzing:fuzz_support",
|
"//c-toxcore/testing/fuzzing:fuzz_support",
|
||||||
],
|
],
|
||||||
|
108
external/toxcore/c-toxcore/toxcore/DHT.c
vendored
108
external/toxcore/c-toxcore/toxcore/DHT.c
vendored
@@ -16,13 +16,15 @@
|
|||||||
#include "LAN_discovery.h"
|
#include "LAN_discovery.h"
|
||||||
#include "bin_pack.h"
|
#include "bin_pack.h"
|
||||||
#include "ccompat.h"
|
#include "ccompat.h"
|
||||||
|
#include "crypto_core.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "mem.h"
|
||||||
#include "mono_time.h"
|
#include "mono_time.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "ping.h"
|
#include "ping.h"
|
||||||
|
#include "ping_array.h"
|
||||||
#include "shared_key_cache.h"
|
#include "shared_key_cache.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "util.h"
|
|
||||||
|
|
||||||
/** The timeout after which a node is discarded completely. */
|
/** The timeout after which a node is discarded completely. */
|
||||||
#define KILL_NODE_TIMEOUT (BAD_NODE_TIMEOUT + PING_INTERVAL)
|
#define KILL_NODE_TIMEOUT (BAD_NODE_TIMEOUT + PING_INTERVAL)
|
||||||
@@ -420,7 +422,8 @@ static bool bin_pack_ip_port(Bin_Pack *bp, const Logger *logger, const IP_Port *
|
|||||||
non_null()
|
non_null()
|
||||||
static bool bin_pack_ip_port_handler(Bin_Pack *bp, const Logger *logger, const void *obj)
|
static bool bin_pack_ip_port_handler(Bin_Pack *bp, const Logger *logger, const void *obj)
|
||||||
{
|
{
|
||||||
return bin_pack_ip_port(bp, logger, (const IP_Port *)obj);
|
const IP_Port *ip_port = (const IP_Port *)obj;
|
||||||
|
return bin_pack_ip_port(bp, logger, ip_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pack_ip_port(const Logger *logger, uint8_t *data, uint16_t length, const IP_Port *ip_port)
|
int pack_ip_port(const Logger *logger, uint8_t *data, uint16_t length, const IP_Port *ip_port)
|
||||||
@@ -445,8 +448,8 @@ int dht_create_packet(const Memory *mem, const Random *rng,
|
|||||||
const uint8_t *plain, size_t plain_length,
|
const uint8_t *plain, size_t plain_length,
|
||||||
uint8_t *packet, size_t length)
|
uint8_t *packet, size_t length)
|
||||||
{
|
{
|
||||||
uint8_t *encrypted = (uint8_t *)mem_balloc(mem, plain_length + CRYPTO_MAC_SIZE);
|
|
||||||
uint8_t nonce[CRYPTO_NONCE_SIZE];
|
uint8_t nonce[CRYPTO_NONCE_SIZE];
|
||||||
|
uint8_t *encrypted = (uint8_t *)mem_balloc(mem, plain_length + CRYPTO_MAC_SIZE);
|
||||||
|
|
||||||
if (encrypted == nullptr) {
|
if (encrypted == nullptr) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -508,7 +511,7 @@ int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ip_port = empty_ip_port;
|
ipport_reset(ip_port);
|
||||||
|
|
||||||
if (is_ipv4) {
|
if (is_ipv4) {
|
||||||
const uint32_t size = 1 + SIZE_IP4 + sizeof(uint16_t);
|
const uint32_t size = 1 + SIZE_IP4 + sizeof(uint16_t);
|
||||||
@@ -747,16 +750,21 @@ static bool client_or_ip_port_in_list(const Logger *log, const Mono_Time *mono_t
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool add_to_list(Node_format *nodes_list, uint32_t length, const uint8_t *pk, const IP_Port *ip_port,
|
bool add_to_list(
|
||||||
const uint8_t *cmp_pk)
|
Node_format *nodes_list, uint32_t length, const uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE],
|
||||||
|
const IP_Port *ip_port, const uint8_t cmp_pk[CRYPTO_PUBLIC_KEY_SIZE])
|
||||||
{
|
{
|
||||||
for (uint32_t i = 0; i < length; ++i) {
|
for (uint32_t i = 0; i < length; ++i) {
|
||||||
if (id_closest(cmp_pk, nodes_list[i].public_key, pk) == 2) {
|
Node_format *node = &nodes_list[i];
|
||||||
|
|
||||||
|
if (id_closest(cmp_pk, node->public_key, pk) == 2) {
|
||||||
uint8_t pk_bak[CRYPTO_PUBLIC_KEY_SIZE];
|
uint8_t pk_bak[CRYPTO_PUBLIC_KEY_SIZE];
|
||||||
memcpy(pk_bak, nodes_list[i].public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
memcpy(pk_bak, node->public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||||
const IP_Port ip_port_bak = nodes_list[i].ip_port;
|
|
||||||
memcpy(nodes_list[i].public_key, pk, CRYPTO_PUBLIC_KEY_SIZE);
|
const IP_Port ip_port_bak = node->ip_port;
|
||||||
nodes_list[i].ip_port = *ip_port;
|
memcpy(node->public_key, pk, CRYPTO_PUBLIC_KEY_SIZE);
|
||||||
|
|
||||||
|
node->ip_port = *ip_port;
|
||||||
|
|
||||||
if (i != length - 1) {
|
if (i != length - 1) {
|
||||||
add_to_list(nodes_list, length, pk_bak, &ip_port_bak, cmp_pk);
|
add_to_list(nodes_list, length, pk_bak, &ip_port_bak, cmp_pk);
|
||||||
@@ -773,10 +781,11 @@ bool add_to_list(Node_format *nodes_list, uint32_t length, const uint8_t *pk, co
|
|||||||
* helper for `get_close_nodes()`. argument list is a monster :D
|
* helper for `get_close_nodes()`. argument list is a monster :D
|
||||||
*/
|
*/
|
||||||
non_null()
|
non_null()
|
||||||
static void get_close_nodes_inner(uint64_t cur_time, const uint8_t *public_key, Node_format *nodes_list,
|
static void get_close_nodes_inner(
|
||||||
Family sa_family, const Client_data *client_list, uint32_t client_list_length,
|
uint64_t cur_time, const uint8_t *public_key,
|
||||||
uint32_t *num_nodes_ptr, bool is_lan,
|
Node_format *nodes_list, uint32_t *num_nodes_ptr,
|
||||||
bool want_announce)
|
Family sa_family, const Client_data *client_list, uint32_t client_list_length,
|
||||||
|
bool is_lan, bool want_announce)
|
||||||
{
|
{
|
||||||
if (!net_family_is_ipv4(sa_family) && !net_family_is_ipv6(sa_family) && !net_family_is_unspec(sa_family)) {
|
if (!net_family_is_ipv4(sa_family) && !net_family_is_ipv6(sa_family) && !net_family_is_unspec(sa_family)) {
|
||||||
return;
|
return;
|
||||||
@@ -843,28 +852,44 @@ static void get_close_nodes_inner(uint64_t cur_time, const uint8_t *public_key,
|
|||||||
* want_announce: return only nodes which implement the dht announcements protocol.
|
* want_announce: return only nodes which implement the dht announcements protocol.
|
||||||
*/
|
*/
|
||||||
non_null()
|
non_null()
|
||||||
static int get_somewhat_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list,
|
static int get_somewhat_close_nodes(
|
||||||
Family sa_family, bool is_lan, bool want_announce)
|
uint64_t cur_time, const uint8_t *public_key, Node_format *nodes_list,
|
||||||
|
Family sa_family, const Client_data *close_clientlist,
|
||||||
|
const DHT_Friend *friends_list, uint16_t friends_list_size,
|
||||||
|
bool is_lan, bool want_announce)
|
||||||
{
|
{
|
||||||
uint32_t num_nodes = 0;
|
memset(nodes_list, 0, MAX_SENT_NODES * sizeof(Node_format));
|
||||||
get_close_nodes_inner(dht->cur_time, public_key, nodes_list, sa_family,
|
|
||||||
dht->close_clientlist, LCLIENT_LIST, &num_nodes, is_lan, want_announce);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < dht->num_friends; ++i) {
|
uint32_t num_nodes = 0;
|
||||||
get_close_nodes_inner(dht->cur_time, public_key, nodes_list, sa_family,
|
get_close_nodes_inner(
|
||||||
dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS,
|
cur_time, public_key,
|
||||||
&num_nodes, is_lan, want_announce);
|
nodes_list, &num_nodes,
|
||||||
|
sa_family, close_clientlist, LCLIENT_LIST,
|
||||||
|
is_lan, want_announce);
|
||||||
|
|
||||||
|
for (uint16_t i = 0; i < friends_list_size; ++i) {
|
||||||
|
const DHT_Friend *dht_friend = &friends_list[i];
|
||||||
|
|
||||||
|
get_close_nodes_inner(
|
||||||
|
cur_time, public_key,
|
||||||
|
nodes_list, &num_nodes,
|
||||||
|
sa_family, dht_friend->client_list, MAX_FRIEND_CLIENTS,
|
||||||
|
is_lan, want_announce);
|
||||||
}
|
}
|
||||||
|
|
||||||
return num_nodes;
|
return num_nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, Family sa_family,
|
int get_close_nodes(
|
||||||
bool is_lan, bool want_announce)
|
const DHT *dht, const uint8_t *public_key,
|
||||||
|
Node_format *nodes_list, Family sa_family,
|
||||||
|
bool is_lan, bool want_announce)
|
||||||
{
|
{
|
||||||
memset(nodes_list, 0, MAX_SENT_NODES * sizeof(Node_format));
|
return get_somewhat_close_nodes(
|
||||||
return get_somewhat_close_nodes(dht, public_key, nodes_list, sa_family,
|
dht->cur_time, public_key, nodes_list,
|
||||||
is_lan, want_announce);
|
sa_family, dht->close_clientlist,
|
||||||
|
dht->friends_list, dht->num_friends,
|
||||||
|
is_lan, want_announce);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct DHT_Cmp_Data {
|
typedef struct DHT_Cmp_Data {
|
||||||
@@ -1477,12 +1502,12 @@ static int sendnodes_ipv6(const DHT *dht, const IP_Port *ip_port, const uint8_t
|
|||||||
non_null()
|
non_null()
|
||||||
static int handle_getnodes(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
|
static int handle_getnodes(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
|
||||||
{
|
{
|
||||||
|
DHT *const dht = (DHT *)object;
|
||||||
|
|
||||||
if (length != (CRYPTO_SIZE + CRYPTO_MAC_SIZE + sizeof(uint64_t))) {
|
if (length != (CRYPTO_SIZE + CRYPTO_MAC_SIZE + sizeof(uint64_t))) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DHT *const dht = (DHT *)object;
|
|
||||||
|
|
||||||
/* Check if packet is from ourself. */
|
/* Check if packet is from ourself. */
|
||||||
if (pk_equal(packet + 1, dht->self_public_key)) {
|
if (pk_equal(packet + 1, dht->self_public_key)) {
|
||||||
return 1;
|
return 1;
|
||||||
@@ -2263,11 +2288,12 @@ non_null()
|
|||||||
static int handle_nat_ping(void *object, const IP_Port *source, const uint8_t *source_pubkey, const uint8_t *packet,
|
static int handle_nat_ping(void *object, const IP_Port *source, const uint8_t *source_pubkey, const uint8_t *packet,
|
||||||
uint16_t length, void *userdata)
|
uint16_t length, void *userdata)
|
||||||
{
|
{
|
||||||
|
DHT *const dht = (DHT *)object;
|
||||||
|
|
||||||
if (length != sizeof(uint64_t) + 1) {
|
if (length != sizeof(uint64_t) + 1) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DHT *const dht = (DHT *)object;
|
|
||||||
uint64_t ping_id;
|
uint64_t ping_id;
|
||||||
memcpy(&ping_id, packet + 1, sizeof(uint64_t));
|
memcpy(&ping_id, packet + 1, sizeof(uint64_t));
|
||||||
|
|
||||||
@@ -2899,23 +2925,27 @@ static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *dat
|
|||||||
}
|
}
|
||||||
|
|
||||||
mem_delete(dht->mem, dht->loaded_nodes_list);
|
mem_delete(dht->mem, dht->loaded_nodes_list);
|
||||||
// Copy to loaded_clients_list
|
|
||||||
dht->loaded_nodes_list = (Node_format *)mem_valloc(dht->mem, MAX_SAVED_DHT_NODES, sizeof(Node_format));
|
|
||||||
|
|
||||||
if (dht->loaded_nodes_list == nullptr) {
|
// Copy to loaded_clients_list
|
||||||
|
Node_format *nodes = (Node_format *)mem_valloc(dht->mem, MAX_SAVED_DHT_NODES, sizeof(Node_format));
|
||||||
|
|
||||||
|
if (nodes == nullptr) {
|
||||||
LOGGER_ERROR(dht->log, "could not allocate %u nodes", MAX_SAVED_DHT_NODES);
|
LOGGER_ERROR(dht->log, "could not allocate %u nodes", MAX_SAVED_DHT_NODES);
|
||||||
dht->loaded_num_nodes = 0;
|
dht->loaded_num_nodes = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, nullptr, data, length, false);
|
const int num = unpack_nodes(nodes, MAX_SAVED_DHT_NODES, nullptr, data, length, false);
|
||||||
|
|
||||||
if (num > 0) {
|
if (num < 0) {
|
||||||
dht->loaded_num_nodes = num;
|
// Unpack error happened, we ignore it.
|
||||||
} else {
|
|
||||||
dht->loaded_num_nodes = 0;
|
dht->loaded_num_nodes = 0;
|
||||||
|
} else {
|
||||||
|
dht->loaded_num_nodes = num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dht->loaded_nodes_list = nodes;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
external/toxcore/c-toxcore/toxcore/DHT.h
vendored
19
external/toxcore/c-toxcore/toxcore/DHT.h
vendored
@@ -232,7 +232,7 @@ int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool
|
|||||||
non_null()
|
non_null()
|
||||||
int dht_create_packet(const Memory *mem, const Random *rng,
|
int dht_create_packet(const Memory *mem, const Random *rng,
|
||||||
const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
|
const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
|
||||||
const uint8_t *shared_key, const uint8_t type,
|
const uint8_t *shared_key, uint8_t type,
|
||||||
const uint8_t *plain, size_t plain_length,
|
const uint8_t *plain, size_t plain_length,
|
||||||
uint8_t *packet, size_t length);
|
uint8_t *packet, size_t length);
|
||||||
|
|
||||||
@@ -370,7 +370,8 @@ unsigned int bit_by_bit_cmp(const uint8_t *pk1, const uint8_t *pk2);
|
|||||||
*/
|
*/
|
||||||
non_null()
|
non_null()
|
||||||
bool add_to_list(
|
bool add_to_list(
|
||||||
Node_format *nodes_list, uint32_t length, const uint8_t *pk, const IP_Port *ip_port, const uint8_t *cmp_pk);
|
Node_format *nodes_list, uint32_t length, const uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE],
|
||||||
|
const IP_Port *ip_port, const uint8_t cmp_pk[CRYPTO_PUBLIC_KEY_SIZE]);
|
||||||
|
|
||||||
/** Return 1 if node can be added to close list, 0 if it can't. */
|
/** Return 1 if node can be added to close list, 0 if it can't. */
|
||||||
non_null()
|
non_null()
|
||||||
@@ -383,18 +384,20 @@ void set_announce_node(DHT *dht, const uint8_t *public_key);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the (maximum MAX_SENT_NODES) closest nodes to public_key we know
|
* @brief Get the (maximum MAX_SENT_NODES) closest nodes to public_key we know
|
||||||
* and put them in nodes_list (must be MAX_SENT_NODES big).
|
* and put them in nodes_list (must be MAX_SENT_NODES big).
|
||||||
*
|
*
|
||||||
* sa_family = family (IPv4 or IPv6) (0 if we don't care)?
|
* @param sa_family family (IPv4 or IPv6) (0 if we don't care)?
|
||||||
* is_LAN = return some LAN ips (true or false)
|
* @param is_lan return some LAN ips (true or false).
|
||||||
* want_announce: return only nodes which implement the dht announcements protocol.
|
* @param want_announce return only nodes which implement the dht announcements protocol.
|
||||||
*
|
*
|
||||||
* @return the number of nodes returned.
|
* @return the number of nodes returned.
|
||||||
*/
|
*/
|
||||||
non_null()
|
non_null()
|
||||||
int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, Family sa_family,
|
int get_close_nodes(
|
||||||
bool is_lan, bool want_announce);
|
const DHT *dht, const uint8_t *public_key,
|
||||||
|
Node_format *nodes_list, Family sa_family,
|
||||||
|
bool is_lan, bool want_announce);
|
||||||
|
|
||||||
|
|
||||||
/** @brief Put up to max_num nodes in nodes from the random friends.
|
/** @brief Put up to max_num nodes in nodes from the random friends.
|
||||||
|
@@ -23,7 +23,7 @@ void TestHandleRequest(Fuzz_Data &input)
|
|||||||
|
|
||||||
void TestUnpackNodes(Fuzz_Data &input)
|
void TestUnpackNodes(Fuzz_Data &input)
|
||||||
{
|
{
|
||||||
CONSUME1_OR_RETURN(const bool tcp_enabled, input);
|
CONSUME1_OR_RETURN(const bool, tcp_enabled, input);
|
||||||
|
|
||||||
const uint16_t node_count = 5;
|
const uint16_t node_count = 5;
|
||||||
Node_format nodes[node_count];
|
Node_format nodes[node_count];
|
||||||
|
262
external/toxcore/c-toxcore/toxcore/DHT_test.cc
vendored
262
external/toxcore/c-toxcore/toxcore/DHT_test.cc
vendored
@@ -1,15 +1,26 @@
|
|||||||
#include "DHT.h"
|
#include "DHT.h"
|
||||||
|
|
||||||
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <cstring>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
|
#include "DHT_test_util.hh"
|
||||||
#include "crypto_core.h"
|
#include "crypto_core.h"
|
||||||
|
#include "crypto_core_test_util.hh"
|
||||||
|
#include "network_test_util.hh"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using PublicKey = std::array<uint8_t, CRYPTO_PUBLIC_KEY_SIZE>;
|
using ::testing::Each;
|
||||||
|
using ::testing::ElementsAre;
|
||||||
|
using ::testing::Eq;
|
||||||
|
using ::testing::PrintToString;
|
||||||
|
using ::testing::UnorderedElementsAre;
|
||||||
|
|
||||||
using SecretKey = std::array<uint8_t, CRYPTO_SECRET_KEY_SIZE>;
|
using SecretKey = std::array<uint8_t, CRYPTO_SECRET_KEY_SIZE>;
|
||||||
|
|
||||||
struct KeyPair {
|
struct KeyPair {
|
||||||
@@ -19,72 +30,66 @@ struct KeyPair {
|
|||||||
explicit KeyPair(const Random *rng) { crypto_new_keypair(rng, pk.data(), sk.data()); }
|
explicit KeyPair(const Random *rng) { crypto_new_keypair(rng, pk.data(), sk.data()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, size_t N>
|
TEST(IdClosest, KeyIsClosestToItself)
|
||||||
std::array<T, N> to_array(T const (&arr)[N])
|
|
||||||
{
|
{
|
||||||
std::array<T, N> stdarr;
|
Test_Random rng;
|
||||||
std::copy(arr, arr + N, stdarr.begin());
|
|
||||||
return stdarr;
|
|
||||||
}
|
|
||||||
|
|
||||||
PublicKey random_pk(const Random *rng)
|
PublicKey pk0 = random_pk(rng);
|
||||||
{
|
PublicKey pk1;
|
||||||
PublicKey pk;
|
do {
|
||||||
random_bytes(rng, pk.data(), pk.size());
|
// Get a random key that's not the same as pk0.
|
||||||
return pk;
|
pk1 = random_pk(rng);
|
||||||
|
} while (pk0 == pk1);
|
||||||
|
|
||||||
|
EXPECT_EQ(id_closest(pk0.data(), pk0.data(), pk1.data()), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(IdClosest, IdenticalKeysAreSameDistance)
|
TEST(IdClosest, IdenticalKeysAreSameDistance)
|
||||||
{
|
{
|
||||||
const Random *rng = system_random();
|
Test_Random rng;
|
||||||
ASSERT_NE(rng, nullptr);
|
|
||||||
|
|
||||||
PublicKey pk0 = random_pk(rng);
|
PublicKey pk0 = random_pk(rng);
|
||||||
PublicKey pk1 = random_pk(rng);
|
PublicKey pk1 = random_pk(rng);
|
||||||
PublicKey pk2 = pk1;
|
|
||||||
|
|
||||||
EXPECT_EQ(id_closest(pk0.data(), pk1.data(), pk2.data()), 0);
|
EXPECT_EQ(id_closest(pk0.data(), pk1.data(), pk1.data()), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(IdClosest, DistanceIsCommutative)
|
TEST(IdClosest, DistanceIsCommutative)
|
||||||
{
|
{
|
||||||
const Random *rng = system_random();
|
Test_Random rng;
|
||||||
ASSERT_NE(rng, nullptr);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < 100; ++i) {
|
PublicKey pk0 = random_pk(rng);
|
||||||
PublicKey pk0 = random_pk(rng);
|
PublicKey pk1 = random_pk(rng);
|
||||||
PublicKey pk1 = random_pk(rng);
|
PublicKey pk2 = random_pk(rng);
|
||||||
PublicKey pk2 = random_pk(rng);
|
|
||||||
|
|
||||||
ASSERT_NE(pk1, pk2); // RNG can't produce the same random key twice
|
ASSERT_NE(pk1, pk2); // RNG can't produce the same random key twice
|
||||||
|
|
||||||
// Two non-equal keys can't have the same distance from any given key.
|
// Two non-equal keys can't have the same distance from any given key.
|
||||||
EXPECT_NE(id_closest(pk0.data(), pk1.data(), pk2.data()), 0);
|
EXPECT_NE(id_closest(pk0.data(), pk1.data(), pk2.data()), 0);
|
||||||
|
|
||||||
if (id_closest(pk0.data(), pk1.data(), pk2.data()) == 1) {
|
if (id_closest(pk0.data(), pk1.data(), pk2.data()) == 1) {
|
||||||
EXPECT_EQ(id_closest(pk0.data(), pk2.data(), pk1.data()), 2);
|
EXPECT_EQ(id_closest(pk0.data(), pk2.data(), pk1.data()), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id_closest(pk0.data(), pk1.data(), pk2.data()) == 2) {
|
if (id_closest(pk0.data(), pk1.data(), pk2.data()) == 2) {
|
||||||
EXPECT_EQ(id_closest(pk0.data(), pk2.data(), pk1.data()), 1);
|
EXPECT_EQ(id_closest(pk0.data(), pk2.data(), pk1.data()), 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(IdClosest, SmallXorDistanceIsCloser)
|
TEST(IdClosest, SmallXorDistanceIsCloser)
|
||||||
{
|
{
|
||||||
PublicKey const pk0 = {{0xaa}};
|
PublicKey const pk0 = {0xaa};
|
||||||
PublicKey const pk1 = {{0xa0}};
|
PublicKey const pk1 = {0xa0};
|
||||||
PublicKey const pk2 = {{0x0a}};
|
PublicKey const pk2 = {0x0a};
|
||||||
|
|
||||||
EXPECT_EQ(id_closest(pk0.data(), pk1.data(), pk2.data()), 1);
|
EXPECT_EQ(id_closest(pk0.data(), pk1.data(), pk2.data()), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(IdClosest, DistinctKeysCannotHaveTheSameDistance)
|
TEST(IdClosest, DistinctKeysCannotHaveTheSameDistance)
|
||||||
{
|
{
|
||||||
PublicKey const pk0 = {{0x06}};
|
PublicKey const pk0 = {0x06};
|
||||||
PublicKey const pk1 = {{0x00}};
|
PublicKey const pk1 = {0x00};
|
||||||
PublicKey pk2 = {{0x00}};
|
PublicKey pk2 = {0x00};
|
||||||
|
|
||||||
for (uint8_t i = 1; i < 0xff; ++i) {
|
for (uint8_t i = 1; i < 0xff; ++i) {
|
||||||
pk2[0] = i;
|
pk2[0] = i;
|
||||||
@@ -94,14 +99,14 @@ TEST(IdClosest, DistinctKeysCannotHaveTheSameDistance)
|
|||||||
|
|
||||||
TEST(AddToList, OverridesKeysWithCloserKeys)
|
TEST(AddToList, OverridesKeysWithCloserKeys)
|
||||||
{
|
{
|
||||||
PublicKey const self_pk = {{0xaa}};
|
PublicKey const self_pk = {0xaa};
|
||||||
PublicKey const keys[] = {
|
PublicKey const keys[] = {
|
||||||
{{0xa0}}, // closest
|
{0xa0}, // closest
|
||||||
{{0x0a}}, //
|
{0x0a}, //
|
||||||
{{0x0b}}, //
|
{0x0b}, //
|
||||||
{{0x0c}}, //
|
{0x0c}, //
|
||||||
{{0x0d}}, //
|
{0x0d}, //
|
||||||
{{0xa1}}, // closer than the 4 keys above
|
{0xa1}, // closer than the 4 keys above
|
||||||
};
|
};
|
||||||
|
|
||||||
std::array<Node_format, 4> nodes{};
|
std::array<Node_format, 4> nodes{};
|
||||||
@@ -128,10 +133,143 @@ TEST(AddToList, OverridesKeysWithCloserKeys)
|
|||||||
EXPECT_EQ(to_array(nodes[3].public_key), keys[2]);
|
EXPECT_EQ(to_array(nodes[3].public_key), keys[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Node_format fill(Node_format v, PublicKey const &pk, IP_Port const &ip_port)
|
||||||
|
{
|
||||||
|
std::copy(pk.begin(), pk.end(), v.public_key);
|
||||||
|
v.ip_port = ip_port;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(AddToList, AddsFirstKeysInOrder)
|
||||||
|
{
|
||||||
|
Test_Random rng;
|
||||||
|
|
||||||
|
// Make cmp_key the furthest away from 00000... as possible, so all initial inserts succeed.
|
||||||
|
PublicKey const cmp_pk{0xff, 0xff, 0xff, 0xff};
|
||||||
|
|
||||||
|
// Generate a bunch of other keys, sorted by distance from cmp_pk.
|
||||||
|
auto const keys
|
||||||
|
= sorted(array_of<20>(random_pk, rng), [&cmp_pk](auto const &pk1, auto const &pk2) {
|
||||||
|
return id_closest(cmp_pk.data(), pk1.data(), pk2.data()) == 1;
|
||||||
|
});
|
||||||
|
auto const ips = array_of<20>(increasing_ip_port(0, rng));
|
||||||
|
|
||||||
|
std::vector<Node_format> nodes(4);
|
||||||
|
|
||||||
|
// Add a bunch of nodes.
|
||||||
|
ASSERT_TRUE(add_to_list(nodes.data(), nodes.size(), keys[2].data(), &ips[2], cmp_pk.data()))
|
||||||
|
<< "failed to insert\n"
|
||||||
|
<< " cmp_pk = " << cmp_pk << "\n"
|
||||||
|
<< " pk = " << keys[2] << "\n"
|
||||||
|
<< " nodes_list = " << PrintToString(nodes);
|
||||||
|
ASSERT_TRUE(add_to_list(nodes.data(), nodes.size(), keys[5].data(), &ips[5], cmp_pk.data()))
|
||||||
|
<< "failed to insert\n"
|
||||||
|
<< " cmp_pk = " << cmp_pk << "\n"
|
||||||
|
<< " pk = " << keys[5] << "\n"
|
||||||
|
<< " nodes_list = " << PrintToString(nodes);
|
||||||
|
ASSERT_TRUE(add_to_list(nodes.data(), nodes.size(), keys[7].data(), &ips[7], cmp_pk.data()))
|
||||||
|
<< "failed to insert\n"
|
||||||
|
<< " cmp_pk = " << cmp_pk << "\n"
|
||||||
|
<< " pk = " << keys[7] << "\n"
|
||||||
|
<< " nodes_list = " << PrintToString(nodes);
|
||||||
|
ASSERT_TRUE(add_to_list(nodes.data(), nodes.size(), keys[9].data(), &ips[9], cmp_pk.data()))
|
||||||
|
<< "failed to insert\n"
|
||||||
|
<< " cmp_pk = " << cmp_pk << "\n"
|
||||||
|
<< " pk = " << keys[9] << "\n"
|
||||||
|
<< " nodes_list = " << PrintToString(nodes);
|
||||||
|
|
||||||
|
// They should all appear in order.
|
||||||
|
EXPECT_THAT(nodes,
|
||||||
|
ElementsAre( //
|
||||||
|
fill(Node_format{}, keys[2], ips[2]), //
|
||||||
|
fill(Node_format{}, keys[5], ips[5]), //
|
||||||
|
fill(Node_format{}, keys[7], ips[7]), //
|
||||||
|
fill(Node_format{}, keys[9], ips[9])));
|
||||||
|
|
||||||
|
// Adding another node that's further away will not happen.
|
||||||
|
ASSERT_FALSE(add_to_list(nodes.data(), nodes.size(), keys[10].data(), &ips[10], cmp_pk.data()))
|
||||||
|
<< "incorrectly inserted\n"
|
||||||
|
<< " cmp_pk = " << cmp_pk << "\n"
|
||||||
|
<< " pk = " << keys[10] << "\n"
|
||||||
|
<< " nodes_list = " << PrintToString(nodes);
|
||||||
|
|
||||||
|
// Now shuffle each time we add a node, which should work fine.
|
||||||
|
std::mt19937 mt_rng;
|
||||||
|
|
||||||
|
// Adding one that's closer will happen.
|
||||||
|
std::shuffle(nodes.begin(), nodes.end(), mt_rng);
|
||||||
|
ASSERT_TRUE(add_to_list(nodes.data(), nodes.size(), keys[8].data(), &ips[8], cmp_pk.data()))
|
||||||
|
<< "failed to insert\n"
|
||||||
|
<< " cmp_pk = " << cmp_pk << "\n"
|
||||||
|
<< " pk = " << keys[8] << "\n"
|
||||||
|
<< " nodes_list = " << PrintToString(nodes);
|
||||||
|
|
||||||
|
EXPECT_THAT(nodes,
|
||||||
|
UnorderedElementsAre( //
|
||||||
|
fill(Node_format{}, keys[2], ips[2]), //
|
||||||
|
fill(Node_format{}, keys[5], ips[5]), //
|
||||||
|
fill(Node_format{}, keys[7], ips[7]), //
|
||||||
|
fill(Node_format{}, keys[8], ips[8])));
|
||||||
|
|
||||||
|
// Adding one that's closer than almost all of them will happen.
|
||||||
|
std::shuffle(nodes.begin(), nodes.end(), mt_rng);
|
||||||
|
ASSERT_TRUE(add_to_list(nodes.data(), nodes.size(), keys[4].data(), &ips[4], cmp_pk.data()))
|
||||||
|
<< "failed to insert\n"
|
||||||
|
<< " cmp_pk = " << cmp_pk << "\n"
|
||||||
|
<< " pk = " << keys[4] << "\n"
|
||||||
|
<< " nodes_list = " << PrintToString(nodes);
|
||||||
|
|
||||||
|
EXPECT_THAT(nodes,
|
||||||
|
UnorderedElementsAre( //
|
||||||
|
fill(Node_format{}, keys[2], ips[2]), //
|
||||||
|
fill(Node_format{}, keys[4], ips[4]), //
|
||||||
|
fill(Node_format{}, keys[5], ips[5]), //
|
||||||
|
fill(Node_format{}, keys[7], ips[7])));
|
||||||
|
|
||||||
|
// Adding one that's closer than all of them will happen.
|
||||||
|
std::shuffle(nodes.begin(), nodes.end(), mt_rng);
|
||||||
|
ASSERT_TRUE(add_to_list(nodes.data(), nodes.size(), keys[1].data(), &ips[1], cmp_pk.data()))
|
||||||
|
<< "failed to insert\n"
|
||||||
|
<< " cmp_pk = " << cmp_pk << "\n"
|
||||||
|
<< " pk = " << keys[1] << "\n"
|
||||||
|
<< " nodes_list = " << PrintToString(nodes);
|
||||||
|
|
||||||
|
EXPECT_THAT(nodes,
|
||||||
|
UnorderedElementsAre( //
|
||||||
|
fill(Node_format{}, keys[1], ips[1]), //
|
||||||
|
fill(Node_format{}, keys[2], ips[2]), //
|
||||||
|
fill(Node_format{}, keys[4], ips[4]), //
|
||||||
|
fill(Node_format{}, keys[5], ips[5])));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(AddToList, KeepsKeysInOrder)
|
||||||
|
{
|
||||||
|
Test_Random rng;
|
||||||
|
|
||||||
|
// Any random cmp_pk should work, as well as the smallest or (approximately) largest pk.
|
||||||
|
for (PublicKey const cmp_pk : {random_pk(rng), PublicKey{0x00}, PublicKey{0xff, 0xff}}) {
|
||||||
|
auto const by_distance = [&cmp_pk](auto const &node1, auto const &node2) {
|
||||||
|
return id_closest(cmp_pk.data(), node1.public_key, node2.public_key) == 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Generate a bunch of other keys, not sorted.
|
||||||
|
auto const nodes = vector_of(16, random_node_format, rng);
|
||||||
|
|
||||||
|
std::vector<Node_format> node_list(4);
|
||||||
|
|
||||||
|
// Add all of them.
|
||||||
|
for (Node_format const &node : nodes) {
|
||||||
|
add_to_list(
|
||||||
|
node_list.data(), node_list.size(), node.public_key, &node.ip_port, cmp_pk.data());
|
||||||
|
// Nodes should always be sorted.
|
||||||
|
EXPECT_THAT(node_list, Eq(sorted(node_list, by_distance)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST(Request, CreateAndParse)
|
TEST(Request, CreateAndParse)
|
||||||
{
|
{
|
||||||
const Random *rng = system_random();
|
Test_Random rng;
|
||||||
ASSERT_NE(rng, nullptr);
|
|
||||||
|
|
||||||
// Peers.
|
// Peers.
|
||||||
const KeyPair sender(rng);
|
const KeyPair sender(rng);
|
||||||
@@ -187,7 +325,7 @@ TEST(Request, CreateAndParse)
|
|||||||
|
|
||||||
TEST(AnnounceNodes, SetAndTest)
|
TEST(AnnounceNodes, SetAndTest)
|
||||||
{
|
{
|
||||||
const Random *rng = system_random();
|
Test_Random rng;
|
||||||
const Network *ns = system_network();
|
const Network *ns = system_network();
|
||||||
const Memory *mem = system_memory();
|
const Memory *mem = system_memory();
|
||||||
|
|
||||||
@@ -195,40 +333,40 @@ TEST(AnnounceNodes, SetAndTest)
|
|||||||
ASSERT_NE(log, nullptr);
|
ASSERT_NE(log, nullptr);
|
||||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||||
ASSERT_NE(mono_time, nullptr);
|
ASSERT_NE(mono_time, nullptr);
|
||||||
Networking_Core *net = new_networking_no_udp(log, mem, ns);
|
Ptr<Networking_Core> net(new_networking_no_udp(log, mem, ns));
|
||||||
ASSERT_NE(net, nullptr);
|
ASSERT_NE(net, nullptr);
|
||||||
DHT *dht = new_dht(log, mem, rng, ns, mono_time, net, true, true);
|
Ptr<DHT> dht(new_dht(log, mem, rng, ns, mono_time, net.get(), true, true));
|
||||||
ASSERT_NE(dht, nullptr);
|
ASSERT_NE(dht, nullptr);
|
||||||
|
|
||||||
uint8_t pk_data[CRYPTO_PUBLIC_KEY_SIZE];
|
uint8_t pk_data[CRYPTO_PUBLIC_KEY_SIZE];
|
||||||
memcpy(pk_data, dht_get_self_public_key(dht), sizeof(pk_data));
|
memcpy(pk_data, dht_get_self_public_key(dht.get()), sizeof(pk_data));
|
||||||
PublicKey self_pk = to_array(pk_data);
|
PublicKey self_pk(to_array(pk_data));
|
||||||
|
|
||||||
PublicKey pk1 = random_pk(rng);
|
PublicKey pk1 = random_pk(rng);
|
||||||
ASSERT_NE(pk1, self_pk);
|
ASSERT_NE(pk1, self_pk);
|
||||||
|
|
||||||
// Test with maximally close key to self
|
// Test with maximally close key to self
|
||||||
pk_data[CRYPTO_PUBLIC_KEY_SIZE - 1] = ~pk_data[CRYPTO_PUBLIC_KEY_SIZE - 1];
|
pk_data[CRYPTO_PUBLIC_KEY_SIZE - 1] = ~pk_data[CRYPTO_PUBLIC_KEY_SIZE - 1];
|
||||||
PublicKey pk2 = to_array(pk_data);
|
PublicKey pk2(to_array(pk_data));
|
||||||
ASSERT_NE(pk2, pk1);
|
ASSERT_NE(pk2, pk1);
|
||||||
|
|
||||||
IP_Port ip_port = {0};
|
IP_Port ip_port = {0};
|
||||||
ip_port.ip.family = net_family_ipv4();
|
ip_port.ip.family = net_family_ipv4();
|
||||||
|
|
||||||
set_announce_node(dht, pk1.data());
|
set_announce_node(dht.get(), pk1.data());
|
||||||
set_announce_node(dht, pk2.data());
|
set_announce_node(dht.get(), pk2.data());
|
||||||
|
|
||||||
EXPECT_TRUE(addto_lists(dht, &ip_port, pk1.data()));
|
EXPECT_TRUE(addto_lists(dht.get(), &ip_port, pk1.data()));
|
||||||
EXPECT_TRUE(addto_lists(dht, &ip_port, pk2.data()));
|
EXPECT_TRUE(addto_lists(dht.get(), &ip_port, pk2.data()));
|
||||||
|
|
||||||
Node_format nodes[MAX_SENT_NODES];
|
Node_format nodes[MAX_SENT_NODES];
|
||||||
EXPECT_EQ(0, get_close_nodes(dht, self_pk.data(), nodes, net_family_unspec(), true, true));
|
EXPECT_EQ(
|
||||||
set_announce_node(dht, pk1.data());
|
0, get_close_nodes(dht.get(), self_pk.data(), nodes, net_family_unspec(), true, true));
|
||||||
set_announce_node(dht, pk2.data());
|
set_announce_node(dht.get(), pk1.data());
|
||||||
EXPECT_EQ(2, get_close_nodes(dht, self_pk.data(), nodes, net_family_unspec(), true, true));
|
set_announce_node(dht.get(), pk2.data());
|
||||||
|
EXPECT_EQ(
|
||||||
|
2, get_close_nodes(dht.get(), self_pk.data(), nodes, net_family_unspec(), true, true));
|
||||||
|
|
||||||
kill_dht(dht);
|
|
||||||
kill_networking(net);
|
|
||||||
mono_time_free(mem, mono_time);
|
mono_time_free(mem, mono_time);
|
||||||
logger_kill(log);
|
logger_kill(log);
|
||||||
}
|
}
|
||||||
|
29
external/toxcore/c-toxcore/toxcore/DHT_test_util.cc
vendored
Normal file
29
external/toxcore/c-toxcore/toxcore/DHT_test_util.cc
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#include "DHT_test_util.hh"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
#include "crypto_core_test_util.hh"
|
||||||
|
#include "network_test_util.hh"
|
||||||
|
|
||||||
|
Node_format random_node_format(const Random *rng)
|
||||||
|
{
|
||||||
|
Node_format node;
|
||||||
|
auto const pk = random_pk(rng);
|
||||||
|
std::copy(pk.begin(), pk.end(), node.public_key);
|
||||||
|
node.ip_port = random_ip_port(rng);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(Node_format const &a, Node_format const &b)
|
||||||
|
{
|
||||||
|
return std::memcmp(a.public_key, b.public_key, sizeof(a.public_key)) == 0
|
||||||
|
&& a.ip_port == b.ip_port;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, Node_format const &v)
|
||||||
|
{
|
||||||
|
return out << "\n Node_format{\n"
|
||||||
|
<< " public_key = " << PublicKey(v.public_key) << ",\n"
|
||||||
|
<< " ip_port = " << v.ip_port << " }";
|
||||||
|
}
|
18
external/toxcore/c-toxcore/toxcore/DHT_test_util.hh
vendored
Normal file
18
external/toxcore/c-toxcore/toxcore/DHT_test_util.hh
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef C_TOXCORE_TOXCORE_DHT_TEST_UTIL_H
|
||||||
|
#define C_TOXCORE_TOXCORE_DHT_TEST_UTIL_H
|
||||||
|
|
||||||
|
#include <iosfwd>
|
||||||
|
|
||||||
|
#include "DHT.h"
|
||||||
|
#include "test_util.hh"
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Deleter<DHT> : Function_Deleter<DHT, kill_dht> { };
|
||||||
|
|
||||||
|
bool operator==(Node_format const &a, Node_format const &b);
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, Node_format const &v);
|
||||||
|
|
||||||
|
Node_format random_node_format(const Random *rng);
|
||||||
|
|
||||||
|
#endif // C_TOXCORE_TOXCORE_DHT_TEST_UTIL_H
|
@@ -32,7 +32,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <linux/netdevice.h>
|
#include <linux/if.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
#include "ccompat.h"
|
#include "ccompat.h"
|
||||||
#include "crypto_core.h"
|
#include "crypto_core.h"
|
||||||
#include "util.h"
|
#include "network.h"
|
||||||
|
|
||||||
#define MAX_INTERFACES 16
|
#define MAX_INTERFACES 16
|
||||||
|
|
||||||
@@ -62,35 +62,38 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
IP_ADAPTER_INFO *pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
|
IP_ADAPTER_INFO *adapter_info = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
|
||||||
unsigned long ulOutBufLen = sizeof(IP_ADAPTER_INFO);
|
|
||||||
|
|
||||||
if (pAdapterInfo == nullptr) {
|
if (adapter_info == nullptr) {
|
||||||
free(broadcast);
|
free(broadcast);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
|
unsigned long out_buf_len = sizeof(IP_ADAPTER_INFO);
|
||||||
free(pAdapterInfo);
|
|
||||||
pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen);
|
|
||||||
|
|
||||||
if (pAdapterInfo == nullptr) {
|
if (GetAdaptersInfo(adapter_info, &out_buf_len) == ERROR_BUFFER_OVERFLOW) {
|
||||||
|
free(adapter_info);
|
||||||
|
IP_ADAPTER_INFO *new_adapter_info = (IP_ADAPTER_INFO *)malloc(out_buf_len);
|
||||||
|
|
||||||
|
if (new_adapter_info == nullptr) {
|
||||||
free(broadcast);
|
free(broadcast);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
adapter_info = new_adapter_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int ret = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen);
|
const int ret = GetAdaptersInfo(adapter_info, &out_buf_len);
|
||||||
|
|
||||||
if (ret == NO_ERROR) {
|
if (ret == NO_ERROR) {
|
||||||
IP_ADAPTER_INFO *pAdapter = pAdapterInfo;
|
IP_ADAPTER_INFO *adapter = adapter_info;
|
||||||
|
|
||||||
while (pAdapter != nullptr) {
|
while (adapter != nullptr) {
|
||||||
IP gateway = {0};
|
IP gateway = {0};
|
||||||
IP subnet_mask = {0};
|
IP subnet_mask = {0};
|
||||||
|
|
||||||
if (addr_parse_ip(pAdapter->IpAddressList.IpMask.String, &subnet_mask)
|
if (addr_parse_ip(adapter->IpAddressList.IpMask.String, &subnet_mask)
|
||||||
&& addr_parse_ip(pAdapter->GatewayList.IpAddress.String, &gateway)) {
|
&& addr_parse_ip(adapter->GatewayList.IpAddress.String, &gateway)) {
|
||||||
if (net_family_is_ipv4(gateway.family) && net_family_is_ipv4(subnet_mask.family)) {
|
if (net_family_is_ipv4(gateway.family) && net_family_is_ipv4(subnet_mask.family)) {
|
||||||
IP *ip = &broadcast->ips[broadcast->count];
|
IP *ip = &broadcast->ips[broadcast->count];
|
||||||
ip->family = net_family_ipv4();
|
ip->family = net_family_ipv4();
|
||||||
@@ -106,12 +109,12 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pAdapter = pAdapter->Next;
|
adapter = adapter->Next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pAdapterInfo != nullptr) {
|
if (adapter_info != nullptr) {
|
||||||
free(pAdapterInfo);
|
free(adapter_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
return broadcast;
|
return broadcast;
|
||||||
@@ -243,11 +246,11 @@ static IP broadcast_ip(Family family_socket, Family family_broadcast)
|
|||||||
ip.ip.v6.uint8[15] = 0x01;
|
ip.ip.v6.uint8[15] = 0x01;
|
||||||
} else if (net_family_is_ipv4(family_broadcast)) {
|
} else if (net_family_is_ipv4(family_broadcast)) {
|
||||||
ip.family = net_family_ipv6();
|
ip.family = net_family_ipv6();
|
||||||
ip.ip.v6 = ip6_broadcast;
|
ip.ip.v6 = get_ip6_broadcast();
|
||||||
}
|
}
|
||||||
} else if (net_family_is_ipv4(family_socket) && net_family_is_ipv4(family_broadcast)) {
|
} else if (net_family_is_ipv4(family_socket) && net_family_is_ipv4(family_broadcast)) {
|
||||||
ip.family = net_family_ipv4();
|
ip.family = net_family_ipv4();
|
||||||
ip.ip.v4 = ip4_broadcast;
|
ip.ip.v4 = get_ip4_broadcast();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ip;
|
return ip;
|
||||||
|
24
external/toxcore/c-toxcore/toxcore/Messenger.c
vendored
24
external/toxcore/c-toxcore/toxcore/Messenger.c
vendored
@@ -10,17 +10,33 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "DHT.h"
|
#include "DHT.h"
|
||||||
|
#include "TCP_client.h"
|
||||||
|
#include "TCP_connection.h"
|
||||||
|
#include "TCP_server.h"
|
||||||
|
#include "announce.h"
|
||||||
|
#include "bin_pack.h"
|
||||||
|
#include "bin_unpack.h"
|
||||||
#include "ccompat.h"
|
#include "ccompat.h"
|
||||||
|
#include "crypto_core.h"
|
||||||
|
#include "forwarding.h"
|
||||||
|
#include "friend_connection.h"
|
||||||
|
#include "friend_requests.h"
|
||||||
|
#include "group_announce.h"
|
||||||
#include "group_chats.h"
|
#include "group_chats.h"
|
||||||
|
#include "group_common.h"
|
||||||
#include "group_onion_announce.h"
|
#include "group_onion_announce.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "mem.h"
|
||||||
#include "mono_time.h"
|
#include "mono_time.h"
|
||||||
|
#include "net_crypto.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
#include "onion.h"
|
||||||
|
#include "onion_announce.h"
|
||||||
|
#include "onion_client.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
@@ -2385,11 +2401,12 @@ static int m_handle_packet_invite_groupchat(Messenger *m, const int i, const uin
|
|||||||
non_null(1, 3) nullable(5)
|
non_null(1, 3) nullable(5)
|
||||||
static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata)
|
static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata)
|
||||||
{
|
{
|
||||||
|
Messenger *m = (Messenger *)object;
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Messenger *m = (Messenger *)object;
|
|
||||||
const uint8_t packet_id = temp[0];
|
const uint8_t packet_id = temp[0];
|
||||||
const uint8_t *data = temp + 1;
|
const uint8_t *data = temp + 1;
|
||||||
const uint16_t data_length = len - 1;
|
const uint16_t data_length = len - 1;
|
||||||
@@ -3176,7 +3193,8 @@ static void pack_groupchats(const GC_Session *c, Bin_Pack *bp)
|
|||||||
non_null()
|
non_null()
|
||||||
static bool pack_groupchats_handler(Bin_Pack *bp, const Logger *log, const void *obj)
|
static bool pack_groupchats_handler(Bin_Pack *bp, const Logger *log, const void *obj)
|
||||||
{
|
{
|
||||||
pack_groupchats((const GC_Session *)obj, bp);
|
const GC_Session *session = (const GC_Session *)obj;
|
||||||
|
pack_groupchats(session, bp);
|
||||||
return true; // TODO(iphydf): Return bool from pack functions.
|
return true; // TODO(iphydf): Return bool from pack functions.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,12 +10,17 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "DHT.h"
|
||||||
#include "TCP_common.h"
|
#include "TCP_common.h"
|
||||||
#include "ccompat.h"
|
#include "ccompat.h"
|
||||||
|
#include "crypto_core.h"
|
||||||
|
#include "forwarding.h"
|
||||||
|
#include "logger.h"
|
||||||
|
#include "mem.h"
|
||||||
#include "mono_time.h"
|
#include "mono_time.h"
|
||||||
|
#include "network.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
typedef struct TCP_Client_Conn {
|
typedef struct TCP_Client_Conn {
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user