Compare commits

..

1 Commits

Author SHA1 Message Date
67aefff940 windows mono_time hotfix 2024-01-09 15:37:02 +01:00
218 changed files with 3646 additions and 3267 deletions

View File

@@ -15,7 +15,9 @@ workflows:
- ubsan
# Static analysis
- clang-analyze
- clang-tidy
- cpplint
- infer
- static-analysis
jobs:
@@ -68,7 +70,6 @@ jobs:
cmake
git
libconfig-dev
libgmock-dev
libgtest-dev
libopus-dev
libsodium-dev
@@ -102,6 +103,27 @@ jobs:
- run: git submodule update --init --recursive
- run: CC=clang .circleci/cmake-ubsan
infer:
working_directory: ~/work
docker:
- image: toxchat/infer
steps:
- run: *apt_install
- checkout
- run: git submodule update --init --recursive
- run: infer --no-progress-bar -- cc
auto_tests/auto_test_support.c
auto_tests/lossless_packet_test.c
testing/misc_tools.c
toxav/*.c
toxcore/*.c
toxcore/*/*.c
toxencryptsave/*.c
third_party/cmp/*.c
-lpthread
$(pkg-config --cflags --libs libsodium opus vpx)
static-analysis:
working_directory: ~/work
docker:
@@ -132,6 +154,24 @@ jobs:
- run: git submodule update --init --recursive
- run: other/analysis/run-clang-analyze
clang-tidy:
working_directory: ~/work
docker:
- image: ubuntu
steps:
- run: *apt_install
- run:
apt-get install -y --no-install-recommends
ca-certificates
clang-tidy-14
- checkout
- run: git submodule update --init --recursive
- run:
other/analysis/run-clang-tidy ||
other/analysis/run-clang-tidy ||
other/analysis/run-clang-tidy
cpplint:
working_directory: ~/work
docker:

View File

@@ -1,5 +1,4 @@
# vim:ft=yaml
HeaderFilterRegex: "/c-toxcore/[^/]+/[^.].+"
CheckOptions:
- key: readability-identifier-naming.ClassCase
value: Camel_Snake_Case
@@ -36,12 +35,6 @@ CheckOptions:
value: lower_case
- key: llvmlibc-restrict-system-libc-headers.Includes
value: "arpa/inet.h,assert.h,ctype.h,errno.h,fcntl.h,getopt.h,libconfig.h,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"
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"
- key: hicpp-signed-bitwise.IgnorePositiveIntegerLiterals
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.

View File

@@ -0,0 +1,61 @@
#!/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"

View File

@@ -5,10 +5,10 @@
add_ld_flag -Wl,-z,defs
# Make compilation error on a warning
add_flag -Werror -Wno-unsafe-buffer-usage
add_flag -Werror
# Coverage flags.
add_flag -fprofile-instr-generate -fcoverage-mapping
add_flag --coverage
# Optimisation, but keep stack traces useful.
add_c_flag -fno-inline -fno-omit-frame-pointer

View File

@@ -1,15 +1,12 @@
#!/bin/bash
set -exu -o pipefail
set -exu
LOCAL="${1:-}"
readarray -t FILES <<<"$(git ls-files)"
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
tar c "${FILES[@]}" | docker build -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node -
docker tag toxchat/bootstrap-node:latest toxchat/bootstrap-node:"$(other/print-version)"
sudo useradd \

View File

@@ -0,0 +1,86 @@
---
_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"

View File

@@ -13,10 +13,7 @@ jobs:
common:
uses: TokTok/ci-tools/.github/workflows/common-ci.yml@master
analysis:
strategy:
matrix:
tool: [autotools, clang-tidy, compcert, cppcheck, doxygen, infer, misra, tcc, tokstyle]
cppcheck:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
@@ -24,16 +21,84 @@ jobs:
- name: Docker Build
uses: docker/build-push-action@v4
with:
file: other/docker/${{ matrix.tool }}/Dockerfile
file: other/docker/cppcheck/Dockerfile
coverage-linux:
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Build, test, and upload coverage
run: other/docker/coverage/run
- name: Set up Python 3.9
uses: actions/setup-python@v1
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:
runs-on: ubuntu-latest
@@ -55,16 +120,23 @@ jobs:
- name: Run cimplefmt
run: other/docker/cimplefmt/run -u $(find tox* -name "*.[ch]")
build-android:
build-win32:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- run: .github/scripts/cmake-android armeabi-v7a
- run: .github/scripts/cmake-android arm64-v8a
- run: .github/scripts/cmake-android x86
- run: .github/scripts/cmake-android x86_64
- 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
@@ -75,58 +147,22 @@ jobs:
- 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]
coverage-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Cross compilation
run: .github/scripts/cmake-win${{ matrix.bits }} script
- name: Build, test, and upload coverage
run: other/docker/coverage/run
mypy:
build-android:
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
- run: .github/scripts/cmake-android armeabi-v7a
- run: .github/scripts/cmake-android arm64-v8a
- run: .github/scripts/cmake-android x86
- run: .github/scripts/cmake-android x86_64

View File

@@ -14,8 +14,6 @@ Thumbs.db
/_build
/_install
/tox-0.0.0*
/.vs
/CppProperties.json
CMakeCache.txt
CMakeFiles
Makefile
@@ -93,5 +91,4 @@ cscope.files
# rpm
tox.spec
/infer
.idea/

View File

@@ -1,7 +1,7 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//tools/project:build_defs.bzl", "project")
project(license = "gpl3-https")
project()
genrule(
name = "public_headers",

View File

@@ -81,7 +81,7 @@ find_package(GTest)
set(CMAKE_MACOSX_RPATH ON)
# Set standard version for compiler.
if(MSVC AND MSVC_TOOLSET_VERSION LESS 143)
if(MSVC)
# https://developercommunity.visualstudio.com/t/older-winsdk-headers-are-incompatible-with-zcprepr/1593479
set(CMAKE_C_STANDARD 99)
else()
@@ -94,35 +94,6 @@ set(CMAKE_CXX_EXTENSIONS OFF)
message(STATUS "Supported C compiler features = ${CMAKE_C_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)")
if(MIN_LOGGER_LEVEL)
if(("${MIN_LOGGER_LEVEL}" STREQUAL "TRACE") OR
@@ -160,7 +131,21 @@ if(BOOTSTRAP_DAEMON AND WIN32)
set(BOOTSTRAP_DAEMON OFF)
endif()
# Enabling this breaks all other tests and no network connections will be possible
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)
option(MSVC_STATIC_SODIUM "Whether to link libsodium statically for MSVC" OFF)
@@ -342,14 +327,10 @@ set(toxcore_SOURCES
toxcore/tox_unpack.h
toxcore/util.c
toxcore/util.h)
if(TARGET unofficial-sodium::sodium)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} unofficial-sodium::sodium)
else()
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${LIBSODIUM_LIBRARIES})
set(toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${LIBSODIUM_LIBRARY_DIRS})
set(toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${LIBSODIUM_INCLUDE_DIRS})
set(toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${LIBSODIUM_CFLAGS_OTHER})
endif()
set(toxcore_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})
set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium)
set(toxcore_API_HEADERS
${toxcore_SOURCE_DIR}/toxcore/tox.h^tox
@@ -385,14 +366,10 @@ if(BUILD_TOXAV)
set(toxcore_API_HEADERS ${toxcore_API_HEADERS}
${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav)
if(MSVC)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} PkgConfig::OPUS PkgConfig::VPX)
else()
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${OPUS_LIBRARIES} ${VPX_LIBRARIES})
set(toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${OPUS_LIBRARY_DIRS} ${VPX_LIBRARY_DIRS})
set(toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${OPUS_INCLUDE_DIRS} ${VPX_INCLUDE_DIRS})
set(toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${OPUS_CFLAGS_OTHER} ${VPX_CFLAGS_OTHER})
endif()
set(toxcore_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})
set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} opus vpx)
endif()
@@ -423,6 +400,7 @@ if(CMAKE_THREAD_LIBS_INIT)
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()
if(NSL_LIBRARIES)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${NSL_LIBRARIES})
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lnsl)
@@ -438,13 +416,9 @@ if(SOCKET_LIBRARIES)
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lsocket)
endif()
if(TARGET PThreads4W::PThreads4W)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} PThreads4W::PThreads4W)
elseif(TARGET Threads::Threads)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} Threads::Threads)
endif()
if(WIN32)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} iphlpapi wsock32 ws2_32)
set(toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ws2_32 iphlpapi)
set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lws2_32 -liphlpapi)
endif()
################################################################################
@@ -454,33 +428,20 @@ endif()
################################################################################
# Create combined library from all the sources.
if(ENABLE_SHARED)
add_library(toxcore_shared SHARED ${toxcore_SOURCES})
set_target_properties(toxcore_shared PROPERTIES OUTPUT_NAME toxcore)
target_link_libraries(toxcore_shared PRIVATE ${toxcore_LINK_LIBRARIES})
target_link_directories(toxcore_shared PUBLIC ${toxcore_LINK_DIRECTORIES})
target_include_directories(toxcore_shared SYSTEM PRIVATE ${toxcore_INCLUDE_DIRECTORIES})
target_compile_options(toxcore_shared PRIVATE ${toxcore_COMPILE_OPTIONS})
endif()
add_module(toxcore ${toxcore_SOURCES})
if(ENABLE_STATIC)
add_library(toxcore_static STATIC ${toxcore_SOURCES})
if(NOT MSVC)
set_target_properties(toxcore_static PROPERTIES OUTPUT_NAME toxcore)
endif()
# Link it to all dependencies.
if(TARGET toxcore_static)
target_link_libraries(toxcore_static PRIVATE ${toxcore_LINK_LIBRARIES})
target_link_directories(toxcore_static PUBLIC ${toxcore_LINK_DIRECTORIES})
target_include_directories(toxcore_static SYSTEM PRIVATE ${toxcore_INCLUDE_DIRECTORIES})
target_compile_options(toxcore_static PRIVATE ${toxcore_COMPILE_OPTIONS})
endif()
if(BUILD_FUZZ_TESTS)
add_library(toxcore_fuzz STATIC ${toxcore_SOURCES})
target_link_libraries(toxcore_fuzz PRIVATE ${toxcore_LINK_LIBRARIES})
target_link_directories(toxcore_fuzz PUBLIC ${toxcore_LINK_DIRECTORIES})
target_include_directories(toxcore_fuzz SYSTEM PRIVATE ${toxcore_INCLUDE_DIRECTORIES})
target_compile_options(toxcore_fuzz PRIVATE ${toxcore_COMPILE_OPTIONS})
target_compile_definitions(toxcore_fuzz PUBLIC "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION")
if(TARGET toxcore_shared)
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()
# Make version script (on systems that support it) to limit symbol visibility.
@@ -496,25 +457,14 @@ 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)
add_executable(unit_${target}_test ${subdir}/${target}_test.cc)
target_link_libraries(unit_${target}_test PRIVATE test_util)
if(TARGET toxcore_static)
target_link_libraries(unit_${target}_test PRIVATE toxcore_static)
else()
target_link_libraries(unit_${target}_test PRIVATE toxcore_shared)
endif()
target_link_libraries(unit_${target}_test PRIVATE GTest::gtest GTest::gtest_main GTest::gmock)
target_link_libraries(unit_${target}_test PRIVATE GTest::GTest GTest::Main)
set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${TEST_CXX_FLAGS}")
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
set_property(TEST ${target} PROPERTY ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw")
@@ -534,7 +484,6 @@ if(GTEST_FOUND)
unit_test(toxcore mem)
unit_test(toxcore mono_time)
unit_test(toxcore ping_array)
unit_test(toxcore test_util)
unit_test(toxcore tox)
unit_test(toxcore util)
endif()
@@ -567,14 +516,6 @@ if(DHT_BOOTSTRAP)
target_link_libraries(DHT_bootstrap PRIVATE toxcore_shared)
endif()
target_link_libraries(DHT_bootstrap PRIVATE misc_tools)
if(TARGET unofficial-sodium::sodium)
target_link_libraries(DHT_bootstrap PRIVATE unofficial-sodium::sodium)
endif()
if(TARGET PThreads4W::PThreads4W)
target_link_libraries(DHT_bootstrap PRIVATE PThreads4W::PThreads4W)
elseif(TARGET Threads::Threads)
target_link_libraries(DHT_bootstrap PRIVATE Threads::Threads)
endif()
install(TARGETS DHT_bootstrap RUNTIME DESTINATION bin)
endif()

View File

@@ -1,21 +0,0 @@
{
"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"
}
}
]
}

View File

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

View File

@@ -9,11 +9,6 @@ if(TARGET toxcore_static)
else()
target_link_libraries(auto_test_support PRIVATE toxcore_shared)
endif()
if(TARGET PThreads4W::PThreads4W)
target_link_libraries(auto_test_support PRIVATE PThreads4W::PThreads4W)
elseif(TARGET Threads::Threads)
target_link_libraries(auto_test_support PRIVATE Threads::Threads)
endif()
function(auto_test target)
add_executable(auto_${target}_test ${target}_test.c)
@@ -23,15 +18,12 @@ function(auto_test target)
else()
target_link_libraries(auto_${target}_test PRIVATE toxcore_shared)
endif()
if(TARGET PThreads4W::PThreads4W)
target_link_libraries(auto_${target}_test PRIVATE PThreads4W::PThreads4W)
elseif(TARGET Threads::Threads)
target_link_libraries(auto_${target}_test PRIVATE Threads::Threads)
if(NOT ARGV1 STREQUAL "DONT_RUN")
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}")
endif()
add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} auto_${target}_test)
set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
# add the source dir as environment variable, so the testdata can be found
set_tests_properties(${target} PROPERTIES ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw;srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
endfunction()
auto_test(TCP)
@@ -97,20 +89,15 @@ if(BUILD_TOXAV)
auto_test(toxav_basic)
auto_test(toxav_many)
if(MSVC)
target_link_libraries(auto_toxav_basic_test PRIVATE PkgConfig::VPX)
target_link_libraries(auto_toxav_many_test PRIVATE PkgConfig::VPX)
else()
target_link_libraries(auto_toxav_basic_test PRIVATE ${VPX_LIBRARIES})
target_link_directories(auto_toxav_basic_test PRIVATE ${VPX_LIBRARY_DIRS})
target_include_directories(auto_toxav_basic_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS})
target_compile_options(auto_toxav_basic_test PRIVATE ${VPX_CFLAGS_OTHER})
target_link_libraries(auto_toxav_basic_test PRIVATE ${VPX_LIBRARIES})
target_link_directories(auto_toxav_basic_test PRIVATE ${VPX_LIBRARY_DIRS})
target_include_directories(auto_toxav_basic_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS})
target_compile_options(auto_toxav_basic_test PRIVATE ${VPX_CFLAGS_OTHER})
target_link_libraries(auto_toxav_many_test PRIVATE ${VPX_LIBRARIES})
target_link_directories(auto_toxav_many_test PRIVATE ${VPX_LIBRARY_DIRS})
target_include_directories(auto_toxav_many_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS})
target_compile_options(auto_toxav_many_test PRIVATE ${VPX_CFLAGS_OTHER})
endif()
target_link_libraries(auto_toxav_many_test PRIVATE ${VPX_LIBRARIES})
target_link_directories(auto_toxav_many_test PRIVATE ${VPX_LIBRARY_DIRS})
target_include_directories(auto_toxav_many_test SYSTEM PRIVATE ${VPX_INCLUDE_DIRS})
target_compile_options(auto_toxav_many_test PRIVATE ${VPX_CFLAGS_OTHER})
endif()
if(PROXY_TEST)

View File

@@ -187,14 +187,14 @@ TCP_test_SOURCES = ../auto_tests/TCP_test.c
TCP_test_CFLAGS = $(AUTOTEST_CFLAGS)
TCP_test_LDADD = $(AUTOTEST_LDADD)
tox_dispatch_test_SOURCES = ../auto_tests/tox_dispatch_test.c
tox_dispatch_test_CFLAGS = $(AUTOTEST_CFLAGS)
tox_dispatch_test_LDADD = $(AUTOTEST_LDADD)
tox_events_test_SOURCES = ../auto_tests/tox_events_test.c
tox_events_test_CFLAGS = $(AUTOTEST_CFLAGS)
tox_events_test_LDADD = $(AUTOTEST_LDADD)
tox_dispatch_test_SOURCES = ../auto_tests/tox_dispatch_test.c
tox_dispatch_test_CFLAGS = $(AUTOTEST_CFLAGS)
tox_dispatch_test_LDADD = $(AUTOTEST_LDADD)
tox_many_tcp_test_SOURCES = ../auto_tests/tox_many_tcp_test.c
tox_many_tcp_test_CFLAGS = $(AUTOTEST_CFLAGS)
tox_many_tcp_test_LDADD = $(AUTOTEST_LDADD)

View File

@@ -149,8 +149,6 @@ void set_mono_time_callback(AutoTox *autotox)
Mono_Time *mono_time = autotox->tox->mono_time;
autotox->clock = current_time_monotonic(mono_time);
ck_assert_msg(autotox->clock >= 1000,
"clock is too low (not initialised?): %lu", (unsigned long)autotox->clock);
mono_time_set_current_time_callback(mono_time, nullptr, nullptr); // set to default first
mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &autotox->clock);
}

View File

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

View File

@@ -395,9 +395,8 @@ static void group_message_test(AutoTox *autotoxes)
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
if (state1->peer_joined && !state1->message_sent) {
state1->pseudo_msg_id = tox_group_send_message(
tox1, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)TEST_MESSAGE,
TEST_MESSAGE_LEN, &err_send);
tox_group_send_message(tox1, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)TEST_MESSAGE,
TEST_MESSAGE_LEN, &state1->pseudo_msg_id, &err_send);
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
state1->message_sent = true;
}
@@ -420,7 +419,7 @@ static void group_message_test(AutoTox *autotoxes)
// tox1 sends group a message which should not be seen by tox0's message handler
tox_group_send_message(tox1, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)IGNORE_MESSAGE,
IGNORE_MESSAGE_LEN, &err_send);
IGNORE_MESSAGE_LEN, nullptr, &err_send);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@@ -507,7 +506,7 @@ static void group_message_test(AutoTox *autotoxes)
memcpy(m + 2, &checksum, sizeof(uint16_t));
tox_group_send_message(tox0, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)m, message_size, &err_send);
tox_group_send_message(tox0, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)m, message_size, nullptr, &err_send);
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
}
@@ -529,7 +528,7 @@ static void group_message_test(AutoTox *autotoxes)
memcpy(m, &i, sizeof(uint16_t));
tox_group_send_message(tox0, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)m, 2, &err_send);
tox_group_send_message(tox0, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)m, 2, nullptr, &err_send);
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
}

View File

@@ -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);
Tox_Err_Group_Send_Message msg_err;
tox_group_send_message(autotox->tox, state->group_number, TOX_MESSAGE_TYPE_NORMAL,
(const uint8_t *)"test", 4, &msg_err);
bool send_ret = tox_group_send_message(autotox->tox, state->group_number, TOX_MESSAGE_TYPE_NORMAL,
(const uint8_t *)"test", 4, nullptr, &msg_err);
switch (self_role) {
case TOX_GROUP_ROLE_OBSERVER: {
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
ck_assert(!send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
break;
}
case TOX_GROUP_ROLE_USER: {
if (voice_state != TOX_GROUP_VOICE_STATE_ALL) {
ck_assert_msg(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS,
"%d", msg_err);
ck_assert_msg(!send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS,
"%d, %d", send_ret, msg_err);
} else {
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
ck_assert(send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
}
break;
@@ -356,16 +356,16 @@ static void voice_state_message_test(AutoTox *autotox, Tox_Group_Voice_State voi
case TOX_GROUP_ROLE_MODERATOR: {
if (voice_state != TOX_GROUP_VOICE_STATE_FOUNDER) {
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
ck_assert(send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
} else {
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
ck_assert(!send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
}
break;
}
case TOX_GROUP_ROLE_FOUNDER: {
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
ck_assert(send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
break;
}
}

View File

@@ -206,7 +206,7 @@ static void group_tcp_test(AutoTox *autotoxes)
Tox_Err_Group_Send_Message merr;
tox_group_send_message(autotoxes[0].tox, groupnumber, TOX_MESSAGE_TYPE_NORMAL,
(const uint8_t *)CODEWORD, CODEWORD_LEN, &merr);
(const uint8_t *)CODEWORD, CODEWORD_LEN, nullptr, &merr);
ck_assert(merr == TOX_ERR_GROUP_SEND_MESSAGE_OK);
while (!state1->got_second_code) {

View File

@@ -10,7 +10,6 @@
#include "../toxcore/tox.h"
#include "../toxcore/tox_dispatch.h"
#include "../toxcore/tox_events.h"
#include "../toxcore/tox_private.h"
#include "../toxcore/tox_unpack.h"
#include "auto_test_support.h"
#include "check_compat.h"

View File

@@ -22,23 +22,21 @@ static bool await_message(Tox **toxes)
Tox_Events *events = tox_events_iterate(toxes[1], false, nullptr);
if (events != nullptr) {
uint32_t events_size = tox_events_get_size(events);
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_events_get_friend_message_size(events) == 1);
const Tox_Event_Friend_Message *msg_event = tox_events_get_friend_message(events, 0);
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);
ck_assert_msg(memcmp(msg, "hello", sizeof("hello")) == 0,
"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);
return true;
}

View File

@@ -1,26 +1,19 @@
###############################################################################
#
# :: For systems that have pkg-config.
# :: For UNIX-like systems that have pkg-config.
#
###############################################################################
find_package(PkgConfig REQUIRED)
include(ModulePackage)
find_package(Threads REQUIRED)
find_library(NSL_LIBRARIES nsl )
find_library(RT_LIBRARIES rt )
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.
pkg_search_module(LIBSODIUM libsodium IMPORTED_TARGET REQUIRED)
if(MSVC)
find_package(unofficial-sodium REQUIRED)
endif()
pkg_search_module(LIBSODIUM libsodium IMPORTED_TARGET)
# For toxav.
pkg_search_module(OPUS opus IMPORTED_TARGET)
@@ -34,3 +27,56 @@ endif()
# For tox-bootstrapd.
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()

View File

@@ -19,6 +19,21 @@ if(FULLY_STATIC)
set(ENABLE_STATIC ON)
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)
if(TARGET ${lib}_shared)
set_target_properties(${lib}_shared PROPERTIES

4
external/toxcore/c-toxcore/heroku.yml vendored Normal file
View File

@@ -0,0 +1,4 @@
---
build:
docker:
web: other/bootstrap_daemon/websocket/Dockerfile

View File

@@ -21,11 +21,13 @@ cc_binary(
"//c-toxcore/toxcore:Messenger",
"//c-toxcore/toxcore:TCP_server",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:friend_requests",
"//c-toxcore/toxcore:group_onion_announce",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:network",
"//c-toxcore/toxcore:onion_announce",
"//c-toxcore/toxcore:tox",
"//c-toxcore/toxcore:util",
],
)

View File

@@ -16,17 +16,12 @@
#include "../toxcore/DHT.h"
#include "../toxcore/LAN_discovery.h"
#include "../toxcore/ccompat.h"
#include "../toxcore/crypto_core.h"
#include "../toxcore/forwarding.h"
#include "../toxcore/group_announce.h"
#include "../toxcore/friend_requests.h"
#include "../toxcore/group_onion_announce.h"
#include "../toxcore/logger.h"
#include "../toxcore/mem.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/util.h"
#define TCP_RELAY_ENABLED
@@ -51,7 +46,7 @@ static const char *motd_str = ""; //Change this to anything within 256 bytes(but
#define PORT 33445
static bool manage_keys(DHT *dht)
static void manage_keys(DHT *dht)
{
enum { KEYS_SIZE = CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE };
uint8_t keys[KEYS_SIZE];
@@ -65,8 +60,7 @@ static bool manage_keys(DHT *dht)
if (read_size != KEYS_SIZE) {
printf("Error while reading the key file\nExiting.\n");
fclose(keys_file);
return false;
exit(1);
}
dht_set_self_public_key(dht, keys);
@@ -79,20 +73,18 @@ static bool manage_keys(DHT *dht)
if (keys_file == nullptr) {
printf("Error opening key file in write mode.\nKeys will not be saved.\n");
return false;
return;
}
if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) {
printf("Error while writing the key file.\nExiting.\n");
fclose(keys_file);
return false;
exit(1);
}
printf("Keys saved successfully.\n");
}
fclose(keys_file);
return true;
}
static const char *strlevel(Logger_Level level)
@@ -129,7 +121,7 @@ int main(int argc, char *argv[])
if (argc == 2 && !tox_strncasecmp(argv[1], "-h", 3)) {
printf("Usage (connected) : %s [--ipv4|--ipv6] IP PORT KEY\n", argv[0]);
printf("Usage (unconnected): %s [--ipv4|--ipv6]\n", argv[0]);
return 0;
exit(0);
}
/* let user override default by cmdline */
@@ -137,7 +129,7 @@ int main(int argc, char *argv[])
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
if (argvoffset < 0) {
return 1;
exit(1);
}
/* Initialize networking -
@@ -170,16 +162,14 @@ int main(int argc, char *argv[])
if (!(onion && forwarding && onion_a)) {
printf("Something failed to initialize.\n");
return 1;
exit(1);
}
gca_onion_init(gc_announces_list, onion_a);
perror("Initialization");
if (!manage_keys(dht)) {
return 1;
}
manage_keys(dht);
printf("Public key: ");
#ifdef TCP_RELAY_ENABLED
@@ -189,7 +179,7 @@ int main(int argc, char *argv[])
if (tcp_s == nullptr) {
printf("TCP server failed to initialize.\n");
return 1;
exit(1);
}
#endif
@@ -199,7 +189,7 @@ int main(int argc, char *argv[])
if (file == nullptr) {
printf("Could not open file \"%s\" for writing. Exiting...\n", public_id_filename);
return 1;
exit(1);
}
for (uint32_t i = 0; i < 32; ++i) {
@@ -220,7 +210,7 @@ int main(int argc, char *argv[])
if (port_conv <= 0 || port_conv > UINT16_MAX) {
printf("Failed to convert \"%s\" into a valid port. Exiting...\n", argv[argvoffset + 2]);
return 1;
exit(1);
}
const uint16_t port = net_htons((uint16_t)port_conv);
@@ -232,7 +222,7 @@ int main(int argc, char *argv[])
if (!res) {
printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
return 1;
exit(1);
}
}

View File

@@ -31,8 +31,8 @@ out = (subprocess.run(
errors = 0
for line in out.split("\n"):
# other/fun and mallocfail can do what they want.
if "/fun/" in line or "/mallocfail/" in line:
# other/fun can do what it wants.
if "/fun/" in line:
continue
filename, include = line.split(":", 1)
# We only check headers.

View File

@@ -15,7 +15,7 @@ CPPFLAGS+=("-Itoxav")
CPPFLAGS+=("-Itoxencryptsave")
CPPFLAGS+=("-Ithird_party/cmp")
LDFLAGS=("-lopus" "-lsodium" "-lvpx" "-lpthread" "-lconfig" "-lgmock" "-lgtest")
LDFLAGS=("-lopus" "-lsodium" "-lvpx" "-lpthread" "-lconfig" "-lgtest")
LDFLAGS+=("-fuse-ld=gold")
LDFLAGS+=("-Wl,--detect-odr-violations")
LDFLAGS+=("-Wl,--warn-common")

View File

@@ -10,7 +10,7 @@ run() {
"${CPPFLAGS[@]}" \
"${LDFLAGS[@]}" \
"$@" \
-std=c++17 \
-std=c++11 \
-Werror \
-Weverything \
-Wno-alloca \

View File

@@ -9,7 +9,7 @@ run() {
clang++ --analyze amalgamation.cc \
"${CPPFLAGS[@]}" \
"$@" \
-std=c++20
-std=c++11
}
. other/analysis/variants.sh

View File

@@ -1,64 +1,6 @@
#!/usr/bin/env bash
#!/bin/bash
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.
CHECKS="$CHECKS,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling"
@@ -139,48 +81,62 @@ CHECKS="$CHECKS,-cert-dcl03-c"
CHECKS="$CHECKS,-hicpp-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
# 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() {
echo "Running clang-tidy in variant '$*'"
EXTRA_ARGS=("$@")
for i in "${!EXTRA_ARGS[@]}"; do
EXTRA_ARGS[$i]="--extra-arg=${EXTRA_ARGS[$i]}"
done
ls .clang-tidy
copy_files a
if ! find "${DIRS[@]}" \
-maxdepth 1 -name "*.c" -print0 \
| xargs -0 -n15 -P"$(nproc)" clang-tidy \
-p="$PWD/_build" \
--extra-arg=-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE \
"${EXTRA_ARGS[@]}" \
--fix \
--checks="$CHECKS" \
--warnings-as-errors="$ERRORS" \
--use-color; then
copy_files b
colordiff -ru a b
rm -rf a b
false
fi
rm -rf a
clang-tidy-14 \
-p=_build \
--extra-arg=-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE \
"${EXTRA_ARGS[@]}" \
--checks="$CHECKS" \
--warnings-as-errors="$ERRORS" \
--use-color \
other/bootstrap_daemon/src/*.c \
other/*.c \
toxav/*.c \
toxcore/*.c \
toxencryptsave/*.c
}
cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

View File

@@ -34,8 +34,6 @@ CPPCHECK_CXX+=("--suppress=AssignmentAddressToInteger")
CPPCHECK_CXX+=("--suppress=cstyleCast")
# Used in Messenger.c for a static_assert(...)
CPPCHECK_CXX+=("--suppress=sizeofFunctionCall")
# This is outdated. Range-for is a good choice.
CPPCHECK_CXX+=("--suppress=useStlAlgorithm")
run() {
echo "Running cppcheck in variant '$*'"

View File

@@ -11,7 +11,7 @@ run() {
"${CPPFLAGS[@]}" \
"${LDFLAGS[@]}" \
"$@" \
-std=c++17 \
-std=c++11 \
-fdiagnostics-color=always \
-Wall \
-Wextra \

View File

@@ -0,0 +1,25 @@
#!/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"

View File

@@ -16,6 +16,7 @@
--align-reference=name
# Formatting Options
--add-brackets
--convert-tabs
--max-code-length=120

View File

@@ -18,6 +18,7 @@ cc_binary(
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:onion_announce",
"//c-toxcore/toxcore:tox",
"//c-toxcore/toxcore:util",
"@libconfig",
],
)

View File

@@ -259,7 +259,7 @@ docker run -d --name tox-bootstrapd --restart always \
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 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.
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.
You can check logs for your public key or any errors:
```sh

View File

@@ -12,7 +12,8 @@ RUN ["apk", "--no-cache", "add",\
"libsodium-static",\
"musl-dev",\
"ninja",\
"python3"]
"python3"\
]
WORKDIR /src/c-toxcore
@@ -48,10 +49,8 @@ RUN CC=clang cmake -B_build -H. \
# Verify checksum from dev-built binary, so we can be sure Docker Hub doesn't
# mess with your binaries.
COPY other/bootstrap_daemon/docker/tox-bootstrapd.sha256 other/bootstrap_daemon/docker/
RUN SHA256="$(sha256sum /usr/local/bin/tox-bootstrapd)" && \
(sha256sum -c other/bootstrap_daemon/docker/tox-bootstrapd.sha256 || \
(echo "::error file=other/bootstrap_daemon/docker/tox-bootstrapd.sha256,line=1::$SHA256" && \
false))
RUN sha256sum /usr/local/bin/tox-bootstrapd && \
sha256sum -c other/bootstrap_daemon/docker/tox-bootstrapd.sha256
# Remove all the example bootstrap nodes from the config file.
COPY other/bootstrap_daemon/tox-bootstrapd.conf other/bootstrap_daemon/

View File

@@ -1,46 +0,0 @@
#!/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}")

View File

@@ -1 +1 @@
08fe68095b88c142e0c7f3369c5f297f1377e219d0e0f0ff6f30ca94d76fca98 /usr/local/bin/tox-bootstrapd
b0bd5099f2f77fbd540a5a929a23cece39ff95e3a66702a5381342d01775cbd3 /usr/local/bin/tox-bootstrapd

View File

@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2016-2024 The TokTok team.
* Copyright © 2016-2018 The TokTok team.
* Copyright © 2015-2016 Tox project.
*/
@@ -10,12 +10,12 @@
#include "command_line_arguments.h"
#include "global.h"
#include "log.h"
#include "../../../toxcore/ccompat.h"
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
@@ -24,9 +24,9 @@
*/
static void print_help(void)
{
// 2 space indent
// Make sure all lines fit into 80 columns
// Make sure options are listed in alphabetical order
// 2 space ident
// make sure all lines fit into 80 columns
// make sure options are listed in alphabetical order
log_write(LOG_LEVEL_INFO,
"Usage: tox-bootstrapd [OPTION]... --config=FILE_PATH\n"
"\n"
@@ -39,7 +39,7 @@ static void print_help(void)
" (detach from the terminal) and won't use the PID file.\n"
" --help Print this help message.\n"
" --log-backend=BACKEND Specify which logging backend to use.\n"
" Valid BACKEND values (case sensitive):\n"
" Valid BACKEND values (case sensetive):\n"
" syslog Writes log messages to syslog.\n"
" Default option when no --log-backend is\n"
" specified.\n"
@@ -47,14 +47,13 @@ static void print_help(void)
" --version Print version information.\n");
}
Cli_Status handle_command_line_arguments(
int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend,
bool *run_in_foreground)
void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend,
bool *run_in_foreground)
{
if (argc < 2) {
log_write(LOG_LEVEL_ERROR, "Error: No arguments provided.\n\n");
print_help();
return CLI_STATUS_ERROR;
exit(1);
}
opterr = 0;
@@ -90,7 +89,7 @@ Cli_Status handle_command_line_arguments(
case 'h':
print_help();
return CLI_STATUS_DONE;
exit(0);
case 'l':
if (strcmp(optarg, "syslog") == 0) {
@@ -102,24 +101,24 @@ Cli_Status handle_command_line_arguments(
} else {
log_write(LOG_LEVEL_ERROR, "Error: Invalid BACKEND value for --log-backend option passed: %s\n\n", optarg);
print_help();
return CLI_STATUS_ERROR;
exit(1);
}
break;
case 'v':
log_write(LOG_LEVEL_INFO, "Version: %lu\n", DAEMON_VERSION_NUMBER);
return CLI_STATUS_DONE;
exit(0);
case '?':
log_write(LOG_LEVEL_ERROR, "Error: Unrecognized option %s\n\n", argv[optind - 1]);
print_help();
return CLI_STATUS_ERROR;
exit(1);
case ':':
log_write(LOG_LEVEL_ERROR, "Error: No argument provided for option %s\n\n", argv[optind - 1]);
print_help();
return CLI_STATUS_ERROR;
exit(1);
}
}
@@ -130,8 +129,6 @@ Cli_Status handle_command_line_arguments(
if (!cfg_file_path_set) {
log_write(LOG_LEVEL_ERROR, "Error: The required --config option wasn't specified\n\n");
print_help();
return CLI_STATUS_ERROR;
exit(1);
}
return CLI_STATUS_OK;
}

View File

@@ -12,15 +12,6 @@
#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.
* Terminates the application if incorrect arguments are specified.
@@ -31,8 +22,7 @@ typedef enum Cli_Status {
* @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.
*/
Cli_Status handle_command_line_arguments(
int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend,
bool *run_in_foreground);
void handle_command_line_arguments(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

View File

@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2016-2024 The TokTok team.
* Copyright © 2016-2023 The TokTok team.
* Copyright © 2014-2016 Tox project.
*/
@@ -10,7 +10,6 @@
#include "config.h"
#include "config_defaults.h"
#include "global.h"
#include "log.h"
#include <stdio.h>
@@ -19,10 +18,6 @@
#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"
/**
@@ -56,7 +51,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]);
}
// 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));
for (size_t i = 0; i < default_ports_count; ++i) {
@@ -73,7 +68,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
++*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) {
*tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t));
} else {
@@ -103,7 +98,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);
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);
break;
}
@@ -125,7 +120,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
++*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) {
*tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t));
} else {
@@ -265,7 +260,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");
// 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 (*tcp_relay_port_count == 0) {
log_write(LOG_LEVEL_ERROR, "No TCP ports could be read.\n");
@@ -412,7 +407,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);
next:
// config_setting_lookup_string() allocates string inside and doesn't allow us to free it directly
// config_setting_lookup_string() allocates string inside and doesn't allow us to free it direcly
// though it's freed when the element is removed, so we free it right away in order to keep memory
// consumption minimal
config_setting_remove_elem(node_list, 0);

View File

@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2016-2024 The TokTok team.
* Copyright © 2016-2018 The TokTok team.
* 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.
*
* @return 1 on success, some or no bootstrap nodes were added
* 0 on failure, an error occurred while parsing the config file.
* 0 on failure, a error accured while parsing config file.
*/
int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6);

View File

@@ -3,8 +3,6 @@
* Copyright © 2015-2016 Tox project.
*/
#include <stdarg.h>
/*
* Tox DHT bootstrap daemon.
* Logging utility with support of multiple logging backends.

View File

@@ -9,11 +9,8 @@
*/
#include "log_backend_stdout.h"
#include <stdarg.h>
#include <stdio.h>
#include "log.h"
static FILE *log_backend_stdout_level(LOG_LEVEL level)
{
switch (level) {

View File

@@ -10,12 +10,10 @@
#include "log_backend_syslog.h"
#include "global.h"
#include "log.h"
#include "../../../toxcore/ccompat.h"
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>

View File

@@ -23,24 +23,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// toxcore
#include "../../../toxcore/DHT.h"
#include "../../../toxcore/tox.h"
#include "../../../toxcore/LAN_discovery.h"
#include "../../../toxcore/TCP_server.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/logger.h"
#include "../../../toxcore/mem.h"
#include "../../../toxcore/mono_time.h"
#include "../../../toxcore/network.h"
#include "../../../toxcore/onion.h"
#include "../../../toxcore/onion_announce.h"
#include "../../../toxcore/util.h"
// misc
#include "../../bootstrap_node_packets.h"
@@ -123,7 +116,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
// Terminates the application if the daemonization fails.
static Cli_Status daemonize(LOG_BACKEND log_backend, char *pid_file_path)
static void daemonize(LOG_BACKEND log_backend, char *pid_file_path)
{
// Check if the PID file exists
FILE *pid_file = fopen(pid_file_path, "r");
@@ -138,7 +131,7 @@ static Cli_Status daemonize(LOG_BACKEND log_backend, char *pid_file_path)
if (pid_file == nullptr) {
log_write(LOG_LEVEL_ERROR, "Couldn't open the PID file for writing: %s. Exiting.\n", pid_file_path);
return CLI_STATUS_ERROR;
exit(1);
}
// Fork off from the parent process
@@ -148,27 +141,27 @@ static Cli_Status daemonize(LOG_BACKEND log_backend, char *pid_file_path)
fprintf(pid_file, "%d", pid);
fclose(pid_file);
log_write(LOG_LEVEL_INFO, "Forked successfully: PID: %d.\n", pid);
return CLI_STATUS_DONE;
exit(0);
} else {
fclose(pid_file);
}
if (pid < 0) {
log_write(LOG_LEVEL_ERROR, "Forking failed. Exiting.\n");
return CLI_STATUS_ERROR;
exit(1);
}
// Create a new SID for the child process
if (setsid() < 0) {
log_write(LOG_LEVEL_ERROR, "SID creation failure. Exiting.\n");
return CLI_STATUS_ERROR;
exit(1);
}
// Change the current working directory
if ((chdir("/")) < 0) {
log_write(LOG_LEVEL_ERROR, "Couldn't change working directory to '/'. Exiting.\n");
return CLI_STATUS_ERROR;
exit(1);
}
// Go quiet
@@ -177,8 +170,6 @@ static Cli_Status daemonize(LOG_BACKEND log_backend, char *pid_file_path)
close(STDIN_FILENO);
close(STDERR_FILENO);
}
return CLI_STATUS_OK;
}
// Logs toxcore logger message using our logger facility
@@ -221,18 +212,11 @@ int main(int argc, char *argv[])
char *cfg_file_path = nullptr;
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_open(log_backend);
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;
}
handle_command_line_arguments(argc, argv, &cfg_file_path, &log_backend, &run_in_foreground);
log_close();
log_open(log_backend);
@@ -270,14 +254,7 @@ int main(int argc, char *argv[])
}
if (!run_in_foreground) {
switch (daemonize(log_backend, pid_file_path)) {
case CLI_STATUS_OK:
break;
case CLI_STATUS_DONE:
return 0;
case CLI_STATUS_ERROR:
return 1;
}
daemonize(log_backend, pid_file_path);
}
free(pid_file_path);

