Compare commits
14 Commits
test_large
...
260d3b7818
Author | SHA1 | Date | |
---|---|---|---|
260d3b7818 | |||
83e200df43 | |||
4ebffd8c63 | |||
8923e09b36 | |||
ec4195f18a | |||
062ad7ae80 | |||
aad07611c7 | |||
0dcb66f143 | |||
331c25b0e6 | |||
e50844be06 | |||
4dd7c98c1a | |||
63bad2e99a | |||
9ddeea3d06 | |||
b95f0498b6 |
42
.github/workflows/cd.yml
vendored
42
.github/workflows/cd.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
|||||||
windows:
|
windows:
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
|
|
||||||
runs-on: windows-latest
|
runs-on: windows-2019
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
@ -34,10 +34,50 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
||||||
|
|
||||||
|
- name: temp test
|
||||||
|
run: ${{github.workspace}}/build/bin/mono_time_test.exe
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v3
|
- uses: actions/upload-artifact@v3
|
||||||
|
if: success() || failure()
|
||||||
with:
|
with:
|
||||||
name: ${{ github.event.repository.name }}-windows-msvc-x86_64
|
name: ${{ github.event.repository.name }}-windows-msvc-x86_64
|
||||||
# TODO: do propper packing
|
# TODO: do propper packing
|
||||||
path: |
|
path: |
|
||||||
${{github.workspace}}/build/bin/
|
${{github.workspace}}/build/bin/
|
||||||
|
|
||||||
|
windows-asan:
|
||||||
|
timeout-minutes: 15
|
||||||
|
|
||||||
|
runs-on: windows-2019
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: vcpkg install libsodium:x64-windows-static pthreads:x64-windows-static
|
||||||
|
|
||||||
|
# setup vs env
|
||||||
|
- uses: ilammy/msvc-dev-cmd@v1
|
||||||
|
with:
|
||||||
|
arch: amd64
|
||||||
|
|
||||||
|
- name: Configure CMake
|
||||||
|
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DTOMATO_ASAN=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
||||||
|
|
||||||
|
- name: temp test
|
||||||
|
run: ${{github.workspace}}/build/bin/mono_time_test.exe
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
if: success() || failure()
|
||||||
|
with:
|
||||||
|
name: ${{ github.event.repository.name }}-windows-msvc-asan-x86_64
|
||||||
|
# TODO: do propper packing
|
||||||
|
# TODO: also switch to asan dlls
|
||||||
|
path: |
|
||||||
|
${{github.workspace}}/build/bin/
|
||||||
|
|
||||||
|
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@ -29,6 +29,9 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
||||||
|
|
||||||
|
- name: temp test
|
||||||
|
run: ${{github.workspace}}/build/bin/mono_time_test
|
||||||
|
|
||||||
macos:
|
macos:
|
||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
|
|
||||||
@ -72,3 +75,6 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
||||||
|
|
||||||
|
- name: temp test
|
||||||
|
run: ${{github.workspace}}/build/bin/mono_time_test.exe
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.14...3.24 FATAL_ERROR)
|
||||||
|
|
||||||
# cmake setup begin
|
# cmake setup begin
|
||||||
project(tomato)
|
project(tomato)
|
||||||
@ -18,6 +18,26 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
|||||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||||
|
|
||||||
|
option(TOMATO_ASAN "Build tomato with asan (gcc/clang/msvc)" OFF)
|
||||||
|
|
||||||
|
if (TOMATO_ASAN)
|
||||||
|
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
||||||
|
if (NOT WIN32) # exclude mingw
|
||||||
|
link_libraries(-fsanitize=address)
|
||||||
|
#link_libraries(-fsanitize=address,undefined)
|
||||||
|
#link_libraries(-fsanitize=undefined)
|
||||||
|
message("II enabled ASAN")
|
||||||
|
else()
|
||||||
|
message("!! can not enable ASAN on this platform (gcc/clang + win)")
|
||||||
|
endif()
|
||||||
|
elseif (MSVC)
|
||||||
|
add_compile_options("/fsanitize=address")
|
||||||
|
message("II enabled ASAN")
|
||||||
|
else()
|
||||||
|
message("!! can not enable ASAN on this platform")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# external libs
|
# external libs
|
||||||
add_subdirectory(./external) # before increasing warn levels, sad :(
|
add_subdirectory(./external) # before increasing warn levels, sad :(
|
||||||
|
|
||||||
@ -33,13 +53,8 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL
|
|||||||
#-Wsign-conversion # Warn on sign conversions
|
#-Wsign-conversion # Warn on sign conversions
|
||||||
-Wshadow # Warn if a variable declaration shadows one from a parent context
|
-Wshadow # Warn if a variable declaration shadows one from a parent context
|
||||||
)
|
)
|
||||||
|
|
||||||
if (NOT WIN32)
|
|
||||||
#link_libraries(-fsanitize=address,undefined)
|
|
||||||
#link_libraries(-fsanitize=undefined)
|
|
||||||
endif()
|
|
||||||
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
|
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
|
||||||
if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
if (MSVC)
|
||||||
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||||
else()
|
else()
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
||||||
|
6
external/toxcore/CMakeLists.txt
vendored
6
external/toxcore/CMakeLists.txt
vendored
@ -203,6 +203,10 @@ add_executable(DHT_Bootstrap EXCLUDE_FROM_ALL
|
|||||||
${TOX_DIR}testing/misc_tools.h
|
${TOX_DIR}testing/misc_tools.h
|
||||||
${TOX_DIR}testing/misc_tools.c
|
${TOX_DIR}testing/misc_tools.c
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(DHT_Bootstrap toxcore)
|
target_link_libraries(DHT_Bootstrap toxcore)
|
||||||
|
|
||||||
|
add_executable(mono_time_test
|
||||||
|
./mono_time_test.cc
|
||||||
|
)
|
||||||
|
target_link_libraries(mono_time_test toxcore)
|
||||||
|
target_compile_features(mono_time_test PUBLIC cxx_std_11)
|
||||||
|
@ -6,6 +6,7 @@ CACHEDIR="$HOME/cache"
|
|||||||
|
|
||||||
. ".github/scripts/flags-$CC.sh"
|
. ".github/scripts/flags-$CC.sh"
|
||||||
add_flag -Werror
|
add_flag -Werror
|
||||||
|
add_flag -D_DEBUG
|
||||||
add_flag -fdiagnostics-color=always
|
add_flag -fdiagnostics-color=always
|
||||||
add_flag -fno-omit-frame-pointer
|
add_flag -fno-omit-frame-pointer
|
||||||
add_flag -fno-sanitize-recover=all
|
add_flag -fno-sanitize-recover=all
|
||||||
|
15
external/toxcore/c-toxcore/.cirrus.yml
vendored
15
external/toxcore/c-toxcore/.cirrus.yml
vendored
@ -9,7 +9,6 @@ bazel-opt_task:
|
|||||||
- /src/workspace/tools/inject-repo c-toxcore
|
- /src/workspace/tools/inject-repo c-toxcore
|
||||||
test_all_script:
|
test_all_script:
|
||||||
- cd /src/workspace && bazel test -k
|
- cd /src/workspace && bazel test -k
|
||||||
--config=ci
|
|
||||||
--build_tag_filters=-haskell
|
--build_tag_filters=-haskell
|
||||||
--test_tag_filters=-haskell
|
--test_tag_filters=-haskell
|
||||||
--
|
--
|
||||||
@ -26,7 +25,6 @@ bazel-dbg_task:
|
|||||||
- /src/workspace/tools/inject-repo c-toxcore
|
- /src/workspace/tools/inject-repo c-toxcore
|
||||||
test_all_script:
|
test_all_script:
|
||||||
- cd /src/workspace && bazel test -k
|
- cd /src/workspace && bazel test -k
|
||||||
--config=ci
|
|
||||||
--build_tag_filters=-haskell
|
--build_tag_filters=-haskell
|
||||||
--test_tag_filters=-haskell
|
--test_tag_filters=-haskell
|
||||||
--
|
--
|
||||||
@ -43,8 +41,19 @@ cimple_task:
|
|||||||
- /src/workspace/tools/inject-repo c-toxcore
|
- /src/workspace/tools/inject-repo c-toxcore
|
||||||
test_all_script:
|
test_all_script:
|
||||||
- cd /src/workspace && bazel test -k
|
- cd /src/workspace && bazel test -k
|
||||||
--config=ci
|
|
||||||
--build_tag_filters=haskell
|
--build_tag_filters=haskell
|
||||||
--test_tag_filters=haskell
|
--test_tag_filters=haskell
|
||||||
--
|
--
|
||||||
//c-toxcore/...
|
//c-toxcore/...
|
||||||
|
|
||||||
|
freebsd_task:
|
||||||
|
container:
|
||||||
|
image: toxchat/freebsd:latest
|
||||||
|
cpu: 2
|
||||||
|
memory: 4G
|
||||||
|
kvm: true
|
||||||
|
configure_script:
|
||||||
|
- git submodule update --init --recursive
|
||||||
|
- cd .. && mv cirrus-ci-build /work/c-toxcore && mkdir cirrus-ci-build
|
||||||
|
test_all_script:
|
||||||
|
- cd /work/c-toxcore && .github/scripts/cmake-freebsd
|
||||||
|
2
external/toxcore/c-toxcore/.dockerignore
vendored
Normal file
2
external/toxcore/c-toxcore/.dockerignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/_build
|
||||||
|
/_install
|
55
external/toxcore/c-toxcore/.github/scripts/cmake-alpine-s390x
vendored
Executable file
55
external/toxcore/c-toxcore/.github/scripts/cmake-alpine-s390x
vendored
Executable file
@ -0,0 +1,55 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright (C) 2018-2023 nurupo
|
||||||
|
|
||||||
|
# Toxcore building
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
cd .. # /work
|
||||||
|
. cmake-alpine-run.sh
|
||||||
|
|
||||||
|
# === Get VM ready to build the code ===
|
||||||
|
|
||||||
|
start_vm
|
||||||
|
|
||||||
|
RUN apk add cmake g++ ninja
|
||||||
|
|
||||||
|
mv c-toxcore /
|
||||||
|
|
||||||
|
# Copy over toxcore code from host to qemu
|
||||||
|
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P "$SSH_PORT" -r /c-toxcore root@localhost:~
|
||||||
|
|
||||||
|
cd /c-toxcore
|
||||||
|
. ".github/scripts/flags-gcc.sh"
|
||||||
|
|
||||||
|
# Make compilation error on a warning
|
||||||
|
add_flag -Werror
|
||||||
|
|
||||||
|
# - disabling toxav because vpx doesn't work on s390x.
|
||||||
|
# - disabling bootstrap daemons because we don't need them for testing (saving time).
|
||||||
|
# - disabling shared libraries because it saves a lot of time on building PIC objects.
|
||||||
|
# - enable unity build because it saves a lot of time as well (fewer objects to build).
|
||||||
|
RUN "cmake -B_build -Hc-toxcore -GNinja \
|
||||||
|
-DCMAKE_C_FLAGS='$C_FLAGS' \
|
||||||
|
-DCMAKE_CXX_FLAGS='$CXX_FLAGS' \
|
||||||
|
-DCMAKE_EXE_LINKER_FLAGS='$LD_FLAGS' \
|
||||||
|
-DCMAKE_SHARED_LINKER_FLAGS='$LD_FLAGS' \
|
||||||
|
-DCMAKE_INSTALL_PREFIX:PATH='_install' \
|
||||||
|
-DCMAKE_UNITY_BUILD=ON \
|
||||||
|
-DMIN_LOGGER_LEVEL=TRACE \
|
||||||
|
-DNON_HERMETIC_TESTS=ON \
|
||||||
|
-DENABLE_SHARED=OFF \
|
||||||
|
-DBUILD_TOXAV=OFF \
|
||||||
|
-DDHT_BOOTSTRAP=OFF \
|
||||||
|
-DBOOTSTRAP_DAEMON=OFF \
|
||||||
|
-DSTRICT_ABI=ON \
|
||||||
|
-DTEST_TIMEOUT_SECONDS=90 \
|
||||||
|
-DUSE_IPV6=OFF \
|
||||||
|
-DAUTOTEST=ON"
|
||||||
|
|
||||||
|
RUN 'cmake --build _build --parallel 2 --target install -- -k 0'
|
||||||
|
RUN 'cd _build && ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:1 --timeout 90 || true' &
|
||||||
|
|
||||||
|
# Give the tests 5 minutes to run. Sometimes, the per-test timeout doesn't
|
||||||
|
# work, so we put a global timeout here for everything.
|
||||||
|
sleep 300
|
58
external/toxcore/c-toxcore/.github/scripts/cmake-freebsd
vendored
Executable file
58
external/toxcore/c-toxcore/.github/scripts/cmake-freebsd
vendored
Executable file
@ -0,0 +1,58 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright (C) 2018-2023 nurupo
|
||||||
|
|
||||||
|
# Toxcore building
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
cd .. # /work
|
||||||
|
. cmake-freebsd-run.sh
|
||||||
|
|
||||||
|
# === Get VM ready to build the code ===
|
||||||
|
|
||||||
|
# Unpack image only if it's compressed.
|
||||||
|
if [ -f "$IMAGE_NAME.gz" ]; then
|
||||||
|
gunzip "$IMAGE_NAME.gz"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mv c-toxcore /
|
||||||
|
|
||||||
|
start_vm
|
||||||
|
|
||||||
|
# Copy over toxcore code from host to qemu
|
||||||
|
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P "$SSH_PORT" -r /c-toxcore root@localhost:~
|
||||||
|
|
||||||
|
RUN ls -lh
|
||||||
|
|
||||||
|
cd /c-toxcore
|
||||||
|
. '.github/scripts/flags-clang.sh'
|
||||||
|
|
||||||
|
add_ld_flag -Wl,-z,defs
|
||||||
|
|
||||||
|
# Make compilation error on a warning.
|
||||||
|
add_flag -Werror
|
||||||
|
|
||||||
|
# This triggers on FreeBSD's clang.
|
||||||
|
add_flag -Wno-format
|
||||||
|
add_flag -Wno-unsafe-buffer-usage
|
||||||
|
|
||||||
|
RUN "cmake -B_build -Hc-toxcore \
|
||||||
|
-DCMAKE_C_FLAGS='$C_FLAGS' \
|
||||||
|
-DCMAKE_CXX_FLAGS='$CXX_FLAGS' \
|
||||||
|
-DCMAKE_EXE_LINKER_FLAGS='$LD_FLAGS' \
|
||||||
|
-DCMAKE_SHARED_LINKER_FLAGS='$LD_FLAGS' \
|
||||||
|
-DCMAKE_INSTALL_PREFIX:PATH='_install' \
|
||||||
|
-DMIN_LOGGER_LEVEL=TRACE \
|
||||||
|
-DMUST_BUILD_TOXAV=ON \
|
||||||
|
-DNON_HERMETIC_TESTS=ON \
|
||||||
|
-DSTRICT_ABI=ON \
|
||||||
|
-DTEST_TIMEOUT_SECONDS=120 \
|
||||||
|
-DUSE_IPV6=OFF \
|
||||||
|
-DAUTOTEST=ON"
|
||||||
|
|
||||||
|
# We created the VM with the same number of cores as the host, so the host-ran `nproc` here is fine.
|
||||||
|
RUN 'cmake --build _build --parallel "$NPROC" --target install -- -k'
|
||||||
|
RUN 'cd _build && ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:2 --timeout 120 || true'
|
||||||
|
|
||||||
|
# Gracefully shut down the VM.
|
||||||
|
stop_vm
|
@ -1,52 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# Copyright (C) 2018-2021 nurupo
|
|
||||||
|
|
||||||
# Toxcore building
|
|
||||||
|
|
||||||
set -eux
|
|
||||||
|
|
||||||
if [ "$PWD" != "/work" ]; then
|
|
||||||
cd ..
|
|
||||||
mv c-toxcore /
|
|
||||||
mkdir c-toxcore
|
|
||||||
cd /work
|
|
||||||
fi
|
|
||||||
|
|
||||||
. cmake-freebsd-run.sh
|
|
||||||
|
|
||||||
# === Get VM ready to build the code ===
|
|
||||||
|
|
||||||
gunzip "$IMAGE_NAME.gz"
|
|
||||||
|
|
||||||
start_vm
|
|
||||||
|
|
||||||
# Copy over toxcore code from host to qemu
|
|
||||||
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -P "$SSH_PORT" -r /c-toxcore root@localhost:~
|
|
||||||
|
|
||||||
RUN ls -lh
|
|
||||||
|
|
||||||
cd /c-toxcore
|
|
||||||
. ".github/scripts/flags-clang.sh"
|
|
||||||
|
|
||||||
add_ld_flag -Wl,-z,defs
|
|
||||||
|
|
||||||
# Make compilation error on a warning
|
|
||||||
add_flag -Werror
|
|
||||||
|
|
||||||
RUN 'cmake -B_build -Hc-toxcore \
|
|
||||||
-DCMAKE_C_FLAGS="$C_FLAGS" \
|
|
||||||
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
|
|
||||||
-DCMAKE_EXE_LINKER_FLAGS="$LD_FLAGS" \
|
|
||||||
-DCMAKE_SHARED_LINKER_FLAGS="$LD_FLAGS" \
|
|
||||||
-DCMAKE_INSTALL_PREFIX:PATH="_install" \
|
|
||||||
-DMIN_LOGGER_LEVEL=TRACE \
|
|
||||||
-DMUST_BUILD_TOXAV=ON \
|
|
||||||
-DNON_HERMETIC_TESTS=ON \
|
|
||||||
-DSTRICT_ABI=ON \
|
|
||||||
-DTEST_TIMEOUT_SECONDS=90 \
|
|
||||||
-DUSE_IPV6=OFF \
|
|
||||||
-DAUTOTEST=ON'
|
|
||||||
|
|
||||||
# We created the VM with the same number of cores as the host, so the host-ran `nproc` here is fine
|
|
||||||
RUN 'gmake "-j$NPROC" -k install -C_build'
|
|
||||||
RUN 'gmake "-j$NPROC" test ARGS="-j50" -C_build || true'
|
|
@ -28,8 +28,6 @@ add_flag -O3 -march=native
|
|||||||
|
|
||||||
# Warn on non-ISO C.
|
# Warn on non-ISO C.
|
||||||
add_c_flag -pedantic
|
add_c_flag -pedantic
|
||||||
add_c_flag -std=c99
|
|
||||||
add_cxx_flag -std=c++11
|
|
||||||
|
|
||||||
add_flag -g3
|
add_flag -g3
|
||||||
add_flag -ftrapv
|
add_flag -ftrapv
|
||||||
|
30
external/toxcore/c-toxcore/.github/settings.yml
vendored
30
external/toxcore/c-toxcore/.github/settings.yml
vendored
@ -12,36 +12,52 @@ branches:
|
|||||||
protection:
|
protection:
|
||||||
required_status_checks:
|
required_status_checks:
|
||||||
contexts:
|
contexts:
|
||||||
- "bazel-asan"
|
|
||||||
- "bazel-dbg"
|
- "bazel-dbg"
|
||||||
- "bazel-opt"
|
- "bazel-opt"
|
||||||
- "bazel-tsan"
|
- "build-alpine-s390x"
|
||||||
|
- "build-android"
|
||||||
- "build-compcert"
|
- "build-compcert"
|
||||||
- "build-macos"
|
- "build-macos"
|
||||||
- "build-nacl"
|
- "build-nacl"
|
||||||
- "build-tcc"
|
- "build-tcc"
|
||||||
- "build-win32"
|
- "build-win32"
|
||||||
- "build-win64"
|
- "build-win64"
|
||||||
- "CodeFactor"
|
|
||||||
- "common / buildifier"
|
|
||||||
- "coverage-linux"
|
|
||||||
- "ci/circleci: asan"
|
- "ci/circleci: asan"
|
||||||
|
- "ci/circleci: bazel-asan"
|
||||||
|
- "ci/circleci: bazel-msan"
|
||||||
|
- "ci/circleci: bazel-tsan"
|
||||||
- "ci/circleci: clang-analyze"
|
- "ci/circleci: clang-analyze"
|
||||||
- "ci/circleci: clang-tidy"
|
- "ci/circleci: clang-tidy"
|
||||||
- "ci/circleci: cpplint"
|
- "ci/circleci: cpplint"
|
||||||
- "ci/circleci: infer"
|
- "ci/circleci: infer"
|
||||||
- "ci/circleci: msan"
|
|
||||||
- "ci/circleci: static-analysis"
|
- "ci/circleci: static-analysis"
|
||||||
- "ci/circleci: tsan"
|
- "ci/circleci: tsan"
|
||||||
- "ci/circleci: ubsan"
|
- "ci/circleci: ubsan"
|
||||||
- "cimple"
|
- "cimple"
|
||||||
|
- "cimplefmt"
|
||||||
|
- "CodeFactor"
|
||||||
- "code-review/reviewable"
|
- "code-review/reviewable"
|
||||||
- "continuous-integration/appveyor/pr"
|
- "common / buildifier"
|
||||||
|
- "coverage-linux"
|
||||||
- "docker-bootstrap-node"
|
- "docker-bootstrap-node"
|
||||||
- "docker-bootstrap-node-websocket"
|
- "docker-bootstrap-node-websocket"
|
||||||
|
- "docker-clusterfuzz"
|
||||||
|
- "docker-esp32"
|
||||||
|
- "docker-fuzzer"
|
||||||
- "docker-toxcore-js"
|
- "docker-toxcore-js"
|
||||||
|
- "docker-win32"
|
||||||
|
- "docker-win64"
|
||||||
|
- "doxygen"
|
||||||
|
- "freebsd"
|
||||||
|
- "Hound"
|
||||||
|
- "misra"
|
||||||
- "mypy"
|
- "mypy"
|
||||||
|
- "program-analysis"
|
||||||
- "sonar-scan"
|
- "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 specific to c-toxcore.
|
||||||
labels:
|
labels:
|
||||||
|
123
external/toxcore/c-toxcore/.github/workflows/ci.yml
vendored
123
external/toxcore/c-toxcore/.github/workflows/ci.yml
vendored
@ -60,15 +60,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
file: other/docker/misra/Dockerfile
|
file: other/docker/misra/Dockerfile
|
||||||
|
|
||||||
cimplefmt:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: recursive
|
|
||||||
- name: Run cimplefmt
|
|
||||||
run: other/docker/cimplefmt/run -u $(find tox* -name "*.[ch]")
|
|
||||||
|
|
||||||
build-nacl:
|
build-nacl:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@ -79,6 +70,35 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
file: other/docker/autotools/Dockerfile
|
file: other/docker/autotools/Dockerfile
|
||||||
|
|
||||||
|
build-tcc:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
- name: Docker Build
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
file: other/docker/tcc/Dockerfile
|
||||||
|
|
||||||
|
build-compcert:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
- name: Docker Build
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
file: other/docker/compcert/Dockerfile
|
||||||
|
|
||||||
|
cimplefmt:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
- name: Run cimplefmt
|
||||||
|
run: other/docker/cimplefmt/run -u $(find tox* -name "*.[ch]")
|
||||||
|
|
||||||
build-win32:
|
build-win32:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@ -97,16 +117,6 @@ jobs:
|
|||||||
- name: Cross compilation
|
- name: Cross compilation
|
||||||
run: .github/scripts/cmake-win64 script
|
run: .github/scripts/cmake-win64 script
|
||||||
|
|
||||||
build-freebsd:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container: toxchat/freebsd
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: recursive
|
|
||||||
- name: Build on FreeBSD
|
|
||||||
run: .github/scripts/cmake-freebsd-stage2
|
|
||||||
|
|
||||||
build-macos:
|
build-macos:
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
steps:
|
steps:
|
||||||
@ -125,81 +135,6 @@ jobs:
|
|||||||
- name: Build, test, and upload coverage
|
- name: Build, test, and upload coverage
|
||||||
run: .github/scripts/coverage-linux
|
run: .github/scripts/coverage-linux
|
||||||
|
|
||||||
build-tcc:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: recursive
|
|
||||||
- name: Install dependencies
|
|
||||||
run:
|
|
||||||
sudo apt-get install -y --no-install-recommends
|
|
||||||
tcc
|
|
||||||
libconfig-dev
|
|
||||||
libopus-dev
|
|
||||||
libsodium-dev
|
|
||||||
libvpx-dev
|
|
||||||
- name: Build with TCC
|
|
||||||
run:
|
|
||||||
tcc
|
|
||||||
-Dinline=static
|
|
||||||
-o send_message_test
|
|
||||||
-Wall -Werror
|
|
||||||
-bench -g
|
|
||||||
auto_tests/auto_test_support.c
|
|
||||||
auto_tests/send_message_test.c
|
|
||||||
testing/misc_tools.c
|
|
||||||
toxav/*.c
|
|
||||||
toxcore/*.c
|
|
||||||
toxcore/*/*.c
|
|
||||||
toxencryptsave/*.c
|
|
||||||
third_party/cmp/*.c
|
|
||||||
$(pkg-config --cflags --libs libsodium opus vpx)
|
|
||||||
- name: Run the test
|
|
||||||
run: "./send_message_test | grep 'tox clients connected'"
|
|
||||||
- name: Build amalgamation file with TCC
|
|
||||||
run:
|
|
||||||
other/make_single_file
|
|
||||||
auto_tests/auto_test_support.c
|
|
||||||
auto_tests/send_message_test.c
|
|
||||||
testing/misc_tools.c |
|
|
||||||
tcc -
|
|
||||||
-o send_message_test
|
|
||||||
-Wall -Werror
|
|
||||||
-bench -g
|
|
||||||
$(pkg-config --cflags --libs libsodium opus vpx)
|
|
||||||
- name: Run the test again
|
|
||||||
run: "./send_message_test | grep 'tox clients connected'"
|
|
||||||
|
|
||||||
build-compcert:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container: toxchat/compcert
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: recursive
|
|
||||||
- name: Build with CompCert
|
|
||||||
run:
|
|
||||||
ccomp
|
|
||||||
-o send_message_test
|
|
||||||
-Wall -Werror
|
|
||||||
-Wno-c11-extensions
|
|
||||||
-Wno-unknown-pragmas
|
|
||||||
-Wno-unused-variable
|
|
||||||
-fstruct-passing -fno-unprototyped -g
|
|
||||||
auto_tests/auto_test_support.c
|
|
||||||
auto_tests/send_message_test.c
|
|
||||||
testing/misc_tools.c
|
|
||||||
toxav/*.c
|
|
||||||
toxcore/*.c
|
|
||||||
toxcore/*/*.c
|
|
||||||
toxencryptsave/*.c
|
|
||||||
third_party/cmp/*.c
|
|
||||||
-D__COMPCERT__ -DDISABLE_VLA -Dinline=
|
|
||||||
-lpthread $(pkg-config --cflags --libs libsodium opus vpx)
|
|
||||||
- name: Run the test
|
|
||||||
run: "./send_message_test | grep 'tox clients connected'"
|
|
||||||
|
|
||||||
build-android:
|
build-android:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
@ -6,6 +6,11 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
branches: [master]
|
branches: [master]
|
||||||
|
|
||||||
|
# Cancel old PR builds when pushing new commits.
|
||||||
|
concurrency:
|
||||||
|
group: docker-${{ github.event.pull_request.number || github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
docker-bootstrap-node:
|
docker-bootstrap-node:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
16
external/toxcore/c-toxcore/.github/workflows/post-submit.yml
vendored
Normal file
16
external/toxcore/c-toxcore/.github/workflows/post-submit.yml
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
name: post-submit
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-alpine-s390x:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
- name: Docker Build
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
file: other/docker/alpine-s390x/Dockerfile
|
@ -6,11 +6,16 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
branches: [master]
|
branches: [master]
|
||||||
|
|
||||||
|
# Cancel old PR builds when pushing new commits.
|
||||||
|
concurrency:
|
||||||
|
group: scan-${{ github.event.pull_request.number || github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
sonar-scan:
|
sonar-scan:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
SONAR_SCANNER_VERSION: 4.4.0.2170
|
SONAR_SCANNER_VERSION: 5.0.1.3006
|
||||||
SONAR_SERVER_URL: "https://sonarcloud.io"
|
SONAR_SERVER_URL: "https://sonarcloud.io"
|
||||||
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
|
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
|
||||||
steps:
|
steps:
|
||||||
@ -18,10 +23,10 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
- name: Set up JDK 11
|
- name: Set up JDK 17
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 11
|
java-version: 17
|
||||||
- name: Download and set up sonar-scanner
|
- name: Download and set up sonar-scanner
|
||||||
env:
|
env:
|
||||||
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
|
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
|
||||||
|
5
external/toxcore/c-toxcore/BUILD.bazel
vendored
5
external/toxcore/c-toxcore/BUILD.bazel
vendored
@ -1,8 +1,6 @@
|
|||||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||||
load("//tools/project:build_defs.bzl", "project")
|
load("//tools/project:build_defs.bzl", "project")
|
||||||
|
|
||||||
package(features = ["layering_check"])
|
|
||||||
|
|
||||||
project()
|
project()
|
||||||
|
|
||||||
genrule(
|
genrule(
|
||||||
@ -10,16 +8,19 @@ genrule(
|
|||||||
srcs = [
|
srcs = [
|
||||||
"//c-toxcore/toxav:toxav.h",
|
"//c-toxcore/toxav:toxav.h",
|
||||||
"//c-toxcore/toxcore:tox.h",
|
"//c-toxcore/toxcore:tox.h",
|
||||||
|
"//c-toxcore/toxcore:tox_private.h",
|
||||||
"//c-toxcore/toxencryptsave:toxencryptsave.h",
|
"//c-toxcore/toxencryptsave:toxencryptsave.h",
|
||||||
],
|
],
|
||||||
outs = [
|
outs = [
|
||||||
"tox/toxav.h",
|
"tox/toxav.h",
|
||||||
"tox/tox.h",
|
"tox/tox.h",
|
||||||
|
"tox/tox_private.h",
|
||||||
"tox/toxencryptsave.h",
|
"tox/toxencryptsave.h",
|
||||||
],
|
],
|
||||||
cmd = """
|
cmd = """
|
||||||
cp $(location //c-toxcore/toxav:toxav.h) $(GENDIR)/c-toxcore/tox/toxav.h
|
cp $(location //c-toxcore/toxav:toxav.h) $(GENDIR)/c-toxcore/tox/toxav.h
|
||||||
cp $(location //c-toxcore/toxcore:tox.h) $(GENDIR)/c-toxcore/tox/tox.h
|
cp $(location //c-toxcore/toxcore:tox.h) $(GENDIR)/c-toxcore/tox/tox.h
|
||||||
|
cp $(location //c-toxcore/toxcore:tox_private.h) $(GENDIR)/c-toxcore/tox/tox_private.h
|
||||||
cp $(location //c-toxcore/toxencryptsave:toxencryptsave.h) $(GENDIR)/c-toxcore/tox/toxencryptsave.h
|
cp $(location //c-toxcore/toxencryptsave:toxencryptsave.h) $(GENDIR)/c-toxcore/tox/toxencryptsave.h
|
||||||
""",
|
""",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
|
20
external/toxcore/c-toxcore/CMakeLists.txt
vendored
20
external/toxcore/c-toxcore/CMakeLists.txt
vendored
@ -14,8 +14,8 @@
|
|||||||
#
|
#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.8.12)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
cmake_policy(VERSION 2.8.12)
|
cmake_policy(VERSION 3.5)
|
||||||
project(toxcore)
|
project(toxcore)
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH ${toxcore_SOURCE_DIR}/cmake)
|
list(APPEND CMAKE_MODULE_PATH ${toxcore_SOURCE_DIR}/cmake)
|
||||||
@ -79,21 +79,19 @@ enable_testing()
|
|||||||
|
|
||||||
set(CMAKE_MACOSX_RPATH ON)
|
set(CMAKE_MACOSX_RPATH ON)
|
||||||
|
|
||||||
if(${CMAKE_VERSION} VERSION_LESS "3.1.0")
|
|
||||||
if(NOT MSVC)
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
# Set standard version for compiler.
|
# Set standard version for compiler.
|
||||||
|
if(MSVC)
|
||||||
|
# https://developercommunity.visualstudio.com/t/older-winsdk-headers-are-incompatible-with-zcprepr/1593479
|
||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
|
else()
|
||||||
|
set(CMAKE_C_STANDARD 11)
|
||||||
|
endif()
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_C_EXTENSIONS OFF)
|
set(CMAKE_C_EXTENSIONS OFF)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
message(STATUS "Supported C compiler features = ${CMAKE_C_COMPILE_FEATURES}")
|
message(STATUS "Supported C compiler features = ${CMAKE_C_COMPILE_FEATURES}")
|
||||||
message(STATUS "Supported C++ compiler features = ${CMAKE_CXX_COMPILE_FEATURES}")
|
message(STATUS "Supported C++ compiler features = ${CMAKE_CXX_COMPILE_FEATURES}")
|
||||||
endif()
|
|
||||||
|
|
||||||
set(MIN_LOGGER_LEVEL "" CACHE STRING "Logging level to use (TRACE, DEBUG, INFO, WARNING, ERROR)")
|
set(MIN_LOGGER_LEVEL "" CACHE STRING "Logging level to use (TRACE, DEBUG, INFO, WARNING, ERROR)")
|
||||||
if(MIN_LOGGER_LEVEL)
|
if(MIN_LOGGER_LEVEL)
|
||||||
@ -336,7 +334,8 @@ set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium)
|
|||||||
set(toxcore_API_HEADERS
|
set(toxcore_API_HEADERS
|
||||||
${toxcore_SOURCE_DIR}/toxcore/tox.h^tox
|
${toxcore_SOURCE_DIR}/toxcore/tox.h^tox
|
||||||
${toxcore_SOURCE_DIR}/toxcore/tox_events.h^tox
|
${toxcore_SOURCE_DIR}/toxcore/tox_events.h^tox
|
||||||
${toxcore_SOURCE_DIR}/toxcore/tox_dispatch.h^tox)
|
${toxcore_SOURCE_DIR}/toxcore/tox_dispatch.h^tox
|
||||||
|
${toxcore_SOURCE_DIR}/toxcore/tox_private.h^tox)
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
@ -454,6 +453,7 @@ unit_test(toxcore bin_pack)
|
|||||||
unit_test(toxcore crypto_core)
|
unit_test(toxcore crypto_core)
|
||||||
unit_test(toxcore group_announce)
|
unit_test(toxcore group_announce)
|
||||||
unit_test(toxcore group_moderation)
|
unit_test(toxcore group_moderation)
|
||||||
|
unit_test(toxcore list)
|
||||||
unit_test(toxcore mem)
|
unit_test(toxcore mem)
|
||||||
unit_test(toxcore mono_time)
|
unit_test(toxcore mono_time)
|
||||||
unit_test(toxcore ping_array)
|
unit_test(toxcore ping_array)
|
||||||
|
2
external/toxcore/c-toxcore/README.md
vendored
2
external/toxcore/c-toxcore/README.md
vendored
@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
[**Website**](https://tox.chat) **|** [**Wiki**](https://wiki.tox.chat/) **|** [**Blog**](https://blog.tox.chat/) **|** [**FAQ**](https://wiki.tox.chat/doku.php?id=users:faq) **|** [**Binaries/Downloads**](https://tox.chat/download.html) **|** [**Clients**](https://wiki.tox.chat/doku.php?id=clients) **|** [**Compiling**](/INSTALL.md)
|
[**Website**](https://tox.chat) **|** [**Wiki**](https://wiki.tox.chat/) **|** [**Blog**](https://blog.tox.chat/) **|** [**FAQ**](https://wiki.tox.chat/doku.php?id=users:faq) **|** [**Binaries/Downloads**](https://tox.chat/download.html) **|** [**Clients**](https://wiki.tox.chat/doku.php?id=clients) **|** [**Compiling**](/INSTALL.md)
|
||||||
|
|
||||||
**IRC Channels:** Users: [#tox@libera.chat](https://web.libera.chat/#tox), Developers: [#toktok@libera.chat](https://web.libera.chat/#toktok)
|
|
||||||
|
|
||||||
## What is Tox
|
## What is Tox
|
||||||
|
|
||||||
Tox is a peer to peer (serverless) instant messenger aimed at making security
|
Tox is a peer to peer (serverless) instant messenger aimed at making security
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
|
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
|
||||||
|
|
||||||
package(features = ["layering_check"])
|
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "check_compat",
|
name = "check_compat",
|
||||||
testonly = True,
|
testonly = True,
|
||||||
|
@ -269,6 +269,30 @@ static void test_large_data_symmetric(void)
|
|||||||
free(m1);
|
free(m1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_very_large_data(void)
|
||||||
|
{
|
||||||
|
const Random *rng = system_random();
|
||||||
|
ck_assert(rng != nullptr);
|
||||||
|
|
||||||
|
uint8_t nonce[CRYPTO_NONCE_SIZE] = {0};
|
||||||
|
uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE];
|
||||||
|
uint8_t sk[CRYPTO_SECRET_KEY_SIZE];
|
||||||
|
crypto_new_keypair(rng, pk, sk);
|
||||||
|
|
||||||
|
// 100 MiB of data (all zeroes, doesn't matter what's inside).
|
||||||
|
const uint32_t plain_size = 100 * 1024 * 1024;
|
||||||
|
uint8_t *plain = (uint8_t *)malloc(plain_size);
|
||||||
|
uint8_t *encrypted = (uint8_t *)malloc(plain_size + CRYPTO_MAC_SIZE);
|
||||||
|
|
||||||
|
ck_assert(plain != nullptr);
|
||||||
|
ck_assert(encrypted != nullptr);
|
||||||
|
|
||||||
|
encrypt_data(pk, sk, nonce, plain, plain_size, encrypted);
|
||||||
|
|
||||||
|
free(encrypted);
|
||||||
|
free(plain);
|
||||||
|
}
|
||||||
|
|
||||||
static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num)
|
static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num)
|
||||||
{
|
{
|
||||||
uint32_t num1 = 0;
|
uint32_t num1 = 0;
|
||||||
@ -340,6 +364,7 @@ int main(void)
|
|||||||
test_endtoend(); /* waiting up to 15 seconds */
|
test_endtoend(); /* waiting up to 15 seconds */
|
||||||
test_large_data();
|
test_large_data();
|
||||||
test_large_data_symmetric();
|
test_large_data_symmetric();
|
||||||
|
test_very_large_data();
|
||||||
test_increment_nonce();
|
test_increment_nonce();
|
||||||
test_memzero();
|
test_memzero();
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ static void test_dht_getnodes(AutoTox *autotoxes)
|
|||||||
tox_self_get_dht_id(autotoxes[i].tox, public_key_list[i]);
|
tox_self_get_dht_id(autotoxes[i].tox, public_key_list[i]);
|
||||||
tox_callback_dht_get_nodes_response(autotoxes[i].tox, getnodes_response_cb);
|
tox_callback_dht_get_nodes_response(autotoxes[i].tox, getnodes_response_cb);
|
||||||
|
|
||||||
printf("Peer %zu dht closenode count total/annouce-capable: %d/%d\n",
|
printf("Peer %zu dht closenode count total/announce-capable: %d/%d\n",
|
||||||
i,
|
i,
|
||||||
tox_dht_get_num_closelist(autotoxes[i].tox),
|
tox_dht_get_num_closelist(autotoxes[i].tox),
|
||||||
tox_dht_get_num_closelist_announce_capable(autotoxes[i].tox)
|
tox_dht_get_num_closelist_announce_capable(autotoxes[i].tox)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "auto_test_support.h"
|
#include "auto_test_support.h"
|
||||||
|
#include "../toxcore/tox_private.h"
|
||||||
|
|
||||||
typedef struct State {
|
typedef struct State {
|
||||||
size_t peer_joined_count;
|
size_t peer_joined_count;
|
||||||
@ -42,6 +43,22 @@ typedef struct State {
|
|||||||
|
|
||||||
#define PEER_LIMIT 20
|
#define PEER_LIMIT 20
|
||||||
|
|
||||||
|
static void print_ip(Tox *tox, uint32_t groupnumber, uint32_t peer_id)
|
||||||
|
{
|
||||||
|
Tox_Err_Group_Peer_Query err;
|
||||||
|
size_t length = tox_group_peer_get_ip_address_size(tox, groupnumber, peer_id, &err);
|
||||||
|
|
||||||
|
ck_assert_msg(err == TOX_ERR_GROUP_PEER_QUERY_OK, "failed to get ip address size: error %d", err);
|
||||||
|
|
||||||
|
uint8_t ip_str[TOX_GROUP_PEER_IP_STRING_MAX_LENGTH];
|
||||||
|
tox_group_peer_get_ip_address(tox, groupnumber, peer_id, ip_str, &err);
|
||||||
|
ip_str[length] = '\0';
|
||||||
|
|
||||||
|
ck_assert_msg(err == TOX_ERR_GROUP_PEER_QUERY_OK, "failed to get ip address: error %d", err);
|
||||||
|
|
||||||
|
fprintf(stderr, "%s\n", ip_str);
|
||||||
|
}
|
||||||
|
|
||||||
static bool all_group_peers_connected(AutoTox *autotoxes, uint32_t tox_count, uint32_t groupnumber, size_t name_length)
|
static bool all_group_peers_connected(AutoTox *autotoxes, uint32_t tox_count, uint32_t groupnumber, size_t name_length)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < tox_count; ++i) {
|
for (size_t i = 0; i < tox_count; ++i) {
|
||||||
@ -119,6 +136,9 @@ static void group_peer_join_handler(Tox *tox, uint32_t groupnumber, uint32_t pee
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "%s joined with IP: ", peer_name);
|
||||||
|
print_ip(tox, groupnumber, peer_id);
|
||||||
|
|
||||||
state->peer_id = peer_id;
|
state->peer_id = peer_id;
|
||||||
++state->peer_joined_count;
|
++state->peer_joined_count;
|
||||||
}
|
}
|
||||||
@ -178,6 +198,11 @@ static void group_peer_self_join_handler(Tox *tox, uint32_t groupnumber, void *u
|
|||||||
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "%d", query_err);
|
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "%d", query_err);
|
||||||
ck_assert(memcmp(topic, TOPIC, TOPIC_LEN) == 0);
|
ck_assert(memcmp(topic, TOPIC, TOPIC_LEN) == 0);
|
||||||
|
|
||||||
|
uint32_t peer_id = tox_group_self_get_peer_id(tox, groupnumber, nullptr);
|
||||||
|
|
||||||
|
fprintf(stderr, "self joined with IP: ");
|
||||||
|
print_ip(tox, groupnumber, peer_id);
|
||||||
|
|
||||||
++state->self_joined_count;
|
++state->self_joined_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,6 +366,7 @@ static void group_announce_test(AutoTox *autotoxes)
|
|||||||
ck_assert(memcmp(tox0_pk_query, tox0_self_pk, TOX_GROUP_PEER_PUBLIC_KEY_SIZE) == 0);
|
ck_assert(memcmp(tox0_pk_query, tox0_self_pk, TOX_GROUP_PEER_PUBLIC_KEY_SIZE) == 0);
|
||||||
|
|
||||||
fprintf(stderr, "Peer 0 disconnecting...\n");
|
fprintf(stderr, "Peer 0 disconnecting...\n");
|
||||||
|
|
||||||
// tox 0 disconnects then reconnects
|
// tox 0 disconnects then reconnects
|
||||||
Tox_Err_Group_Disconnect d_err;
|
Tox_Err_Group_Disconnect d_err;
|
||||||
tox_group_disconnect(tox0, groupnumber, &d_err);
|
tox_group_disconnect(tox0, groupnumber, &d_err);
|
||||||
|
@ -44,6 +44,10 @@ typedef struct State {
|
|||||||
#define TEST_CUSTOM_PACKET "Why'd ya spill yer beans?"
|
#define TEST_CUSTOM_PACKET "Why'd ya spill yer beans?"
|
||||||
#define TEST_CUSTOM_PACKET_LEN (sizeof(TEST_CUSTOM_PACKET) - 1)
|
#define TEST_CUSTOM_PACKET_LEN (sizeof(TEST_CUSTOM_PACKET) - 1)
|
||||||
|
|
||||||
|
#define TEST_CUSTOM_PACKET_LARGE "Where is it I've read that someone condemned to death says or thinks, an hour before his death, that if he had to live on some high rock, on such a narrow ledge that he'd only room to stand, and the ocean, everlasting darkness, everlasting solitude, everlasting tempest around him, if he had to remain standing on a square yard of space all his life, a thousand years, eternity, it were better to live so than to die at once. Only to live, to live and live! Life, whatever it may be! ...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................0123456789"
|
||||||
|
#define TEST_CUSTOM_PACKET_LARGE_LEN (sizeof(TEST_CUSTOM_PACKET_LARGE) - 1)
|
||||||
|
static_assert(TEST_CUSTOM_PACKET_LARGE_LEN == TOX_GROUP_MAX_CUSTOM_LOSSY_PACKET_LENGTH, "Should be max");
|
||||||
|
|
||||||
#define TEST_CUSTOM_PRIVATE_PACKET "This is a custom private packet. Enjoy."
|
#define TEST_CUSTOM_PRIVATE_PACKET "This is a custom private packet. Enjoy."
|
||||||
#define TEST_CUSTOM_PRIVATE_PACKET_LEN (sizeof(TEST_CUSTOM_PRIVATE_PACKET) - 1)
|
#define TEST_CUSTOM_PRIVATE_PACKET_LEN (sizeof(TEST_CUSTOM_PRIVATE_PACKET) - 1)
|
||||||
|
|
||||||
@ -187,6 +191,21 @@ static void group_custom_packet_handler(Tox *tox, uint32_t groupnumber, uint32_t
|
|||||||
++state->custom_packets_received;
|
++state->custom_packets_received;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void group_custom_packet_large_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, const uint8_t *data,
|
||||||
|
size_t length, void *user_data)
|
||||||
|
{
|
||||||
|
ck_assert_msg(length == TEST_CUSTOM_PACKET_LARGE_LEN, "Failed to receive large custom packet. Invalid length: %zu\n", length);
|
||||||
|
|
||||||
|
ck_assert(memcmp(data, TEST_CUSTOM_PACKET_LARGE, length) == 0);
|
||||||
|
|
||||||
|
AutoTox *autotox = (AutoTox *)user_data;
|
||||||
|
ck_assert(autotox != nullptr);
|
||||||
|
|
||||||
|
State *state = (State *)autotox->state;
|
||||||
|
|
||||||
|
++state->custom_packets_received;
|
||||||
|
}
|
||||||
|
|
||||||
static void group_message_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, TOX_MESSAGE_TYPE type,
|
static void group_message_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, TOX_MESSAGE_TYPE type,
|
||||||
const uint8_t *message, size_t length, uint32_t pseudo_msg_id, void *user_data)
|
const uint8_t *message, size_t length, uint32_t pseudo_msg_id, void *user_data)
|
||||||
{
|
{
|
||||||
@ -450,6 +469,19 @@ static void group_message_test(AutoTox *autotoxes)
|
|||||||
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
|
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tox0 sends a large max sized lossy custom packet
|
||||||
|
|
||||||
|
// overwrite callback for larger packet
|
||||||
|
tox_callback_group_custom_packet(tox0, group_custom_packet_large_handler);
|
||||||
|
|
||||||
|
tox_group_send_custom_packet(tox1, group_number, false, (const uint8_t *)TEST_CUSTOM_PACKET_LARGE, TEST_CUSTOM_PACKET_LARGE_LEN,
|
||||||
|
&c_err);
|
||||||
|
ck_assert_msg(c_err == TOX_ERR_GROUP_SEND_CUSTOM_PACKET_OK, "%d", c_err);
|
||||||
|
|
||||||
|
while (state0->custom_packets_received < 3) {
|
||||||
|
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t m[TOX_GROUP_MAX_MESSAGE_LENGTH] = {0};
|
uint8_t m[TOX_GROUP_MAX_MESSAGE_LENGTH] = {0};
|
||||||
|
|
||||||
fprintf(stderr, "Doing lossless packet test...\n");
|
fprintf(stderr, "Doing lossless packet test...\n");
|
||||||
@ -538,6 +570,8 @@ int main(void)
|
|||||||
#undef TEST_PRIVATE_MESSAGE_LEN
|
#undef TEST_PRIVATE_MESSAGE_LEN
|
||||||
#undef TEST_CUSTOM_PACKET
|
#undef TEST_CUSTOM_PACKET
|
||||||
#undef TEST_CUSTOM_PACKET_LEN
|
#undef TEST_CUSTOM_PACKET_LEN
|
||||||
|
#undef TEST_CUSTOM_PACKET_LARGE
|
||||||
|
#undef TEST_CUSTOM_PACKET_LARGE_LEN
|
||||||
#undef TEST_CUSTOM_PRIVATE_PACKET
|
#undef TEST_CUSTOM_PRIVATE_PACKET
|
||||||
#undef TEST_CUSTOM_PRIVATE_PACKET_LEN
|
#undef TEST_CUSTOM_PRIVATE_PACKET_LEN
|
||||||
#undef IGNORE_MESSAGE
|
#undef IGNORE_MESSAGE
|
||||||
|
@ -53,7 +53,7 @@ static int handle_test_1(void *object, const IP_Port *source, const uint8_t *pac
|
|||||||
res_packet[0] = NET_PACKET_ANNOUNCE_RESPONSE;
|
res_packet[0] = NET_PACKET_ANNOUNCE_RESPONSE;
|
||||||
memcpy(res_packet + 1, res_message, sizeof(res_message));
|
memcpy(res_packet + 1, res_message, sizeof(res_message));
|
||||||
|
|
||||||
if (send_onion_response(onion->net, source, res_packet, sizeof(res_packet),
|
if (send_onion_response(onion->log, onion->net, source, res_packet, sizeof(res_packet),
|
||||||
packet + sizeof(res_packet)) == -1) {
|
packet + sizeof(res_packet)) == -1) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -293,7 +293,7 @@ static void test_basic(void)
|
|||||||
uint64_t s;
|
uint64_t s;
|
||||||
memcpy(&s, sb_data, sizeof(uint64_t));
|
memcpy(&s, sb_data, sizeof(uint64_t));
|
||||||
memcpy(test_3_pub_key, nodes[3].public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
memcpy(test_3_pub_key, nodes[3].public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||||
int ret = send_announce_request(onion1->net, rng, &path, &nodes[3],
|
int ret = send_announce_request(log1, onion1->net, rng, &path, &nodes[3],
|
||||||
dht_get_self_public_key(onion1->dht),
|
dht_get_self_public_key(onion1->dht),
|
||||||
dht_get_self_secret_key(onion1->dht),
|
dht_get_self_secret_key(onion1->dht),
|
||||||
zeroes,
|
zeroes,
|
||||||
@ -315,7 +315,7 @@ static void test_basic(void)
|
|||||||
memcpy(onion_announce_entry_public_key(onion2_a, 1), dht_get_self_public_key(onion2->dht), CRYPTO_PUBLIC_KEY_SIZE);
|
memcpy(onion_announce_entry_public_key(onion2_a, 1), dht_get_self_public_key(onion2->dht), CRYPTO_PUBLIC_KEY_SIZE);
|
||||||
onion_announce_entry_set_time(onion2_a, 1, mono_time_get(mono_time2));
|
onion_announce_entry_set_time(onion2_a, 1, mono_time_get(mono_time2));
|
||||||
networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1);
|
networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1);
|
||||||
send_announce_request(onion1->net, rng, &path, &nodes[3],
|
send_announce_request(log1, onion1->net, rng, &path, &nodes[3],
|
||||||
dht_get_self_public_key(onion1->dht),
|
dht_get_self_public_key(onion1->dht),
|
||||||
dht_get_self_secret_key(onion1->dht),
|
dht_get_self_secret_key(onion1->dht),
|
||||||
test_3_ping_id,
|
test_3_ping_id,
|
||||||
@ -340,7 +340,7 @@ static void test_basic(void)
|
|||||||
ck_assert_msg((onion3 != nullptr), "Onion failed initializing.");
|
ck_assert_msg((onion3 != nullptr), "Onion failed initializing.");
|
||||||
|
|
||||||
random_nonce(rng, nonce);
|
random_nonce(rng, nonce);
|
||||||
ret = send_data_request(onion3->net, rng, &path, &nodes[3].ip_port,
|
ret = send_data_request(log3, onion3->net, rng, &path, &nodes[3].ip_port,
|
||||||
dht_get_self_public_key(onion1->dht),
|
dht_get_self_public_key(onion1->dht),
|
||||||
dht_get_self_public_key(onion1->dht),
|
dht_get_self_public_key(onion1->dht),
|
||||||
nonce, (const uint8_t *)"Install gentoo", sizeof("Install gentoo"));
|
nonce, (const uint8_t *)"Install gentoo", sizeof("Install gentoo"));
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "../toxcore/tox.h"
|
#include "../toxcore/tox.h"
|
||||||
#include "../toxcore/tox_dispatch.h"
|
#include "../toxcore/tox_dispatch.h"
|
||||||
#include "../toxcore/tox_events.h"
|
#include "../toxcore/tox_events.h"
|
||||||
|
#include "../toxcore/tox_unpack.h"
|
||||||
#include "auto_test_support.h"
|
#include "auto_test_support.h"
|
||||||
#include "check_compat.h"
|
#include "check_compat.h"
|
||||||
|
|
||||||
@ -160,9 +161,22 @@ static void test_tox_events(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void fake_test_unpack(void)
|
||||||
|
{
|
||||||
|
// TODO(Green-Sky): add proper unpack tests and/or implement ngc events
|
||||||
|
(void)tox_unpack_group_privacy_state;
|
||||||
|
(void)tox_unpack_group_privacy_state;
|
||||||
|
(void)tox_unpack_group_voice_state;
|
||||||
|
(void)tox_unpack_group_topic_lock;
|
||||||
|
(void)tox_unpack_group_join_fail;
|
||||||
|
(void)tox_unpack_group_mod_event;
|
||||||
|
(void)tox_unpack_group_exit_type;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||||
test_tox_events();
|
test_tox_events();
|
||||||
|
fake_test_unpack();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,4 @@ jobs:
|
|||||||
- bash: python -m pip install conan==1.59.0
|
- bash: python -m pip install conan==1.59.0
|
||||||
- bash: git submodule update --init --recursive
|
- bash: git submodule update --init --recursive
|
||||||
- bash: conan install -if _build -o with_tests=True -o shared=$(conan.shared) .
|
- bash: conan install -if _build -o with_tests=True -o shared=$(conan.shared) .
|
||||||
- bash: CONAN_CPU_COUNT=50 CTEST_OUTPUT_ON_FAILURE=1 conan build -bf _build -if _build .
|
- bash: CONAN_CPU_COUNT=50 CTEST_OUTPUT_ON_FAILURE=1 conan build -bf _build -if _build . || true
|
||||||
|
@ -29,7 +29,7 @@ function(_make_version_script target)
|
|||||||
list(GET sublib 1 ns)
|
list(GET sublib 1 ns)
|
||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND ${SHELL} -c "egrep '^\\w' ${header} | grep '${ns}_[a-z0-9_]*(' | grep -v '^typedef' | grep -o '${ns}_[a-z0-9_]*(' | egrep -o '\\w+' | sort -u"
|
COMMAND ${SHELL} -c "egrep '^\\w' ${header} | grep '${ns}_[a-z0-9_]*(' | grep -v '^typedef' | grep -o '${ns}_[a-z0-9_]*(' | egrep -o '[a-z0-9_]+' | sort -u"
|
||||||
OUTPUT_VARIABLE sublib_SYMS
|
OUTPUT_VARIABLE sublib_SYMS
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
string(REPLACE "\n" ";" sublib_SYMS ${sublib_SYMS})
|
string(REPLACE "\n" ";" sublib_SYMS ${sublib_SYMS})
|
||||||
|
2
external/toxcore/c-toxcore/other/BUILD.bazel
vendored
2
external/toxcore/c-toxcore/other/BUILD.bazel
vendored
@ -1,8 +1,6 @@
|
|||||||
load("@rules_cc//cc:defs.bzl", "cc_binary")
|
load("@rules_cc//cc:defs.bzl", "cc_binary")
|
||||||
load("//tools:no_undefined.bzl", "cc_library")
|
load("//tools:no_undefined.bzl", "cc_library")
|
||||||
|
|
||||||
package(features = ["layering_check"])
|
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "bootstrap_node_packets",
|
name = "bootstrap_node_packets",
|
||||||
srcs = ["bootstrap_node_packets.c"],
|
srcs = ["bootstrap_node_packets.c"],
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
CHECKS="*"
|
CHECKS="*"
|
||||||
|
|
||||||
|
# We don't use memcpy_s.
|
||||||
|
CHECKS="$CHECKS,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling"
|
||||||
|
|
||||||
# __attribute__((nonnull)) causes this warning on defensive null checks.
|
# __attribute__((nonnull)) causes this warning on defensive null checks.
|
||||||
CHECKS="$CHECKS,-clang-diagnostic-pointer-bool-conversion"
|
CHECKS="$CHECKS,-clang-diagnostic-pointer-bool-conversion"
|
||||||
CHECKS="$CHECKS,-clang-diagnostic-tautological-pointer-compare"
|
CHECKS="$CHECKS,-clang-diagnostic-tautological-pointer-compare"
|
||||||
@ -57,6 +60,27 @@ CHECKS="$CHECKS,-readability-redundant-control-flow"
|
|||||||
CHECKS="$CHECKS,-bugprone-narrowing-conversions"
|
CHECKS="$CHECKS,-bugprone-narrowing-conversions"
|
||||||
CHECKS="$CHECKS,-cppcoreguidelines-narrowing-conversions"
|
CHECKS="$CHECKS,-cppcoreguidelines-narrowing-conversions"
|
||||||
|
|
||||||
|
# Mistakenly thinks that
|
||||||
|
# const int a = 0, b = 1;
|
||||||
|
# assert(a < b);
|
||||||
|
# is a constant expression in C (it is in C++ though, which is probably why it's
|
||||||
|
# mistaken), suggesting to replace 'assert()' with 'static_assert()' in cases
|
||||||
|
# where that won't work.
|
||||||
|
#
|
||||||
|
# There are ways to make 'static_assert()' work, but they are rather annoying --
|
||||||
|
# they are somewhat ugly, hurting the readability, and some are error-prone:
|
||||||
|
#
|
||||||
|
# - Turning 'a' and 'b' into enum constants would make it work, but this falls
|
||||||
|
# apart if the enum types are compared against non-enums down the line
|
||||||
|
# error: enumerated and non-enumerated type in conditional expression [-Werror=extra]
|
||||||
|
#
|
||||||
|
# - Turning 'a' and 'b' into pre-processor macros is the only option left, but
|
||||||
|
# #defines and #undefs in the middle of a function hurt the readability and
|
||||||
|
# are less idiomatic than simply using 'const int'.
|
||||||
|
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
|
# TODO(iphydf): We might want some of these. For the ones we don't want, add a
|
||||||
# comment explaining why not.
|
# comment explaining why not.
|
||||||
CHECKS="$CHECKS,-clang-analyzer-optin.performance.Padding"
|
CHECKS="$CHECKS,-clang-analyzer-optin.performance.Padding"
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
load("@rules_cc//cc:defs.bzl", "cc_binary")
|
load("@rules_cc//cc:defs.bzl", "cc_binary")
|
||||||
|
|
||||||
package(features = ["layering_check"])
|
|
||||||
|
|
||||||
cc_binary(
|
cc_binary(
|
||||||
name = "bootstrap_daemon",
|
name = "bootstrap_daemon",
|
||||||
srcs = glob([
|
srcs = glob([
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
###########################################################
|
###########################################################
|
||||||
# Builder image: we compile the code here (static build)
|
# Builder image: we compile the code here (static build)
|
||||||
FROM alpine:3.15.0 AS build
|
FROM alpine:3.19.0 AS build
|
||||||
|
|
||||||
RUN ["apk", "--no-cache", "add",\
|
RUN ["apk", "--no-cache", "add",\
|
||||||
"build-base",\
|
"clang",\
|
||||||
"cmake",\
|
"cmake",\
|
||||||
"linux-headers",\
|
"linux-headers",\
|
||||||
"libconfig-dev",\
|
"libconfig-dev",\
|
||||||
"libconfig-static",\
|
"libconfig-static",\
|
||||||
"libsodium-dev",\
|
"libsodium-dev",\
|
||||||
"libsodium-static",\
|
"libsodium-static",\
|
||||||
|
"musl-dev",\
|
||||||
"ninja",\
|
"ninja",\
|
||||||
"python3"\
|
"python3"\
|
||||||
]
|
]
|
||||||
@ -34,9 +35,9 @@ COPY CMakeLists.txt so.version ./
|
|||||||
COPY other/bootstrap_daemon/CMakeLists.txt other/bootstrap_daemon/CMakeLists.txt
|
COPY other/bootstrap_daemon/CMakeLists.txt other/bootstrap_daemon/CMakeLists.txt
|
||||||
COPY testing/CMakeLists.txt testing/CMakeLists.txt
|
COPY testing/CMakeLists.txt testing/CMakeLists.txt
|
||||||
|
|
||||||
RUN cmake -B_build -H. \
|
RUN CC=clang cmake -B_build -H. \
|
||||||
-GNinja \
|
-GNinja \
|
||||||
-DCMAKE_C_FLAGS="-DTCP_SERVER_USE_EPOLL -fstack-protector-all -fisolate-erroneous-paths-attribute" \
|
-DCMAKE_C_FLAGS="-DTCP_SERVER_USE_EPOLL -fsanitize=alignment,return,returns-nonnull-attribute,vla-bound,unreachable,float-cast-overflow,null -fsanitize-trap=all -fstack-protector-all" \
|
||||||
-DCMAKE_UNITY_BUILD=ON \
|
-DCMAKE_UNITY_BUILD=ON \
|
||||||
-DCMAKE_BUILD_TYPE=Release \
|
-DCMAKE_BUILD_TYPE=Release \
|
||||||
-DFULLY_STATIC=ON \
|
-DFULLY_STATIC=ON \
|
||||||
@ -62,7 +63,7 @@ RUN ["other/bootstrap_daemon/docker/get-nodes.py", "other/bootstrap_daemon/tox-b
|
|||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
# Final image build: this is what runs the bootstrap node
|
# Final image build: this is what runs the bootstrap node
|
||||||
FROM debian:bullseye-slim
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
COPY --from=build /usr/local/bin/tox-bootstrapd /usr/local/bin/
|
COPY --from=build /usr/local/bin/tox-bootstrapd /usr/local/bin/
|
||||||
COPY --from=build /src/c-toxcore/other/bootstrap_daemon/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
|
COPY --from=build /src/c-toxcore/other/bootstrap_daemon/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
|
||||||
|
@ -1 +1 @@
|
|||||||
b2996d73cab7c7453dc10ccf7ad733622558de3b1ad0db824a379cf96f500379 /usr/local/bin/tox-bootstrapd
|
21cf23b1a2e46712663dc4f8daa322991af51b9e82626a127cf1bc8dc583b598 /usr/local/bin/tox-bootstrapd
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
set -eux
|
set -eux
|
||||||
|
|
||||||
docker_build() {
|
docker_build() {
|
||||||
docker build -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node .
|
DOCKER_BUILDKIT=1 docker build --progress=plain -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node .
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run Docker build once. If it succeeds, we're good.
|
# Run Docker build once. If it succeeds, we're good.
|
||||||
@ -12,12 +12,11 @@ if docker_build; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# We're not good. Run it again, but now capture the output.
|
# We're not good. Run it again, but now capture the output.
|
||||||
OUTPUT=$(docker_build || true 2>&1)
|
OUTPUT=$(docker_build 2>&1 || true)
|
||||||
|
|
||||||
if echo "$OUTPUT" | grep '/usr/local/bin/tox-bootstrapd: FAILED'; then
|
if echo "$OUTPUT" | grep '/usr/local/bin/tox-bootstrapd: FAILED'; then
|
||||||
# This is a checksum warning, so we need to update it.
|
# This is a checksum warning, so we need to update it.
|
||||||
IMAGE=$(echo "$OUTPUT" | grep '^ ---> [0-9a-f]*$' | grep -o '[0-9a-f]*$' | tail -n1)
|
echo "$OUTPUT" | grep -Eo '[0-9a-f]{64} /usr/local/bin/tox-bootstrapd' | tail -n1 >other/bootstrap_daemon/docker/tox-bootstrapd.sha256
|
||||||
docker run --rm "$IMAGE" sha256sum /usr/local/bin/tox-bootstrapd >other/bootstrap_daemon/docker/tox-bootstrapd.sha256
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run once last time to complete the build.
|
# Run once last time to complete the build.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2023 The TokTok team.
|
||||||
* Copyright © 2014-2016 Tox project.
|
* Copyright © 2014-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -39,22 +39,28 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
|
|||||||
log_write(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file.\n", NAME_TCP_RELAY_PORTS);
|
log_write(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file.\n", NAME_TCP_RELAY_PORTS);
|
||||||
log_write(LOG_LEVEL_WARNING, "Using default '%s':\n", NAME_TCP_RELAY_PORTS);
|
log_write(LOG_LEVEL_WARNING, "Using default '%s':\n", NAME_TCP_RELAY_PORTS);
|
||||||
|
|
||||||
uint16_t default_ports[DEFAULT_TCP_RELAY_PORTS_COUNT] = {DEFAULT_TCP_RELAY_PORTS};
|
uint16_t default_ports[] = {DEFAULT_TCP_RELAY_PORTS};
|
||||||
|
|
||||||
for (int i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; ++i) {
|
// Check to avoid calling malloc(0) later on
|
||||||
log_write(LOG_LEVEL_INFO, "Port #%d: %u\n", i, default_ports[i]);
|
// NOLINTNEXTLINE, clang-tidy: error: suspicious comparison of 'sizeof(expr)' to a constant [bugprone-sizeof-expression,-warnings-as-errors]
|
||||||
|
static_assert(sizeof(default_ports) > 0, "At least one default TCP relay port should be provided");
|
||||||
|
|
||||||
|
const size_t default_ports_count = sizeof(default_ports)/sizeof(*default_ports);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < default_ports_count; ++i) {
|
||||||
|
log_write(LOG_LEVEL_INFO, "Port #%zu: %u\n", i, default_ports[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// similar procedure to the one of reading config file below
|
// similar procedure to the one of reading config file below
|
||||||
*tcp_relay_ports = (uint16_t *)malloc(DEFAULT_TCP_RELAY_PORTS_COUNT * sizeof(uint16_t));
|
*tcp_relay_ports = (uint16_t *)malloc(default_ports_count * sizeof(uint16_t));
|
||||||
|
|
||||||
for (int i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; ++i) {
|
for (size_t i = 0; i < default_ports_count; ++i) {
|
||||||
|
|
||||||
(*tcp_relay_ports)[*tcp_relay_port_count] = default_ports[i];
|
(*tcp_relay_ports)[*tcp_relay_port_count] = default_ports[i];
|
||||||
|
|
||||||
if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT
|
if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT
|
||||||
|| (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) {
|
|| (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) {
|
||||||
log_write(LOG_LEVEL_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i,
|
log_write(LOG_LEVEL_WARNING, "Port #%zu: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i,
|
||||||
(*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT);
|
(*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2023 The TokTok team.
|
||||||
* Copyright © 2014-2016 Tox project.
|
* Copyright © 2014-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -19,8 +19,7 @@
|
|||||||
#define DEFAULT_ENABLE_IPV4_FALLBACK 1 // 1 - true, 0 - false
|
#define DEFAULT_ENABLE_IPV4_FALLBACK 1 // 1 - true, 0 - false
|
||||||
#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false
|
#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false
|
||||||
#define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false
|
#define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false
|
||||||
#define DEFAULT_TCP_RELAY_PORTS 443, 3389, 33445 // comma-separated list of ports. make sure to adjust DEFAULT_TCP_RELAY_PORTS_COUNT accordingly
|
#define DEFAULT_TCP_RELAY_PORTS 443, 3389, 33445 // comma-separated list of ports
|
||||||
#define DEFAULT_TCP_RELAY_PORTS_COUNT 3
|
|
||||||
#define DEFAULT_ENABLE_MOTD 1 // 1 - true, 0 - false
|
#define DEFAULT_ENABLE_MOTD 1 // 1 - true, 0 - false
|
||||||
#define DEFAULT_MOTD DAEMON_NAME
|
#define DEFAULT_MOTD DAEMON_NAME
|
||||||
|
|
||||||
|
@ -375,6 +375,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (!onion) {
|
if (!onion) {
|
||||||
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion. Exiting.\n");
|
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion. Exiting.\n");
|
||||||
|
kill_gca(group_announce);
|
||||||
kill_announcements(announce);
|
kill_announcements(announce);
|
||||||
kill_forwarding(forwarding);
|
kill_forwarding(forwarding);
|
||||||
kill_dht(dht);
|
kill_dht(dht);
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
||||||
|
|
||||||
package(features = ["-layering_check"])
|
|
||||||
|
|
||||||
go_library(
|
go_library(
|
||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = ["websockify.go"],
|
srcs = ["websockify.go"],
|
||||||
|
6
external/toxcore/c-toxcore/other/docker/alpine-s390x/Dockerfile
vendored
Normal file
6
external/toxcore/c-toxcore/other/docker/alpine-s390x/Dockerfile
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
FROM toxchat/alpine-s390x:latest
|
||||||
|
|
||||||
|
WORKDIR /work/c-toxcore
|
||||||
|
COPY . /work/c-toxcore/
|
||||||
|
|
||||||
|
RUN [".github/scripts/cmake-alpine-s390x"]
|
5
external/toxcore/c-toxcore/other/docker/alpine-s390x/run
vendored
Executable file
5
external/toxcore/c-toxcore/other/docker/alpine-s390x/run
vendored
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
BUILD=alpine-s390x
|
||||||
|
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
|
@ -1,3 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
docker build -t toxchat/c-toxcore:autotools -f other/docker/autotools/Dockerfile .
|
set -eux
|
||||||
|
BUILD=autotools
|
||||||
|
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
|
||||||
|
@ -5,4 +5,4 @@ if [ "$1" = "-u" ]; then
|
|||||||
docker pull toxchat/haskell:hs-cimple
|
docker pull toxchat/haskell:hs-cimple
|
||||||
docker build -t toxchat/cimplefmt -f other/docker/cimplefmt/Dockerfile .
|
docker build -t toxchat/cimplefmt -f other/docker/cimplefmt/Dockerfile .
|
||||||
fi
|
fi
|
||||||
docker run --rm -v "$PWD:/work" toxchat/cimplefmt "$@"
|
docker run --name toxcore-cimplefmt --rm -v "$PWD:/work" toxchat/cimplefmt "$@"
|
||||||
|
@ -3,4 +3,4 @@
|
|||||||
SANITIZER="${1:-asan}"
|
SANITIZER="${1:-asan}"
|
||||||
|
|
||||||
docker build -t toxchat/c-toxcore:circleci other/docker/circleci
|
docker build -t toxchat/c-toxcore:circleci other/docker/circleci
|
||||||
docker run --rm -it -v "$PWD:/c-toxcore" toxchat/c-toxcore:circleci "$SANITIZER"
|
docker run --name toxcore-circleci --rm -it -v "$PWD:/c-toxcore" toxchat/c-toxcore:circleci "$SANITIZER"
|
||||||
|
30
external/toxcore/c-toxcore/other/docker/compcert/Dockerfile
vendored
Normal file
30
external/toxcore/c-toxcore/other/docker/compcert/Dockerfile
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
FROM toxchat/compcert:latest
|
||||||
|
|
||||||
|
WORKDIR /work
|
||||||
|
COPY auto_tests/ /work/auto_tests/
|
||||||
|
COPY testing/ /work/testing/
|
||||||
|
COPY toxav/ /work/toxav/
|
||||||
|
COPY toxcore/ /work/toxcore/
|
||||||
|
COPY toxencryptsave/ /work/toxencryptsave/
|
||||||
|
COPY third_party/ /work/third_party/
|
||||||
|
|
||||||
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||||
|
|
||||||
|
RUN ccomp \
|
||||||
|
-o send_message_test \
|
||||||
|
-Wall -Werror \
|
||||||
|
-Wno-c11-extensions \
|
||||||
|
-Wno-unknown-pragmas \
|
||||||
|
-Wno-unused-variable \
|
||||||
|
-fstruct-passing -fno-unprototyped -g \
|
||||||
|
auto_tests/auto_test_support.c \
|
||||||
|
auto_tests/send_message_test.c \
|
||||||
|
testing/misc_tools.c \
|
||||||
|
toxav/*.c \
|
||||||
|
toxcore/*.c \
|
||||||
|
toxcore/*/*.c \
|
||||||
|
toxencryptsave/*.c \
|
||||||
|
third_party/cmp/*.c \
|
||||||
|
-D__COMPCERT__ -DDISABLE_VLA -Dinline= \
|
||||||
|
-lpthread $(pkg-config --cflags --libs libsodium opus vpx) \
|
||||||
|
&& ./send_message_test | grep 'tox clients connected'
|
5
external/toxcore/c-toxcore/other/docker/compcert/run
vendored
Executable file
5
external/toxcore/c-toxcore/other/docker/compcert/run
vendored
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
BUILD=compcert
|
||||||
|
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
|
@ -4,4 +4,4 @@ set -eux
|
|||||||
|
|
||||||
docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile .
|
docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile .
|
||||||
docker build -t toxchat/c-toxcore:coverage other/docker/coverage
|
docker build -t toxchat/c-toxcore:coverage other/docker/coverage
|
||||||
docker run --rm -it -p "28192:80" toxchat/c-toxcore:coverage
|
docker run --name toxcore-coverage --rm -it -p "28192:80" toxchat/c-toxcore:coverage
|
||||||
|
@ -3,4 +3,4 @@
|
|||||||
set -eux
|
set -eux
|
||||||
|
|
||||||
docker build -t toxchat/c-toxcore:docs -f other/docker/doxygen/Dockerfile .
|
docker build -t toxchat/c-toxcore:docs -f other/docker/doxygen/Dockerfile .
|
||||||
docker run --rm -it -p "28192:80" toxchat/c-toxcore:docs
|
docker run --name toxcore-docs --rm -it -p "28192:80" toxchat/c-toxcore:docs
|
||||||
|
6
external/toxcore/c-toxcore/other/docker/freebsd/Dockerfile
vendored
Normal file
6
external/toxcore/c-toxcore/other/docker/freebsd/Dockerfile
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
FROM toxchat/freebsd:latest
|
||||||
|
|
||||||
|
WORKDIR /work/c-toxcore
|
||||||
|
COPY . /work/c-toxcore/
|
||||||
|
|
||||||
|
RUN [".github/scripts/cmake-freebsd"]
|
5
external/toxcore/c-toxcore/other/docker/freebsd/run
vendored
Executable file
5
external/toxcore/c-toxcore/other/docker/freebsd/run
vendored
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
BUILD=freebsd
|
||||||
|
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
|
@ -1,3 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
docker build -f other/docker/misra/Dockerfile .
|
set -eux
|
||||||
|
BUILD=misra
|
||||||
|
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
set -eux
|
set -eux
|
||||||
|
|
||||||
docker build -t toxchat/c-toxcore:perf -f other/docker/perf/Dockerfile .
|
docker build -t toxchat/c-toxcore:perf -f other/docker/perf/Dockerfile .
|
||||||
docker run --privileged --rm -it \
|
docker run --name toxcore-perf --privileged --rm -it \
|
||||||
-v "$PWD:/work/c-toxcore" \
|
-v "$PWD:/work/c-toxcore" \
|
||||||
toxchat/c-toxcore:perf \
|
toxchat/c-toxcore:perf \
|
||||||
"$@"
|
"$@"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM ubuntu:20.04
|
FROM ubuntu:22.04
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
|
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
|
||||||
@ -17,6 +17,9 @@ COPY testing/ /work/testing/
|
|||||||
COPY toxav/ /work/toxav/
|
COPY toxav/ /work/toxav/
|
||||||
COPY toxcore/ /work/toxcore/
|
COPY toxcore/ /work/toxcore/
|
||||||
COPY toxencryptsave/ /work/toxencryptsave/
|
COPY toxencryptsave/ /work/toxencryptsave/
|
||||||
|
COPY third_party/ /work/third_party/
|
||||||
|
|
||||||
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||||
|
|
||||||
RUN tcc \
|
RUN tcc \
|
||||||
-Dinline=static \
|
-Dinline=static \
|
||||||
@ -31,9 +34,9 @@ RUN tcc \
|
|||||||
toxcore/*/*.c \
|
toxcore/*/*.c \
|
||||||
toxencryptsave/*.c \
|
toxencryptsave/*.c \
|
||||||
third_party/cmp/*.c \
|
third_party/cmp/*.c \
|
||||||
$(pkg-config --cflags --libs libsodium opus vpx)
|
$(pkg-config --cflags --libs libsodium opus vpx) \
|
||||||
|
&& ./send_message_test | grep 'tox clients connected'
|
||||||
|
|
||||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
|
||||||
COPY other/make_single_file /work/other/
|
COPY other/make_single_file /work/other/
|
||||||
RUN \
|
RUN \
|
||||||
other/make_single_file \
|
other/make_single_file \
|
||||||
@ -44,4 +47,5 @@ RUN \
|
|||||||
-o send_message_test \
|
-o send_message_test \
|
||||||
-Wall -Werror \
|
-Wall -Werror \
|
||||||
-bench -g \
|
-bench -g \
|
||||||
$(pkg-config --cflags --libs libsodium opus vpx)
|
$(pkg-config --cflags --libs libsodium opus vpx) \
|
||||||
|
&& ./send_message_test | grep 'tox clients connected'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
set -eux
|
set -eux
|
||||||
|
BUILD=tcc
|
||||||
docker build -t toxchat/c-toxcore:tcc -f other/docker/tcc/Dockerfile .
|
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
docker build -f other/docker/tokstyle/Dockerfile .
|
set -eux
|
||||||
|
BUILD=tokstyle
|
||||||
|
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
load("@rules_cc//cc:defs.bzl", "cc_binary")
|
load("@rules_cc//cc:defs.bzl", "cc_binary")
|
||||||
|
|
||||||
package(features = ["layering_check"])
|
|
||||||
|
|
||||||
#cc_binary(
|
#cc_binary(
|
||||||
# name = "cracker",
|
# name = "cracker",
|
||||||
# testonly = 1,
|
# testonly = 1,
|
||||||
|
@ -73,10 +73,15 @@ static void print_information(Tox *tox)
|
|||||||
int length = snprintf(nospam_str, sizeof(nospam_str), "%08X", nospam);
|
int length = snprintf(nospam_str, sizeof(nospam_str), "%08X", nospam);
|
||||||
nospam_str[length] = '\0';
|
nospam_str[length] = '\0';
|
||||||
|
|
||||||
uint8_t *name = (uint8_t *)malloc(tox_self_get_name_size(tox) + 1);
|
size_t name_size = tox_self_get_name_size(tox);
|
||||||
assert(name != nullptr);
|
uint8_t *name = (uint8_t *)malloc(name_size + 1);
|
||||||
|
|
||||||
|
if (!name) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
tox_self_get_name(tox, name);
|
tox_self_get_name(tox, name);
|
||||||
name[tox_self_get_name_size(tox)] = '\0';
|
name[name_size] = '\0';
|
||||||
|
|
||||||
printf("INFORMATION\n");
|
printf("INFORMATION\n");
|
||||||
printf("----------------------------------\n");
|
printf("----------------------------------\n");
|
||||||
@ -86,6 +91,8 @@ static void print_information(Tox *tox)
|
|||||||
printf("Status message: %s.\n", GENERATED_STATUS_MESSAGE);
|
printf("Status message: %s.\n", GENERATED_STATUS_MESSAGE);
|
||||||
printf("Number of friends: %zu.\n", tox_self_get_friend_list_size(tox));
|
printf("Number of friends: %zu.\n", tox_self_get_friend_list_size(tox));
|
||||||
printf("----------------------------------\n");
|
printf("----------------------------------\n");
|
||||||
|
|
||||||
|
free(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
||||||
|
|
||||||
package(features = ["layering_check"])
|
|
||||||
|
|
||||||
go_library(
|
go_library(
|
||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = ["proxy_server.go"],
|
srcs = ["proxy_server.go"],
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
load("@rules_cc//cc:defs.bzl", "cc_binary")
|
load("@rules_cc//cc:defs.bzl", "cc_binary")
|
||||||
|
|
||||||
package(features = ["layering_check"])
|
|
||||||
|
|
||||||
cc_binary(
|
cc_binary(
|
||||||
name = "grencez_tok5",
|
name = "grencez_tok5",
|
||||||
srcs = ["grencez_tok5.c"],
|
srcs = ["grencez_tok5.c"],
|
||||||
|
24
external/toxcore/c-toxcore/testing/BUILD.bazel
vendored
24
external/toxcore/c-toxcore/testing/BUILD.bazel
vendored
@ -1,7 +1,5 @@
|
|||||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
||||||
|
|
||||||
package(features = ["layering_check"])
|
|
||||||
|
|
||||||
CIMPLE_FILES = [
|
CIMPLE_FILES = [
|
||||||
"//c-toxcore/toxav:cimple_files",
|
"//c-toxcore/toxav:cimple_files",
|
||||||
"//c-toxcore/toxcore:cimple_files",
|
"//c-toxcore/toxcore:cimple_files",
|
||||||
@ -24,6 +22,28 @@ sh_test(
|
|||||||
tags = ["haskell"],
|
tags = ["haskell"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
sh_test(
|
||||||
|
name = "c_test",
|
||||||
|
size = "small",
|
||||||
|
srcs = ["//hs-tokstyle/tools:check-c"],
|
||||||
|
args = [
|
||||||
|
"--cc=$(CC)",
|
||||||
|
"-Iexternal/libsodium/include",
|
||||||
|
"-Iexternal/libvpx",
|
||||||
|
"-Iexternal/opus/include",
|
||||||
|
"-Ihs-tokstyle/include",
|
||||||
|
] + ["$(locations %s)" % f for f in CIMPLE_FILES],
|
||||||
|
data = CIMPLE_FILES + [
|
||||||
|
"//c-toxcore/third_party:headers",
|
||||||
|
"//hs-tokstyle:headers",
|
||||||
|
"@libsodium//:headers",
|
||||||
|
"@libvpx//:headers",
|
||||||
|
"@opus//:headers",
|
||||||
|
],
|
||||||
|
tags = ["haskell"],
|
||||||
|
toolchains = ["@rules_cc//cc:current_cc_toolchain"],
|
||||||
|
)
|
||||||
|
|
||||||
sh_test(
|
sh_test(
|
||||||
name = "cimplefmt_test",
|
name = "cimplefmt_test",
|
||||||
size = "small",
|
size = "small",
|
||||||
|
@ -2,8 +2,6 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
|||||||
load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test")
|
load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test")
|
||||||
load("@rules_fuzzing//fuzzing/private:binary.bzl", "fuzzing_binary") # buildifier: disable=bzl-visibility
|
load("@rules_fuzzing//fuzzing/private:binary.bzl", "fuzzing_binary") # buildifier: disable=bzl-visibility
|
||||||
|
|
||||||
package(features = ["layering_check"])
|
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "fuzz_support",
|
name = "fuzz_support",
|
||||||
srcs = [
|
srcs = [
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
load("//tools:no_undefined.bzl", "cc_library")
|
load("//tools:no_undefined.bzl", "cc_library")
|
||||||
|
|
||||||
package(features = ["layering_check"])
|
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "cmp",
|
name = "cmp",
|
||||||
srcs = ["cmp/cmp.c"],
|
srcs = ["cmp/cmp.c"],
|
||||||
@ -9,3 +7,9 @@ cc_library(
|
|||||||
copts = ["-DCMP_NO_FLOAT"],
|
copts = ["-DCMP_NO_FLOAT"],
|
||||||
visibility = ["//c-toxcore:__subpackages__"],
|
visibility = ["//c-toxcore:__subpackages__"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "headers",
|
||||||
|
srcs = ["cmp/cmp.h"],
|
||||||
|
visibility = ["//c-toxcore:__subpackages__"],
|
||||||
|
)
|
||||||
|
2
external/toxcore/c-toxcore/toxav/BUILD.bazel
vendored
2
external/toxcore/c-toxcore/toxav/BUILD.bazel
vendored
@ -1,8 +1,6 @@
|
|||||||
load("@rules_cc//cc:defs.bzl", "cc_test")
|
load("@rules_cc//cc:defs.bzl", "cc_test")
|
||||||
load("//tools:no_undefined.bzl", "cc_library")
|
load("//tools:no_undefined.bzl", "cc_library")
|
||||||
|
|
||||||
package(features = ["layering_check"])
|
|
||||||
|
|
||||||
exports_files(
|
exports_files(
|
||||||
srcs = ["toxav.h"],
|
srcs = ["toxav.h"],
|
||||||
visibility = ["//c-toxcore:__pkg__"],
|
visibility = ["//c-toxcore:__pkg__"],
|
||||||
|
1
external/toxcore/c-toxcore/toxav/msi.c
vendored
1
external/toxcore/c-toxcore/toxav/msi.c
vendored
@ -821,6 +821,7 @@ static void handle_pop(MSICall *call, const MSIMessage *msg)
|
|||||||
switch (call->state) {
|
switch (call->state) {
|
||||||
case MSI_CALL_INACTIVE: {
|
case MSI_CALL_INACTIVE: {
|
||||||
LOGGER_FATAL(call->session->messenger->log, "Handling what should be impossible case");
|
LOGGER_FATAL(call->session->messenger->log, "Handling what should be impossible case");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case MSI_CALL_ACTIVE: {
|
case MSI_CALL_ACTIVE: {
|
||||||
|
48
external/toxcore/c-toxcore/toxcore/BUILD.bazel
vendored
48
external/toxcore/c-toxcore/toxcore/BUILD.bazel
vendored
@ -2,10 +2,11 @@ load("@rules_cc//cc:defs.bzl", "cc_test")
|
|||||||
load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test")
|
load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test")
|
||||||
load("//tools:no_undefined.bzl", "cc_library")
|
load("//tools:no_undefined.bzl", "cc_library")
|
||||||
|
|
||||||
package(features = ["layering_check"])
|
|
||||||
|
|
||||||
exports_files(
|
exports_files(
|
||||||
srcs = ["tox.h"],
|
srcs = [
|
||||||
|
"tox.h",
|
||||||
|
"tox_private.h",
|
||||||
|
],
|
||||||
visibility = ["//c-toxcore:__pkg__"],
|
visibility = ["//c-toxcore:__pkg__"],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -76,6 +77,22 @@ cc_test(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "logger",
|
||||||
|
srcs = ["logger.c"],
|
||||||
|
hdrs = ["logger.h"],
|
||||||
|
visibility = [
|
||||||
|
"//c-toxcore/auto_tests:__pkg__",
|
||||||
|
"//c-toxcore/other:__pkg__",
|
||||||
|
"//c-toxcore/other/bootstrap_daemon:__pkg__",
|
||||||
|
"//c-toxcore/toxav:__pkg__",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":attributes",
|
||||||
|
":ccompat",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "bin_pack",
|
name = "bin_pack",
|
||||||
srcs = ["bin_pack.c"],
|
srcs = ["bin_pack.c"],
|
||||||
@ -84,6 +101,7 @@ cc_library(
|
|||||||
deps = [
|
deps = [
|
||||||
":attributes",
|
":attributes",
|
||||||
":ccompat",
|
":ccompat",
|
||||||
|
":logger",
|
||||||
"//c-toxcore/third_party:cmp",
|
"//c-toxcore/third_party:cmp",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -158,22 +176,6 @@ cc_test(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_library(
|
|
||||||
name = "logger",
|
|
||||||
srcs = ["logger.c"],
|
|
||||||
hdrs = ["logger.h"],
|
|
||||||
visibility = [
|
|
||||||
"//c-toxcore/auto_tests:__pkg__",
|
|
||||||
"//c-toxcore/other:__pkg__",
|
|
||||||
"//c-toxcore/other/bootstrap_daemon:__pkg__",
|
|
||||||
"//c-toxcore/toxav:__pkg__",
|
|
||||||
],
|
|
||||||
deps = [
|
|
||||||
":attributes",
|
|
||||||
":ccompat",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "state",
|
name = "state",
|
||||||
srcs = ["state.c"],
|
srcs = ["state.c"],
|
||||||
@ -199,6 +201,7 @@ cc_library(
|
|||||||
":attributes",
|
":attributes",
|
||||||
":ccompat",
|
":ccompat",
|
||||||
":mem",
|
":mem",
|
||||||
|
":util",
|
||||||
"@pthread",
|
"@pthread",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -228,6 +231,7 @@ cc_library(
|
|||||||
deps = [
|
deps = [
|
||||||
":ccompat",
|
":ccompat",
|
||||||
":crypto_core",
|
":crypto_core",
|
||||||
|
":logger",
|
||||||
":mem",
|
":mem",
|
||||||
":mono_time",
|
":mono_time",
|
||||||
],
|
],
|
||||||
@ -339,6 +343,7 @@ cc_library(
|
|||||||
deps = [
|
deps = [
|
||||||
":LAN_discovery",
|
":LAN_discovery",
|
||||||
":attributes",
|
":attributes",
|
||||||
|
":bin_pack",
|
||||||
":ccompat",
|
":ccompat",
|
||||||
":crypto_core",
|
":crypto_core",
|
||||||
":logger",
|
":logger",
|
||||||
@ -366,6 +371,7 @@ cc_test(
|
|||||||
|
|
||||||
cc_fuzz_test(
|
cc_fuzz_test(
|
||||||
name = "DHT_fuzz_test",
|
name = "DHT_fuzz_test",
|
||||||
|
size = "small",
|
||||||
srcs = ["DHT_fuzz_test.cc"],
|
srcs = ["DHT_fuzz_test.cc"],
|
||||||
corpus = ["//tools/toktok-fuzzer/corpus:DHT_fuzz_test"],
|
corpus = ["//tools/toktok-fuzzer/corpus:DHT_fuzz_test"],
|
||||||
deps = [
|
deps = [
|
||||||
@ -405,6 +411,7 @@ cc_library(
|
|||||||
|
|
||||||
cc_fuzz_test(
|
cc_fuzz_test(
|
||||||
name = "forwarding_fuzz_test",
|
name = "forwarding_fuzz_test",
|
||||||
|
size = "small",
|
||||||
srcs = ["forwarding_fuzz_test.cc"],
|
srcs = ["forwarding_fuzz_test.cc"],
|
||||||
#corpus = ["//tools/toktok-fuzzer/corpus:forwarding_fuzz_test"],
|
#corpus = ["//tools/toktok-fuzzer/corpus:forwarding_fuzz_test"],
|
||||||
deps = [
|
deps = [
|
||||||
@ -603,6 +610,7 @@ cc_library(
|
|||||||
|
|
||||||
cc_fuzz_test(
|
cc_fuzz_test(
|
||||||
name = "group_announce_fuzz_test",
|
name = "group_announce_fuzz_test",
|
||||||
|
size = "small",
|
||||||
srcs = ["group_announce_fuzz_test.cc"],
|
srcs = ["group_announce_fuzz_test.cc"],
|
||||||
#corpus = ["//tools/toktok-fuzzer/corpus:group_announce_fuzz_test"],
|
#corpus = ["//tools/toktok-fuzzer/corpus:group_announce_fuzz_test"],
|
||||||
deps = [
|
deps = [
|
||||||
@ -706,6 +714,7 @@ cc_test(
|
|||||||
|
|
||||||
cc_fuzz_test(
|
cc_fuzz_test(
|
||||||
name = "group_moderation_fuzz_test",
|
name = "group_moderation_fuzz_test",
|
||||||
|
size = "small",
|
||||||
srcs = ["group_moderation_fuzz_test.cc"],
|
srcs = ["group_moderation_fuzz_test.cc"],
|
||||||
corpus = ["//tools/toktok-fuzzer/corpus:group_moderation_fuzz_test"],
|
corpus = ["//tools/toktok-fuzzer/corpus:group_moderation_fuzz_test"],
|
||||||
deps = [
|
deps = [
|
||||||
@ -862,6 +871,7 @@ cc_test(
|
|||||||
|
|
||||||
cc_fuzz_test(
|
cc_fuzz_test(
|
||||||
name = "tox_events_fuzz_test",
|
name = "tox_events_fuzz_test",
|
||||||
|
size = "small",
|
||||||
srcs = ["tox_events_fuzz_test.cc"],
|
srcs = ["tox_events_fuzz_test.cc"],
|
||||||
corpus = ["//tools/toktok-fuzzer/corpus:tox_events_fuzz_test"],
|
corpus = ["//tools/toktok-fuzzer/corpus:tox_events_fuzz_test"],
|
||||||
deps = [
|
deps = [
|
||||||
|
125
external/toxcore/c-toxcore/toxcore/DHT.c
vendored
125
external/toxcore/c-toxcore/toxcore/DHT.c
vendored
@ -9,10 +9,12 @@
|
|||||||
#include "DHT.h"
|
#include "DHT.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "LAN_discovery.h"
|
#include "LAN_discovery.h"
|
||||||
|
#include "bin_pack.h"
|
||||||
#include "ccompat.h"
|
#include "ccompat.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "mono_time.h"
|
#include "mono_time.h"
|
||||||
@ -360,12 +362,32 @@ int packed_node_size(Family ip_family)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int pack_ip_port(const Logger *logger, uint8_t *data, uint16_t length, const IP_Port *ip_port)
|
/** @brief Packs an IP structure.
|
||||||
|
*
|
||||||
|
* It's the caller's responsibility to make sure `is_ipv4` tells the truth. This
|
||||||
|
* function is an implementation detail of @ref bin_pack_ip_port.
|
||||||
|
*
|
||||||
|
* @param is_ipv4 whether this IP is an IP4 or IP6.
|
||||||
|
*
|
||||||
|
* @retval true on success.
|
||||||
|
*/
|
||||||
|
non_null()
|
||||||
|
static bool bin_pack_ip(Bin_Pack *bp, const IP *ip, bool is_ipv4)
|
||||||
{
|
{
|
||||||
if (data == nullptr) {
|
if (is_ipv4) {
|
||||||
return -1;
|
return bin_pack_bin_b(bp, ip->ip.v4.uint8, SIZE_IP4);
|
||||||
|
} else {
|
||||||
|
return bin_pack_bin_b(bp, ip->ip.v6.uint8, SIZE_IP6);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Packs an IP_Port structure.
|
||||||
|
*
|
||||||
|
* @retval true on success.
|
||||||
|
*/
|
||||||
|
non_null()
|
||||||
|
static bool bin_pack_ip_port(Bin_Pack *bp, const Logger *logger, const IP_Port *ip_port)
|
||||||
|
{
|
||||||
bool is_ipv4;
|
bool is_ipv4;
|
||||||
uint8_t family;
|
uint8_t family;
|
||||||
|
|
||||||
@ -387,32 +409,34 @@ int pack_ip_port(const Logger *logger, uint8_t *data, uint16_t length, const IP_
|
|||||||
// TODO(iphydf): Find out why we're trying to pack invalid IPs, stop
|
// TODO(iphydf): Find out why we're trying to pack invalid IPs, stop
|
||||||
// doing that, and turn this into an error.
|
// doing that, and turn this into an error.
|
||||||
LOGGER_TRACE(logger, "cannot pack invalid IP: %s", net_ip_ntoa(&ip_port->ip, &ip_str));
|
LOGGER_TRACE(logger, "cannot pack invalid IP: %s", net_ip_ntoa(&ip_port->ip, &ip_str));
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_ipv4) {
|
return bin_pack_u08_b(bp, family)
|
||||||
const uint32_t size = 1 + SIZE_IP4 + sizeof(uint16_t);
|
&& bin_pack_ip(bp, &ip_port->ip, is_ipv4)
|
||||||
|
&& bin_pack_u16_b(bp, net_ntohs(ip_port->port));
|
||||||
|
}
|
||||||
|
|
||||||
|
non_null()
|
||||||
|
static bool bin_pack_ip_port_handler(Bin_Pack *bp, const Logger *logger, const void *obj)
|
||||||
|
{
|
||||||
|
return bin_pack_ip_port(bp, logger, (const IP_Port *)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
int pack_ip_port(const Logger *logger, uint8_t *data, uint16_t length, const IP_Port *ip_port)
|
||||||
|
{
|
||||||
|
const uint32_t size = bin_pack_obj_size(bin_pack_ip_port_handler, logger, ip_port);
|
||||||
|
|
||||||
if (size > length) {
|
if (size > length) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
data[0] = family;
|
if (!bin_pack_obj(bin_pack_ip_port_handler, logger, ip_port, data, length)) {
|
||||||
memcpy(data + 1, &ip_port->ip.ip.v4, SIZE_IP4);
|
|
||||||
memcpy(data + 1 + SIZE_IP4, &ip_port->port, sizeof(uint16_t));
|
|
||||||
return size;
|
|
||||||
} else {
|
|
||||||
const uint32_t size = 1 + SIZE_IP6 + sizeof(uint16_t);
|
|
||||||
|
|
||||||
if (size > length) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
data[0] = family;
|
assert(size < INT_MAX);
|
||||||
memcpy(data + 1, &ip_port->ip.ip.v6, SIZE_IP6);
|
return (int)size;
|
||||||
memcpy(data + 1 + SIZE_IP6, &ip_port->port, sizeof(uint16_t));
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int dht_create_packet(const Memory *mem, const Random *rng,
|
int dht_create_packet(const Memory *mem, const Random *rng,
|
||||||
@ -511,33 +535,25 @@ int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Pack a single node from a node array.
|
||||||
|
*
|
||||||
|
* @retval true on success.
|
||||||
|
*/
|
||||||
|
non_null()
|
||||||
|
static bool bin_pack_node_handler(Bin_Pack *bp, const Logger *logger, const void *arr, uint32_t index)
|
||||||
|
{
|
||||||
|
const Node_format *nodes = (const Node_format *)arr;
|
||||||
|
return bin_pack_ip_port(bp, logger, &nodes[index].ip_port)
|
||||||
|
&& bin_pack_bin_b(bp, nodes[index].public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
int pack_nodes(const Logger *logger, uint8_t *data, uint16_t length, const Node_format *nodes, uint16_t number)
|
int pack_nodes(const Logger *logger, uint8_t *data, uint16_t length, const Node_format *nodes, uint16_t number)
|
||||||
{
|
{
|
||||||
uint32_t packed_length = 0;
|
const uint32_t size = bin_pack_obj_array_size(bin_pack_node_handler, logger, nodes, number);
|
||||||
|
if (!bin_pack_obj_array(bin_pack_node_handler, logger, nodes, number, data, length)) {
|
||||||
for (uint32_t i = 0; i < number && packed_length < length; ++i) {
|
|
||||||
const int ipp_size = pack_ip_port(logger, data + packed_length, length - packed_length, &nodes[i].ip_port);
|
|
||||||
|
|
||||||
if (ipp_size == -1) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
return size;
|
||||||
packed_length += ipp_size;
|
|
||||||
|
|
||||||
if (packed_length + CRYPTO_PUBLIC_KEY_SIZE > length) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(data + packed_length, nodes[i].public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
|
||||||
packed_length += CRYPTO_PUBLIC_KEY_SIZE;
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
const uint32_t increment = ipp_size + CRYPTO_PUBLIC_KEY_SIZE;
|
|
||||||
assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return packed_length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed_data_len, const uint8_t *data,
|
int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed_data_len, const uint8_t *data,
|
||||||
@ -1812,7 +1828,9 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
|
|||||||
++not_kill;
|
++not_kill;
|
||||||
|
|
||||||
if (mono_time_is_timeout(dht->mono_time, assoc->last_pinged, PING_INTERVAL)) {
|
if (mono_time_is_timeout(dht->mono_time, assoc->last_pinged, PING_INTERVAL)) {
|
||||||
dht_getnodes(dht, &assoc->ip_port, client->public_key, public_key);
|
const IP_Port *target = &assoc->ip_port;
|
||||||
|
const uint8_t *target_key = client->public_key;
|
||||||
|
dht_getnodes(dht, target, target_key, public_key);
|
||||||
assoc->last_pinged = temp_time;
|
assoc->last_pinged = temp_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1845,7 +1863,9 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
|
|||||||
rand_node += random_range_u32(dht->rng, num_nodes - (rand_node + 1));
|
rand_node += random_range_u32(dht->rng, num_nodes - (rand_node + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
dht_getnodes(dht, &assoc_list[rand_node]->ip_port, client_list[rand_node]->public_key, public_key);
|
const IP_Port *target = &assoc_list[rand_node]->ip_port;
|
||||||
|
const uint8_t *target_key = client_list[rand_node]->public_key;
|
||||||
|
dht_getnodes(dht, target, target_key, public_key);
|
||||||
|
|
||||||
*lastgetnode = temp_time;
|
*lastgetnode = temp_time;
|
||||||
++*bootstrap_times;
|
++*bootstrap_times;
|
||||||
@ -1874,8 +1894,7 @@ static void do_dht_friends(DHT *dht)
|
|||||||
dht_friend->num_to_bootstrap = 0;
|
dht_friend->num_to_bootstrap = 0;
|
||||||
|
|
||||||
do_ping_and_sendnode_requests(dht, &dht_friend->lastgetnode, dht_friend->public_key, dht_friend->client_list,
|
do_ping_and_sendnode_requests(dht, &dht_friend->lastgetnode, dht_friend->public_key, dht_friend->client_list,
|
||||||
MAX_FRIEND_CLIENTS,
|
MAX_FRIEND_CLIENTS, &dht_friend->bootstrap_times, true);
|
||||||
&dht_friend->bootstrap_times, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2618,6 +2637,7 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw
|
|||||||
DHT *const dht = (DHT *)mem_alloc(mem, sizeof(DHT));
|
DHT *const dht = (DHT *)mem_alloc(mem, sizeof(DHT));
|
||||||
|
|
||||||
if (dht == nullptr) {
|
if (dht == nullptr) {
|
||||||
|
LOGGER_ERROR(log, "failed to allocate DHT struct (%ld bytes)", (unsigned long)sizeof(DHT));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2635,6 +2655,7 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw
|
|||||||
dht->ping = ping_new(mem, mono_time, rng, dht);
|
dht->ping = ping_new(mem, mono_time, rng, dht);
|
||||||
|
|
||||||
if (dht->ping == nullptr) {
|
if (dht->ping == nullptr) {
|
||||||
|
LOGGER_ERROR(log, "failed to initialise ping");
|
||||||
kill_dht(dht);
|
kill_dht(dht);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -2651,10 +2672,11 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw
|
|||||||
|
|
||||||
crypto_new_keypair(rng, dht->self_public_key, dht->self_secret_key);
|
crypto_new_keypair(rng, dht->self_public_key, dht->self_secret_key);
|
||||||
|
|
||||||
dht->shared_keys_recv = shared_key_cache_new(mono_time, mem, dht->self_secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
dht->shared_keys_recv = shared_key_cache_new(log, mono_time, mem, dht->self_secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
||||||
dht->shared_keys_sent = shared_key_cache_new(mono_time, mem, dht->self_secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
dht->shared_keys_sent = shared_key_cache_new(log, mono_time, mem, dht->self_secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
||||||
|
|
||||||
if (dht->shared_keys_recv == nullptr || dht->shared_keys_sent == nullptr) {
|
if (dht->shared_keys_recv == nullptr || dht->shared_keys_sent == nullptr) {
|
||||||
|
LOGGER_ERROR(log, "failed to initialise shared key cache");
|
||||||
kill_dht(dht);
|
kill_dht(dht);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -2663,6 +2685,7 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw
|
|||||||
dht->dht_ping_array = ping_array_new(mem, DHT_PING_ARRAY_SIZE, PING_TIMEOUT);
|
dht->dht_ping_array = ping_array_new(mem, DHT_PING_ARRAY_SIZE, PING_TIMEOUT);
|
||||||
|
|
||||||
if (dht->dht_ping_array == nullptr) {
|
if (dht->dht_ping_array == nullptr) {
|
||||||
|
LOGGER_ERROR(log, "failed to initialise ping array");
|
||||||
kill_dht(dht);
|
kill_dht(dht);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -2675,6 +2698,7 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw
|
|||||||
|
|
||||||
uint32_t token; // We don't intend to delete these ever, but need to pass the token
|
uint32_t token; // We don't intend to delete these ever, but need to pass the token
|
||||||
if (dht_addfriend(dht, random_public_key_bytes, nullptr, nullptr, 0, &token) != 0) {
|
if (dht_addfriend(dht, random_public_key_bytes, nullptr, nullptr, 0, &token) != 0) {
|
||||||
|
LOGGER_ERROR(log, "failed to add initial random seed DHT friends");
|
||||||
kill_dht(dht);
|
kill_dht(dht);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -2829,8 +2853,9 @@ void dht_save(const DHT *dht, uint8_t *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
state_write_section_header(old_data, DHT_STATE_COOKIE_TYPE, pack_nodes(dht->log, data, sizeof(Node_format) * num,
|
state_write_section_header(
|
||||||
clients, num), DHT_STATE_TYPE_NODES);
|
old_data, DHT_STATE_COOKIE_TYPE, pack_nodes(dht->log, data, sizeof(Node_format) * num, clients, num),
|
||||||
|
DHT_STATE_TYPE_NODES);
|
||||||
|
|
||||||
mem_delete(dht->mem, clients);
|
mem_delete(dht->mem, clients);
|
||||||
}
|
}
|
||||||
|
20
external/toxcore/c-toxcore/toxcore/DHT.h
vendored
20
external/toxcore/c-toxcore/toxcore/DHT.h
vendored
@ -214,6 +214,16 @@ int packed_node_size(Family ip_family);
|
|||||||
non_null()
|
non_null()
|
||||||
int pack_ip_port(const Logger *logger, uint8_t *data, uint16_t length, const IP_Port *ip_port);
|
int pack_ip_port(const Logger *logger, uint8_t *data, uint16_t length, const IP_Port *ip_port);
|
||||||
|
|
||||||
|
/** @brief Unpack IP_Port structure from data of max size length into ip_port.
|
||||||
|
*
|
||||||
|
* len_processed is the offset of data currently unpacked.
|
||||||
|
*
|
||||||
|
* @return size of unpacked ip_port on success.
|
||||||
|
* @retval -1 on failure.
|
||||||
|
*/
|
||||||
|
non_null()
|
||||||
|
int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool tcp_enabled);
|
||||||
|
|
||||||
/** @brief Encrypt plain and write resulting DHT packet into packet with max size length.
|
/** @brief Encrypt plain and write resulting DHT packet into packet with max size length.
|
||||||
*
|
*
|
||||||
* @return size of packet on success.
|
* @return size of packet on success.
|
||||||
@ -226,16 +236,6 @@ int dht_create_packet(const Memory *mem, const Random *rng,
|
|||||||
const uint8_t *plain, size_t plain_length,
|
const uint8_t *plain, size_t plain_length,
|
||||||
uint8_t *packet, size_t length);
|
uint8_t *packet, size_t length);
|
||||||
|
|
||||||
/** @brief Unpack IP_Port structure from data of max size length into ip_port.
|
|
||||||
*
|
|
||||||
* len_processed is the offset of data currently unpacked.
|
|
||||||
*
|
|
||||||
* @return size of unpacked ip_port on success.
|
|
||||||
* @retval -1 on failure.
|
|
||||||
*/
|
|
||||||
non_null()
|
|
||||||
int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool tcp_enabled);
|
|
||||||
|
|
||||||
/** @brief Pack number of nodes into data of maxlength length.
|
/** @brief Pack number of nodes into data of maxlength length.
|
||||||
*
|
*
|
||||||
* @return length of packed nodes on success.
|
* @return length of packed nodes on success.
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "DHT.h"
|
#include "DHT.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "../testing/fuzzing/fuzz_support.h"
|
#include "../testing/fuzzing/fuzz_support.h"
|
||||||
@ -36,6 +38,16 @@ void TestUnpackNodes(Fuzz_Data &input)
|
|||||||
LOGGER_ASSERT(logger, packed_size == processed_data_len,
|
LOGGER_ASSERT(logger, packed_size == processed_data_len,
|
||||||
"packed size (%d) != unpacked size (%d)", packed_size, processed_data_len);
|
"packed size (%d) != unpacked size (%d)", packed_size, processed_data_len);
|
||||||
logger_kill(logger);
|
logger_kill(logger);
|
||||||
|
|
||||||
|
// Check that packed nodes can be unpacked again and result in the
|
||||||
|
// original unpacked nodes.
|
||||||
|
Node_format nodes2[node_count];
|
||||||
|
uint16_t processed_data_len2;
|
||||||
|
const int packed_count2 = unpack_nodes(
|
||||||
|
nodes2, node_count, &processed_data_len2, packed.data(), packed.size(), tcp_enabled);
|
||||||
|
assert(processed_data_len2 == processed_data_len);
|
||||||
|
assert(packed_count2 == packed_count);
|
||||||
|
assert(memcmp(nodes, nodes2, sizeof(Node_format) * packed_count) == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
lib_LTLIBRARIES += libtoxcore.la
|
lib_LTLIBRARIES += libtoxcore.la
|
||||||
|
|
||||||
libtoxcore_la_include_HEADERS = \
|
libtoxcore_la_include_HEADERS = \
|
||||||
../toxcore/tox.h
|
../toxcore/tox.h \
|
||||||
|
../toxcore/tox_private.h
|
||||||
|
|
||||||
libtoxcore_la_includedir = $(includedir)/tox
|
libtoxcore_la_includedir = $(includedir)/tox
|
||||||
|
|
||||||
|
43
external/toxcore/c-toxcore/toxcore/Messenger.c
vendored
43
external/toxcore/c-toxcore/toxcore/Messenger.c
vendored
@ -757,6 +757,20 @@ int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Userstatus userstatus_from_int(uint8_t status)
|
||||||
|
{
|
||||||
|
switch (status) {
|
||||||
|
case 0:
|
||||||
|
return USERSTATUS_NONE;
|
||||||
|
case 1:
|
||||||
|
return USERSTATUS_AWAY;
|
||||||
|
case 2:
|
||||||
|
return USERSTATUS_BUSY;
|
||||||
|
default:
|
||||||
|
return USERSTATUS_INVALID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int m_set_userstatus(Messenger *m, uint8_t status)
|
int m_set_userstatus(Messenger *m, uint8_t status)
|
||||||
{
|
{
|
||||||
if (status >= USERSTATUS_INVALID) {
|
if (status >= USERSTATUS_INVALID) {
|
||||||
@ -767,7 +781,7 @@ int m_set_userstatus(Messenger *m, uint8_t status)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m->userstatus = (Userstatus)status;
|
m->userstatus = userstatus_from_int(status);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < m->numfriends; ++i) {
|
for (uint32_t i = 0; i < m->numfriends; ++i) {
|
||||||
m->friendlist[i].userstatus_sent = false;
|
m->friendlist[i].userstatus_sent = false;
|
||||||
@ -923,7 +937,7 @@ static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, co
|
|||||||
non_null()
|
non_null()
|
||||||
static void set_friend_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
|
static void set_friend_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
|
||||||
{
|
{
|
||||||
m->friendlist[friendnumber].userstatus = (Userstatus)status;
|
m->friendlist[friendnumber].userstatus = userstatus_from_int(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
non_null()
|
non_null()
|
||||||
@ -2081,9 +2095,9 @@ static int m_handle_packet_userstatus(Messenger *m, const int i, const uint8_t *
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Userstatus status = (Userstatus)data[0];
|
const Userstatus status = userstatus_from_int(data[0]);
|
||||||
|
|
||||||
if (status >= USERSTATUS_INVALID) {
|
if (status == USERSTATUS_INVALID) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2627,7 +2641,7 @@ void do_messenger(Messenger *m, void *userdata)
|
|||||||
if (m->tcp_server != nullptr) {
|
if (m->tcp_server != nullptr) {
|
||||||
/* Add self tcp server. */
|
/* Add self tcp server. */
|
||||||
IP_Port local_ip_port;
|
IP_Port local_ip_port;
|
||||||
local_ip_port.port = m->options.tcp_server_port;
|
local_ip_port.port = net_htons(m->options.tcp_server_port);
|
||||||
local_ip_port.ip.family = net_family_ipv4();
|
local_ip_port.ip.family = net_family_ipv4();
|
||||||
local_ip_port.ip.ip.v4 = get_ip4_loopback();
|
local_ip_port.ip.ip.v4 = get_ip4_loopback();
|
||||||
add_tcp_relay(m->net_crypto, &local_ip_port, tcp_server_public_key(m->tcp_server));
|
add_tcp_relay(m->net_crypto, &local_ip_port, tcp_server_public_key(m->tcp_server));
|
||||||
@ -3153,7 +3167,7 @@ static void pack_groupchats(const GC_Session *c, Bin_Pack *bp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
non_null()
|
non_null()
|
||||||
static bool pack_groupchats_handler(Bin_Pack *bp, const void *obj)
|
static bool pack_groupchats_handler(Bin_Pack *bp, const Logger *log, const void *obj)
|
||||||
{
|
{
|
||||||
pack_groupchats((const GC_Session *)obj, bp);
|
pack_groupchats((const GC_Session *)obj, bp);
|
||||||
return true; // TODO(iphydf): Return bool from pack functions.
|
return true; // TODO(iphydf): Return bool from pack functions.
|
||||||
@ -3163,7 +3177,7 @@ non_null()
|
|||||||
static uint32_t saved_groups_size(const Messenger *m)
|
static uint32_t saved_groups_size(const Messenger *m)
|
||||||
{
|
{
|
||||||
GC_Session *c = m->group_handler;
|
GC_Session *c = m->group_handler;
|
||||||
return bin_pack_obj_size(pack_groupchats_handler, c);
|
return bin_pack_obj_size(pack_groupchats_handler, m->log, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
non_null()
|
non_null()
|
||||||
@ -3185,7 +3199,7 @@ static uint8_t *groups_save(const Messenger *m, uint8_t *data)
|
|||||||
|
|
||||||
data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_GROUPS);
|
data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_GROUPS);
|
||||||
|
|
||||||
if (!bin_pack_obj(pack_groupchats_handler, c, data, len)) {
|
if (!bin_pack_obj(pack_groupchats_handler, m->log, c, data, len)) {
|
||||||
LOGGER_FATAL(m->log, "failed to pack group chats into buffer of length %u", len);
|
LOGGER_FATAL(m->log, "failed to pack group chats into buffer of length %u", len);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -3569,6 +3583,7 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
|||||||
mem_delete(mem, m);
|
mem_delete(mem, m);
|
||||||
|
|
||||||
if (error != nullptr && net_err == 1) {
|
if (error != nullptr && net_err == 1) {
|
||||||
|
LOGGER_WARNING(m->log, "network initialisation failed (no ports available)");
|
||||||
*error = MESSENGER_ERROR_PORT;
|
*error = MESSENGER_ERROR_PORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3588,6 +3603,8 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
|||||||
m->net_crypto = new_net_crypto(m->log, m->mem, m->rng, m->ns, m->mono_time, m->dht, &options->proxy_info);
|
m->net_crypto = new_net_crypto(m->log, m->mem, m->rng, m->ns, m->mono_time, m->dht, &options->proxy_info);
|
||||||
|
|
||||||
if (m->net_crypto == nullptr) {
|
if (m->net_crypto == nullptr) {
|
||||||
|
LOGGER_WARNING(m->log, "net_crypto initialisation failed");
|
||||||
|
|
||||||
kill_dht(m->dht);
|
kill_dht(m->dht);
|
||||||
kill_networking(m->net);
|
kill_networking(m->net);
|
||||||
friendreq_kill(m->fr);
|
friendreq_kill(m->fr);
|
||||||
@ -3600,6 +3617,8 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
|||||||
m->group_announce = new_gca_list();
|
m->group_announce = new_gca_list();
|
||||||
|
|
||||||
if (m->group_announce == nullptr) {
|
if (m->group_announce == nullptr) {
|
||||||
|
LOGGER_WARNING(m->log, "DHT group chats initialisation failed");
|
||||||
|
|
||||||
kill_net_crypto(m->net_crypto);
|
kill_net_crypto(m->net_crypto);
|
||||||
kill_dht(m->dht);
|
kill_dht(m->dht);
|
||||||
kill_networking(m->net);
|
kill_networking(m->net);
|
||||||
@ -3622,10 +3641,14 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
|||||||
m->onion = new_onion(m->log, m->mem, m->mono_time, m->rng, m->dht);
|
m->onion = new_onion(m->log, m->mem, m->mono_time, m->rng, m->dht);
|
||||||
m->onion_a = new_onion_announce(m->log, m->mem, m->rng, m->mono_time, m->dht);
|
m->onion_a = new_onion_announce(m->log, m->mem, m->rng, m->mono_time, m->dht);
|
||||||
m->onion_c = new_onion_client(m->log, m->mem, m->rng, m->mono_time, m->net_crypto);
|
m->onion_c = new_onion_client(m->log, m->mem, m->rng, m->mono_time, m->net_crypto);
|
||||||
|
if (m->onion_c != nullptr) {
|
||||||
m->fr_c = new_friend_connections(m->log, m->mono_time, m->ns, m->onion_c, options->local_discovery_enabled);
|
m->fr_c = new_friend_connections(m->log, m->mono_time, m->ns, m->onion_c, options->local_discovery_enabled);
|
||||||
|
}
|
||||||
|
|
||||||
if ((options->dht_announcements_enabled && (m->forwarding == nullptr || m->announce == nullptr)) ||
|
if ((options->dht_announcements_enabled && (m->forwarding == nullptr || m->announce == nullptr)) ||
|
||||||
m->onion == nullptr || m->onion_a == nullptr || m->onion_c == nullptr || m->fr_c == nullptr) {
|
m->onion == nullptr || m->onion_a == nullptr || m->onion_c == nullptr || m->fr_c == nullptr) {
|
||||||
|
LOGGER_WARNING(m->log, "onion initialisation failed");
|
||||||
|
|
||||||
kill_onion(m->onion);
|
kill_onion(m->onion);
|
||||||
kill_onion_announce(m->onion_a);
|
kill_onion_announce(m->onion_a);
|
||||||
kill_onion_client(m->onion_c);
|
kill_onion_client(m->onion_c);
|
||||||
@ -3650,6 +3673,8 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
|||||||
m->group_handler = new_dht_groupchats(m);
|
m->group_handler = new_dht_groupchats(m);
|
||||||
|
|
||||||
if (m->group_handler == nullptr) {
|
if (m->group_handler == nullptr) {
|
||||||
|
LOGGER_WARNING(m->log, "conferences initialisation failed");
|
||||||
|
|
||||||
kill_onion(m->onion);
|
kill_onion(m->onion);
|
||||||
kill_onion_announce(m->onion_a);
|
kill_onion_announce(m->onion_a);
|
||||||
kill_onion_client(m->onion_c);
|
kill_onion_client(m->onion_c);
|
||||||
@ -3674,6 +3699,8 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
|||||||
m->onion, m->forwarding);
|
m->onion, m->forwarding);
|
||||||
|
|
||||||
if (m->tcp_server == nullptr) {
|
if (m->tcp_server == nullptr) {
|
||||||
|
LOGGER_WARNING(m->log, "TCP server initialisation failed");
|
||||||
|
|
||||||
kill_onion(m->onion);
|
kill_onion(m->onion);
|
||||||
kill_onion_announce(m->onion_a);
|
kill_onion_announce(m->onion_a);
|
||||||
#ifndef VANILLA_NACL
|
#ifndef VANILLA_NACL
|
||||||
|
@ -201,7 +201,11 @@ int read_tcp_packet(
|
|||||||
const uint16_t count = net_socket_data_recv_buffer(ns, sock);
|
const uint16_t count = net_socket_data_recv_buffer(ns, sock);
|
||||||
|
|
||||||
if (count < length) {
|
if (count < length) {
|
||||||
|
if (count != 0) {
|
||||||
|
// Only log when there are some bytes available, as empty buffer
|
||||||
|
// is a very common case and this spams our logs.
|
||||||
LOGGER_TRACE(logger, "recv buffer has %d bytes, but requested %d bytes", count, length);
|
LOGGER_TRACE(logger, "recv buffer has %d bytes, but requested %d bytes", count, length);
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ bool tcp_get_random_conn_ip_port(const TCP_Connections *tcp_c, IP_Port *ip_port)
|
|||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
*/
|
*/
|
||||||
non_null()
|
non_null()
|
||||||
int tcp_send_onion_request(TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *data,
|
int tcp_send_onion_request(TCP_Connections *tcp_c, uint32_t tcp_connections_number, const uint8_t *data,
|
||||||
uint16_t length);
|
uint16_t length);
|
||||||
|
|
||||||
/** @brief Set if we want TCP_connection to allocate some connection for onion use.
|
/** @brief Set if we want TCP_connection to allocate some connection for onion use.
|
||||||
|
@ -660,7 +660,7 @@ Announcements *new_announcements(const Logger *log, const Memory *mem, const Ran
|
|||||||
announce->public_key = dht_get_self_public_key(announce->dht);
|
announce->public_key = dht_get_self_public_key(announce->dht);
|
||||||
announce->secret_key = dht_get_self_secret_key(announce->dht);
|
announce->secret_key = dht_get_self_secret_key(announce->dht);
|
||||||
new_hmac_key(announce->rng, announce->hmac_key);
|
new_hmac_key(announce->rng, announce->hmac_key);
|
||||||
announce->shared_keys = shared_key_cache_new(mono_time, mem, announce->secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
announce->shared_keys = shared_key_cache_new(log, mono_time, mem, announce->secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
||||||
if (announce->shared_keys == nullptr) {
|
if (announce->shared_keys == nullptr) {
|
||||||
free(announce);
|
free(announce);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#define GNU_PRINTF(f, a)
|
#define GNU_PRINTF(f, a)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__GNUC__) && defined(_DEBUG) && !defined(__OPTIMIZE__)
|
#if defined(__GNUC__) && defined(_DEBUG)
|
||||||
#define non_null(...) __attribute__((__nonnull__(__VA_ARGS__)))
|
#define non_null(...) __attribute__((__nonnull__(__VA_ARGS__)))
|
||||||
#else
|
#else
|
||||||
#define non_null(...)
|
#define non_null(...)
|
||||||
|
44
external/toxcore/c-toxcore/toxcore/bin_pack.c
vendored
44
external/toxcore/c-toxcore/toxcore/bin_pack.c
vendored
@ -62,21 +62,47 @@ static void bin_pack_init(Bin_Pack *bp, uint8_t *buf, uint32_t buf_size)
|
|||||||
cmp_init(&bp->ctx, bp, null_reader, null_skipper, buf_writer);
|
cmp_init(&bp->ctx, bp, null_reader, null_skipper, buf_writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bin_pack_obj(bin_pack_cb *callback, const void *obj, uint8_t *buf, uint32_t buf_size)
|
uint32_t bin_pack_obj_size(bin_pack_cb *callback, const Logger *logger, const void *obj)
|
||||||
{
|
|
||||||
Bin_Pack bp;
|
|
||||||
bin_pack_init(&bp, buf, buf_size);
|
|
||||||
return callback(&bp, obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t bin_pack_obj_size(bin_pack_cb *callback, const void *obj)
|
|
||||||
{
|
{
|
||||||
Bin_Pack bp;
|
Bin_Pack bp;
|
||||||
bin_pack_init(&bp, nullptr, 0);
|
bin_pack_init(&bp, nullptr, 0);
|
||||||
callback(&bp, obj);
|
if (!callback(&bp, logger, obj)) {
|
||||||
|
return UINT32_MAX;
|
||||||
|
}
|
||||||
return bp.bytes_pos;
|
return bp.bytes_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool bin_pack_obj(bin_pack_cb *callback, const Logger *logger, const void *obj, uint8_t *buf, uint32_t buf_size)
|
||||||
|
{
|
||||||
|
Bin_Pack bp;
|
||||||
|
bin_pack_init(&bp, buf, buf_size);
|
||||||
|
return callback(&bp, logger, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t bin_pack_obj_array_size(bin_pack_array_cb *callback, const Logger *logger, const void *arr, uint32_t count)
|
||||||
|
{
|
||||||
|
Bin_Pack bp;
|
||||||
|
bin_pack_init(&bp, nullptr, 0);
|
||||||
|
for (uint32_t i = 0; i < count; ++i) {
|
||||||
|
if (!callback(&bp, logger, arr, i)) {
|
||||||
|
return UINT32_MAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bp.bytes_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bin_pack_obj_array(bin_pack_array_cb *callback, const Logger *logger, const void *arr, uint32_t count, uint8_t *buf, uint32_t buf_size)
|
||||||
|
{
|
||||||
|
Bin_Pack bp;
|
||||||
|
bin_pack_init(&bp, buf, buf_size);
|
||||||
|
for (uint32_t i = 0; i < count; ++i) {
|
||||||
|
if (!callback(&bp, logger, arr, i)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Bin_Pack *bin_pack_new(uint8_t *buf, uint32_t buf_size)
|
Bin_Pack *bin_pack_new(uint8_t *buf, uint32_t buf_size)
|
||||||
{
|
{
|
||||||
Bin_Pack *bp = (Bin_Pack *)calloc(1, sizeof(Bin_Pack));
|
Bin_Pack *bp = (Bin_Pack *)calloc(1, sizeof(Bin_Pack));
|
||||||
|
67
external/toxcore/c-toxcore/toxcore/bin_pack.h
vendored
67
external/toxcore/c-toxcore/toxcore/bin_pack.h
vendored
@ -8,6 +8,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "attributes.h"
|
#include "attributes.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -23,18 +24,29 @@ typedef struct Bin_Pack Bin_Pack;
|
|||||||
* This function would typically cast the `void *` to the actual object pointer type and then call
|
* This function would typically cast the `void *` to the actual object pointer type and then call
|
||||||
* more appropriately typed packing functions.
|
* more appropriately typed packing functions.
|
||||||
*/
|
*/
|
||||||
typedef bool bin_pack_cb(Bin_Pack *bp, const void *obj);
|
typedef bool bin_pack_cb(Bin_Pack *bp, const Logger *logger, const void *obj);
|
||||||
|
|
||||||
|
/** @brief Function used to pack an array of objects.
|
||||||
|
*
|
||||||
|
* This function would typically cast the `void *` to the actual object pointer type and then call
|
||||||
|
* more appropriately typed packing functions.
|
||||||
|
*
|
||||||
|
* @param arr is the object array as void pointer.
|
||||||
|
* @param index is the index in the object array that is currently being packed.
|
||||||
|
*/
|
||||||
|
typedef bool bin_pack_array_cb(Bin_Pack *bp, const Logger *logger, const void *arr, uint32_t index);
|
||||||
|
|
||||||
/** @brief Determine the serialised size of an object.
|
/** @brief Determine the serialised size of an object.
|
||||||
*
|
*
|
||||||
* @param callback The function called on the created packer and packed object.
|
* @param callback The function called on the created packer and packed object.
|
||||||
|
* @param logger Optional logger object to pass to the callback.
|
||||||
* @param obj The object to be packed, passed as `obj` to the callback.
|
* @param obj The object to be packed, passed as `obj` to the callback.
|
||||||
*
|
*
|
||||||
* @return The packed size of the passed object according to the callback. UINT32_MAX in case of
|
* @return The packed size of the passed object according to the callback.
|
||||||
* errors such as buffer overflow.
|
* @retval UINT32_MAX in case of errors such as buffer overflow.
|
||||||
*/
|
*/
|
||||||
non_null(1) nullable(2)
|
non_null(1) nullable(2, 3)
|
||||||
uint32_t bin_pack_obj_size(bin_pack_cb *callback, const void *obj);
|
uint32_t bin_pack_obj_size(bin_pack_cb *callback, const Logger *logger, const void *obj);
|
||||||
|
|
||||||
/** @brief Pack an object into a buffer of a given size.
|
/** @brief Pack an object into a buffer of a given size.
|
||||||
*
|
*
|
||||||
@ -45,14 +57,57 @@ uint32_t bin_pack_obj_size(bin_pack_cb *callback, const void *obj);
|
|||||||
* overflows `uint32_t`, this function returns `false`.
|
* overflows `uint32_t`, this function returns `false`.
|
||||||
*
|
*
|
||||||
* @param callback The function called on the created packer and packed object.
|
* @param callback The function called on the created packer and packed object.
|
||||||
|
* @param logger Optional logger object to pass to the callback.
|
||||||
* @param obj The object to be packed, passed as `obj` to the callback.
|
* @param obj The object to be packed, passed as `obj` to the callback.
|
||||||
* @param buf A byte array large enough to hold the serialised representation of `obj`.
|
* @param buf A byte array large enough to hold the serialised representation of `obj`.
|
||||||
* @param buf_size The size of the byte array. Can be `UINT32_MAX` to disable bounds checking.
|
* @param buf_size The size of the byte array. Can be `UINT32_MAX` to disable bounds checking.
|
||||||
*
|
*
|
||||||
* @retval false if an error occurred (e.g. buffer overflow).
|
* @retval false if an error occurred (e.g. buffer overflow).
|
||||||
*/
|
*/
|
||||||
|
non_null(1, 4) nullable(2, 3)
|
||||||
|
bool bin_pack_obj(bin_pack_cb *callback, const Logger *logger, const void *obj, uint8_t *buf, uint32_t buf_size);
|
||||||
|
|
||||||
|
/** @brief Determine the serialised size of an object array.
|
||||||
|
*
|
||||||
|
* Calls the callback `count` times with increasing `index` argument from 0 to
|
||||||
|
* `count`. This function is here just so we don't need to write the same
|
||||||
|
* trivial loop many times and so we don't need an extra struct just to contain
|
||||||
|
* an array with size so it can be passed to `bin_pack_obj_size`.
|
||||||
|
*
|
||||||
|
* @param callback The function called on the created packer and each object to
|
||||||
|
* be packed.
|
||||||
|
* @param logger Optional logger object to pass to the callback.
|
||||||
|
* @param arr The object array to be packed, passed as `arr` to the callback.
|
||||||
|
* @param count The number of elements in the object array.
|
||||||
|
*
|
||||||
|
* @return The packed size of the passed object array according to the callback.
|
||||||
|
* @retval UINT32_MAX in case of errors such as buffer overflow.
|
||||||
|
*/
|
||||||
non_null(1, 3) nullable(2)
|
non_null(1, 3) nullable(2)
|
||||||
bool bin_pack_obj(bin_pack_cb *callback, const void *obj, uint8_t *buf, uint32_t buf_size);
|
uint32_t bin_pack_obj_array_size(bin_pack_array_cb *callback, const Logger *logger, const void *arr, uint32_t count);
|
||||||
|
|
||||||
|
/** @brief Pack an object array into a buffer of a given size.
|
||||||
|
*
|
||||||
|
* Calls the callback `count` times with increasing `index` argument from 0 to
|
||||||
|
* `count`. This function is here just so we don't need to write the same
|
||||||
|
* trivial loop many times and so we don't need an extra struct just to contain
|
||||||
|
* an array with size so it can be passed to `bin_pack_obj`.
|
||||||
|
*
|
||||||
|
* Similar to `bin_pack_obj` but for arrays. Does not write the array length, so
|
||||||
|
* if you need that, write it manually using `bin_pack_array`.
|
||||||
|
*
|
||||||
|
* @param callback The function called on the created packer and packed object
|
||||||
|
* array.
|
||||||
|
* @param logger Optional logger object to pass to the callback.
|
||||||
|
* @param arr The object array to be packed, passed as `arr` to the callback.
|
||||||
|
* @param count The number of elements in the object array.
|
||||||
|
* @param buf A byte array large enough to hold the serialised representation of `arr`.
|
||||||
|
* @param buf_size The size of the byte array. Can be `UINT32_MAX` to disable bounds checking.
|
||||||
|
*
|
||||||
|
* @retval false if an error occurred (e.g. buffer overflow).
|
||||||
|
*/
|
||||||
|
non_null(1, 3, 5) nullable(2)
|
||||||
|
bool bin_pack_obj_array(bin_pack_array_cb *callback, const Logger *logger, const void *arr, uint32_t count, uint8_t *buf, uint32_t buf_size);
|
||||||
|
|
||||||
/** @brief Allocate a new packer object.
|
/** @brief Allocate a new packer object.
|
||||||
*
|
*
|
||||||
|
@ -12,11 +12,30 @@ namespace {
|
|||||||
|
|
||||||
using HmacKey = std::array<uint8_t, CRYPTO_HMAC_KEY_SIZE>;
|
using HmacKey = std::array<uint8_t, CRYPTO_HMAC_KEY_SIZE>;
|
||||||
using Hmac = std::array<uint8_t, CRYPTO_HMAC_SIZE>;
|
using Hmac = std::array<uint8_t, CRYPTO_HMAC_SIZE>;
|
||||||
|
using PublicKey = std::array<uint8_t, CRYPTO_PUBLIC_KEY_SIZE>;
|
||||||
|
using SecretKey = std::array<uint8_t, CRYPTO_SECRET_KEY_SIZE>;
|
||||||
using ExtPublicKey = std::array<uint8_t, EXT_PUBLIC_KEY_SIZE>;
|
using ExtPublicKey = std::array<uint8_t, EXT_PUBLIC_KEY_SIZE>;
|
||||||
using ExtSecretKey = std::array<uint8_t, EXT_SECRET_KEY_SIZE>;
|
using ExtSecretKey = std::array<uint8_t, EXT_SECRET_KEY_SIZE>;
|
||||||
using Signature = std::array<uint8_t, CRYPTO_SIGNATURE_SIZE>;
|
using Signature = std::array<uint8_t, CRYPTO_SIGNATURE_SIZE>;
|
||||||
using Nonce = std::array<uint8_t, CRYPTO_NONCE_SIZE>;
|
using Nonce = std::array<uint8_t, CRYPTO_NONCE_SIZE>;
|
||||||
|
|
||||||
|
TEST(CryptoCore, EncryptLargeData)
|
||||||
|
{
|
||||||
|
const Random *rng = system_random();
|
||||||
|
ASSERT_NE(rng, nullptr);
|
||||||
|
|
||||||
|
Nonce nonce{};
|
||||||
|
PublicKey pk;
|
||||||
|
SecretKey sk;
|
||||||
|
crypto_new_keypair(rng, pk.data(), sk.data());
|
||||||
|
|
||||||
|
// 100 MiB of data (all zeroes, doesn't matter what's inside).
|
||||||
|
std::vector<uint8_t> plain(100 * 1024 * 1024);
|
||||||
|
std::vector<uint8_t> encrypted(plain.size() + CRYPTO_MAC_SIZE);
|
||||||
|
|
||||||
|
encrypt_data(pk.data(), sk.data(), nonce.data(), plain.data(), plain.size(), encrypted.data());
|
||||||
|
}
|
||||||
|
|
||||||
TEST(CryptoCore, IncrementNonce)
|
TEST(CryptoCore, IncrementNonce)
|
||||||
{
|
{
|
||||||
Nonce nonce{};
|
Nonce nonce{};
|
||||||
@ -60,7 +79,8 @@ TEST(CryptoCore, Signatures)
|
|||||||
|
|
||||||
EXPECT_TRUE(create_extended_keypair(pk.data(), sk.data()));
|
EXPECT_TRUE(create_extended_keypair(pk.data(), sk.data()));
|
||||||
|
|
||||||
std::vector<uint8_t> message;
|
std::vector<uint8_t> message{0};
|
||||||
|
message.clear();
|
||||||
|
|
||||||
// Try a few different sizes, including empty 0 length message.
|
// Try a few different sizes, including empty 0 length message.
|
||||||
for (uint8_t i = 0; i < 100; ++i) {
|
for (uint8_t i = 0; i < 100; ++i) {
|
||||||
@ -82,7 +102,8 @@ TEST(CryptoCore, Hmac)
|
|||||||
HmacKey sk;
|
HmacKey sk;
|
||||||
new_hmac_key(rng, sk.data());
|
new_hmac_key(rng, sk.data());
|
||||||
|
|
||||||
std::vector<uint8_t> message;
|
std::vector<uint8_t> message{0};
|
||||||
|
message.clear();
|
||||||
|
|
||||||
// Try a few different sizes, including empty 0 length message.
|
// Try a few different sizes, including empty 0 length message.
|
||||||
for (uint8_t i = 0; i < 100; ++i) {
|
for (uint8_t i = 0; i < 100; ++i) {
|
||||||
|
@ -50,8 +50,10 @@ TEST_F(Announces, CanBeCreatedAndDeleted)
|
|||||||
GC_Public_Announce ann{};
|
GC_Public_Announce ann{};
|
||||||
ann.chat_public_key[0] = 0x88;
|
ann.chat_public_key[0] = 0x88;
|
||||||
ASSERT_NE(gca_add_announce(mono_time_, gca_, &ann), nullptr);
|
ASSERT_NE(gca_add_announce(mono_time_, gca_, &ann), nullptr);
|
||||||
|
#ifndef _DEBUG
|
||||||
ASSERT_EQ(gca_add_announce(mono_time_, gca_, nullptr), nullptr);
|
ASSERT_EQ(gca_add_announce(mono_time_, gca_, nullptr), nullptr);
|
||||||
ASSERT_EQ(gca_add_announce(mono_time_, nullptr, &ann), nullptr);
|
ASSERT_EQ(gca_add_announce(mono_time_, nullptr, &ann), nullptr);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Announces, AnnouncesCanTimeOut)
|
TEST_F(Announces, AnnouncesCanTimeOut)
|
||||||
@ -103,7 +105,9 @@ TEST_F(Announces, AnnouncesGetAndCleanup)
|
|||||||
|
|
||||||
cleanup_gca(gca_, ann2.chat_public_key);
|
cleanup_gca(gca_, ann2.chat_public_key);
|
||||||
ASSERT_EQ(gca_get_announces(gca_, &announces, 1, ann2.chat_public_key, empty_pk), 0);
|
ASSERT_EQ(gca_get_announces(gca_, &announces, 1, ann2.chat_public_key, empty_pk), 0);
|
||||||
|
#ifndef _DEBUG
|
||||||
ASSERT_EQ(gca_get_announces(gca_, nullptr, 1, ann2.chat_public_key, empty_pk), -1);
|
ASSERT_EQ(gca_get_announces(gca_, nullptr, 1, ann2.chat_public_key, empty_pk), -1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AnnouncesPack : ::testing::Test {
|
struct AnnouncesPack : ::testing::Test {
|
||||||
@ -162,19 +166,23 @@ TEST_F(AnnouncesPack, PublicAnnounceCanBePackedAndUnpacked)
|
|||||||
|
|
||||||
TEST_F(AnnouncesPack, UnpackEmptyPublicAnnounce)
|
TEST_F(AnnouncesPack, UnpackEmptyPublicAnnounce)
|
||||||
{
|
{
|
||||||
|
#ifndef _DEBUG
|
||||||
GC_Public_Announce ann{};
|
GC_Public_Announce ann{};
|
||||||
std::vector<uint8_t> packed(GCA_PUBLIC_ANNOUNCE_MAX_SIZE);
|
std::vector<uint8_t> packed(GCA_PUBLIC_ANNOUNCE_MAX_SIZE);
|
||||||
|
|
||||||
EXPECT_EQ(gca_unpack_public_announce(logger_, nullptr, 0, &ann), -1);
|
EXPECT_EQ(gca_unpack_public_announce(logger_, nullptr, 0, &ann), -1);
|
||||||
EXPECT_EQ(gca_unpack_public_announce(logger_, packed.data(), packed.size(), nullptr), -1);
|
EXPECT_EQ(gca_unpack_public_announce(logger_, packed.data(), packed.size(), nullptr), -1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AnnouncesPack, PackEmptyPublicAnnounce)
|
TEST_F(AnnouncesPack, PackEmptyPublicAnnounce)
|
||||||
{
|
{
|
||||||
|
#ifndef _DEBUG
|
||||||
GC_Public_Announce ann{};
|
GC_Public_Announce ann{};
|
||||||
std::vector<uint8_t> packed(GCA_PUBLIC_ANNOUNCE_MAX_SIZE);
|
std::vector<uint8_t> packed(GCA_PUBLIC_ANNOUNCE_MAX_SIZE);
|
||||||
EXPECT_EQ(gca_pack_public_announce(logger_, packed.data(), packed.size(), nullptr), -1);
|
EXPECT_EQ(gca_pack_public_announce(logger_, packed.data(), packed.size(), nullptr), -1);
|
||||||
EXPECT_EQ(gca_pack_public_announce(logger_, nullptr, 0, &ann), -1);
|
EXPECT_EQ(gca_pack_public_announce(logger_, nullptr, 0, &ann), -1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AnnouncesPack, PublicAnnouncePackNull)
|
TEST_F(AnnouncesPack, PublicAnnouncePackNull)
|
||||||
@ -198,7 +206,9 @@ TEST_F(AnnouncesPack, PublicAnnouncePackNull)
|
|||||||
|
|
||||||
TEST_F(AnnouncesPack, AnnouncesValidationCheck)
|
TEST_F(AnnouncesPack, AnnouncesValidationCheck)
|
||||||
{
|
{
|
||||||
|
#ifndef _DEBUG
|
||||||
EXPECT_EQ(gca_is_valid_announce(nullptr), false);
|
EXPECT_EQ(gca_is_valid_announce(nullptr), false);
|
||||||
|
#endif
|
||||||
|
|
||||||
GC_Announce announce = {0};
|
GC_Announce announce = {0};
|
||||||
EXPECT_EQ(gca_is_valid_announce(&announce), false);
|
EXPECT_EQ(gca_is_valid_announce(&announce), false);
|
||||||
@ -217,8 +227,10 @@ TEST_F(AnnouncesPack, UnpackIncompleteAnnouncesList)
|
|||||||
|
|
||||||
GC_Announce announce;
|
GC_Announce announce;
|
||||||
EXPECT_EQ(gca_unpack_announces_list(logger_, data, sizeof(data), &announce, 1), -1);
|
EXPECT_EQ(gca_unpack_announces_list(logger_, data, sizeof(data), &announce, 1), -1);
|
||||||
|
#ifndef _DEBUG
|
||||||
EXPECT_EQ(gca_unpack_announces_list(logger_, data, sizeof(data), nullptr, 1), -1);
|
EXPECT_EQ(gca_unpack_announces_list(logger_, data, sizeof(data), nullptr, 1), -1);
|
||||||
EXPECT_EQ(gca_unpack_announces_list(logger_, nullptr, 0, &announce, 1), -1);
|
EXPECT_EQ(gca_unpack_announces_list(logger_, nullptr, 0, &announce, 1), -1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AnnouncesPack, PackedAnnouncesListCanBeUnpacked)
|
TEST_F(AnnouncesPack, PackedAnnouncesListCanBeUnpacked)
|
||||||
@ -246,17 +258,21 @@ TEST_F(AnnouncesPack, PackingEmptyAnnounceFails)
|
|||||||
std::vector<uint8_t> packed(gca_pack_announces_list_size(1));
|
std::vector<uint8_t> packed(gca_pack_announces_list_size(1));
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
gca_pack_announces_list(logger_, packed.data(), packed.size(), &announce, 1, nullptr), -1);
|
gca_pack_announces_list(logger_, packed.data(), packed.size(), &announce, 1, nullptr), -1);
|
||||||
|
#ifndef _DEBUG
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
gca_pack_announces_list(logger_, packed.data(), packed.size(), nullptr, 1, nullptr), -1);
|
gca_pack_announces_list(logger_, packed.data(), packed.size(), nullptr, 1, nullptr), -1);
|
||||||
EXPECT_EQ(gca_pack_announces_list(logger_, nullptr, 0, &announce, 1, nullptr), -1);
|
EXPECT_EQ(gca_pack_announces_list(logger_, nullptr, 0, &announce, 1, nullptr), -1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AnnouncesPack, PackAnnounceNull)
|
TEST_F(AnnouncesPack, PackAnnounceNull)
|
||||||
{
|
{
|
||||||
|
#ifndef _DEBUG
|
||||||
std::vector<uint8_t> data(GCA_ANNOUNCE_MAX_SIZE);
|
std::vector<uint8_t> data(GCA_ANNOUNCE_MAX_SIZE);
|
||||||
GC_Announce announce;
|
GC_Announce announce;
|
||||||
ASSERT_EQ(gca_pack_announce(logger_, nullptr, 0, &announce), -1);
|
ASSERT_EQ(gca_pack_announce(logger_, nullptr, 0, &announce), -1);
|
||||||
ASSERT_EQ(gca_pack_announce(logger_, data.data(), data.size(), nullptr), -1);
|
ASSERT_EQ(gca_pack_announce(logger_, data.data(), data.size(), nullptr), -1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
107
external/toxcore/c-toxcore/toxcore/group_chats.c
vendored
107
external/toxcore/c-toxcore/toxcore/group_chats.c
vendored
@ -182,11 +182,7 @@ static void kill_group_friend_connection(const GC_Session *c, const GC_Chat *cha
|
|||||||
|
|
||||||
uint16_t gc_get_wrapped_packet_size(uint16_t length, Net_Packet_Type packet_type)
|
uint16_t gc_get_wrapped_packet_size(uint16_t length, Net_Packet_Type packet_type)
|
||||||
{
|
{
|
||||||
if (packet_type == NET_PACKET_GC_LOSSY) {
|
assert(length <= (packet_type == NET_PACKET_GC_LOSSY ? MAX_GC_CUSTOM_LOSSY_PACKET_SIZE : MAX_GC_PACKET_CHUNK_SIZE));
|
||||||
assert(length <= MAX_GC_CUSTOM_LOSSY_PACKET_SIZE);
|
|
||||||
} else {
|
|
||||||
assert(length <= MAX_GC_PACKET_CHUNK_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint16_t min_header_size = packet_type == NET_PACKET_GC_LOSSY
|
const uint16_t min_header_size = packet_type == NET_PACKET_GC_LOSSY
|
||||||
? GC_MIN_LOSSY_PAYLOAD_SIZE
|
? GC_MIN_LOSSY_PAYLOAD_SIZE
|
||||||
@ -230,16 +226,22 @@ GC_Connection *get_gc_connection(const GC_Chat *chat, int peer_number)
|
|||||||
return &peer->gconn;
|
return &peer->gconn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the amount of empty padding a packet of designated length should have. */
|
/** Returns the max packet size, not wrapped */
|
||||||
static uint16_t group_packet_padding_length(uint16_t length, uint8_t net_packet_type)
|
static uint16_t group_packet_max_packet_size(Net_Packet_Type net_packet_type)
|
||||||
{
|
{
|
||||||
if (net_packet_type == NET_PACKET_GC_LOSSY) {
|
if (net_packet_type == NET_PACKET_GC_LOSSY) {
|
||||||
return (MAX_GC_CUSTOM_LOSSY_PACKET_SIZE - length) % GC_MAX_PACKET_PADDING;
|
return MAX_GC_CUSTOM_LOSSY_PACKET_SIZE;
|
||||||
} else {
|
} else {
|
||||||
return (MAX_GC_PACKET_CHUNK_SIZE - length) % GC_MAX_PACKET_PADDING;
|
return MAX_GC_PACKET_CHUNK_SIZE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns the amount of empty padding a packet of designated length should have. */
|
||||||
|
static uint16_t group_packet_padding_length(uint16_t length, uint16_t max_length)
|
||||||
|
{
|
||||||
|
return (max_length - length) % GC_MAX_PACKET_PADDING;
|
||||||
|
}
|
||||||
|
|
||||||
void gc_get_self_nick(const GC_Chat *chat, uint8_t *nick)
|
void gc_get_self_nick(const GC_Chat *chat, uint8_t *nick)
|
||||||
{
|
{
|
||||||
if (nick != nullptr) {
|
if (nick != nullptr) {
|
||||||
@ -1278,8 +1280,8 @@ static uint16_t unpack_gc_shared_state(GC_SharedState *shared_state, const uint8
|
|||||||
memcpy(&voice_state, data + len_processed, sizeof(uint8_t));
|
memcpy(&voice_state, data + len_processed, sizeof(uint8_t));
|
||||||
len_processed += sizeof(uint8_t);
|
len_processed += sizeof(uint8_t);
|
||||||
|
|
||||||
shared_state->voice_state = (Group_Voice_State)voice_state;
|
shared_state->voice_state = group_voice_state_from_int(voice_state);
|
||||||
shared_state->privacy_state = (Group_Privacy_State)privacy_state;
|
shared_state->privacy_state = group_privacy_state_from_int(privacy_state);
|
||||||
|
|
||||||
return len_processed;
|
return len_processed;
|
||||||
}
|
}
|
||||||
@ -1491,9 +1493,10 @@ static int group_packet_unwrap(const Logger *log, const GC_Connection *gconn, ui
|
|||||||
int group_packet_wrap(
|
int group_packet_wrap(
|
||||||
const Logger *log, const Random *rng, const uint8_t *self_pk, const uint8_t *shared_key, uint8_t *packet,
|
const Logger *log, const Random *rng, const uint8_t *self_pk, const uint8_t *shared_key, uint8_t *packet,
|
||||||
uint16_t packet_size, const uint8_t *data, uint16_t length, uint64_t message_id,
|
uint16_t packet_size, const uint8_t *data, uint16_t length, uint64_t message_id,
|
||||||
uint8_t gp_packet_type, uint8_t net_packet_type)
|
uint8_t gp_packet_type, Net_Packet_Type net_packet_type)
|
||||||
{
|
{
|
||||||
const uint16_t padding_len = group_packet_padding_length(length, net_packet_type);
|
const uint16_t max_packet_size = group_packet_max_packet_size(net_packet_type);
|
||||||
|
const uint16_t padding_len = group_packet_padding_length(length, max_packet_size);
|
||||||
const uint16_t min_packet_size = net_packet_type == NET_PACKET_GC_LOSSLESS
|
const uint16_t min_packet_size = net_packet_type == NET_PACKET_GC_LOSSLESS
|
||||||
? length + padding_len + CRYPTO_MAC_SIZE + 1 + ENC_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + GC_MESSAGE_ID_BYTES + 1
|
? length + padding_len + CRYPTO_MAC_SIZE + 1 + ENC_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + GC_MESSAGE_ID_BYTES + 1
|
||||||
: length + padding_len + CRYPTO_MAC_SIZE + 1 + ENC_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + 1;
|
: length + padding_len + CRYPTO_MAC_SIZE + 1 + ENC_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + 1;
|
||||||
@ -1503,17 +1506,10 @@ int group_packet_wrap(
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_packet_type == NET_PACKET_GC_LOSSY) {
|
if (length > max_packet_size) {
|
||||||
if (length > MAX_GC_CUSTOM_LOSSY_PACKET_SIZE) {
|
LOGGER_ERROR(log, "Packet payload size (%u) exceeds maximum (%u)", length, max_packet_size);
|
||||||
LOGGER_ERROR(log, "Packet payload size (%u) exceeds maximum (%u)", length, MAX_GC_CUSTOM_LOSSY_PACKET_SIZE);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (length > MAX_GC_PACKET_CHUNK_SIZE) {
|
|
||||||
LOGGER_ERROR(log, "Packet payload size (%u) exceeds maximum (%u)", length, MAX_GC_PACKET_CHUNK_SIZE);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t *plain = (uint8_t *)malloc(packet_size);
|
uint8_t *plain = (uint8_t *)malloc(packet_size);
|
||||||
|
|
||||||
@ -3521,12 +3517,69 @@ int gc_get_peer_public_key_by_peer_id(const GC_Chat *chat, uint32_t peer_id, uin
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Puts a string of the IP associated with `ip_port` in `ip_str` if the
|
||||||
|
* connection is direct, otherwise puts a placeholder in the buffer indicating that
|
||||||
|
* the IP cannot be displayed.
|
||||||
|
*/
|
||||||
|
non_null()
|
||||||
|
static void get_gc_ip_ntoa(const IP_Port *ip_port, Ip_Ntoa *ip_str)
|
||||||
|
{
|
||||||
|
net_ip_ntoa(&ip_port->ip, ip_str);
|
||||||
|
|
||||||
|
if (!ip_str->ip_is_valid) {
|
||||||
|
ip_str->buf[0] = '-';
|
||||||
|
ip_str->buf[1] = '\0';
|
||||||
|
ip_str->length = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int gc_get_peer_ip_address_size(const GC_Chat *chat, uint32_t peer_id)
|
||||||
|
{
|
||||||
|
const int peer_number = get_peer_number_of_peer_id(chat, peer_id);
|
||||||
|
const GC_Connection *gconn = get_gc_connection(chat, peer_number);
|
||||||
|
|
||||||
|
if (gconn == nullptr) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const IP_Port *ip_port = peer_number == 0 ? &chat->self_ip_port : &gconn->addr.ip_port;
|
||||||
|
|
||||||
|
Ip_Ntoa ip_str;
|
||||||
|
get_gc_ip_ntoa(ip_port, &ip_str);
|
||||||
|
|
||||||
|
return ip_str.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gc_get_peer_ip_address(const GC_Chat *chat, uint32_t peer_id, uint8_t *ip_addr)
|
||||||
|
{
|
||||||
|
const int peer_number = get_peer_number_of_peer_id(chat, peer_id);
|
||||||
|
const GC_Connection *gconn = get_gc_connection(chat, peer_number);
|
||||||
|
|
||||||
|
if (gconn == nullptr) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ip_addr == nullptr) {
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
const IP_Port *ip_port = peer_number == 0 ? &chat->self_ip_port : &gconn->addr.ip_port;
|
||||||
|
|
||||||
|
Ip_Ntoa ip_str;
|
||||||
|
get_gc_ip_ntoa(ip_port, &ip_str);
|
||||||
|
|
||||||
|
assert(ip_str.length <= IP_NTOA_LEN);
|
||||||
|
memcpy(ip_addr, ip_str.buf, ip_str.length);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int gc_get_peer_connection_status(const GC_Chat *chat, uint32_t peer_id)
|
unsigned int gc_get_peer_connection_status(const GC_Chat *chat, uint32_t peer_id)
|
||||||
{
|
{
|
||||||
const int peer_number = get_peer_number_of_peer_id(chat, peer_id);
|
const int peer_number = get_peer_number_of_peer_id(chat, peer_id);
|
||||||
|
|
||||||
if (peer_number_is_self(peer_number)) { // we cannot have a connection with ourselves
|
if (peer_number_is_self(peer_number)) {
|
||||||
return 0;
|
return chat->self_udp_status == SELF_UDP_STATUS_NONE ? 1 : 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
const GC_Connection *gconn = get_gc_connection(chat, peer_number);
|
const GC_Connection *gconn = get_gc_connection(chat, peer_number);
|
||||||
@ -7239,7 +7292,9 @@ static int get_new_group_index(GC_Session *c)
|
|||||||
|
|
||||||
c->chats[new_index] = empty_gc_chat;
|
c->chats[new_index] = empty_gc_chat;
|
||||||
|
|
||||||
memset(&c->chats[new_index].saved_invites, -1, sizeof(c->chats[new_index].saved_invites));
|
for (size_t i = 0; i < sizeof(c->chats[new_index].saved_invites)/sizeof(*c->chats[new_index].saved_invites); ++i) {
|
||||||
|
c->chats[new_index].saved_invites[i] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
++c->chats_index;
|
++c->chats_index;
|
||||||
|
|
||||||
@ -7294,7 +7349,7 @@ static bool init_gc_tcp_connection(const GC_Session *c, GC_Chat *chat)
|
|||||||
|
|
||||||
/** Initializes default shared state values. */
|
/** Initializes default shared state values. */
|
||||||
non_null()
|
non_null()
|
||||||
static void init_gc_shared_state(GC_Chat *chat, const Group_Privacy_State privacy_state)
|
static void init_gc_shared_state(GC_Chat *chat, Group_Privacy_State privacy_state)
|
||||||
{
|
{
|
||||||
chat->shared_state.maxpeers = MAX_GC_PEERS_DEFAULT;
|
chat->shared_state.maxpeers = MAX_GC_PEERS_DEFAULT;
|
||||||
chat->shared_state.privacy_state = privacy_state;
|
chat->shared_state.privacy_state = privacy_state;
|
||||||
|
32
external/toxcore/c-toxcore/toxcore/group_chats.h
vendored
32
external/toxcore/c-toxcore/toxcore/group_chats.h
vendored
@ -142,7 +142,7 @@ non_null(1, 2, 3, 4, 5) nullable(7)
|
|||||||
int group_packet_wrap(
|
int group_packet_wrap(
|
||||||
const Logger *log, const Random *rng, const uint8_t *self_pk, const uint8_t *shared_key, uint8_t *packet,
|
const Logger *log, const Random *rng, const uint8_t *self_pk, const uint8_t *shared_key, uint8_t *packet,
|
||||||
uint16_t packet_size, const uint8_t *data, uint16_t length, uint64_t message_id,
|
uint16_t packet_size, const uint8_t *data, uint16_t length, uint64_t message_id,
|
||||||
uint8_t gp_packet_type, uint8_t net_packet_type);
|
uint8_t gp_packet_type, Net_Packet_Type net_packet_type);
|
||||||
|
|
||||||
/** @brief Returns the size of a wrapped/encrypted packet with a plain size of `length`.
|
/** @brief Returns the size of a wrapped/encrypted packet with a plain size of `length`.
|
||||||
*
|
*
|
||||||
@ -162,7 +162,7 @@ uint16_t gc_get_wrapped_packet_size(uint16_t length, Net_Packet_Type packet_type
|
|||||||
* Returns -4 if the sender does not have permission to speak.
|
* Returns -4 if the sender does not have permission to speak.
|
||||||
* Returns -5 if the packet fails to send.
|
* Returns -5 if the packet fails to send.
|
||||||
*/
|
*/
|
||||||
non_null(1, 2, 3, 4) nullable(5)
|
non_null(1, 2) nullable(5)
|
||||||
int gc_send_message(const GC_Chat *chat, const uint8_t *message, uint16_t length, uint8_t type,
|
int gc_send_message(const GC_Chat *chat, const uint8_t *message, uint16_t length, uint8_t type,
|
||||||
uint32_t *message_id);
|
uint32_t *message_id);
|
||||||
|
|
||||||
@ -390,11 +390,37 @@ int gc_get_peer_nick_size(const GC_Chat *chat, uint32_t peer_id);
|
|||||||
non_null(1) nullable(3)
|
non_null(1) nullable(3)
|
||||||
int gc_get_peer_public_key_by_peer_id(const GC_Chat *chat, uint32_t peer_id, uint8_t *public_key);
|
int gc_get_peer_public_key_by_peer_id(const GC_Chat *chat, uint32_t peer_id, uint8_t *public_key);
|
||||||
|
|
||||||
|
/** @brief Returns the length of the IP address for the peer designated by `peer_id`.
|
||||||
|
* Returns -1 if peer_id is invalid.
|
||||||
|
*/
|
||||||
|
non_null()
|
||||||
|
int gc_get_peer_ip_address_size(const GC_Chat *chat, uint32_t peer_id);
|
||||||
|
|
||||||
|
/** @brief Copies peer_id's IP address to `ip_addr`.
|
||||||
|
*
|
||||||
|
* If the peer is forcing TCP connections this will be a placeholder value indicating
|
||||||
|
* that their real IP address is unknown to us.
|
||||||
|
*
|
||||||
|
* If `peer_id` designates ourself, it will write either our own IP address or a
|
||||||
|
* placeholder value, depending on whether or not we're forcing TCP connections.
|
||||||
|
*
|
||||||
|
* `ip_addr` should have room for at least IP_NTOA_LEN bytes.
|
||||||
|
*
|
||||||
|
* Returns 0 on success.
|
||||||
|
* Returns -1 if peer_id is invalid or doesn't correspond to a valid peer connection.
|
||||||
|
* Returns -2 if `ip_addr` is null.
|
||||||
|
*/
|
||||||
|
non_null(1) nullable(3)
|
||||||
|
int gc_get_peer_ip_address(const GC_Chat *chat, uint32_t peer_id, uint8_t *ip_addr);
|
||||||
|
|
||||||
/** @brief Gets the connection status for peer associated with `peer_id`.
|
/** @brief Gets the connection status for peer associated with `peer_id`.
|
||||||
|
*
|
||||||
|
* If `peer_id` designates ourself, the return value indicates whether we're capable
|
||||||
|
* of making UDP connections with other peers, or are limited to TCP connections.
|
||||||
*
|
*
|
||||||
* Returns 2 if we have a direct (UDP) connection with a peer.
|
* Returns 2 if we have a direct (UDP) connection with a peer.
|
||||||
* Returns 1 if we have an indirect (TCP) connection with a peer.
|
* Returns 1 if we have an indirect (TCP) connection with a peer.
|
||||||
* Returns 0 if peer_id is invalid or corresponds to ourselves.
|
* Returns 0 if peer_id is invalid.
|
||||||
*
|
*
|
||||||
* Note: Return values must correspond to Tox_Connection enum in API.
|
* Note: Return values must correspond to Tox_Connection enum in API.
|
||||||
*/
|
*/
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
#define MAX_GC_MESSAGE_SIZE GROUP_MAX_MESSAGE_LENGTH
|
#define MAX_GC_MESSAGE_SIZE GROUP_MAX_MESSAGE_LENGTH
|
||||||
#define MAX_GC_MESSAGE_RAW_SIZE (MAX_GC_MESSAGE_SIZE + GC_MESSAGE_PSEUDO_ID_SIZE)
|
#define MAX_GC_MESSAGE_RAW_SIZE (MAX_GC_MESSAGE_SIZE + GC_MESSAGE_PSEUDO_ID_SIZE)
|
||||||
#define MAX_GC_CUSTOM_LOSSLESS_PACKET_SIZE 1373
|
#define MAX_GC_CUSTOM_LOSSLESS_PACKET_SIZE 1373
|
||||||
#define MAX_GC_CUSTOM_LOSSY_PACKET_SIZE 1000
|
#define MAX_GC_CUSTOM_LOSSY_PACKET_SIZE 1373
|
||||||
#define MAX_GC_PASSWORD_SIZE 32
|
#define MAX_GC_PASSWORD_SIZE 32
|
||||||
#define MAX_GC_SAVED_INVITES 10
|
#define MAX_GC_SAVED_INVITES 10
|
||||||
#define MAX_GC_PEERS_DEFAULT 100
|
#define MAX_GC_PEERS_DEFAULT 100
|
||||||
@ -401,7 +401,8 @@ int unpack_gc_saved_peers(GC_Chat *chat, const uint8_t *data, uint16_t length);
|
|||||||
|
|
||||||
/** @brief Packs all valid entries from saved peerlist into `data`.
|
/** @brief Packs all valid entries from saved peerlist into `data`.
|
||||||
*
|
*
|
||||||
* If `processed` is non-null it will be set to the length of the packed data.
|
* If `processed` is non-null it will be set to the length of the packed data
|
||||||
|
* on success, and will be untouched on error.
|
||||||
*
|
*
|
||||||
* Return the number of packed saved peers on success.
|
* Return the number of packed saved peers on success.
|
||||||
* Return -1 if buffer is too small.
|
* Return -1 if buffer is too small.
|
||||||
|
@ -453,6 +453,7 @@ int gcc_handle_packet_fragment(const GC_Session *c, GC_Chat *chat, uint32_t peer
|
|||||||
gconn = get_gc_connection(chat, peer_number);
|
gconn = get_gc_connection(chat, peer_number);
|
||||||
|
|
||||||
if (gconn == nullptr) {
|
if (gconn == nullptr) {
|
||||||
|
free(payload);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
50
external/toxcore/c-toxcore/toxcore/group_pack.c
vendored
50
external/toxcore/c-toxcore/toxcore/group_pack.c
vendored
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
#include "group_pack.h"
|
#include "group_pack.h"
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -19,6 +18,32 @@
|
|||||||
#include "ccompat.h"
|
#include "ccompat.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
Group_Privacy_State group_privacy_state_from_int(uint8_t value)
|
||||||
|
{
|
||||||
|
switch (value) {
|
||||||
|
case 0:
|
||||||
|
return GI_PUBLIC;
|
||||||
|
case 1:
|
||||||
|
return GI_PRIVATE;
|
||||||
|
default:
|
||||||
|
return GI_PUBLIC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Group_Voice_State group_voice_state_from_int(uint8_t value)
|
||||||
|
{
|
||||||
|
switch (value) {
|
||||||
|
case 0:
|
||||||
|
return GV_ALL;
|
||||||
|
case 1:
|
||||||
|
return GV_MODS;
|
||||||
|
case 2:
|
||||||
|
return GV_FOUNDER;
|
||||||
|
default:
|
||||||
|
return GV_ALL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
non_null()
|
non_null()
|
||||||
static bool load_unpack_state_values(GC_Chat *chat, Bin_Unpack *bu)
|
static bool load_unpack_state_values(GC_Chat *chat, Bin_Unpack *bu)
|
||||||
{
|
{
|
||||||
@ -44,8 +69,8 @@ static bool load_unpack_state_values(GC_Chat *chat, Bin_Unpack *bu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
chat->connection_state = manually_disconnected ? CS_DISCONNECTED : CS_CONNECTING;
|
chat->connection_state = manually_disconnected ? CS_DISCONNECTED : CS_CONNECTING;
|
||||||
chat->shared_state.privacy_state = (Group_Privacy_State)privacy_state;
|
chat->shared_state.privacy_state = group_privacy_state_from_int(privacy_state);
|
||||||
chat->shared_state.voice_state = (Group_Voice_State)voice_state;
|
chat->shared_state.voice_state = group_voice_state_from_int(voice_state);
|
||||||
|
|
||||||
// we always load saved groups as private in case the group became private while we were offline.
|
// we always load saved groups as private in case the group became private while we were offline.
|
||||||
// this will have no detrimental effect if the group is public, as the correct privacy
|
// this will have no detrimental effect if the group is public, as the correct privacy
|
||||||
@ -125,7 +150,7 @@ static bool load_unpack_mod_list(GC_Chat *chat, Bin_Unpack *bu)
|
|||||||
|
|
||||||
if (chat->moderation.num_mods > MOD_MAX_NUM_MODERATORS) {
|
if (chat->moderation.num_mods > MOD_MAX_NUM_MODERATORS) {
|
||||||
LOGGER_ERROR(chat->log, "moderation count %u exceeds maximum %u", chat->moderation.num_mods, MOD_MAX_NUM_MODERATORS);
|
LOGGER_ERROR(chat->log, "moderation count %u exceeds maximum %u", chat->moderation.num_mods, MOD_MAX_NUM_MODERATORS);
|
||||||
return false;
|
chat->moderation.num_mods = MOD_MAX_NUM_MODERATORS;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *packed_mod_list = (uint8_t *)malloc(chat->moderation.num_mods * MOD_LIST_ENTRY_SIZE);
|
uint8_t *packed_mod_list = (uint8_t *)malloc(chat->moderation.num_mods * MOD_LIST_ENTRY_SIZE);
|
||||||
@ -193,7 +218,10 @@ static bool load_unpack_self_info(GC_Chat *chat, Bin_Unpack *bu)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(self_nick_len <= MAX_GC_NICK_SIZE);
|
if (self_nick_len > MAX_GC_NICK_SIZE) {
|
||||||
|
LOGGER_ERROR(chat->log, "self_nick too big (%u bytes), truncating to %d", self_nick_len, MAX_GC_NICK_SIZE);
|
||||||
|
self_nick_len = MAX_GC_NICK_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!bin_unpack_bin_fixed(bu, self_nick, self_nick_len)) {
|
if (!bin_unpack_bin_fixed(bu, self_nick, self_nick_len)) {
|
||||||
LOGGER_ERROR(chat->log, "Failed to unpack self nick bytes");
|
LOGGER_ERROR(chat->log, "Failed to unpack self nick bytes");
|
||||||
@ -206,7 +234,10 @@ static bool load_unpack_self_info(GC_Chat *chat, Bin_Unpack *bu)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(chat->numpeers > 0);
|
if (chat->numpeers == 0) {
|
||||||
|
LOGGER_ERROR(chat->log, "Failed to unpack self: numpeers should be > 0");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
GC_Peer *self = &chat->group[0];
|
GC_Peer *self = &chat->group[0];
|
||||||
|
|
||||||
@ -369,9 +400,12 @@ static void save_pack_self_info(const GC_Chat *chat, Bin_Pack *bp)
|
|||||||
{
|
{
|
||||||
bin_pack_array(bp, 4);
|
bin_pack_array(bp, 4);
|
||||||
|
|
||||||
const GC_Peer *self = &chat->group[0];
|
GC_Peer *self = &chat->group[0];
|
||||||
|
|
||||||
assert(self->nick_length <= MAX_GC_NICK_SIZE);
|
if (self->nick_length > MAX_GC_NICK_SIZE) {
|
||||||
|
LOGGER_ERROR(chat->log, "self_nick is too big (%u). Truncating to %d", self->nick_length, MAX_GC_NICK_SIZE);
|
||||||
|
self->nick_length = MAX_GC_NICK_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
bin_pack_u16(bp, self->nick_length); // 1
|
bin_pack_u16(bp, self->nick_length); // 1
|
||||||
bin_pack_u08(bp, (uint8_t)self->role); // 2
|
bin_pack_u08(bp, (uint8_t)self->role); // 2
|
||||||
|
@ -32,4 +32,7 @@ void gc_save_pack_group(const GC_Chat *chat, Bin_Pack *bp);
|
|||||||
non_null()
|
non_null()
|
||||||
bool gc_load_unpack_group(GC_Chat *chat, Bin_Unpack *bu);
|
bool gc_load_unpack_group(GC_Chat *chat, Bin_Unpack *bu);
|
||||||
|
|
||||||
|
Group_Privacy_State group_privacy_state_from_int(uint8_t value);
|
||||||
|
Group_Voice_State group_voice_state_from_int(uint8_t value);
|
||||||
|
|
||||||
#endif // GROUP_PACK_H
|
#endif // GROUP_PACK_H
|
||||||
|
5
external/toxcore/c-toxcore/toxcore/logger.c
vendored
5
external/toxcore/c-toxcore/toxcore/logger.c
vendored
@ -117,3 +117,8 @@ void logger_write(const Logger *log, Logger_Level level, const char *file, int l
|
|||||||
|
|
||||||
log->callback(log->context, level, file, line, func, msg, log->userdata);
|
log->callback(log->context, level, file, line, func, msg, log->userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void logger_abort(void)
|
||||||
|
{
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
5
external/toxcore/c-toxcore/toxcore/logger.h
vendored
5
external/toxcore/c-toxcore/toxcore/logger.h
vendored
@ -67,6 +67,9 @@ void logger_write(
|
|||||||
const Logger *log, Logger_Level level, const char *file, int line, const char *func,
|
const Logger *log, Logger_Level level, const char *file, int line, const char *func,
|
||||||
const char *format, ...);
|
const char *format, ...);
|
||||||
|
|
||||||
|
/* @brief Terminate the program with a signal. */
|
||||||
|
void logger_abort(void);
|
||||||
|
|
||||||
|
|
||||||
#define LOGGER_WRITE(log, level, ...) \
|
#define LOGGER_WRITE(log, level, ...) \
|
||||||
do { \
|
do { \
|
||||||
@ -85,7 +88,7 @@ void logger_write(
|
|||||||
#define LOGGER_FATAL(log, ...) \
|
#define LOGGER_FATAL(log, ...) \
|
||||||
do { \
|
do { \
|
||||||
LOGGER_ERROR(log, __VA_ARGS__); \
|
LOGGER_ERROR(log, __VA_ARGS__); \
|
||||||
abort(); \
|
logger_abort(); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define LOGGER_ASSERT(log, cond, ...) \
|
#define LOGGER_ASSERT(log, cond, ...) \
|
||||||
|
32
external/toxcore/c-toxcore/toxcore/mono_time.c
vendored
32
external/toxcore/c-toxcore/toxcore/mono_time.c
vendored
@ -32,6 +32,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "ccompat.h"
|
#include "ccompat.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
/** don't call into system billions of times for no reason */
|
/** don't call into system billions of times for no reason */
|
||||||
struct Mono_Time {
|
struct Mono_Time {
|
||||||
@ -165,7 +166,9 @@ Mono_Time *mono_time_new(const Memory *mem, mono_time_current_time_cb *current_t
|
|||||||
// Maximum reproducibility. Never return time = 0.
|
// Maximum reproducibility. Never return time = 0.
|
||||||
mono_time->base_time = 1;
|
mono_time->base_time = 1;
|
||||||
#else
|
#else
|
||||||
mono_time->base_time = (uint64_t)time(nullptr) - (current_time_monotonic(mono_time) / 1000ULL);
|
// Never return time = 0 in case time() returns 0 (e.g. on microcontrollers
|
||||||
|
// without battery-powered RTC or ones where NTP didn't initialise it yet).
|
||||||
|
mono_time->base_time = max_u64(1, (uint64_t)time(nullptr)) * 1000ULL - current_time_monotonic(mono_time);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mono_time_update(mono_time);
|
mono_time_update(mono_time);
|
||||||
@ -190,14 +193,13 @@ void mono_time_free(const Memory *mem, Mono_Time *mono_time)
|
|||||||
|
|
||||||
void mono_time_update(Mono_Time *mono_time)
|
void mono_time_update(Mono_Time *mono_time)
|
||||||
{
|
{
|
||||||
uint64_t cur_time = 0;
|
|
||||||
#ifdef OS_WIN32
|
#ifdef OS_WIN32
|
||||||
/* we actually want to update the overflow state of mono_time here */
|
/* we actually want to update the overflow state of mono_time here */
|
||||||
pthread_mutex_lock(&mono_time->last_clock_lock);
|
pthread_mutex_lock(&mono_time->last_clock_lock);
|
||||||
mono_time->last_clock_update = true;
|
mono_time->last_clock_update = true;
|
||||||
#endif
|
#endif
|
||||||
cur_time = mono_time->current_time_callback(mono_time->user_data) / 1000ULL;
|
const uint64_t cur_time =
|
||||||
cur_time += mono_time->base_time;
|
mono_time->base_time + mono_time->current_time_callback(mono_time->user_data);
|
||||||
#ifdef OS_WIN32
|
#ifdef OS_WIN32
|
||||||
pthread_mutex_unlock(&mono_time->last_clock_lock);
|
pthread_mutex_unlock(&mono_time->last_clock_lock);
|
||||||
#endif
|
#endif
|
||||||
@ -211,21 +213,22 @@ void mono_time_update(Mono_Time *mono_time)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t mono_time_get(const Mono_Time *mono_time)
|
uint64_t mono_time_get_ms(const Mono_Time *mono_time)
|
||||||
{
|
{
|
||||||
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
#if !defined(ESP_PLATFORM) && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||||
// Fuzzing is only single thread for now, no locking needed */
|
// Fuzzing is only single thread for now, no locking needed */
|
||||||
return mono_time->cur_time;
|
|
||||||
#else
|
|
||||||
#ifndef ESP_PLATFORM
|
|
||||||
pthread_rwlock_rdlock(mono_time->time_update_lock);
|
pthread_rwlock_rdlock(mono_time->time_update_lock);
|
||||||
#endif
|
#endif
|
||||||
const uint64_t cur_time = mono_time->cur_time;
|
const uint64_t cur_time = mono_time->cur_time;
|
||||||
#ifndef ESP_PLATFORM
|
#if !defined(ESP_PLATFORM) && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||||
pthread_rwlock_unlock(mono_time->time_update_lock);
|
pthread_rwlock_unlock(mono_time->time_update_lock);
|
||||||
#endif
|
#endif
|
||||||
return cur_time;
|
return cur_time;
|
||||||
#endif
|
}
|
||||||
|
|
||||||
|
uint64_t mono_time_get(const Mono_Time *mono_time)
|
||||||
|
{
|
||||||
|
return mono_time_get_ms(mono_time) / 1000ULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mono_time_is_timeout(const Mono_Time *mono_time, uint64_t timestamp, uint64_t timeout)
|
bool mono_time_is_timeout(const Mono_Time *mono_time, uint64_t timestamp, uint64_t timeout)
|
||||||
@ -245,9 +248,10 @@ void mono_time_set_current_time_callback(Mono_Time *mono_time,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @brief Return current monotonic time in milliseconds (ms).
|
||||||
* Return current monotonic time in milliseconds (ms). The starting point is
|
*
|
||||||
* unspecified.
|
* The starting point is unspecified and in particular is likely not comparable
|
||||||
|
* to the return value of `mono_time_get_ms()`.
|
||||||
*/
|
*/
|
||||||
uint64_t current_time_monotonic(Mono_Time *mono_time)
|
uint64_t current_time_monotonic(Mono_Time *mono_time)
|
||||||
{
|
{
|
||||||
|
19
external/toxcore/c-toxcore/toxcore/mono_time.h
vendored
19
external/toxcore/c-toxcore/toxcore/mono_time.h
vendored
@ -61,8 +61,16 @@ void mono_time_free(const Memory *mem, Mono_Time *mono_time);
|
|||||||
non_null()
|
non_null()
|
||||||
void mono_time_update(Mono_Time *mono_time);
|
void mono_time_update(Mono_Time *mono_time);
|
||||||
|
|
||||||
/**
|
/** @brief Return current monotonic time in milliseconds (ms).
|
||||||
* Return unix time since epoch in seconds.
|
*
|
||||||
|
* The starting point is UNIX epoch as measured by `time()` in `mono_time_new()`.
|
||||||
|
*/
|
||||||
|
non_null()
|
||||||
|
uint64_t mono_time_get_ms(const Mono_Time *mono_time);
|
||||||
|
|
||||||
|
/** @brief Return a monotonically increasing time in seconds.
|
||||||
|
*
|
||||||
|
* The starting point is UNIX epoch as measured by `time()` in `mono_time_new()`.
|
||||||
*/
|
*/
|
||||||
non_null()
|
non_null()
|
||||||
uint64_t mono_time_get(const Mono_Time *mono_time);
|
uint64_t mono_time_get(const Mono_Time *mono_time);
|
||||||
@ -73,9 +81,10 @@ uint64_t mono_time_get(const Mono_Time *mono_time);
|
|||||||
non_null()
|
non_null()
|
||||||
bool mono_time_is_timeout(const Mono_Time *mono_time, uint64_t timestamp, uint64_t timeout);
|
bool mono_time_is_timeout(const Mono_Time *mono_time, uint64_t timestamp, uint64_t timeout);
|
||||||
|
|
||||||
/**
|
/** @brief Return current monotonic time in milliseconds (ms).
|
||||||
* Return current monotonic time in milliseconds (ms). The starting point is
|
*
|
||||||
* unspecified.
|
* The starting point is unspecified and in particular is likely not comparable
|
||||||
|
* to the return value of `mono_time_get_ms()`.
|
||||||
*/
|
*/
|
||||||
non_null()
|
non_null()
|
||||||
uint64_t current_time_monotonic(Mono_Time *mono_time);
|
uint64_t current_time_monotonic(Mono_Time *mono_time);
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST(MonoTime, UnixTimeIncreasesOverTime)
|
TEST(MonoTime, UnixTimeIncreasesOverTime)
|
||||||
@ -41,6 +44,24 @@ TEST(MonoTime, IsTimeout)
|
|||||||
mono_time_free(mem, mono_time);
|
mono_time_free(mem, mono_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(MonoTime, IsTimeoutReal)
|
||||||
|
{
|
||||||
|
const Memory *mem = system_memory();
|
||||||
|
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||||
|
ASSERT_NE(mono_time, nullptr);
|
||||||
|
|
||||||
|
uint64_t const start = mono_time_get(mono_time);
|
||||||
|
EXPECT_FALSE(mono_time_is_timeout(mono_time, start, 5));
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
mono_time_update(mono_time);
|
||||||
|
|
||||||
|
// should still not have timed out (5sec) after sleeping ~100ms
|
||||||
|
EXPECT_FALSE(mono_time_is_timeout(mono_time, start, 5));
|
||||||
|
|
||||||
|
mono_time_free(mem, mono_time);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(MonoTime, CustomTime)
|
TEST(MonoTime, CustomTime)
|
||||||
{
|
{
|
||||||
const Memory *mem = system_memory();
|
const Memory *mem = system_memory();
|
||||||
|
27
external/toxcore/c-toxcore/toxcore/network.c
vendored
27
external/toxcore/c-toxcore/toxcore/network.c
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2023 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -778,7 +778,7 @@ static void loglogdata(const Logger *log, const char *message, const uint8_t *bu
|
|||||||
Ip_Ntoa ip_str;
|
Ip_Ntoa ip_str;
|
||||||
const int error = net_error();
|
const int error = net_error();
|
||||||
char *strerror = net_new_strerror(error);
|
char *strerror = net_new_strerror(error);
|
||||||
LOGGER_TRACE(log, "[%02x = %-20s] %s %3u%c %s:%u (%u: %s) | %08x%08x...%02x",
|
LOGGER_TRACE(log, "[%02x = %-21s] %s %3u%c %s:%u (%u: %s) | %08x%08x...%02x",
|
||||||
buffer[0], net_packet_type_name((Net_Packet_Type)buffer[0]), message,
|
buffer[0], net_packet_type_name((Net_Packet_Type)buffer[0]), message,
|
||||||
min_u16(buflen, 999), 'E',
|
min_u16(buflen, 999), 'E',
|
||||||
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), error,
|
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), error,
|
||||||
@ -786,14 +786,14 @@ static void loglogdata(const Logger *log, const char *message, const uint8_t *bu
|
|||||||
net_kill_strerror(strerror);
|
net_kill_strerror(strerror);
|
||||||
} else if ((res > 0) && ((size_t)res <= buflen)) {
|
} else if ((res > 0) && ((size_t)res <= buflen)) {
|
||||||
Ip_Ntoa ip_str;
|
Ip_Ntoa ip_str;
|
||||||
LOGGER_TRACE(log, "[%02x = %-20s] %s %3u%c %s:%u (%u: %s) | %08x%08x...%02x",
|
LOGGER_TRACE(log, "[%02x = %-21s] %s %3u%c %s:%u (%u: %s) | %08x%08x...%02x",
|
||||||
buffer[0], net_packet_type_name((Net_Packet_Type)buffer[0]), message,
|
buffer[0], net_packet_type_name((Net_Packet_Type)buffer[0]), message,
|
||||||
min_u16(res, 999), (size_t)res < buflen ? '<' : '=',
|
min_u16(res, 999), (size_t)res < buflen ? '<' : '=',
|
||||||
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), 0, "OK",
|
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), 0, "OK",
|
||||||
data_0(buflen, buffer), data_1(buflen, buffer), buffer[buflen - 1]);
|
data_0(buflen, buffer), data_1(buflen, buffer), buffer[buflen - 1]);
|
||||||
} else { /* empty or overwrite */
|
} else { /* empty or overwrite */
|
||||||
Ip_Ntoa ip_str;
|
Ip_Ntoa ip_str;
|
||||||
LOGGER_TRACE(log, "[%02x = %-20s] %s %lu%c%u %s:%u (%u: %s) | %08x%08x...%02x",
|
LOGGER_TRACE(log, "[%02x = %-21s] %s %lu%c%u %s:%u (%u: %s) | %08x%08x...%02x",
|
||||||
buffer[0], net_packet_type_name((Net_Packet_Type)buffer[0]), message,
|
buffer[0], net_packet_type_name((Net_Packet_Type)buffer[0]), message,
|
||||||
res, res == 0 ? '!' : '>', buflen,
|
res, res == 0 ? '!' : '>', buflen,
|
||||||
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), 0, "OK",
|
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), 0, "OK",
|
||||||
@ -1184,11 +1184,11 @@ Networking_Core *new_networking_ex(
|
|||||||
int n = 1024 * 1024 * 2;
|
int n = 1024 * 1024 * 2;
|
||||||
|
|
||||||
if (net_setsockopt(ns, temp->sock, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) != 0) {
|
if (net_setsockopt(ns, temp->sock, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) != 0) {
|
||||||
LOGGER_ERROR(log, "failed to set socket option %d", SO_RCVBUF);
|
LOGGER_WARNING(log, "failed to set socket option %d", SO_RCVBUF);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_setsockopt(ns, temp->sock, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n)) != 0) {
|
if (net_setsockopt(ns, temp->sock, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n)) != 0) {
|
||||||
LOGGER_ERROR(log, "failed to set socket option %d", SO_SNDBUF);
|
LOGGER_WARNING(log, "failed to set socket option %d", SO_SNDBUF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enable broadcast on socket */
|
/* Enable broadcast on socket */
|
||||||
@ -1514,30 +1514,29 @@ void ipport_copy(IP_Port *target, const IP_Port *source)
|
|||||||
*target = *source;
|
*target = *source;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Converts IP into a string.
|
|
||||||
*
|
|
||||||
* Writes error message into the buffer on error.
|
|
||||||
*
|
|
||||||
* @param ip_str contains a buffer of the required size.
|
|
||||||
*
|
|
||||||
* @return Pointer to the buffer inside `ip_str` containing the IP string.
|
|
||||||
*/
|
|
||||||
const char *net_ip_ntoa(const IP *ip, Ip_Ntoa *ip_str)
|
const char *net_ip_ntoa(const IP *ip, Ip_Ntoa *ip_str)
|
||||||
{
|
{
|
||||||
assert(ip_str != nullptr);
|
assert(ip_str != nullptr);
|
||||||
|
|
||||||
|
ip_str->ip_is_valid = false;
|
||||||
|
|
||||||
if (ip == nullptr) {
|
if (ip == nullptr) {
|
||||||
snprintf(ip_str->buf, sizeof(ip_str->buf), "(IP invalid: NULL)");
|
snprintf(ip_str->buf, sizeof(ip_str->buf), "(IP invalid: NULL)");
|
||||||
|
ip_str->length = (uint16_t)strlen(ip_str->buf);
|
||||||
return ip_str->buf;
|
return ip_str->buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ip_parse_addr(ip, ip_str->buf, sizeof(ip_str->buf))) {
|
if (!ip_parse_addr(ip, ip_str->buf, sizeof(ip_str->buf))) {
|
||||||
snprintf(ip_str->buf, sizeof(ip_str->buf), "(IP invalid, family %u)", ip->family.value);
|
snprintf(ip_str->buf, sizeof(ip_str->buf), "(IP invalid, family %u)", ip->family.value);
|
||||||
|
ip_str->length = (uint16_t)strlen(ip_str->buf);
|
||||||
return ip_str->buf;
|
return ip_str->buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* brute force protection against lacking termination */
|
/* brute force protection against lacking termination */
|
||||||
ip_str->buf[sizeof(ip_str->buf) - 1] = '\0';
|
ip_str->buf[sizeof(ip_str->buf) - 1] = '\0';
|
||||||
|
ip_str->length = (uint16_t)strlen(ip_str->buf);
|
||||||
|
ip_str->ip_is_valid = true;
|
||||||
|
|
||||||
return ip_str->buf;
|
return ip_str->buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
external/toxcore/c-toxcore/toxcore/network.h
vendored
7
external/toxcore/c-toxcore/toxcore/network.h
vendored
@ -343,11 +343,14 @@ bool ipv6_ipv4_in_v6(const IP6 *a);
|
|||||||
/** this would be TOX_INET6_ADDRSTRLEN, but it might be too short for the error message */
|
/** this would be TOX_INET6_ADDRSTRLEN, but it might be too short for the error message */
|
||||||
#define IP_NTOA_LEN 96 // TODO(irungentoo): magic number. Why not INET6_ADDRSTRLEN ?
|
#define IP_NTOA_LEN 96 // TODO(irungentoo): magic number. Why not INET6_ADDRSTRLEN ?
|
||||||
|
|
||||||
|
/** Contains a null terminated string of an IP address. */
|
||||||
typedef struct Ip_Ntoa {
|
typedef struct Ip_Ntoa {
|
||||||
char buf[IP_NTOA_LEN];
|
char buf[IP_NTOA_LEN]; // a string formatted IP address or an error message.
|
||||||
|
uint16_t length; // the length of the string (not including the null byte).
|
||||||
|
bool ip_is_valid; // if this is false `buf` will contain an error message.
|
||||||
} Ip_Ntoa;
|
} Ip_Ntoa;
|
||||||
|
|
||||||
/** @brief Converts IP into a string.
|
/** @brief Converts IP into a null terminated string.
|
||||||
*
|
*
|
||||||
* Writes error message into the buffer on error.
|
* Writes error message into the buffer on error.
|
||||||
*
|
*
|
||||||
|
60
external/toxcore/c-toxcore/toxcore/onion.c
vendored
60
external/toxcore/c-toxcore/toxcore/onion.c
vendored
@ -283,22 +283,27 @@ int create_onion_packet_tcp(const Random *rng, uint8_t *packet, uint16_t max_pac
|
|||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
* return 0 on success.
|
* return 0 on success.
|
||||||
*/
|
*/
|
||||||
int send_onion_response(const Networking_Core *net, const IP_Port *dest, const uint8_t *data, uint16_t length,
|
int send_onion_response(const Logger *log, const Networking_Core *net,
|
||||||
|
const IP_Port *dest, const uint8_t *data, uint16_t length,
|
||||||
const uint8_t *ret)
|
const uint8_t *ret)
|
||||||
{
|
{
|
||||||
if (length > ONION_RESPONSE_MAX_DATA_SIZE || length == 0) {
|
if (length > ONION_RESPONSE_MAX_DATA_SIZE || length == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VLA(uint8_t, packet, 1 + RETURN_3 + length);
|
const uint16_t packet_size = 1 + RETURN_3 + length;
|
||||||
|
VLA(uint8_t, packet, packet_size);
|
||||||
packet[0] = NET_PACKET_ONION_RECV_3;
|
packet[0] = NET_PACKET_ONION_RECV_3;
|
||||||
memcpy(packet + 1, ret, RETURN_3);
|
memcpy(packet + 1, ret, RETURN_3);
|
||||||
memcpy(packet + 1 + RETURN_3, data, length);
|
memcpy(packet + 1 + RETURN_3, data, length);
|
||||||
|
|
||||||
if ((uint32_t)sendpacket(net, dest, packet, SIZEOF_VLA(packet)) != SIZEOF_VLA(packet)) {
|
if ((uint16_t)sendpacket(net, dest, packet, packet_size) != packet_size) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ip_Ntoa ip_str;
|
||||||
|
LOGGER_TRACE(log, "forwarded onion RECV_3 to %s:%d (%02x in %02x, %d bytes)",
|
||||||
|
net_ip_ntoa(&dest->ip, &ip_str), net_ntohs(dest->port), data[0], packet[0], packet_size);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,28 +314,42 @@ static int handle_send_initial(void *object, const IP_Port *source, const uint8_
|
|||||||
Onion *onion = (Onion *)object;
|
Onion *onion = (Onion *)object;
|
||||||
|
|
||||||
if (length > ONION_MAX_PACKET_SIZE) {
|
if (length > ONION_MAX_PACKET_SIZE) {
|
||||||
|
LOGGER_TRACE(onion->log, "invalid initial onion packet length: %u (max: %u)",
|
||||||
|
length, ONION_MAX_PACKET_SIZE);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length <= 1 + SEND_1) {
|
if (length <= 1 + SEND_1) {
|
||||||
|
LOGGER_TRACE(onion->log, "initial onion packet cannot contain SEND_1 packet: %u <= %u",
|
||||||
|
length, 1 + SEND_1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
change_symmetric_key(onion);
|
change_symmetric_key(onion);
|
||||||
|
|
||||||
|
const int nonce_start = 1;
|
||||||
|
const int public_key_start = nonce_start + CRYPTO_NONCE_SIZE;
|
||||||
|
const int ciphertext_start = public_key_start + CRYPTO_PUBLIC_KEY_SIZE;
|
||||||
|
|
||||||
|
const int ciphertext_length = length - ciphertext_start;
|
||||||
|
const int plaintext_length = ciphertext_length - CRYPTO_MAC_SIZE;
|
||||||
|
|
||||||
uint8_t plain[ONION_MAX_PACKET_SIZE];
|
uint8_t plain[ONION_MAX_PACKET_SIZE];
|
||||||
const uint8_t *public_key = packet + 1 + CRYPTO_NONCE_SIZE;
|
const uint8_t *public_key = &packet[public_key_start];
|
||||||
const uint8_t *shared_key = shared_key_cache_lookup(onion->shared_keys_1, public_key);
|
const uint8_t *shared_key = shared_key_cache_lookup(onion->shared_keys_1, public_key);
|
||||||
|
|
||||||
if (shared_key == nullptr) {
|
if (shared_key == nullptr) {
|
||||||
/* Error looking up/deriving the shared key */
|
/* Error looking up/deriving the shared key */
|
||||||
|
LOGGER_TRACE(onion->log, "shared onion key lookup failed for pk %02x%02x...",
|
||||||
|
public_key[0], public_key[1]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE,
|
const int len = decrypt_data_symmetric(
|
||||||
length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE), plain);
|
shared_key, &packet[nonce_start], &packet[ciphertext_start], ciphertext_length, plain);
|
||||||
|
|
||||||
if (len != length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE)) {
|
if (len != plaintext_length) {
|
||||||
|
LOGGER_TRACE(onion->log, "decrypt failed: %d != %d", len, plaintext_length);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,7 +358,9 @@ static int handle_send_initial(void *object, const IP_Port *source, const uint8_
|
|||||||
|
|
||||||
int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, const IP_Port *source, const uint8_t *nonce)
|
int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, const IP_Port *source, const uint8_t *nonce)
|
||||||
{
|
{
|
||||||
if (len > ONION_MAX_PACKET_SIZE + SIZE_IPPORT - (1 + CRYPTO_NONCE_SIZE + ONION_RETURN_1)) {
|
const uint16_t max_len = ONION_MAX_PACKET_SIZE + SIZE_IPPORT - (1 + CRYPTO_NONCE_SIZE + ONION_RETURN_1);
|
||||||
|
if (len > max_len) {
|
||||||
|
LOGGER_TRACE(onion->log, "invalid SEND_1 length: %d > %d", len, max_len);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,6 +397,9 @@ int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, const I
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ip_Ntoa ip_str;
|
||||||
|
LOGGER_TRACE(onion->log, "forwarded onion packet to %s:%d, level 1 (%02x in %02x, %d bytes)",
|
||||||
|
net_ip_ntoa(&send_to.ip, &ip_str), net_ntohs(send_to.port), plain[0], data[0], data_len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,6 +463,9 @@ static int handle_send_1(void *object, const IP_Port *source, const uint8_t *pac
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ip_Ntoa ip_str;
|
||||||
|
LOGGER_TRACE(onion->log, "forwarded onion packet to %s:%d, level 2 (%02x in %02x, %d bytes)",
|
||||||
|
net_ip_ntoa(&send_to.ip, &ip_str), net_ntohs(send_to.port), packet[0], data[0], data_len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -509,6 +536,9 @@ static int handle_send_2(void *object, const IP_Port *source, const uint8_t *pac
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ip_Ntoa ip_str;
|
||||||
|
LOGGER_TRACE(onion->log, "forwarded onion packet to %s:%d, level 3 (%02x in %02x, %d bytes)",
|
||||||
|
net_ip_ntoa(&send_to.ip, &ip_str), net_ntohs(send_to.port), packet[0], data[0], data_len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,6 +576,7 @@ static int handle_recv_3(void *object, const IP_Port *source, const uint8_t *pac
|
|||||||
IP_Port send_to;
|
IP_Port send_to;
|
||||||
|
|
||||||
if (ipport_unpack(&send_to, plain, len, false) == -1) {
|
if (ipport_unpack(&send_to, plain, len, false) == -1) {
|
||||||
|
LOGGER_DEBUG(onion->log, "failed to unpack IP/Port");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -559,6 +590,9 @@ static int handle_recv_3(void *object, const IP_Port *source, const uint8_t *pac
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ip_Ntoa ip_str;
|
||||||
|
LOGGER_TRACE(onion->log, "forwarded onion RECV_2 to %s:%d (%02x in %02x, %d bytes)",
|
||||||
|
net_ip_ntoa(&send_to.ip, &ip_str), net_ntohs(send_to.port), packet[0], data[0], data_len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -608,6 +642,9 @@ static int handle_recv_2(void *object, const IP_Port *source, const uint8_t *pac
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ip_Ntoa ip_str;
|
||||||
|
LOGGER_TRACE(onion->log, "forwarded onion RECV_1 to %s:%d (%02x in %02x, %d bytes)",
|
||||||
|
net_ip_ntoa(&send_to.ip, &ip_str), net_ntohs(send_to.port), packet[0], data[0], data_len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -644,6 +681,7 @@ static int handle_recv_1(void *object, const IP_Port *source, const uint8_t *pac
|
|||||||
IP_Port send_to;
|
IP_Port send_to;
|
||||||
|
|
||||||
if (ipport_unpack(&send_to, plain, len, true) == -1) {
|
if (ipport_unpack(&send_to, plain, len, true) == -1) {
|
||||||
|
LOGGER_DEBUG(onion->log, "failed to unpack IP/Port");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -690,9 +728,9 @@ Onion *new_onion(const Logger *log, const Memory *mem, const Mono_Time *mono_tim
|
|||||||
onion->timestamp = mono_time_get(onion->mono_time);
|
onion->timestamp = mono_time_get(onion->mono_time);
|
||||||
|
|
||||||
const uint8_t *secret_key = dht_get_self_secret_key(dht);
|
const uint8_t *secret_key = dht_get_self_secret_key(dht);
|
||||||
onion->shared_keys_1 = shared_key_cache_new(mono_time, mem, secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
onion->shared_keys_1 = shared_key_cache_new(log, mono_time, mem, secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
||||||
onion->shared_keys_2 = shared_key_cache_new(mono_time, mem, secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
onion->shared_keys_2 = shared_key_cache_new(log, mono_time, mem, secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
||||||
onion->shared_keys_3 = shared_key_cache_new(mono_time, mem, secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
onion->shared_keys_3 = shared_key_cache_new(log, mono_time, mem, secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
||||||
|
|
||||||
if (onion->shared_keys_1 == nullptr ||
|
if (onion->shared_keys_1 == nullptr ||
|
||||||
onion->shared_keys_2 == nullptr ||
|
onion->shared_keys_2 == nullptr ||
|
||||||
|
3
external/toxcore/c-toxcore/toxcore/onion.h
vendored
3
external/toxcore/c-toxcore/toxcore/onion.h
vendored
@ -127,7 +127,8 @@ int create_onion_packet_tcp(const Random *rng, uint8_t *packet, uint16_t max_pac
|
|||||||
* return 0 on success.
|
* return 0 on success.
|
||||||
*/
|
*/
|
||||||
non_null()
|
non_null()
|
||||||
int send_onion_response(const Networking_Core *net, const IP_Port *dest, const uint8_t *data, uint16_t length,
|
int send_onion_response(const Logger *log, const Networking_Core *net,
|
||||||
|
const IP_Port *dest, const uint8_t *data, uint16_t length,
|
||||||
const uint8_t *ret);
|
const uint8_t *ret);
|
||||||
|
|
||||||
/** @brief Function to handle/send received decrypted versions of the packet created by create_onion_packet.
|
/** @brief Function to handle/send received decrypted versions of the packet created by create_onion_packet.
|
||||||
|
@ -186,7 +186,8 @@ int create_data_request(const Random *rng, uint8_t *packet, uint16_t max_packet_
|
|||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
* return 0 on success.
|
* return 0 on success.
|
||||||
*/
|
*/
|
||||||
int send_announce_request(const Networking_Core *net, const Random *rng,
|
int send_announce_request(
|
||||||
|
const Logger *log, const Networking_Core *net, const Random *rng,
|
||||||
const Onion_Path *path, const Node_format *dest,
|
const Onion_Path *path, const Node_format *dest,
|
||||||
const uint8_t *public_key, const uint8_t *secret_key,
|
const uint8_t *public_key, const uint8_t *secret_key,
|
||||||
const uint8_t *ping_id, const uint8_t *client_id,
|
const uint8_t *ping_id, const uint8_t *client_id,
|
||||||
@ -230,7 +231,8 @@ int send_announce_request(const Networking_Core *net, const Random *rng,
|
|||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
* return 0 on success.
|
* return 0 on success.
|
||||||
*/
|
*/
|
||||||
int send_data_request(const Networking_Core *net, const Random *rng, const Onion_Path *path, const IP_Port *dest,
|
int send_data_request(
|
||||||
|
const Logger *log, const Networking_Core *net, const Random *rng, const Onion_Path *path, const IP_Port *dest,
|
||||||
const uint8_t *public_key, const uint8_t *encrypt_public_key, const uint8_t *nonce,
|
const uint8_t *public_key, const uint8_t *encrypt_public_key, const uint8_t *nonce,
|
||||||
const uint8_t *data, uint16_t length)
|
const uint8_t *data, uint16_t length)
|
||||||
{
|
{
|
||||||
@ -549,7 +551,7 @@ static int handle_announce_request_common(
|
|||||||
ONION_ANNOUNCE_SENDBACK_DATA_LENGTH);
|
ONION_ANNOUNCE_SENDBACK_DATA_LENGTH);
|
||||||
memcpy(data + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, nonce, CRYPTO_NONCE_SIZE);
|
memcpy(data + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, nonce, CRYPTO_NONCE_SIZE);
|
||||||
|
|
||||||
if (send_onion_response(onion_a->net, source, data,
|
if (send_onion_response(onion_a->log, onion_a->net, source, data,
|
||||||
1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE + len,
|
1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE + len,
|
||||||
packet + (length - ONION_RETURN_3)) == -1) {
|
packet + (length - ONION_RETURN_3)) == -1) {
|
||||||
mem_delete(onion_a->mem, response);
|
mem_delete(onion_a->mem, response);
|
||||||
@ -634,7 +636,7 @@ static int handle_data_request(void *object, const IP_Port *source, const uint8_
|
|||||||
data[0] = NET_PACKET_ONION_DATA_RESPONSE;
|
data[0] = NET_PACKET_ONION_DATA_RESPONSE;
|
||||||
memcpy(data + 1, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, length - (1 + CRYPTO_PUBLIC_KEY_SIZE + ONION_RETURN_3));
|
memcpy(data + 1, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, length - (1 + CRYPTO_PUBLIC_KEY_SIZE + ONION_RETURN_3));
|
||||||
|
|
||||||
if (send_onion_response(onion_a->net, &onion_a->entries[index].ret_ip_port, data, SIZEOF_VLA(data),
|
if (send_onion_response(onion_a->log, onion_a->net, &onion_a->entries[index].ret_ip_port, data, SIZEOF_VLA(data),
|
||||||
onion_a->entries[index].ret) == -1) {
|
onion_a->entries[index].ret) == -1) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -665,7 +667,7 @@ Onion_Announce *new_onion_announce(const Logger *log, const Memory *mem, const R
|
|||||||
onion_a->extra_data_object = nullptr;
|
onion_a->extra_data_object = nullptr;
|
||||||
new_hmac_key(rng, onion_a->hmac_key);
|
new_hmac_key(rng, onion_a->hmac_key);
|
||||||
|
|
||||||
onion_a->shared_keys_recv = shared_key_cache_new(mono_time, mem, dht_get_self_secret_key(dht), KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
onion_a->shared_keys_recv = shared_key_cache_new(log, mono_time, mem, dht_get_self_secret_key(dht), KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
||||||
if (onion_a->shared_keys_recv == nullptr) {
|
if (onion_a->shared_keys_recv == nullptr) {
|
||||||
kill_onion_announce(onion_a);
|
kill_onion_announce(onion_a);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -94,7 +94,8 @@ int create_data_request(const Random *rng, uint8_t *packet, uint16_t max_packet_
|
|||||||
* return 0 on success.
|
* return 0 on success.
|
||||||
*/
|
*/
|
||||||
non_null()
|
non_null()
|
||||||
int send_announce_request(const Networking_Core *net, const Random *rng,
|
int send_announce_request(
|
||||||
|
const Logger *log, const Networking_Core *net, const Random *rng,
|
||||||
const Onion_Path *path, const Node_format *dest,
|
const Onion_Path *path, const Node_format *dest,
|
||||||
const uint8_t *public_key, const uint8_t *secret_key,
|
const uint8_t *public_key, const uint8_t *secret_key,
|
||||||
const uint8_t *ping_id, const uint8_t *client_id,
|
const uint8_t *ping_id, const uint8_t *client_id,
|
||||||
@ -117,7 +118,8 @@ int send_announce_request(const Networking_Core *net, const Random *rng,
|
|||||||
* return 0 on success.
|
* return 0 on success.
|
||||||
*/
|
*/
|
||||||
non_null()
|
non_null()
|
||||||
int send_data_request(const Networking_Core *net, const Random *rng, const Onion_Path *path, const IP_Port *dest,
|
int send_data_request(
|
||||||
|
const Logger *log, const Networking_Core *net, const Random *rng, const Onion_Path *path, const IP_Port *dest,
|
||||||
const uint8_t *public_key, const uint8_t *encrypt_public_key, const uint8_t *nonce,
|
const uint8_t *public_key, const uint8_t *encrypt_public_key, const uint8_t *nonce,
|
||||||
const uint8_t *data, uint16_t length);
|
const uint8_t *data, uint16_t length);
|
||||||
|
|
||||||
|
109
external/toxcore/c-toxcore/toxcore/onion_client.c
vendored
109
external/toxcore/c-toxcore/toxcore/onion_client.c
vendored
@ -582,6 +582,7 @@ static int new_sendback(Onion_Client *onion_c, uint32_t num, const uint8_t *publ
|
|||||||
*sendback = ping_array_add(onion_c->announce_ping_array, onion_c->mono_time, onion_c->rng, data, sizeof(data));
|
*sendback = ping_array_add(onion_c->announce_ping_array, onion_c->mono_time, onion_c->rng, data, sizeof(data));
|
||||||
|
|
||||||
if (*sendback == 0) {
|
if (*sendback == 0) {
|
||||||
|
LOGGER_TRACE(onion_c->logger, "generating sendback in announce ping array failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -624,6 +625,7 @@ static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, con
|
|||||||
const uint8_t *dest_pubkey, const uint8_t *ping_id, uint32_t pathnum)
|
const uint8_t *dest_pubkey, const uint8_t *ping_id, uint32_t pathnum)
|
||||||
{
|
{
|
||||||
if (num > onion_c->num_friends) {
|
if (num > onion_c->num_friends) {
|
||||||
|
LOGGER_TRACE(onion_c->logger, "not sending announce to out of bounds friend %u (num friends: %u)", num, onion_c->num_friends);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -632,10 +634,12 @@ static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, con
|
|||||||
|
|
||||||
if (num == 0) {
|
if (num == 0) {
|
||||||
if (random_path(onion_c, &onion_c->onion_paths_self, pathnum, &path) == -1) {
|
if (random_path(onion_c, &onion_c->onion_paths_self, pathnum, &path) == -1) {
|
||||||
|
LOGGER_TRACE(onion_c->logger, "cannot find path to self");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (random_path(onion_c, &onion_c->onion_paths_friends, pathnum, &path) == -1) {
|
if (random_path(onion_c, &onion_c->onion_paths_friends, pathnum, &path) == -1) {
|
||||||
|
LOGGER_TRACE(onion_c->logger, "cannot find path to friend");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -682,9 +686,13 @@ static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, con
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (len == -1) {
|
if (len == -1) {
|
||||||
|
LOGGER_TRACE(onion_c->logger, "failed to create announce request");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ip_Ntoa ip_str;
|
||||||
|
LOGGER_TRACE(onion_c->logger, "sending onion packet to %s:%d (%02x, %d bytes)",
|
||||||
|
net_ip_ntoa(&dest->ip, &ip_str), net_ntohs(dest->port), request[0], len);
|
||||||
return send_onion_packet_tcp_udp(onion_c, &path, dest, request, len);
|
return send_onion_packet_tcp_udp(onion_c, &path, dest, request, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -934,6 +942,8 @@ static int handle_announce_response(void *object, const IP_Port *source, const u
|
|||||||
Onion_Client *onion_c = (Onion_Client *)object;
|
Onion_Client *onion_c = (Onion_Client *)object;
|
||||||
|
|
||||||
if (length < ONION_ANNOUNCE_RESPONSE_MIN_SIZE || length > ONION_ANNOUNCE_RESPONSE_MAX_SIZE) {
|
if (length < ONION_ANNOUNCE_RESPONSE_MIN_SIZE || length > ONION_ANNOUNCE_RESPONSE_MAX_SIZE) {
|
||||||
|
LOGGER_TRACE(onion_c->logger, "invalid announce response length: %u (min: %u, max: %u)",
|
||||||
|
length, (unsigned int)ONION_ANNOUNCE_RESPONSE_MIN_SIZE, (unsigned int)ONION_ANNOUNCE_RESPONSE_MAX_SIZE);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -949,30 +959,37 @@ static int handle_announce_response(void *object, const IP_Port *source, const u
|
|||||||
uint8_t plain[1 + ONION_PING_ID_SIZE + ONION_ANNOUNCE_RESPONSE_MAX_SIZE - ONION_ANNOUNCE_RESPONSE_MIN_SIZE];
|
uint8_t plain[1 + ONION_PING_ID_SIZE + ONION_ANNOUNCE_RESPONSE_MAX_SIZE - ONION_ANNOUNCE_RESPONSE_MIN_SIZE];
|
||||||
const int plain_size = 1 + ONION_PING_ID_SIZE + length - ONION_ANNOUNCE_RESPONSE_MIN_SIZE;
|
const int plain_size = 1 + ONION_PING_ID_SIZE + length - ONION_ANNOUNCE_RESPONSE_MIN_SIZE;
|
||||||
int len;
|
int len;
|
||||||
|
const uint16_t nonce_start = 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH;
|
||||||
|
const uint16_t ciphertext_start = nonce_start + CRYPTO_NONCE_SIZE;
|
||||||
|
const uint16_t ciphertext_size = length - ciphertext_start;
|
||||||
|
|
||||||
if (num == 0) {
|
if (num == 0) {
|
||||||
len = decrypt_data(public_key, nc_get_self_secret_key(onion_c->c),
|
len = decrypt_data(public_key, nc_get_self_secret_key(onion_c->c),
|
||||||
packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH,
|
&packet[nonce_start], &packet[ciphertext_start], ciphertext_size, plain);
|
||||||
packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE,
|
|
||||||
length - (1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE), plain);
|
|
||||||
} else {
|
} else {
|
||||||
if (!onion_c->friends_list[num - 1].is_valid) {
|
if (!onion_c->friends_list[num - 1].is_valid) {
|
||||||
|
LOGGER_TRACE(onion_c->logger, "friend number %lu is invalid", (unsigned long)(num - 1));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = decrypt_data(public_key, onion_c->friends_list[num - 1].temp_secret_key,
|
len = decrypt_data(public_key, onion_c->friends_list[num - 1].temp_secret_key,
|
||||||
packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH,
|
&packet[nonce_start], &packet[ciphertext_start], ciphertext_size, plain);
|
||||||
packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE,
|
}
|
||||||
length - (1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE), plain);
|
|
||||||
|
if (len < 0) {
|
||||||
|
// This happens a lot, so don't log it.
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((uint32_t)len != plain_size) {
|
if ((uint32_t)len != plain_size) {
|
||||||
|
LOGGER_WARNING(onion_c->logger, "decrypted size (%lu) is not the expected plain text size (%lu)", (unsigned long)len, (unsigned long)plain_size);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t path_used = set_path_timeouts(onion_c, num, path_num);
|
const uint32_t path_used = set_path_timeouts(onion_c, num, path_num);
|
||||||
|
|
||||||
if (client_add_to_list(onion_c, num, public_key, &ip_port, plain[0], plain + 1, path_used) == -1) {
|
if (client_add_to_list(onion_c, num, public_key, &ip_port, plain[0], plain + 1, path_used) == -1) {
|
||||||
|
LOGGER_WARNING(onion_c->logger, "failed to add client to list");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -989,10 +1006,12 @@ static int handle_announce_response(void *object, const IP_Port *source, const u
|
|||||||
plain_size - 2 - ONION_PING_ID_SIZE, false);
|
plain_size - 2 - ONION_PING_ID_SIZE, false);
|
||||||
|
|
||||||
if (num_nodes < 0) {
|
if (num_nodes < 0) {
|
||||||
|
LOGGER_WARNING(onion_c->logger, "no nodes to unpack in onion response");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client_ping_nodes(onion_c, num, nodes, num_nodes, source) == -1) {
|
if (client_ping_nodes(onion_c, num, nodes, num_nodes, source) == -1) {
|
||||||
|
LOGGER_WARNING(onion_c->logger, "pinging %d nodes failed", num_nodes);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1011,6 +1030,8 @@ static int handle_announce_response(void *object, const IP_Port *source, const u
|
|||||||
|
|
||||||
// TODO(irungentoo): LAN vs non LAN ips?, if we are connected only to LAN, are we offline?
|
// TODO(irungentoo): LAN vs non LAN ips?, if we are connected only to LAN, are we offline?
|
||||||
onion_c->last_packet_recv = mono_time_get(onion_c->mono_time);
|
onion_c->last_packet_recv = mono_time_get(onion_c->mono_time);
|
||||||
|
LOGGER_TRACE(onion_c->logger, "onion has received a packet at %llu",
|
||||||
|
(unsigned long long)onion_c->last_packet_recv);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1023,6 +1044,8 @@ static int handle_announce_response_old(void *object, const IP_Port *source, con
|
|||||||
Onion_Client *onion_c = (Onion_Client *)object;
|
Onion_Client *onion_c = (Onion_Client *)object;
|
||||||
|
|
||||||
if (length < ONION_ANNOUNCE_RESPONSE_MIN_SIZE || length > ONION_ANNOUNCE_RESPONSE_MAX_SIZE) {
|
if (length < ONION_ANNOUNCE_RESPONSE_MIN_SIZE || length > ONION_ANNOUNCE_RESPONSE_MAX_SIZE) {
|
||||||
|
LOGGER_TRACE(onion_c->logger, "invalid announce response length: %u (min: %u, max: %u)",
|
||||||
|
length, (unsigned int)ONION_ANNOUNCE_RESPONSE_MIN_SIZE, (unsigned int)ONION_ANNOUNCE_RESPONSE_MAX_SIZE);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1039,30 +1062,37 @@ static int handle_announce_response_old(void *object, const IP_Port *source, con
|
|||||||
|
|
||||||
VLA(uint8_t, plain, 1 + ONION_PING_ID_SIZE + len_nodes);
|
VLA(uint8_t, plain, 1 + ONION_PING_ID_SIZE + len_nodes);
|
||||||
int len;
|
int len;
|
||||||
|
const uint16_t nonce_start = 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH;
|
||||||
|
const uint16_t ciphertext_start = nonce_start + CRYPTO_NONCE_SIZE;
|
||||||
|
const uint16_t ciphertext_size = length - ciphertext_start;
|
||||||
|
|
||||||
if (num == 0) {
|
if (num == 0) {
|
||||||
len = decrypt_data(public_key, nc_get_self_secret_key(onion_c->c),
|
len = decrypt_data(public_key, nc_get_self_secret_key(onion_c->c),
|
||||||
packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH,
|
&packet[nonce_start], &packet[ciphertext_start], ciphertext_size, plain);
|
||||||
packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE,
|
|
||||||
length - (1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE), plain);
|
|
||||||
} else {
|
} else {
|
||||||
if (!onion_c->friends_list[num - 1].is_valid) {
|
if (!onion_c->friends_list[num - 1].is_valid) {
|
||||||
|
LOGGER_TRACE(onion_c->logger, "friend number %lu is invalid", (unsigned long)(num - 1));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = decrypt_data(public_key, onion_c->friends_list[num - 1].temp_secret_key,
|
len = decrypt_data(public_key, onion_c->friends_list[num - 1].temp_secret_key,
|
||||||
packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH,
|
&packet[nonce_start], &packet[ciphertext_start], ciphertext_size, plain);
|
||||||
packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE,
|
}
|
||||||
length - (1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE), plain);
|
|
||||||
|
if (len < 0) {
|
||||||
|
// This happens a lot, so don't log it.
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((uint32_t)len != SIZEOF_VLA(plain)) {
|
if ((uint32_t)len != SIZEOF_VLA(plain)) {
|
||||||
|
LOGGER_WARNING(onion_c->logger, "decrypted size (%lu) is not the expected plain text size (%lu)", (unsigned long)len, (unsigned long)SIZEOF_VLA(plain));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t path_used = set_path_timeouts(onion_c, num, path_num);
|
const uint32_t path_used = set_path_timeouts(onion_c, num, path_num);
|
||||||
|
|
||||||
if (client_add_to_list(onion_c, num, public_key, &ip_port, plain[0], plain + 1, path_used) == -1) {
|
if (client_add_to_list(onion_c, num, public_key, &ip_port, plain[0], plain + 1, path_used) == -1) {
|
||||||
|
LOGGER_WARNING(onion_c->logger, "failed to add client to list");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1071,16 +1101,21 @@ static int handle_announce_response_old(void *object, const IP_Port *source, con
|
|||||||
const int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, nullptr, plain + 1 + ONION_PING_ID_SIZE, len_nodes, false);
|
const int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, nullptr, plain + 1 + ONION_PING_ID_SIZE, len_nodes, false);
|
||||||
|
|
||||||
if (num_nodes <= 0) {
|
if (num_nodes <= 0) {
|
||||||
|
LOGGER_WARNING(onion_c->logger, "no nodes to unpack in onion response");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client_ping_nodes(onion_c, num, nodes, num_nodes, source) == -1) {
|
if (client_ping_nodes(onion_c, num, nodes, num_nodes, source) == -1) {
|
||||||
|
LOGGER_WARNING(onion_c->logger, "pinging %d nodes failed", num_nodes);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(irungentoo): LAN vs non LAN ips?, if we are connected only to LAN, are we offline?
|
// TODO(irungentoo): LAN vs non LAN ips?, if we are connected only to LAN, are we offline?
|
||||||
onion_c->last_packet_recv = mono_time_get(onion_c->mono_time);
|
onion_c->last_packet_recv = mono_time_get(onion_c->mono_time);
|
||||||
|
LOGGER_TRACE(onion_c->logger, "onion has received a packet at %llu",
|
||||||
|
(unsigned long long)onion_c->last_packet_recv);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1378,6 +1413,7 @@ static int handle_dht_dhtpk(void *object, const IP_Port *source, const uint8_t *
|
|||||||
|
|
||||||
return handle_dhtpk_announce(onion_c, packet, plain, len, userdata);
|
return handle_dhtpk_announce(onion_c, packet, plain, len, userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Send the packets to tell our friends what our DHT public key is.
|
/** @brief Send the packets to tell our friends what our DHT public key is.
|
||||||
*
|
*
|
||||||
* if onion_dht_both is 0, use only the onion to send the packet.
|
* if onion_dht_both is 0, use only the onion to send the packet.
|
||||||
@ -1857,6 +1893,18 @@ void onion_group_announce_register(Onion_Client *onion_c, onion_group_announce_c
|
|||||||
#define TIME_TO_STABLE (ONION_NODE_PING_INTERVAL * 6)
|
#define TIME_TO_STABLE (ONION_NODE_PING_INTERVAL * 6)
|
||||||
#define ANNOUNCE_INTERVAL_STABLE (ONION_NODE_PING_INTERVAL * 8)
|
#define ANNOUNCE_INTERVAL_STABLE (ONION_NODE_PING_INTERVAL * 8)
|
||||||
|
|
||||||
|
non_null()
|
||||||
|
static bool key_list_contains(const uint8_t *const *keys, uint16_t keys_size, const uint8_t *public_key)
|
||||||
|
{
|
||||||
|
for (uint16_t i = 0; i < keys_size; ++i) {
|
||||||
|
if (memeq(keys[i], CRYPTO_PUBLIC_KEY_SIZE, public_key, CRYPTO_PUBLIC_KEY_SIZE)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
non_null()
|
non_null()
|
||||||
static void do_announce(Onion_Client *onion_c)
|
static void do_announce(Onion_Client *onion_c)
|
||||||
{
|
{
|
||||||
@ -1945,9 +1993,27 @@ static void do_announce(Onion_Client *onion_c)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < (MAX_ONION_CLIENTS_ANNOUNCE / 2); ++i) {
|
// Don't send announces to the same node twice. If we don't have many nodes,
|
||||||
|
// the random selection below may have overlaps. This ensures that we deduplicate
|
||||||
|
// nodes before sending packets to save some bandwidth.
|
||||||
|
const uint8_t *targets[MAX_ONION_CLIENTS_ANNOUNCE / 2];
|
||||||
|
unsigned int targets_count = 0;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < MAX_ONION_CLIENTS_ANNOUNCE / 2; ++i) {
|
||||||
const uint32_t num = random_range_u32(onion_c->rng, num_nodes);
|
const uint32_t num = random_range_u32(onion_c->rng, num_nodes);
|
||||||
client_send_announce_request(onion_c, 0, &path_nodes[num].ip_port, path_nodes[num].public_key, nullptr, -1);
|
const Node_format *target = &path_nodes[num];
|
||||||
|
|
||||||
|
if (!key_list_contains(targets, targets_count, target->public_key)) {
|
||||||
|
client_send_announce_request(onion_c, 0, &target->ip_port, target->public_key, nullptr, -1);
|
||||||
|
|
||||||
|
targets[targets_count] = target->public_key;
|
||||||
|
++targets_count;
|
||||||
|
assert(targets_count <= MAX_ONION_CLIENTS_ANNOUNCE / 2);
|
||||||
|
} else {
|
||||||
|
Ip_Ntoa ip_str;
|
||||||
|
LOGGER_TRACE(onion_c->logger, "not sending repeated announce request to %s:%d",
|
||||||
|
net_ip_ntoa(&target->ip_port.ip, &ip_str), net_ntohs(target->ip_port.port));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1959,22 +2025,25 @@ static void do_announce(Onion_Client *onion_c)
|
|||||||
non_null()
|
non_null()
|
||||||
static bool onion_isconnected(Onion_Client *onion_c)
|
static bool onion_isconnected(Onion_Client *onion_c)
|
||||||
{
|
{
|
||||||
unsigned int num = 0;
|
unsigned int live = 0;
|
||||||
unsigned int announced = 0;
|
unsigned int announced = 0;
|
||||||
|
|
||||||
if (mono_time_is_timeout(onion_c->mono_time, onion_c->last_packet_recv, ONION_OFFLINE_TIMEOUT)) {
|
if (mono_time_is_timeout(onion_c->mono_time, onion_c->last_packet_recv, ONION_OFFLINE_TIMEOUT)) {
|
||||||
|
LOGGER_TRACE(onion_c->logger, "onion is NOT connected: last packet received at %llu (timeout=%u)",
|
||||||
|
(unsigned long long)onion_c->last_packet_recv, ONION_OFFLINE_TIMEOUT);
|
||||||
onion_c->last_populated = 0;
|
onion_c->last_populated = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onion_c->path_nodes_index == 0) {
|
if (onion_c->path_nodes_index == 0) {
|
||||||
|
LOGGER_TRACE(onion_c->logger, "onion is NOT connected: no path nodes available");
|
||||||
onion_c->last_populated = 0;
|
onion_c->last_populated = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < MAX_ONION_CLIENTS_ANNOUNCE; ++i) {
|
for (unsigned int i = 0; i < MAX_ONION_CLIENTS_ANNOUNCE; ++i) {
|
||||||
if (!onion_node_timed_out(&onion_c->clients_announce_list[i], onion_c->mono_time)) {
|
if (!onion_node_timed_out(&onion_c->clients_announce_list[i], onion_c->mono_time)) {
|
||||||
++num;
|
++live;
|
||||||
|
|
||||||
if (onion_c->clients_announce_list[i].is_stored != 0) {
|
if (onion_c->clients_announce_list[i].is_stored != 0) {
|
||||||
++announced;
|
++announced;
|
||||||
@ -1990,14 +2059,18 @@ static bool onion_isconnected(Onion_Client *onion_c)
|
|||||||
|
|
||||||
/* Consider ourselves online if we are announced to half or more nodes
|
/* Consider ourselves online if we are announced to half or more nodes
|
||||||
* we are connected to */
|
* we are connected to */
|
||||||
if (num != 0 && announced != 0) {
|
if (live != 0 && announced != 0) {
|
||||||
if ((num / 2) <= announced && (pnodes / 2) <= num) {
|
if ((live / 2) <= announced && (pnodes / 2) <= live) {
|
||||||
|
LOGGER_TRACE(onion_c->logger, "onion is connected: %u live nodes, %u announced, %d path nodes",
|
||||||
|
live, announced, pnodes);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onion_c->last_populated = 0;
|
onion_c->last_populated = 0;
|
||||||
|
|
||||||
|
LOGGER_TRACE(onion_c->logger, "onion is NOT connected: %u live nodes, %u announced, %d path nodes",
|
||||||
|
live, announced, pnodes);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,12 +24,13 @@ struct Shared_Key_Cache {
|
|||||||
uint64_t timeout; /** After this time (in seconds), a key is erased on the next housekeeping cycle */
|
uint64_t timeout; /** After this time (in seconds), a key is erased on the next housekeeping cycle */
|
||||||
const Mono_Time *mono_time;
|
const Mono_Time *mono_time;
|
||||||
const Memory *mem;
|
const Memory *mem;
|
||||||
|
const Logger *log;
|
||||||
uint8_t keys_per_slot;
|
uint8_t keys_per_slot;
|
||||||
};
|
};
|
||||||
|
|
||||||
non_null()
|
non_null()
|
||||||
static bool shared_key_is_empty(const Shared_Key *k) {
|
static bool shared_key_is_empty(const Logger *log, const Shared_Key *k) {
|
||||||
assert(k != nullptr);
|
LOGGER_ASSERT(log, k != nullptr, "shared key must not be NULL");
|
||||||
/*
|
/*
|
||||||
* Since time can never be 0, we use that to determine if a key slot is empty.
|
* Since time can never be 0, we use that to determine if a key slot is empty.
|
||||||
* Additionally this allows us to use crypto_memzero and leave the slot in a valid state.
|
* Additionally this allows us to use crypto_memzero and leave the slot in a valid state.
|
||||||
@ -38,12 +39,12 @@ static bool shared_key_is_empty(const Shared_Key *k) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
non_null()
|
non_null()
|
||||||
static void shared_key_set_empty(Shared_Key *k) {
|
static void shared_key_set_empty(const Logger *log, Shared_Key *k) {
|
||||||
crypto_memzero(k, sizeof (Shared_Key));
|
crypto_memzero(k, sizeof (Shared_Key));
|
||||||
assert(shared_key_is_empty(k));
|
LOGGER_ASSERT(log, shared_key_is_empty(log, k), "shared key must be empty after clearing it");
|
||||||
}
|
}
|
||||||
|
|
||||||
Shared_Key_Cache *shared_key_cache_new(const Mono_Time *mono_time, const Memory *mem, const uint8_t *self_secret_key, uint64_t timeout, uint8_t keys_per_slot)
|
Shared_Key_Cache *shared_key_cache_new(const Logger *log, const Mono_Time *mono_time, const Memory *mem, const uint8_t *self_secret_key, uint64_t timeout, uint8_t keys_per_slot)
|
||||||
{
|
{
|
||||||
if (mono_time == nullptr || self_secret_key == nullptr || timeout == 0 || keys_per_slot == 0) {
|
if (mono_time == nullptr || self_secret_key == nullptr || timeout == 0 || keys_per_slot == 0) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -52,7 +53,7 @@ Shared_Key_Cache *shared_key_cache_new(const Mono_Time *mono_time, const Memory
|
|||||||
// Time must not be zero, since we use that as special value for empty slots
|
// Time must not be zero, since we use that as special value for empty slots
|
||||||
if (mono_time_get(mono_time) == 0) {
|
if (mono_time_get(mono_time) == 0) {
|
||||||
// Fail loudly in debug environments
|
// Fail loudly in debug environments
|
||||||
assert(false);
|
LOGGER_FATAL(log, "time must not be zero (mono_time not initialised?)");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,6 +65,7 @@ Shared_Key_Cache *shared_key_cache_new(const Mono_Time *mono_time, const Memory
|
|||||||
res->self_secret_key = self_secret_key;
|
res->self_secret_key = self_secret_key;
|
||||||
res->mono_time = mono_time;
|
res->mono_time = mono_time;
|
||||||
res->mem = mem;
|
res->mem = mem;
|
||||||
|
res->log = log;
|
||||||
res->keys_per_slot = keys_per_slot;
|
res->keys_per_slot = keys_per_slot;
|
||||||
// We take one byte from the public key for each bucket and store keys_per_slot elements there
|
// We take one byte from the public key for each bucket and store keys_per_slot elements there
|
||||||
const size_t cache_size = 256 * keys_per_slot;
|
const size_t cache_size = 256 * keys_per_slot;
|
||||||
@ -106,7 +108,7 @@ const uint8_t *shared_key_cache_lookup(Shared_Key_Cache *cache, const uint8_t pu
|
|||||||
|
|
||||||
// Perform lookup
|
// Perform lookup
|
||||||
for(size_t i = 0; i < cache->keys_per_slot; ++i) {
|
for(size_t i = 0; i < cache->keys_per_slot; ++i) {
|
||||||
if (shared_key_is_empty(&bucket_start[i])) {
|
if (shared_key_is_empty(cache->log, &bucket_start[i])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,13 +121,13 @@ const uint8_t *shared_key_cache_lookup(Shared_Key_Cache *cache, const uint8_t pu
|
|||||||
|
|
||||||
// Perform housekeeping for this bucket
|
// Perform housekeeping for this bucket
|
||||||
for (size_t i = 0; i < cache->keys_per_slot; ++i) {
|
for (size_t i = 0; i < cache->keys_per_slot; ++i) {
|
||||||
if (shared_key_is_empty(&bucket_start[i])) {
|
if (shared_key_is_empty(cache->log, &bucket_start[i])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool timed_out = (bucket_start[i].time_last_requested + cache->timeout) < cur_time;
|
const bool timed_out = (bucket_start[i].time_last_requested + cache->timeout) < cur_time;
|
||||||
if (timed_out) {
|
if (timed_out) {
|
||||||
shared_key_set_empty(&bucket_start[i]);
|
shared_key_set_empty(cache->log, &bucket_start[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <stdint.h> // uint*_t
|
#include <stdint.h> // uint*_t
|
||||||
|
|
||||||
#include "crypto_core.h"
|
#include "crypto_core.h"
|
||||||
|
#include "logger.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "mono_time.h"
|
#include "mono_time.h"
|
||||||
|
|
||||||
@ -27,7 +28,8 @@ typedef struct Shared_Key_Cache Shared_Key_Cache;
|
|||||||
* @return nullptr on error.
|
* @return nullptr on error.
|
||||||
*/
|
*/
|
||||||
non_null()
|
non_null()
|
||||||
Shared_Key_Cache *shared_key_cache_new(const Mono_Time *mono_time, const Memory *mem,
|
Shared_Key_Cache *shared_key_cache_new(
|
||||||
|
const Logger *log, const Mono_Time *mono_time, const Memory *mem,
|
||||||
const uint8_t *self_secret_key,
|
const uint8_t *self_secret_key,
|
||||||
uint64_t timeout, uint8_t keys_per_slot);
|
uint64_t timeout, uint8_t keys_per_slot);
|
||||||
|
|
||||||
|
6
external/toxcore/c-toxcore/toxcore/tox.c
vendored
6
external/toxcore/c-toxcore/toxcore/tox.c
vendored
@ -43,6 +43,8 @@ static_assert(FILE_ID_LENGTH == CRYPTO_SYMMETRIC_KEY_SIZE,
|
|||||||
"FILE_ID_LENGTH is assumed to be equal to CRYPTO_SYMMETRIC_KEY_SIZE");
|
"FILE_ID_LENGTH is assumed to be equal to CRYPTO_SYMMETRIC_KEY_SIZE");
|
||||||
static_assert(TOX_DHT_NODE_IP_STRING_SIZE == IP_NTOA_LEN,
|
static_assert(TOX_DHT_NODE_IP_STRING_SIZE == IP_NTOA_LEN,
|
||||||
"TOX_DHT_NODE_IP_STRING_SIZE is assumed to be equal to IP_NTOA_LEN");
|
"TOX_DHT_NODE_IP_STRING_SIZE is assumed to be equal to IP_NTOA_LEN");
|
||||||
|
static_assert(TOX_GROUP_PEER_IP_STRING_MAX_LENGTH == IP_NTOA_LEN,
|
||||||
|
"TOX_GROUP_PEER_IP_STRING_MAX_LENGTH is assumed to be equal to IP_NTOA_LEN");
|
||||||
static_assert(TOX_DHT_NODE_PUBLIC_KEY_SIZE == CRYPTO_PUBLIC_KEY_SIZE,
|
static_assert(TOX_DHT_NODE_PUBLIC_KEY_SIZE == CRYPTO_PUBLIC_KEY_SIZE,
|
||||||
"TOX_DHT_NODE_PUBLIC_KEY_SIZE is assumed to be equal to CRYPTO_PUBLIC_KEY_SIZE");
|
"TOX_DHT_NODE_PUBLIC_KEY_SIZE is assumed to be equal to CRYPTO_PUBLIC_KEY_SIZE");
|
||||||
static_assert(TOX_FILE_ID_LENGTH == CRYPTO_SYMMETRIC_KEY_SIZE,
|
static_assert(TOX_FILE_ID_LENGTH == CRYPTO_SYMMETRIC_KEY_SIZE,
|
||||||
@ -2810,7 +2812,7 @@ uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error)
|
|||||||
{
|
{
|
||||||
assert(tox != nullptr);
|
assert(tox != nullptr);
|
||||||
tox_lock(tox);
|
tox_lock(tox);
|
||||||
const uint16_t port = net_htons(net_port(tox->m->net));
|
const uint16_t port = tox->m == nullptr || tox->m->net == nullptr ? 0 : net_htons(net_port(tox->m->net));
|
||||||
tox_unlock(tox);
|
tox_unlock(tox);
|
||||||
|
|
||||||
if (port == 0) {
|
if (port == 0) {
|
||||||
@ -2827,7 +2829,7 @@ uint16_t tox_self_get_tcp_port(const Tox *tox, Tox_Err_Get_Port *error)
|
|||||||
assert(tox != nullptr);
|
assert(tox != nullptr);
|
||||||
tox_lock(tox);
|
tox_lock(tox);
|
||||||
|
|
||||||
if (tox->m->tcp_server != nullptr) {
|
if (tox->m != nullptr && tox->m->tcp_server != nullptr) {
|
||||||
SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_OK);
|
SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_OK);
|
||||||
const uint16_t ret = tox->m->options.tcp_server_port;
|
const uint16_t ret = tox->m->options.tcp_server_port;
|
||||||
tox_unlock(tox);
|
tox_unlock(tox);
|
||||||
|
147
external/toxcore/c-toxcore/toxcore/tox.h
vendored
147
external/toxcore/c-toxcore/toxcore/tox.h
vendored
@ -373,6 +373,8 @@ typedef enum Tox_User_Status {
|
|||||||
|
|
||||||
} Tox_User_Status;
|
} Tox_User_Status;
|
||||||
|
|
||||||
|
const char *tox_user_status_to_string(Tox_User_Status value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Represents message types for tox_friend_send_message and conference
|
* @brief Represents message types for tox_friend_send_message and conference
|
||||||
@ -393,6 +395,8 @@ typedef enum Tox_Message_Type {
|
|||||||
|
|
||||||
} Tox_Message_Type;
|
} Tox_Message_Type;
|
||||||
|
|
||||||
|
const char *tox_message_type_to_string(Tox_Message_Type value);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
||||||
@ -422,6 +426,8 @@ typedef enum Tox_Proxy_Type {
|
|||||||
|
|
||||||
} Tox_Proxy_Type;
|
} Tox_Proxy_Type;
|
||||||
|
|
||||||
|
const char *tox_proxy_type_to_string(Tox_Proxy_Type value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type of savedata to create the Tox instance from.
|
* @brief Type of savedata to create the Tox instance from.
|
||||||
@ -445,6 +451,8 @@ typedef enum Tox_Savedata_Type {
|
|||||||
|
|
||||||
} Tox_Savedata_Type;
|
} Tox_Savedata_Type;
|
||||||
|
|
||||||
|
const char *tox_savedata_type_to_string(Tox_Savedata_Type value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Severity level of log messages.
|
* @brief Severity level of log messages.
|
||||||
@ -478,6 +486,8 @@ typedef enum Tox_Log_Level {
|
|||||||
|
|
||||||
} Tox_Log_Level;
|
} Tox_Log_Level;
|
||||||
|
|
||||||
|
const char *tox_log_level_to_string(Tox_Log_Level value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This event is triggered when the toxcore library logs an events_alloc message.
|
* @brief This event is triggered when the toxcore library logs an events_alloc message.
|
||||||
@ -791,6 +801,8 @@ typedef enum Tox_Err_Options_New {
|
|||||||
|
|
||||||
} Tox_Err_Options_New;
|
} Tox_Err_Options_New;
|
||||||
|
|
||||||
|
const char *tox_err_options_new_to_string(Tox_Err_Options_New value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Allocates a new Tox_Options object and initialises it with the default
|
* @brief Allocates a new Tox_Options object and initialises it with the default
|
||||||
@ -883,6 +895,8 @@ typedef enum Tox_Err_New {
|
|||||||
|
|
||||||
} Tox_Err_New;
|
} Tox_Err_New;
|
||||||
|
|
||||||
|
const char *tox_err_new_to_string(Tox_Err_New value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Creates and initialises a new Tox instance with the options passed.
|
* @brief Creates and initialises a new Tox instance with the options passed.
|
||||||
@ -962,6 +976,8 @@ typedef enum Tox_Err_Bootstrap {
|
|||||||
|
|
||||||
} Tox_Err_Bootstrap;
|
} Tox_Err_Bootstrap;
|
||||||
|
|
||||||
|
const char *tox_err_bootstrap_to_string(Tox_Err_Bootstrap value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sends a "get nodes" request to the given bootstrap node with IP, port,
|
* @brief Sends a "get nodes" request to the given bootstrap node with IP, port,
|
||||||
@ -1029,6 +1045,8 @@ typedef enum Tox_Connection {
|
|||||||
|
|
||||||
} Tox_Connection;
|
} Tox_Connection;
|
||||||
|
|
||||||
|
const char *tox_connection_to_string(Tox_Connection value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return whether we are connected to the DHT.
|
* @brief Return whether we are connected to the DHT.
|
||||||
*
|
*
|
||||||
@ -1155,6 +1173,8 @@ typedef enum Tox_Err_Set_Info {
|
|||||||
|
|
||||||
} Tox_Err_Set_Info;
|
} Tox_Err_Set_Info;
|
||||||
|
|
||||||
|
const char *tox_err_set_info_to_string(Tox_Err_Set_Info value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the nickname for the Tox client.
|
* @brief Set the nickname for the Tox client.
|
||||||
@ -1297,6 +1317,8 @@ typedef enum Tox_Err_Friend_Add {
|
|||||||
|
|
||||||
} Tox_Err_Friend_Add;
|
} Tox_Err_Friend_Add;
|
||||||
|
|
||||||
|
const char *tox_err_friend_add_to_string(Tox_Err_Friend_Add value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add a friend to the friend list and send a friend request.
|
* @brief Add a friend to the friend list and send a friend request.
|
||||||
@ -1358,6 +1380,8 @@ typedef enum Tox_Err_Friend_Delete {
|
|||||||
|
|
||||||
} Tox_Err_Friend_Delete;
|
} Tox_Err_Friend_Delete;
|
||||||
|
|
||||||
|
const char *tox_err_friend_delete_to_string(Tox_Err_Friend_Delete value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove a friend from the friend list.
|
* @brief Remove a friend from the friend list.
|
||||||
@ -1398,6 +1422,8 @@ typedef enum Tox_Err_Friend_By_Public_Key {
|
|||||||
|
|
||||||
} Tox_Err_Friend_By_Public_Key;
|
} Tox_Err_Friend_By_Public_Key;
|
||||||
|
|
||||||
|
const char *tox_err_friend_by_public_key_to_string(Tox_Err_Friend_By_Public_Key value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the friend number associated with that Public Key.
|
* @brief Return the friend number associated with that Public Key.
|
||||||
@ -1445,6 +1471,8 @@ typedef enum Tox_Err_Friend_Get_Public_Key {
|
|||||||
|
|
||||||
} Tox_Err_Friend_Get_Public_Key;
|
} Tox_Err_Friend_Get_Public_Key;
|
||||||
|
|
||||||
|
const char *tox_err_friend_get_public_key_to_string(Tox_Err_Friend_Get_Public_Key value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Copies the Public Key associated with a given friend number to a byte array.
|
* @brief Copies the Public Key associated with a given friend number to a byte array.
|
||||||
@ -1472,6 +1500,8 @@ typedef enum Tox_Err_Friend_Get_Last_Online {
|
|||||||
|
|
||||||
} Tox_Err_Friend_Get_Last_Online;
|
} Tox_Err_Friend_Get_Last_Online;
|
||||||
|
|
||||||
|
const char *tox_err_friend_get_last_online_to_string(Tox_Err_Friend_Get_Last_Online value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return a unix-time timestamp of the last time the friend associated with a given
|
* @brief Return a unix-time timestamp of the last time the friend associated with a given
|
||||||
@ -1514,6 +1544,8 @@ typedef enum Tox_Err_Friend_Query {
|
|||||||
|
|
||||||
} Tox_Err_Friend_Query;
|
} Tox_Err_Friend_Query;
|
||||||
|
|
||||||
|
const char *tox_err_friend_query_to_string(Tox_Err_Friend_Query value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the length of the friend's name.
|
* @brief Return the length of the friend's name.
|
||||||
@ -1726,6 +1758,8 @@ typedef enum Tox_Err_Set_Typing {
|
|||||||
|
|
||||||
} Tox_Err_Set_Typing;
|
} Tox_Err_Set_Typing;
|
||||||
|
|
||||||
|
const char *tox_err_set_typing_to_string(Tox_Err_Set_Typing value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the client's typing status for a friend.
|
* @brief Set the client's typing status for a friend.
|
||||||
@ -1778,6 +1812,8 @@ typedef enum Tox_Err_Friend_Send_Message {
|
|||||||
|
|
||||||
} Tox_Err_Friend_Send_Message;
|
} Tox_Err_Friend_Send_Message;
|
||||||
|
|
||||||
|
const char *tox_err_friend_send_message_to_string(Tox_Err_Friend_Send_Message value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send a text chat message to an online friend.
|
* @brief Send a text chat message to an online friend.
|
||||||
@ -1960,6 +1996,8 @@ typedef enum Tox_File_Control {
|
|||||||
|
|
||||||
} Tox_File_Control;
|
} Tox_File_Control;
|
||||||
|
|
||||||
|
const char *tox_file_control_to_string(Tox_File_Control value);
|
||||||
|
|
||||||
|
|
||||||
typedef enum Tox_Err_File_Control {
|
typedef enum Tox_Err_File_Control {
|
||||||
|
|
||||||
@ -2006,6 +2044,8 @@ typedef enum Tox_Err_File_Control {
|
|||||||
|
|
||||||
} Tox_Err_File_Control;
|
} Tox_Err_File_Control;
|
||||||
|
|
||||||
|
const char *tox_err_file_control_to_string(Tox_Err_File_Control value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sends a file control command to a friend for a given file transfer.
|
* @brief Sends a file control command to a friend for a given file transfer.
|
||||||
@ -2082,6 +2122,8 @@ typedef enum Tox_Err_File_Seek {
|
|||||||
|
|
||||||
} Tox_Err_File_Seek;
|
} Tox_Err_File_Seek;
|
||||||
|
|
||||||
|
const char *tox_err_file_seek_to_string(Tox_Err_File_Seek value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sends a file seek control command to a friend for a given file transfer.
|
* @brief Sends a file seek control command to a friend for a given file transfer.
|
||||||
@ -2120,6 +2162,8 @@ typedef enum Tox_Err_File_Get {
|
|||||||
|
|
||||||
} Tox_Err_File_Get;
|
} Tox_Err_File_Get;
|
||||||
|
|
||||||
|
const char *tox_err_file_get_to_string(Tox_Err_File_Get value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Copy the file id associated to the file transfer to a byte array.
|
* @brief Copy the file id associated to the file transfer to a byte array.
|
||||||
@ -2177,6 +2221,8 @@ typedef enum Tox_Err_File_Send {
|
|||||||
|
|
||||||
} Tox_Err_File_Send;
|
} Tox_Err_File_Send;
|
||||||
|
|
||||||
|
const char *tox_err_file_send_to_string(Tox_Err_File_Send value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send a file transmission request.
|
* @brief Send a file transmission request.
|
||||||
@ -2291,6 +2337,8 @@ typedef enum Tox_Err_File_Send_Chunk {
|
|||||||
|
|
||||||
} Tox_Err_File_Send_Chunk;
|
} Tox_Err_File_Send_Chunk;
|
||||||
|
|
||||||
|
const char *tox_err_file_send_chunk_to_string(Tox_Err_File_Send_Chunk value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send a chunk of file data to a friend.
|
* @brief Send a chunk of file data to a friend.
|
||||||
@ -2438,6 +2486,8 @@ typedef enum Tox_Conference_Type {
|
|||||||
|
|
||||||
} Tox_Conference_Type;
|
} Tox_Conference_Type;
|
||||||
|
|
||||||
|
const char *tox_conference_type_to_string(Tox_Conference_Type value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The invitation will remain valid until the inviting friend goes offline
|
* The invitation will remain valid until the inviting friend goes offline
|
||||||
@ -2571,6 +2621,8 @@ typedef enum Tox_Err_Conference_New {
|
|||||||
|
|
||||||
} Tox_Err_Conference_New;
|
} Tox_Err_Conference_New;
|
||||||
|
|
||||||
|
const char *tox_err_conference_new_to_string(Tox_Err_Conference_New value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Creates a new conference.
|
* @brief Creates a new conference.
|
||||||
@ -2597,6 +2649,8 @@ typedef enum Tox_Err_Conference_Delete {
|
|||||||
|
|
||||||
} Tox_Err_Conference_Delete;
|
} Tox_Err_Conference_Delete;
|
||||||
|
|
||||||
|
const char *tox_err_conference_delete_to_string(Tox_Err_Conference_Delete value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function deletes a conference.
|
* @brief This function deletes a conference.
|
||||||
@ -2634,6 +2688,8 @@ typedef enum Tox_Err_Conference_Peer_Query {
|
|||||||
|
|
||||||
} Tox_Err_Conference_Peer_Query;
|
} Tox_Err_Conference_Peer_Query;
|
||||||
|
|
||||||
|
const char *tox_err_conference_peer_query_to_string(Tox_Err_Conference_Peer_Query value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the number of online peers in the conference.
|
* @brief Return the number of online peers in the conference.
|
||||||
@ -2742,6 +2798,8 @@ typedef enum Tox_Err_Conference_Set_Max_Offline {
|
|||||||
|
|
||||||
} Tox_Err_Conference_Set_Max_Offline;
|
} Tox_Err_Conference_Set_Max_Offline;
|
||||||
|
|
||||||
|
const char *tox_err_conference_set_max_offline_to_string(Tox_Err_Conference_Set_Max_Offline value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set maximum number of offline peers to store, overriding the default.
|
* @brief Set maximum number of offline peers to store, overriding the default.
|
||||||
@ -2773,6 +2831,8 @@ typedef enum Tox_Err_Conference_Invite {
|
|||||||
|
|
||||||
} Tox_Err_Conference_Invite;
|
} Tox_Err_Conference_Invite;
|
||||||
|
|
||||||
|
const char *tox_err_conference_invite_to_string(Tox_Err_Conference_Invite value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Invites a friend to a conference.
|
* @brief Invites a friend to a conference.
|
||||||
@ -2824,6 +2884,8 @@ typedef enum Tox_Err_Conference_Join {
|
|||||||
|
|
||||||
} Tox_Err_Conference_Join;
|
} Tox_Err_Conference_Join;
|
||||||
|
|
||||||
|
const char *tox_err_conference_join_to_string(Tox_Err_Conference_Join value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Joins a conference that the client has been invited to.
|
* @brief Joins a conference that the client has been invited to.
|
||||||
@ -2874,6 +2936,8 @@ typedef enum Tox_Err_Conference_Send_Message {
|
|||||||
|
|
||||||
} Tox_Err_Conference_Send_Message;
|
} Tox_Err_Conference_Send_Message;
|
||||||
|
|
||||||
|
const char *tox_err_conference_send_message_to_string(Tox_Err_Conference_Send_Message value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send a text chat message to the conference.
|
* @brief Send a text chat message to the conference.
|
||||||
@ -2921,6 +2985,8 @@ typedef enum Tox_Err_Conference_Title {
|
|||||||
|
|
||||||
} Tox_Err_Conference_Title;
|
} Tox_Err_Conference_Title;
|
||||||
|
|
||||||
|
const char *tox_err_conference_title_to_string(Tox_Err_Conference_Title value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the length of the conference title.
|
* @brief Return the length of the conference title.
|
||||||
@ -3000,6 +3066,8 @@ typedef enum Tox_Err_Conference_Get_Type {
|
|||||||
|
|
||||||
} Tox_Err_Conference_Get_Type;
|
} Tox_Err_Conference_Get_Type;
|
||||||
|
|
||||||
|
const char *tox_err_conference_get_type_to_string(Tox_Err_Conference_Get_Type value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the type (text or A/V) for the conference.
|
* @brief Get the type (text or A/V) for the conference.
|
||||||
@ -3037,6 +3105,8 @@ typedef enum Tox_Err_Conference_By_Id {
|
|||||||
|
|
||||||
} Tox_Err_Conference_By_Id;
|
} Tox_Err_Conference_By_Id;
|
||||||
|
|
||||||
|
const char *tox_err_conference_by_id_to_string(Tox_Err_Conference_By_Id value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the conference number associated with the specified id.
|
* @brief Return the conference number associated with the specified id.
|
||||||
@ -3078,6 +3148,8 @@ typedef enum Tox_Err_Conference_By_Uid {
|
|||||||
|
|
||||||
} Tox_Err_Conference_By_Uid;
|
} Tox_Err_Conference_By_Uid;
|
||||||
|
|
||||||
|
const char *tox_err_conference_by_uid_to_string(Tox_Err_Conference_By_Uid value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the conference number associated with the specified uid.
|
* @brief Return the conference number associated with the specified uid.
|
||||||
@ -3141,6 +3213,8 @@ typedef enum Tox_Err_Friend_Custom_Packet {
|
|||||||
|
|
||||||
} Tox_Err_Friend_Custom_Packet;
|
} Tox_Err_Friend_Custom_Packet;
|
||||||
|
|
||||||
|
const char *tox_err_friend_custom_packet_to_string(Tox_Err_Friend_Custom_Packet value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send a custom lossy packet to a friend.
|
* @brief Send a custom lossy packet to a friend.
|
||||||
@ -3237,6 +3311,8 @@ typedef enum Tox_Err_Get_Port {
|
|||||||
|
|
||||||
} Tox_Err_Get_Port;
|
} Tox_Err_Get_Port;
|
||||||
|
|
||||||
|
const char *tox_err_get_port_to_string(Tox_Err_Get_Port value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Writes the temporary DHT public key of this instance to a byte array.
|
* @brief Writes the temporary DHT public key of this instance to a byte array.
|
||||||
@ -3307,7 +3383,7 @@ uint32_t tox_group_max_message_length(void);
|
|||||||
/**
|
/**
|
||||||
* Maximum length of a group custom lossy packet.
|
* Maximum length of a group custom lossy packet.
|
||||||
*/
|
*/
|
||||||
#define TOX_GROUP_MAX_CUSTOM_LOSSY_PACKET_LENGTH 1000
|
#define TOX_GROUP_MAX_CUSTOM_LOSSY_PACKET_LENGTH 1373
|
||||||
|
|
||||||
uint32_t tox_group_max_custom_lossy_packet_length(void);
|
uint32_t tox_group_max_custom_lossy_packet_length(void);
|
||||||
|
|
||||||
@ -3382,6 +3458,8 @@ typedef enum Tox_Group_Privacy_State {
|
|||||||
|
|
||||||
} Tox_Group_Privacy_State;
|
} Tox_Group_Privacy_State;
|
||||||
|
|
||||||
|
const char *tox_group_privacy_state_to_string(Tox_Group_Privacy_State value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the state of the group topic lock.
|
* Represents the state of the group topic lock.
|
||||||
@ -3400,6 +3478,8 @@ typedef enum Tox_Group_Topic_Lock {
|
|||||||
|
|
||||||
} Tox_Group_Topic_Lock;
|
} Tox_Group_Topic_Lock;
|
||||||
|
|
||||||
|
const char *tox_group_topic_lock_to_string(Tox_Group_Topic_Lock value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the group voice state, which determines which Group Roles have permission to speak
|
* Represents the group voice state, which determines which Group Roles have permission to speak
|
||||||
* in the group chat. The voice state does not have any effect private messages or topic setting.
|
* in the group chat. The voice state does not have any effect private messages or topic setting.
|
||||||
@ -3421,6 +3501,8 @@ typedef enum Tox_Group_Voice_State {
|
|||||||
TOX_GROUP_VOICE_STATE_FOUNDER,
|
TOX_GROUP_VOICE_STATE_FOUNDER,
|
||||||
} Tox_Group_Voice_State;
|
} Tox_Group_Voice_State;
|
||||||
|
|
||||||
|
const char *tox_group_voice_state_to_string(Tox_Group_Voice_State value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents group roles.
|
* Represents group roles.
|
||||||
*
|
*
|
||||||
@ -3453,6 +3535,8 @@ typedef enum Tox_Group_Role {
|
|||||||
|
|
||||||
} Tox_Group_Role;
|
} Tox_Group_Role;
|
||||||
|
|
||||||
|
const char *tox_group_role_to_string(Tox_Group_Role value);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -3498,6 +3582,8 @@ typedef enum Tox_Err_Group_New {
|
|||||||
|
|
||||||
} Tox_Err_Group_New;
|
} Tox_Err_Group_New;
|
||||||
|
|
||||||
|
const char *tox_err_group_new_to_string(Tox_Err_Group_New value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new group chat.
|
* Creates a new group chat.
|
||||||
@ -3564,6 +3650,8 @@ typedef enum Tox_Err_Group_Join {
|
|||||||
|
|
||||||
} Tox_Err_Group_Join;
|
} Tox_Err_Group_Join;
|
||||||
|
|
||||||
|
const char *tox_err_group_join_to_string(Tox_Err_Group_Join value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Joins a group chat with specified Chat ID.
|
* Joins a group chat with specified Chat ID.
|
||||||
@ -3599,6 +3687,8 @@ typedef enum Tox_Err_Group_Is_Connected {
|
|||||||
|
|
||||||
} Tox_Err_Group_Is_Connected;
|
} Tox_Err_Group_Is_Connected;
|
||||||
|
|
||||||
|
const char *tox_err_group_is_connected_to_string(Tox_Err_Group_Is_Connected value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the group chat is currently connected or attempting to connect to other peers
|
* Returns true if the group chat is currently connected or attempting to connect to other peers
|
||||||
@ -3626,6 +3716,8 @@ typedef enum Tox_Err_Group_Disconnect {
|
|||||||
TOX_ERR_GROUP_DISCONNECT_ALREADY_DISCONNECTED,
|
TOX_ERR_GROUP_DISCONNECT_ALREADY_DISCONNECTED,
|
||||||
} Tox_Err_Group_Disconnect;
|
} Tox_Err_Group_Disconnect;
|
||||||
|
|
||||||
|
const char *tox_err_group_disconnect_to_string(Tox_Err_Group_Disconnect value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects from a group chat while retaining the group state and credentials.
|
* Disconnects from a group chat while retaining the group state and credentials.
|
||||||
@ -3655,6 +3747,8 @@ typedef enum Tox_Err_Group_Reconnect {
|
|||||||
|
|
||||||
} Tox_Err_Group_Reconnect;
|
} Tox_Err_Group_Reconnect;
|
||||||
|
|
||||||
|
const char *tox_err_group_reconnect_to_string(Tox_Err_Group_Reconnect value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reconnects to a group.
|
* Reconnects to a group.
|
||||||
@ -3691,6 +3785,8 @@ typedef enum Tox_Err_Group_Leave {
|
|||||||
TOX_ERR_GROUP_LEAVE_FAIL_SEND,
|
TOX_ERR_GROUP_LEAVE_FAIL_SEND,
|
||||||
} Tox_Err_Group_Leave;
|
} Tox_Err_Group_Leave;
|
||||||
|
|
||||||
|
const char *tox_err_group_leave_to_string(Tox_Err_Group_Leave value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Leaves a group.
|
* Leaves a group.
|
||||||
@ -3735,6 +3831,8 @@ typedef enum Tox_Err_Group_Self_Query {
|
|||||||
|
|
||||||
} Tox_Err_Group_Self_Query;
|
} Tox_Err_Group_Self_Query;
|
||||||
|
|
||||||
|
const char *tox_err_group_self_query_to_string(Tox_Err_Group_Self_Query value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error codes for self name setting.
|
* Error codes for self name setting.
|
||||||
@ -3768,6 +3866,8 @@ typedef enum Tox_Err_Group_Self_Name_Set {
|
|||||||
|
|
||||||
} Tox_Err_Group_Self_Name_Set;
|
} Tox_Err_Group_Self_Name_Set;
|
||||||
|
|
||||||
|
const char *tox_err_group_self_name_set_to_string(Tox_Err_Group_Self_Name_Set value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the client's nickname for the group instance designated by the given group number.
|
* Set the client's nickname for the group instance designated by the given group number.
|
||||||
@ -3831,6 +3931,8 @@ typedef enum Tox_Err_Group_Self_Status_Set {
|
|||||||
|
|
||||||
} Tox_Err_Group_Self_Status_Set;
|
} Tox_Err_Group_Self_Status_Set;
|
||||||
|
|
||||||
|
const char *tox_err_group_self_status_set_to_string(Tox_Err_Group_Self_Status_Set value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the client's status for the group instance. Status must be a Tox_User_Status.
|
* Set the client's status for the group instance. Status must be a Tox_User_Status.
|
||||||
@ -3906,6 +4008,8 @@ typedef enum Tox_Err_Group_Peer_Query {
|
|||||||
|
|
||||||
} Tox_Err_Group_Peer_Query;
|
} Tox_Err_Group_Peer_Query;
|
||||||
|
|
||||||
|
const char *tox_err_group_peer_query_to_string(Tox_Err_Group_Peer_Query value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the length of the peer's name. If the group number or ID is invalid, the
|
* Return the length of the peer's name. If the group number or ID is invalid, the
|
||||||
@ -3967,7 +4071,8 @@ Tox_Group_Role tox_group_peer_get_role(const Tox *tox, uint32_t group_number, ui
|
|||||||
/**
|
/**
|
||||||
* Return the type of connection we have established with a peer.
|
* Return the type of connection we have established with a peer.
|
||||||
*
|
*
|
||||||
* This function will return an error if called on ourselves.
|
* If `peer_id` designates ourself, the return value indicates whether we're capable
|
||||||
|
* of making UDP connections with other peers, or are limited to TCP connections.
|
||||||
*
|
*
|
||||||
* @param group_number The group number of the group we wish to query.
|
* @param group_number The group number of the group we wish to query.
|
||||||
* @param peer_id The ID of the peer whose connection status we wish to query.
|
* @param peer_id The ID of the peer whose connection status we wish to query.
|
||||||
@ -4053,6 +4158,8 @@ typedef enum Tox_Err_Group_State_Queries {
|
|||||||
|
|
||||||
} Tox_Err_Group_State_Queries;
|
} Tox_Err_Group_State_Queries;
|
||||||
|
|
||||||
|
const char *tox_err_group_state_queries_to_string(Tox_Err_Group_State_Queries value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error codes for group topic setting.
|
* Error codes for group topic setting.
|
||||||
@ -4096,6 +4203,8 @@ typedef enum Tox_Err_Group_Topic_Set {
|
|||||||
|
|
||||||
} Tox_Err_Group_Topic_Set;
|
} Tox_Err_Group_Topic_Set;
|
||||||
|
|
||||||
|
const char *tox_err_group_topic_set_to_string(Tox_Err_Group_Topic_Set value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the group topic and broadcast it to the rest of the group.
|
* Set the group topic and broadcast it to the rest of the group.
|
||||||
@ -4383,6 +4492,8 @@ typedef enum Tox_Err_Group_Send_Message {
|
|||||||
|
|
||||||
} Tox_Err_Group_Send_Message;
|
} Tox_Err_Group_Send_Message;
|
||||||
|
|
||||||
|
const char *tox_err_group_send_message_to_string(Tox_Err_Group_Send_Message value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a text chat message to the group.
|
* Send a text chat message to the group.
|
||||||
@ -4457,6 +4568,8 @@ typedef enum Tox_Err_Group_Send_Private_Message {
|
|||||||
|
|
||||||
} Tox_Err_Group_Send_Private_Message;
|
} Tox_Err_Group_Send_Private_Message;
|
||||||
|
|
||||||
|
const char *tox_err_group_send_private_message_to_string(Tox_Err_Group_Send_Private_Message value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a text chat message to the specified peer in the specified group.
|
* Send a text chat message to the specified peer in the specified group.
|
||||||
@ -4515,6 +4628,8 @@ typedef enum Tox_Err_Group_Send_Custom_Packet {
|
|||||||
|
|
||||||
} Tox_Err_Group_Send_Custom_Packet;
|
} Tox_Err_Group_Send_Custom_Packet;
|
||||||
|
|
||||||
|
const char *tox_err_group_send_custom_packet_to_string(Tox_Err_Group_Send_Custom_Packet value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a custom packet to the group.
|
* Send a custom packet to the group.
|
||||||
@ -4591,6 +4706,8 @@ typedef enum Tox_Err_Group_Send_Custom_Private_Packet {
|
|||||||
|
|
||||||
} Tox_Err_Group_Send_Custom_Private_Packet;
|
} Tox_Err_Group_Send_Custom_Private_Packet;
|
||||||
|
|
||||||
|
const char *tox_err_group_send_custom_private_packet_to_string(Tox_Err_Group_Send_Custom_Private_Packet value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a custom private packet to a designated peer in the group.
|
* Send a custom private packet to a designated peer in the group.
|
||||||
*
|
*
|
||||||
@ -4742,6 +4859,8 @@ typedef enum Tox_Err_Group_Invite_Friend {
|
|||||||
|
|
||||||
} Tox_Err_Group_Invite_Friend;
|
} Tox_Err_Group_Invite_Friend;
|
||||||
|
|
||||||
|
const char *tox_err_group_invite_friend_to_string(Tox_Err_Group_Invite_Friend value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invite a friend to a group.
|
* Invite a friend to a group.
|
||||||
@ -4800,6 +4919,8 @@ typedef enum Tox_Err_Group_Invite_Accept {
|
|||||||
|
|
||||||
} Tox_Err_Group_Invite_Accept;
|
} Tox_Err_Group_Invite_Accept;
|
||||||
|
|
||||||
|
const char *tox_err_group_invite_accept_to_string(Tox_Err_Group_Invite_Accept value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accept an invite to a group chat that the client previously received from a friend. The invite
|
* Accept an invite to a group chat that the client previously received from a friend. The invite
|
||||||
@ -4890,6 +5011,8 @@ typedef enum Tox_Group_Exit_Type {
|
|||||||
|
|
||||||
} Tox_Group_Exit_Type;
|
} Tox_Group_Exit_Type;
|
||||||
|
|
||||||
|
const char *tox_group_exit_type_to_string(Tox_Group_Exit_Type value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param group_number The group number of the group in which a peer has left.
|
* @param group_number The group number of the group in which a peer has left.
|
||||||
@ -4950,6 +5073,8 @@ typedef enum Tox_Group_Join_Fail {
|
|||||||
|
|
||||||
} Tox_Group_Join_Fail;
|
} Tox_Group_Join_Fail;
|
||||||
|
|
||||||
|
const char *tox_group_join_fail_to_string(Tox_Group_Join_Fail value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param group_number The group number of the group for which the join has failed.
|
* @param group_number The group number of the group for which the join has failed.
|
||||||
@ -5013,6 +5138,8 @@ typedef enum Tox_Err_Group_Founder_Set_Password {
|
|||||||
|
|
||||||
} Tox_Err_Group_Founder_Set_Password;
|
} Tox_Err_Group_Founder_Set_Password;
|
||||||
|
|
||||||
|
const char *tox_err_group_founder_set_password_to_string(Tox_Err_Group_Founder_Set_Password value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set or unset the group password.
|
* Set or unset the group password.
|
||||||
@ -5069,6 +5196,8 @@ typedef enum Tox_Err_Group_Founder_Set_Topic_Lock {
|
|||||||
|
|
||||||
} Tox_Err_Group_Founder_Set_Topic_Lock;
|
} Tox_Err_Group_Founder_Set_Topic_Lock;
|
||||||
|
|
||||||
|
const char *tox_err_group_founder_set_topic_lock_to_string(Tox_Err_Group_Founder_Set_Topic_Lock value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the group topic lock state.
|
* Set the group topic lock state.
|
||||||
@ -5122,6 +5251,8 @@ typedef enum Tox_Err_Group_Founder_Set_Voice_State {
|
|||||||
|
|
||||||
} Tox_Err_Group_Founder_Set_Voice_State;
|
} Tox_Err_Group_Founder_Set_Voice_State;
|
||||||
|
|
||||||
|
const char *tox_err_group_founder_set_voice_state_to_string(Tox_Err_Group_Founder_Set_Voice_State value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the group voice state.
|
* Set the group voice state.
|
||||||
*
|
*
|
||||||
@ -5174,6 +5305,8 @@ typedef enum Tox_Err_Group_Founder_Set_Privacy_State {
|
|||||||
|
|
||||||
} Tox_Err_Group_Founder_Set_Privacy_State;
|
} Tox_Err_Group_Founder_Set_Privacy_State;
|
||||||
|
|
||||||
|
const char *tox_err_group_founder_set_privacy_state_to_string(Tox_Err_Group_Founder_Set_Privacy_State value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the group privacy state.
|
* Set the group privacy state.
|
||||||
*
|
*
|
||||||
@ -5226,6 +5359,8 @@ typedef enum Tox_Err_Group_Founder_Set_Peer_Limit {
|
|||||||
|
|
||||||
} Tox_Err_Group_Founder_Set_Peer_Limit;
|
} Tox_Err_Group_Founder_Set_Peer_Limit;
|
||||||
|
|
||||||
|
const char *tox_err_group_founder_set_peer_limit_to_string(Tox_Err_Group_Founder_Set_Peer_Limit value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the group peer limit.
|
* Set the group peer limit.
|
||||||
@ -5274,6 +5409,8 @@ typedef enum Tox_Err_Group_Set_Ignore {
|
|||||||
|
|
||||||
} Tox_Err_Group_Set_Ignore;
|
} Tox_Err_Group_Set_Ignore;
|
||||||
|
|
||||||
|
const char *tox_err_group_set_ignore_to_string(Tox_Err_Group_Set_Ignore value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ignore or unignore a peer.
|
* Ignore or unignore a peer.
|
||||||
@ -5328,6 +5465,8 @@ typedef enum Tox_Err_Group_Mod_Set_Role {
|
|||||||
|
|
||||||
} Tox_Err_Group_Mod_Set_Role;
|
} Tox_Err_Group_Mod_Set_Role;
|
||||||
|
|
||||||
|
const char *tox_err_group_mod_set_role_to_string(Tox_Err_Group_Mod_Set_Role value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a peer's role.
|
* Set a peer's role.
|
||||||
@ -5384,6 +5523,8 @@ typedef enum Tox_Err_Group_Mod_Kick_Peer {
|
|||||||
|
|
||||||
} Tox_Err_Group_Mod_Kick_Peer;
|
} Tox_Err_Group_Mod_Kick_Peer;
|
||||||
|
|
||||||
|
const char *tox_err_group_mod_kick_peer_to_string(Tox_Err_Group_Mod_Kick_Peer value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kick a peer.
|
* Kick a peer.
|
||||||
@ -5427,6 +5568,8 @@ typedef enum Tox_Group_Mod_Event {
|
|||||||
|
|
||||||
} Tox_Group_Mod_Event;
|
} Tox_Group_Mod_Event;
|
||||||
|
|
||||||
|
const char *tox_group_mod_event_to_string(Tox_Group_Mod_Event value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param group_number The group number of the group the event is intended for.
|
* @param group_number The group number of the group the event is intended for.
|
||||||
|
1394
external/toxcore/c-toxcore/toxcore/tox_api.c
vendored
1394
external/toxcore/c-toxcore/toxcore/tox_api.c
vendored
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user