View File

@@ -12,8 +12,6 @@
#include <string.h>
#include "../toxcore/network.h"
#define INFO_REQUEST_PACKET_LENGTH 78
static uint32_t bootstrap_version;

View File

@@ -2,8 +2,7 @@
# autotools-linux
FROM ubuntu:22.04
RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
RUN apt-get update && apt-get install --no-install-recommends -y \
autoconf \
automake \
ca-certificates \

View File

@@ -7,7 +7,6 @@ RUN apt-get update && \
clang \
cmake \
libconfig-dev \
libgmock-dev \
libgtest-dev \
libopus-dev \
libsodium-dev \

View File

@@ -1,21 +0,0 @@
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

View File

@@ -1,5 +0,0 @@
#!/bin/sh
set -eux
BUILD=clang-tidy
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .

View File

@@ -1,57 +1,50 @@
FROM toxchat/c-toxcore:sources AS src
FROM ubuntu:20.04 AS build
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
ca-certificates \
curl \
&& 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 \
clang \
cmake \
curl \
gcc \
git \
golang-1.18 \
libclang-rt-17-dev \
libconfig-dev \
libgmock-dev \
libgtest-dev \
libopus-dev \
libsodium-dev \
libunwind-17-dev \
libvpx-dev \
lld-17 \
llvm-17-dev \
llvm-dev \
make \
ninja-build \
pkg-config \
python3-pip \
python3-pygments \
&& 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 ["chmod", "+x", "/usr/local/bin/codecov"]
ENV CC=clang-17 \
CXX=clang++-17 \
ENV CC=clang \
CXX=clang++ \
PYTHONUNBUFFERED=1 \
PATH=$PATH:/usr/lib/go-1.18/bin
COPY --from=src /src/ /work/
SHELL ["/bin/bash", "-c"]
WORKDIR /work
RUN git clone --depth=1 https://github.com/TokTok/toktok-fuzzer /work/testing/fuzzing/toktok-fuzzer
COPY --from=src /src/ /work/
RUN source .github/scripts/flags-coverage.sh \
&& go version \
&& (cd other/proxy && go get github.com/things-go/go-socks5 && go build proxy_server.go) \
&& cmake -B_build -H. -GNinja \
-DCMAKE_C_FLAGS="$C_FLAGS" \
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
-DCMAKE_EXE_LINKER_FLAGS="$LD_FLAGS -fuse-ld=lld" \
-DCMAKE_EXE_LINKER_FLAGS="$LD_FLAGS" \
-DCMAKE_UNITY_BUILD=ON \
-DENABLE_SHARED=OFF \
-DMIN_LOGGER_LEVEL=TRACE \
@@ -60,7 +53,6 @@ RUN source .github/scripts/flags-coverage.sh \
-DSTRICT_ABI=ON \
-DAUTOTEST=ON \
-DPROXY_TEST=ON \
-DBUILD_FUZZ_TESTS=ON \
-DUSE_IPV6=OFF \
-DTEST_TIMEOUT_SECONDS=40 \
&& cmake --build _build --parallel 8 --target install
@@ -71,15 +63,24 @@ RUN /work/other/proxy/proxy_server \
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6)
WORKDIR /work/mallocfail
RUN ["git", "clone", "--depth=1", "https://github.com/TokTok/mallocfail", "/work/mallocfail"]
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 ["git", "clone", "--depth=1", "https://github.com/ralight/mallocfail", "/work/mallocfail"]
COPY other/docker/coverage/syscall_funcs.c src/
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
WORKDIR /work/_build
COPY other/docker/coverage/run_mallocfail /usr/local/bin/
RUN ["run_mallocfail", "--ctest=1", "--jobs=8"]
RUN llvm-profdata-17 merge -sparse $(find . -name "*.profraw") -o toxcore.profdata
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
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
RUN ["run_mallocfail", "--ctest=2", "--jobs=8"]
RUN ["gcovr", \
"--sort-percentage", \
"--gcov-executable=llvm-cov gcov", \
"--html-details=html/", \
"--root=..", \
"--exclude=CMakeFiles/", \
"--exclude=_deps/", \
"--exclude=(.+/)?auto_tests/", \
"--exclude=.+_test.cc?$", \
"--exclude=(.+/)?other/", \
"--exclude=(.+/)?testing/"]
WORKDIR /work

View File

@@ -1,4 +1,5 @@
# vim:ft=dockerfile
FROM toxchat/c-toxcore:coverage AS build
FROM nginx:alpine
COPY --from=build --chown=nginx:nginx /work/_build/html/ /usr/share/nginx/html/
COPY --from=build /work/_build/html/coverage_details.html /usr/share/nginx/html/index.html
COPY --from=build /work/_build/html/ /usr/share/nginx/html/

View File

@@ -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: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
docker run "${ci_env[@]}" -e CI=true --name toxcore-coverage --rm -t toxchat/c-toxcore:coverage /usr/local/bin/codecov -x "llvm-cov gcov"

View File

@@ -27,12 +27,11 @@ from typing import NoReturn
from typing import Optional
from typing import Tuple
_PRIMER = "auto_tests/auto_version_test"
_PRIMER = "./unit_util_test"
_MALLOCFAIL_SO = "/usr/local/lib/mallocfail.so"
_HASHES = "mallocfail_hashes"
_HASHES_PREV = "mallocfail_hashes.prev"
_TIMEOUT = 3.0
_BUILD_DIR = os.getcwd()
_ENV = {
"LD_PRELOAD": _MALLOCFAIL_SO,
@@ -46,19 +45,10 @@ def run_mallocfail(tmpdir: str, timeout: float, exe: str, iteration: int,
print(f"\x1b[1;33mmallocfail '{exe}' run #{iteration}\x1b[0m")
hashes = os.path.join(tmpdir, _HASHES)
hashes_prev = os.path.join(tmpdir, _HASHES_PREV)
profraw = os.path.join(_BUILD_DIR, "mallocfail.out", exe, "%p.profraw")
if os.path.exists(hashes):
shutil.copy(hashes, hashes_prev)
try:
proc = subprocess.run(
[exe],
timeout=timeout,
env={
"LLVM_PROFILE_FILE": profraw,
**_ENV,
},
cwd=tmpdir,
)
proc = subprocess.run([exe], timeout=timeout, env=_ENV, cwd=tmpdir)
except subprocess.TimeoutExpired:
print(f"\x1b[1;34mProgram {exe} timed out\x1b[0m")
return True
@@ -75,16 +65,13 @@ def run_mallocfail(tmpdir: str, timeout: float, exe: str, iteration: int,
# Process exited cleanly (success or failure).
pass
elif proc.returncode == -6:
# abort(), we allow it.
pass
elif proc.returncode == 7:
# ck_assert failed, also fine for us.
# Assertion failed.
pass
elif proc.returncode == -14:
print(f"\x1b[0;34mProgram '{exe}' timed out\x1b[0m")
else:
print(
f"\x1b[1;32mProgram '{exe}' failed to handle OOM situation cleanly (code {proc.returncode})\x1b[0m"
f"\x1b[1;32mProgram '{exe}' failed to handle OOM situation cleanly\x1b[0m"
)
if not keep_going:
raise Exception("Aborting test")
@@ -109,8 +96,8 @@ def find_prog(name: str) -> Tuple[Optional[str], ...]:
return path
return None
return (attempt(f"auto_tests/auto_{name}_test"),
) # attempt(f"./unit_{name}_test"),
return (attempt(f"./unit_{name}_test"),
attempt(f"auto_tests/auto_{name}_test"))
def parse_flags(args: List[str]) -> Tuple[Dict[str, str], List[str]]:
@@ -141,9 +128,6 @@ def isolated_mallocfail(timeout: int, exe: str) -> None:
shutil.copy(exe, os.path.join(tmpdir, exe))
shutil.copy(_HASHES, os.path.join(tmpdir, _HASHES))
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:
@@ -166,12 +150,12 @@ def main(args: List[str]) -> None:
else:
jobs = 1
# Start by running version_test, which allocates no memory of its own, just
# Start by running util_test, which allocates no memory of its own, just
# to prime the mallocfail hashes so it doesn't make global initialisers
# such as llvm_gcov_init fail.
if os.path.exists(_PRIMER):
print(f"\x1b[1;33mPriming hashes with {_PRIMER}\x1b[0m")
loop_mallocfail(os.getcwd(), timeout, _PRIMER, keep_going=True)
print(f"\x1b[1;33mPriming hashes with unit_util_test\x1b[0m")
loop_mallocfail(".", timeout, _PRIMER, keep_going=True)
print(f"\x1b[1;33m--------------------------------\x1b[0m")
print(f"\x1b[1;33mStarting mallocfail for {len(exes)} programs:\x1b[0m")

View File

@@ -0,0 +1,149 @@
#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);
}

View File

@@ -92,10 +92,6 @@
<alloc init="true">new_networking_no_udp</alloc>
<dealloc arg="1">kill_networking</dealloc>
</resource>
<resource>
<alloc init="true">net_new_strerror</alloc>
<dealloc arg="1">net_kill_strerror</dealloc>
</resource>
<resource>
<alloc init="true">new_onion</alloc>
<dealloc arg="1">kill_onion</dealloc>

View File

@@ -5,7 +5,7 @@ ENV LANG=en_US.UTF-8 \
LC_CTYPE=en_US.UTF-8 \
LC_ALL=en_US.UTF-8
RUN apk add --no-cache doxygen git graphviz texlive \
RUN apk add --no-cache doxygen git graphviz \
&& git clone --depth=1 https://github.com/jothepro/doxygen-awesome-css.git /work/doxygen-awesome-css
WORKDIR /work
COPY . /work/

View File

@@ -1,41 +0,0 @@
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.

View File

@@ -1,5 +0,0 @@
#!/bin/sh
set -eux
BUILD=infer
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .

View File

@@ -1,7 +1,6 @@
FROM ubuntu:20.04
RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
RUN apt-get update && apt-get install --no-install-recommends -y \
ca-certificates \
cppcheck \
libopus-dev \

View File

@@ -1,8 +1,7 @@
FROM toxchat/haskell:hs-tokstyle AS tokstyle
FROM ubuntu:22.04
RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
RUN apt-get update && apt-get install --no-install-recommends -y \
ca-certificates \
clang \
git \

View File

@@ -2,7 +2,7 @@ FROM debian:bullseye-slim
# Build-time environment variables
ARG VERSION_MSGPACK=4.0.0 \
VERSION_SODIUM=1.0.19 \
VERSION_SODIUM=1.0.18 \
VERSION_OPUS=1.3.1 \
VERSION_VPX=1.11.0 \
\

View File

@@ -40,9 +40,9 @@ build() {
echo
echo "=== Building Sodium $VERSION_SODIUM $ARCH ==="
curl "${CURL_OPTIONS[@]}" -O "https://github.com/jedisct1/libsodium/releases/download/$VERSION_SODIUM-RELEASE/libsodium-$VERSION_SODIUM.tar.gz"
curl "${CURL_OPTIONS[@]}" -O "https://download.libsodium.org/libsodium/releases/libsodium-$VERSION_SODIUM.tar.gz"
tar -xf "libsodium-$VERSION_SODIUM.tar.gz"
cd "libsodium-stable"
cd "libsodium-$VERSION_SODIUM"
./configure --host="$WINDOWS_TOOLCHAIN" --prefix="$PREFIX_DIR" --disable-shared --enable-static
make
make install

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright © 2023-2024 The TokTok team.
// Copyright © 2023 The TokTok team.
// this file can be used to generate event.c files
// requires c++17
@@ -119,54 +119,22 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
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
* Copyright © 2023-2024 The TokTok team.
* Copyright © 2023 The TokTok team.
*/
#include "events_alloc.h"
#include <assert.h>)";
if (need_stdlib_h) {
f << R"(
#include <stdlib.h>)";
}
if (need_string_h) {
f << R"(
#include <string.h>)";
}
f << R"(
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "../bin_pack.h"
#include "../bin_unpack.h"
#include "../ccompat.h"
#include "../mem.h"
#include "../tox.h"
#include "../tox_events.h")";
if (need_tox_unpack_h) {
f << R"(
#include "../tox_unpack.h")";
}
f << R"(
#include "../tox_events.h"
#include "../tox_unpack.h"
/*****************************************************
@@ -237,11 +205,10 @@ 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_length << " = 0;\n";
f << " }\n\n";
f << " uint8_t *" << t.name_data << "_copy = (uint8_t *)malloc(" << t.name_length << ");\n\n";
f << " if (" << t.name_data << "_copy == nullptr) {\n";
f << " " << event_name_l << "->" << t.name_data << " = (uint8_t *)malloc(" << t.name_length << ");\n\n";
f << " if (" << event_name_l << "->" << t.name_data << " == nullptr) {\n";
f << " return false;\n }\n\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 << " memcpy(" << event_name_l << "->" << t.name_data << ", " << t.name_data << ", " << t.name_length << ");\n";
f << " " << event_name_l << "->" << t.name_length << " = " << t.name_length << ";\n";
f << " return true;\n";
}
@@ -404,6 +371,28 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
f << " tox_events_add(events, &event);\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
f << "bool tox_event_" << event_name_l << "_unpack(\n";
f << " Tox_Event_" << event_name << " **event, Bin_Unpack *bu, const Memory *mem)\n{\n";

View File

@@ -10,6 +10,3 @@ sonar.sources=.
# Encoding of the source code.
sonar.sourceEncoding=UTF-8
# More precise Python version.
sonar.python.version=3.11

View File

@@ -13,6 +13,7 @@ sh_test(
args = ["$(locations %s)" % f for f in CIMPLE_FILES] + [
"-Wno-boolean-return",
"-Wno-callback-names",
"-Wno-enum-names",
"+RTS",
"-N4",
"-RTS",

View File

@@ -8,19 +8,10 @@ if(TARGET toxcore_static)
else()
target_link_libraries(misc_tools PRIVATE toxcore_shared)
endif()
if(TARGET unofficial-sodium::sodium)
target_link_libraries(misc_tools PRIVATE unofficial-sodium::sodium)
else()
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()
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})
################################################################################
#
@@ -36,9 +27,4 @@ if(BUILD_MISC_TESTS)
else()
target_link_libraries(Messenger_test PRIVATE toxcore_shared)
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()

View File

@@ -1,33 +1,26 @@
# For coverage tests
target_compile_definitions(toxcore_static PUBLIC "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION")
# Override network and random functions
add_library(fuzz_support func_conversion.h fuzz_support.cc fuzz_support.h)
set(LIBFUZZER_LINKER_FLAGS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(LIBFUZZER_LINKER_FLAGS "-fsanitize=fuzzer")
else()
message(SEND_ERROR "Compiler must be Clang to build fuzz targets")
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
add_executable(toxsave_fuzzer toxsave_harness.cc)
target_link_libraries(toxsave_fuzzer PRIVATE toxcore_fuzz fuzz_support ${LIBFUZZER_LINKER_FLAGS})
target_link_libraries(toxsave_fuzzer PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS})
# Fuzzes the bootstrap process
add_executable(bootstrap_fuzzer bootstrap_harness.cc)
target_link_libraries(bootstrap_fuzzer PRIVATE toxcore_fuzz fuzz_support ${LIBFUZZER_LINKER_FLAGS})
target_link_libraries(bootstrap_fuzzer PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS})
fuzz_test(DHT ../../toxcore)
fuzz_test(forwarding ../../toxcore)
fuzz_test(group_announce ../../toxcore)
fuzz_test(group_moderation ../../toxcore)
fuzz_test(tox_events ../../toxcore)
add_executable(DHT_fuzz_test ../../toxcore/DHT_fuzz_test.cc)
target_link_libraries(DHT_fuzz_test PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS})
add_executable(tox_events_fuzz_test ../../toxcore/tox_events_fuzz_test.cc)
target_link_libraries(tox_events_fuzz_test PRIVATE toxcore_static fuzz_support ${LIBFUZZER_LINKER_FLAGS})

View File

@@ -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) {
tox_options_set_proxy_type(opts.get(), TOX_PROXY_TYPE_NONE);
} else if (proxy_type == 1) {
@@ -139,7 +139,7 @@ void TestBootstrap(Fuzz_Data &input)
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)) {
tox_options_set_tcp_port(opts.get(), 33445);
}

View File

@@ -8,7 +8,6 @@
#include <fstream>
#include <vector>
#include "../../toxcore/crypto_core.h"
#include "../../toxcore/tox.h"
#include "../../toxcore/tox_dispatch.h"
#include "../../toxcore/tox_events.h"

View File

@@ -30,16 +30,6 @@ struct Network_Addr {
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() { }
static int recv_common(Fuzz_Data &input, uint8_t *buf, size_t buf_len)
@@ -77,7 +67,7 @@ static int recv_common(Fuzz_Data &input, uint8_t *buf, size_t buf_len)
template <typename F>
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) {
return nullptr;
}

View File

@@ -7,12 +7,11 @@
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <memory>
#include <vector>
#include <unordered_map>
#include <utility>
#include <vector>
#include "../../toxcore/tox.h"
@@ -21,28 +20,19 @@ struct Fuzz_Data {
std::size_t 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(const Fuzz_Data &rhs) = delete;
struct Consumer {
Fuzz_Data &fd;
template <typename T>
operator T()
{
const uint8_t *bytes = fd.consume(sizeof(T));
T val;
std::memcpy(&val, bytes, sizeof(T));
return val;
}
};
Consumer consume1() { return Consumer{*this}; }
uint8_t consume1()
{
const uint8_t val = data[0];
++data;
--size;
return val;
}
const uint8_t *consume(std::size_t count)
{
@@ -60,14 +50,14 @@ struct Fuzz_Data {
*
* @example
* @code
* CONSUME1_OR_RETURN(const uint8_t, one_byte, input);
* CONSUME1_OR_RETURN(const uint8_t one_byte, input);
* @endcode
*/
#define CONSUME1_OR_RETURN(TYPE, NAME, INPUT) \
if (INPUT.size < sizeof(TYPE)) { \
return; \
} \
TYPE NAME = INPUT.consume1()
#define CONSUME1_OR_RETURN(DECL, INPUT) \
if (INPUT.size < 1) { \
return; \
} \
DECL = INPUT.consume1()
/** @brief Consumes 1 byte of the fuzzer input or returns a value if no data
* available.
@@ -80,11 +70,11 @@ struct Fuzz_Data {
* CONSUME1_OR_RETURN_VAL(const uint8_t one_byte, input, nullptr);
* @endcode
*/
#define CONSUME1_OR_RETURN_VAL(TYPE, NAME, INPUT, VAL) \
if (INPUT.size < sizeof(TYPE)) { \
return VAL; \
} \
TYPE NAME = INPUT.consume1()
#define CONSUME1_OR_RETURN_VAL(DECL, INPUT, VAL) \
if (INPUT.size < 1) { \
return VAL; \
} \
DECL = INPUT.consume1()
/** @brief Consumes SIZE bytes of the fuzzer input or returns if not enough data available.
*
@@ -103,12 +93,6 @@ struct Fuzz_Data {
} \
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)
{
// The selector selected no function, so we do nothing and rely on the
@@ -116,7 +100,7 @@ inline void fuzz_select_target(uint8_t selector, Fuzz_Data &input)
}
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)) {
return fn(input);
@@ -125,11 +109,11 @@ void fuzz_select_target(uint8_t selector, Fuzz_Data &input, Arg &&fn, 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};
CONSUME1_OR_RETURN(const uint8_t, selector, input);
CONSUME1_OR_RETURN(uint8_t selector, input);
return fuzz_select_target(selector, input, std::forward<Args>(args)...);
}
@@ -143,10 +127,6 @@ struct System {
std::unique_ptr<Network> ns;
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.
~System();

View File

@@ -1,17 +1,96 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2022-2024 The TokTok team.
* Copyright © 2022 The TokTok team.
*/
#ifndef C_TOXCORE_TESTING_FUZZING_FUZZ_TOX_H
#define C_TOXCORE_TESTING_FUZZING_FUZZ_TOX_H
#include <cassert>
#include <memory>
#include "../../toxcore/DHT.h"
#include "../../toxcore/logger.h"
#include "../../toxcore/network.h"
#include "fuzz_support.h"
constexpr uint16_t SIZE_IP_PORT = SIZE_IP6 + sizeof(uint16_t);
template <typename 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

View File

@@ -1,11 +1,9 @@
#include <cassert>
#include <cstdio>
#include "../../toxcore/crypto_core.h"
#include "../../toxcore/tox.h"
#include "../../toxcore/tox_dispatch.h"
#include "../../toxcore/tox_events.h"
#include "../../toxcore/tox_private.h"
#include "fuzz_support.h"
#include "fuzz_tox.h"

View File

@@ -196,13 +196,13 @@ void ac_iterate(ACSession *ac)
int ac_queue_message(Mono_Time *mono_time, void *acp, struct RTPMessage *msg)
{
ACSession *ac = (ACSession *)acp;
if (ac == nullptr || msg == nullptr) {
if (acp == nullptr || msg == nullptr) {
free(msg);
return -1;
}
ACSession *ac = (ACSession *)acp;
if ((msg->header.pt & 0x7f) == (RTP_TYPE_AUDIO + 2) % 128) {
LOGGER_WARNING(ac->log, "Got dummy!");
free(msg);

View File

@@ -208,8 +208,6 @@ 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)
{
BWController *bwc = (BWController *)object;
if (length - 1 != sizeof(struct BWCMessage)) {
return -1;
}
@@ -220,5 +218,5 @@ static int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *d
offset += net_unpack_u32(data + offset, &msg.recv);
assert(offset == length);
return on_update(bwc, &msg);
return on_update((BWController *)object, &msg);
}

View File

@@ -290,9 +290,8 @@ static void group_av_peer_delete(void *object, uint32_t groupnumber, void *peer_
static void group_av_groupchat_delete(void *object, uint32_t groupnumber)
{
Group_AV *group_av = (Group_AV *)object;
if (group_av != nullptr) {
kill_group_av(group_av);
if (object != nullptr) {
kill_group_av((Group_AV *)object);
}
}
@@ -405,13 +404,12 @@ 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,
const uint8_t *packet, uint16_t length)
{
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)) {
if (peer_object == nullptr || object == nullptr || length <= sizeof(uint16_t)) {
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));
if (pk == nullptr) {
@@ -435,7 +433,7 @@ static int handle_group_audio_packet(void *object, uint32_t groupnumber, uint32_
return -1;
}
while (decode_audio_packet(group_av, peer_av, groupnumber, friendgroupnumber) == 0) {
while (decode_audio_packet((Group_AV *)object, peer_av, groupnumber, friendgroupnumber) == 0) {
/* Continue. */
}

View File

@@ -60,7 +60,7 @@ typedef struct MSIMessage {
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 uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const uint8_t *value, uint8_t value_len,
static uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const void *value, uint8_t value_len,
uint16_t *length);
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);
@@ -425,7 +425,7 @@ static int msg_parse_in(const Logger *log, MSIMessage *dest, const uint8_t *data
return 0;
}
static uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const uint8_t *value, uint8_t value_len,
static uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const void *value, uint8_t value_len,
uint16_t *length)
{
/* 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_head = friend_number;
} else if (session->calls_tail < friend_number) { /* Appending */
MSICall **tmp = (MSICall **)realloc(session->calls, (friend_number + 1) * sizeof(MSICall *));
MSICall **tmp = (MSICall **)realloc(session->calls, sizeof(MSICall *) * (friend_number + 1));
if (tmp == nullptr) {
free(rc);
@@ -657,13 +657,12 @@ CLEAR_CONTAINER:
}
static void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *data)
{
MSISession *session = (MSISession *)data;
if (status != 0) {
// Friend is online.
return;
}
MSISession *session = (MSISession *)data;
LOGGER_DEBUG(m->log, "Friend %d is now offline", friend_number);
pthread_mutex_lock(session->mutex);
@@ -852,10 +851,9 @@ 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)
{
MSISession *session = (MSISession *)object;
LOGGER_DEBUG(m->log, "Got msi message");
MSISession *session = (MSISession *)object;
MSIMessage msg;
if (msg_parse_in(m->log, &msg, data, length) == -1) {

View File

@@ -106,9 +106,8 @@ uint16_t rb_size(const RingBuffer *b)
uint16_t rb_data(const RingBuffer *b, void **dest)
{
uint16_t i;
const uint16_t size = rb_size(b);
for (i = 0; i < size; ++i) {
for (i = 0; i < rb_size(b); ++i) {
dest[i] = b->data[(b->start + i) % b->size];
}

View File

@@ -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_head = friend_number;
} else if (av->calls_tail < friend_number) { /* Appending */
ToxAVCall **tmp = (ToxAVCall **)realloc(av->calls, (friend_number + 1) * sizeof(ToxAVCall *));
ToxAVCall **tmp = (ToxAVCall **)realloc(av->calls, sizeof(ToxAVCall *) * (friend_number + 1));
if (tmp == nullptr) {
pthread_mutex_destroy(call->toxav_call_mutex);

View File

@@ -65,17 +65,15 @@ extern "C" {
/**
* External Tox type.
*/
#ifndef APIGEN_IGNORE
#ifndef TOX_DEFINED
#define TOX_DEFINED
typedef struct Tox Tox;
#endif /* !TOX_DEFINED */
#endif /* !APIGEN_IGNORE */
#endif /* TOX_DEFINED */
/**
* @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
* prior closing Tox instance otherwise undefined behaviour occurs. Upon
* closing of ToxAV instance, all active calls will be forcibly terminated
@@ -607,7 +605,7 @@ typedef enum Toxav_Err_Send_Frame {
* @param sampling_rate Audio sampling rate used in this frame. Valid sampling
* 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);
/**
@@ -654,12 +652,8 @@ void toxav_callback_audio_bit_rate(ToxAV *av, toxav_audio_bit_rate_cb *callback,
* @param u U (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[/*! height * width */],
const uint8_t u[/*! height/2 * width/2 */],
const uint8_t v[/*! height/2 * width/2 */],
Toxav_Err_Send_Frame *error);
bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height, const uint8_t *y,
const uint8_t *u, const uint8_t *v, Toxav_Err_Send_Frame *error);
/**
* Set the bit rate to be used in subsequent video frames.
@@ -709,7 +703,7 @@ void toxav_callback_video_bit_rate(ToxAV *av, toxav_video_bit_rate_cb *callback,
* @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);
@@ -741,13 +735,8 @@ void toxav_callback_audio_receive_frame(ToxAV *av, toxav_audio_receive_frame_cb
* @param ustride U 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,
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,
typedef void toxav_video_receive_frame_cb(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height,
const uint8_t *y, const uint8_t *u, const uint8_t *v, int32_t ystride, int32_t ustride, int32_t vstride,
void *user_data);
@@ -757,8 +746,6 @@ typedef void toxav_video_receive_frame_cb(
*/
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
*
@@ -768,10 +755,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.
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);
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);
/** @brief Create a new toxav group.
@@ -781,7 +768,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)`.
*/
int32_t toxav_add_av_groupchat(Tox *tox, toxav_audio_data_cb *audio_callback, void *userdata);
int 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).
*
@@ -790,9 +777,8 @@ int32_t toxav_add_av_groupchat(Tox *tox, toxav_audio_data_cb *audio_callback, vo
*
* Note that total size of pcm in bytes is equal to `samples * channels * sizeof(int16_t)`.
*/
int32_t toxav_join_av_groupchat(
Tox *tox, uint32_t friendnumber, const uint8_t data[], uint16_t length,
toxav_audio_data_cb *audio_callback, void *userdata);
int toxav_join_av_groupchat(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.
*
@@ -808,9 +794,8 @@ int32_t toxav_join_av_groupchat(
*
* Recommended values are: samples = 960, channels = 1, sample_rate = 48000
*/
int32_t toxav_group_send_audio(
Tox *tox, uint32_t groupnumber, const int16_t pcm[], uint32_t samples, uint8_t channels,
uint32_t sample_rate);
int toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels,
uint32_t sample_rate);
/** @brief Enable A/V in a groupchat.
*
@@ -827,22 +812,19 @@ int32_t toxav_group_send_audio(
*
* Note that total size of pcm in bytes is equal to `samples * channels * sizeof(int16_t)`.
*/
int32_t toxav_groupchat_enable_av(
Tox *tox, uint32_t groupnumber,
toxav_audio_data_cb *audio_callback, void *userdata);
int toxav_groupchat_enable_av(Tox *tox, uint32_t groupnumber,
toxav_audio_data_cb *audio_callback, void *userdata);
/** @brief Disable A/V in a groupchat.
*
* @retval 0 on success.
* @retval -1 on failure.
*/
int32_t toxav_groupchat_disable_av(Tox *tox, uint32_t groupnumber);
int toxav_groupchat_disable_av(Tox *tox, uint32_t groupnumber);
/** @brief Return whether A/V is enabled in the groupchat. */
bool toxav_groupchat_av_enabled(Tox *tox, uint32_t groupnumber);
#endif /* !APIGEN_IGNORE */
/** @} */
#ifdef __cplusplus
@@ -852,7 +834,6 @@ bool toxav_groupchat_av_enabled(Tox *tox, uint32_t groupnumber);
//!TOKSTYLE-
#ifndef DOXYGEN_IGNORE
typedef ToxAV Toxav;
typedef Toxav_Err_Call TOXAV_ERR_CALL;
typedef Toxav_Err_New TOXAV_ERR_NEW;
typedef Toxav_Err_Answer TOXAV_ERR_ANSWER;

View File

@@ -345,18 +345,17 @@ void vc_iterate(VCSession *vc)
int vc_queue_message(Mono_Time *mono_time, void *vcp, struct RTPMessage *msg)
{
VCSession *vc = (VCSession *)vcp;
/* This function is called with complete messages
* they have already been assembled.
* this function gets called from handle_rtp_packet() and handle_rtp_packet_v3()
*/
if (vc == nullptr || msg == nullptr) {
if (vcp == nullptr || msg == nullptr) {
free(msg);
return -1;
}
VCSession *vc = (VCSession *)vcp;
const struct RTPHeader *const header = &msg->header;
if (msg->header.pt == (RTP_TYPE_VIDEO + 2) % 128) {

View File

@@ -10,23 +10,6 @@ exports_files(
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(
name = "attributes",
hdrs = ["attributes.h"],
@@ -88,7 +71,6 @@ cc_test(
srcs = ["util_test.cc"],
deps = [
":crypto_core",
":crypto_core_test_util",
":util",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
@@ -160,16 +142,6 @@ 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(
name = "crypto_core_test",
size = "small",
@@ -177,7 +149,6 @@ cc_test(
flaky = True,
deps = [
":crypto_core",
":crypto_core_test_util",
":util",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
@@ -290,17 +261,6 @@ 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(
name = "network_test",
size = "small",
@@ -397,28 +357,13 @@ 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(
name = "DHT_test",
size = "small",
srcs = ["DHT_test.cc"],
deps = [
":DHT",
":DHT_test_util",
":crypto_core",
":network_test_util",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
@@ -936,7 +881,6 @@ cc_fuzz_test(
srcs = ["tox_events_fuzz_test.cc"],
corpus = ["//tools/toktok-fuzzer/corpus:tox_events_fuzz_test"],
deps = [
":tox_dispatch",
":tox_events",
"//c-toxcore/testing/fuzzing:fuzz_support",
],

View File

@@ -16,15 +16,13 @@
#include "LAN_discovery.h"
#include "bin_pack.h"
#include "ccompat.h"
#include "crypto_core.h"
#include "logger.h"
#include "mem.h"
#include "mono_time.h"
#include "network.h"
#include "ping.h"
#include "ping_array.h"
#include "shared_key_cache.h"
#include "state.h"
#include "util.h"
/** The timeout after which a node is discarded completely. */
#define KILL_NODE_TIMEOUT (BAD_NODE_TIMEOUT + PING_INTERVAL)
@@ -422,8 +420,7 @@ static bool bin_pack_ip_port(Bin_Pack *bp, const Logger *logger, const IP_Port *
non_null()
static bool bin_pack_ip_port_handler(Bin_Pack *bp, const Logger *logger, const void *obj)
{
const IP_Port *ip_port = (const IP_Port *)obj;
return bin_pack_ip_port(bp, logger, ip_port);
return bin_pack_ip_port(bp, logger, (const IP_Port *)obj);
}
int pack_ip_port(const Logger *logger, uint8_t *data, uint16_t length, const IP_Port *ip_port)
@@ -448,8 +445,8 @@ int dht_create_packet(const Memory *mem, const Random *rng,
const uint8_t *plain, size_t plain_length,
uint8_t *packet, size_t length)
{
uint8_t nonce[CRYPTO_NONCE_SIZE];
uint8_t *encrypted = (uint8_t *)mem_balloc(mem, plain_length + CRYPTO_MAC_SIZE);
uint8_t nonce[CRYPTO_NONCE_SIZE];
if (encrypted == nullptr) {
return -1;
@@ -511,7 +508,7 @@ int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool
return -1;
}
ipport_reset(ip_port);
*ip_port = empty_ip_port;
if (is_ipv4) {
const uint32_t size = 1 + SIZE_IP4 + sizeof(uint16_t);
@@ -750,21 +747,16 @@ static bool client_or_ip_port_in_list(const Logger *log, const Mono_Time *mono_t
return true;
}
bool add_to_list(
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])
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)
{
for (uint32_t i = 0; i < length; ++i) {
Node_format *node = &nodes_list[i];
if (id_closest(cmp_pk, node->public_key, pk) == 2) {
if (id_closest(cmp_pk, nodes_list[i].public_key, pk) == 2) {
uint8_t pk_bak[CRYPTO_PUBLIC_KEY_SIZE];
memcpy(pk_bak, node->public_key, CRYPTO_PUBLIC_KEY_SIZE);
const IP_Port ip_port_bak = node->ip_port;
memcpy(node->public_key, pk, CRYPTO_PUBLIC_KEY_SIZE);
node->ip_port = *ip_port;
memcpy(pk_bak, nodes_list[i].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);
nodes_list[i].ip_port = *ip_port;
if (i != length - 1) {
add_to_list(nodes_list, length, pk_bak, &ip_port_bak, cmp_pk);
@@ -781,11 +773,10 @@ bool add_to_list(
* helper for `get_close_nodes()`. argument list is a monster :D
*/
non_null()
static void get_close_nodes_inner(
uint64_t cur_time, const uint8_t *public_key,
Node_format *nodes_list, uint32_t *num_nodes_ptr,
Family sa_family, const Client_data *client_list, uint32_t client_list_length,
bool is_lan, bool want_announce)
static void get_close_nodes_inner(uint64_t cur_time, const uint8_t *public_key, Node_format *nodes_list,
Family sa_family, const Client_data *client_list, uint32_t client_list_length,
uint32_t *num_nodes_ptr, 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)) {
return;
@@ -852,44 +843,28 @@ static void get_close_nodes_inner(
* want_announce: return only nodes which implement the dht announcements protocol.
*/
non_null()
static int get_somewhat_close_nodes(
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)
static int get_somewhat_close_nodes(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));
uint32_t num_nodes = 0;
get_close_nodes_inner(
cur_time, public_key,
nodes_list, &num_nodes,
sa_family, close_clientlist, LCLIENT_LIST,
is_lan, want_announce);
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 (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);
for (uint32_t i = 0; i < dht->num_friends; ++i) {
get_close_nodes_inner(dht->cur_time, public_key, nodes_list, sa_family,
dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS,
&num_nodes, is_lan, want_announce);
}
return num_nodes;
}
int get_close_nodes(
const DHT *dht, const uint8_t *public_key,
Node_format *nodes_list, Family sa_family,
bool is_lan, bool want_announce)
int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, Family sa_family,
bool is_lan, bool want_announce)
{
return get_somewhat_close_nodes(
dht->cur_time, public_key, nodes_list,
sa_family, dht->close_clientlist,
dht->friends_list, dht->num_friends,
is_lan, want_announce);
memset(nodes_list, 0, MAX_SENT_NODES * sizeof(Node_format));
return get_somewhat_close_nodes(dht, public_key, nodes_list, sa_family,
is_lan, want_announce);
}
typedef struct DHT_Cmp_Data {
@@ -1502,12 +1477,12 @@ static int sendnodes_ipv6(const DHT *dht, const IP_Port *ip_port, const uint8_t
non_null()
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))) {
return 1;
}
DHT *const dht = (DHT *)object;
/* Check if packet is from ourself. */
if (pk_equal(packet + 1, dht->self_public_key)) {
return 1;
@@ -2288,12 +2263,11 @@ non_null()
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)
{
DHT *const dht = (DHT *)object;
if (length != sizeof(uint64_t) + 1) {
return 1;
}
DHT *const dht = (DHT *)object;
uint64_t ping_id;
memcpy(&ping_id, packet + 1, sizeof(uint64_t));
@@ -2925,27 +2899,23 @@ static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *dat
}
mem_delete(dht->mem, dht->loaded_nodes_list);
// Copy to loaded_clients_list
Node_format *nodes = (Node_format *)mem_valloc(dht->mem, MAX_SAVED_DHT_NODES, sizeof(Node_format));
dht->loaded_nodes_list = (Node_format *)mem_valloc(dht->mem, MAX_SAVED_DHT_NODES, sizeof(Node_format));
if (nodes == nullptr) {
if (dht->loaded_nodes_list == nullptr) {
LOGGER_ERROR(dht->log, "could not allocate %u nodes", MAX_SAVED_DHT_NODES);
dht->loaded_num_nodes = 0;
break;
}
const int num = unpack_nodes(nodes, MAX_SAVED_DHT_NODES, nullptr, data, length, false);
const int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, nullptr, data, length, false);
if (num < 0) {
// Unpack error happened, we ignore it.
dht->loaded_num_nodes = 0;
} else {
if (num > 0) {
dht->loaded_num_nodes = num;
} else {
dht->loaded_num_nodes = 0;
}
dht->loaded_nodes_list = nodes;
break;
}

View File

@@ -232,7 +232,7 @@ int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool
non_null()
int dht_create_packet(const Memory *mem, const Random *rng,
const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
const uint8_t *shared_key, uint8_t type,
const uint8_t *shared_key, const uint8_t type,
const uint8_t *plain, size_t plain_length,
uint8_t *packet, size_t length);
@@ -370,8 +370,7 @@ unsigned int bit_by_bit_cmp(const uint8_t *pk1, const uint8_t *pk2);
*/
non_null()
bool add_to_list(
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]);
Node_format *nodes_list, uint32_t length, const uint8_t *pk, const IP_Port *ip_port, const uint8_t *cmp_pk);
/** Return 1 if node can be added to close list, 0 if it can't. */
non_null()
@@ -384,20 +383,18 @@ void set_announce_node(DHT *dht, const uint8_t *public_key);
#endif
/**
* @brief Get the (maximum MAX_SENT_NODES) closest nodes to public_key we know
* 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).
*
* @param sa_family family (IPv4 or IPv6) (0 if we don't care)?
* @param is_lan return some LAN ips (true or false).
* @param want_announce return only nodes which implement the dht announcements protocol.
* sa_family = family (IPv4 or IPv6) (0 if we don't care)?
* is_LAN = return some LAN ips (true or false)
* want_announce: return only nodes which implement the dht announcements protocol.
*
* @return the number of nodes returned.
*/
non_null()
int get_close_nodes(
const DHT *dht, const uint8_t *public_key,
Node_format *nodes_list, Family sa_family,
bool is_lan, bool want_announce);
int get_close_nodes(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.

View File

@@ -23,7 +23,7 @@ void TestHandleRequest(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;
Node_format nodes[node_count];

View File

@@ -1,26 +1,15 @@
#include "DHT.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <algorithm>
#include <array>
#include <cstring>
#include <random>
#include "DHT_test_util.hh"
#include "crypto_core.h"
#include "crypto_core_test_util.hh"
#include "network_test_util.hh"
namespace {
using ::testing::Each;
using ::testing::ElementsAre;
using ::testing::Eq;
using ::testing::PrintToString;
using ::testing::UnorderedElementsAre;
using PublicKey = std::array<uint8_t, CRYPTO_PUBLIC_KEY_SIZE>;
using SecretKey = std::array<uint8_t, CRYPTO_SECRET_KEY_SIZE>;
struct KeyPair {
@@ -30,66 +19,72 @@ struct KeyPair {
explicit KeyPair(const Random *rng) { crypto_new_keypair(rng, pk.data(), sk.data()); }
};
TEST(IdClosest, KeyIsClosestToItself)
template <typename T, size_t N>
std::array<T, N> to_array(T const (&arr)[N])
{
Test_Random rng;
std::array<T, N> stdarr;
std::copy(arr, arr + N, stdarr.begin());
return stdarr;
}
PublicKey pk0 = random_pk(rng);
PublicKey pk1;
do {
// Get a random key that's not the same as pk0.
pk1 = random_pk(rng);
} while (pk0 == pk1);
EXPECT_EQ(id_closest(pk0.data(), pk0.data(), pk1.data()), 1);
PublicKey random_pk(const Random *rng)
{
PublicKey pk;
random_bytes(rng, pk.data(), pk.size());
return pk;
}
TEST(IdClosest, IdenticalKeysAreSameDistance)
{
Test_Random rng;
const Random *rng = system_random();
ASSERT_NE(rng, nullptr);
PublicKey pk0 = random_pk(rng);
PublicKey pk1 = random_pk(rng);
PublicKey pk2 = pk1;
EXPECT_EQ(id_closest(pk0.data(), pk1.data(), pk1.data()), 0);
EXPECT_EQ(id_closest(pk0.data(), pk1.data(), pk2.data()), 0);
}
TEST(IdClosest, DistanceIsCommutative)
{
Test_Random rng;
const Random *rng = system_random();
ASSERT_NE(rng, nullptr);
PublicKey pk0 = random_pk(rng);
PublicKey pk1 = random_pk(rng);
PublicKey pk2 = random_pk(rng);
for (uint32_t i = 0; i < 100; ++i) {
PublicKey pk0 = random_pk(rng);
PublicKey pk1 = 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.
EXPECT_NE(id_closest(pk0.data(), pk1.data(), pk2.data()), 0);
// 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);
if (id_closest(pk0.data(), pk1.data(), pk2.data()) == 1) {
EXPECT_EQ(id_closest(pk0.data(), pk2.data(), pk1.data()), 2);
}
if (id_closest(pk0.data(), pk1.data(), pk2.data()) == 1) {
EXPECT_EQ(id_closest(pk0.data(), pk2.data(), pk1.data()), 2);
}
if (id_closest(pk0.data(), pk1.data(), pk2.data()) == 2) {
EXPECT_EQ(id_closest(pk0.data(), pk2.data(), pk1.data()), 1);
if (id_closest(pk0.data(), pk1.data(), pk2.data()) == 2) {
EXPECT_EQ(id_closest(pk0.data(), pk2.data(), pk1.data()), 1);
}
}
}
TEST(IdClosest, SmallXorDistanceIsCloser)
{
PublicKey const pk0 = {0xaa};
PublicKey const pk1 = {0xa0};
PublicKey const pk2 = {0x0a};
PublicKey const pk0 = {{0xaa}};
PublicKey const pk1 = {{0xa0}};
PublicKey const pk2 = {{0x0a}};
EXPECT_EQ(id_closest(pk0.data(), pk1.data(), pk2.data()), 1);
}
TEST(IdClosest, DistinctKeysCannotHaveTheSameDistance)
{
PublicKey const pk0 = {0x06};
PublicKey const pk1 = {0x00};
PublicKey pk2 = {0x00};
PublicKey const pk0 = {{0x06}};
PublicKey const pk1 = {{0x00}};
PublicKey pk2 = {{0x00}};
for (uint8_t i = 1; i < 0xff; ++i) {
pk2[0] = i;
@@ -99,14 +94,14 @@ TEST(IdClosest, DistinctKeysCannotHaveTheSameDistance)
TEST(AddToList, OverridesKeysWithCloserKeys)
{
PublicKey const self_pk = {0xaa};
PublicKey const self_pk = {{0xaa}};
PublicKey const keys[] = {
{0xa0}, // closest
{0x0a}, //
{0x0b}, //
{0x0c}, //
{0x0d}, //
{0xa1}, // closer than the 4 keys above
{{0xa0}}, // closest
{{0x0a}}, //
{{0x0b}}, //
{{0x0c}}, //
{{0x0d}}, //
{{0xa1}}, // closer than the 4 keys above
};
std::array<Node_format, 4> nodes{};
@@ -133,143 +128,10 @@ TEST(AddToList, OverridesKeysWithCloserKeys)
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_Random rng;
const Random *rng = system_random();
ASSERT_NE(rng, nullptr);
// Peers.
const KeyPair sender(rng);
@@ -325,7 +187,7 @@ TEST(Request, CreateAndParse)
TEST(AnnounceNodes, SetAndTest)
{
Test_Random rng;
const Random *rng = system_random();
const Network *ns = system_network();
const Memory *mem = system_memory();
@@ -333,40 +195,40 @@ TEST(AnnounceNodes, SetAndTest)
ASSERT_NE(log, nullptr);
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
ASSERT_NE(mono_time, nullptr);
Ptr<Networking_Core> net(new_networking_no_udp(log, mem, ns));
Networking_Core *net = new_networking_no_udp(log, mem, ns);
ASSERT_NE(net, nullptr);
Ptr<DHT> dht(new_dht(log, mem, rng, ns, mono_time, net.get(), true, true));
DHT *dht = new_dht(log, mem, rng, ns, mono_time, net, true, true);
ASSERT_NE(dht, nullptr);
uint8_t pk_data[CRYPTO_PUBLIC_KEY_SIZE];
memcpy(pk_data, dht_get_self_public_key(dht.get()), sizeof(pk_data));
PublicKey self_pk(to_array(pk_data));
memcpy(pk_data, dht_get_self_public_key(dht), sizeof(pk_data));
PublicKey self_pk = to_array(pk_data);
PublicKey pk1 = random_pk(rng);
ASSERT_NE(pk1, self_pk);
// Test with maximally close key to self
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);
IP_Port ip_port = {0};
ip_port.ip.family = net_family_ipv4();
set_announce_node(dht.get(), pk1.data());
set_announce_node(dht.get(), pk2.data());
set_announce_node(dht, pk1.data());
set_announce_node(dht, pk2.data());
EXPECT_TRUE(addto_lists(dht.get(), &ip_port, pk1.data()));
EXPECT_TRUE(addto_lists(dht.get(), &ip_port, pk2.data()));
EXPECT_TRUE(addto_lists(dht, &ip_port, pk1.data()));
EXPECT_TRUE(addto_lists(dht, &ip_port, pk2.data()));
Node_format nodes[MAX_SENT_NODES];
EXPECT_EQ(
0, get_close_nodes(dht.get(), self_pk.data(), nodes, net_family_unspec(), true, true));
set_announce_node(dht.get(), pk1.data());
set_announce_node(dht.get(), pk2.data());
EXPECT_EQ(
2, get_close_nodes(dht.get(), self_pk.data(), nodes, net_family_unspec(), true, true));
EXPECT_EQ(0, get_close_nodes(dht, self_pk.data(), nodes, net_family_unspec(), true, true));
set_announce_node(dht, pk1.data());
set_announce_node(dht, pk2.data());
EXPECT_EQ(2, get_close_nodes(dht, self_pk.data(), nodes, net_family_unspec(), true, true));
kill_dht(dht);
kill_networking(net);
mono_time_free(mem, mono_time);
logger_kill(log);
}

View File

@@ -1,29 +0,0 @@
#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 << " }";
}

View File

@@ -1,18 +0,0 @@
#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

View File

@@ -32,7 +32,7 @@
#endif
#ifdef __linux__
#include <linux/if.h>
#include <linux/netdevice.h>
#endif
#if defined(__FreeBSD__) || defined(__DragonFly__)
@@ -41,7 +41,7 @@
#include "ccompat.h"
#include "crypto_core.h"
#include "network.h"
#include "util.h"
#define MAX_INTERFACES 16
@@ -62,38 +62,35 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
return nullptr;
}
IP_ADAPTER_INFO *adapter_info = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
IP_ADAPTER_INFO *pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
unsigned long ulOutBufLen = sizeof(IP_ADAPTER_INFO);
if (adapter_info == nullptr) {
if (pAdapterInfo == nullptr) {
free(broadcast);
return nullptr;
}
unsigned long out_buf_len = sizeof(IP_ADAPTER_INFO);
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen);
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) {
if (pAdapterInfo == nullptr) {
free(broadcast);
return nullptr;
}
adapter_info = new_adapter_info;
}
const int ret = GetAdaptersInfo(adapter_info, &out_buf_len);
const int ret = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen);
if (ret == NO_ERROR) {
IP_ADAPTER_INFO *adapter = adapter_info;
IP_ADAPTER_INFO *pAdapter = pAdapterInfo;
while (adapter != nullptr) {
while (pAdapter != nullptr) {
IP gateway = {0};
IP subnet_mask = {0};
if (addr_parse_ip(adapter->IpAddressList.IpMask.String, &subnet_mask)
&& addr_parse_ip(adapter->GatewayList.IpAddress.String, &gateway)) {
if (addr_parse_ip(pAdapter->IpAddressList.IpMask.String, &subnet_mask)
&& addr_parse_ip(pAdapter->GatewayList.IpAddress.String, &gateway)) {
if (net_family_is_ipv4(gateway.family) && net_family_is_ipv4(subnet_mask.family)) {
IP *ip = &broadcast->ips[broadcast->count];
ip->family = net_family_ipv4();
@@ -109,12 +106,12 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
}
}
adapter = adapter->Next;
pAdapter = pAdapter->Next;
}
}
if (adapter_info != nullptr) {
free(adapter_info);
if (pAdapterInfo != nullptr) {
free(pAdapterInfo);
}
return broadcast;
@@ -246,11 +243,11 @@ static IP broadcast_ip(Family family_socket, Family family_broadcast)
ip.ip.v6.uint8[15] = 0x01;
} else if (net_family_is_ipv4(family_broadcast)) {
ip.family = net_family_ipv6();
ip.ip.v6 = get_ip6_broadcast();
ip.ip.v6 = ip6_broadcast;
}
} else if (net_family_is_ipv4(family_socket) && net_family_is_ipv4(family_broadcast)) {
ip.family = net_family_ipv4();
ip.ip.v4 = get_ip4_broadcast();
ip.ip.v4 = ip4_broadcast;
}
return ip;

View File

@@ -10,33 +10,17 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.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 "crypto_core.h"
#include "forwarding.h"
#include "friend_connection.h"
#include "friend_requests.h"
#include "group_announce.h"
#include "group_chats.h"
#include "group_common.h"
#include "group_onion_announce.h"
#include "logger.h"
#include "mem.h"
#include "mono_time.h"
#include "net_crypto.h"
#include "network.h"
#include "onion.h"
#include "onion_announce.h"
#include "onion_client.h"
#include "state.h"
#include "util.h"
@@ -2401,12 +2385,11 @@ static int m_handle_packet_invite_groupchat(Messenger *m, const int i, const uin
non_null(1, 3) nullable(5)
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) {
return -1;
}
Messenger *m = (Messenger *)object;
const uint8_t packet_id = temp[0];
const uint8_t *data = temp + 1;
const uint16_t data_length = len - 1;
@@ -3193,8 +3176,7 @@ static void pack_groupchats(const GC_Session *c, Bin_Pack *bp)
non_null()
static bool pack_groupchats_handler(Bin_Pack *bp, const Logger *log, const void *obj)
{
const GC_Session *session = (const GC_Session *)obj;
pack_groupchats(session, bp);
pack_groupchats((const GC_Session *)obj, bp);
return true; // TODO(iphydf): Return bool from pack functions.
}

View File

@@ -10,17 +10,12 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "DHT.h"
#include "TCP_common.h"
#include "ccompat.h"
#include "crypto_core.h"
#include "forwarding.h"
#include "logger.h"
#include "mem.h"
#include "mono_time.h"
#include "network.h"
#include "util.h"
typedef struct TCP_Client_Conn {

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