Squashed 'external/toxcore/c-toxcore/' changes from 1701691d5..640e6cace

640e6cace fix(toxav): remove extra copy of video frame on encode Tested and works, but there might be alignment issues and other stuff.
6f7f51554 chore(toxav): use realtime deadline for vp8 encoder Technically all this does is choose a quality based on frame duration, which we always set to 1, and as such is always realtime. (In same timebase as pts, which we use as a frame counter...)
5047ae5a2 chore: make the source tarball exhibit the old behavior
14804a4b8 chore: Fix sonar-scan CI action.
e2db7d946 cleanup: Exclude lan_discovery test from running on macos, instead of excluding it from the project.
3accade67 chore: Fix CI, disabling some tests that no longer run on CI.
ef8d767e6 cleanup: Fix comment formatting errors.
34ec822da cleanup: Fix some clang-19 format warnings.
40b3f0b46 refactor: Use clang's nullability qualifiers instead of attributes.
f81e30679 refactor: Use per-parameter nullability annotations.
REVERT: 1701691d5 chore(toxav): use realtime deadline for vp8 encoder Technically all this does is choose a quality based on frame duration, which we always set to 1, and as such is always realtime. (In same timebase as pts, which we use as a frame counter...)
REVERT: a87505867 fix(toxav): remove extra copy of video frame on encode Tested and works, but there might be alignment issues and other stuff.

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: 640e6cace81b4412c45977b94eb9c41e53c54035
This commit is contained in:
Green Sky
2025-10-08 12:03:02 +02:00
parent ab12fbe820
commit 54c0a3c874
195 changed files with 3148 additions and 5495 deletions

View File

@@ -125,15 +125,12 @@ jobs:
cimple: cimple:
working_directory: /tmp/cirrus-ci-build working_directory: /tmp/cirrus-ci-build
docker: docker:
- image: toxchat/toktok-stack:latest-release - image: toxchat/toktok-stack:latest
steps: steps:
- checkout - checkout
- run: git submodule update --init --recursive - run:
- run: /src/workspace/tools/inject-repo c-toxcore CIRCLE_JOB=release bash <(curl -s https://raw.githubusercontent.com/TokTok/ci-tools/refs/heads/master/tools/circleci-bazel-test)
- run: cd /src/workspace &&
bazel test
-k
--build_tag_filters=haskell --build_tag_filters=haskell
--test_tag_filters=haskell --test_tag_filters=haskell
-- --

View File

@@ -23,6 +23,7 @@ add_flag -Werror
# C99-only compilers we test against anyway. Anything that passes all the # C99-only compilers we test against anyway. Anything that passes all the
# compilers we use is fine. # compilers we use is fine.
add_c_flag -Wno-c11-extensions add_c_flag -Wno-c11-extensions
add_c_flag -Wno-pre-c11-compat
cmake -B_build -H. \ cmake -B_build -H. \
-DCMAKE_C_FLAGS="$C_FLAGS" \ -DCMAKE_C_FLAGS="$C_FLAGS" \
@@ -39,6 +40,9 @@ cmake -B_build -H. \
cd _build # pushd cd _build # pushd
make "-j$NPROC" -k install make "-j$NPROC" -k install
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6 ||
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6 # TODO(iphydf): Investigate if we can get lan discovery to work on macos CI.
# It works, but CI doesn't let us press the "allow broadcast" button.
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6 -E lan_discovery ||
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6 -E lan_discovery
cd - # popd cd - # popd

View File

@@ -9,6 +9,11 @@ add_flag -Weverything
# Disable specific warning flags for both C and C++. # Disable specific warning flags for both C and C++.
# We're not checking nullability, yet.
# TODO(iphydf): Remove.
add_flag -Wno-nullable-to-nonnull-conversion
add_flag -Wno-nullability-completeness
# Very verbose, not very useful. This warns about things like int -> uint # Very verbose, not very useful. This warns about things like int -> uint
# conversions that change sign without a cast and narrowing conversions. # conversions that change sign without a cast and narrowing conversions.
add_flag -Wno-conversion add_flag -Wno-conversion
@@ -30,6 +35,8 @@ add_flag -Wno-missing-braces
add_flag -Wno-missing-field-initializers add_flag -Wno-missing-field-initializers
# We don't use this attribute. It appears in the non-NDEBUG stderr logger. # We don't use this attribute. It appears in the non-NDEBUG stderr logger.
add_flag -Wno-missing-noreturn add_flag -Wno-missing-noreturn
# We want to use this extension.
add_flag -Wno-nullability-extension
# Useful sometimes, but we accept padding in structs for clarity. # Useful sometimes, but we accept padding in structs for clarity.
# Reordering fields to avoid padding will reduce readability. # Reordering fields to avoid padding will reduce readability.
add_flag -Wno-padded add_flag -Wno-padded

View File

@@ -17,6 +17,7 @@ add_ld_flag -Wl,-z,defs
add_flag -Werror add_flag -Werror
cmake -B_build -H. -GNinja \ cmake -B_build -H. -GNinja \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_C_FLAGS="$C_FLAGS" \ -DCMAKE_C_FLAGS="$C_FLAGS" \
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \ -DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
-DCMAKE_EXE_LINKER_FLAGS="$LD_FLAGS" \ -DCMAKE_EXE_LINKER_FLAGS="$LD_FLAGS" \

View File

@@ -72,7 +72,7 @@ jobs:
build-windows-msvc: build-windows-msvc:
strategy: strategy:
matrix: matrix:
version: [2019, 2022] version: [2022, 2025]
runs-on: windows-${{ matrix.version }} runs-on: windows-${{ matrix.version }}
env: env:
VCPKG_ROOT: "C:/vcpkg" VCPKG_ROOT: "C:/vcpkg"
@@ -116,12 +116,12 @@ jobs:
libopus libopus
libsodium libsodium
libvpx libvpx
ninja ninja-build
pkg-config pkg-config
run: | run: |
# TODO(iphydf): Investigate NetBSD failures on these tests. # TODO(iphydf): Investigate NetBSD failures on these tests.
sed -Ei -e '/\((TCP|dht_nodes_response_api)\)/s/^/#/' auto_tests/CMakeLists.txt sed -Ei -e '/\((TCP|dht_nodes_response_api|tcp_relay)\)/s/^/#/' auto_tests/CMakeLists.txt
cmake . \ cmake . \
-DMIN_LOGGER_LEVEL=TRACE \ -DMIN_LOGGER_LEVEL=TRACE \
-DMUST_BUILD_TOXAV=ON \ -DMUST_BUILD_TOXAV=ON \

View File

@@ -345,14 +345,12 @@ jobs:
uses: TokTok/ci-tools/.github/workflows/deploy-artifact.yml@master uses: TokTok/ci-tools/.github/workflows/deploy-artifact.yml@master
with: with:
project-name: toxcore project-name: toxcore
artifact-source: tox-*.tar.{gz,xz} artifact-source: toxcore.tar.{gz,xz}
artifact-versioned: $VERSION.tar.{gz,xz} artifact-versioned: c-toxcore-$VERSION.tar.{gz,xz}
build: tarball build: tarball
run: | run: |
sudo apt-get install -y --no-install-recommends libsodium-dev sudo apt-get install -y --no-install-recommends libsodium-dev
autoreconf -fi autoreconf -fi
./configure touch toxcore.tar.gz # prevent error of file changes
make dist tar --exclude-vcs --exclude='toxcore.tar.gz' --exclude='third_party/ci-tools' --exclude='*.github' --exclude='autom4te.cache' -zcvf toxcore.tar.gz .
for f in tox-*.tar.gz; do gunzip -c toxcore.tar.gz | xz -z - >"toxcore.tar.xz"
gunzip -c "$f" | xz -z - >"${f%.gz}.xz"
done

View File

@@ -8,50 +8,34 @@ on:
# Cancel old PR builds when pushing new commits. # Cancel old PR builds when pushing new commits.
concurrency: concurrency:
group: scan-${{ github.event.pull_request.number || github.ref }} group: sonar-scan-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true cancel-in-progress: true
jobs: jobs:
sonar-scan: sonar-scan:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
SONAR_SCANNER_VERSION: 5.0.1.3006
SONAR_SERVER_URL: "https://sonarcloud.io"
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
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 17 - name: Install Build Wrapper
uses: actions/setup-java@v2 uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v6
with:
distribution: "zulu"
java-version: 17
- name: Download and set up sonar-scanner
env:
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
run: |
mkdir -p $HOME/.sonar
curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }}
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH
- name: Download and set up build-wrapper
env:
BUILD_WRAPPER_DOWNLOAD_URL: ${{ env.SONAR_SERVER_URL }}/static/cpp/build-wrapper-linux-x86.zip
run: |
curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }}
unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH
- name: Install dependencies and prepare build - name: Install dependencies and prepare build
run: | run: |
.github/scripts/sonar-prepare .github/scripts/sonar-prepare
- name: Run build-wrapper - name: Run Build Wrapper
run: | run: |
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} .github/scripts/sonar-build build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} .github/scripts/sonar-build
- name: Run sonar-scanner - name: Ensure compile_commands.json is generated
run: ls -l "${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"
- name: SonarQube Scan
if: github.event_name == 'push' if: github.event_name == 'push'
uses: SonarSource/sonarqube-scan-action@v6
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: 'sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"' with:
args: >
--define "sonar.cfamily.compile-commands=${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"

View File

@@ -544,8 +544,8 @@ static void test_client(void)
// The connection status should be unconfirmed here because we have finished // The connection status should be unconfirmed here because we have finished
// sending our data and are awaiting a response. // sending our data and are awaiting a response.
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_UNCONFIRMED, "Wrong connection status. Expected: %d, is: %d.", ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_UNCONFIRMED, "Wrong connection status. Expected: %u, is: %u.",
TCP_CLIENT_UNCONFIRMED, tcp_con_status(conn)); (unsigned int)TCP_CLIENT_UNCONFIRMED, tcp_con_status(conn));
do_tcp_server_delay(tcp_s, mono_time, 50); // Now let the server handle requests... do_tcp_server_delay(tcp_s, mono_time, 50); // Now let the server handle requests...
@@ -556,8 +556,8 @@ static void test_client(void)
do_tcp_connection(logger, mono_time, conn, nullptr); // Run the connection loop. do_tcp_connection(logger, mono_time, conn, nullptr); // Run the connection loop.
// The status of the connection should continue to be TCP_CLIENT_CONFIRMED after multiple subsequent do_tcp_connection() calls. // The status of the connection should continue to be TCP_CLIENT_CONFIRMED after multiple subsequent do_tcp_connection() calls.
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONFIRMED, "Wrong connection status. Expected: %d, is: %d", ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONFIRMED, "Wrong connection status. Expected: %u, is: %u",
TCP_CLIENT_CONFIRMED, tcp_con_status(conn)); (unsigned int)TCP_CLIENT_CONFIRMED, tcp_con_status(conn));
c_sleep(i == loop_size - 1 ? 0 : 500); // Sleep for 500ms on all except third loop. c_sleep(i == loop_size - 1 ? 0 : 500); // Sleep for 500ms on all except third loop.
} }
@@ -565,7 +565,7 @@ static void test_client(void)
do_tcp_server_delay(tcp_s, mono_time, 50); do_tcp_server_delay(tcp_s, mono_time, 50);
// And still after the server runs again. // And still after the server runs again.
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %d, is: %d", TCP_CLIENT_CONFIRMED, ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", (unsigned int)TCP_CLIENT_CONFIRMED,
tcp_con_status(conn)); tcp_con_status(conn));
uint8_t f2_public_key[CRYPTO_PUBLIC_KEY_SIZE]; uint8_t f2_public_key[CRYPTO_PUBLIC_KEY_SIZE];
@@ -680,20 +680,20 @@ static void test_client_invalid(void)
c_sleep(50); c_sleep(50);
// After 50ms of no response... // After 50ms of no response...
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %d, is: %d.", ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %u, is: %u.",
TCP_CLIENT_CONNECTING, tcp_con_status(conn)); (unsigned int)TCP_CLIENT_CONNECTING, tcp_con_status(conn));
// After 5s... // After 5s...
c_sleep(5000); c_sleep(5000);
mono_time_update(mono_time); mono_time_update(mono_time);
do_tcp_connection(logger, mono_time, conn, nullptr); do_tcp_connection(logger, mono_time, conn, nullptr);
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %d, is: %d.", ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %u, is: %u.",
TCP_CLIENT_CONNECTING, tcp_con_status(conn)); (unsigned int)TCP_CLIENT_CONNECTING, tcp_con_status(conn));
// 11s... (Should wait for 10 before giving up.) // 11s... (Should wait for 10 before giving up.)
c_sleep(6000); c_sleep(6000);
mono_time_update(mono_time); mono_time_update(mono_time);
do_tcp_connection(logger, mono_time, conn, nullptr); do_tcp_connection(logger, mono_time, conn, nullptr);
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %d, is: %d.", ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %u, is: %u.",
TCP_CLIENT_DISCONNECTED, tcp_con_status(conn)); (unsigned int)TCP_CLIENT_DISCONNECTED, tcp_con_status(conn));
kill_tcp_connection(conn); kill_tcp_connection(conn);

View File

@@ -79,14 +79,14 @@ void bootstrap_tox_live_network(Tox *tox, bool enable_tcp)
tox_bootstrap(tox, ip, port, key, &err); tox_bootstrap(tox, ip, port, key, &err);
if (err != TOX_ERR_BOOTSTRAP_OK) { if (err != TOX_ERR_BOOTSTRAP_OK) {
fprintf(stderr, "Failed to bootstrap node %zu (%s): error %d\n", j, ip, err); fprintf(stderr, "Failed to bootstrap node %zu (%s): error %u\n", j, ip, err);
} }
if (enable_tcp) { if (enable_tcp) {
tox_add_tcp_relay(tox, ip, port, key, &err); tox_add_tcp_relay(tox, ip, port, key, &err);
if (err != TOX_ERR_BOOTSTRAP_OK) { if (err != TOX_ERR_BOOTSTRAP_OK) {
fprintf(stderr, "Failed to add TCP relay %zu (%s): error %d\n", j, ip, err); fprintf(stderr, "Failed to add TCP relay %zu (%s): error %u\n", j, ip, err);
} }
} }
} }
@@ -247,7 +247,7 @@ static void initialise_autotox(struct Tox_Options *options, AutoTox *autotox, ui
tox_options_set_tcp_port(options, 0); tox_options_set_tcp_port(options, 0);
autotest_opts->tcp_port = 0; autotest_opts->tcp_port = 0;
autotox->tox = tox_new_log(options, &err, &autotox->index); autotox->tox = tox_new_log(options, &err, &autotox->index);
ck_assert_msg(err == TOX_ERR_NEW_OK, "unexpected tox_new error: %d", err); ck_assert_msg(err == TOX_ERR_NEW_OK, "unexpected tox_new error: %u", err);
} else { } else {
// Try a few ports for the TCP relay. // Try a few ports for the TCP relay.
for (uint16_t tcp_port = autotest_opts->tcp_port; tcp_port < autotest_opts->tcp_port + 200; ++tcp_port) { for (uint16_t tcp_port = autotest_opts->tcp_port; tcp_port < autotest_opts->tcp_port + 200; ++tcp_port) {
@@ -259,7 +259,7 @@ static void initialise_autotox(struct Tox_Options *options, AutoTox *autotox, ui
break; break;
} }
ck_assert_msg(err == TOX_ERR_NEW_PORT_ALLOC, "unexpected tox_new error (expected PORT_ALLOC): %d", err); ck_assert_msg(err == TOX_ERR_NEW_PORT_ALLOC, "unexpected tox_new error (expected PORT_ALLOC): %u", err);
} }
} }
@@ -273,7 +273,7 @@ static void initialise_autotox(struct Tox_Options *options, AutoTox *autotox, ui
autotox->tox = tox_new_log(options, &err, &autotox->index); autotox->tox = tox_new_log(options, &err, &autotox->index);
} }
ck_assert_msg(autotox->tox != nullptr, "failed to create tox instance #%u (error = %d)", index, err); ck_assert_msg(autotox->tox != nullptr, "failed to create tox instance #%u (error = %u)", index, err);
set_mono_time_callback(autotox); set_mono_time_callback(autotox);
@@ -348,7 +348,7 @@ static void bootstrap_autotoxes(const Tox_Options *options, uint32_t tox_count,
for (uint32_t i = 1; i < tox_count; ++i) { for (uint32_t i = 1; i < tox_count; ++i) {
Tox_Err_Bootstrap err; Tox_Err_Bootstrap err;
tox_bootstrap(autotoxes[i].tox, "localhost", dht_port, dht_key, &err); tox_bootstrap(autotoxes[i].tox, "localhost", dht_port, dht_key, &err);
ck_assert_msg(err == TOX_ERR_BOOTSTRAP_OK, "bootstrap error for port %d: %d", dht_port, err); ck_assert_msg(err == TOX_ERR_BOOTSTRAP_OK, "bootstrap error for port %d: %u", dht_port, err);
} }
if (!udp_enabled) { if (!udp_enabled) {

View File

@@ -25,8 +25,8 @@ int main(void)
const Tox_Connection status = tox_self_get_connection_status(tox_udp); const Tox_Connection status = tox_self_get_connection_status(tox_udp);
ck_assert_msg(status == TOX_CONNECTION_UDP, ck_assert_msg(status == TOX_CONNECTION_UDP,
"expected connection status to be UDP, but got %d", status); "expected connection status to be UDP, but got %u", status);
printf("Connection (UDP): %d\n", tox_self_get_connection_status(tox_udp)); printf("Connection (UDP): %u\n", tox_self_get_connection_status(tox_udp));
tox_kill(tox_udp); tox_kill(tox_udp);

View File

@@ -83,7 +83,7 @@ static void handle_conference_invite(
const uint8_t *cookie = tox_event_conference_invite_get_cookie(event); const uint8_t *cookie = tox_event_conference_invite_get_cookie(event);
const size_t length = tox_event_conference_invite_get_cookie_length(event); const size_t length = tox_event_conference_invite_get_cookie_length(event);
ck_assert_msg(type == TOX_CONFERENCE_TYPE_AV, "tox #%u: wrong conference type: %d", autotox->index, type); ck_assert_msg(type == TOX_CONFERENCE_TYPE_AV, "tox #%u: wrong conference type: %u", autotox->index, type);
ck_assert_msg(toxav_join_av_groupchat(autotox->tox, friend_number, cookie, length, audio_callback, user_data) == 0, ck_assert_msg(toxav_join_av_groupchat(autotox->tox, friend_number, cookie, length, audio_callback, user_data) == 0,
"tox #%u: failed to join group", autotox->index); "tox #%u: failed to join group", autotox->index);
@@ -101,7 +101,7 @@ static void handle_conference_connected(
Tox_Err_Conference_Invite err; Tox_Err_Conference_Invite err;
tox_conference_invite(autotox->tox, 1, 0, &err); tox_conference_invite(autotox->tox, 1, 0, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox #%u failed to invite next friend: err = %d", autotox->index, ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox #%u failed to invite next friend: err = %u", autotox->index,
err); err);
printf("tox #%u: invited next friend\n", autotox->index); printf("tox #%u: invited next friend\n", autotox->index);
state->invited_next = true; state->invited_next = true;

View File

@@ -22,7 +22,7 @@ static void handle_conference_invite(
const uint8_t *cookie = tox_event_conference_invite_get_cookie(event); const uint8_t *cookie = tox_event_conference_invite_get_cookie(event);
const size_t length = tox_event_conference_invite_get_cookie_length(event); const size_t length = tox_event_conference_invite_get_cookie_length(event);
fprintf(stderr, "handle_conference_invite(#%u, %u, %d, uint8_t[%u], _)\n", fprintf(stderr, "handle_conference_invite(#%u, %u, %u, uint8_t[%u], _)\n",
autotox->index, friend_number, type, (unsigned)length); autotox->index, friend_number, type, (unsigned)length);
fprintf(stderr, "tox%u joining conference\n", autotox->index); fprintf(stderr, "tox%u joining conference\n", autotox->index);
@@ -32,7 +32,7 @@ static void handle_conference_invite(
Tox_Err_Conference_Join err; Tox_Err_Conference_Join err;
state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err); state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK,
"attempting to join the conference returned with an error: %d", err); "attempting to join the conference returned with an error: %u", err);
fprintf(stderr, "tox%u joined conference %u\n", autotox->index, state->conference); fprintf(stderr, "tox%u joined conference %u\n", autotox->index, state->conference);
state->joined = true; state->joined = true;
} }
@@ -54,7 +54,7 @@ static void conference_double_invite_test(AutoTox *autotoxes)
state[0]->conference = tox_conference_new(autotoxes[0].tox, &err); state[0]->conference = tox_conference_new(autotoxes[0].tox, &err);
state[0]->joined = true; state[0]->joined = true;
ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK,
"attempting to create a new conference returned with an error: %d", err); "attempting to create a new conference returned with an error: %u", err);
fprintf(stderr, "Created conference: index=%u\n", state[0]->conference); fprintf(stderr, "Created conference: index=%u\n", state[0]->conference);
} }
@@ -63,7 +63,7 @@ static void conference_double_invite_test(AutoTox *autotoxes)
Tox_Err_Conference_Invite err; Tox_Err_Conference_Invite err;
tox_conference_invite(autotoxes[0].tox, 0, state[0]->conference, &err); tox_conference_invite(autotoxes[0].tox, 0, state[0]->conference, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK,
"attempting to invite a friend returned with an error: %d", err); "attempting to invite a friend returned with an error: %u", err);
fprintf(stderr, "tox0 invited tox1\n"); fprintf(stderr, "tox0 invited tox1\n");
} }

View File

@@ -25,7 +25,7 @@ static void handle_conference_invite(
Tox_Err_Conference_Join err; Tox_Err_Conference_Join err;
state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err); state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK,
"attempting to join the conference returned with an error: %d", err); "attempting to join the conference returned with an error: %u", err);
fprintf(stderr, "#%u accepted invite to conference %u\n", autotox->index, state->conference); fprintf(stderr, "#%u accepted invite to conference %u\n", autotox->index, state->conference);
} }
} }
@@ -54,7 +54,7 @@ static void do_invite(AutoTox *autotoxes, AutoTox *inviter, AutoTox *invitee, ui
Tox_Err_Conference_Invite err; Tox_Err_Conference_Invite err;
tox_conference_invite(inviter->tox, friendnum, ((State *)inviter->state)->conference, &err); tox_conference_invite(inviter->tox, friendnum, ((State *)inviter->state)->conference, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK,
"#%u attempting to invite #%u (friendnumber %u) returned with an error: %d", inviter->index, invitee->index, "#%u attempting to invite #%u (friendnumber %u) returned with an error: %u", inviter->index, invitee->index,
friendnum, err); friendnum, err);
do { do {
@@ -110,7 +110,7 @@ static void conference_invite_merge_test(AutoTox *autotoxes)
state2->conference = tox_conference_new(autotoxes[2].tox, &err); state2->conference = tox_conference_new(autotoxes[2].tox, &err);
state2->connected = true; state2->connected = true;
ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK,
"attempting to create a new conference returned with an error: %d", err); "attempting to create a new conference returned with an error: %u", err);
fprintf(stderr, "Created conference: index=%u\n", state2->conference); fprintf(stderr, "Created conference: index=%u\n", state2->conference);
} }

View File

@@ -23,14 +23,14 @@ static void handle_conference_invite(
const uint8_t *cookie = tox_event_conference_invite_get_cookie(event); const uint8_t *cookie = tox_event_conference_invite_get_cookie(event);
const size_t length = tox_event_conference_invite_get_cookie_length(event); const size_t length = tox_event_conference_invite_get_cookie_length(event);
fprintf(stderr, "handle_conference_invite(#%u, %u, %d, uint8_t[%u], _)\n", fprintf(stderr, "handle_conference_invite(#%u, %u, %u, uint8_t[%u], _)\n",
autotox->index, friend_number, type, (unsigned)length); autotox->index, friend_number, type, (unsigned)length);
fprintf(stderr, "tox%u joining conference\n", autotox->index); fprintf(stderr, "tox%u joining conference\n", autotox->index);
Tox_Err_Conference_Join err; Tox_Err_Conference_Join err;
state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err); state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK,
"attempting to join the conference returned with an error: %d", err); "attempting to join the conference returned with an error: %u", err);
fprintf(stderr, "tox%u joined conference %u\n", autotox->index, state->conference); fprintf(stderr, "tox%u joined conference %u\n", autotox->index, state->conference);
state->joined = true; state->joined = true;
} }
@@ -47,7 +47,7 @@ static void handle_peer_list_changed(const Tox_Event_Conference_Peer_List_Change
Tox_Err_Conference_Peer_Query err; Tox_Err_Conference_Peer_Query err;
uint32_t const count = tox_conference_peer_count(autotox->tox, conference_number, &err); uint32_t const count = tox_conference_peer_count(autotox->tox, conference_number, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK, ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
"failed to get conference peer count: err = %d", err); "failed to get conference peer count: err = %u", err);
printf("tox%u has %u peers\n", autotox->index, count); printf("tox%u has %u peers\n", autotox->index, count);
state->friend_in_group = count == 2; state->friend_in_group = count == 2;
} }
@@ -60,18 +60,18 @@ static void rebuild_peer_list(Tox *tox)
Tox_Err_Conference_Peer_Query err; Tox_Err_Conference_Peer_Query err;
uint32_t const count = tox_conference_peer_count(tox, conference_number, &err); uint32_t const count = tox_conference_peer_count(tox, conference_number, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK, ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
"failed to get conference peer count for conference %u: err = %d", conference_number, err); "failed to get conference peer count for conference %u: err = %u", conference_number, err);
for (uint32_t peer_number = 0; peer_number < count; peer_number++) { for (uint32_t peer_number = 0; peer_number < count; peer_number++) {
size_t size = tox_conference_peer_get_name_size(tox, conference_number, peer_number, &err); size_t size = tox_conference_peer_get_name_size(tox, conference_number, peer_number, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK, ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
"failed to get conference peer %u's name size (conference = %u): err = %d", peer_number, conference_number, err); "failed to get conference peer %u's name size (conference = %u): err = %u", peer_number, conference_number, err);
uint8_t *const name = (uint8_t *)malloc(size); uint8_t *const name = (uint8_t *)malloc(size);
ck_assert(name != nullptr); ck_assert(name != nullptr);
tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err); tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK, ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
"failed to get conference peer %u's name (conference = %u): err = %d", peer_number, conference_number, err); "failed to get conference peer %u's name (conference = %u): err = %u", peer_number, conference_number, err);
free(name); free(name);
} }
} }
@@ -99,7 +99,7 @@ static void conference_peer_nick_test(AutoTox *autotoxes)
state[0]->conference = tox_conference_new(autotoxes[0].tox, &err); state[0]->conference = tox_conference_new(autotoxes[0].tox, &err);
state[0]->joined = true; state[0]->joined = true;
ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK,
"attempting to create a new conference returned with an error: %d", err); "attempting to create a new conference returned with an error: %u", err);
fprintf(stderr, "Created conference: index=%u\n", state[0]->conference); fprintf(stderr, "Created conference: index=%u\n", state[0]->conference);
} }
@@ -108,7 +108,7 @@ static void conference_peer_nick_test(AutoTox *autotoxes)
Tox_Err_Conference_Invite err; Tox_Err_Conference_Invite err;
tox_conference_invite(autotoxes[0].tox, 0, state[0]->conference, &err); tox_conference_invite(autotoxes[0].tox, 0, state[0]->conference, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK,
"attempting to invite a friend returned with an error: %d", err); "attempting to invite a friend returned with an error: %u", err);
fprintf(stderr, "tox0 invited tox1\n"); fprintf(stderr, "tox0 invited tox1\n");
} }

View File

@@ -28,7 +28,7 @@ static void handle_self_connection_status(const Tox_Event_Self_Connection_Status
State *state = (State *)user_data; State *state = (State *)user_data;
const Tox_Connection connection_status = tox_event_self_connection_status_get_connection_status(event); const Tox_Connection connection_status = tox_event_self_connection_status_get_connection_status(event);
fprintf(stderr, "self_connection_status(#%u, %d, _)\n", state->id, connection_status); fprintf(stderr, "self_connection_status(#%u, %u, _)\n", state->id, connection_status);
state->self_online = connection_status != TOX_CONNECTION_NONE; state->self_online = connection_status != TOX_CONNECTION_NONE;
} }
@@ -39,7 +39,7 @@ static void handle_friend_connection_status(const Tox_Event_Friend_Connection_St
const uint32_t friend_number = tox_event_friend_connection_status_get_friend_number(event); const uint32_t friend_number = tox_event_friend_connection_status_get_friend_number(event);
const Tox_Connection connection_status = tox_event_friend_connection_status_get_connection_status(event); const Tox_Connection connection_status = tox_event_friend_connection_status_get_connection_status(event);
fprintf(stderr, "handle_friend_connection_status(#%u, %u, %d, _)\n", state->id, friend_number, connection_status); fprintf(stderr, "handle_friend_connection_status(#%u, %u, %u, _)\n", state->id, friend_number, connection_status);
state->friend_online = connection_status != TOX_CONNECTION_NONE; state->friend_online = connection_status != TOX_CONNECTION_NONE;
} }
@@ -51,14 +51,14 @@ static void handle_conference_invite(const Tox_Event_Conference_Invite *event, v
const Tox_Conference_Type type = tox_event_conference_invite_get_type(event); const Tox_Conference_Type type = tox_event_conference_invite_get_type(event);
const uint8_t *cookie = tox_event_conference_invite_get_cookie(event); const uint8_t *cookie = tox_event_conference_invite_get_cookie(event);
const size_t length = tox_event_conference_invite_get_cookie_length(event); const size_t length = tox_event_conference_invite_get_cookie_length(event);
fprintf(stderr, "handle_conference_invite(#%u, %u, %d, uint8_t[%u], _)\n", fprintf(stderr, "handle_conference_invite(#%u, %u, %u, uint8_t[%u], _)\n",
state->id, friend_number, type, (unsigned)length); state->id, friend_number, type, (unsigned)length);
fprintf(stderr, "tox%u joining conference\n", state->id); fprintf(stderr, "tox%u joining conference\n", state->id);
{ {
Tox_Err_Conference_Join err; Tox_Err_Conference_Join err;
state->conference = tox_conference_join(state->tox, friend_number, cookie, length, &err); state->conference = tox_conference_join(state->tox, friend_number, cookie, length, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "failed to join a conference: err = %d", err); ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "failed to join a conference: err = %u", err);
fprintf(stderr, "tox%u Joined conference %u\n", state->id, state->conference); fprintf(stderr, "tox%u Joined conference %u\n", state->id, state->conference);
state->joined = true; state->joined = true;
} }
@@ -74,7 +74,7 @@ static void handle_conference_message(const Tox_Event_Conference_Message *event,
const uint8_t *message = tox_event_conference_message_get_message(event); const uint8_t *message = tox_event_conference_message_get_message(event);
const size_t length = tox_event_conference_message_get_message_length(event); const size_t length = tox_event_conference_message_get_message_length(event);
fprintf(stderr, "handle_conference_message(#%u, %u, %u, %d, uint8_t[%u], _)\n", fprintf(stderr, "handle_conference_message(#%u, %u, %u, %u, uint8_t[%u], _)\n",
state->id, conference_number, peer_number, type, (unsigned)length); state->id, conference_number, peer_number, type, (unsigned)length);
fprintf(stderr, "tox%u got message: %s\n", state->id, (const char *)message); fprintf(stderr, "tox%u got message: %s\n", state->id, (const char *)message);
@@ -93,7 +93,7 @@ static void handle_conference_peer_list_changed(const Tox_Event_Conference_Peer_
uint32_t count = tox_conference_peer_count(state->tox, conference_number, &err); uint32_t count = tox_conference_peer_count(state->tox, conference_number, &err);
if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) { if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
fprintf(stderr, "ERROR: %d\n", err); fprintf(stderr, "ERROR: %u\n", err);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@@ -109,7 +109,7 @@ static void handle_conference_connected(const Tox_Event_Conference_Connected *ev
if (state->id == 2 && !state->invited_next) { if (state->id == 2 && !state->invited_next) {
Tox_Err_Conference_Invite err; Tox_Err_Conference_Invite err;
tox_conference_invite(state->tox, 1, state->conference, &err); tox_conference_invite(state->tox, 1, state->conference, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox2 failed to invite tox3: err = %d", err); ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox2 failed to invite tox3: err = %u", err);
state->invited_next = true; state->invited_next = true;
fprintf(stderr, "tox2 invited tox3\n"); fprintf(stderr, "tox2 invited tox3\n");
@@ -209,7 +209,7 @@ int main(void)
Tox_Err_Conference_New err; Tox_Err_Conference_New err;
state1.conference = tox_conference_new(state1.tox, &err); state1.conference = tox_conference_new(state1.tox, &err);
state1.joined = true; state1.joined = true;
ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create a conference: err = %d", err); ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create a conference: err = %u", err);
fprintf(stderr, "Created conference: id = %u\n", state1.conference); fprintf(stderr, "Created conference: id = %u\n", state1.conference);
} }
@@ -217,7 +217,7 @@ int main(void)
// Invite friend. // Invite friend.
Tox_Err_Conference_Invite err; Tox_Err_Conference_Invite err;
tox_conference_invite(state1.tox, 0, state1.conference, &err); tox_conference_invite(state1.tox, 0, state1.conference, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "failed to invite a friend: err = %d", err); ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "failed to invite a friend: err = %u", err);
state1.invited_next = true; state1.invited_next = true;
fprintf(stderr, "tox1 invited tox2\n"); fprintf(stderr, "tox1 invited tox2\n");
} }
@@ -245,7 +245,7 @@ int main(void)
(const uint8_t *)"hello!", 7, &err); (const uint8_t *)"hello!", 7, &err);
if (err != TOX_ERR_CONFERENCE_SEND_MESSAGE_OK) { if (err != TOX_ERR_CONFERENCE_SEND_MESSAGE_OK) {
fprintf(stderr, "ERROR: %d\n", err); fprintf(stderr, "ERROR: %u\n", err);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }

View File

@@ -53,12 +53,12 @@ static void handle_conference_invite(
const uint8_t *data, size_t length, void *user_data) const uint8_t *data, size_t length, void *user_data)
{ {
const AutoTox *autotox = (AutoTox *)user_data; const AutoTox *autotox = (AutoTox *)user_data;
ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%u: wrong conference type: %d", autotox->index, type); ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%u: wrong conference type: %u", autotox->index, type);
Tox_Err_Conference_Join err; Tox_Err_Conference_Join err;
uint32_t g_num = tox_conference_join(autotox->tox, friendnumber, data, length, &err); uint32_t g_num = tox_conference_join(autotox->tox, friendnumber, data, length, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "tox #%u: error joining group: %d", autotox->index, err); ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "tox #%u: error joining group: %u", autotox->index, err);
ck_assert_msg(g_num == 0, "tox #%u: group number was not 0", autotox->index); ck_assert_msg(g_num == 0, "tox #%u: group number was not 0", autotox->index);
// Try joining again. We should only be allowed to join once. // Try joining again. We should only be allowed to join once.
@@ -79,7 +79,7 @@ static void handle_conference_connected(
Tox_Err_Conference_Invite err; Tox_Err_Conference_Invite err;
tox_conference_invite(autotox->tox, 1, 0, &err); tox_conference_invite(autotox->tox, 1, 0, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox #%u failed to invite next friend: err = %d", autotox->index, ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox #%u failed to invite next friend: err = %u", autotox->index,
err); err);
printf("tox #%u: invited next friend\n", autotox->index); printf("tox #%u: invited next friend\n", autotox->index);
state->invited_next = true; state->invited_next = true;
@@ -206,7 +206,7 @@ static void run_conference_tests(AutoTox *autotoxes)
Tox_Err_Conference_Set_Max_Offline err; Tox_Err_Conference_Set_Max_Offline err;
tox_conference_set_max_offline(autotoxes[i].tox, 0, max_frozen, &err); tox_conference_set_max_offline(autotoxes[i].tox, 0, max_frozen, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_SET_MAX_OFFLINE_OK, ck_assert_msg(err == TOX_ERR_CONFERENCE_SET_MAX_OFFLINE_OK,
"tox #%u failed to set max offline: err = %d", autotoxes[i].index, err); "tox #%u failed to set max offline: err = %u", autotoxes[i].index, err);
} }
printf("letting random toxes timeout\n"); printf("letting random toxes timeout\n");

View File

@@ -17,9 +17,9 @@ int main(void)
// Create two conferences and then exit. // Create two conferences and then exit.
Tox_Err_Conference_New err; Tox_Err_Conference_New err;
tox_conference_new(tox1, &err); tox_conference_new(tox1, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create conference 1: %d", err); ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create conference 1: %u", err);
tox_conference_new(tox1, &err); tox_conference_new(tox1, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create conference 2: %d", err); ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create conference 2: %u", err);
tox_kill(tox1); tox_kill(tox1);

View File

@@ -48,7 +48,7 @@ static void test_save_friend(void)
ck_assert(enc_data != nullptr); ck_assert(enc_data != nullptr);
Tox_Err_Encryption error1; Tox_Err_Encryption error1;
bool ret = tox_pass_encrypt(data, size, (const uint8_t *)"correcthorsebatterystaple", 25, enc_data, &error1); bool ret = tox_pass_encrypt(data, size, (const uint8_t *)"correcthorsebatterystaple", 25, enc_data, &error1);
ck_assert_msg(ret, "failed to encrypted save: %d", error1); ck_assert_msg(ret, "failed to encrypted save: %u", error1);
ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing"); ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing");
struct Tox_Options *options = tox_options_new(nullptr); struct Tox_Options *options = tox_options_new(nullptr);
@@ -58,17 +58,17 @@ static void test_save_friend(void)
Tox_Err_New err2; Tox_Err_New err2;
Tox *tox3 = tox_new_log(options, &err2, nullptr); Tox *tox3 = tox_new_log(options, &err2, nullptr);
ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %d. should fail with %d", err2, ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %d", err2,
TOX_ERR_NEW_LOAD_ENCRYPTED); (int)TOX_ERR_NEW_LOAD_ENCRYPTED);
ck_assert_msg(tox3 == nullptr, "tox_new with error should return NULL"); ck_assert_msg(tox3 == nullptr, "tox_new with error should return NULL");
uint8_t *dec_data = (uint8_t *)malloc(size); uint8_t *dec_data = (uint8_t *)malloc(size);
ck_assert(dec_data != nullptr); ck_assert(dec_data != nullptr);
Tox_Err_Decryption err3; Tox_Err_Decryption err3;
ret = tox_pass_decrypt(enc_data, size2, (const uint8_t *)"correcthorsebatterystaple", 25, dec_data, &err3); ret = tox_pass_decrypt(enc_data, size2, (const uint8_t *)"correcthorsebatterystaple", 25, dec_data, &err3);
ck_assert_msg(ret, "failed to decrypt save: %d", err3); ck_assert_msg(ret, "failed to decrypt save: %u", err3);
tox_options_set_savedata_data(options, dec_data, size); tox_options_set_savedata_data(options, dec_data, size);
tox3 = tox_new_log(options, &err2, nullptr); tox3 = tox_new_log(options, &err2, nullptr);
ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to load from decrypted data: %d", err2); ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to load from decrypted data: %u", err2);
uint8_t address2[TOX_PUBLIC_KEY_SIZE]; uint8_t address2[TOX_PUBLIC_KEY_SIZE];
ret = tox_friend_get_public_key(tox3, 0, address2, nullptr); ret = tox_friend_get_public_key(tox3, 0, address2, nullptr);
ck_assert_msg(ret, "no friends!"); ck_assert_msg(ret, "no friends!");
@@ -87,7 +87,7 @@ static void test_save_friend(void)
uint8_t *encdata2 = (uint8_t *)malloc(size2); uint8_t *encdata2 = (uint8_t *)malloc(size2);
ck_assert(encdata2 != nullptr); ck_assert(encdata2 != nullptr);
ret = tox_pass_key_encrypt(key, data2, size, encdata2, &error1); ret = tox_pass_key_encrypt(key, data2, size, encdata2, &error1);
ck_assert_msg(ret, "failed to key encrypt %d", error1); ck_assert_msg(ret, "failed to key encrypt %u", error1);
ck_assert_msg(tox_is_data_encrypted(encdata2), "magic number the second missing"); ck_assert_msg(tox_is_data_encrypted(encdata2), "magic number the second missing");
uint8_t *out1 = (uint8_t *)malloc(size); uint8_t *out1 = (uint8_t *)malloc(size);
@@ -95,9 +95,9 @@ static void test_save_friend(void)
uint8_t *out2 = (uint8_t *)malloc(size); uint8_t *out2 = (uint8_t *)malloc(size);
ck_assert(out2 != nullptr); ck_assert(out2 != nullptr);
ret = tox_pass_decrypt(encdata2, size2, (const uint8_t *)pw, pwlen, out1, &err3); ret = tox_pass_decrypt(encdata2, size2, (const uint8_t *)pw, pwlen, out1, &err3);
ck_assert_msg(ret, "failed to pw decrypt %d", err3); ck_assert_msg(ret, "failed to pw decrypt %u", err3);
ret = tox_pass_key_decrypt(key, encdata2, size2, out2, &err3); ret = tox_pass_key_decrypt(key, encdata2, size2, out2, &err3);
ck_assert_msg(ret, "failed to key decrypt %d", err3); ck_assert_msg(ret, "failed to key decrypt %u", err3);
ck_assert_msg(memcmp(out1, out2, size) == 0, "differing output data"); ck_assert_msg(memcmp(out1, out2, size) == 0, "differing output data");
// and now with the code in use (I only bothered with manually to debug this, and it seems a waste // and now with the code in use (I only bothered with manually to debug this, and it seems a waste
@@ -134,12 +134,12 @@ static void test_keys(void)
Tox_Err_Key_Derivation keyerr; Tox_Err_Key_Derivation keyerr;
const uint8_t *key_char = (const uint8_t *)"123qweasdzxc"; const uint8_t *key_char = (const uint8_t *)"123qweasdzxc";
Tox_Pass_Key *key = tox_pass_key_derive(key_char, 12, &keyerr); Tox_Pass_Key *key = tox_pass_key_derive(key_char, 12, &keyerr);
ck_assert_msg(key != nullptr, "generic failure 1: %d", keyerr); ck_assert_msg(key != nullptr, "generic failure 1: %u", keyerr);
const uint8_t *string = (const uint8_t *)"No Patrick, mayonnaise is not an instrument."; // 44 const uint8_t *string = (const uint8_t *)"No Patrick, mayonnaise is not an instrument."; // 44
uint8_t encrypted[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH]; uint8_t encrypted[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
bool ret = tox_pass_key_encrypt(key, string, 44, encrypted, &encerr); bool ret = tox_pass_key_encrypt(key, string, 44, encrypted, &encerr);
ck_assert_msg(ret, "generic failure 2: %d", encerr); ck_assert_msg(ret, "generic failure 2: %u", encerr);
// Testing how tox handles encryption of large messages. // Testing how tox handles encryption of large messages.
int size_large = 30 * 1024 * 1024; int size_large = 30 * 1024 * 1024;
@@ -153,13 +153,13 @@ static void test_keys(void)
ck_assert(rng != nullptr); ck_assert(rng != nullptr);
random_bytes(rng, in_plaintext2a, plaintext_length2a); random_bytes(rng, in_plaintext2a, plaintext_length2a);
ret = tox_pass_encrypt(in_plaintext2a, plaintext_length2a, key_char, 12, encrypted2a, &encerr); ret = tox_pass_encrypt(in_plaintext2a, plaintext_length2a, key_char, 12, encrypted2a, &encerr);
ck_assert_msg(ret, "tox_pass_encrypt failure 2a: %d", encerr); ck_assert_msg(ret, "tox_pass_encrypt failure 2a: %u", encerr);
// Decryption of same message. // Decryption of same message.
uint8_t *out_plaintext2a = (uint8_t *)malloc(plaintext_length2a); uint8_t *out_plaintext2a = (uint8_t *)malloc(plaintext_length2a);
ck_assert(out_plaintext2a != nullptr); ck_assert(out_plaintext2a != nullptr);
ret = tox_pass_decrypt(encrypted2a, ciphertext_length2a, key_char, 12, out_plaintext2a, &decerr); ret = tox_pass_decrypt(encrypted2a, ciphertext_length2a, key_char, 12, out_plaintext2a, &decerr);
ck_assert_msg(ret, "tox_pass_decrypt failure 2a: %d", decerr); ck_assert_msg(ret, "tox_pass_decrypt failure 2a: %u", decerr);
ck_assert_msg(memcmp(in_plaintext2a, out_plaintext2a, plaintext_length2a) == 0, "Large message decryption failed"); ck_assert_msg(memcmp(in_plaintext2a, out_plaintext2a, plaintext_length2a) == 0, "Large message decryption failed");
free(encrypted2a); free(encrypted2a);
free(in_plaintext2a); free(in_plaintext2a);
@@ -167,28 +167,28 @@ static void test_keys(void)
uint8_t encrypted2[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH]; uint8_t encrypted2[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
ret = tox_pass_encrypt(string, 44, key_char, 12, encrypted2, &encerr); ret = tox_pass_encrypt(string, 44, key_char, 12, encrypted2, &encerr);
ck_assert_msg(ret, "generic failure 3: %d", encerr); ck_assert_msg(ret, "generic failure 3: %u", encerr);
uint8_t out1[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH]; uint8_t out1[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
uint8_t out2[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH]; uint8_t out2[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
ret = tox_pass_key_decrypt(key, encrypted, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, out1, &decerr); ret = tox_pass_key_decrypt(key, encrypted, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, out1, &decerr);
ck_assert_msg(ret, "generic failure 4: %d", decerr); ck_assert_msg(ret, "generic failure 4: %u", decerr);
ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 1 failed"); ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 1 failed");
ret = tox_pass_decrypt(encrypted2, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)"123qweasdzxc", 12, out2, ret = tox_pass_decrypt(encrypted2, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)"123qweasdzxc", 12, out2,
&decerr); &decerr);
ck_assert_msg(ret, "generic failure 5: %d", decerr); ck_assert_msg(ret, "generic failure 5: %u", decerr);
ck_assert_msg(memcmp(out2, string, 44) == 0, "decryption 2 failed"); ck_assert_msg(memcmp(out2, string, 44) == 0, "decryption 2 failed");
ret = tox_pass_decrypt(encrypted2, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, nullptr, 0, out2, &decerr); ret = tox_pass_decrypt(encrypted2, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, nullptr, 0, out2, &decerr);
ck_assert_msg(!ret, "Decrypt succeeded with wrong pass"); ck_assert_msg(!ret, "Decrypt succeeded with wrong pass");
ck_assert_msg(decerr != TOX_ERR_DECRYPTION_FAILED, "Bad error code %d", decerr); ck_assert_msg(decerr != TOX_ERR_DECRYPTION_FAILED, "Bad error code %u", decerr);
// test that pass_decrypt can decrypt things from pass_key_encrypt // test that pass_decrypt can decrypt things from pass_key_encrypt
ret = tox_pass_decrypt(encrypted, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)"123qweasdzxc", 12, out1, ret = tox_pass_decrypt(encrypted, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)"123qweasdzxc", 12, out1,
&decerr); &decerr);
ck_assert_msg(ret, "generic failure 6: %d", decerr); ck_assert_msg(ret, "generic failure 6: %u", decerr);
ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 3 failed"); ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 3 failed");
uint8_t salt[TOX_PASS_SALT_LENGTH]; uint8_t salt[TOX_PASS_SALT_LENGTH];
@@ -196,7 +196,7 @@ static void test_keys(void)
ck_assert_msg(tox_get_salt(encrypted, salt, &salt_err), "couldn't get salt"); ck_assert_msg(tox_get_salt(encrypted, salt, &salt_err), "couldn't get salt");
ck_assert_msg(salt_err == TOX_ERR_GET_SALT_OK, "get_salt returned an error"); ck_assert_msg(salt_err == TOX_ERR_GET_SALT_OK, "get_salt returned an error");
Tox_Pass_Key *key2 = tox_pass_key_derive_with_salt((const uint8_t *)"123qweasdzxc", 12, salt, &keyerr); Tox_Pass_Key *key2 = tox_pass_key_derive_with_salt((const uint8_t *)"123qweasdzxc", 12, salt, &keyerr);
ck_assert_msg(key2 != nullptr, "generic failure 7: %d", keyerr); ck_assert_msg(key2 != nullptr, "generic failure 7: %u", keyerr);
ck_assert_msg(0 == memcmp(key, key2, TOX_PASS_KEY_LENGTH + TOX_PASS_SALT_LENGTH), "salt comparison failed"); ck_assert_msg(0 == memcmp(key, key2, TOX_PASS_KEY_LENGTH + TOX_PASS_SALT_LENGTH), "salt comparison failed");
tox_pass_key_free(key2); tox_pass_key_free(key2);
tox_pass_key_free(key); tox_pass_key_free(key);

View File

@@ -54,7 +54,7 @@ static void save_data_encrypted(void)
ck_assert_msg(tox_pass_encrypt(clear, size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)pphrase, ck_assert_msg(tox_pass_encrypt(clear, size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)pphrase,
strlen(pphrase), cipher, strlen(pphrase), cipher,
&eerr), "Could not encrypt, error code %d.", eerr); &eerr), "Could not encrypt, error code %u.", eerr);
size_t written_value = fwrite(cipher, sizeof(*cipher), size, f); size_t written_value = fwrite(cipher, sizeof(*cipher), size, f);
printf("written written_value = %u of %u\n", (unsigned)written_value, (unsigned)size); printf("written written_value = %u of %u\n", (unsigned)written_value, (unsigned)size);

View File

@@ -75,7 +75,7 @@ static void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_num
Tox_Err_File_Control error; Tox_Err_File_Control error;
ck_assert_msg(tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error), ck_assert_msg(tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error),
"tox_file_control failed. %i", error); "tox_file_control failed. %u", error);
++file_accepted; ++file_accepted;
Tox_Err_File_Seek err_s; Tox_Err_File_Seek err_s;
@@ -189,7 +189,7 @@ static void file_transfer_test(void)
tox_iterate(tox2, nullptr); tox_iterate(tox2, nullptr);
tox_iterate(tox3, nullptr); tox_iterate(tox3, nullptr);
printf("Connections: self (%d, %d, %d), friends (%d, %d)\n", printf("Connections: self (%u, %u, %u), friends (%u, %u)\n",
tox_self_get_connection_status(tox1), tox_self_get_connection_status(tox1),
tox_self_get_connection_status(tox2), tox_self_get_connection_status(tox2),
tox_self_get_connection_status(tox3), tox_self_get_connection_status(tox3),
@@ -252,7 +252,7 @@ static void file_transfer_test(void)
ck_assert_msg(sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending ck_assert_msg(sendf_ok && file_recv && m_send_reached && totalf_size == file_size && size_recv == max_sending
&& sending_pos == size_recv && file_accepted == 1, && sending_pos == size_recv && file_accepted == 1,
"something went wrong in file transfer %u %u %u %u %u %u %u %lu %lu %lu %lu", sendf_ok, file_recv, "something went wrong in file transfer %u %u %d %d %d %d %d %lu %lu %lu %lu", sendf_ok, file_recv,
m_send_reached, totalf_size == file_size, size_recv == max_sending, sending_pos == size_recv, file_accepted == 1, m_send_reached, totalf_size == file_size, size_recv == max_sending, sending_pos == size_recv, file_accepted == 1,
(unsigned long)totalf_size, (unsigned long)file_size, (unsigned long)totalf_size, (unsigned long)file_size,
(unsigned long)size_recv, (unsigned long)sending_pos); (unsigned long)size_recv, (unsigned long)sending_pos);

View File

@@ -89,7 +89,7 @@ static void tox_file_receive(const Tox_Event_File_Recv *event, void *userdata)
Tox_Err_File_Control error; Tox_Err_File_Control error;
ck_assert_msg(tox_file_control(state_tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error), ck_assert_msg(tox_file_control(state_tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error),
"tox_file_control failed. %i", error); "tox_file_control failed. %u", error);
++file_accepted; ++file_accepted;
Tox_Err_File_Seek err_s; Tox_Err_File_Seek err_s;
@@ -238,7 +238,7 @@ static void file_transfer_test(void)
iterate_and_dispatch(dispatch2, tox2); iterate_and_dispatch(dispatch2, tox2);
iterate_and_dispatch(dispatch3, tox3); iterate_and_dispatch(dispatch3, tox3);
printf("Connections: self (%d, %d, %d), friends (%d, %d)\n", printf("Connections: self (%u, %u, %u), friends (%u, %u)\n",
tox_self_get_connection_status(tox1), tox_self_get_connection_status(tox1),
tox_self_get_connection_status(tox2), tox_self_get_connection_status(tox2),
tox_self_get_connection_status(tox3), tox_self_get_connection_status(tox3),
@@ -285,7 +285,7 @@ static void file_transfer_test(void)
if (file_sending_done) { if (file_sending_done) {
ck_assert_msg(sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv ck_assert_msg(sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv
&& file_accepted == 1, && file_accepted == 1,
"Something went wrong in file transfer %u %u %u %u %u %u %lu %lu %lu", "Something went wrong in file transfer %u %u %d %d %d %d %lu %lu %lu",
sendf_ok, file_recv, totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, sendf_ok, file_recv, totalf_size == file_size, size_recv == file_size, sending_pos == size_recv,
file_accepted == 1, (unsigned long)totalf_size, (unsigned long)size_recv, file_accepted == 1, (unsigned long)totalf_size, (unsigned long)size_recv,
(unsigned long)sending_pos); (unsigned long)sending_pos);
@@ -304,7 +304,7 @@ static void file_transfer_test(void)
} }
ck_assert_msg(file_sending_done, "file sending did not complete after %u iterations: sendf_ok:%u file_recv:%u " ck_assert_msg(file_sending_done, "file sending did not complete after %u iterations: sendf_ok:%u file_recv:%u "
"totalf_size==file_size:%u size_recv==file_size:%u sending_pos==size_recv:%u file_accepted:%u " "totalf_size==file_size:%d size_recv==file_size:%d sending_pos==size_recv:%d file_accepted:%d "
"totalf_size:%lu size_recv:%lu sending_pos:%lu", "totalf_size:%lu size_recv:%lu sending_pos:%lu",
(unsigned int)max_iterations, sendf_ok, file_recv, (unsigned int)max_iterations, sendf_ok, file_recv,
totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, file_accepted == 1, totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, file_accepted == 1,
@@ -352,7 +352,7 @@ static void file_transfer_test(void)
ck_assert_msg(sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size ck_assert_msg(sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size
&& sending_pos == size_recv && file_accepted == 1, && sending_pos == size_recv && file_accepted == 1,
"something went wrong in file transfer %u %u %u %u %u %u %llu %llu %llu", sendf_ok, file_recv, "something went wrong in file transfer %u %u %d %d %d %d %llu %llu %llu", sendf_ok, file_recv,
totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, file_accepted == 1, totalf_size == file_size, size_recv == file_size, sending_pos == size_recv, file_accepted == 1,
(unsigned long long)totalf_size, (unsigned long long)size_recv, (unsigned long long)totalf_size, (unsigned long long)size_recv,
(unsigned long long)sending_pos); (unsigned long long)sending_pos);

View File

@@ -49,7 +49,7 @@ static void test_friend_request(AutoTox *autotoxes)
for (uint32_t i = 2; i < FR_TOX_COUNT; ++i) { for (uint32_t i = 2; i < FR_TOX_COUNT; ++i) {
Tox_Err_Friend_Add err; Tox_Err_Friend_Add err;
tox_friend_add(autotoxes[i].tox, address, (const uint8_t *)FR_MESSAGE, sizeof(FR_MESSAGE), &err); tox_friend_add(autotoxes[i].tox, address, (const uint8_t *)FR_MESSAGE, sizeof(FR_MESSAGE), &err);
ck_assert_msg(err == TOX_ERR_FRIEND_ADD_OK, "tox %u failed to add friend error code: %d", autotoxes[i].index, err); ck_assert_msg(err == TOX_ERR_FRIEND_ADD_OK, "tox %u failed to add friend error code: %u", autotoxes[i].index, err);
} }
for (uint32_t t = 0; t < 100; ++t) { for (uint32_t t = 0; t < 100; ++t) {

View File

@@ -39,7 +39,7 @@ static void accept_friend_request(const Tox_Event_Friend_Request *event, void *u
Tox_Err_Friend_Add err; Tox_Err_Friend_Add err;
tox_friend_add_norequest(cb_data->tox2, public_key, &err); tox_friend_add_norequest(cb_data->tox2, public_key, &err);
ck_assert_msg(err == TOX_ERR_FRIEND_ADD_OK, "tox_friend_add_norequest failed: %d", err); ck_assert_msg(err == TOX_ERR_FRIEND_ADD_OK, "tox_friend_add_norequest failed: %u", err);
} }
static void iterate2_wait(const Tox_Dispatch *dispatch, Callback_Data *cb_data) static void iterate2_wait(const Tox_Dispatch *dispatch, Callback_Data *cb_data)
@@ -108,7 +108,7 @@ static void test_friend_request(const uint8_t *message, uint16_t length)
Tox_Err_Friend_Add err; Tox_Err_Friend_Add err;
const uint32_t test = tox_friend_add(tox1, address, message, length, &err); const uint32_t test = tox_friend_add(tox1, address, message, length, &err);
ck_assert_msg(err == TOX_ERR_FRIEND_ADD_OK, "tox_friend_add failed: %d", err); ck_assert_msg(err == TOX_ERR_FRIEND_ADD_OK, "tox_friend_add failed: %u", err);
ck_assert_msg(test == 0, "failed to add friend error code: %u", test); ck_assert_msg(test == 0, "failed to add friend error code: %u", test);
do { do {

View File

@@ -48,13 +48,13 @@ static void print_ip(const Tox *tox, uint32_t groupnumber, uint32_t peer_id)
Tox_Err_Group_Peer_Query err; Tox_Err_Group_Peer_Query err;
size_t length = tox_group_peer_get_ip_address_size(tox, groupnumber, peer_id, &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); ck_assert_msg(err == TOX_ERR_GROUP_PEER_QUERY_OK, "failed to get ip address size: error %u", err);
uint8_t ip_str[TOX_GROUP_PEER_IP_STRING_MAX_LENGTH]; uint8_t ip_str[TOX_GROUP_PEER_IP_STRING_MAX_LENGTH];
tox_group_peer_get_ip_address(tox, groupnumber, peer_id, ip_str, &err); tox_group_peer_get_ip_address(tox, groupnumber, peer_id, ip_str, &err);
ip_str[length] = '\0'; ip_str[length] = '\0';
ck_assert_msg(err == TOX_ERR_GROUP_PEER_QUERY_OK, "failed to get ip address: error %d", err); ck_assert_msg(err == TOX_ERR_GROUP_PEER_QUERY_OK, "failed to get ip address: error %u", err);
fprintf(stderr, "%s\n", ip_str); fprintf(stderr, "%s\n", ip_str);
} }
@@ -98,10 +98,10 @@ static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void
ck_assert(connection_status != TOX_CONNECTION_NONE); ck_assert(connection_status != TOX_CONNECTION_NONE);
Tox_Group_Role role = tox_group_peer_get_role(autotox->tox, groupnumber, peer_id, &pq_err); Tox_Group_Role role = tox_group_peer_get_role(autotox->tox, groupnumber, peer_id, &pq_err);
ck_assert_msg(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK, "%d", pq_err); ck_assert_msg(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK, "%u", pq_err);
Tox_User_Status status = tox_group_peer_get_status(autotox->tox, groupnumber, peer_id, &pq_err); Tox_User_Status status = tox_group_peer_get_status(autotox->tox, groupnumber, peer_id, &pq_err);
ck_assert_msg(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK, "%d", pq_err); ck_assert_msg(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK, "%u", pq_err);
size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, groupnumber, peer_id, &pq_err); size_t peer_name_len = tox_group_peer_get_name_size(autotox->tox, groupnumber, peer_id, &pq_err);
char peer_name[TOX_MAX_NAME_LENGTH + 1]; char peer_name[TOX_MAX_NAME_LENGTH + 1];
@@ -116,26 +116,26 @@ static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void
// make sure we see the correct peer state on join // make sure we see the correct peer state on join
if (!state->is_founder) { if (!state->is_founder) {
ck_assert_msg(role == TOX_GROUP_ROLE_FOUNDER, "wrong role: %d", role); ck_assert_msg(role == TOX_GROUP_ROLE_FOUNDER, "wrong role: %u", role);
if (state->peer_joined_count == 0) { if (state->peer_joined_count == 0) {
ck_assert_msg(status == TOX_USER_STATUS_NONE, "wrong status: %d", status); ck_assert_msg(status == TOX_USER_STATUS_NONE, "wrong status: %u", status);
ck_assert_msg(peer_name_len == PEER0_NICK_LEN, "wrong nick: %s", peer_name); ck_assert_msg(peer_name_len == PEER0_NICK_LEN, "wrong nick: %s", peer_name);
ck_assert(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0); ck_assert(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0);
} else { } else {
ck_assert_msg(status == TOX_USER_STATUS_BUSY, "wrong status: %d", status); ck_assert_msg(status == TOX_USER_STATUS_BUSY, "wrong status: %u", status);
ck_assert(peer_name_len == PEER0_NICK2_LEN); ck_assert(peer_name_len == PEER0_NICK2_LEN);
ck_assert(memcmp(peer_name, PEER0_NICK2, peer_name_len) == 0); ck_assert(memcmp(peer_name, PEER0_NICK2, peer_name_len) == 0);
} }
} else { } else {
ck_assert_msg(role == TOX_GROUP_ROLE_USER, "wrong role: %d", role); ck_assert_msg(role == TOX_GROUP_ROLE_USER, "wrong role: %u", role);
ck_assert(peer_name_len == PEER1_NICK_LEN); ck_assert(peer_name_len == PEER1_NICK_LEN);
ck_assert(memcmp(peer_name, PEER1_NICK, peer_name_len) == 0); ck_assert(memcmp(peer_name, PEER1_NICK, peer_name_len) == 0);
if (state->peer_joined_count == 0) { if (state->peer_joined_count == 0) {
ck_assert_msg(status == TOX_USER_STATUS_NONE, "wrong status: %d", status); ck_assert_msg(status == TOX_USER_STATUS_NONE, "wrong status: %u", status);
} else { } else {
ck_assert_msg(status == TOX_USER_STATUS_AWAY, "wrong status: %d", status); ck_assert_msg(status == TOX_USER_STATUS_AWAY, "wrong status: %u", status);
} }
} }
@@ -196,11 +196,11 @@ static void group_peer_self_join_handler(const Tox_Event_Group_Self_Join *event,
Tox_Err_Group_State_Query query_err; Tox_Err_Group_State_Query query_err;
tox_group_get_name(autotox->tox, groupnumber, group_name, &query_err); tox_group_get_name(autotox->tox, groupnumber, group_name, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%d", query_err); ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%u", query_err);
ck_assert(memcmp(group_name, GROUP_NAME, GROUP_NAME_LEN) == 0); ck_assert(memcmp(group_name, GROUP_NAME, GROUP_NAME_LEN) == 0);
tox_group_get_topic(autotox->tox, groupnumber, topic, &query_err); tox_group_get_topic(autotox->tox, groupnumber, topic, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%d", query_err); ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%u", 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(autotox->tox, groupnumber, nullptr); uint32_t peer_id = tox_group_self_get_peer_id(autotox->tox, groupnumber, nullptr);
@@ -263,7 +263,7 @@ static void group_peer_status_handler(const Tox_Event_Group_Peer_Status *event,
Tox_Err_Group_Peer_Query err; Tox_Err_Group_Peer_Query err;
Tox_User_Status cur_status = tox_group_peer_get_status(autotox->tox, groupnumber, peer_id, &err); Tox_User_Status cur_status = tox_group_peer_get_status(autotox->tox, groupnumber, peer_id, &err);
ck_assert_msg(cur_status == status, "%d, %d", cur_status, status); ck_assert_msg(cur_status == status, "%u, %u", cur_status, status);
ck_assert(status == TOX_USER_STATUS_BUSY); ck_assert(status == TOX_USER_STATUS_BUSY);
state->peer_status = true; state->peer_status = true;
@@ -300,7 +300,7 @@ static void group_announce_test(AutoTox *autotoxes)
// changes the state (for sync check purposes) // changes the state (for sync check purposes)
Tox_Err_Group_Set_Peer_Limit limit_set_err; Tox_Err_Group_Set_Peer_Limit limit_set_err;
tox_group_set_peer_limit(tox0, groupnumber, PEER_LIMIT, &limit_set_err); tox_group_set_peer_limit(tox0, groupnumber, PEER_LIMIT, &limit_set_err);
ck_assert_msg(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK, "failed to set peer limit: %d", limit_set_err); ck_assert_msg(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK, "failed to set peer limit: %u", limit_set_err);
Tox_Err_Group_Topic_Set tp_err; Tox_Err_Group_Topic_Set tp_err;
tox_group_set_topic(tox0, groupnumber, (const uint8_t *)TOPIC, TOPIC_LEN, &tp_err); tox_group_set_topic(tox0, groupnumber, (const uint8_t *)TOPIC, TOPIC_LEN, &tp_err);
@@ -359,7 +359,7 @@ static void group_announce_test(AutoTox *autotoxes)
ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK); ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK);
ck_assert(self_status == TOX_USER_STATUS_BUSY); ck_assert(self_status == TOX_USER_STATUS_BUSY);
fprintf(stderr, "Peer 0 successfully changed status to %d\n", self_status); fprintf(stderr, "Peer 0 successfully changed status to %u\n", self_status);
while (!state1->peer_nick && !state1->peer_status) { while (!state1->peer_nick && !state1->peer_status) {
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);

View File

@@ -130,7 +130,7 @@ static void group_invite_test(AutoTox *autotoxes)
Tox_Err_Group_New new_err; Tox_Err_Group_New new_err;
uint32_t groupnumber = tox_group_new(tox0, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *)"test", 4, uint32_t groupnumber = tox_group_new(tox0, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *)"test", 4,
(const uint8_t *)"test", 4, &new_err); (const uint8_t *)"test", 4, &new_err);
ck_assert_msg(new_err == TOX_ERR_GROUP_NEW_OK, "tox_group_new failed: %d", new_err); ck_assert_msg(new_err == TOX_ERR_GROUP_NEW_OK, "tox_group_new failed: %u", new_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@@ -138,12 +138,12 @@ static void group_invite_test(AutoTox *autotoxes)
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err); tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%d", id_err); ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%u", id_err);
// peer 1 joins public group with no password // peer 1 joins public group with no password
Tox_Err_Group_Join join_err; Tox_Err_Group_Join join_err;
tox_group_join(tox1, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err); tox_group_join(tox1, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err);
ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%d", join_err); ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%u", join_err);
while (state0->num_peers < 1) { while (state0->num_peers < 1) {
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@@ -154,13 +154,13 @@ static void group_invite_test(AutoTox *autotoxes)
// founder sets a password // founder sets a password
Tox_Err_Group_Set_Password pass_set_err; Tox_Err_Group_Set_Password pass_set_err;
tox_group_set_password(tox0, groupnumber, (const uint8_t *)PASSWORD, PASS_LEN, &pass_set_err); tox_group_set_password(tox0, groupnumber, (const uint8_t *)PASSWORD, PASS_LEN, &pass_set_err);
ck_assert_msg(pass_set_err == TOX_ERR_GROUP_SET_PASSWORD_OK, "%d", pass_set_err); ck_assert_msg(pass_set_err == TOX_ERR_GROUP_SET_PASSWORD_OK, "%u", pass_set_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 5000); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 5000);
// peer 2 attempts to join with no password // peer 2 attempts to join with no password
tox_group_join(tox2, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err); tox_group_join(tox2, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err);
ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%d", join_err); ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%u", join_err);
while (!state2->password_fail) { while (!state2->password_fail) {
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@@ -170,7 +170,7 @@ static void group_invite_test(AutoTox *autotoxes)
// peer 3 attempts to join with invalid password // peer 3 attempts to join with invalid password
tox_group_join(tox3, chat_id, (const uint8_t *)"Test", 4, (const uint8_t *)WRONG_PASS, WRONG_PASS_LEN, &join_err); tox_group_join(tox3, chat_id, (const uint8_t *)"Test", 4, (const uint8_t *)WRONG_PASS, WRONG_PASS_LEN, &join_err);
ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%d", join_err); ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%u", join_err);
while (!state3->password_fail) { while (!state3->password_fail) {
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@@ -181,13 +181,13 @@ static void group_invite_test(AutoTox *autotoxes)
// founder sets peer limit to 1 // founder sets peer limit to 1
Tox_Err_Group_Set_Peer_Limit limit_set_err; Tox_Err_Group_Set_Peer_Limit limit_set_err;
tox_group_set_peer_limit(tox0, groupnumber, 1, &limit_set_err); tox_group_set_peer_limit(tox0, groupnumber, 1, &limit_set_err);
ck_assert_msg(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK, "%d", limit_set_err); ck_assert_msg(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK, "%u", limit_set_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 5000); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 5000);
// peer 4 attempts to join with correct password // peer 4 attempts to join with correct password
tox_group_join(tox4, chat_id, (const uint8_t *)"Test", 4, (const uint8_t *)PASSWORD, PASS_LEN, &join_err); tox_group_join(tox4, chat_id, (const uint8_t *)"Test", 4, (const uint8_t *)PASSWORD, PASS_LEN, &join_err);
ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%d", join_err); ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%u", join_err);
while (!state4->peer_limit_fail) { while (!state4->peer_limit_fail) {
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@@ -197,16 +197,16 @@ static void group_invite_test(AutoTox *autotoxes)
// founder removes password and increases peer limit to 100 // founder removes password and increases peer limit to 100
tox_group_set_password(tox0, groupnumber, nullptr, 0, &pass_set_err); tox_group_set_password(tox0, groupnumber, nullptr, 0, &pass_set_err);
ck_assert_msg(pass_set_err == TOX_ERR_GROUP_SET_PASSWORD_OK, "%d", pass_set_err); ck_assert_msg(pass_set_err == TOX_ERR_GROUP_SET_PASSWORD_OK, "%u", pass_set_err);
tox_group_set_peer_limit(tox0, groupnumber, 100, &limit_set_err); tox_group_set_peer_limit(tox0, groupnumber, 100, &limit_set_err);
ck_assert_msg(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK, "%d", limit_set_err); ck_assert_msg(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK, "%u", limit_set_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 5000); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 5000);
// peer 5 attempts to join group // peer 5 attempts to join group
tox_group_join(tox5, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err); tox_group_join(tox5, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err);
ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%d", join_err); ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%u", join_err);
while (!state5->connected) { while (!state5->connected) {
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@@ -217,13 +217,13 @@ static void group_invite_test(AutoTox *autotoxes)
// founder makes group private // founder makes group private
Tox_Err_Group_Set_Privacy_State priv_err; Tox_Err_Group_Set_Privacy_State priv_err;
tox_group_set_privacy_state(tox0, groupnumber, TOX_GROUP_PRIVACY_STATE_PRIVATE, &priv_err); tox_group_set_privacy_state(tox0, groupnumber, TOX_GROUP_PRIVACY_STATE_PRIVATE, &priv_err);
ck_assert_msg(priv_err == TOX_ERR_GROUP_SET_PRIVACY_STATE_OK, "%d", priv_err); ck_assert_msg(priv_err == TOX_ERR_GROUP_SET_PRIVACY_STATE_OK, "%u", priv_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 5000); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 5000);
// peer 6 attempts to join group via chat ID // peer 6 attempts to join group via chat ID
tox_group_join(tox6, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err); tox_group_join(tox6, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err);
ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%d", join_err); ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%u", join_err);
// since we don't receive a fail packet in this case we just wait a while and check if we're in the group // since we don't receive a fail packet in this case we just wait a while and check if we're in the group
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 20000); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 20000);
@@ -234,7 +234,7 @@ static void group_invite_test(AutoTox *autotoxes)
// founder makes group public again // founder makes group public again
tox_group_set_privacy_state(tox0, groupnumber, TOX_GROUP_PRIVACY_STATE_PUBLIC, &priv_err); tox_group_set_privacy_state(tox0, groupnumber, TOX_GROUP_PRIVACY_STATE_PUBLIC, &priv_err);
ck_assert_msg(priv_err == TOX_ERR_GROUP_SET_PRIVACY_STATE_OK, "%d", priv_err); ck_assert_msg(priv_err == TOX_ERR_GROUP_SET_PRIVACY_STATE_OK, "%u", priv_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@@ -243,7 +243,7 @@ static void group_invite_test(AutoTox *autotoxes)
for (size_t i = 7; i < NUM_GROUP_TOXES; ++i) { for (size_t i = 7; i < NUM_GROUP_TOXES; ++i) {
tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err); tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err);
ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%d", join_err); ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%u", join_err);
} }
const uint32_t expected_peer_count = num_new_peers + state0->num_peers + 1; const uint32_t expected_peer_count = num_new_peers + state0->num_peers + 1;

View File

@@ -90,7 +90,7 @@ static void group_invite_handler(const Tox_Event_Group_Invite *event, void *user
static void group_join_fail_handler(const Tox_Event_Group_Join_Fail *event, void *user_data) static void group_join_fail_handler(const Tox_Event_Group_Join_Fail *event, void *user_data)
{ {
const Tox_Group_Join_Fail fail_type = tox_event_group_join_fail_get_fail_type(event); const Tox_Group_Join_Fail fail_type = tox_event_group_join_fail_get_fail_type(event);
printf("join failed: %d\n", fail_type); printf("join failed: %u\n", fail_type);
} }
static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void *user_data) static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void *user_data)
@@ -448,7 +448,7 @@ static void group_message_test(AutoTox *autotoxes)
// tox0 ignores tox1 // tox0 ignores tox1
Tox_Err_Group_Set_Ignore ig_err; Tox_Err_Group_Set_Ignore ig_err;
tox_group_set_ignore(tox0, group_number, state0->peer_id, true, &ig_err); tox_group_set_ignore(tox0, group_number, state0->peer_id, true, &ig_err);
ck_assert_msg(ig_err == TOX_ERR_GROUP_SET_IGNORE_OK, "%d", ig_err); ck_assert_msg(ig_err == TOX_ERR_GROUP_SET_IGNORE_OK, "%u", ig_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@@ -460,7 +460,7 @@ static void group_message_test(AutoTox *autotoxes)
// tox0 unignores tox1 // tox0 unignores tox1
tox_group_set_ignore(tox0, group_number, state0->peer_id, false, &ig_err); tox_group_set_ignore(tox0, group_number, state0->peer_id, false, &ig_err);
ck_assert_msg(ig_err == TOX_ERR_GROUP_SET_IGNORE_OK, "%d", ig_err); ck_assert_msg(ig_err == TOX_ERR_GROUP_SET_IGNORE_OK, "%u", ig_err);
fprintf(stderr, "Sending private action...\n"); fprintf(stderr, "Sending private action...\n");
@@ -470,7 +470,7 @@ static void group_message_test(AutoTox *autotoxes)
TOX_MESSAGE_TYPE_ACTION, (const uint8_t *)TEST_PRIVATE_MESSAGE, TOX_MESSAGE_TYPE_ACTION, (const uint8_t *)TEST_PRIVATE_MESSAGE,
TEST_PRIVATE_MESSAGE_LEN, &m_err); TEST_PRIVATE_MESSAGE_LEN, &m_err);
ck_assert_msg(m_err == TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_OK, "%d", m_err); ck_assert_msg(m_err == TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_OK, "%u", m_err);
while (!state0->private_message_received) { while (!state0->private_message_received) {
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@@ -485,11 +485,11 @@ static void group_message_test(AutoTox *autotoxes)
Tox_Err_Group_Send_Custom_Packet c_err; Tox_Err_Group_Send_Custom_Packet c_err;
tox_group_send_custom_packet(tox1, group_number, true, (const uint8_t *)TEST_CUSTOM_PACKET, TEST_CUSTOM_PACKET_LEN, tox_group_send_custom_packet(tox1, group_number, true, (const uint8_t *)TEST_CUSTOM_PACKET, TEST_CUSTOM_PACKET_LEN,
&c_err); &c_err);
ck_assert_msg(c_err == TOX_ERR_GROUP_SEND_CUSTOM_PACKET_OK, "%d", c_err); ck_assert_msg(c_err == TOX_ERR_GROUP_SEND_CUSTOM_PACKET_OK, "%u", c_err);
tox_group_send_custom_packet(tox1, group_number, false, (const uint8_t *)TEST_CUSTOM_PACKET, TEST_CUSTOM_PACKET_LEN, tox_group_send_custom_packet(tox1, group_number, false, (const uint8_t *)TEST_CUSTOM_PACKET, TEST_CUSTOM_PACKET_LEN,
&c_err); &c_err);
ck_assert_msg(c_err == TOX_ERR_GROUP_SEND_CUSTOM_PACKET_OK, "%d", c_err); ck_assert_msg(c_err == TOX_ERR_GROUP_SEND_CUSTOM_PACKET_OK, "%u", c_err);
fprintf(stderr, "Sending custom private packets...\n"); fprintf(stderr, "Sending custom private packets...\n");
@@ -499,13 +499,13 @@ static void group_message_test(AutoTox *autotoxes)
(const uint8_t *)TEST_CUSTOM_PRIVATE_PACKET, (const uint8_t *)TEST_CUSTOM_PRIVATE_PACKET,
TEST_CUSTOM_PRIVATE_PACKET_LEN, &cperr); TEST_CUSTOM_PRIVATE_PACKET_LEN, &cperr);
ck_assert_msg(cperr == TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_OK, "%d", cperr); ck_assert_msg(cperr == TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_OK, "%u", cperr);
tox_group_send_custom_private_packet(tox1, group_number, state1->peer_id, false, tox_group_send_custom_private_packet(tox1, group_number, state1->peer_id, false,
(const uint8_t *)TEST_CUSTOM_PRIVATE_PACKET, (const uint8_t *)TEST_CUSTOM_PRIVATE_PACKET,
TEST_CUSTOM_PRIVATE_PACKET_LEN, &cperr); TEST_CUSTOM_PRIVATE_PACKET_LEN, &cperr);
ck_assert_msg(cperr == TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_OK, "%d", cperr); ck_assert_msg(cperr == TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_OK, "%u", cperr);
while (state0->custom_packets_received < 2 || state0->custom_private_packets_received < 2) { while (state0->custom_packets_received < 2 || state0->custom_private_packets_received < 2) {
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@@ -518,7 +518,7 @@ static void group_message_test(AutoTox *autotoxes)
tox_group_send_custom_packet(tox1, group_number, false, (const uint8_t *)TEST_CUSTOM_PACKET_LARGE, TEST_CUSTOM_PACKET_LARGE_LEN, tox_group_send_custom_packet(tox1, group_number, false, (const uint8_t *)TEST_CUSTOM_PACKET_LARGE, TEST_CUSTOM_PACKET_LARGE_LEN,
&c_err); &c_err);
ck_assert_msg(c_err == TOX_ERR_GROUP_SEND_CUSTOM_PACKET_OK, "%d", c_err); ck_assert_msg(c_err == TOX_ERR_GROUP_SEND_CUSTOM_PACKET_OK, "%u", c_err);
while (state0->custom_packets_received < 3) { while (state0->custom_packets_received < 3) {
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);

View File

@@ -158,7 +158,7 @@ static size_t get_state_index_by_nick(const AutoTox *autotoxes, size_t num_peers
static void group_join_fail_handler(const Tox_Event_Group_Join_Fail *event, void *user_data) static void group_join_fail_handler(const Tox_Event_Group_Join_Fail *event, void *user_data)
{ {
const Tox_Group_Join_Fail fail_type = tox_event_group_join_fail_get_fail_type(event); const Tox_Group_Join_Fail fail_type = tox_event_group_join_fail_get_fail_type(event);
fprintf(stderr, "Failed to join group: %d", fail_type); fprintf(stderr, "Failed to join group: %u", fail_type);
} }
static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void *user_data) static void group_peer_join_handler(const Tox_Event_Group_Peer_Join *event, void *user_data)
@@ -268,7 +268,7 @@ static void group_mod_event_handler(const Tox_Event_Group_Moderation *event, voi
return; return;
} }
ck_assert_msg(q_err == TOX_ERR_GROUP_PEER_QUERY_OK, "error %d", q_err); ck_assert_msg(q_err == TOX_ERR_GROUP_PEER_QUERY_OK, "error %u", q_err);
ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH); ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH);
tox_group_peer_get_name(autotox->tox, group_number, target_peer_id, (uint8_t *) peer_name, &q_err); tox_group_peer_get_name(autotox->tox, group_number, target_peer_id, (uint8_t *) peer_name, &q_err);
@@ -279,7 +279,7 @@ static void group_mod_event_handler(const Tox_Event_Group_Moderation *event, voi
ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(role <= TOX_GROUP_ROLE_OBSERVER); ck_assert(role <= TOX_GROUP_ROLE_OBSERVER);
fprintf(stderr, "tox%u: got moderator event %d (%s), role = %s\n", fprintf(stderr, "tox%u: got moderator event %u (%s), role = %s\n",
autotox->index, mod_type, tox_group_mod_event_to_string(mod_type), autotox->index, mod_type, tox_group_mod_event_to_string(mod_type),
tox_group_role_to_string(role)); tox_group_role_to_string(role));
@@ -306,7 +306,7 @@ static void group_mod_event_handler(const Tox_Event_Group_Moderation *event, voi
} }
default: { default: {
ck_assert_msg(0, "Got invalid moderator event %d", mod_type); ck_assert_msg(0, "Got invalid moderator event %u", mod_type);
return; return;
} }
} }
@@ -354,7 +354,7 @@ static void voice_state_message_test(AutoTox *autotox, Tox_Group_Voice_State voi
case TOX_GROUP_ROLE_USER: { case TOX_GROUP_ROLE_USER: {
if (voice_state != TOX_GROUP_VOICE_STATE_ALL) { if (voice_state != TOX_GROUP_VOICE_STATE_ALL) {
ck_assert_msg(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS, ck_assert_msg(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS,
"%d", msg_err); "%u", msg_err);
} else { } else {
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK); ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
} }
@@ -469,14 +469,14 @@ static void group_moderation_test(AutoTox *autotoxes)
GROUP_NAME_LEN, (const uint8_t *)state0->self_name, state0->self_name_length, GROUP_NAME_LEN, (const uint8_t *)state0->self_name, state0->self_name_length,
&err_new); &err_new);
ck_assert_msg(err_new == TOX_ERR_GROUP_NEW_OK, "Failed to create group. error: %d\n", err_new); ck_assert_msg(err_new == TOX_ERR_GROUP_NEW_OK, "Failed to create group. error: %u\n", err_new);
/* Founder gets chat ID */ /* Founder gets chat ID */
Tox_Err_Group_State_Query id_err; Tox_Err_Group_State_Query id_err;
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(tox0, state0->group_number, chat_id, &id_err); tox_group_get_chat_id(tox0, state0->group_number, chat_id, &id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get chat ID. error: %d", id_err); ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get chat ID. error: %u", id_err);
fprintf(stderr, "Peers attemping to join DHT group via the chat ID\n"); fprintf(stderr, "Peers attemping to join DHT group via the chat ID\n");
@@ -488,7 +488,7 @@ static void group_moderation_test(AutoTox *autotoxes)
state->group_number = tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)state->self_name, state->group_number = tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)state->self_name,
state->self_name_length, state->self_name_length,
nullptr, 0, &join_err); nullptr, 0, &join_err);
ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "Peer %s (%zu) failed to join group. error %d", ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "Peer %s (%zu) failed to join group. error %u",
state->self_name, i, join_err); state->self_name, i, join_err);
c_sleep(100); c_sleep(100);
@@ -527,7 +527,7 @@ static void group_moderation_test(AutoTox *autotoxes)
Tox_Err_Group_Set_Role role_err; Tox_Err_Group_Set_Role role_err;
tox_group_set_role(tox0, state0->group_number, state0->peers[0].peer_id, TOX_GROUP_ROLE_MODERATOR, &role_err); tox_group_set_role(tox0, state0->group_number, state0->peers[0].peer_id, TOX_GROUP_ROLE_MODERATOR, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set moderator. error: %d", role_err); ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set moderator. error: %u", role_err);
// manually flag the role setter because they don't get a callback // manually flag the role setter because they don't get a callback
state0->mod_check = true; state0->mod_check = true;
@@ -542,7 +542,7 @@ static void group_moderation_test(AutoTox *autotoxes)
fprintf(stderr, "Founder setting %s to observer\n", state0->peers[1].name); fprintf(stderr, "Founder setting %s to observer\n", state0->peers[1].name);
tox_group_set_role(tox0, state0->group_number, state0->peers[1].peer_id, TOX_GROUP_ROLE_OBSERVER, &role_err); tox_group_set_role(tox0, state0->group_number, state0->peers[1].peer_id, TOX_GROUP_ROLE_OBSERVER, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set observer. error: %d", role_err); ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set observer. error: %u", role_err);
state0->observer_check = true; state0->observer_check = true;
++state0->observer_event_count; ++state0->observer_event_count;
@@ -553,7 +553,7 @@ static void group_moderation_test(AutoTox *autotoxes)
fprintf(stderr, "Founder setting %s to observer\n", state0->peers[2].name); fprintf(stderr, "Founder setting %s to observer\n", state0->peers[2].name);
tox_group_set_role(tox0, state0->group_number, state0->peers[2].peer_id, TOX_GROUP_ROLE_OBSERVER, &role_err); tox_group_set_role(tox0, state0->group_number, state0->peers[2].peer_id, TOX_GROUP_ROLE_OBSERVER, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set observer. error: %d", role_err); ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set observer. error: %u", role_err);
state0->observer_check = true; state0->observer_check = true;
++state0->observer_event_count; ++state0->observer_event_count;
@@ -579,7 +579,7 @@ static void group_moderation_test(AutoTox *autotoxes)
fprintf(stderr, "%s is promoting %s back to user\n", state1->self_name, state0->peers[1].name); fprintf(stderr, "%s is promoting %s back to user\n", state1->self_name, state0->peers[1].name);
tox_group_set_role(tox1, state1->group_number, obs_peer_id, TOX_GROUP_ROLE_USER, &role_err); tox_group_set_role(tox1, state1->group_number, obs_peer_id, TOX_GROUP_ROLE_USER, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to promote observer back to user. error: %d", ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to promote observer back to user. error: %u",
role_err); role_err);
state1->user_check = true; state1->user_check = true;
@@ -592,7 +592,7 @@ static void group_moderation_test(AutoTox *autotoxes)
fprintf(stderr, "Founder setting %s to moderator\n", state0->peers[2].name); fprintf(stderr, "Founder setting %s to moderator\n", state0->peers[2].name);
tox_group_set_role(tox0, state0->group_number, state0->peers[2].peer_id, TOX_GROUP_ROLE_MODERATOR, &role_err); tox_group_set_role(tox0, state0->group_number, state0->peers[2].peer_id, TOX_GROUP_ROLE_MODERATOR, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set moderator. error: %d", role_err); ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set moderator. error: %u", role_err);
state0->mod_check = true; state0->mod_check = true;
++state0->mod_event_count; ++state0->mod_event_count;
@@ -624,7 +624,7 @@ static void group_moderation_test(AutoTox *autotoxes)
fprintf(stderr, "Founder is kicking %s\n", state0->peers[0].name); fprintf(stderr, "Founder is kicking %s\n", state0->peers[0].name);
tox_group_kick_peer(tox0, state0->group_number, state0->peers[0].peer_id, &k_err); tox_group_kick_peer(tox0, state0->group_number, state0->peers[0].peer_id, &k_err);
ck_assert_msg(k_err == TOX_ERR_GROUP_KICK_PEER_OK, "Failed to kick peer. error: %d", k_err); ck_assert_msg(k_err == TOX_ERR_GROUP_KICK_PEER_OK, "Failed to kick peer. error: %u", k_err);
state0->kick_check = true; state0->kick_check = true;
check_mod_event(autotoxes, NUM_GROUP_TOXES, TOX_GROUP_MOD_EVENT_KICK); check_mod_event(autotoxes, NUM_GROUP_TOXES, TOX_GROUP_MOD_EVENT_KICK);
@@ -633,7 +633,7 @@ static void group_moderation_test(AutoTox *autotoxes)
fprintf(stderr, "Founder is demoting moderator to user\n"); fprintf(stderr, "Founder is demoting moderator to user\n");
tox_group_set_role(tox0, state0->group_number, state0->peers[2].peer_id, TOX_GROUP_ROLE_USER, &role_err); tox_group_set_role(tox0, state0->group_number, state0->peers[2].peer_id, TOX_GROUP_ROLE_USER, &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to demote peer 3 to User. error: %d", role_err); ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to demote peer 3 to User. error: %u", role_err);
state0->user_check = true; state0->user_check = true;
++state0->user_event_count; ++state0->user_event_count;

View File

@@ -73,7 +73,7 @@ static void group_topic_lock_handler(const Tox_Event_Group_Topic_Lock *event,
Tox_Group_Topic_Lock current_topic_lock = tox_group_get_topic_lock(autotox->tox, groupnumber, &err); Tox_Group_Topic_Lock current_topic_lock = tox_group_get_topic_lock(autotox->tox, groupnumber, &err);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERY_OK); ck_assert(err == TOX_ERR_GROUP_STATE_QUERY_OK);
ck_assert_msg(current_topic_lock == topic_lock, "topic locks don't match in callback: %d %d", ck_assert_msg(current_topic_lock == topic_lock, "topic locks don't match in callback: %u %u",
topic_lock, current_topic_lock); topic_lock, current_topic_lock);
} }
@@ -90,7 +90,7 @@ static void group_voice_state_handler(const Tox_Event_Group_Voice_State *event,
Tox_Group_Voice_State current_voice_state = tox_group_get_voice_state(autotox->tox, groupnumber, &err); Tox_Group_Voice_State current_voice_state = tox_group_get_voice_state(autotox->tox, groupnumber, &err);
ck_assert(err == TOX_ERR_GROUP_STATE_QUERY_OK); ck_assert(err == TOX_ERR_GROUP_STATE_QUERY_OK);
ck_assert_msg(current_voice_state == voice_state, "voice states don't match in callback: %d %d", ck_assert_msg(current_voice_state == voice_state, "voice states don't match in callback: %u %u",
voice_state, current_voice_state); voice_state, current_voice_state);
} }
@@ -171,21 +171,21 @@ static int check_group_state(const Tox *tox, uint32_t groupnumber, uint32_t peer
Tox_Err_Group_State_Query query_err; Tox_Err_Group_State_Query query_err;
Tox_Group_Privacy_State my_priv_state = tox_group_get_privacy_state(tox, groupnumber, &query_err); Tox_Group_Privacy_State my_priv_state = tox_group_get_privacy_state(tox, groupnumber, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get privacy state: %d", query_err); ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get privacy state: %u", query_err);
if (my_priv_state != priv_state) { if (my_priv_state != priv_state) {
return -1; return -1;
} }
uint32_t my_peer_limit = tox_group_get_peer_limit(tox, groupnumber, &query_err); uint32_t my_peer_limit = tox_group_get_peer_limit(tox, groupnumber, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get peer limit: %d", query_err); ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get peer limit: %u", query_err);
if (my_peer_limit != peer_limit) { if (my_peer_limit != peer_limit) {
return -2; return -2;
} }
size_t my_pass_len = tox_group_get_password_size(tox, groupnumber, &query_err); size_t my_pass_len = tox_group_get_password_size(tox, groupnumber, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get password size: %d", query_err); ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get password size: %u", query_err);
if (my_pass_len != pass_len) { if (my_pass_len != pass_len) {
return -5; return -5;
@@ -197,7 +197,7 @@ static int check_group_state(const Tox *tox, uint32_t groupnumber, uint32_t peer
uint8_t my_pass[TOX_GROUP_MAX_PASSWORD_SIZE + 1]; uint8_t my_pass[TOX_GROUP_MAX_PASSWORD_SIZE + 1];
tox_group_get_password(tox, groupnumber, my_pass, &query_err); tox_group_get_password(tox, groupnumber, my_pass, &query_err);
my_pass[my_pass_len] = 0; my_pass[my_pass_len] = 0;
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get password: %d", query_err); ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get password: %u", query_err);
if (memcmp(my_pass, password, my_pass_len) != 0) { if (memcmp(my_pass, password, my_pass_len) != 0) {
return -6; return -6;
@@ -206,7 +206,7 @@ static int check_group_state(const Tox *tox, uint32_t groupnumber, uint32_t peer
/* Group name should never change */ /* Group name should never change */
size_t my_gname_len = tox_group_get_name_size(tox, groupnumber, &query_err); size_t my_gname_len = tox_group_get_name_size(tox, groupnumber, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get group name size: %d", query_err); ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get group name size: %u", query_err);
if (my_gname_len != GROUP_NAME_LEN) { if (my_gname_len != GROUP_NAME_LEN) {
return -7; return -7;
@@ -223,14 +223,14 @@ static int check_group_state(const Tox *tox, uint32_t groupnumber, uint32_t peer
} }
Tox_Group_Topic_Lock current_topic_lock = tox_group_get_topic_lock(tox, groupnumber, &query_err); Tox_Group_Topic_Lock current_topic_lock = tox_group_get_topic_lock(tox, groupnumber, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get topic lock: %d", query_err); ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get topic lock: %u", query_err);
if (current_topic_lock != topic_lock) { if (current_topic_lock != topic_lock) {
return -9; return -9;
} }
Tox_Group_Voice_State current_voice_state = tox_group_get_voice_state(tox, groupnumber, &query_err); Tox_Group_Voice_State current_voice_state = tox_group_get_voice_state(tox, groupnumber, &query_err);
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get voice state: %d", query_err); ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERY_OK, "Failed to get voice state: %u", query_err);
if (current_voice_state != voice_state) { if (current_voice_state != voice_state) {
return -10; return -10;
@@ -246,24 +246,24 @@ static void set_group_state(Tox *tox, uint32_t groupnumber, uint32_t peer_limit,
Tox_Err_Group_Set_Peer_Limit limit_set_err; Tox_Err_Group_Set_Peer_Limit limit_set_err;
tox_group_set_peer_limit(tox, groupnumber, peer_limit, &limit_set_err); tox_group_set_peer_limit(tox, groupnumber, peer_limit, &limit_set_err);
ck_assert_msg(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK, "failed to set peer limit: %d", limit_set_err); ck_assert_msg(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK, "failed to set peer limit: %u", limit_set_err);
Tox_Err_Group_Set_Privacy_State priv_err; Tox_Err_Group_Set_Privacy_State priv_err;
tox_group_set_privacy_state(tox, groupnumber, priv_state, &priv_err); tox_group_set_privacy_state(tox, groupnumber, priv_state, &priv_err);
ck_assert_msg(priv_err == TOX_ERR_GROUP_SET_PRIVACY_STATE_OK, "failed to set privacy state: %d", priv_err); ck_assert_msg(priv_err == TOX_ERR_GROUP_SET_PRIVACY_STATE_OK, "failed to set privacy state: %u", priv_err);
Tox_Err_Group_Set_Password pass_set_err; Tox_Err_Group_Set_Password pass_set_err;
tox_group_set_password(tox, groupnumber, password, pass_len, &pass_set_err); tox_group_set_password(tox, groupnumber, password, pass_len, &pass_set_err);
ck_assert_msg(pass_set_err == TOX_ERR_GROUP_SET_PASSWORD_OK, "failed to set password: %d", pass_set_err); ck_assert_msg(pass_set_err == TOX_ERR_GROUP_SET_PASSWORD_OK, "failed to set password: %u", pass_set_err);
Tox_Err_Group_Set_Topic_Lock lock_set_err; Tox_Err_Group_Set_Topic_Lock lock_set_err;
tox_group_set_topic_lock(tox, groupnumber, topic_lock, &lock_set_err); tox_group_set_topic_lock(tox, groupnumber, topic_lock, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to set topic lock: %d", ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to set topic lock: %u",
lock_set_err); lock_set_err);
Tox_Err_Group_Set_Voice_State voice_set_err; Tox_Err_Group_Set_Voice_State voice_set_err;
tox_group_set_voice_state(tox, groupnumber, voice_state, &voice_set_err); tox_group_set_voice_state(tox, groupnumber, voice_state, &voice_set_err);
ck_assert_msg(voice_set_err == TOX_ERR_GROUP_SET_VOICE_STATE_OK, "failed to set voice state: %d", ck_assert_msg(voice_set_err == TOX_ERR_GROUP_SET_VOICE_STATE_OK, "failed to set voice state: %u",
voice_set_err); voice_set_err);
} }
@@ -287,7 +287,7 @@ static void group_state_test(AutoTox *autotoxes)
uint32_t groupnum = tox_group_new(tox0, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *)GROUP_NAME, GROUP_NAME_LEN, uint32_t groupnum = tox_group_new(tox0, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *)GROUP_NAME, GROUP_NAME_LEN,
(const uint8_t *)PEER0_NICK, PEER0_NICK_LEN, &new_err); (const uint8_t *)PEER0_NICK, PEER0_NICK_LEN, &new_err);
ck_assert_msg(new_err == TOX_ERR_GROUP_NEW_OK, "tox_group_new failed: %d", new_err); ck_assert_msg(new_err == TOX_ERR_GROUP_NEW_OK, "tox_group_new failed: %u", new_err);
/* Founder sets default group state before anyone else joins */ /* Founder sets default group state before anyone else joins */
set_group_state(tox0, groupnum, PEER_LIMIT_1, TOX_GROUP_PRIVACY_STATE_PUBLIC, TOX_GROUP_VOICE_STATE_ALL, set_group_state(tox0, groupnum, PEER_LIMIT_1, TOX_GROUP_PRIVACY_STATE_PUBLIC, TOX_GROUP_VOICE_STATE_ALL,
@@ -298,7 +298,7 @@ static void group_state_test(AutoTox *autotoxes)
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(tox0, groupnum, chat_id, &id_err); tox_group_get_chat_id(tox0, groupnum, chat_id, &id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "tox_group_get_chat_id failed %d", id_err); ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "tox_group_get_chat_id failed %u", id_err);
/* All other peers join the group using the Chat ID and password */ /* All other peers join the group using the Chat ID and password */
for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) { for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) {
@@ -307,7 +307,7 @@ static void group_state_test(AutoTox *autotoxes)
Tox_Err_Group_Join join_err; Tox_Err_Group_Join join_err;
tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)"Test", 4, (const uint8_t *)PASSWORD, PASS_LEN, tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)"Test", 4, (const uint8_t *)PASSWORD, PASS_LEN,
&join_err); &join_err);
ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "tox_group_join failed: %d", join_err); ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "tox_group_join failed: %u", join_err);
} }
fprintf(stderr, "Peers attempting to join group\n"); fprintf(stderr, "Peers attempting to join group\n");
@@ -344,7 +344,7 @@ static void group_state_test(AutoTox *autotoxes)
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) { for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
Tox_Err_Group_Leave err_exit; Tox_Err_Group_Leave err_exit;
tox_group_leave(autotoxes[i].tox, groupnum, nullptr, 0, &err_exit); tox_group_leave(autotoxes[i].tox, groupnum, nullptr, 0, &err_exit);
ck_assert_msg(err_exit == TOX_ERR_GROUP_LEAVE_OK, "%d", err_exit); ck_assert_msg(err_exit == TOX_ERR_GROUP_LEAVE_OK, "%u", err_exit);
} }
fprintf(stderr, "All tests passed!\n"); fprintf(stderr, "All tests passed!\n");

View File

@@ -364,12 +364,12 @@ static void group_sync_test(AutoTox *autotoxes)
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err); tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%d", id_err); ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%u", id_err);
for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) { for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) {
Tox_Err_Group_Join join_err; Tox_Err_Group_Join join_err;
tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err); tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err);
ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%d", join_err); ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%u", join_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
} }
@@ -381,7 +381,7 @@ static void group_sync_test(AutoTox *autotoxes)
Tox_Err_Group_Set_Topic_Lock lock_set_err; Tox_Err_Group_Set_Topic_Lock lock_set_err;
tox_group_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err); tox_group_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to disable topic lock: %d", ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to disable topic lock: %u",
lock_set_err); lock_set_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@@ -393,7 +393,7 @@ static void group_sync_test(AutoTox *autotoxes)
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
tox_group_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_ENABLED, &lock_set_err); tox_group_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_ENABLED, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to enable topic lock: %d", ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to enable topic lock: %u",
lock_set_err); lock_set_err);
do { do {
@@ -407,7 +407,7 @@ static void group_sync_test(AutoTox *autotoxes)
for (size_t i = 0; i < state0->peers->num_peers; ++i) { for (size_t i = 0; i < state0->peers->num_peers; ++i) {
tox_group_set_role(tox0, groupnumber, (uint32_t)state0->peers->peer_ids[i], TOX_GROUP_ROLE_MODERATOR, tox_group_set_role(tox0, groupnumber, (uint32_t)state0->peers->peer_ids[i], TOX_GROUP_ROLE_MODERATOR,
&role_err); &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set moderator. error: %d", role_err); ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set moderator. error: %u", role_err);
} }
fprintf(stderr, "founder enabled topic lock and set all peers to moderator role\n"); fprintf(stderr, "founder enabled topic lock and set all peers to moderator role\n");
@@ -425,7 +425,7 @@ static void group_sync_test(AutoTox *autotoxes)
for (size_t i = 0; i < num_demoted; ++i) { for (size_t i = 0; i < num_demoted; ++i) {
tox_group_set_role(tox0, groupnumber, (uint32_t)state0->peers->peer_ids[i], TOX_GROUP_ROLE_USER, tox_group_set_role(tox0, groupnumber, (uint32_t)state0->peers->peer_ids[i], TOX_GROUP_ROLE_USER,
&role_err); &role_err);
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set user. error: %d", role_err); ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set user. error: %u", role_err);
} }
do { do {

View File

@@ -156,7 +156,7 @@ static void group_tcp_test(AutoTox *autotoxes)
Tox_Err_Group_New new_err; Tox_Err_Group_New new_err;
uint32_t groupnumber = tox_group_new(autotoxes[0].tox, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *)"test", 4, uint32_t groupnumber = tox_group_new(autotoxes[0].tox, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *)"test", 4,
(const uint8_t *)"test", 4, &new_err); (const uint8_t *)"test", 4, &new_err);
ck_assert_msg(new_err == TOX_ERR_GROUP_NEW_OK, "tox_group_new failed: %d", new_err); ck_assert_msg(new_err == TOX_ERR_GROUP_NEW_OK, "tox_group_new failed: %u", new_err);
iterate_group(autotoxes, NUM_GROUP_TOXES, GROUP_ITERATION_INTERVAL); iterate_group(autotoxes, NUM_GROUP_TOXES, GROUP_ITERATION_INTERVAL);
@@ -164,14 +164,14 @@ static void group_tcp_test(AutoTox *autotoxes)
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(autotoxes[0].tox, groupnumber, chat_id, &id_err); tox_group_get_chat_id(autotoxes[0].tox, groupnumber, chat_id, &id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%d", id_err); ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "%u", id_err);
printf("Tox 0 created new group...\n"); printf("Tox 0 created new group...\n");
for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) { for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) {
Tox_Err_Group_Join jerr; Tox_Err_Group_Join jerr;
tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)"test", 4, nullptr, 0, &jerr); tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)"test", 4, nullptr, 0, &jerr);
ck_assert_msg(jerr == TOX_ERR_GROUP_JOIN_OK, "%d", jerr); ck_assert_msg(jerr == TOX_ERR_GROUP_JOIN_OK, "%u", jerr);
iterate_group(autotoxes, NUM_GROUP_TOXES, GROUP_ITERATION_INTERVAL * 10); iterate_group(autotoxes, NUM_GROUP_TOXES, GROUP_ITERATION_INTERVAL * 10);
} }
@@ -187,7 +187,7 @@ static void group_tcp_test(AutoTox *autotoxes)
tox_group_send_private_message(autotoxes[0].tox, groupnumber, state0->peer_id[i], tox_group_send_private_message(autotoxes[0].tox, groupnumber, state0->peer_id[i],
TOX_MESSAGE_TYPE_NORMAL, TOX_MESSAGE_TYPE_NORMAL,
(const uint8_t *)CODEWORD, CODEWORD_LEN, &perr); (const uint8_t *)CODEWORD, CODEWORD_LEN, &perr);
ck_assert_msg(perr == TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_OK, "%d", perr); ck_assert_msg(perr == TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_OK, "%u", perr);
} }
while (!all_peers_got_code(autotoxes)) while (!all_peers_got_code(autotoxes))

View File

@@ -241,7 +241,7 @@ static void group_topic_test(AutoTox *autotoxes)
GROUP_NAME_LEN, GROUP_NAME_LEN,
(const uint8_t *)PEER0_NICK, PEER0_NICK_LEN, &new_err); (const uint8_t *)PEER0_NICK, PEER0_NICK_LEN, &new_err);
ck_assert_msg(new_err == TOX_ERR_GROUP_NEW_OK, "tox_group_new failed: %d", new_err); ck_assert_msg(new_err == TOX_ERR_GROUP_NEW_OK, "tox_group_new failed: %u", new_err);
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
@@ -254,7 +254,7 @@ static void group_topic_test(AutoTox *autotoxes)
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err); tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err);
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "tox_group_get_chat_id failed %d", id_err); ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERY_OK, "tox_group_get_chat_id failed %u", id_err);
/* All other peers join the group using the Chat ID */ /* All other peers join the group using the Chat ID */
for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) { for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) {
@@ -262,7 +262,7 @@ static void group_topic_test(AutoTox *autotoxes)
Tox_Err_Group_Join join_err; Tox_Err_Group_Join join_err;
tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err); tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err);
ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "tox_group_join failed: %d", join_err); ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "tox_group_join failed: %u", join_err);
c_sleep(100); c_sleep(100);
} }
@@ -276,7 +276,7 @@ static void group_topic_test(AutoTox *autotoxes)
/* Founder disables topic lock */ /* Founder disables topic lock */
Tox_Err_Group_Set_Topic_Lock lock_set_err; Tox_Err_Group_Set_Topic_Lock lock_set_err;
tox_group_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err); tox_group_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to disable topic lock: %d", ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to disable topic lock: %u",
lock_set_err); lock_set_err);
fprintf(stderr, "Topic lock disabled\n"); fprintf(stderr, "Topic lock disabled\n");
@@ -292,7 +292,7 @@ static void group_topic_test(AutoTox *autotoxes)
/* founder silences the last peer he saw join */ /* founder silences the last peer he saw join */
Tox_Err_Group_Set_Role merr; Tox_Err_Group_Set_Role merr;
tox_group_set_role(tox0, groupnumber, state0->peer_id, TOX_GROUP_ROLE_OBSERVER, &merr); tox_group_set_role(tox0, groupnumber, state0->peer_id, TOX_GROUP_ROLE_OBSERVER, &merr);
ck_assert_msg(merr == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set %u to observer role: %d", state0->peer_id, merr); ck_assert_msg(merr == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set %u to observer role: %u", state0->peer_id, merr);
fprintf(stderr, "Random peer is set to observer\n"); fprintf(stderr, "Random peer is set to observer\n");
@@ -305,7 +305,7 @@ static void group_topic_test(AutoTox *autotoxes)
/* Founder enables topic lock and sets topic back to original */ /* Founder enables topic lock and sets topic back to original */
tox_group_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_ENABLED, &lock_set_err); tox_group_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_ENABLED, &lock_set_err);
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to enable topic lock: %d", ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to enable topic lock: %u",
lock_set_err); lock_set_err);
fprintf(stderr, "Topic lock enabled\n"); fprintf(stderr, "Topic lock enabled\n");
@@ -330,7 +330,7 @@ static void group_topic_test(AutoTox *autotoxes)
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) { for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
Tox_Err_Group_Leave err_exit; Tox_Err_Group_Leave err_exit;
tox_group_leave(autotoxes[i].tox, groupnumber, nullptr, 0, &err_exit); tox_group_leave(autotoxes[i].tox, groupnumber, nullptr, 0, &err_exit);
ck_assert_msg(err_exit == TOX_ERR_GROUP_LEAVE_OK, "%d", err_exit); ck_assert_msg(err_exit == TOX_ERR_GROUP_LEAVE_OK, "%u", err_exit);
} }
fprintf(stderr, "All tests passed!\n"); fprintf(stderr, "All tests passed!\n");

View File

@@ -32,7 +32,7 @@ int main(void)
// None of the iterations should have a connection. // None of the iterations should have a connection.
const Tox_Connection status = tox_self_get_connection_status(tox); const Tox_Connection status = tox_self_get_connection_status(tox);
ck_assert_msg(status == TOX_CONNECTION_NONE, ck_assert_msg(status == TOX_CONNECTION_NONE,
"unexpectedly got a connection (%d)", status); "unexpectedly got a connection (%u)", status);
} }
tox_kill(tox); tox_kill(tox);

View File

@@ -32,7 +32,7 @@ int main(void)
// None of the iterations should have a connection. // None of the iterations should have a connection.
const Tox_Connection status = tox_self_get_connection_status(tox); const Tox_Connection status = tox_self_get_connection_status(tox);
ck_assert_msg(status == TOX_CONNECTION_NONE, ck_assert_msg(status == TOX_CONNECTION_NONE,
"unexpectedly got a connection (%d)", status); "unexpectedly got a connection (%u)", status);
} }
tox_kill(tox); tox_kill(tox);

View File

@@ -43,7 +43,7 @@ int main(void)
} while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || } while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE ||
tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE); tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE);
printf(" %d <-> %d\n", printf(" %u <-> %u\n",
tox_self_get_connection_status(tox1), tox_self_get_connection_status(tox1),
tox_self_get_connection_status(tox2)); tox_self_get_connection_status(tox2));

View File

@@ -112,7 +112,7 @@ int main(void)
Tox_Err_Options_New options_err; Tox_Err_Options_New options_err;
struct Tox_Options *tox_opts = tox_options_new(&options_err); struct Tox_Options *tox_opts = tox_options_new(&options_err);
ck_assert_msg(options_err == TOX_ERR_OPTIONS_NEW_OK, "Failed to initialize tox options: %d\n", options_err); ck_assert_msg(options_err == TOX_ERR_OPTIONS_NEW_OK, "Failed to initialize tox options: %u\n", options_err);
tox_options_default(tox_opts); tox_options_default(tox_opts);
tox_options_set_udp_enabled(tox_opts, true); tox_options_set_udp_enabled(tox_opts, true);

View File

@@ -43,7 +43,7 @@ static void net_crypto_overflow_test(AutoTox *autotoxes)
} }
ck_assert_msg(err == TOX_ERR_FRIEND_SEND_MESSAGE_OK, ck_assert_msg(err == TOX_ERR_FRIEND_SEND_MESSAGE_OK,
"tox%u failed to send message number %u: %d", tox_index, i, err); "tox%u failed to send message number %u: %u", tox_index, i, err);
} }
} }

View File

@@ -24,10 +24,10 @@ static void net_crypto_overflow_test(AutoTox *autotoxes)
// As soon as we get the first error, we expect the same error (SENDQ) // As soon as we get the first error, we expect the same error (SENDQ)
// every time we try to send. // every time we try to send.
ck_assert_msg(err == TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ, ck_assert_msg(err == TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ,
"expected SENDQ error on message %u, but got %d", i, err); "expected SENDQ error on message %u, but got %u", i, err);
} else { } else {
ck_assert_msg(err == TOX_ERR_FRIEND_SEND_MESSAGE_OK, ck_assert_msg(err == TOX_ERR_FRIEND_SEND_MESSAGE_OK,
"failed to send message number %u: %d", i, err); "failed to send message number %u: %u", i, err);
} }
} }

View File

@@ -23,7 +23,7 @@ static bool try_bootstrap(Tox *tox1, Tox *tox2, Tox *tox3, Tox *tox4)
tox_self_get_connection_status(tox2) != TOX_CONNECTION_NONE && tox_self_get_connection_status(tox2) != TOX_CONNECTION_NONE &&
tox_self_get_connection_status(tox3) != TOX_CONNECTION_NONE && tox_self_get_connection_status(tox3) != TOX_CONNECTION_NONE &&
tox_self_get_connection_status(tox4) != TOX_CONNECTION_NONE) { tox_self_get_connection_status(tox4) != TOX_CONNECTION_NONE) {
printf("%d %d %d %d\n", printf("%u %u %u %u\n",
tox_self_get_connection_status(tox1), tox_self_get_connection_status(tox1),
tox_self_get_connection_status(tox2), tox_self_get_connection_status(tox2),
tox_self_get_connection_status(tox3), tox_self_get_connection_status(tox3),
@@ -37,7 +37,7 @@ static bool try_bootstrap(Tox *tox1, Tox *tox2, Tox *tox3, Tox *tox4)
tox_iterate(tox4, nullptr); tox_iterate(tox4, nullptr);
if (i % 10 == 0) { if (i % 10 == 0) {
printf("%d %d %d %d\n", printf("%u %u %u %u\n",
tox_self_get_connection_status(tox1), tox_self_get_connection_status(tox1),
tox_self_get_connection_status(tox2), tox_self_get_connection_status(tox2),
tox_self_get_connection_status(tox3), tox_self_get_connection_status(tox3),

View File

@@ -84,7 +84,7 @@ static void test_save_compatibility(const char *save_path)
size_t index = 0; size_t index = 0;
Tox_Err_New err; Tox_Err_New err;
Tox *tox = tox_new_log(options, &err, &index); Tox *tox = tox_new_log(options, &err, &index);
ck_assert_msg(tox, "failed to create tox, error number: %d", err); ck_assert_msg(tox, "failed to create tox, error number: %u", err);
tox_options_free(options); tox_options_free(options);
free(save_data); free(save_data);

View File

@@ -54,7 +54,7 @@ static void tox_connection_status(const Tox_Event_Self_Connection_Status *event,
ck_abort_msg("Tox went offline"); ck_abort_msg("Tox went offline");
} }
ck_assert_msg(connection_status != TOX_CONNECTION_NONE, "wrong status %d", connection_status); ck_assert_msg(connection_status != TOX_CONNECTION_NONE, "wrong status %u", connection_status);
connected_t1 = connection_status; connected_t1 = connection_status;
} }
@@ -153,7 +153,7 @@ static void test_few_clients(void)
tox_options_set_tcp_port(opts1, TCP_RELAY_PORT); tox_options_set_tcp_port(opts1, TCP_RELAY_PORT);
Tox_Err_New t_n_error; Tox_Err_New t_n_error;
Tox *tox1 = tox_new_log(opts1, &t_n_error, &index[0]); Tox *tox1 = tox_new_log(opts1, &t_n_error, &index[0]);
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %d", t_n_error); ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %u", t_n_error);
tox_options_free(opts1); tox_options_free(opts1);
tox_events_init(tox1); tox_events_init(tox1);
Tox_Dispatch *dispatch1 = tox_dispatch_new(nullptr); Tox_Dispatch *dispatch1 = tox_dispatch_new(nullptr);
@@ -164,7 +164,7 @@ static void test_few_clients(void)
tox_options_set_udp_enabled(opts2, false); tox_options_set_udp_enabled(opts2, false);
tox_options_set_local_discovery_enabled(opts2, false); tox_options_set_local_discovery_enabled(opts2, false);
Tox *tox2 = tox_new_log(opts2, &t_n_error, &index[1]); Tox *tox2 = tox_new_log(opts2, &t_n_error, &index[1]);
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %d", t_n_error); ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %u", t_n_error);
tox_events_init(tox2); tox_events_init(tox2);
Tox_Dispatch *dispatch2 = tox_dispatch_new(nullptr); Tox_Dispatch *dispatch2 = tox_dispatch_new(nullptr);
ck_assert(dispatch2 != nullptr); ck_assert(dispatch2 != nullptr);
@@ -173,7 +173,7 @@ static void test_few_clients(void)
tox_options_set_ipv6_enabled(opts3, USE_IPV6); tox_options_set_ipv6_enabled(opts3, USE_IPV6);
tox_options_set_local_discovery_enabled(opts3, false); tox_options_set_local_discovery_enabled(opts3, false);
Tox *tox3 = tox_new_log(opts3, &t_n_error, &index[2]); Tox *tox3 = tox_new_log(opts3, &t_n_error, &index[2]);
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %d", t_n_error); ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %u", t_n_error);
ck_assert_msg(tox1 && tox2 && tox3, "Failed to create 3 tox instances"); ck_assert_msg(tox1 && tox2 && tox3, "Failed to create 3 tox instances");

View File

@@ -50,10 +50,10 @@ static void send_message_test(AutoTox *autotoxes)
Tox_Err_Friend_Send_Message errm; Tox_Err_Friend_Send_Message errm;
tox_friend_send_message(autotoxes[0].tox, 0, TOX_MESSAGE_TYPE_NORMAL, msgs, msgs_len, &errm); tox_friend_send_message(autotoxes[0].tox, 0, TOX_MESSAGE_TYPE_NORMAL, msgs, msgs_len, &errm);
ck_assert_msg(errm == TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG, "tox_max_message_length() is too small? error=%d", errm); ck_assert_msg(errm == TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG, "tox_max_message_length() is too small? error=%u", errm);
tox_friend_send_message(autotoxes[0].tox, 0, TOX_MESSAGE_TYPE_NORMAL, msgs, tox_max_message_length(), &errm); tox_friend_send_message(autotoxes[0].tox, 0, TOX_MESSAGE_TYPE_NORMAL, msgs, tox_max_message_length(), &errm);
ck_assert_msg(errm == TOX_ERR_FRIEND_SEND_MESSAGE_OK, "tox_max_message_length() is too big? error=%d", errm); ck_assert_msg(errm == TOX_ERR_FRIEND_SEND_MESSAGE_OK, "tox_max_message_length() is too big? error=%u", errm);
free(msgs); free(msgs);

View File

@@ -92,7 +92,7 @@ static void test_set_name(void)
tox_events_callback_friend_name(dispatch2, nickchange_callback); tox_events_callback_friend_name(dispatch2, nickchange_callback);
Tox_Err_Set_Info err_n; Tox_Err_Set_Info err_n;
bool ret = tox_self_set_name(tox1, (const uint8_t *)NICKNAME, sizeof(NICKNAME), &err_n); bool ret = tox_self_set_name(tox1, (const uint8_t *)NICKNAME, sizeof(NICKNAME), &err_n);
ck_assert_msg(ret && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_name failed because %d\n", err_n); ck_assert_msg(ret && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_name failed because %u\n", err_n);
bool nickname_updated = false; bool nickname_updated = false;

View File

@@ -93,7 +93,7 @@ static void test_set_status_message(void)
Tox_Err_Set_Info err_n; Tox_Err_Set_Info err_n;
bool ret = tox_self_set_status_message(tox1, (const uint8_t *)STATUS_MESSAGE, sizeof(STATUS_MESSAGE), bool ret = tox_self_set_status_message(tox1, (const uint8_t *)STATUS_MESSAGE, sizeof(STATUS_MESSAGE),
&err_n); &err_n);
ck_assert_msg(ret && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_status_message failed because %d\n", err_n); ck_assert_msg(ret && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_status_message failed because %u\n", err_n);
bool status_updated = false; bool status_updated = false;

View File

@@ -35,8 +35,8 @@ int main(void)
const Tox_Connection status = tox_self_get_connection_status(tox_tcp); const Tox_Connection status = tox_self_get_connection_status(tox_tcp);
ck_assert_msg(status == TOX_CONNECTION_TCP, ck_assert_msg(status == TOX_CONNECTION_TCP,
"expected TCP connection, but got %d", status); "expected TCP connection, but got %u", status);
printf("Connection (TCP): %d\n", status); printf("Connection (TCP): %u\n", status);
tox_kill(tox_tcp); tox_kill(tox_tcp);

View File

@@ -88,7 +88,7 @@ static void test_many_clients_tcp(void)
uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; uint8_t dpk[TOX_PUBLIC_KEY_SIZE];
tox_self_get_dht_id(toxes[0], dpk); tox_self_get_dht_id(toxes[0], dpk);
Tox_Err_Bootstrap error; Tox_Err_Bootstrap error;
ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, tcp_relay_port, dpk, &error), "add relay error, %u, %d", i, ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, tcp_relay_port, dpk, &error), "add relay error, %u, %u", i,
error); error);
uint16_t first_port = tox_self_get_udp_port(toxes[0], nullptr); uint16_t first_port = tox_self_get_udp_port(toxes[0], nullptr);
ck_assert_msg(tox_bootstrap(toxes[i], TOX_LOCALHOST, first_port, dpk, nullptr), "Bootstrap error"); ck_assert_msg(tox_bootstrap(toxes[i], TOX_LOCALHOST, first_port, dpk, nullptr), "Bootstrap error");
@@ -128,7 +128,7 @@ loop_top:
goto loop_top; goto loop_top;
} }
ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test); ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %u", test);
} }
while (true) { while (true) {
@@ -233,7 +233,7 @@ loop_top:
goto loop_top; goto loop_top;
} }
ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %i", test); ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "Failed to add friend error code: %u", test);
} }
uint16_t last_count = 0; uint16_t last_count = 0;

View File

@@ -90,7 +90,7 @@ loop_top:
tox_bootstrap(toxes[pairs[i].tox2], "localhost", dht_port, dht_key, nullptr); tox_bootstrap(toxes[pairs[i].tox2], "localhost", dht_port, dht_key, nullptr);
ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "failed to add friend error code: %i", test); ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "failed to add friend error code: %u", test);
} }
for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) { for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {

View File

@@ -27,7 +27,7 @@
Toxav_Err_Call_Control cc_err; \ Toxav_Err_Call_Control cc_err; \
bool ok = toxav_call_control(a, b, c, &cc_err); \ bool ok = toxav_call_control(a, b, c, &cc_err); \
if (!ok) { \ if (!ok) { \
printf("toxav_call_control returned error %d\n", cc_err); \ printf("toxav_call_control returned error %u\n", cc_err); \
} \ } \
ck_assert(ok); \ ck_assert(ok); \
ck_assert(cc_err == TOXAV_ERR_CALL_CONTROL_OK); \ ck_assert(cc_err == TOXAV_ERR_CALL_CONTROL_OK); \
@@ -115,7 +115,7 @@ static void regular_call_flow(
Toxav_Err_Call call_err; Toxav_Err_Call call_err;
toxav_call(alice_av, 0, a_br, v_br, &call_err); toxav_call(alice_av, 0, a_br, v_br, &call_err);
ck_assert_msg(call_err == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", call_err); ck_assert_msg(call_err == TOXAV_ERR_CALL_OK, "toxav_call failed: %u\n", call_err);
const time_t start_time = time(nullptr); const time_t start_time = time(nullptr);
@@ -124,7 +124,7 @@ static void regular_call_flow(
Toxav_Err_Answer answer_err; Toxav_Err_Answer answer_err;
toxav_answer(bob_av, 0, a_br, v_br, &answer_err); toxav_answer(bob_av, 0, a_br, v_br, &answer_err);
ck_assert_msg(answer_err == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", answer_err); ck_assert_msg(answer_err == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %u\n", answer_err);
bob_cc->incoming = false; bob_cc->incoming = false;
} else { /* TODO(mannol): rtp */ } else { /* TODO(mannol): rtp */
@@ -133,7 +133,7 @@ static void regular_call_flow(
Toxav_Err_Call_Control cc_err; Toxav_Err_Call_Control cc_err;
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &cc_err); toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &cc_err);
ck_assert_msg(cc_err == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", cc_err); ck_assert_msg(cc_err == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %u\n", cc_err);
} }
} }
@@ -253,7 +253,7 @@ static void test_av_flows(void)
Toxav_Err_Call rc; Toxav_Err_Call rc;
toxav_call(alice_av, 0, 48, 0, &rc); toxav_call(alice_av, 0, 48, 0, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc); ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %u\n", rc);
} }
do { do {
@@ -265,7 +265,7 @@ static void test_av_flows(void)
Toxav_Err_Call_Control rc; Toxav_Err_Call_Control rc;
toxav_call_control(bob_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); toxav_call_control(bob_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc); ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %u\n", rc);
} }
do { do {
@@ -285,7 +285,7 @@ static void test_av_flows(void)
Toxav_Err_Call rc; Toxav_Err_Call rc;
toxav_call(alice_av, 0, 48, 0, &rc); toxav_call(alice_av, 0, 48, 0, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc); ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %u\n", rc);
} }
do { do {
@@ -297,7 +297,7 @@ static void test_av_flows(void)
Toxav_Err_Call_Control rc; Toxav_Err_Call_Control rc;
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc); ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %u\n", rc);
} }
/* Alice will not receive end state */ /* Alice will not receive end state */
@@ -319,7 +319,7 @@ static void test_av_flows(void)
Toxav_Err_Call rc; Toxav_Err_Call rc;
toxav_call(alice_av, 0, 48, 1000, &rc); toxav_call(alice_av, 0, 48, 1000, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc); ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %u\n", rc);
} }
do { do {
@@ -338,7 +338,7 @@ static void test_av_flows(void)
Toxav_Err_Answer rc; Toxav_Err_Answer rc;
toxav_answer(bob_av, 0, 48, 4000, &rc); toxav_answer(bob_av, 0, 48, 4000, &rc);
ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", rc); ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %u\n", rc);
} }
iterate_tox(bootstrap, alice, bob); iterate_tox(bootstrap, alice, bob);
@@ -380,7 +380,7 @@ static void test_av_flows(void)
Toxav_Err_Call_Control rc; Toxav_Err_Call_Control rc;
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc); ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %u\n", rc);
} }
iterate_tox(bootstrap, alice, bob); iterate_tox(bootstrap, alice, bob);
@@ -400,7 +400,7 @@ static void test_av_flows(void)
Toxav_Err_Call rc; Toxav_Err_Call rc;
toxav_call(alice_av, 0, 48, 0, &rc); toxav_call(alice_av, 0, 48, 0, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc); ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %u\n", rc);
} }
do { do {
@@ -411,7 +411,7 @@ static void test_av_flows(void)
Toxav_Err_Answer rc; Toxav_Err_Answer rc;
toxav_answer(bob_av, 0, 48, 0, &rc); toxav_answer(bob_av, 0, 48, 0, &rc);
ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", rc); ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %u\n", rc);
} }
iterate_tox(bootstrap, alice, bob); iterate_tox(bootstrap, alice, bob);
@@ -439,7 +439,7 @@ static void test_av_flows(void)
Toxav_Err_Call_Control rc; Toxav_Err_Call_Control rc;
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc); ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %u\n", rc);
} }
iterate_tox(bootstrap, alice, bob); iterate_tox(bootstrap, alice, bob);
@@ -459,7 +459,7 @@ static void test_av_flows(void)
Toxav_Err_Call rc; Toxav_Err_Call rc;
toxav_call(alice_av, 0, 48, 0, &rc); toxav_call(alice_av, 0, 48, 0, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc); ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %u\n", rc);
} }
do { do {
@@ -470,7 +470,7 @@ static void test_av_flows(void)
Toxav_Err_Answer rc; Toxav_Err_Answer rc;
toxav_answer(bob_av, 0, 48, 0, &rc); toxav_answer(bob_av, 0, 48, 0, &rc);
ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", rc); ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %u\n", rc);
} }
iterate_tox(bootstrap, alice, bob); iterate_tox(bootstrap, alice, bob);
@@ -488,7 +488,7 @@ static void test_av_flows(void)
Toxav_Err_Call_Control rc; Toxav_Err_Call_Control rc;
toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc);
ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc); ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %u\n", rc);
} }
iterate_tox(bootstrap, alice, bob); iterate_tox(bootstrap, alice, bob);

View File

@@ -297,7 +297,7 @@ static void test_av_three_calls(void)
toxav_call(alice_av, tds[i].friend_number, 48, 3000, &rc); toxav_call(alice_av, tds[i].friend_number, 48, 3000, &rc);
if (rc != TOXAV_ERR_CALL_OK) { if (rc != TOXAV_ERR_CALL_OK) {
printf("toxav_call failed: %d\n", rc); printf("toxav_call failed: %u\n", rc);
ck_assert(0); ck_assert(0);
} }
} }
@@ -316,7 +316,7 @@ static void test_av_three_calls(void)
toxav_answer(bobs_av[i], 0, 8, 500, &rc); toxav_answer(bobs_av[i], 0, 8, 500, &rc);
if (rc != TOXAV_ERR_ANSWER_OK) { if (rc != TOXAV_ERR_ANSWER_OK) {
printf("toxav_answer failed: %d\n", rc); printf("toxav_answer failed: %u\n", rc);
ck_assert(0); ck_assert(0);
} }
@@ -334,7 +334,7 @@ static void test_av_three_calls(void)
toxav_call_control(alice_av, i, TOXAV_CALL_CONTROL_CANCEL, &rc); toxav_call_control(alice_av, i, TOXAV_CALL_CONTROL_CANCEL, &rc);
if (rc != TOXAV_ERR_CALL_CONTROL_OK) { if (rc != TOXAV_ERR_CALL_CONTROL_OK) {
printf("toxav_call_control failed: %d %p %p\n", rc, (void *)alice_av, (void *)&bobs_av[i]); printf("toxav_call_control failed: %u %p %p\n", rc, (void *)alice_av, (void *)&bobs_av[i]);
} }
} }

View File

@@ -25,15 +25,18 @@ run() {
-Wno-missing-braces \ -Wno-missing-braces \
-Wno-missing-field-initializers \ -Wno-missing-field-initializers \
-Wno-missing-noreturn \ -Wno-missing-noreturn \
-Wno-nullability-completeness \
-Wno-nullability-extension \
-Wno-nullable-to-nonnull-conversion \
-Wno-old-style-cast \ -Wno-old-style-cast \
-Wno-padded \ -Wno-padded \
-Wno-source-uses-openmp \
-Wno-switch-default \ -Wno-switch-default \
-Wno-tautological-pointer-compare \ -Wno-tautological-pointer-compare \
-Wno-unreachable-code-return \ -Wno-unreachable-code-return \
-Wno-unsafe-buffer-usage \ -Wno-unsafe-buffer-usage \
-Wno-unused-parameter \ -Wno-unused-parameter \
-Wno-used-but-marked-unused \ -Wno-used-but-marked-unused
-Wno-source-uses-openmp
} }
. other/analysis/variants.sh . other/analysis/variants.sh

View File

@@ -7,6 +7,11 @@ ERRORS="*"
# Still good to occasionally look at. # Still good to occasionally look at.
ERRORS="$ERRORS,-google-readability-casting" ERRORS="$ERRORS,-google-readability-casting"
# TODO(iphydf): Fix these.
CHECKS="$CHECKS,-clang-analyzer-nullability.NullableDereferenced"
CHECKS="$CHECKS,-clang-analyzer-nullability.NullablePassedToNonnull"
CHECKS="$CHECKS,-clang-analyzer-nullability.NullPassedToNonnull"
# Need to investigate or disable and document these. # Need to investigate or disable and document these.
# ========================================================= # =========================================================

View File

@@ -12,8 +12,12 @@ CPPCHECK+=("--check-level=exhaustive")
CPPCHECK+=("--inline-suppr") CPPCHECK+=("--inline-suppr")
CPPCHECK+=("--library=other/docker/cppcheck/toxcore.cfg") CPPCHECK+=("--library=other/docker/cppcheck/toxcore.cfg")
CPPCHECK+=("--error-exitcode=1") CPPCHECK+=("--error-exitcode=1")
# Some files don't match all our suppressions below.
CPPCHECK+=("--suppress=unmatchedSuppression")
# We don't cast function pointers, which cppcheck suggests here. # We don't cast function pointers, which cppcheck suggests here.
CPPCHECK+=("--suppress=constParameterCallback") CPPCHECK+=("--suppress=constParameterCallback")
# This disagrees with clang's warnings.
CPPCHECK+=("--suppress=invalidPrintfArgType_uint")
# False positives in switch statements. # False positives in switch statements.
CPPCHECK+=("--suppress=knownConditionTrueFalse") CPPCHECK+=("--suppress=knownConditionTrueFalse")
# Cppcheck does not need standard library headers to get proper results. # Cppcheck does not need standard library headers to get proper results.

View File

@@ -1,5 +1,5 @@
FROM toxchat/c-toxcore:sources AS sources FROM toxchat/c-toxcore:sources AS sources
FROM ghcr.io/goblint/analyzer:latest FROM ghcr.io/goblint/analyzer:2.5.0
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 \

View File

@@ -216,17 +216,6 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
// gen setters and getters // gen setters and getters
for (const auto& t : event_types) { for (const auto& t : event_types) {
// setter // setter
std::visit(
overloaded{
[&](const EventTypeTrivial& t) {
f << "non_null()\n";
},
[&](const EventTypeByteRange& t) {
f << "non_null(1) nullable(2)\n";
}
},
t
);
f << "static " << (t.index() == 0 ? "void" : "bool") << " tox_event_" << event_name_l << "_set_"; f << "static " << (t.index() == 0 ? "void" : "bool") << " tox_event_" << event_name_l << "_set_";
std::visit( std::visit(
overloaded{ overloaded{
@@ -239,15 +228,14 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
}, },
t t
); );
f << "(Tox_Event_" << event_name << " *" << event_name_l << ",\n"; f << "(Tox_Event_" << event_name << " *_Nonnull " << event_name_l << ",";
f << " ";
std::visit( std::visit(
overloaded{ overloaded{
[&](const EventTypeTrivial& t) { [&](const EventTypeTrivial& t) {
f << t.type << " " << t.name << ")\n"; f << " " << t.type << " " << t.name << ")\n";
}, },
[&](const EventTypeByteRange& t) { [&](const EventTypeByteRange& t) {
f << "const uint8_t *" << t.name_data << ", uint32_t " << t.name_length << ")\n"; f << "\n const uint8_t *_Nullable " << t.name_data << ", uint32_t " << t.name_length << ")\n";
} }
}, },
t t
@@ -259,7 +247,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
f << " " << event_name_l << "->" << t.name << " = " << t.name << ";\n"; f << " " << event_name_l << "->" << t.name << " = " << t.name << ";\n";
}, },
[&](const EventTypeByteRange& t) { [&](const EventTypeByteRange& t) {
f << "\n if (" << event_name_l << "->" << t.name_data << " != nullptr) {\n"; f << " if (" << event_name_l << "->" << t.name_data << " != nullptr) {\n";
f << " free(" << event_name_l << "->" << t.name_data << ");\n"; f << " free(" << event_name_l << "->" << t.name_data << ");\n";
f << " " << event_name_l << "->" << t.name_data << " = nullptr;\n"; f << " " << event_name_l << "->" << t.name_data << " = nullptr;\n";
f << " " << event_name_l << "->" << t.name_length << " = 0;\n"; f << " " << event_name_l << "->" << t.name_length << " = 0;\n";
@@ -308,16 +296,14 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
// gen contruct // gen contruct
f << "non_null()\n"; f << "static void tox_event_" << event_name_l << "_construct(Tox_Event_" << event_name << " *_Nonnull " << event_name_l << ")\n{\n";
f << "static void tox_event_" << event_name_l << "_construct(Tox_Event_" << event_name << " *" << event_name_l << ")\n{\n";
// TODO: initialize all members properly // TODO: initialize all members properly
// TODO: check if _NONE is universal // TODO: check if _NONE is universal
// str_toupper( // str_toupper(
f << " *" << event_name_l << " = (Tox_Event_" << event_name << ") {\n 0\n };\n}\n"; f << " *" << event_name_l << " = (Tox_Event_" << event_name << ") {\n 0\n };\n}\n";
// gen destruct // gen destruct
f << "non_null()\n"; f << "static void tox_event_" << event_name_l << "_destruct(Tox_Event_" << event_name << " *_Nonnull " << event_name_l << ", const Memory *_Nonnull mem)\n{\n";
f << "static void tox_event_" << event_name_l << "_destruct(Tox_Event_" << event_name << " *" << event_name_l << ", const Memory *mem)\n{\n";
size_t data_count = 0; size_t data_count = 0;
for (const auto& t : event_types) { for (const auto& t : event_types) {
std::visit( std::visit(
@@ -375,9 +361,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
f << ";\n}\n\n"; f << ";\n}\n\n";
// unpack // unpack
f << "non_null()\n"; f << "static bool tox_event_" << event_name_l << "_unpack_into(Tox_Event_" << event_name << " *_Nonnull event, Bin_Unpack *_Nonnull bu)\n{\n";
f << "static bool tox_event_" << event_name_l << "_unpack_into(\n";
f << " Tox_Event_" << event_name << " *event, Bin_Unpack *bu)\n{\n";
f << " assert(event != nullptr);\n"; f << " assert(event != nullptr);\n";
if (event_types.size() > 1) { if (event_types.size() > 1) {
f << " if (!bin_unpack_array_fixed(bu, " << event_types.size() << ", nullptr)) {\n return false;\n }\n\n"; f << " if (!bin_unpack_array_fixed(bu, " << event_types.size() << ", nullptr)) {\n return false;\n }\n\n";
@@ -437,8 +421,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
f << " mem_delete(mem, " << event_name_l << ");\n}\n\n"; f << " mem_delete(mem, " << event_name_l << ");\n}\n\n";
// add // add
f << "non_null()\n"; f << "static Tox_Event_" << event_name << " *tox_events_add_" << event_name_l << "(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)\n{\n";
f << "static Tox_Event_" << event_name << " *tox_events_add_" << event_name_l << "(Tox_Events *events, const Memory *mem)\n{\n";
f << " Tox_Event_" << event_name << " *const " << event_name_l << " = tox_event_" << event_name_l << "_new(mem);\n\n"; f << " Tox_Event_" << event_name << " *const " << event_name_l << " = tox_event_" << event_name_l << "_new(mem);\n\n";
f << " if (" << event_name_l << " == nullptr) {\n"; f << " if (" << event_name_l << " == nullptr) {\n";
f << " return nullptr;\n }\n\n"; f << " return nullptr;\n }\n\n";
@@ -461,8 +444,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
f << " return tox_event_" << event_name_l << "_unpack_into(*event, bu);\n}\n\n"; f << " return tox_event_" << event_name_l << "_unpack_into(*event, bu);\n}\n\n";
// alloc // alloc
f << "non_null()\n"; f << "static Tox_Event_" << event_name << " *tox_event_" << event_name_l << "_alloc(void *_Nonnull user_data)\n{\n";
f << "static Tox_Event_" << event_name << " *tox_event_" << event_name_l << "_alloc(void *user_data)\n{\n";
f << " Tox_Events_State *state = tox_events_alloc(user_data);\n"; f << " Tox_Events_State *state = tox_events_alloc(user_data);\n";
f << " assert(state != nullptr);\n\n"; f << " assert(state != nullptr);\n\n";
f << " if (state->events == nullptr) {\n return nullptr;\n }\n\n"; f << " if (state->events == nullptr) {\n return nullptr;\n }\n\n";

View File

@@ -46,7 +46,7 @@ static bool bootstrap_tox(Tox *tox)
free(key); free(key);
if (err != TOX_ERR_BOOTSTRAP_OK) { if (err != TOX_ERR_BOOTSTRAP_OK) {
printf("Failed to bootstrap. Error number: %d", err); printf("Failed to bootstrap. Error number: %u", err);
return false; return false;
} }
@@ -128,13 +128,13 @@ int main(int argc, char *argv[])
tox_self_set_name(tox, name, strlen((const char *)name), &err); tox_self_set_name(tox, name, strlen((const char *)name), &err);
if (err != TOX_ERR_SET_INFO_OK) { if (err != TOX_ERR_SET_INFO_OK) {
printf("Failed to set name. Error number %d\n", err); printf("Failed to set name. Error number %u\n", err);
} }
tox_self_set_status_message(tox, (const uint8_t *)GENERATED_STATUS_MESSAGE, strlen(GENERATED_STATUS_MESSAGE), &err); tox_self_set_status_message(tox, (const uint8_t *)GENERATED_STATUS_MESSAGE, strlen(GENERATED_STATUS_MESSAGE), &err);
if (err != TOX_ERR_SET_INFO_OK) { if (err != TOX_ERR_SET_INFO_OK) {
printf("Failed to set status. Error number: %d\n", err); printf("Failed to set status. Error number: %u\n", err);
} }
for (int i = 2; i < argc; i++) { //start at 2 because that is where the tox ids are for (int i = 2; i < argc; i++) { //start at 2 because that is where the tox ids are
@@ -145,7 +145,7 @@ int main(int argc, char *argv[])
free(address); free(address);
if (friend_err != TOX_ERR_FRIEND_ADD_OK) { if (friend_err != TOX_ERR_FRIEND_ADD_OK) {
printf("Failed to add friend number %d. Error number: %d\n", i - 1, friend_err); printf("Failed to add friend number %d. Error number: %u\n", i - 1, friend_err);
} }
} }

View File

@@ -110,7 +110,7 @@ void TestBootstrap(Fuzz_Data &input)
const char *message, void *user_data) { const char *message, void *user_data) {
// Log to stdout. // Log to stdout.
if (Fuzz_Data::FUZZ_DEBUG) { if (Fuzz_Data::FUZZ_DEBUG) {
std::printf("[tox1] %c %s:%d(%s): %s\n", tox_log_level_name(level), file, line, std::printf("[tox1] %c %s:%u(%s): %s\n", tox_log_level_name(level), file, line,
func, message); func, message);
} }
}); });

View File

@@ -144,7 +144,7 @@ void TestEndToEnd(Fuzz_Data &input)
const char *message, void *user_data) { const char *message, void *user_data) {
// Log to stdout. // Log to stdout.
if (Fuzz_Data::FUZZ_DEBUG) { if (Fuzz_Data::FUZZ_DEBUG) {
std::printf("[tox1] %c %s:%d(%s): %s\n", tox_log_level_name(level), file, line, std::printf("[tox1] %c %s:%u(%s): %s\n", tox_log_level_name(level), file, line,
func, message); func, message);
} }
}); });

View File

@@ -489,7 +489,7 @@ static bool reconfigure_audio_encoder(const Logger *log, OpusEncoder **e, uint32
*old_sr = new_sr; *old_sr = new_sr;
*old_ch = new_ch; *old_ch = new_ch;
LOGGER_DEBUG(log, "Reconfigured audio encoder br: %d sr: %d cc:%d", new_br, new_sr, new_ch); LOGGER_DEBUG(log, "Reconfigured audio encoder br: %u sr: %u cc:%d", new_br, new_sr, new_ch);
return true; return true;
} }
@@ -504,7 +504,7 @@ static bool reconfigure_audio_decoder(ACSession *ac, uint32_t sampling_rate, uin
OpusDecoder *new_dec = opus_decoder_create(sampling_rate, channels, &status); OpusDecoder *new_dec = opus_decoder_create(sampling_rate, channels, &status);
if (status != OPUS_OK) { if (status != OPUS_OK) {
LOGGER_ERROR(ac->log, "Error while starting audio decoder(%d %d): %s", sampling_rate, channels, opus_strerror(status)); LOGGER_ERROR(ac->log, "Error while starting audio decoder(%u %u): %s", sampling_rate, channels, opus_strerror(status));
return false; return false;
} }
@@ -515,7 +515,7 @@ static bool reconfigure_audio_decoder(ACSession *ac, uint32_t sampling_rate, uin
opus_decoder_destroy(ac->decoder); opus_decoder_destroy(ac->decoder);
ac->decoder = new_dec; ac->decoder = new_dec;
LOGGER_DEBUG(ac->log, "Reconfigured audio decoder sr: %d cc: %d", sampling_rate, channels); LOGGER_DEBUG(ac->log, "Reconfigured audio decoder sr: %u cc: %u", sampling_rate, channels);
} }
return true; return true;

View File

@@ -156,7 +156,7 @@ static void send_update(BWController *bwc)
tox_friend_send_lossy_packet(bwc->tox, bwc->friend_number, bwc_packet, sizeof(bwc_packet), &error); tox_friend_send_lossy_packet(bwc->tox, bwc->friend_number, bwc_packet, sizeof(bwc_packet), &error);
if (error != TOX_ERR_FRIEND_CUSTOM_PACKET_OK) { if (error != TOX_ERR_FRIEND_CUSTOM_PACKET_OK) {
LOGGER_WARNING(bwc->log, "BWC send failed: %d", error); LOGGER_WARNING(bwc->log, "BWC send failed: %u", error);
} }
} }

View File

@@ -183,7 +183,7 @@ bool check_peer_offline_status(const Logger *log, const Tox *tox, MSISession *se
if (f_con_status == TOX_CONNECTION_NONE) { if (f_con_status == TOX_CONNECTION_NONE) {
/* Friend is now offline */ /* Friend is now offline */
LOGGER_DEBUG(log, "Friend %d is now offline", friend_number); LOGGER_DEBUG(log, "Friend %u is now offline", friend_number);
pthread_mutex_lock(session->mutex); pthread_mutex_lock(session->mutex);
MSICall *call = get_call(session, friend_number); MSICall *call = get_call(session, friend_number);
@@ -575,7 +575,7 @@ static int send_error(const Logger *log, Tox *tox, uint32_t friend_number, MSIEr
assert(tox != nullptr); assert(tox != nullptr);
/* Send error message */ /* Send error message */
LOGGER_DEBUG(log, "Sending error: %d to friend: %d", error, friend_number); LOGGER_DEBUG(log, "Sending error: %u to friend: %u", error, friend_number);
MSIMessage msg; MSIMessage msg;
msg_init(&msg, REQU_POP); msg_init(&msg, REQU_POP);
@@ -590,7 +590,7 @@ static int send_error(const Logger *log, Tox *tox, uint32_t friend_number, MSIEr
static int invoke_callback_inner(const Logger *log, MSICall *call, MSICallbackID id) static int invoke_callback_inner(const Logger *log, MSICall *call, MSICallbackID id)
{ {
MSISession *session = call->session; MSISession *session = call->session;
LOGGER_DEBUG(log, "invoking callback function: %d", id); LOGGER_DEBUG(log, "invoking callback function: %u", id);
switch (id) { switch (id) {
case MSI_ON_INVITE: case MSI_ON_INVITE:
@@ -612,7 +612,7 @@ static int invoke_callback_inner(const Logger *log, MSICall *call, MSICallbackID
return session->capabilities_callback(session->av, call); return session->capabilities_callback(session->av, call);
} }
LOGGER_FATAL(log, "invalid callback id: %d", id); LOGGER_FATAL(log, "invalid callback id: %u", id);
return -1; return -1;
} }
@@ -803,7 +803,7 @@ static void handle_init(const Logger *log, MSICall *call, const MSIMessage *msg)
{ {
assert(call != nullptr); assert(call != nullptr);
LOGGER_DEBUG(log, LOGGER_DEBUG(log,
"Session: %p Handling 'init' friend: %d", (void *)call->session, call->friend_number); "Session: %p Handling 'init' friend: %u", (void *)call->session, call->friend_number);
if (!try_handle_init(log, call, msg)) { if (!try_handle_init(log, call, msg)) {
send_error(log, call->session->tox, call->friend_number, call->error); send_error(log, call->session->tox, call->friend_number, call->error);
@@ -815,7 +815,7 @@ static void handle_push(const Logger *log, MSICall *call, const MSIMessage *msg)
{ {
assert(call != nullptr); assert(call != nullptr);
LOGGER_DEBUG(log, "Session: %p Handling 'push' friend: %d", (void *)call->session, LOGGER_DEBUG(log, "Session: %p Handling 'push' friend: %u", (void *)call->session,
call->friend_number); call->friend_number);
if (!msg->capabilities.exists) { if (!msg->capabilities.exists) {
@@ -871,13 +871,13 @@ static void handle_pop(const Logger *log, MSICall *call, const MSIMessage *msg)
{ {
assert(call != nullptr); assert(call != nullptr);
LOGGER_DEBUG(log, "Session: %p Handling 'pop', friend id: %d", (void *)call->session, LOGGER_DEBUG(log, "Session: %p Handling 'pop', friend id: %u", (void *)call->session,
call->friend_number); call->friend_number);
/* callback errors are ignored */ /* callback errors are ignored */
if (msg->error.exists) { if (msg->error.exists) {
LOGGER_WARNING(log, "Friend detected an error: %d", msg->error.value); LOGGER_WARNING(log, "Friend detected an error: %u", msg->error.value);
call->error = msg->error.value; call->error = msg->error.value;
invoke_callback(log, call, MSI_ON_ERROR); invoke_callback(log, call, MSI_ON_ERROR);
} else { } else {

View File

@@ -308,7 +308,7 @@ static void update_bwc_values(RTPSession *session, const struct RTPMessage *msg)
bwc_add_recv(session->bwc, data_length_full); bwc_add_recv(session->bwc, data_length_full);
if (received_length_full < data_length_full) { if (received_length_full < data_length_full) {
LOGGER_DEBUG(session->log, "BWC: full length=%u received length=%d", data_length_full, received_length_full); LOGGER_DEBUG(session->log, "BWC: full length=%u received length=%u", data_length_full, received_length_full);
bwc_add_lost(session->bwc, data_length_full - received_length_full); bwc_add_lost(session->bwc, data_length_full - received_length_full);
} }
} }

View File

@@ -78,9 +78,9 @@ struct RTPHeader {
uint64_t flags; uint64_t flags;
/** /**
* The full 32 bit data offset of the current data chunk. The @ref * The full 32 bit data offset of the current data chunk. The
* offset_lower data member contains the lower 16 bits of this value. For * @ref offset_lower data member contains the lower 16 bits of this value.
* frames smaller than 64KiB, @ref offset_full and @ref offset_lower are * For frames smaller than 64KiB, @ref offset_full and @ref offset_lower are
* equal. * equal.
*/ */
uint32_t offset_full; uint32_t offset_full;

View File

@@ -737,10 +737,10 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_ra
goto RETURN; goto RETURN;
} }
LOGGER_DEBUG(av->log, "Setting new audio bitrate to: %d", bit_rate); LOGGER_DEBUG(av->log, "Setting new audio bitrate to: %u", bit_rate);
if (call->audio_bit_rate == bit_rate) { if (call->audio_bit_rate == bit_rate) {
LOGGER_DEBUG(av->log, "Audio bitrate already set to: %d", bit_rate); LOGGER_DEBUG(av->log, "Audio bitrate already set to: %u", bit_rate);
} else if (bit_rate == 0) { } else if (bit_rate == 0) {
LOGGER_DEBUG(av->log, "Turned off audio sending"); LOGGER_DEBUG(av->log, "Turned off audio sending");
@@ -768,7 +768,7 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_ra
goto RETURN; goto RETURN;
} }
} else { } else {
LOGGER_DEBUG(av->log, "Set new audio bit rate %d", bit_rate); LOGGER_DEBUG(av->log, "Set new audio bit rate %u", bit_rate);
} }
call->audio_bit_rate = bit_rate; call->audio_bit_rate = bit_rate;
@@ -810,10 +810,10 @@ bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_ra
goto RETURN; goto RETURN;
} }
LOGGER_DEBUG(av->log, "Setting new video bitrate to: %d", bit_rate); LOGGER_DEBUG(av->log, "Setting new video bitrate to: %u", bit_rate);
if (call->video_bit_rate == bit_rate) { if (call->video_bit_rate == bit_rate) {
LOGGER_DEBUG(av->log, "Video bitrate already set to: %d", bit_rate); LOGGER_DEBUG(av->log, "Video bitrate already set to: %u", bit_rate);
} else if (bit_rate == 0) { } else if (bit_rate == 0) {
LOGGER_DEBUG(av->log, "Turned off video sending"); LOGGER_DEBUG(av->log, "Turned off video sending");
@@ -841,7 +841,7 @@ bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_ra
goto RETURN; goto RETURN;
} }
} else { } else {
LOGGER_DEBUG(av->log, "Set new video bit rate %d", bit_rate); LOGGER_DEBUG(av->log, "Set new video bit rate %u", bit_rate);
} }
call->video_bit_rate = bit_rate; call->video_bit_rate = bit_rate;
@@ -1048,13 +1048,13 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
if (call->video_rtp->ssrc < VIDEO_SEND_X_KEYFRAMES_FIRST) { if (call->video_rtp->ssrc < VIDEO_SEND_X_KEYFRAMES_FIRST) {
// Key frame flag for first frames // Key frame flag for first frames
vpx_encode_flags = VPX_EFLAG_FORCE_KF; vpx_encode_flags = VPX_EFLAG_FORCE_KF;
LOGGER_DEBUG(av->log, "I_FRAME_FLAG:%d only-i-frame mode", call->video_rtp->ssrc); LOGGER_DEBUG(av->log, "I_FRAME_FLAG:%u only-i-frame mode", call->video_rtp->ssrc);
++call->video_rtp->ssrc; ++call->video_rtp->ssrc;
} else if (call->video_rtp->ssrc == VIDEO_SEND_X_KEYFRAMES_FIRST) { } else if (call->video_rtp->ssrc == VIDEO_SEND_X_KEYFRAMES_FIRST) {
// normal keyframe placement // normal keyframe placement
vpx_encode_flags = 0; vpx_encode_flags = 0;
LOGGER_DEBUG(av->log, "I_FRAME_FLAG:%d normal mode", call->video_rtp->ssrc); LOGGER_DEBUG(av->log, "I_FRAME_FLAG:%u normal mode", call->video_rtp->ssrc);
++call->video_rtp->ssrc; ++call->video_rtp->ssrc;
} }
@@ -1083,11 +1083,8 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
memcpy(img.planes[VPX_PLANE_V], v, (width / 2) * (height / 2)); memcpy(img.planes[VPX_PLANE_V], v, (width / 2) * (height / 2));
} }
// TODO(zoff99): don't hardcode this, let the application choose it
const unsigned long deadline = VPX_DL_REALTIME;
const vpx_codec_err_t vrc = vpx_codec_encode(call->video->encoder, &img, const vpx_codec_err_t vrc = vpx_codec_encode(call->video->encoder, &img,
call->video->frame_counter, 1, vpx_encode_flags, deadline); call->video->frame_counter, 1, vpx_encode_flags, VPX_DL_REALTIME);
vpx_img_free(&img); vpx_img_free(&img);

View File

@@ -14,22 +14,16 @@
typedef struct ToxAVCall ToxAVCall; typedef struct ToxAVCall ToxAVCall;
#endif /* TOXAV_CALL_DEFINED */ #endif /* TOXAV_CALL_DEFINED */
non_null() ToxAVCall *_Nullable call_get(ToxAV *_Nonnull av, uint32_t friend_number);
ToxAVCall *call_get(ToxAV *av, uint32_t friend_number);
non_null() RTPSession *_Nullable rtp_session_get(ToxAVCall *_Nonnull call, int payload_type);
RTPSession *rtp_session_get(ToxAVCall *call, int payload_type);
non_null() MSISession *_Nullable tox_av_msi_get(const ToxAV *_Nonnull av);
MSISession *tox_av_msi_get(const ToxAV *av);
non_null() BWController *_Nullable bwc_controller_get(const ToxAVCall *_Nonnull call);
BWController *bwc_controller_get(const ToxAVCall *call);
non_null() Mono_Time *_Nullable toxav_get_av_mono_time(const ToxAV *_Nonnull av);
Mono_Time *toxav_get_av_mono_time(const ToxAV *av);
non_null() const Logger *_Nonnull toxav_get_logger(const ToxAV *_Nonnull av);
const Logger *toxav_get_logger(const ToxAV *av);
#endif /* C_TOXCORE_TOXAV_HACKS_H */ #endif /* C_TOXCORE_TOXAV_HACKS_H */

View File

@@ -91,10 +91,10 @@ static void vc_init_encoder_cfg(const Logger *log, vpx_codec_enc_cfg_t *cfg, int
*/ */
if (kf_max_dist > 1) { if (kf_max_dist > 1) {
cfg->kf_max_dist = kf_max_dist; // a full frame every x frames minimum (can be more often, codec decides automatically) cfg->kf_max_dist = kf_max_dist; // a full frame every x frames minimum (can be more often, codec decides automatically)
LOGGER_DEBUG(log, "kf_max_dist=%d (1)", cfg->kf_max_dist); LOGGER_DEBUG(log, "kf_max_dist=%u (1)", cfg->kf_max_dist);
} else { } else {
cfg->kf_max_dist = VPX_MAX_DIST_START; cfg->kf_max_dist = VPX_MAX_DIST_START;
LOGGER_DEBUG(log, "kf_max_dist=%d (2)", cfg->kf_max_dist); LOGGER_DEBUG(log, "kf_max_dist=%u (2)", cfg->kf_max_dist);
} }
cfg->g_threads = VPX_MAX_ENCODER_THREADS; // Maximum number of threads to use cfg->g_threads = VPX_MAX_ENCODER_THREADS; // Maximum number of threads to use
@@ -213,7 +213,7 @@ VCSession *vc_new(const Logger *log, const Mono_Time *mono_time, ToxAV *av, uint
} }
/* /*
* VPX_CTRL_USE_TYPE(VP8E_SET_NOISE_SENSITIVITY, unsigned int) * VPX_CTRL_USE_TYPE(VP8E_SET_NOISE_SENSITIVITY, unsigned int)
* control function to set noise sensitivity * control function to set noise sensitivity
* 0: off, 1: OnYOnly, 2: OnYUV, 3: OnYUVAggressive, 4: Adaptive * 0: off, 1: OnYOnly, 2: OnYUV, 3: OnYUVAggressive, 4: Adaptive
*/ */

View File

@@ -194,8 +194,7 @@ const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t friend_num)
return dht->friends_list[friend_num].public_key; return dht->friends_list[friend_num].public_key;
} }
non_null() static bool assoc_timeout(uint64_t cur_time, const IPPTsPng *_Nonnull assoc)
static bool assoc_timeout(uint64_t cur_time, const IPPTsPng *assoc)
{ {
return (assoc->timestamp + BAD_NODE_TIMEOUT) <= cur_time; return (assoc->timestamp + BAD_NODE_TIMEOUT) <= cur_time;
} }
@@ -204,8 +203,7 @@ static bool assoc_timeout(uint64_t cur_time, const IPPTsPng *assoc)
* *
* If the ip_port is already IPv4 this function returns a copy of the original ip_port. * If the ip_port is already IPv4 this function returns a copy of the original ip_port.
*/ */
non_null() static IP_Port ip_port_normalize(const IP_Port *_Nonnull ip_port)
static IP_Port ip_port_normalize(const IP_Port *ip_port)
{ {
IP_Port res = *ip_port; IP_Port res = *ip_port;
@@ -404,8 +402,7 @@ int dht_create_packet(const Memory *mem, const Random *rng,
* *
* @retval true on success. * @retval true on success.
*/ */
non_null() static bool bin_pack_node_handler(const void *_Nonnull arr, uint32_t index, const Logger *_Nonnull logger, Bin_Pack *_Nonnull bp)
static bool bin_pack_node_handler(const void *arr, uint32_t index, const Logger *logger, Bin_Pack *bp)
{ {
const Node_format *nodes = (const Node_format *)arr; const Node_format *nodes = (const Node_format *)arr;
return bin_pack_ip_port(bp, logger, &nodes[index].ip_port) return bin_pack_ip_port(bp, logger, &nodes[index].ip_port)
@@ -465,11 +462,9 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed
* *
* @return index or UINT32_MAX if not found. * @return index or UINT32_MAX if not found.
*/ */
non_null(3) nullable(1) static uint32_t index_of_client_pk(const Client_data *_Nullable array, uint32_t size, const uint8_t *_Nonnull pk)
static uint32_t index_of_client_pk(const Client_data *array, uint32_t size, const uint8_t *pk)
{ {
assert(size == 0 || array != nullptr); assert(size == 0 || array != nullptr);
for (uint32_t i = 0; i < size; ++i) { for (uint32_t i = 0; i < size; ++i) {
if (pk_equal(array[i].public_key, pk)) { if (pk_equal(array[i].public_key, pk)) {
return i; return i;
@@ -479,11 +474,9 @@ static uint32_t index_of_client_pk(const Client_data *array, uint32_t size, cons
return UINT32_MAX; return UINT32_MAX;
} }
non_null(3) nullable(1) static uint32_t index_of_friend_pk(const DHT_Friend *_Nullable array, uint32_t size, const uint8_t *_Nonnull pk)
static uint32_t index_of_friend_pk(const DHT_Friend *array, uint32_t size, const uint8_t *pk)
{ {
assert(size == 0 || array != nullptr); assert(size == 0 || array != nullptr);
for (uint32_t i = 0; i < size; ++i) { for (uint32_t i = 0; i < size; ++i) {
if (pk_equal(array[i].public_key, pk)) { if (pk_equal(array[i].public_key, pk)) {
return i; return i;
@@ -493,11 +486,9 @@ static uint32_t index_of_friend_pk(const DHT_Friend *array, uint32_t size, const
return UINT32_MAX; return UINT32_MAX;
} }
non_null(3) nullable(1) static uint32_t index_of_node_pk(const Node_format *_Nullable array, uint32_t size, const uint8_t *_Nonnull pk)
static uint32_t index_of_node_pk(const Node_format *array, uint32_t size, const uint8_t *pk)
{ {
assert(size == 0 || array != nullptr); assert(size == 0 || array != nullptr);
for (uint32_t i = 0; i < size; ++i) { for (uint32_t i = 0; i < size; ++i) {
if (pk_equal(array[i].public_key, pk)) { if (pk_equal(array[i].public_key, pk)) {
return i; return i;
@@ -511,11 +502,9 @@ static uint32_t index_of_node_pk(const Node_format *array, uint32_t size, const
* *
* @return index or UINT32_MAX if not found. * @return index or UINT32_MAX if not found.
*/ */
non_null(3) nullable(1) static uint32_t index_of_client_ip_port(const Client_data *_Nullable array, uint32_t size, const IP_Port *_Nonnull ip_port)
static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size, const IP_Port *ip_port)
{ {
assert(size == 0 || array != nullptr); assert(size == 0 || array != nullptr);
for (uint32_t i = 0; i < size; ++i) { for (uint32_t i = 0; i < size; ++i) {
if ((net_family_is_ipv4(ip_port->ip.family) && ipport_equal(&array[i].assoc4.ip_port, ip_port)) || if ((net_family_is_ipv4(ip_port->ip.family) && ipport_equal(&array[i].assoc4.ip_port, ip_port)) ||
(net_family_is_ipv6(ip_port->ip.family) && ipport_equal(&array[i].assoc6.ip_port, ip_port))) { (net_family_is_ipv6(ip_port->ip.family) && ipport_equal(&array[i].assoc6.ip_port, ip_port))) {
@@ -527,9 +516,7 @@ static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size,
} }
/** Update ip_port of client if it's needed. */ /** Update ip_port of client if it's needed. */
non_null() static void update_client(const Logger *_Nonnull log, const Mono_Time *_Nonnull mono_time, int index, Client_data *_Nonnull client, const IP_Port *_Nonnull ip_port)
static void update_client(const Logger *log, const Mono_Time *mono_time, int index, Client_data *client,
const IP_Port *ip_port)
{ {
IPPTsPng *assoc; IPPTsPng *assoc;
int ip_version; int ip_version;
@@ -548,7 +535,7 @@ static void update_client(const Logger *log, const Mono_Time *mono_time, int ind
Ip_Ntoa ip_str_from; Ip_Ntoa ip_str_from;
Ip_Ntoa ip_str_to; Ip_Ntoa ip_str_to;
LOGGER_TRACE(log, "coipil[%u]: switching ipv%d from %s:%u to %s:%u", LOGGER_TRACE(log, "coipil[%u]: switching ipv%d from %s:%u to %s:%u",
index, ip_version, (unsigned int)index, ip_version,
net_ip_ntoa(&assoc->ip_port.ip, &ip_str_from), net_ip_ntoa(&assoc->ip_port.ip, &ip_str_from),
net_ntohs(assoc->ip_port.port), net_ntohs(assoc->ip_port.port),
net_ip_ntoa(&ip_port->ip, &ip_str_to), net_ip_ntoa(&ip_port->ip, &ip_str_to),
@@ -569,9 +556,8 @@ static void update_client(const Logger *log, const Mono_Time *mono_time, int ind
* If the id is already in the list with a different ip_port, update it. * If the id is already in the list with a different ip_port, update it.
* TODO(irungentoo): Maybe optimize this. * TODO(irungentoo): Maybe optimize this.
*/ */
non_null() static bool client_or_ip_port_in_list(const Logger *_Nonnull log, const Mono_Time *_Nonnull mono_time, Client_data *_Nonnull list, uint16_t length, const uint8_t *_Nonnull public_key,
static bool client_or_ip_port_in_list(const Logger *log, const Mono_Time *mono_time, Client_data *list, uint16_t length, const IP_Port *_Nonnull ip_port)
const uint8_t *public_key, const IP_Port *ip_port)
{ {
const uint64_t temp_time = mono_time_get(mono_time); const uint64_t temp_time = mono_time_get(mono_time);
uint32_t index = index_of_client_pk(list, length, public_key); uint32_t index = index_of_client_pk(list, length, public_key);
@@ -646,12 +632,8 @@ bool add_to_list(
/** /**
* helper for `get_close_nodes()`. argument list is a monster :D * helper for `get_close_nodes()`. argument list is a monster :D
*/ */
non_null() static void get_close_nodes_inner(uint64_t cur_time, const uint8_t *_Nonnull public_key, Node_format *_Nonnull nodes_list, uint32_t *_Nonnull num_nodes_ptr, Family sa_family,
static void get_close_nodes_inner( const Client_data *_Nonnull client_list, uint32_t client_list_length, bool is_lan, bool want_announce)
uint64_t cur_time, const uint8_t *public_key,
Node_format *nodes_list, uint32_t *num_nodes_ptr,
Family sa_family, const Client_data *client_list, uint32_t client_list_length,
bool is_lan, bool want_announce)
{ {
if (!net_family_is_ipv4(sa_family) && !net_family_is_ipv6(sa_family) && !net_family_is_unspec(sa_family)) { if (!net_family_is_ipv4(sa_family) && !net_family_is_ipv6(sa_family) && !net_family_is_unspec(sa_family)) {
return; return;
@@ -717,12 +699,8 @@ static void get_close_nodes_inner(
* *
* want_announce: return only nodes which implement the dht announcements protocol. * want_announce: return only nodes which implement the dht announcements protocol.
*/ */
non_null() static int get_somewhat_close_nodes(uint64_t cur_time, const uint8_t *_Nonnull public_key, Node_format nodes_list[_Nonnull MAX_SENT_NODES], Family sa_family,
static int get_somewhat_close_nodes( const Client_data *_Nonnull close_clientlist, const DHT_Friend *_Nonnull friends_list, uint16_t friends_list_size, bool is_lan, bool want_announce)
uint64_t cur_time, const uint8_t *public_key, Node_format nodes_list[MAX_SENT_NODES],
Family sa_family, const Client_data *close_clientlist,
const DHT_Friend *friends_list, uint16_t friends_list_size,
bool is_lan, bool want_announce)
{ {
for (uint16_t i = 0; i < MAX_SENT_NODES; ++i) { for (uint16_t i = 0; i < MAX_SENT_NODES; ++i) {
nodes_list[i] = empty_node_format; nodes_list[i] = empty_node_format;
@@ -761,8 +739,7 @@ int get_close_nodes(
} }
#ifdef CHECK_ANNOUNCE_NODE #ifdef CHECK_ANNOUNCE_NODE
non_null() static void set_announce_node_in_list(Client_data *_Nonnull list, uint32_t list_len, const uint8_t *_Nonnull public_key)
static void set_announce_node_in_list(Client_data *list, uint32_t list_len, const uint8_t *public_key)
{ {
const uint32_t index = index_of_client_pk(list, list_len, public_key); const uint32_t index = index_of_client_pk(list, list_len, public_key);
@@ -787,8 +764,7 @@ void set_announce_node(DHT *dht, const uint8_t *public_key)
} }
/** @brief Send data search request, searching for a random key. */ /** @brief Send data search request, searching for a random key. */
non_null() static bool send_announce_ping(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port)
static bool send_announce_ping(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port)
{ {
uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t)]; uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t)];
@@ -815,13 +791,11 @@ static bool send_announce_ping(DHT *dht, const uint8_t *public_key, const IP_Por
} }
/** @brief If the response is valid, set the sender as an announce node. */ /** @brief If the response is valid, set the sender as an announce node. */
non_null(1, 2, 3) nullable(5) static int handle_data_search_response(void *_Nonnull object, const IP_Port *_Nonnull source,
static int handle_data_search_response(void *object, const IP_Port *source, const uint8_t *_Nonnull packet, uint16_t length,
const uint8_t *packet, uint16_t length, void *_Nullable userdata)
void *userdata)
{ {
DHT *dht = (DHT *) object; DHT *dht = (DHT *) object;
const int32_t plain_len = (int32_t)length - (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE); const int32_t plain_len = (int32_t)length - (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE);
if (plain_len < (int32_t)(CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t))) { if (plain_len < (int32_t)(CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t))) {
@@ -867,9 +841,7 @@ static int handle_data_search_response(void *object, const IP_Port *source,
* return false if node can't be stored. * return false if node can't be stored.
* return true if it can. * return true if it can.
*/ */
non_null() static bool store_node_ok(const Client_data *_Nonnull client, uint64_t cur_time, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull comp_public_key)
static bool store_node_ok(const Client_data *client, uint64_t cur_time, const uint8_t *public_key,
const uint8_t *comp_public_key)
{ {
return (assoc_timeout(cur_time, &client->assoc4) return (assoc_timeout(cur_time, &client->assoc4)
&& assoc_timeout(cur_time, &client->assoc6)) && assoc_timeout(cur_time, &client->assoc6))
@@ -882,8 +854,7 @@ typedef struct Client_data_Cmp {
const uint8_t *comp_public_key; const uint8_t *comp_public_key;
} Client_data_Cmp; } Client_data_Cmp;
non_null() static int client_data_cmp(const Client_data_Cmp *_Nonnull cmp, const Client_data *_Nonnull entry1, const Client_data *_Nonnull entry2)
static int client_data_cmp(const Client_data_Cmp *cmp, const Client_data *entry1, const Client_data *entry2)
{ {
const bool t1 = assoc_timeout(cmp->cur_time, &entry1->assoc4) && assoc_timeout(cmp->cur_time, &entry1->assoc6); const bool t1 = assoc_timeout(cmp->cur_time, &entry1->assoc4) && assoc_timeout(cmp->cur_time, &entry1->assoc6);
const bool t2 = assoc_timeout(cmp->cur_time, &entry2->assoc4) && assoc_timeout(cmp->cur_time, &entry2->assoc6); const bool t2 = assoc_timeout(cmp->cur_time, &entry2->assoc4) && assoc_timeout(cmp->cur_time, &entry2->assoc6);
@@ -913,8 +884,7 @@ static int client_data_cmp(const Client_data_Cmp *cmp, const Client_data *entry1
return 0; return 0;
} }
non_null() static bool client_data_less_handler(const void *_Nonnull object, const void *_Nonnull a, const void *_Nonnull b)
static bool client_data_less_handler(const void *object, const void *a, const void *b)
{ {
const Client_data_Cmp *cmp = (const Client_data_Cmp *)object; const Client_data_Cmp *cmp = (const Client_data_Cmp *)object;
const Client_data *entry1 = (const Client_data *)a; const Client_data *entry1 = (const Client_data *)a;
@@ -923,30 +893,26 @@ static bool client_data_less_handler(const void *object, const void *a, const vo
return client_data_cmp(cmp, entry1, entry2) < 0; return client_data_cmp(cmp, entry1, entry2) < 0;
} }
non_null() static const void *client_data_get_handler(const void *_Nonnull arr, uint32_t index)
static const void *client_data_get_handler(const void *arr, uint32_t index)
{ {
const Client_data *entries = (const Client_data *)arr; const Client_data *entries = (const Client_data *)arr;
return &entries[index]; return &entries[index];
} }
non_null() static void client_data_set_handler(void *_Nonnull arr, uint32_t index, const void *_Nonnull val)
static void client_data_set_handler(void *arr, uint32_t index, const void *val)
{ {
Client_data *entries = (Client_data *)arr; Client_data *entries = (Client_data *)arr;
const Client_data *entry = (const Client_data *)val; const Client_data *entry = (const Client_data *)val;
entries[index] = *entry; entries[index] = *entry;
} }
non_null() static void *client_data_subarr_handler(void *_Nonnull arr, uint32_t index, uint32_t size)
static void *client_data_subarr_handler(void *arr, uint32_t index, uint32_t size)
{ {
Client_data *entries = (Client_data *)arr; Client_data *entries = (Client_data *)arr;
return &entries[index]; return &entries[index];
} }
non_null() static void *client_data_alloc_handler(const void *_Nonnull object, uint32_t size)
static void *client_data_alloc_handler(const void *object, uint32_t size)
{ {
const Client_data_Cmp *cmp = (const Client_data_Cmp *)object; const Client_data_Cmp *cmp = (const Client_data_Cmp *)object;
Client_data *tmp = (Client_data *)mem_valloc(cmp->mem, size, sizeof(Client_data)); Client_data *tmp = (Client_data *)mem_valloc(cmp->mem, size, sizeof(Client_data));
@@ -958,8 +924,7 @@ static void *client_data_alloc_handler(const void *object, uint32_t size)
return tmp; return tmp;
} }
non_null() static void client_data_delete_handler(const void *_Nonnull object, void *_Nonnull arr, uint32_t size)
static void client_data_delete_handler(const void *object, void *arr, uint32_t size)
{ {
const Client_data_Cmp *cmp = (const Client_data_Cmp *)object; const Client_data_Cmp *cmp = (const Client_data_Cmp *)object;
mem_delete(cmp->mem, arr); mem_delete(cmp->mem, arr);
@@ -974,9 +939,7 @@ static const Sort_Funcs client_data_cmp_funcs = {
client_data_delete_handler, client_data_delete_handler,
}; };
non_null() static void sort_client_list(const Memory *_Nonnull mem, Client_data *_Nonnull list, uint64_t cur_time, unsigned int length, const uint8_t *_Nonnull comp_public_key)
static void sort_client_list(const Memory *mem, Client_data *list, uint64_t cur_time, unsigned int length,
const uint8_t *comp_public_key)
{ {
// Pass comp_public_key to merge_sort with each Client_data entry, so the // Pass comp_public_key to merge_sort with each Client_data entry, so the
// comparison function can use it as the base of comparison. // comparison function can use it as the base of comparison.
@@ -989,8 +952,7 @@ static void sort_client_list(const Memory *mem, Client_data *list, uint64_t cur_
merge_sort(list, length, &cmp, &client_data_cmp_funcs); merge_sort(list, length, &cmp, &client_data_cmp_funcs);
} }
non_null() static void update_client_with_reset(const Mono_Time *_Nonnull mono_time, Client_data *_Nonnull client, const IP_Port *_Nonnull ip_port)
static void update_client_with_reset(const Mono_Time *mono_time, Client_data *client, const IP_Port *ip_port)
{ {
IPPTsPng *ipptp_write = nullptr; IPPTsPng *ipptp_write = nullptr;
IPPTsPng *ipptp_clear = nullptr; IPPTsPng *ipptp_clear = nullptr;
@@ -1031,13 +993,8 @@ static void update_client_with_reset(const Mono_Time *mono_time, Client_data *cl
* *
* @return true when the item was stored, false otherwise * @return true when the item was stored, false otherwise
*/ */
non_null() static bool replace_all(const DHT *_Nonnull dht, Client_data *_Nonnull list, uint16_t length, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port,
static bool replace_all(const DHT *dht, const uint8_t *_Nonnull comp_public_key)
Client_data *list,
uint16_t length,
const uint8_t *public_key,
const IP_Port *ip_port,
const uint8_t *comp_public_key)
{ {
if (!net_family_is_ipv4(ip_port->ip.family) && !net_family_is_ipv6(ip_port->ip.family)) { if (!net_family_is_ipv4(ip_port->ip.family) && !net_family_is_ipv6(ip_port->ip.family)) {
return false; return false;
@@ -1064,8 +1021,7 @@ static bool replace_all(const DHT *dht,
* return false on failure. * return false on failure.
* return true on success. * return true on success.
*/ */
non_null() static bool add_to_close(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port, bool simulate)
static bool add_to_close(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port, bool simulate)
{ {
unsigned int index = bit_by_bit_cmp(public_key, dht->self_public_key); unsigned int index = bit_by_bit_cmp(public_key, dht->self_public_key);
@@ -1105,9 +1061,7 @@ bool node_addable_to_close_list(DHT *dht, const uint8_t *public_key, const IP_Po
return add_to_close(dht, public_key, ip_port, true); return add_to_close(dht, public_key, ip_port, true);
} }
non_null() static bool is_pk_in_client_list(const Client_data *_Nonnull list, unsigned int client_list_length, uint64_t cur_time, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port)
static bool is_pk_in_client_list(const Client_data *list, unsigned int client_list_length, uint64_t cur_time,
const uint8_t *public_key, const IP_Port *ip_port)
{ {
const uint32_t index = index_of_client_pk(list, client_list_length, public_key); const uint32_t index = index_of_client_pk(list, client_list_length, public_key);
@@ -1122,8 +1076,7 @@ static bool is_pk_in_client_list(const Client_data *list, unsigned int client_li
return !assoc_timeout(cur_time, assoc); return !assoc_timeout(cur_time, assoc);
} }
non_null() static bool is_pk_in_close_list(const DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port)
static bool is_pk_in_close_list(const DHT *dht, const uint8_t *public_key, const IP_Port *ip_port)
{ {
unsigned int index = bit_by_bit_cmp(public_key, dht->self_public_key); unsigned int index = bit_by_bit_cmp(public_key, dht->self_public_key);
@@ -1142,8 +1095,7 @@ static bool is_pk_in_close_list(const DHT *dht, const uint8_t *public_key, const
* return false if the node should not be pinged. * return false if the node should not be pinged.
* return true if it should. * return true if it should.
*/ */
non_null() static bool ping_node_from_nodes_response_ok(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port)
static bool ping_node_from_nodes_response_ok(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port)
{ {
bool ret = false; bool ret = false;
@@ -1260,9 +1212,7 @@ uint32_t addto_lists(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key
return used; return used;
} }
non_null() static bool update_client_data(const Mono_Time *_Nonnull mono_time, Client_data *_Nonnull array, size_t size, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull pk, bool node_is_self)
static bool update_client_data(const Mono_Time *mono_time, Client_data *array, size_t size, const IP_Port *ip_port,
const uint8_t *pk, bool node_is_self)
{ {
const uint64_t temp_time = mono_time_get(mono_time); const uint64_t temp_time = mono_time_get(mono_time);
const uint32_t index = index_of_client_pk(array, size, pk); const uint32_t index = index_of_client_pk(array, size, pk);
@@ -1293,8 +1243,7 @@ static bool update_client_data(const Mono_Time *mono_time, Client_data *array, s
* If public_key is a friend or us, update ret_ip_port * If public_key is a friend or us, update ret_ip_port
* nodepublic_key is the id of the node that sent us this info. * nodepublic_key is the id of the node that sent us this info.
*/ */
non_null() static void returnedip_ports(DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull nodepublic_key)
static void returnedip_ports(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *nodepublic_key)
{ {
const IP_Port ipp_copy = ip_port_normalize(ip_port); const IP_Port ipp_copy = ip_port_normalize(ip_port);
@@ -1361,9 +1310,8 @@ bool dht_send_nodes_request(DHT *dht, const IP_Port *ip_port, const uint8_t *pub
} }
/** Send a nodes response */ /** Send a nodes response */
non_null() static int send_nodes_response(const DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull client_id,
static int send_nodes_response(const DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *client_id, const uint8_t *_Nonnull sendback_data, uint16_t length, const uint8_t *_Nonnull shared_encryption_key)
const uint8_t *sendback_data, uint16_t length, const uint8_t *shared_encryption_key)
{ {
/* Check if packet is going to be sent to ourself. */ /* Check if packet is going to be sent to ourself. */
if (pk_equal(public_key, dht->self_public_key)) { if (pk_equal(public_key, dht->self_public_key)) {
@@ -1412,8 +1360,7 @@ static int send_nodes_response(const DHT *dht, const IP_Port *ip_port, const uin
#define CRYPTO_NODE_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t)) #define CRYPTO_NODE_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t))
non_null() static int handle_nodes_request(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length, void *_Nonnull userdata)
static int handle_nodes_request(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
{ {
DHT *const dht = (DHT *)object; DHT *const dht = (DHT *)object;
@@ -1448,8 +1395,7 @@ static int handle_nodes_request(void *object, const IP_Port *source, const uint8
} }
/** Return true if we sent a nodes request packet to the peer associated with the supplied info. */ /** Return true if we sent a nodes request packet to the peer associated with the supplied info. */
non_null() static bool sent_nodes_request_to_node(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull node_ip_port, uint64_t ping_id)
static bool sent_nodes_request_to_node(DHT *dht, const uint8_t *public_key, const IP_Port *node_ip_port, uint64_t ping_id)
{ {
uint8_t data[sizeof(Node_format) * 2]; uint8_t data[sizeof(Node_format) * 2];
@@ -1466,9 +1412,8 @@ static bool sent_nodes_request_to_node(DHT *dht, const uint8_t *public_key, cons
return ipport_equal(&test.ip_port, node_ip_port) && pk_equal(test.public_key, public_key); return ipport_equal(&test.ip_port, node_ip_port) && pk_equal(test.public_key, public_key);
} }
non_null() static bool handle_nodes_response_core(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length, Node_format *_Nonnull plain_nodes,
static bool handle_nodes_response_core(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, uint16_t size_plain_nodes, uint32_t *_Nonnull num_nodes_out)
Node_format *plain_nodes, uint16_t size_plain_nodes, uint32_t *num_nodes_out)
{ {
DHT *const dht = (DHT *)object; DHT *const dht = (DHT *)object;
const uint32_t cid_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + 1 + sizeof(uint64_t) + CRYPTO_MAC_SIZE; const uint32_t cid_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + 1 + sizeof(uint64_t) + CRYPTO_MAC_SIZE;
@@ -1536,9 +1481,7 @@ static bool handle_nodes_response_core(void *object, const IP_Port *source, cons
return true; return true;
} }
non_null() static int handle_nodes_response(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length, void *_Nonnull userdata)
static int handle_nodes_response(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{ {
DHT *const dht = (DHT *)object; DHT *const dht = (DHT *)object;
Node_format plain_nodes[MAX_SENT_NODES]; Node_format plain_nodes[MAX_SENT_NODES];
@@ -1569,9 +1512,8 @@ static int handle_nodes_response(void *object, const IP_Port *source, const uint
/*----------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------*/
/*------------------------END of packet handling functions--------------------------*/ /*------------------------END of packet handling functions--------------------------*/
non_null(1) nullable(2, 3) static uint32_t dht_friend_lock(DHT_Friend *_Nonnull dht_friend, dht_ip_cb *_Nullable ip_callback,
static uint32_t dht_friend_lock(DHT_Friend *const dht_friend, dht_ip_cb *ip_callback, void *_Nullable data, int32_t number)
void *data, int32_t number)
{ {
// find first free slot // find first free slot
uint8_t lock_num; uint8_t lock_num;
@@ -1598,8 +1540,7 @@ static uint32_t dht_friend_lock(DHT_Friend *const dht_friend, dht_ip_cb *ip_call
return lock_token; return lock_token;
} }
non_null() static void dht_friend_unlock(DHT_Friend *_Nonnull dht_friend, uint32_t lock_token)
static void dht_friend_unlock(DHT_Friend *const dht_friend, uint32_t lock_token)
{ {
// If this triggers, there was a double free // If this triggers, there was a double free
assert((lock_token & dht_friend->lock_flags) > 0); assert((lock_token & dht_friend->lock_flags) > 0);
@@ -1736,9 +1677,8 @@ int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
} }
/** returns number of nodes not in kill-timeout */ /** returns number of nodes not in kill-timeout */
non_null() static uint8_t do_ping_and_sendnode_requests(DHT *_Nonnull dht, uint64_t *_Nonnull lastgetnode, const uint8_t *_Nonnull public_key, Client_data *_Nonnull list, uint32_t list_count,
static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, const uint8_t *public_key, uint32_t *_Nonnull bootstrap_times, bool sortable)
Client_data *list, uint32_t list_count, uint32_t *bootstrap_times, bool sortable)
{ {
uint8_t not_kill = 0; uint8_t not_kill = 0;
const uint64_t temp_time = mono_time_get(dht->mono_time); const uint64_t temp_time = mono_time_get(dht->mono_time);
@@ -1822,8 +1762,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
* Send a nodes request every NODES_REQUEST_INTERVAL seconds to a random good * Send a nodes request every NODES_REQUEST_INTERVAL seconds to a random good
* node for each "friend" in our "friends" list. * node for each "friend" in our "friends" list.
*/ */
non_null() static void do_dht_friends(DHT *_Nonnull dht)
static void do_dht_friends(DHT *dht)
{ {
for (size_t i = 0; i < dht->num_friends; ++i) { for (size_t i = 0; i < dht->num_friends; ++i) {
DHT_Friend *const dht_friend = &dht->friends_list[i]; DHT_Friend *const dht_friend = &dht->friends_list[i];
@@ -1843,8 +1782,7 @@ static void do_dht_friends(DHT *dht)
* *
* Send a nodes request every NODES_REQUEST_INTERVAL seconds to a random good node in the list. * Send a nodes request every NODES_REQUEST_INTERVAL seconds to a random good node in the list.
*/ */
non_null() static void do_close(DHT *_Nonnull dht)
static void do_close(DHT *dht)
{ {
for (size_t i = 0; i < dht->num_to_bootstrap; ++i) { for (size_t i = 0; i < dht->num_to_bootstrap; ++i) {
dht_send_nodes_request(dht, &dht->to_bootstrap[i].ip_port, dht->to_bootstrap[i].public_key, dht->self_public_key); dht_send_nodes_request(dht, &dht->to_bootstrap[i].ip_port, dht->to_bootstrap[i].public_key, dht->self_public_key);
@@ -1950,8 +1888,7 @@ int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packe
* @retval 0 if we are connected to friend or if no ips were found. * @retval 0 if we are connected to friend or if no ips were found.
* @retval -1 if no such friend. * @retval -1 if no such friend.
*/ */
non_null() static int friend_iplist(const DHT *_Nonnull dht, IP_Port *_Nonnull ip_portlist, uint16_t friend_num)
static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_num)
{ {
if (friend_num >= dht->num_friends) { if (friend_num >= dht->num_friends) {
return -1; return -1;
@@ -2031,7 +1968,7 @@ static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_n
* @param n A pointer to the number that will be returned from `foreach_ip_port`. * @param n A pointer to the number that will be returned from `foreach_ip_port`.
* @param userdata The `userdata` pointer passed to `foreach_ip_port`. * @param userdata The `userdata` pointer passed to `foreach_ip_port`.
*/ */
typedef bool foreach_ip_port_cb(const DHT *dht, const IP_Port *ip_port, uint32_t *n, void *userdata); typedef bool foreach_ip_port_cb(const DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, uint32_t *_Nonnull n, void *_Nonnull userdata);
/** /**
* Runs a callback on every active connection for a given DHT friend. * Runs a callback on every active connection for a given DHT friend.
@@ -2044,9 +1981,7 @@ typedef bool foreach_ip_port_cb(const DHT *dht, const IP_Port *ip_port, uint32_t
* @param callback The callback to invoke for each IP/port. * @param callback The callback to invoke for each IP/port.
* @param userdata Extra pointer passed to the callback. * @param userdata Extra pointer passed to the callback.
*/ */
non_null() static uint32_t foreach_ip_port(const DHT *_Nonnull dht, const DHT_Friend *_Nonnull dht_friend, foreach_ip_port_cb *_Nonnull callback, void *_Nonnull userdata)
static uint32_t foreach_ip_port(const DHT *dht, const DHT_Friend *dht_friend,
foreach_ip_port_cb *callback, void *userdata)
{ {
uint32_t n = 0; uint32_t n = 0;
@@ -2076,8 +2011,7 @@ static uint32_t foreach_ip_port(const DHT *dht, const DHT_Friend *dht_friend,
return n; return n;
} }
non_null() static bool send_packet_to_friend(const DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, uint32_t *_Nonnull n, void *_Nonnull userdata)
static bool send_packet_to_friend(const DHT *dht, const IP_Port *ip_port, uint32_t *n, void *userdata)
{ {
const Packet *packet = (const Packet *)userdata; const Packet *packet = (const Packet *)userdata;
const int retval = send_packet(dht->net, ip_port, *packet); const int retval = send_packet(dht->net, ip_port, *packet);
@@ -2118,8 +2052,7 @@ uint32_t route_to_friend(const DHT *dht, const uint8_t *friend_id, const Packet
return foreach_ip_port(dht, dht_friend, send_packet_to_friend, &packet_userdata); return foreach_ip_port(dht, dht_friend, send_packet_to_friend, &packet_userdata);
} }
non_null() static bool get_ip_port(const DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, uint32_t *_Nonnull n, void *_Nonnull userdata)
static bool get_ip_port(const DHT *dht, const IP_Port *ip_port, uint32_t *n, void *userdata)
{ {
IP_Port *ip_list = (IP_Port *)userdata; IP_Port *ip_list = (IP_Port *)userdata;
ip_list[*n] = *ip_port; ip_list[*n] = *ip_port;
@@ -2131,8 +2064,7 @@ static bool get_ip_port(const DHT *dht, const IP_Port *ip_port, uint32_t *n, voi
* *
* @return number of nodes the packet was sent to. * @return number of nodes the packet was sent to.
*/ */
non_null() static uint32_t routeone_to_friend(const DHT *_Nonnull dht, const uint8_t *_Nonnull friend_id, const Packet *_Nonnull packet)
static uint32_t routeone_to_friend(const DHT *dht, const uint8_t *friend_id, const Packet *packet)
{ {
const uint32_t num = index_of_friend_pk(dht->friends_list, dht->num_friends, friend_id); const uint32_t num = index_of_friend_pk(dht->friends_list, dht->num_friends, friend_id);
@@ -2163,8 +2095,7 @@ static uint32_t routeone_to_friend(const DHT *dht, const uint8_t *friend_id, con
/*----------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------*/
/*---------------------BEGINNING OF NAT PUNCHING FUNCTIONS--------------------------*/ /*---------------------BEGINNING OF NAT PUNCHING FUNCTIONS--------------------------*/
non_null() static int send_nat_ping(const DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, uint64_t ping_id, uint8_t type)
static int send_nat_ping(const DHT *dht, const uint8_t *public_key, uint64_t ping_id, uint8_t type)
{ {
uint8_t data[sizeof(uint64_t) + 1]; uint8_t data[sizeof(uint64_t) + 1];
uint8_t packet_data[MAX_CRYPTO_REQUEST_SIZE]; uint8_t packet_data[MAX_CRYPTO_REQUEST_SIZE];
@@ -2198,9 +2129,8 @@ static int send_nat_ping(const DHT *dht, const uint8_t *public_key, uint64_t pin
} }
/** Handle a received ping request for. */ /** Handle a received ping request for. */
non_null() static int handle_nat_ping(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull source_pubkey, const uint8_t *_Nonnull packet, uint16_t length,
static int handle_nat_ping(void *object, const IP_Port *source, const uint8_t *source_pubkey, const uint8_t *packet, void *_Nonnull userdata)
uint16_t length, void *userdata)
{ {
DHT *const dht = (DHT *)object; DHT *const dht = (DHT *)object;
@@ -2243,8 +2173,7 @@ static int handle_nat_ping(void *object, const IP_Port *source, const uint8_t *s
* *
* @return ip of 0 if failure. * @return ip of 0 if failure.
*/ */
non_null() static IP nat_commonip(const IP_Port *_Nonnull ip_portlist, uint16_t len, uint16_t min_num)
static IP nat_commonip(const IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
{ {
IP zero; IP zero;
ip_reset(&zero); ip_reset(&zero);
@@ -2276,8 +2205,7 @@ static IP nat_commonip(const IP_Port *ip_portlist, uint16_t len, uint16_t min_nu
* *
* @return number of ports and puts the list of ports in portlist. * @return number of ports and puts the list of ports in portlist.
*/ */
non_null() static uint16_t nat_getports(uint16_t *_Nonnull portlist, const IP_Port *_Nonnull ip_portlist, uint16_t len, const IP *_Nonnull ip)
static uint16_t nat_getports(uint16_t *portlist, const IP_Port *ip_portlist, uint16_t len, const IP *ip)
{ {
uint16_t num = 0; uint16_t num = 0;
@@ -2291,8 +2219,7 @@ static uint16_t nat_getports(uint16_t *portlist, const IP_Port *ip_portlist, uin
return num; return num;
} }
non_null() static void punch_holes(DHT *_Nonnull dht, const IP *_Nonnull ip, const uint16_t *_Nonnull port_list, uint16_t numports, uint16_t friend_num)
static void punch_holes(DHT *dht, const IP *ip, const uint16_t *port_list, uint16_t numports, uint16_t friend_num)
{ {
if (!dht->hole_punching_enabled) { if (!dht->hole_punching_enabled) {
return; return;
@@ -2352,8 +2279,7 @@ static void punch_holes(DHT *dht, const IP *ip, const uint16_t *port_list, uint1
++dht->friends_list[friend_num].nat.tries; ++dht->friends_list[friend_num].nat.tries;
} }
non_null() static void do_nat(DHT *_Nonnull dht)
static void do_nat(DHT *dht)
{ {
const uint64_t temp_time = mono_time_get(dht->mono_time); const uint64_t temp_time = mono_time_get(dht->mono_time);
@@ -2404,9 +2330,7 @@ static void do_nat(DHT *dht)
* *
* @return the number of nodes. * @return the number of nodes.
*/ */
non_null() static uint16_t list_nodes(const Random *_Nonnull rng, const Client_data *_Nonnull list, size_t length, uint64_t cur_time, Node_format *_Nonnull nodes, uint16_t max_num)
static uint16_t list_nodes(const Random *rng, const Client_data *list, size_t length,
uint64_t cur_time, Node_format *nodes, uint16_t max_num)
{ {
if (max_num == 0) { if (max_num == 0) {
return 0; return 0;
@@ -2490,9 +2414,7 @@ void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_c
dht->cryptopackethandlers[byte].object = object; dht->cryptopackethandlers[byte].object = object;
} }
non_null() static int cryptopacket_handle(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length, void *_Nonnull userdata)
static int cryptopacket_handle(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
{ {
DHT *const dht = (DHT *)object; DHT *const dht = (DHT *)object;
@@ -2539,12 +2461,10 @@ void dht_callback_nodes_response(DHT *dht, dht_nodes_response_cb *function)
dht->nodes_response_callback = function; dht->nodes_response_callback = function;
} }
non_null(1, 2, 3) nullable(5) static int handle_lan_discovery(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length,
static int handle_lan_discovery(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *_Nullable userdata)
void *userdata)
{ {
DHT *dht = (DHT *)object; DHT *dht = (DHT *)object;
if (!dht->lan_discovery_enabled) { if (!dht->lan_discovery_enabled) {
return 1; return 1;
} }
@@ -2574,7 +2494,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)); LOGGER_ERROR(log, "failed to allocate DHT struct (%lu bytes)", (unsigned long)sizeof(DHT));
return nullptr; return nullptr;
} }
@@ -2746,7 +2666,7 @@ void dht_save(const DHT *dht, uint8_t *data)
Node_format *clients = (Node_format *)mem_valloc(dht->mem, MAX_SAVED_DHT_NODES, sizeof(Node_format)); Node_format *clients = (Node_format *)mem_valloc(dht->mem, MAX_SAVED_DHT_NODES, sizeof(Node_format));
if (clients == nullptr) { if (clients == nullptr) {
LOGGER_ERROR(dht->log, "could not allocate %u nodes", MAX_SAVED_DHT_NODES); LOGGER_ERROR(dht->log, "could not allocate %u nodes", (unsigned int)MAX_SAVED_DHT_NODES);
return; return;
} }
@@ -2826,8 +2746,7 @@ int dht_connect_after_load(DHT *dht)
return 0; return 0;
} }
non_null() static State_Load_Status dht_load_state_callback(void *_Nonnull outer, const uint8_t *_Nonnull data, uint32_t length, uint16_t type)
static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type)
{ {
DHT *dht = (DHT *)outer; DHT *dht = (DHT *)outer;
@@ -2843,7 +2762,7 @@ static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *dat
Node_format *nodes = (Node_format *)mem_valloc(dht->mem, MAX_SAVED_DHT_NODES, sizeof(Node_format)); Node_format *nodes = (Node_format *)mem_valloc(dht->mem, MAX_SAVED_DHT_NODES, sizeof(Node_format));
if (nodes == nullptr) { if (nodes == nullptr) {
LOGGER_ERROR(dht->log, "could not allocate %u nodes", MAX_SAVED_DHT_NODES); LOGGER_ERROR(dht->log, "could not allocate %u nodes", (unsigned int)MAX_SAVED_DHT_NODES);
dht->loaded_num_nodes = 0; dht->loaded_num_nodes = 0;
break; break;
} }

View File

@@ -98,10 +98,8 @@ extern "C" {
* @retval -1 on failure. * @retval -1 on failure.
* @return the length of the created packet on success. * @return the length of the created packet on success.
*/ */
non_null() int create_request(const Memory *_Nonnull mem, const Random *_Nonnull rng, const uint8_t *_Nonnull send_public_key, const uint8_t *_Nonnull send_secret_key, uint8_t *_Nonnull packet,
int create_request(const Memory *mem, const Random *rng, const uint8_t *send_public_key, const uint8_t *send_secret_key, const uint8_t *_Nonnull recv_public_key, const uint8_t *_Nonnull data, uint32_t data_length, uint8_t request_id);
uint8_t *packet, const uint8_t *recv_public_key,
const uint8_t *data, uint32_t data_length, uint8_t request_id);
/** /**
* @brief Decrypts and unpacks a DHT request packet. * @brief Decrypts and unpacks a DHT request packet.
@@ -125,10 +123,8 @@ int create_request(const Memory *mem, const Random *rng, const uint8_t *send_pub
* @retval -1 if not valid request. * @retval -1 if not valid request.
* @return the length of the unpacked data. * @return the length of the unpacked data.
*/ */
non_null() int handle_request(const Memory *_Nonnull mem, const uint8_t *_Nonnull self_public_key, const uint8_t *_Nonnull self_secret_key, uint8_t *_Nonnull public_key, uint8_t *_Nonnull data,
int handle_request( uint8_t *_Nonnull request_id, const uint8_t *_Nonnull packet, uint16_t packet_length);
const Memory *mem, const uint8_t *self_public_key, const uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data,
uint8_t *request_id, const uint8_t *packet, uint16_t packet_length);
typedef struct IPPTs { typedef struct IPPTs {
IP_Port ip_port; IP_Port ip_port;
@@ -182,8 +178,8 @@ extern const Node_format empty_node_format;
typedef struct DHT_Friend DHT_Friend; typedef struct DHT_Friend DHT_Friend;
non_null() const uint8_t *dht_friend_public_key(const DHT_Friend *dht_friend); const uint8_t *_Nonnull dht_friend_public_key(const DHT_Friend *_Nonnull dht_friend);
non_null() const Client_data *dht_friend_client(const DHT_Friend *dht_friend, size_t index); const Client_data *_Nonnull dht_friend_client(const DHT_Friend *_Nonnull dht_friend, size_t index);
/** @return packet size of packed node with ip_family on success. /** @return packet size of packed node with ip_family on success.
* @retval -1 on failure. * @retval -1 on failure.
@@ -195,20 +191,15 @@ int packed_node_size(Family ip_family);
* @return size of packet on success. * @return size of packet on success.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() int dht_create_packet(const Memory *_Nonnull mem, const Random *_Nonnull rng, const uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t *_Nonnull shared_key, uint8_t type,
int dht_create_packet(const Memory *mem, const Random *rng, const uint8_t *_Nonnull plain, size_t plain_length, uint8_t *_Nonnull packet, size_t length);
const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
const uint8_t *shared_key, uint8_t type,
const uint8_t *plain, size_t plain_length,
uint8_t *packet, size_t length);
/** @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.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() int pack_nodes(const Logger *_Nonnull logger, uint8_t *_Nonnull data, uint16_t length, const Node_format *_Nonnull nodes, uint16_t number);
int pack_nodes(const Logger *logger, uint8_t *data, uint16_t length, const Node_format *nodes, uint16_t number);
/** @brief Unpack data of length into nodes of size max_num_nodes. /** @brief Unpack data of length into nodes of size max_num_nodes.
* Put the length of the data processed in processed_data_len. * Put the length of the data processed in processed_data_len.
@@ -217,30 +208,28 @@ int pack_nodes(const Logger *logger, uint8_t *data, uint16_t length, const Node_
* @return number of unpacked nodes on success. * @return number of unpacked nodes on success.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null(1, 4) nullable(3) int unpack_nodes(Node_format *_Nonnull nodes, uint16_t max_num_nodes, uint16_t *_Nullable processed_data_len, const uint8_t *_Nonnull data,
int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed_data_len, const uint8_t *data,
uint16_t length, bool tcp_enabled); uint16_t length, bool tcp_enabled);
/*----------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------*/
typedef int cryptopacket_handler_cb(void *object, const IP_Port *source, const uint8_t *source_pubkey, typedef int cryptopacket_handler_cb(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull source_pubkey,
const uint8_t *packet, uint16_t length, void *userdata); const uint8_t *_Nonnull packet, uint16_t length, void *_Nullable userdata);
typedef struct DHT DHT; typedef struct DHT DHT;
non_null() const uint8_t *dht_get_self_public_key(const DHT *dht); const uint8_t *_Nonnull dht_get_self_public_key(const DHT *_Nonnull dht);
non_null() const uint8_t *dht_get_self_secret_key(const DHT *dht); const uint8_t *_Nonnull dht_get_self_secret_key(const DHT *_Nonnull dht);
non_null() void dht_set_self_public_key(DHT *dht, const uint8_t *key); void dht_set_self_public_key(DHT *_Nonnull dht, const uint8_t *_Nonnull key);
non_null() void dht_set_self_secret_key(DHT *dht, const uint8_t *key); void dht_set_self_secret_key(DHT *_Nonnull dht, const uint8_t *_Nonnull key);
non_null() Networking_Core *dht_get_net(const DHT *dht); Networking_Core *_Nonnull dht_get_net(const DHT *_Nonnull dht);
non_null() struct Ping *dht_get_ping(const DHT *dht); struct Ping *_Nonnull dht_get_ping(const DHT *_Nonnull dht);
non_null() const Client_data *dht_get_close_clientlist(const DHT *dht); const Client_data *_Nonnull dht_get_close_clientlist(const DHT *_Nonnull dht);
non_null() const Client_data *dht_get_close_client(const DHT *dht, uint32_t client_num); const Client_data *_Nonnull dht_get_close_client(const DHT *_Nonnull dht, uint32_t client_num);
non_null() uint16_t dht_get_num_friends(const DHT *dht); uint16_t dht_get_num_friends(const DHT *_Nonnull dht);
non_null() DHT_Friend *dht_get_friend(DHT *dht, uint32_t friend_num); DHT_Friend *_Nonnull dht_get_friend(DHT *_Nonnull dht, uint32_t friend_num);
non_null() const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t friend_num); const uint8_t *_Nonnull dht_get_friend_public_key(const DHT *_Nonnull dht, uint32_t friend_num);
/*----------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------*/
@@ -248,15 +237,13 @@ non_null() const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t fri
* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key * Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
* for packets that we receive. * for packets that we receive.
*/ */
non_null() const uint8_t *_Nullable dht_get_shared_key_recv(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key);
const uint8_t *dht_get_shared_key_recv(DHT *dht, const uint8_t *public_key);
/** /**
* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key * Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
* for packets that we send. * for packets that we send.
*/ */
non_null() const uint8_t *_Nullable dht_get_shared_key_sent(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key);
const uint8_t *dht_get_shared_key_sent(DHT *dht, const uint8_t *public_key);
/** /**
* Sends a nodes request to `ip_port` with the public key `public_key` for nodes * Sends a nodes request to `ip_port` with the public key `public_key` for nodes
@@ -264,17 +251,14 @@ const uint8_t *dht_get_shared_key_sent(DHT *dht, const uint8_t *public_key);
* *
* @retval true on success. * @retval true on success.
*/ */
non_null() bool dht_send_nodes_request(DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull client_id);
bool dht_send_nodes_request(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *client_id);
typedef void dht_ip_cb(void *object, int32_t number, const IP_Port *ip_port); typedef void dht_ip_cb(void *_Nullable object, int32_t number, const IP_Port *_Nonnull ip_port);
typedef void dht_nodes_response_cb(const DHT *dht, const Node_format *node, void *user_data); typedef void dht_nodes_response_cb(const DHT *_Nonnull dht, const Node_format *_Nonnull node, void *_Nullable user_data);
/** Sets the callback to be triggered on a nodes response. */ /** Sets the callback to be triggered on a nodes response. */
non_null(1) nullable(2) void dht_callback_nodes_response(DHT *_Nonnull dht, dht_nodes_response_cb *_Nullable function);
void dht_callback_nodes_response(DHT *dht, dht_nodes_response_cb *function);
/** @brief Add a new friend to the friends list. /** @brief Add a new friend to the friends list.
* @param public_key must be CRYPTO_PUBLIC_KEY_SIZE bytes long. * @param public_key must be CRYPTO_PUBLIC_KEY_SIZE bytes long.
* *
@@ -289,10 +273,8 @@ void dht_callback_nodes_response(DHT *dht, dht_nodes_response_cb *function);
* @retval 0 if success. * @retval 0 if success.
* @retval -1 if failure (friends list is full). * @retval -1 if failure (friends list is full).
*/ */
non_null(1, 2, 6) nullable(3, 4) int dht_addfriend(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, dht_ip_cb *_Nullable ip_callback,
int dht_addfriend(DHT *dht, const uint8_t *public_key, dht_ip_cb *ip_callback, void *_Nullable data, int32_t number, uint32_t *_Nonnull lock_token);
void *data, int32_t number, uint32_t *lock_token);
/** @brief Delete a friend from the friends list. /** @brief Delete a friend from the friends list.
* public_key must be CRYPTO_PUBLIC_KEY_SIZE bytes long. * public_key must be CRYPTO_PUBLIC_KEY_SIZE bytes long.
* @param dht The DHT object * @param dht The DHT object
@@ -302,8 +284,7 @@ int dht_addfriend(DHT *dht, const uint8_t *public_key, dht_ip_cb *ip_callback,
* @retval 0 if success. * @retval 0 if success.
* @retval -1 if failure (public_key not in friends list). * @retval -1 if failure (public_key not in friends list).
*/ */
non_null() int dht_delfriend(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, uint32_t lock_token);
int dht_delfriend(DHT *dht, const uint8_t *public_key, uint32_t lock_token);
/** @brief Get ip of friend. /** @brief Get ip of friend.
* *
@@ -313,8 +294,7 @@ int dht_delfriend(DHT *dht, const uint8_t *public_key, uint32_t lock_token);
* @retval 0 if public_key refers to a friend and we failed to find the friend (yet) * @retval 0 if public_key refers to a friend and we failed to find the friend (yet)
* @retval 1 if public_key refers to a friend and we found him * @retval 1 if public_key refers to a friend and we found him
*/ */
non_null() int dht_getfriendip(const DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, IP_Port *_Nonnull ip_port);
int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port);
/** @brief Compares pk1 and pk2 with pk. /** @brief Compares pk1 and pk2 with pk.
* *
@@ -322,31 +302,25 @@ int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
* @retval 1 if pk1 is closer. * @retval 1 if pk1 is closer.
* @retval 2 if pk2 is closer. * @retval 2 if pk2 is closer.
*/ */
non_null() int id_closest(const uint8_t *_Nonnull pk, const uint8_t *_Nonnull pk1, const uint8_t *_Nonnull pk2);
int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2);
/** Return index of first unequal bit number between public keys pk1 and pk2. */ /** Return index of first unequal bit number between public keys pk1 and pk2. */
non_null() unsigned int bit_by_bit_cmp(const uint8_t *_Nonnull pk1, const uint8_t *_Nonnull pk2);
unsigned int bit_by_bit_cmp(const uint8_t *pk1, const uint8_t *pk2);
/** /**
* Add node to the node list making sure only the nodes closest to cmp_pk are in the list. * Add node to the node list making sure only the nodes closest to cmp_pk are in the list.
* *
* @return true iff the node was added to the list. * @return true iff the node was added to the list.
*/ */
non_null() bool add_to_list(Node_format *_Nonnull nodes_list, uint32_t length, const uint8_t pk[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const IP_Port *_Nonnull ip_port,
bool add_to_list( const uint8_t cmp_pk[_Nonnull CRYPTO_PUBLIC_KEY_SIZE]);
Node_format *nodes_list, uint32_t length, const uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE],
const IP_Port *ip_port, const uint8_t cmp_pk[CRYPTO_PUBLIC_KEY_SIZE]);
/** Return 1 if node can be added to close list, 0 if it can't. */ /** Return 1 if node can be added to close list, 0 if it can't. */
non_null() bool node_addable_to_close_list(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port);
bool node_addable_to_close_list(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port);
#ifdef CHECK_ANNOUNCE_NODE #ifdef CHECK_ANNOUNCE_NODE
/** Set node as announce node. */ /** Set node as announce node. */
non_null() void set_announce_node(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key);
void set_announce_node(DHT *dht, const uint8_t *public_key);
#endif /* CHECK_ANNOUNCE_NODE */ #endif /* CHECK_ANNOUNCE_NODE */
/** /**
@@ -359,11 +333,7 @@ void set_announce_node(DHT *dht, const uint8_t *public_key);
* *
* @return the number of nodes returned. * @return the number of nodes returned.
*/ */
non_null() int get_close_nodes(const DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, Node_format nodes_list[_Nonnull MAX_SENT_NODES], Family sa_family, bool is_lan, bool want_announce);
int get_close_nodes(
const DHT *dht, const uint8_t *public_key,
Node_format nodes_list[MAX_SENT_NODES], Family sa_family,
bool is_lan, bool want_announce);
/** @brief Put up to max_num nodes in nodes from the random friends. /** @brief Put up to max_num nodes in nodes from the random friends.
* *
@@ -372,19 +342,16 @@ int get_close_nodes(
* *
* @return the number of nodes. * @return the number of nodes.
*/ */
non_null() uint16_t randfriends_nodes(const DHT *_Nonnull dht, Node_format *_Nonnull nodes, uint16_t max_num);
uint16_t randfriends_nodes(const DHT *dht, Node_format *nodes, uint16_t max_num);
/** @brief Put up to max_num nodes in nodes from the closelist. /** @brief Put up to max_num nodes in nodes from the closelist.
* *
* @return the number of nodes. * @return the number of nodes.
*/ */
non_null() uint16_t closelist_nodes(const DHT *_Nonnull dht, Node_format *_Nonnull nodes, uint16_t max_num);
uint16_t closelist_nodes(const DHT *dht, Node_format *nodes, uint16_t max_num);
/** Run this function at least a couple times per second (It's the main loop). */ /** Run this function at least a couple times per second (It's the main loop). */
non_null() void do_dht(DHT *_Nonnull dht);
void do_dht(DHT *dht);
/* /*
* Use these two functions to bootstrap the client. * Use these two functions to bootstrap the client.
@@ -393,8 +360,7 @@ void do_dht(DHT *dht);
* @brief Sends a "nodes request" to the given node with ip, port and public_key * @brief Sends a "nodes request" to the given node with ip, port and public_key
* to setup connections * to setup connections
*/ */
non_null() bool dht_bootstrap(DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key);
bool dht_bootstrap(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key);
/** @brief Resolves address into an IP address. /** @brief Resolves address into an IP address.
* *
@@ -409,17 +375,14 @@ bool dht_bootstrap(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key);
* @retval true if the address could be converted into an IP address * @retval true if the address could be converted into an IP address
* @retval false otherwise * @retval false otherwise
*/ */
non_null() bool dht_bootstrap_from_address(DHT *_Nonnull dht, const char *_Nonnull address, bool ipv6enabled, bool dns_enabled, uint16_t port, const uint8_t *_Nonnull public_key);
bool dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled, bool dns_enabled,
uint16_t port, const uint8_t *public_key);
/** @brief Start sending packets after DHT loaded_friends_list and loaded_clients_list are set. /** @brief Start sending packets after DHT loaded_friends_list and loaded_clients_list are set.
* *
* @retval 0 if successful * @retval 0 if successful
* @retval -1 otherwise * @retval -1 otherwise
*/ */
non_null() int dht_connect_after_load(DHT *_Nonnull dht);
int dht_connect_after_load(DHT *dht);
/* ROUTING FUNCTIONS */ /* ROUTING FUNCTIONS */
@@ -428,8 +391,7 @@ int dht_connect_after_load(DHT *dht);
* @return number of bytes sent. * @return number of bytes sent.
* @retval -1 if failure. * @retval -1 if failure.
*/ */
non_null() int route_packet(const DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull packet, uint16_t length);
int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packet, uint16_t length);
/** /**
* Send the following packet to everyone who tells us they are connected to friend_id. * Send the following packet to everyone who tells us they are connected to friend_id.
@@ -437,52 +399,41 @@ int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packe
* @return ip for friend. * @return ip for friend.
* @return number of nodes the packet was sent to. (Only works if more than (MAX_FRIEND_CLIENTS / 4). * @return number of nodes the packet was sent to. (Only works if more than (MAX_FRIEND_CLIENTS / 4).
*/ */
non_null() uint32_t route_to_friend(const DHT *_Nonnull dht, const uint8_t *_Nonnull friend_id, const Packet *_Nonnull packet);
uint32_t route_to_friend(const DHT *dht, const uint8_t *friend_id, const Packet *packet);
/** Function to handle crypto packets. */ /** Function to handle crypto packets. */
non_null(1) nullable(3, 4) void cryptopacket_registerhandler(DHT *_Nonnull dht, uint8_t byte, cryptopacket_handler_cb *_Nullable cb, void *_Nullable object);
void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_cb *cb, void *object);
/* SAVE/LOAD functions */ /* SAVE/LOAD functions */
/** Get the size of the DHT (for saving). */ /** Get the size of the DHT (for saving). */
non_null() uint32_t dht_size(const DHT *_Nonnull dht);
uint32_t dht_size(const DHT *dht);
/** Save the DHT in data where data is an array of size `dht_size()`. */ /** Save the DHT in data where data is an array of size `dht_size()`. */
non_null() void dht_save(const DHT *_Nonnull dht, uint8_t *_Nonnull data);
void dht_save(const DHT *dht, uint8_t *data);
/** @brief Load the DHT from data of size size. /** @brief Load the DHT from data of size size.
* *
* @retval -1 if failure. * @retval -1 if failure.
* @retval 0 if success. * @retval 0 if success.
*/ */
non_null() int dht_load(DHT *_Nonnull dht, const uint8_t *_Nonnull data, uint32_t length);
int dht_load(DHT *dht, const uint8_t *data, uint32_t length);
/** Initialize DHT. */ /** Initialize DHT. */
non_null() DHT *_Nullable new_dht(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Network *_Nonnull ns, Mono_Time *_Nonnull mono_time, Networking_Core *_Nonnull net,
DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Network *ns, bool hole_punching_enabled, bool lan_discovery_enabled);
Mono_Time *mono_time, Networking_Core *net, bool hole_punching_enabled, bool lan_discovery_enabled);
nullable(1)
void kill_dht(DHT *dht);
void kill_dht(DHT *_Nullable dht);
/** /**
* @retval false if we are not connected to the DHT. * @retval false if we are not connected to the DHT.
* @retval true if we are. * @retval true if we are.
*/ */
non_null() bool dht_isconnected(const DHT *_Nonnull dht);
bool dht_isconnected(const DHT *dht);
/** /**
* @retval false if we are not connected or only connected to lan peers with the DHT. * @retval false if we are not connected or only connected to lan peers with the DHT.
* @retval true if we are. * @retval true if we are.
*/ */
non_null() bool dht_non_lan_connected(const DHT *_Nonnull dht);
bool dht_non_lan_connected(const DHT *dht);
/** /**
* This function returns the ratio of close dht nodes that are known to support announce/store. * This function returns the ratio of close dht nodes that are known to support announce/store.
@@ -490,8 +441,7 @@ bool dht_non_lan_connected(const DHT *dht);
* *
* @return number * @return number
*/ */
non_null() uint16_t dht_get_num_closelist(const DHT *_Nonnull dht);
uint16_t dht_get_num_closelist(const DHT *dht);
/** /**
* This function returns the number of DHT nodes in the closelist, * This function returns the number of DHT nodes in the closelist,
@@ -499,16 +449,14 @@ uint16_t dht_get_num_closelist(const DHT *dht);
* *
* @return number * @return number
*/ */
non_null() uint16_t dht_get_num_closelist_announce_capable(const DHT *_Nonnull dht);
uint16_t dht_get_num_closelist_announce_capable(const DHT *dht);
/** @brief Attempt to add client with ip_port and public_key to the friends client list /** @brief Attempt to add client with ip_port and public_key to the friends client list
* and close_clientlist. * and close_clientlist.
* *
* @return 1+ if the item is used in any list, 0 else * @return 1+ if the item is used in any list, 0 else
*/ */
non_null() uint32_t addto_lists(DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key);
uint32_t addto_lists(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key);
/** @brief Copies our own ip_port structure to `dest`. /** @brief Copies our own ip_port structure to `dest`.
* *
@@ -520,8 +468,7 @@ uint32_t addto_lists(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key
* @retval 1 if IP is a WAN address. * @retval 1 if IP is a WAN address.
* @retval 2 if IP is a LAN address. * @retval 2 if IP is a LAN address.
*/ */
non_null() unsigned int ipport_self_copy(const DHT *_Nonnull dht, IP_Port *_Nonnull dest);
unsigned int ipport_self_copy(const DHT *dht, IP_Port *dest);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View File

@@ -53,8 +53,7 @@ struct Broadcast_Info {
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
non_null() static Broadcast_Info *fetch_broadcast_info(const Memory *_Nonnull mem, const Network *_Nonnull ns)
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
{ {
Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info)); Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info));
@@ -124,11 +123,9 @@ static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns
#elif !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && (defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)) #elif !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && (defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__))
non_null() static bool ip4_is_local(const IP4 *_Nonnull ip4);
static bool ip4_is_local(const IP4 *ip4);
non_null() static Broadcast_Info *fetch_broadcast_info(const Memory *_Nonnull mem, const Network *_Nonnull ns)
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
{ {
Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info)); Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info));
@@ -222,8 +219,7 @@ static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns
#else // TODO(irungentoo): Other platforms? #else // TODO(irungentoo): Other platforms?
non_null() static Broadcast_Info *fetch_broadcast_info(const Memory *_Nonnull mem, const Network *_Nonnull ns)
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
{ {
Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info)); Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info));
@@ -243,9 +239,7 @@ static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns
* @retval true if sent to at least one broadcast target. * @retval true if sent to at least one broadcast target.
* @retval false on failure to find any valid broadcast target. * @retval false on failure to find any valid broadcast target.
*/ */
non_null() static bool send_broadcasts(const Networking_Core *_Nonnull net, const Broadcast_Info *_Nonnull broadcast, uint16_t port, const uint8_t *_Nonnull data, uint16_t length)
static bool send_broadcasts(const Networking_Core *net, const Broadcast_Info *broadcast, uint16_t port,
const uint8_t *data, uint16_t length)
{ {
if (broadcast->count == 0) { if (broadcast->count == 0) {
return false; return false;
@@ -288,8 +282,7 @@ static IP broadcast_ip(Family family_socket, Family family_broadcast)
return ip; return ip;
} }
non_null() static bool ip4_is_local(const IP4 *_Nonnull ip4)
static bool ip4_is_local(const IP4 *ip4)
{ {
/* Loopback. */ /* Loopback. */
return ip4->uint8[0] == 127; return ip4->uint8[0] == 127;
@@ -315,8 +308,7 @@ bool ip_is_local(const IP *ip)
return ip->ip.v6.uint64[0] == 0 && ip->ip.v6.uint32[2] == 0 && ip->ip.v6.uint32[3] == net_htonl(1); return ip->ip.v6.uint64[0] == 0 && ip->ip.v6.uint32[2] == 0 && ip->ip.v6.uint32[3] == net_htonl(1);
} }
non_null() static bool ip4_is_lan(const IP4 *_Nonnull ip4)
static bool ip4_is_lan(const IP4 *ip4)
{ {
/* 10.0.0.0 to 10.255.255.255 range. */ /* 10.0.0.0 to 10.255.255.255 range. */
if (ip4->uint8[0] == 10) { if (ip4->uint8[0] == 10) {

View File

@@ -25,34 +25,27 @@ typedef struct Broadcast_Info Broadcast_Info;
* *
* @return true on success, false on failure. * @return true on success, false on failure.
*/ */
non_null() bool lan_discovery_send(const Networking_Core *_Nonnull net, const Broadcast_Info *_Nonnull broadcast, const uint8_t *_Nonnull dht_pk, uint16_t port);
bool lan_discovery_send(const Networking_Core *net, const Broadcast_Info *broadcast, const uint8_t *dht_pk,
uint16_t port);
/** /**
* Discovers broadcast devices and IP addresses. * Discovers broadcast devices and IP addresses.
*/ */
non_null() Broadcast_Info *_Nullable lan_discovery_init(const Memory *_Nonnull mem, const Network *_Nonnull ns);
Broadcast_Info *lan_discovery_init(const Memory *mem, const Network *ns);
/** /**
* Free all resources associated with the broadcast info. * Free all resources associated with the broadcast info.
*/ */
nullable(1) void lan_discovery_kill(Broadcast_Info *_Nullable broadcast);
void lan_discovery_kill(Broadcast_Info *broadcast);
/** /**
* Is IP a local ip or not. * Is IP a local ip or not.
*/ */
non_null() bool ip_is_local(const IP *_Nonnull ip);
bool ip_is_local(const IP *ip);
/** /**
* Checks if a given IP isn't routable. * Checks if a given IP isn't routable.
* *
* @return true if ip is a LAN ip, false if it is not. * @return true if ip is a LAN ip, false if it is not.
*/ */
non_null() bool ip_is_lan(const IP *_Nonnull ip);
bool ip_is_lan(const IP *ip);
#endif /* C_TOXCORE_TOXCORE_LAN_DISCOVERY_H */ #endif /* C_TOXCORE_TOXCORE_LAN_DISCOVERY_H */

View File

@@ -61,8 +61,7 @@ bool friend_is_valid(const Messenger *m, int32_t friendnumber)
* *
* @retval -1 if mem_vrealloc fails. * @retval -1 if mem_vrealloc fails.
*/ */
non_null() static int realloc_friendlist(Messenger *_Nonnull m, uint32_t num)
static int realloc_friendlist(Messenger *m, uint32_t num)
{ {
if (num == 0) { if (num == 0) {
mem_delete(m->mem, m->friendlist); mem_delete(m->mem, m->friendlist);
@@ -137,32 +136,25 @@ void getaddress(const Messenger *m, uint8_t *address)
memcpy(address + CRYPTO_PUBLIC_KEY_SIZE + sizeof(nospam), &checksum, sizeof(checksum)); memcpy(address + CRYPTO_PUBLIC_KEY_SIZE + sizeof(nospam), &checksum, sizeof(checksum));
} }
non_null() static bool send_online_packet(const Messenger *_Nonnull m, int friendcon_id)
static bool send_online_packet(const Messenger *m, int friendcon_id)
{ {
const uint8_t packet[1] = {PACKET_ID_ONLINE}; const uint8_t packet[1] = {PACKET_ID_ONLINE};
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet, return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet,
sizeof(packet), false) != -1; sizeof(packet), false) != -1;
} }
non_null() static bool send_offline_packet(const Messenger *_Nonnull m, int friendcon_id)
static bool send_offline_packet(const Messenger *m, int friendcon_id)
{ {
const uint8_t packet[1] = {PACKET_ID_OFFLINE}; const uint8_t packet[1] = {PACKET_ID_OFFLINE};
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet, return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet,
sizeof(packet), false) != -1; sizeof(packet), false) != -1;
} }
non_null(1) nullable(4) static int m_handle_status(void *_Nonnull object, int friendcon_id, bool status, void *_Nullable userdata);
static int m_handle_status(void *object, int friendcon_id, bool status, void *userdata); static int m_handle_packet(void *_Nonnull object, int friendcon_id, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
non_null(1, 3) nullable(5) static int m_handle_lossy_packet(void *_Nonnull object, int friendcon_id, const uint8_t *_Nonnull data, uint16_t length,
static int m_handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata); void *_Nullable userdata);
non_null(1, 3) nullable(5) static int32_t init_new_friend(Messenger *_Nonnull m, const uint8_t *_Nonnull real_pk, uint8_t status)
static int m_handle_lossy_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length,
void *userdata);
non_null()
static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t status)
{ {
if (m->numfriends == UINT32_MAX) { if (m->numfriends == UINT32_MAX) {
LOGGER_ERROR(m->log, "Friend list full: we have more than 4 billion friends"); LOGGER_ERROR(m->log, "Friend list full: we have more than 4 billion friends");
@@ -211,8 +203,7 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta
return FAERR_NOMEM; return FAERR_NOMEM;
} }
non_null() static int32_t m_add_friend_contact_norequest(Messenger *_Nonnull m, const uint8_t *_Nonnull real_pk)
static int32_t m_add_friend_contact_norequest(Messenger *m, const uint8_t *real_pk)
{ {
if (getfriend_id(m, real_pk) != -1) { if (getfriend_id(m, real_pk) != -1) {
return FAERR_ALREADYSENT; return FAERR_ALREADYSENT;
@@ -320,8 +311,7 @@ int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk)
return m_add_friend_contact_norequest(m, real_pk); return m_add_friend_contact_norequest(m, real_pk);
} }
non_null() static int clear_receipts(Messenger *_Nonnull m, int32_t friendnumber)
static int clear_receipts(Messenger *m, int32_t friendnumber)
{ {
if (!m_friend_exists(m, friendnumber)) { if (!m_friend_exists(m, friendnumber)) {
return -1; return -1;
@@ -340,8 +330,7 @@ static int clear_receipts(Messenger *m, int32_t friendnumber)
return 0; return 0;
} }
non_null() static int add_receipt(Messenger *_Nonnull m, int32_t friendnumber, uint32_t packet_num, uint32_t msg_id)
static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num, uint32_t msg_id)
{ {
if (!m_friend_exists(m, friendnumber)) { if (!m_friend_exists(m, friendnumber)) {
return -1; return -1;
@@ -370,8 +359,7 @@ static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num,
* return -1 on failure. * return -1 on failure.
* return 0 if packet was received. * return 0 if packet was received.
*/ */
non_null() static int friend_received_packet(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t number)
static int friend_received_packet(const Messenger *m, int32_t friendnumber, uint32_t number)
{ {
if (!m_friend_exists(m, friendnumber)) { if (!m_friend_exists(m, friendnumber)) {
return -1; return -1;
@@ -428,8 +416,7 @@ void m_kill_group_connection(Messenger *m, const GC_Chat *chat)
kill_friend_connection(m->fr_c, chat->friend_connection_id); kill_friend_connection(m->fr_c, chat->friend_connection_id);
} }
non_null(1) nullable(3) static int do_receipts(Messenger *_Nonnull m, int32_t friendnumber, void *_Nullable userdata)
static int do_receipts(Messenger *m, int32_t friendnumber, void *userdata)
{ {
if (!m_friend_exists(m, friendnumber)) { if (!m_friend_exists(m, friendnumber)) {
return -1; return -1;
@@ -606,9 +593,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con
return 0; return 0;
} }
non_null() static bool write_cryptpacket_id(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t packet_id, const uint8_t *_Nonnull data, uint32_t length, bool congestion_control)
static bool write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data,
uint32_t length, bool congestion_control)
{ {
if (!m_friend_exists(m, friendnumber)) { if (!m_friend_exists(m, friendnumber)) {
return false; return false;
@@ -631,8 +616,7 @@ static bool write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8
/** @brief Send a name packet to friendnumber. /** @brief Send a name packet to friendnumber.
* length is the length with the NULL terminator. * length is the length with the NULL terminator.
*/ */
non_null() static bool m_sendname(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull name, uint16_t length)
static bool m_sendname(const Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length)
{ {
if (length > MAX_NAME_LENGTH) { if (length > MAX_NAME_LENGTH) {
return false; return false;
@@ -771,8 +755,7 @@ int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length)
return 0; return 0;
} }
non_null() static bool userstatus_from_int(uint8_t status, Userstatus *_Nonnull out_enum)
static bool userstatus_from_int(uint8_t status, Userstatus *out_enum)
{ {
switch (status) { switch (status) {
case USERSTATUS_NONE: { case USERSTATUS_NONE: {
@@ -927,27 +910,23 @@ int m_get_istyping(const Messenger *m, int32_t friendnumber)
return m->friendlist[friendnumber].is_typing ? 1 : 0; return m->friendlist[friendnumber].is_typing ? 1 : 0;
} }
non_null() static bool send_statusmessage(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull status, uint16_t length)
static bool send_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length)
{ {
return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length, false); return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length, false);
} }
non_null() static bool send_userstatus(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t status)
static bool send_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
{ {
return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &status, sizeof(status), false); return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &status, sizeof(status), false);
} }
non_null() static bool send_user_istyping(const Messenger *_Nonnull m, int32_t friendnumber, bool is_typing)
static bool send_user_istyping(const Messenger *m, int32_t friendnumber, bool is_typing)
{ {
const uint8_t typing = is_typing ? 1 : 0; const uint8_t typing = is_typing ? 1 : 0;
return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing), false); return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing), false);
} }
non_null() static int set_friend_statusmessage(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull status, uint16_t length)
static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length)
{ {
if (!m_friend_exists(m, friendnumber)) { if (!m_friend_exists(m, friendnumber)) {
return -1; return -1;
@@ -965,14 +944,12 @@ static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, co
return 0; return 0;
} }
non_null() static void set_friend_userstatus(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t status)
static void set_friend_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
{ {
userstatus_from_int(status, &m->friendlist[friendnumber].userstatus); userstatus_from_int(status, &m->friendlist[friendnumber].userstatus);
} }
non_null() static void set_friend_typing(const Messenger *_Nonnull m, int32_t friendnumber, bool is_typing)
static void set_friend_typing(const Messenger *m, int32_t friendnumber, bool is_typing)
{ {
m->friendlist[friendnumber].is_typing = is_typing; m->friendlist[friendnumber].is_typing = is_typing;
} }
@@ -1024,11 +1001,9 @@ void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *funct
m->core_connection_change = function; m->core_connection_change = function;
} }
non_null(1) nullable(3) static void check_friend_tcp_udp(Messenger *_Nonnull m, int32_t friendnumber, void *_Nullable userdata)
static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber, void *userdata)
{ {
const int last_connection_udp_tcp = m->friendlist[friendnumber].last_connection_udp_tcp; const int last_connection_udp_tcp = m->friendlist[friendnumber].last_connection_udp_tcp;
const int ret = m_get_friend_connectionstatus(m, friendnumber); const int ret = m_get_friend_connectionstatus(m, friendnumber);
if (ret == -1) { if (ret == -1) {
@@ -1044,11 +1019,9 @@ static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber, void *userd
m->friendlist[friendnumber].last_connection_udp_tcp = (Connection_Status)ret; m->friendlist[friendnumber].last_connection_udp_tcp = (Connection_Status)ret;
} }
non_null() static void break_files(const Messenger *_Nonnull m, int32_t friendnumber);
static void break_files(const Messenger *m, int32_t friendnumber);
non_null(1) nullable(4) static void check_friend_connectionstatus(Messenger *_Nonnull m, int32_t friendnumber, uint8_t status, void *_Nullable userdata)
static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata)
{ {
if (status == NOFRIEND) { if (status == NOFRIEND) {
return; return;
@@ -1074,8 +1047,7 @@ static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, ui
} }
} }
non_null(1) nullable(4) static void set_friend_status(Messenger *_Nonnull m, int32_t friendnumber, uint8_t status, void *_Nullable userdata)
static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata)
{ {
check_friend_connectionstatus(m, friendnumber, status, userdata); check_friend_connectionstatus(m, friendnumber, status, userdata);
m->friendlist[friendnumber].status = status; m->friendlist[friendnumber].status = status;
@@ -1193,9 +1165,8 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u
* @retval 1 on success * @retval 1 on success
* @retval 0 on failure * @retval 0 on failure
*/ */
non_null() static bool file_sendrequest(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t filenumber, uint32_t file_type, uint64_t filesize, const uint8_t *_Nonnull file_id,
static bool file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint32_t file_type, const uint8_t *_Nonnull filename, uint16_t filename_length)
uint64_t filesize, const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length)
{ {
if (!m_friend_exists(m, friendnumber)) { if (!m_friend_exists(m, friendnumber)) {
return false; return false;
@@ -1274,12 +1245,10 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_
return i; return i;
} }
non_null(1) nullable(6) static bool send_file_control_packet(const Messenger *_Nonnull m, int32_t friendnumber, bool inbound, uint8_t filenumber,
static bool send_file_control_packet(const Messenger *m, int32_t friendnumber, bool inbound, uint8_t filenumber, uint8_t control_type, const uint8_t *_Nullable data, uint16_t data_length)
uint8_t control_type, const uint8_t *data, uint16_t data_length)
{ {
assert(data_length == 0 || data != nullptr); assert(data_length == 0 || data != nullptr);
if ((unsigned int)(1 + 3 + data_length) > MAX_CRYPTO_DATA_SIZE) { if ((unsigned int)(1 + 3 + data_length) > MAX_CRYPTO_DATA_SIZE) {
return false; return false;
} }
@@ -1475,12 +1444,10 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
/** @return packet number on success. /** @return packet number on success.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null(1) nullable(4) static int64_t send_file_data_packet(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t filenumber, const uint8_t *_Nullable data,
static int64_t send_file_data_packet(const Messenger *m, int32_t friendnumber, uint8_t filenumber, const uint8_t *data,
uint16_t length) uint16_t length)
{ {
assert(length == 0 || data != nullptr); assert(length == 0 || data != nullptr);
if (!m_friend_exists(m, friendnumber)) { if (!m_friend_exists(m, friendnumber)) {
return -1; return -1;
} }
@@ -1588,8 +1555,7 @@ int send_file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber
* @return true if there's still work to do, false otherwise. * @return true if there's still work to do, false otherwise.
* *
*/ */
non_null() static bool do_all_filetransfers(Messenger *_Nonnull m, int32_t friendnumber, void *_Nonnull userdata, uint32_t *_Nonnull free_slots)
static bool do_all_filetransfers(Messenger *m, int32_t friendnumber, void *userdata, uint32_t *free_slots)
{ {
Friend *const friendcon = &m->friendlist[friendnumber]; Friend *const friendcon = &m->friendlist[friendnumber];
@@ -1656,8 +1622,7 @@ static bool do_all_filetransfers(Messenger *m, int32_t friendnumber, void *userd
return true; return true;
} }
non_null(1) nullable(3) static void do_reqchunk_filecb(Messenger *_Nonnull m, int32_t friendnumber, void *_Nullable userdata)
static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber, void *userdata)
{ {
// We're not currently doing any file transfers. // We're not currently doing any file transfers.
if (m->friendlist[friendnumber].num_sending_files == 0) { if (m->friendlist[friendnumber].num_sending_files == 0) {
@@ -1711,9 +1676,7 @@ static void break_files(const Messenger *m, int32_t friendnumber)
} }
} }
non_null() static struct File_Transfers *get_file_transfer(bool outbound, uint8_t filenumber, uint32_t *_Nonnull real_filenumber, Friend *_Nonnull sender)
static struct File_Transfers *get_file_transfer(bool outbound, uint8_t filenumber,
uint32_t *real_filenumber, Friend *sender)
{ {
struct File_Transfers *ft; struct File_Transfers *ft;
@@ -1735,9 +1698,8 @@ static struct File_Transfers *get_file_transfer(bool outbound, uint8_t filenumbe
/** @retval -1 on failure /** @retval -1 on failure
* @retval 0 on success. * @retval 0 on success.
*/ */
non_null(1, 6) nullable(8) static int handle_filecontrol(Messenger *_Nonnull m, int32_t friendnumber, bool outbound, uint8_t filenumber,
static int handle_filecontrol(Messenger *m, int32_t friendnumber, bool outbound, uint8_t filenumber, uint8_t control_type, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata)
uint8_t control_type, const uint8_t *data, uint16_t length, void *userdata)
{ {
uint32_t real_filenumber; uint32_t real_filenumber;
struct File_Transfers *ft = get_file_transfer(outbound, filenumber, &real_filenumber, &m->friendlist[friendnumber]); struct File_Transfers *ft = get_file_transfer(outbound, filenumber, &real_filenumber, &m->friendlist[friendnumber]);
@@ -1805,8 +1767,8 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, bool outbound,
uint64_t position; uint64_t position;
if (length != sizeof(position)) { if (length != sizeof(position)) {
LOGGER_DEBUG(m->log, "file control (friend %d, file %d): expected payload of length %d, but got %d", LOGGER_DEBUG(m->log, "file control (friend %d, file %d): expected payload of length %u, but got %d",
friendnumber, filenumber, (uint32_t)sizeof(position), length); friendnumber, filenumber, (unsigned int)sizeof(position), length);
return -1; return -1;
} }
@@ -1822,7 +1784,7 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, bool outbound,
if (position >= ft->size) { if (position >= ft->size) {
LOGGER_DEBUG(m->log, LOGGER_DEBUG(m->log,
"file control (friend %d, file %d): seek position %ld exceeds file size %ld", "file control (friend %d, file %d): seek position %lu exceeds file size %lu",
friendnumber, filenumber, (unsigned long)position, (unsigned long)ft->size); friendnumber, filenumber, (unsigned long)position, (unsigned long)ft->size);
return -1; return -1;
} }
@@ -1887,12 +1849,10 @@ int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const u
return 0; return 0;
} }
non_null(1, 3) nullable(5) static int handle_custom_lossless_packet(void *_Nonnull object, int friend_num, const uint8_t *_Nonnull packet, uint16_t length,
static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length, void *_Nullable userdata)
void *userdata)
{ {
Messenger *m = (Messenger *)object; Messenger *m = (Messenger *)object;
if (!m_friend_exists(m, friend_num)) { if (!m_friend_exists(m, friend_num)) {
return -1; return -1;
} }
@@ -1944,8 +1904,7 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const
} }
/** Function to filter out some friend requests*/ /** Function to filter out some friend requests*/
non_null() static int friend_already_added(void *_Nonnull object, const uint8_t *_Nonnull public_key)
static int friend_already_added(void *object, const uint8_t *public_key)
{ {
const Messenger *m = (const Messenger *)object; const Messenger *m = (const Messenger *)object;
@@ -1962,11 +1921,9 @@ static int friend_already_added(void *object, const uint8_t *public_key)
* @param friendcon_id friendlist index of the timed-out friend * @param friendcon_id friendlist index of the timed-out friend
* @param t time * @param t time
*/ */
non_null(1) nullable(4) static void check_friend_request_timed_out(Messenger *_Nonnull m, uint32_t friendcon_id, uint64_t t, void *_Nullable userdata)
static void check_friend_request_timed_out(Messenger *m, uint32_t friendcon_id, uint64_t t, void *userdata)
{ {
Friend *f = &m->friendlist[friendcon_id]; Friend *f = &m->friendlist[friendcon_id];
if (f->friendrequest_lastsent + f->friendrequest_timeout < t) { if (f->friendrequest_lastsent + f->friendrequest_timeout < t) {
set_friend_status(m, friendcon_id, FRIEND_ADDED, userdata); set_friend_status(m, friendcon_id, FRIEND_ADDED, userdata);
/* Double the default timeout every time if friendrequest is assumed /* Double the default timeout every time if friendrequest is assumed
@@ -1976,11 +1933,9 @@ static void check_friend_request_timed_out(Messenger *m, uint32_t friendcon_id,
} }
} }
non_null(1) nullable(4) static int m_handle_status(void *_Nonnull object, int friendcon_id, bool status, void *_Nullable userdata)
static int m_handle_status(void *object, int friendcon_id, bool status, void *userdata)
{ {
Messenger *m = (Messenger *)object; Messenger *m = (Messenger *)object;
if (status) { /* Went online. */ if (status) { /* Went online. */
send_online_packet(m, m->friendlist[friendcon_id].friendcon_id); send_online_packet(m, m->friendlist[friendcon_id].friendcon_id);
} else { /* Went offline. */ } else { /* Went offline. */
@@ -1992,8 +1947,7 @@ static int m_handle_status(void *object, int friendcon_id, bool status, void *us
return 0; return 0;
} }
non_null(1, 3) nullable(5) static int m_handle_packet_offline(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
static int m_handle_packet_offline(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
{ {
if (data_length == 0) { if (data_length == 0) {
set_friend_status(m, friendcon_id, FRIEND_CONFIRMED, userdata); set_friend_status(m, friendcon_id, FRIEND_CONFIRMED, userdata);
@@ -2002,8 +1956,7 @@ static int m_handle_packet_offline(Messenger *m, const int friendcon_id, const u
return 0; return 0;
} }
non_null(1, 3) nullable(5) static int m_handle_packet_nickname(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
static int m_handle_packet_nickname(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
{ {
if (data_length > MAX_NAME_LENGTH) { if (data_length > MAX_NAME_LENGTH) {
return 0; return 0;
@@ -2025,8 +1978,7 @@ static int m_handle_packet_nickname(Messenger *m, const int friendcon_id, const
return 0; return 0;
} }
non_null(1, 3) nullable(5) static int m_handle_packet_statusmessage(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
static int m_handle_packet_statusmessage(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
{ {
if (data_length > MAX_STATUSMESSAGE_LENGTH) { if (data_length > MAX_STATUSMESSAGE_LENGTH) {
return 0; return 0;
@@ -2046,8 +1998,7 @@ static int m_handle_packet_statusmessage(Messenger *m, const int friendcon_id, c
return 0; return 0;
} }
non_null(1, 3) nullable(5) static int m_handle_packet_userstatus(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
static int m_handle_packet_userstatus(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
{ {
if (data_length != 1) { if (data_length != 1) {
return 0; return 0;
@@ -2067,8 +2018,7 @@ static int m_handle_packet_userstatus(Messenger *m, const int friendcon_id, cons
return 0; return 0;
} }
non_null(1, 3) nullable(5) static int m_handle_packet_typing(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
static int m_handle_packet_typing(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
{ {
if (data_length != 1) { if (data_length != 1) {
return 0; return 0;
@@ -2085,8 +2035,8 @@ static int m_handle_packet_typing(Messenger *m, const int friendcon_id, const ui
return 0; return 0;
} }
non_null(1, 3) nullable(6) static int m_handle_packet_message(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, const Message_Type message_type,
static int m_handle_packet_message(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, const Message_Type message_type, void *userdata) void *_Nullable userdata)
{ {
if (data_length == 0) { if (data_length == 0) {
return 0; return 0;
@@ -2107,8 +2057,7 @@ static int m_handle_packet_message(Messenger *m, const int friendcon_id, const u
return 0; return 0;
} }
non_null(1, 3) nullable(5) static int m_handle_packet_invite_conference(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
static int m_handle_packet_invite_conference(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
{ {
if (data_length == 0) { if (data_length == 0) {
return 0; return 0;
@@ -2121,11 +2070,9 @@ static int m_handle_packet_invite_conference(Messenger *m, const int friendcon_i
return 0; return 0;
} }
non_null(1, 3) nullable(5) static int m_handle_packet_file_sendrequest(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
static int m_handle_packet_file_sendrequest(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
{ {
const unsigned int head_length = 1 + sizeof(uint32_t) + sizeof(uint64_t) + FILE_ID_LENGTH; const unsigned int head_length = 1 + sizeof(uint32_t) + sizeof(uint64_t) + FILE_ID_LENGTH;
if (data_length < head_length) { if (data_length < head_length) {
return 0; return 0;
} }
@@ -2186,8 +2133,7 @@ static int m_handle_packet_file_sendrequest(Messenger *m, const int friendcon_id
return 0; return 0;
} }
non_null(1, 3) nullable(5) static int m_handle_packet_file_control(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
static int m_handle_packet_file_control(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
{ {
if (data_length < 3) { if (data_length < 3) {
return 0; return 0;
@@ -2217,8 +2163,7 @@ static int m_handle_packet_file_control(Messenger *m, const int friendcon_id, co
return 0; return 0;
} }
non_null(1, 3) nullable(5) static int m_handle_packet_file_data(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
static int m_handle_packet_file_data(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
{ {
if (data_length < 1) { if (data_length < 1) {
return 0; return 0;
@@ -2283,8 +2228,7 @@ static int m_handle_packet_file_data(Messenger *m, const int friendcon_id, const
return 0; return 0;
} }
non_null(1, 3) nullable(5) static int m_handle_packet_invite_groupchat(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
static int m_handle_packet_invite_groupchat(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
{ {
// first two bytes are messenger packet type and group invite type // first two bytes are messenger packet type and group invite type
if (data_length < 2 + GC_JOIN_DATA_LENGTH) { if (data_length < 2 + GC_JOIN_DATA_LENGTH) {
@@ -2309,11 +2253,9 @@ static int m_handle_packet_invite_groupchat(Messenger *m, const int friendcon_id
return 0; return 0;
} }
non_null(1, 3) nullable(5) static int m_handle_packet(void *_Nonnull object, int friendcon_id, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata)
static int m_handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata)
{ {
Messenger *m = (Messenger *)object; Messenger *m = (Messenger *)object;
if (length == 0) { if (length == 0) {
return -1; return -1;
} }
@@ -2364,11 +2306,9 @@ static int m_handle_packet(void *object, int friendcon_id, const uint8_t *data,
return handle_custom_lossless_packet(object, friendcon_id, data, length, userdata); return handle_custom_lossless_packet(object, friendcon_id, data, length, userdata);
} }
non_null(1) nullable(2) static void do_friends(Messenger *_Nonnull m, void *_Nullable userdata)
static void do_friends(Messenger *m, void *userdata)
{ {
const uint64_t temp_time = mono_time_get(m->mono_time); const uint64_t temp_time = mono_time_get(m->mono_time);
for (uint32_t i = 0; i < m->numfriends; ++i) { for (uint32_t i = 0; i < m->numfriends; ++i) {
if (m->friendlist[i].status == FRIEND_ADDED) { if (m->friendlist[i].status == FRIEND_ADDED) {
const int fr = send_friend_request_packet(m->fr_c, m->friendlist[i].friendcon_id, m->friendlist[i].friendrequest_nospam, const int fr = send_friend_request_packet(m->fr_c, m->friendlist[i].friendcon_id, m->friendlist[i].friendrequest_nospam,
@@ -2423,11 +2363,9 @@ static void do_friends(Messenger *m, void *userdata)
} }
} }
non_null(1) nullable(2) static void m_connection_status_callback(Messenger *_Nonnull m, void *_Nullable userdata)
static void m_connection_status_callback(Messenger *m, void *userdata)
{ {
const Onion_Connection_Status conn_status = onion_connection_status(m->onion_c); const Onion_Connection_Status conn_status = onion_connection_status(m->onion_c);
if (conn_status != m->last_connection_status) { if (conn_status != m->last_connection_status) {
if (m->core_connection_change != nullptr) { if (m->core_connection_change != nullptr) {
m->core_connection_change(m, conn_status, userdata); m->core_connection_change(m, conn_status, userdata);
@@ -2441,8 +2379,7 @@ static void m_connection_status_callback(Messenger *m, void *userdata)
#define IDSTRING_LEN (CRYPTO_PUBLIC_KEY_SIZE * 2 + 1) #define IDSTRING_LEN (CRYPTO_PUBLIC_KEY_SIZE * 2 + 1)
/** id_str should be of length at least IDSTRING_LEN */ /** id_str should be of length at least IDSTRING_LEN */
non_null() static char *id_to_string(const uint8_t *_Nonnull pk, char *_Nonnull id_str, size_t length)
static char *id_to_string(const uint8_t *pk, char *id_str, size_t length)
{ {
if (length < IDSTRING_LEN) { if (length < IDSTRING_LEN) {
snprintf(id_str, length, "Bad buf length"); snprintf(id_str, length, "Bad buf length");
@@ -2484,8 +2421,7 @@ uint32_t messenger_run_interval(const Messenger *m)
* *
* @retval true if success. * @retval true if success.
*/ */
non_null() static bool self_announce_group(const Messenger *_Nonnull m, GC_Chat *_Nonnull chat, Onion_Friend *_Nonnull onion_friend)
static bool self_announce_group(const Messenger *m, GC_Chat *chat, Onion_Friend *onion_friend)
{ {
GC_Public_Announce announce = {{{{{0}}}}}; GC_Public_Announce announce = {{{{{0}}}}};
@@ -2531,13 +2467,12 @@ static bool self_announce_group(const Messenger *m, GC_Chat *chat, Onion_Friend
memzero(chat->announced_tcp_relay_pk, sizeof(chat->announced_tcp_relay_pk)); memzero(chat->announced_tcp_relay_pk, sizeof(chat->announced_tcp_relay_pk));
} }
LOGGER_DEBUG(chat->log, "Published group announce. TCP relays: %d, UDP status: %d", tcp_num, LOGGER_DEBUG(chat->log, "Published group announce. TCP relays: %d, UDP status: %u", tcp_num,
chat->self_udp_status); chat->self_udp_status);
return true; return true;
} }
non_null() static void do_gc_onion_friends(const Messenger *_Nonnull m)
static void do_gc_onion_friends(const Messenger *m)
{ {
const uint16_t num_friends = onion_get_friend_count(m->onion_c); const uint16_t num_friends = onion_get_friend_count(m->onion_c);
@@ -2668,7 +2603,7 @@ void do_messenger(Messenger *m, void *userdata)
if (msgfptr != nullptr) { if (msgfptr != nullptr) {
char id_str[IDSTRING_LEN]; char id_str[IDSTRING_LEN];
LOGGER_TRACE(m->log, "F[%2u:%2u] <%s> %s", LOGGER_TRACE(m->log, "F[%2d:%2u] <%s> %s",
dht2m[friend_idx], friend_idx, msgfptr->name, dht2m[friend_idx], friend_idx, msgfptr->name,
id_to_string(msgfptr->real_pk, id_str, sizeof(id_str))); id_to_string(msgfptr->real_pk, id_str, sizeof(id_str)));
} else { } else {
@@ -2759,8 +2694,7 @@ static uint32_t friend_size(void)
return data; return data;
} }
non_null() static uint8_t *friend_save(const struct Saved_Friend *_Nonnull temp, uint8_t *_Nonnull data)
static uint8_t *friend_save(const struct Saved_Friend *temp, uint8_t *data)
{ {
#define VALUE_MEMBER(data, name) \ #define VALUE_MEMBER(data, name) \
do { \ do { \
@@ -2796,8 +2730,7 @@ static uint8_t *friend_save(const struct Saved_Friend *temp, uint8_t *data)
return data; return data;
} }
non_null() static const uint8_t *friend_load(struct Saved_Friend *_Nonnull temp, const uint8_t *_Nonnull data)
static const uint8_t *friend_load(struct Saved_Friend *temp, const uint8_t *data)
{ {
#define VALUE_MEMBER(data, name) \ #define VALUE_MEMBER(data, name) \
do { \ do { \
@@ -2833,8 +2766,7 @@ static const uint8_t *friend_load(struct Saved_Friend *temp, const uint8_t *data
return data; return data;
} }
non_null() static uint32_t m_state_plugins_size(const Messenger *_Nonnull m)
static uint32_t m_state_plugins_size(const Messenger *m)
{ {
const uint32_t size32 = sizeof(uint32_t); const uint32_t size32 = sizeof(uint32_t);
const uint32_t sizesubhead = size32 * 2; const uint32_t sizesubhead = size32 * 2;
@@ -2879,8 +2811,7 @@ bool m_register_state_plugin(Messenger *m, State_Type type, m_state_size_cb *siz
return true; return true;
} }
non_null() static uint32_t m_plugin_size(const Messenger *_Nonnull m, State_Type type)
static uint32_t m_plugin_size(const Messenger *m, State_Type type)
{ {
for (uint8_t i = 0; i < m->options.state_plugins_length; ++i) { for (uint8_t i = 0; i < m->options.state_plugins_length; ++i) {
const Messenger_State_Plugin plugin = m->options.state_plugins[i]; const Messenger_State_Plugin plugin = m->options.state_plugins[i];
@@ -2913,14 +2844,12 @@ uint8_t *messenger_save(const Messenger *m, uint8_t *data)
} }
// nospam state plugin // nospam state plugin
non_null() static uint32_t nospam_keys_size(const Messenger *_Nonnull m)
static uint32_t nospam_keys_size(const Messenger *m)
{ {
return sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE; return sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE;
} }
non_null() static State_Load_Status load_nospam_keys(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
static State_Load_Status load_nospam_keys(Messenger *m, const uint8_t *data, uint32_t length)
{ {
if (length != m_plugin_size(m, STATE_TYPE_NOSPAMKEYS)) { if (length != m_plugin_size(m, STATE_TYPE_NOSPAMKEYS)) {
return STATE_LOAD_STATUS_ERROR; return STATE_LOAD_STATUS_ERROR;
@@ -2939,8 +2868,7 @@ static State_Load_Status load_nospam_keys(Messenger *m, const uint8_t *data, uin
return STATE_LOAD_STATUS_CONTINUE; return STATE_LOAD_STATUS_CONTINUE;
} }
non_null() static uint8_t *save_nospam_keys(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
static uint8_t *save_nospam_keys(const Messenger *m, uint8_t *data)
{ {
const uint32_t len = m_plugin_size(m, STATE_TYPE_NOSPAMKEYS); const uint32_t len = m_plugin_size(m, STATE_TYPE_NOSPAMKEYS);
static_assert(sizeof(get_nospam(m->fr)) == sizeof(uint32_t), "nospam doesn't fit in a 32 bit int"); static_assert(sizeof(get_nospam(m->fr)) == sizeof(uint32_t), "nospam doesn't fit in a 32 bit int");
@@ -2953,14 +2881,12 @@ static uint8_t *save_nospam_keys(const Messenger *m, uint8_t *data)
} }
// DHT state plugin // DHT state plugin
non_null() static uint32_t m_dht_size(const Messenger *_Nonnull m)
static uint32_t m_dht_size(const Messenger *m)
{ {
return dht_size(m->dht); return dht_size(m->dht);
} }
non_null() static uint8_t *save_dht(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
static uint8_t *save_dht(const Messenger *m, uint8_t *data)
{ {
const uint32_t len = m_plugin_size(m, STATE_TYPE_DHT); const uint32_t len = m_plugin_size(m, STATE_TYPE_DHT);
data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_DHT); data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_DHT);
@@ -2969,22 +2895,19 @@ static uint8_t *save_dht(const Messenger *m, uint8_t *data)
return data; return data;
} }
non_null() static State_Load_Status m_dht_load(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
static State_Load_Status m_dht_load(Messenger *m, const uint8_t *data, uint32_t length)
{ {
dht_load(m->dht, data, length); // TODO(endoffile78): Should we throw an error if dht_load fails? dht_load(m->dht, data, length); // TODO(endoffile78): Should we throw an error if dht_load fails?
return STATE_LOAD_STATUS_CONTINUE; return STATE_LOAD_STATUS_CONTINUE;
} }
// friendlist state plugin // friendlist state plugin
non_null() static uint32_t saved_friendslist_size(const Messenger *_Nonnull m)
static uint32_t saved_friendslist_size(const Messenger *m)
{ {
return count_friendlist(m) * friend_size(); return count_friendlist(m) * friend_size();
} }
non_null() static uint8_t *friends_list_save(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
static uint8_t *friends_list_save(const Messenger *m, uint8_t *data)
{ {
const uint32_t len = m_plugin_size(m, STATE_TYPE_FRIENDS); const uint32_t len = m_plugin_size(m, STATE_TYPE_FRIENDS);
data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_FRIENDS); data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_FRIENDS);
@@ -3034,8 +2957,7 @@ static uint8_t *friends_list_save(const Messenger *m, uint8_t *data)
return data; return data;
} }
non_null() static State_Load_Status friends_list_load(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
static State_Load_Status friends_list_load(Messenger *m, const uint8_t *data, uint32_t length)
{ {
const uint32_t l_friend_size = friend_size(); const uint32_t l_friend_size = friend_size();
@@ -3078,8 +3000,7 @@ static State_Load_Status friends_list_load(Messenger *m, const uint8_t *data, ui
return STATE_LOAD_STATUS_CONTINUE; return STATE_LOAD_STATUS_CONTINUE;
} }
non_null() static void pack_groupchats(const GC_Session *_Nonnull c, Bin_Pack *_Nonnull bp)
static void pack_groupchats(const GC_Session *c, Bin_Pack *bp)
{ {
assert(bp != nullptr && c != nullptr); assert(bp != nullptr && c != nullptr);
bin_pack_array(bp, gc_count_groups(c)); bin_pack_array(bp, gc_count_groups(c));
@@ -3095,23 +3016,20 @@ static void pack_groupchats(const GC_Session *c, Bin_Pack *bp)
} }
} }
non_null() static bool pack_groupchats_handler(const void *_Nonnull obj, const Logger *_Nonnull logger, Bin_Pack *_Nonnull bp)
static bool pack_groupchats_handler(const void *obj, const Logger *logger, Bin_Pack *bp)
{ {
const GC_Session *session = (const GC_Session *)obj; const GC_Session *session = (const GC_Session *)obj;
pack_groupchats(session, bp); pack_groupchats(session, bp);
return true; // TODO(iphydf): Return bool from pack functions. return true; // TODO(iphydf): Return bool from pack functions.
} }
non_null() static uint32_t saved_groups_size(const Messenger *_Nonnull m)
static uint32_t saved_groups_size(const Messenger *m)
{ {
const GC_Session *session = m->group_handler; const GC_Session *session = m->group_handler;
return bin_pack_obj_size(pack_groupchats_handler, session, m->log); return bin_pack_obj_size(pack_groupchats_handler, session, m->log);
} }
non_null() static uint8_t *groups_save(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
static uint8_t *groups_save(const Messenger *m, uint8_t *data)
{ {
const GC_Session *c = m->group_handler; const GC_Session *c = m->group_handler;
@@ -3141,8 +3059,7 @@ static uint8_t *groups_save(const Messenger *m, uint8_t *data)
return data; return data;
} }
non_null() static bool handle_groups_load(void *_Nonnull obj, Bin_Unpack *_Nonnull bu)
static bool handle_groups_load(void *obj, Bin_Unpack *bu)
{ {
Messenger *m = (Messenger *)obj; Messenger *m = (Messenger *)obj;
@@ -3169,8 +3086,7 @@ static bool handle_groups_load(void *obj, Bin_Unpack *bu)
return true; return true;
} }
non_null() static State_Load_Status groups_load(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
static State_Load_Status groups_load(Messenger *m, const uint8_t *data, uint32_t length)
{ {
if (!bin_unpack_obj(m->mem, handle_groups_load, m, data, length)) { if (!bin_unpack_obj(m->mem, handle_groups_load, m, data, length)) {
LOGGER_ERROR(m->log, "msgpack failed to unpack groupchats array"); LOGGER_ERROR(m->log, "msgpack failed to unpack groupchats array");
@@ -3181,14 +3097,12 @@ static State_Load_Status groups_load(Messenger *m, const uint8_t *data, uint32_t
} }
// name state plugin // name state plugin
non_null() static uint32_t name_size(const Messenger *_Nonnull m)
static uint32_t name_size(const Messenger *m)
{ {
return m->name_length; return m->name_length;
} }
non_null() static uint8_t *save_name(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
static uint8_t *save_name(const Messenger *m, uint8_t *data)
{ {
const uint32_t len = m_plugin_size(m, STATE_TYPE_NAME); const uint32_t len = m_plugin_size(m, STATE_TYPE_NAME);
data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_NAME); data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_NAME);
@@ -3197,8 +3111,7 @@ static uint8_t *save_name(const Messenger *m, uint8_t *data)
return data; return data;
} }
non_null() static State_Load_Status load_name(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
static State_Load_Status load_name(Messenger *m, const uint8_t *data, uint32_t length)
{ {
if (length > 0 && length <= MAX_NAME_LENGTH) { if (length > 0 && length <= MAX_NAME_LENGTH) {
setname(m, data, length); setname(m, data, length);
@@ -3208,14 +3121,12 @@ static State_Load_Status load_name(Messenger *m, const uint8_t *data, uint32_t l
} }
// status message state plugin // status message state plugin
non_null() static uint32_t status_message_size(const Messenger *_Nonnull m)
static uint32_t status_message_size(const Messenger *m)
{ {
return m->statusmessage_length; return m->statusmessage_length;
} }
non_null() static uint8_t *save_status_message(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
static uint8_t *save_status_message(const Messenger *m, uint8_t *data)
{ {
const uint32_t len = m_plugin_size(m, STATE_TYPE_STATUSMESSAGE); const uint32_t len = m_plugin_size(m, STATE_TYPE_STATUSMESSAGE);
data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_STATUSMESSAGE); data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_STATUSMESSAGE);
@@ -3224,8 +3135,7 @@ static uint8_t *save_status_message(const Messenger *m, uint8_t *data)
return data; return data;
} }
non_null() static State_Load_Status load_status_message(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
static State_Load_Status load_status_message(Messenger *m, const uint8_t *data, uint32_t length)
{ {
if (length > 0 && length <= MAX_STATUSMESSAGE_LENGTH) { if (length > 0 && length <= MAX_STATUSMESSAGE_LENGTH) {
m_set_statusmessage(m, data, length); m_set_statusmessage(m, data, length);
@@ -3235,14 +3145,12 @@ static State_Load_Status load_status_message(Messenger *m, const uint8_t *data,
} }
// status state plugin // status state plugin
non_null() static uint32_t status_size(const Messenger *_Nonnull m)
static uint32_t status_size(const Messenger *m)
{ {
return 1; return 1;
} }
non_null() static uint8_t *save_status(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
static uint8_t *save_status(const Messenger *m, uint8_t *data)
{ {
const uint32_t len = m_plugin_size(m, STATE_TYPE_STATUS); const uint32_t len = m_plugin_size(m, STATE_TYPE_STATUS);
data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_STATUS); data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_STATUS);
@@ -3251,8 +3159,7 @@ static uint8_t *save_status(const Messenger *m, uint8_t *data)
return data; return data;
} }
non_null() static State_Load_Status load_status(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
static State_Load_Status load_status(Messenger *m, const uint8_t *data, uint32_t length)
{ {
if (length == 1) { if (length == 1) {
m_set_userstatus(m, *data); m_set_userstatus(m, *data);
@@ -3262,14 +3169,12 @@ static State_Load_Status load_status(Messenger *m, const uint8_t *data, uint32_t
} }
// TCP Relay state plugin // TCP Relay state plugin
non_null() static uint32_t tcp_relay_size(const Messenger *_Nonnull m)
static uint32_t tcp_relay_size(const Messenger *m)
{ {
return NUM_SAVED_TCP_RELAYS * packed_node_size(net_family_tcp_ipv6()); return NUM_SAVED_TCP_RELAYS * packed_node_size(net_family_tcp_ipv6());
} }
non_null() static uint8_t *save_tcp_relays(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
static uint8_t *save_tcp_relays(const Messenger *m, uint8_t *data)
{ {
Node_format relays[NUM_SAVED_TCP_RELAYS] = {{{0}}}; Node_format relays[NUM_SAVED_TCP_RELAYS] = {{{0}}};
uint8_t *temp_data = data; uint8_t *temp_data = data;
@@ -3293,8 +3198,7 @@ static uint8_t *save_tcp_relays(const Messenger *m, uint8_t *data)
return data; return data;
} }
non_null() static State_Load_Status load_tcp_relays(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
static State_Load_Status load_tcp_relays(Messenger *m, const uint8_t *data, uint32_t length)
{ {
if (length > 0) { if (length > 0) {
const int num = unpack_nodes(m->loaded_relays, NUM_SAVED_TCP_RELAYS, nullptr, data, length, true); const int num = unpack_nodes(m->loaded_relays, NUM_SAVED_TCP_RELAYS, nullptr, data, length, true);
@@ -3312,14 +3216,12 @@ static State_Load_Status load_tcp_relays(Messenger *m, const uint8_t *data, uint
} }
// path node state plugin // path node state plugin
non_null() static uint32_t path_node_size(const Messenger *_Nonnull m)
static uint32_t path_node_size(const Messenger *m)
{ {
return NUM_SAVED_PATH_NODES * packed_node_size(net_family_tcp_ipv6()); return NUM_SAVED_PATH_NODES * packed_node_size(net_family_tcp_ipv6());
} }
non_null() static uint8_t *save_path_nodes(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
static uint8_t *save_path_nodes(const Messenger *m, uint8_t *data)
{ {
Node_format nodes[NUM_SAVED_PATH_NODES] = {{{0}}}; Node_format nodes[NUM_SAVED_PATH_NODES] = {{{0}}};
uint8_t *temp_data = data; uint8_t *temp_data = data;
@@ -3336,8 +3238,7 @@ static uint8_t *save_path_nodes(const Messenger *m, uint8_t *data)
return data; return data;
} }
non_null() static State_Load_Status load_path_nodes(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
static State_Load_Status load_path_nodes(Messenger *m, const uint8_t *data, uint32_t length)
{ {
if (length > 0) { if (length > 0) {
Node_format nodes[NUM_SAVED_PATH_NODES]; Node_format nodes[NUM_SAVED_PATH_NODES];
@@ -3355,8 +3256,7 @@ static State_Load_Status load_path_nodes(Messenger *m, const uint8_t *data, uint
return STATE_LOAD_STATUS_CONTINUE; return STATE_LOAD_STATUS_CONTINUE;
} }
non_null() static void m_register_default_plugins(Messenger *_Nonnull m)
static void m_register_default_plugins(Messenger *m)
{ {
m_register_state_plugin(m, STATE_TYPE_NOSPAMKEYS, nospam_keys_size, load_nospam_keys, save_nospam_keys); m_register_state_plugin(m, STATE_TYPE_NOSPAMKEYS, nospam_keys_size, load_nospam_keys, save_nospam_keys);
m_register_state_plugin(m, STATE_TYPE_DHT, m_dht_size, m_dht_load, save_dht); m_register_state_plugin(m, STATE_TYPE_DHT, m_dht_size, m_dht_load, save_dht);
@@ -3411,7 +3311,7 @@ uint32_t count_friendlist(const Messenger *m)
* If the array was too small, the contents * If the array was too small, the contents
* of out_list will be truncated to list_size. * of out_list will be truncated to list_size.
*/ */
uint32_t copy_friendlist(Messenger const *m, uint32_t *out_list, uint32_t list_size) uint32_t copy_friendlist(const Messenger *m, uint32_t *out_list, uint32_t list_size)
{ {
if (out_list == nullptr) { if (out_list == nullptr) {
return 0; return 0;
@@ -3438,9 +3338,8 @@ uint32_t copy_friendlist(Messenger const *m, uint32_t *out_list, uint32_t list_s
} }
static fr_friend_request_cb m_handle_friend_request; static fr_friend_request_cb m_handle_friend_request;
non_null(1, 2, 3) nullable(5)
static void m_handle_friend_request( static void m_handle_friend_request(
void *object, const uint8_t *public_key, const uint8_t *message, size_t length, void *user_data) void *_Nonnull object, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull message, size_t length, void *_Nullable user_data)
{ {
Messenger *m = (Messenger *)object; Messenger *m = (Messenger *)object;
assert(m != nullptr); assert(m != nullptr);

View File

@@ -54,19 +54,19 @@ typedef struct Messenger Messenger;
#endif /* MESSENGER_DEFINED */ #endif /* MESSENGER_DEFINED */
// Returns the size of the data // Returns the size of the data
typedef uint32_t m_state_size_cb(const Messenger *m); typedef uint32_t m_state_size_cb(const Messenger *_Nonnull m);
// Returns the new pointer to data // Returns the new pointer to data
typedef uint8_t *m_state_save_cb(const Messenger *m, uint8_t *data); typedef uint8_t *m_state_save_cb(const Messenger *_Nonnull m, uint8_t *_Nonnull data);
// Returns if there were any erros during loading // Returns if there were any erros during loading
typedef State_Load_Status m_state_load_cb(Messenger *m, const uint8_t *data, uint32_t length); typedef State_Load_Status m_state_load_cb(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length);
typedef struct Messenger_State_Plugin { typedef struct Messenger_State_Plugin {
State_Type type; State_Type type;
m_state_size_cb *size; m_state_size_cb *_Nullable size;
m_state_save_cb *save; m_state_save_cb *_Nullable save;
m_state_load_cb *load; m_state_load_cb *_Nullable load;
} Messenger_State_Plugin; } Messenger_State_Plugin;
typedef struct Messenger_Options { typedef struct Messenger_Options {
@@ -81,11 +81,11 @@ typedef struct Messenger_Options {
bool dht_announcements_enabled; bool dht_announcements_enabled;
bool groups_persistence_enabled; bool groups_persistence_enabled;
logger_cb *log_callback; logger_cb *_Nullable log_callback;
void *log_context; void *_Nullable log_context;
void *log_user_data; void *_Nullable log_user_data;
Messenger_State_Plugin *state_plugins; Messenger_State_Plugin *_Nullable state_plugins;
uint8_t state_plugins_length; uint8_t state_plugins_length;
bool dns_enabled; bool dns_enabled;
@@ -94,7 +94,7 @@ typedef struct Messenger_Options {
struct Receipts { struct Receipts {
uint32_t packet_num; uint32_t packet_num;
uint32_t msg_id; uint32_t msg_id;
struct Receipts *next; struct Receipts *_Nullable next;
}; };
/** Status definitions. */ /** Status definitions. */
@@ -177,36 +177,36 @@ typedef enum Filekind {
FILEKIND_AVATAR, FILEKIND_AVATAR,
} Filekind; } Filekind;
typedef void m_self_connection_status_cb(Messenger *m, Onion_Connection_Status connection_status, void *user_data); typedef void m_self_connection_status_cb(Messenger *_Nonnull m, Onion_Connection_Status connection_status, void *_Nullable user_data);
typedef void m_friend_status_cb(Messenger *m, uint32_t friend_number, unsigned int status, void *user_data); typedef void m_friend_status_cb(Messenger *_Nonnull m, uint32_t friend_number, unsigned int status, void *_Nullable user_data);
typedef void m_friend_connection_status_cb(Messenger *m, uint32_t friend_number, unsigned int connection_status, typedef void m_friend_connection_status_cb(Messenger *_Nonnull m, uint32_t friend_number, unsigned int connection_status,
void *user_data); void *_Nullable user_data);
typedef void m_friend_message_cb(Messenger *m, uint32_t friend_number, unsigned int message_type, typedef void m_friend_message_cb(Messenger *_Nonnull m, uint32_t friend_number, unsigned int message_type,
const uint8_t *message, size_t length, void *user_data); const uint8_t *_Nonnull message, size_t length, void *_Nullable user_data);
typedef void m_file_recv_control_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, unsigned int control, typedef void m_file_recv_control_cb(Messenger *_Nonnull m, uint32_t friend_number, uint32_t file_number, unsigned int control,
void *user_data); void *_Nullable user_data);
typedef void m_friend_request_cb(Messenger *m, const uint8_t *public_key, const uint8_t *message, size_t length, typedef void m_friend_request_cb(Messenger *_Nonnull m, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull message, size_t length,
void *user_data); void *_Nullable user_data);
typedef void m_friend_name_cb(Messenger *m, uint32_t friend_number, const uint8_t *name, size_t length, typedef void m_friend_name_cb(Messenger *_Nonnull m, uint32_t friend_number, const uint8_t *_Nonnull name, size_t length,
void *user_data); void *_Nullable user_data);
typedef void m_friend_status_message_cb(Messenger *m, uint32_t friend_number, const uint8_t *message, size_t length, typedef void m_friend_status_message_cb(Messenger *_Nonnull m, uint32_t friend_number, const uint8_t *_Nonnull message, size_t length,
void *user_data); void *_Nullable user_data);
typedef void m_friend_typing_cb(Messenger *m, uint32_t friend_number, bool is_typing, void *user_data); typedef void m_friend_typing_cb(Messenger *_Nonnull m, uint32_t friend_number, bool is_typing, void *_Nullable user_data);
typedef void m_friend_read_receipt_cb(Messenger *m, uint32_t friend_number, uint32_t message_id, void *user_data); typedef void m_friend_read_receipt_cb(Messenger *_Nonnull m, uint32_t friend_number, uint32_t message_id, void *_Nullable user_data);
typedef void m_file_recv_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, uint32_t kind, typedef void m_file_recv_cb(Messenger *_Nonnull m, uint32_t friend_number, uint32_t file_number, uint32_t kind,
uint64_t file_size, const uint8_t *filename, size_t filename_length, void *user_data); uint64_t file_size, const uint8_t *_Nonnull filename, size_t filename_length, void *_Nullable user_data);
typedef void m_file_chunk_request_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, uint64_t position, typedef void m_file_chunk_request_cb(Messenger *_Nonnull m, uint32_t friend_number, uint32_t file_number, uint64_t position,
size_t length, void *user_data); size_t length, void *_Nullable user_data);
typedef void m_file_recv_chunk_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, uint64_t position, typedef void m_file_recv_chunk_cb(Messenger *_Nonnull m, uint32_t friend_number, uint32_t file_number, uint64_t position,
const uint8_t *data, size_t length, void *user_data); const uint8_t *_Nullable data, size_t length, void *_Nullable user_data);
typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data, typedef void m_friend_lossy_packet_cb(Messenger *_Nonnull m, uint32_t friend_number, uint8_t packet_id, const uint8_t *_Nonnull data,
size_t length, void *user_data); size_t length, void *_Nullable user_data);
typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data, typedef void m_friend_lossless_packet_cb(Messenger *_Nonnull m, uint32_t friend_number, uint8_t packet_id, const uint8_t *_Nonnull data,
size_t length, void *user_data); size_t length, void *_Nullable user_data);
typedef void m_conference_invite_cb(Messenger *m, uint32_t friend_number, const uint8_t *cookie, uint16_t length, typedef void m_conference_invite_cb(Messenger *_Nonnull m, uint32_t friend_number, const uint8_t *_Nonnull cookie, uint16_t length,
void *user_data); void *_Nullable user_data);
typedef void m_group_invite_cb(const Messenger *m, uint32_t friend_number, const uint8_t *invite_data, size_t length, typedef void m_group_invite_cb(const Messenger *_Nonnull m, uint32_t friend_number, const uint8_t *_Nonnull invite_data, size_t length,
const uint8_t *group_name, size_t group_name_length, void *user_data); const uint8_t *_Nullable group_name, size_t group_name_length, void *_Nullable user_data);
typedef struct Friend { typedef struct Friend {
uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE];
@@ -236,33 +236,33 @@ typedef struct Friend {
uint32_t num_sending_files; uint32_t num_sending_files;
struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES]; struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
struct Receipts *receipts_start; struct Receipts *_Nullable receipts_start;
struct Receipts *receipts_end; struct Receipts *_Nullable receipts_end;
} Friend; } Friend;
struct Messenger { struct Messenger {
Logger *log; Logger *_Nullable log;
Mono_Time *mono_time; Mono_Time *_Nullable mono_time;
const Memory *mem; const Memory *_Nullable mem;
const Random *rng; const Random *_Nullable rng;
const Network *ns; const Network *_Nullable ns;
Networking_Core *net; Networking_Core *_Nonnull net;
Net_Crypto *net_crypto; Net_Crypto *_Nonnull net_crypto;
Net_Profile *tcp_np; Net_Profile *_Nullable tcp_np;
DHT *dht; DHT *_Nonnull dht;
Forwarding *forwarding; Forwarding *_Nullable forwarding;
Announcements *announce; Announcements *_Nullable announce;
Onion *onion; Onion *_Nullable onion;
Onion_Announce *onion_a; Onion_Announce *_Nullable onion_a;
Onion_Client *onion_c; Onion_Client *_Nullable onion_c;
Friend_Connections *fr_c; Friend_Connections *_Nullable fr_c;
TCP_Server *tcp_server; TCP_Server *_Nullable tcp_server;
Friend_Requests *fr; Friend_Requests *_Nullable fr;
uint8_t name[MAX_NAME_LENGTH]; uint8_t name[MAX_NAME_LENGTH];
uint16_t name_length; uint16_t name_length;
@@ -271,43 +271,43 @@ struct Messenger {
Userstatus userstatus; Userstatus userstatus;
Friend *friendlist; Friend *_Nullable friendlist;
uint32_t numfriends; uint32_t numfriends;
uint64_t lastdump; uint64_t lastdump;
uint8_t is_receiving_file; uint8_t is_receiving_file;
GC_Session *group_handler; GC_Session *_Nonnull group_handler;
GC_Announces_List *group_announce; GC_Announces_List *_Nonnull group_announce;
bool has_added_relays; // If the first connection has occurred in do_messenger bool has_added_relays; // If the first connection has occurred in do_messenger
uint16_t num_loaded_relays; uint16_t num_loaded_relays;
Node_format loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config Node_format loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config
m_friend_request_cb *friend_request; m_friend_request_cb *_Nullable friend_request;
m_friend_message_cb *friend_message; m_friend_message_cb *_Nullable friend_message;
m_friend_name_cb *friend_namechange; m_friend_name_cb *_Nullable friend_namechange;
m_friend_status_message_cb *friend_statusmessagechange; m_friend_status_message_cb *_Nullable friend_statusmessagechange;
m_friend_status_cb *friend_userstatuschange; m_friend_status_cb *_Nullable friend_userstatuschange;
m_friend_typing_cb *friend_typingchange; m_friend_typing_cb *_Nullable friend_typingchange;
m_friend_read_receipt_cb *read_receipt; m_friend_read_receipt_cb *_Nullable read_receipt;
m_friend_connection_status_cb *friend_connectionstatuschange; m_friend_connection_status_cb *_Nullable friend_connectionstatuschange;
struct Group_Chats *conferences_object; struct Group_Chats *_Nullable conferences_object;
m_conference_invite_cb *conference_invite; m_conference_invite_cb *_Nullable conference_invite;
m_group_invite_cb *group_invite; m_group_invite_cb *_Nullable group_invite;
m_file_recv_cb *file_sendrequest; m_file_recv_cb *_Nullable file_sendrequest;
m_file_recv_control_cb *file_filecontrol; m_file_recv_control_cb *_Nullable file_filecontrol;
m_file_recv_chunk_cb *file_filedata; m_file_recv_chunk_cb *_Nullable file_filedata;
m_file_chunk_request_cb *file_reqchunk; m_file_chunk_request_cb *_Nullable file_reqchunk;
m_friend_lossy_packet_cb *lossy_packethandler; m_friend_lossy_packet_cb *_Nullable lossy_packethandler;
m_friend_lossless_packet_cb *lossless_packethandler; m_friend_lossless_packet_cb *_Nullable lossless_packethandler;
m_self_connection_status_cb *core_connection_change; m_self_connection_status_cb *_Nullable core_connection_change;
Onion_Connection_Status last_connection_status; Onion_Connection_Status last_connection_status;
Messenger_Options options; Messenger_Options options;
@@ -318,16 +318,14 @@ struct Messenger {
* *
* @param friendnumber The index in the friend list. * @param friendnumber The index in the friend list.
*/ */
non_null() bool friend_is_valid(const Messenger *_Nonnull m, int32_t friendnumber);
bool friend_is_valid(const Messenger *m, int32_t friendnumber);
/** /**
* Format: `[real_pk (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]` * Format: `[real_pk (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]`
* *
* @param[out] address FRIEND_ADDRESS_SIZE byte address to give to others. * @param[out] address FRIEND_ADDRESS_SIZE byte address to give to others.
*/ */
non_null() void getaddress(const Messenger *_Nonnull m, uint8_t *_Nonnull address);
void getaddress(const Messenger *m, uint8_t *address);
/** /**
* Add a friend. * Add a friend.
@@ -350,8 +348,7 @@ void getaddress(const Messenger *m, uint8_t *address);
* (the nospam for that friend was set to the new one). * (the nospam for that friend was set to the new one).
* @retval FAERR_NOMEM if increasing the friend list size fails. * @retval FAERR_NOMEM if increasing the friend list size fails.
*/ */
non_null() int32_t m_addfriend(Messenger *_Nonnull m, const uint8_t *_Nonnull address, const uint8_t *_Nonnull data, uint16_t length);
int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, uint16_t length);
/** @brief Add a friend without sending a friendrequest. /** @brief Add a friend without sending a friendrequest.
* @return the friend number if success. * @return the friend number if success.
@@ -360,27 +357,23 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u
* @retval -6 if bad checksum in address. * @retval -6 if bad checksum in address.
* @retval -8 if increasing the friend list size fails. * @retval -8 if increasing the friend list size fails.
*/ */
non_null() int32_t m_addfriend_norequest(Messenger *_Nonnull m, const uint8_t *_Nonnull real_pk);
int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk);
/** @brief Initializes the friend connection and onion connection for a groupchat. /** @brief Initializes the friend connection and onion connection for a groupchat.
* *
* @retval true on success. * @retval true on success.
*/ */
non_null() bool m_create_group_connection(Messenger *_Nonnull m, GC_Chat *_Nonnull chat);
bool m_create_group_connection(Messenger *m, GC_Chat *chat);
/* /*
* Kills the friend connection for a groupchat. * Kills the friend connection for a groupchat.
*/ */
non_null() void m_kill_group_connection(Messenger *_Nonnull m, const GC_Chat *_Nonnull chat);
void m_kill_group_connection(Messenger *m, const GC_Chat *chat);
/** @return the friend number associated to that public key. /** @return the friend number associated to that public key.
* @retval -1 if no such friend. * @retval -1 if no such friend.
*/ */
non_null() int32_t getfriend_id(const Messenger *_Nonnull m, const uint8_t *_Nonnull real_pk);
int32_t getfriend_id(const Messenger *m, const uint8_t *real_pk);
/** @brief Copies the public key associated to that friend id into real_pk buffer. /** @brief Copies the public key associated to that friend id into real_pk buffer.
* *
@@ -389,22 +382,19 @@ int32_t getfriend_id(const Messenger *m, const uint8_t *real_pk);
* @retval 0 if success. * @retval 0 if success.
* @retval -1 if failure. * @retval -1 if failure.
*/ */
non_null() int get_real_pk(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t *_Nonnull real_pk);
int get_real_pk(const Messenger *m, int32_t friendnumber, uint8_t *real_pk);
/** @return friend connection id on success. /** @return friend connection id on success.
* @retval -1 if failure. * @retval -1 if failure.
*/ */
non_null() int getfriendcon_id(const Messenger *_Nonnull m, int32_t friendnumber);
int getfriendcon_id(const Messenger *m, int32_t friendnumber);
/** @brief Remove a friend. /** @brief Remove a friend.
* *
* @retval 0 if success. * @retval 0 if success.
* @retval -1 if failure. * @retval -1 if failure.
*/ */
non_null() int m_delfriend(Messenger *_Nonnull m, int32_t friendnumber);
int m_delfriend(Messenger *m, int32_t friendnumber);
/** @brief Checks friend's connection status. /** @brief Checks friend's connection status.
* *
@@ -413,8 +403,7 @@ int m_delfriend(Messenger *m, int32_t friendnumber);
* @retval CONNECTION_NONE (0) if friend is not connected to us (Offline). * @retval CONNECTION_NONE (0) if friend is not connected to us (Offline).
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() int m_get_friend_connectionstatus(const Messenger *_Nonnull m, int32_t friendnumber);
int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber);
/** /**
* Checks if there exists a friend with given friendnumber. * Checks if there exists a friend with given friendnumber.
@@ -424,8 +413,7 @@ int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber);
* @retval true if friend exists. * @retval true if friend exists.
* @retval false if friend doesn't exist. * @retval false if friend doesn't exist.
*/ */
non_null() bool m_friend_exists(const Messenger *_Nonnull m, int32_t friendnumber);
bool m_friend_exists(const Messenger *m, int32_t friendnumber);
/** @brief Send a message of type to an online friend. /** @brief Send a message of type to an online friend.
* *
@@ -438,10 +426,8 @@ bool m_friend_exists(const Messenger *m, int32_t friendnumber);
* *
* The value in message_id will be passed to your read_receipt callback when the other receives the message. * The value in message_id will be passed to your read_receipt callback when the other receives the message.
*/ */
non_null(1, 4) nullable(6) int m_send_message_generic(Messenger *_Nonnull m, int32_t friendnumber, uint8_t type, const uint8_t *_Nonnull message, uint32_t length,
int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, const uint8_t *message, uint32_t length, uint32_t *_Nullable message_id);
uint32_t *message_id);
/** @brief Set the name and name_length of a friend. /** @brief Set the name and name_length of a friend.
* *
* name must be a string of maximum MAX_NAME_LENGTH length. * name must be a string of maximum MAX_NAME_LENGTH length.
@@ -451,8 +437,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con
* @retval 0 if success. * @retval 0 if success.
* @retval -1 if failure. * @retval -1 if failure.
*/ */
non_null() int setfriendname(Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull name, uint16_t length);
int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length);
/** @brief Set our nickname. /** @brief Set our nickname.
* *
@@ -463,8 +448,7 @@ int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint1
* @retval 0 if success. * @retval 0 if success.
* @retval -1 if failure. * @retval -1 if failure.
*/ */
non_null() int setname(Messenger *_Nonnull m, const uint8_t *_Nonnull name, uint16_t length);
int setname(Messenger *m, const uint8_t *name, uint16_t length);
/** /**
* @brief Get your nickname. * @brief Get your nickname.
@@ -475,8 +459,7 @@ int setname(Messenger *m, const uint8_t *name, uint16_t length);
* @return length of the name. * @return length of the name.
* @retval 0 on error. * @retval 0 on error.
*/ */
non_null() uint16_t getself_name(const Messenger *_Nonnull m, uint8_t *_Nonnull name);
uint16_t getself_name(const Messenger *m, uint8_t *name);
/** @brief Get name of friendnumber and put it in name. /** @brief Get name of friendnumber and put it in name.
* *
@@ -485,23 +468,22 @@ uint16_t getself_name(const Messenger *m, uint8_t *name);
* @return length of name if success. * @return length of name if success.
* @retval -1 if failure. * @retval -1 if failure.
*/ */
non_null() int getname(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t *_Nonnull name);
int getname(const Messenger *m, int32_t friendnumber, uint8_t *name);
/** @return the length of name, including null on success. /** @return the length of name, including null on success.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() int m_get_name_size(const Messenger *m, int32_t friendnumber); int m_get_name_size(const Messenger *_Nonnull m, int32_t friendnumber);
non_null() int m_get_self_name_size(const Messenger *m); int m_get_self_name_size(const Messenger *_Nonnull m);
/** @brief Set our user status. /** @brief Set our user status.
* You are responsible for freeing status after. * You are responsible for freeing status after.
* *
* @retval 0 on success. * @retval 0 if success.
* @retval -1 on failure. * @retval -1 if failure.
*/ */
non_null() int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length); int m_set_statusmessage(Messenger *_Nonnull m, const uint8_t *_Nonnull status, uint16_t length);
non_null() int m_set_userstatus(Messenger *m, uint8_t status); int m_set_userstatus(Messenger *_Nonnull m, uint8_t status);
/** /**
* Guaranteed to be at most MAX_STATUSMESSAGE_LENGTH. * Guaranteed to be at most MAX_STATUSMESSAGE_LENGTH.
@@ -509,8 +491,8 @@ non_null() int m_set_userstatus(Messenger *m, uint8_t status);
* @return the length of friendnumber's status message, including null on success. * @return the length of friendnumber's status message, including null on success.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber); int m_get_statusmessage_size(const Messenger *_Nonnull m, int32_t friendnumber);
non_null() int m_get_self_statusmessage_size(const Messenger *m); int m_get_self_statusmessage_size(const Messenger *_Nonnull m);
/** @brief Copy friendnumber's status message into buf, truncating if size is over maxlen. /** @brief Copy friendnumber's status message into buf, truncating if size is over maxlen.
* *
@@ -520,8 +502,8 @@ non_null() int m_get_self_statusmessage_size(const Messenger *m);
* @return the length of the copied data on success * @return the length of the copied data on success
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen); int m_copy_statusmessage(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t *_Nonnull buf, uint32_t maxlen);
non_null() int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf); int m_copy_self_statusmessage(const Messenger *_Nonnull m, uint8_t *_Nonnull buf);
/** @brief return one of Userstatus values. /** @brief return one of Userstatus values.
* *
@@ -529,13 +511,13 @@ non_null() int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf);
* As above, the self variant will return our own Userstatus. * As above, the self variant will return our own Userstatus.
* If friendnumber is invalid, this shall return USERSTATUS_INVALID. * If friendnumber is invalid, this shall return USERSTATUS_INVALID.
*/ */
non_null() uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber); uint8_t m_get_userstatus(const Messenger *_Nonnull m, int32_t friendnumber);
non_null() uint8_t m_get_self_userstatus(const Messenger *m); uint8_t m_get_self_userstatus(const Messenger *_Nonnull m);
/** @brief returns timestamp of last time friendnumber was seen online or 0 if never seen. /** @brief returns timestamp of last time friendnumber was seen online or 0 if never seen.
* if friendnumber is invalid this function will return UINT64_MAX. * if friendnumber is invalid this function will return UINT64_MAX.
*/ */
non_null() uint64_t m_get_last_online(const Messenger *m, int32_t friendnumber); uint64_t m_get_last_online(const Messenger *_Nonnull m, int32_t friendnumber);
/** @brief Set our typing status for a friend. /** @brief Set our typing status for a friend.
* You are responsible for turning it on or off. * You are responsible for turning it on or off.
@@ -543,8 +525,7 @@ non_null() uint64_t m_get_last_online(const Messenger *m, int32_t friendnumber);
* @retval 0 on success. * @retval 0 on success.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() int m_set_usertyping(Messenger *_Nonnull m, int32_t friendnumber, bool is_typing);
int m_set_usertyping(Messenger *m, int32_t friendnumber, bool is_typing);
/** @brief Get the typing status of a friend. /** @brief Get the typing status of a friend.
* *
@@ -552,32 +533,29 @@ int m_set_usertyping(Messenger *m, int32_t friendnumber, bool is_typing);
* @retval 0 if friend is not typing. * @retval 0 if friend is not typing.
* @retval 1 if friend is typing. * @retval 1 if friend is typing.
*/ */
non_null() int m_get_istyping(const Messenger *_Nonnull m, int32_t friendnumber);
int m_get_istyping(const Messenger *m, int32_t friendnumber);
/** Set the function that will be executed when a friend request is received. */ /** Set the function that will be executed when a friend request is received. */
non_null(1) nullable(2) void m_callback_friendrequest(Messenger *_Nonnull m, m_friend_request_cb *_Nullable function);
void m_callback_friendrequest(Messenger *m, m_friend_request_cb *function);
/** Set the function that will be executed when a message from a friend is received. */ /** Set the function that will be executed when a message from a friend is received. */
non_null() void m_callback_friendmessage(Messenger *m, m_friend_message_cb *function); void m_callback_friendmessage(Messenger *_Nonnull m, m_friend_message_cb *_Nonnull function);
/** @brief Set the callback for name changes. /** @brief Set the callback for name changes.
* You are not responsible for freeing newname. * You are not responsible for freeing newname.
*/ */
non_null() void m_callback_namechange(Messenger *m, m_friend_name_cb *function); void m_callback_namechange(Messenger *_Nonnull m, m_friend_name_cb *_Nonnull function);
/** @brief Set the callback for status message changes. /** @brief Set the callback for status message changes.
* *
* You are not responsible for freeing newstatus * You are not responsible for freeing newstatus
*/ */
non_null() void m_callback_statusmessage(Messenger *m, m_friend_status_message_cb *function); void m_callback_statusmessage(Messenger *_Nonnull m, m_friend_status_message_cb *_Nonnull function);
/** @brief Set the callback for status type changes. */ /** @brief Set the callback for status type changes. */
non_null() void m_callback_userstatus(Messenger *m, m_friend_status_cb *function); void m_callback_userstatus(Messenger *_Nonnull m, m_friend_status_cb *_Nonnull function);
/** @brief Set the callback for typing changes. */ /** @brief Set the callback for typing changes. */
non_null() void m_callback_typingchange(Messenger *m, m_friend_typing_cb *function); void m_callback_typingchange(Messenger *_Nonnull m, m_friend_typing_cb *_Nonnull function);
/** @brief Set the callback for read receipts. /** @brief Set the callback for read receipts.
* *
@@ -587,7 +565,7 @@ non_null() void m_callback_typingchange(Messenger *m, m_friend_typing_cb *functi
* Since core doesn't track ids for you, receipt may not correspond to any message. * Since core doesn't track ids for you, receipt may not correspond to any message.
* In that case, you should discard it. * In that case, you should discard it.
*/ */
non_null() void m_callback_read_receipt(Messenger *m, m_friend_read_receipt_cb *function); void m_callback_read_receipt(Messenger *_Nonnull m, m_friend_read_receipt_cb *_Nonnull function);
/** @brief Set the callback for connection status changes. /** @brief Set the callback for connection status changes.
* *
@@ -599,29 +577,24 @@ non_null() void m_callback_read_receipt(Messenger *m, m_friend_read_receipt_cb *
* "after being previously online" part. * "after being previously online" part.
* It's assumed that when adding friends, their connection status is offline. * It's assumed that when adding friends, their connection status is offline.
*/ */
non_null() void m_callback_connectionstatus(Messenger *m, m_friend_connection_status_cb *function); void m_callback_connectionstatus(Messenger *_Nonnull m, m_friend_connection_status_cb *_Nonnull function);
/** @brief Set the callback for typing changes. */ /** @brief Set the callback for typing changes. */
non_null() void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *function); void m_callback_core_connection(Messenger *_Nonnull m, m_self_connection_status_cb *_Nonnull function);
/*** CONFERENCES */ /*** CONFERENCES */
/** @brief Set the callback for conference invites. */ /** @brief Set the callback for conference invites. */
non_null(1) nullable(2) void m_callback_conference_invite(Messenger *_Nonnull m, m_conference_invite_cb *_Nullable function);
void m_callback_conference_invite(Messenger *m, m_conference_invite_cb *function);
/* Set the callback for group invites. /* Set the callback for group invites.
*/ */
non_null(1) nullable(2) void m_callback_group_invite(Messenger *_Nonnull m, m_group_invite_cb *_Nullable function);
void m_callback_group_invite(Messenger *m, m_group_invite_cb *function);
/** @brief Send a conference invite packet. /** @brief Send a conference invite packet.
* *
* return true on success * return true on success
* return false on failure * return false on failure
*/ */
non_null() bool send_conference_invite_packet(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull data, uint16_t length);
bool send_conference_invite_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length);
/* Send a group invite packet. /* Send a group invite packet.
* *
@@ -630,22 +603,21 @@ bool send_conference_invite_packet(const Messenger *m, int32_t friendnumber, con
* *
* return true on success * return true on success
*/ */
non_null() bool send_group_invite_packet(const Messenger *_Nonnull m, uint32_t friendnumber, const uint8_t *_Nonnull packet, uint16_t length);
bool send_group_invite_packet(const Messenger *m, uint32_t friendnumber, const uint8_t *packet, uint16_t length);
/*** FILE SENDING */ /*** FILE SENDING */
/** @brief Set the callback for file send requests. */ /** @brief Set the callback for file send requests. */
non_null() void callback_file_sendrequest(Messenger *m, m_file_recv_cb *function); void callback_file_sendrequest(Messenger *_Nonnull m, m_file_recv_cb *_Nonnull function);
/** @brief Set the callback for file control requests. */ /** @brief Set the callback for file control requests. */
non_null() void callback_file_control(Messenger *m, m_file_recv_control_cb *function); void callback_file_control(Messenger *_Nonnull m, m_file_recv_control_cb *_Nonnull function);
/** @brief Set the callback for file data. */ /** @brief Set the callback for file data. */
non_null() void callback_file_data(Messenger *m, m_file_recv_chunk_cb *function); void callback_file_data(Messenger *_Nonnull m, m_file_recv_chunk_cb *_Nonnull function);
/** @brief Set the callback for file request chunk. */ /** @brief Set the callback for file request chunk. */
non_null() void callback_file_reqchunk(Messenger *m, m_file_chunk_request_cb *function); void callback_file_reqchunk(Messenger *_Nonnull m, m_file_chunk_request_cb *_Nonnull function);
/** @brief Copy the file transfer file id to file_id /** @brief Copy the file transfer file id to file_id
* *
@@ -653,8 +625,7 @@ non_null() void callback_file_reqchunk(Messenger *m, m_file_chunk_request_cb *fu
* @retval -1 if friend not valid. * @retval -1 if friend not valid.
* @retval -2 if filenumber not valid * @retval -2 if filenumber not valid
*/ */
non_null() int file_get_id(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t filenumber, uint8_t *_Nonnull file_id);
int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint8_t *file_id);
/** @brief Send a file send request. /** @brief Send a file send request.
* *
@@ -666,9 +637,8 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u
* @retval -3 if no more file sending slots left. * @retval -3 if no more file sending slots left.
* @retval -4 if could not send packet (friend offline). * @retval -4 if could not send packet (friend offline).
*/ */
non_null() long int new_filesender(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t file_type, uint64_t filesize, const uint8_t *_Nonnull file_id, const uint8_t *_Nonnull filename,
long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize, uint16_t filename_length);
const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length);
/** @brief Send a file control request. /** @brief Send a file control request.
* *
@@ -682,8 +652,7 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_
* @retval -7 if resume file failed because it wasn't paused. * @retval -7 if resume file failed because it wasn't paused.
* @retval -8 if packet failed to send. * @retval -8 if packet failed to send.
*/ */
non_null() int file_control(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t filenumber, unsigned int control);
int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber, unsigned int control);
/** @brief Send a seek file control request. /** @brief Send a seek file control request.
* *
@@ -696,8 +665,7 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber,
* @retval -6 if position bad. * @retval -6 if position bad.
* @retval -8 if packet failed to send. * @retval -8 if packet failed to send.
*/ */
non_null() int file_seek(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t filenumber, uint64_t position);
int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position);
/** @brief Send file data. /** @brief Send file data.
* *
@@ -710,14 +678,12 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
* @retval -6 if packet queue full. * @retval -6 if packet queue full.
* @retval -7 if wrong position. * @retval -7 if wrong position.
*/ */
non_null(1) nullable(5) int send_file_data(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t filenumber, uint64_t position,
int send_file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *_Nullable data, uint16_t length);
const uint8_t *data, uint16_t length);
/*** CUSTOM PACKETS */ /*** CUSTOM PACKETS */
/** @brief Set handlers for custom lossy packets. */ /** @brief Set handlers for custom lossy packets. */
non_null() void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy_packet_cb *lossy_packethandler); void custom_lossy_packet_registerhandler(Messenger *_Nonnull m, m_friend_lossy_packet_cb *_Nonnull lossy_packethandler);
/** @brief High level function to send custom lossy packets. /** @brief High level function to send custom lossy packets.
* *
@@ -728,12 +694,10 @@ non_null() void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy
* @retval -5 if packet failed to send because of other error. * @retval -5 if packet failed to send because of other error.
* @retval 0 on success. * @retval 0 on success.
*/ */
non_null() int m_send_custom_lossy_packet(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull data, uint32_t length);
int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
/** @brief Set handlers for custom lossless packets. */ /** @brief Set handlers for custom lossless packets. */
non_null() void custom_lossless_packet_registerhandler(Messenger *_Nonnull m, m_friend_lossless_packet_cb *_Nonnull lossless_packethandler);
void custom_lossless_packet_registerhandler(Messenger *m, m_friend_lossless_packet_cb *lossless_packethandler);
/** @brief High level function to send custom lossless packets. /** @brief High level function to send custom lossless packets.
* *
@@ -744,8 +708,7 @@ void custom_lossless_packet_registerhandler(Messenger *m, m_friend_lossless_pack
* @retval -5 if packet failed to send because of other error. * @retval -5 if packet failed to send because of other error.
* @retval 0 on success. * @retval 0 on success.
*/ */
non_null() int send_custom_lossless_packet(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull data, uint32_t length);
int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
/*** Messenger constructor/destructor/operations. */ /*** Messenger constructor/destructor/operations. */
@@ -763,29 +726,23 @@ typedef enum Messenger_Error {
* *
* if error is not NULL it will be set to one of the values in the enum above. * if error is not NULL it will be set to one of the values in the enum above.
*/ */
non_null() Messenger *_Nullable new_messenger(Mono_Time *_Nonnull mono_time, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Network *_Nonnull ns, Messenger_Options *_Nonnull options,
Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *rng, const Network *ns, Messenger_Error *_Nonnull error);
Messenger_Options *options, Messenger_Error *error);
/** @brief Run this before closing shop. /** @brief Run this before closing shop.
* *
* Free all datastructures. * Free all datastructures.
*/ */
nullable(1) void kill_messenger(Messenger *_Nullable m);
void kill_messenger(Messenger *m);
/** @brief The main loop that needs to be run at least 20 times per second. */ /** @brief The main loop that needs to be run at least 20 times per second. */
non_null(1) nullable(2) void do_messenger(Messenger *_Nonnull m, void *_Nullable userdata);
void do_messenger(Messenger *m, void *userdata);
/** /**
* @brief Return the time in milliseconds before `do_messenger()` should be called again * @brief Return the time in milliseconds before `do_messenger()` should be called again
* for optimal performance. * for optimal performance.
* *
* @return time (in ms) before the next `do_messenger()` needs to be run on success. * @return time (in ms) before the next `do_messenger()` needs to be run on success.
*/ */
non_null() uint32_t messenger_run_interval(const Messenger *_Nonnull m);
uint32_t messenger_run_interval(const Messenger *m);
/* SAVING AND LOADING FUNCTIONS: */ /* SAVING AND LOADING FUNCTIONS: */
@@ -794,19 +751,13 @@ uint32_t messenger_run_interval(const Messenger *m);
* @retval true on success * @retval true on success
* @retval false on error * @retval false on error
*/ */
non_null() bool m_register_state_plugin(Messenger *_Nonnull m, State_Type type, m_state_size_cb *_Nonnull size_callback, m_state_load_cb *_Nonnull load_callback, m_state_save_cb *_Nonnull save_callback);
bool m_register_state_plugin(Messenger *m, State_Type type,
m_state_size_cb *size_callback,
m_state_load_cb *load_callback,
m_state_save_cb *save_callback);
/** return size of the messenger data (for saving). */ /** return size of the messenger data (for saving). */
non_null() uint32_t messenger_size(const Messenger *_Nonnull m);
uint32_t messenger_size(const Messenger *m);
/** Save the messenger in data (must be allocated memory of size at least `Messenger_size()`) */ /** Save the messenger in data (must be allocated memory of size at least `Messenger_size()`) */
non_null() uint8_t *_Nonnull messenger_save(const Messenger *_Nonnull m, uint8_t *_Nonnull data);
uint8_t *messenger_save(const Messenger *m, uint8_t *data);
/** @brief Load a state section. /** @brief Load a state section.
* *
@@ -816,17 +767,14 @@ uint8_t *messenger_save(const Messenger *m, uint8_t *data);
* @param status Result of loading section is stored here if the section is handled. * @param status Result of loading section is stored here if the section is handled.
* @return true iff section handled. * @return true iff section handled.
*/ */
non_null() bool messenger_load_state_section(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length, uint16_t type, State_Load_Status *_Nonnull status);
bool messenger_load_state_section(Messenger *m, const uint8_t *data, uint32_t length, uint16_t type,
State_Load_Status *status);
/** @brief Return the number of friends in the instance m. /** @brief Return the number of friends in the instance m.
* *
* You should use this to determine how much memory to allocate * You should use this to determine how much memory to allocate
* for copy_friendlist. * for copy_friendlist.
*/ */
non_null() uint32_t count_friendlist(const Messenger *_Nonnull m);
uint32_t count_friendlist(const Messenger *m);
/** @brief Copy a list of valid friend IDs into the array out_list. /** @brief Copy a list of valid friend IDs into the array out_list.
* If out_list is NULL, returns 0. * If out_list is NULL, returns 0.
@@ -834,10 +782,8 @@ uint32_t count_friendlist(const Messenger *m);
* If the array was too small, the contents * If the array was too small, the contents
* of out_list will be truncated to list_size. * of out_list will be truncated to list_size.
*/ */
non_null() uint32_t copy_friendlist(const Messenger *_Nonnull m, uint32_t *_Nonnull out_list, uint32_t list_size);
uint32_t copy_friendlist(const Messenger *m, uint32_t *out_list, uint32_t list_size);
non_null() bool m_is_receiving_file(Messenger *_Nonnull m);
bool m_is_receiving_file(Messenger *m);
#endif /* C_TOXCORE_TOXCORE_MESSENGER_H */ #endif /* C_TOXCORE_TOXCORE_MESSENGER_H */

View File

@@ -107,8 +107,8 @@ void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value)
* @retval true on success * @retval true on success
* @retval false on failure * @retval false on failure
*/ */
non_null() static bool connect_sock_to(const Network *_Nonnull ns, const Logger *_Nonnull logger, const Memory *_Nonnull mem, Socket sock, const IP_Port *_Nonnull ip_port,
static bool connect_sock_to(const Network *ns, const Logger *logger, const Memory *mem, Socket sock, const IP_Port *ip_port, const TCP_Proxy_Info *proxy_info) const TCP_Proxy_Info *_Nonnull proxy_info)
{ {
Net_Err_Connect err; Net_Err_Connect err;
if (proxy_info->proxy_type != TCP_PROXY_NONE) { if (proxy_info->proxy_type != TCP_PROXY_NONE) {
@@ -133,8 +133,7 @@ static bool connect_sock_to(const Network *ns, const Logger *logger, const Memor
* @retval 1 on success. * @retval 1 on success.
* @retval 0 on failure. * @retval 0 on failure.
*/ */
non_null() static int proxy_http_generate_connection_request(TCP_Client_Connection *_Nonnull tcp_conn)
static int proxy_http_generate_connection_request(TCP_Client_Connection *tcp_conn)
{ {
const char one[] = "CONNECT "; const char one[] = "CONNECT ";
const char two[] = " HTTP/1.1\nHost: "; const char two[] = " HTTP/1.1\nHost: ";
@@ -164,8 +163,7 @@ static int proxy_http_generate_connection_request(TCP_Client_Connection *tcp_con
* @retval 0 if no data received. * @retval 0 if no data received.
* @retval -1 on failure (connection refused). * @retval -1 on failure (connection refused).
*/ */
non_null() static int proxy_http_read_connection_response(const Logger *_Nonnull logger, const TCP_Client_Connection *_Nonnull tcp_conn)
static int proxy_http_read_connection_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
{ {
const char success[] = "200"; const char success[] = "200";
uint8_t data[16]; // draining works the best if the length is a power of 2 uint8_t data[16]; // draining works the best if the length is a power of 2
@@ -214,8 +212,7 @@ enum Tcp_Socks5_Proxy_Hs {
TCP_SOCKS5_PROXY_HS_ADDR_TYPE_IPV6 = 0x04, TCP_SOCKS5_PROXY_HS_ADDR_TYPE_IPV6 = 0x04,
}; };
non_null() static void proxy_socks5_generate_greetings(TCP_Client_Connection *_Nonnull tcp_conn)
static void proxy_socks5_generate_greetings(TCP_Client_Connection *tcp_conn)
{ {
tcp_conn->con.last_packet[0] = TCP_SOCKS5_PROXY_HS_VERSION_SOCKS5; tcp_conn->con.last_packet[0] = TCP_SOCKS5_PROXY_HS_VERSION_SOCKS5;
tcp_conn->con.last_packet[1] = TCP_SOCKS5_PROXY_HS_AUTH_METHODS_SUPPORTED; tcp_conn->con.last_packet[1] = TCP_SOCKS5_PROXY_HS_AUTH_METHODS_SUPPORTED;
@@ -230,8 +227,7 @@ static void proxy_socks5_generate_greetings(TCP_Client_Connection *tcp_conn)
* @retval 0 if no data received. * @retval 0 if no data received.
* @retval -1 on failure (connection refused). * @retval -1 on failure (connection refused).
*/ */
non_null() static int socks5_read_handshake_response(const Logger *_Nonnull logger, const TCP_Client_Connection *_Nonnull tcp_conn)
static int socks5_read_handshake_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
{ {
uint8_t data[2]; uint8_t data[2];
const TCP_Connection *con = &tcp_conn->con; const TCP_Connection *con = &tcp_conn->con;
@@ -248,8 +244,7 @@ static int socks5_read_handshake_response(const Logger *logger, const TCP_Client
return -1; return -1;
} }
non_null() static void proxy_socks5_generate_connection_request(TCP_Client_Connection *_Nonnull tcp_conn)
static void proxy_socks5_generate_connection_request(TCP_Client_Connection *tcp_conn)
{ {
tcp_conn->con.last_packet[0] = TCP_SOCKS5_PROXY_HS_VERSION_SOCKS5; tcp_conn->con.last_packet[0] = TCP_SOCKS5_PROXY_HS_VERSION_SOCKS5;
tcp_conn->con.last_packet[1] = TCP_SOCKS5_PROXY_HS_COMM_ESTABLISH_REQUEST; tcp_conn->con.last_packet[1] = TCP_SOCKS5_PROXY_HS_COMM_ESTABLISH_REQUEST;
@@ -280,8 +275,7 @@ static void proxy_socks5_generate_connection_request(TCP_Client_Connection *tcp_
* @retval 0 if no data received. * @retval 0 if no data received.
* @retval -1 on failure (connection refused). * @retval -1 on failure (connection refused).
*/ */
non_null() static int proxy_socks5_read_connection_response(const Logger *_Nonnull logger, const TCP_Client_Connection *_Nonnull tcp_conn)
static int proxy_socks5_read_connection_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
{ {
if (net_family_is_ipv4(tcp_conn->ip_port.ip.family)) { if (net_family_is_ipv4(tcp_conn->ip_port.ip.family)) {
uint8_t data[4 + sizeof(IP4) + sizeof(uint16_t)]; uint8_t data[4 + sizeof(IP4) + sizeof(uint16_t)];
@@ -316,8 +310,7 @@ static int proxy_socks5_read_connection_response(const Logger *logger, const TCP
* @retval 0 on success. * @retval 0 on success.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() static int generate_handshake(TCP_Client_Connection *_Nonnull tcp_conn)
static int generate_handshake(TCP_Client_Connection *tcp_conn)
{ {
uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE]; uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE];
crypto_new_keypair(tcp_conn->con.rng, plain, tcp_conn->temp_secret_key); crypto_new_keypair(tcp_conn->con.rng, plain, tcp_conn->temp_secret_key);
@@ -343,8 +336,7 @@ static int generate_handshake(TCP_Client_Connection *tcp_conn)
* @retval 0 on success. * @retval 0 on success.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() static int handle_handshake(TCP_Client_Connection *_Nonnull tcp_conn, const uint8_t *_Nonnull data)
static int handle_handshake(TCP_Client_Connection *tcp_conn, const uint8_t *data)
{ {
uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE]; uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE];
const int len = decrypt_data_symmetric(tcp_conn->con.mem, tcp_conn->con.shared_key, data, data + CRYPTO_NONCE_SIZE, const int len = decrypt_data_symmetric(tcp_conn->con.mem, tcp_conn->con.shared_key, data, data + CRYPTO_NONCE_SIZE,
@@ -385,8 +377,8 @@ void routing_status_handler(TCP_Client_Connection *con, tcp_routing_status_cb *s
con->status_callback_object = object; con->status_callback_object = object;
} }
non_null() static int tcp_send_ping_response(const Logger *logger, TCP_Client_Connection *con); static int tcp_send_ping_response(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con);
non_null() static int tcp_send_ping_request(const Logger *logger, TCP_Client_Connection *con); static int tcp_send_ping_request(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con);
/** /**
* @retval 1 on success. * @retval 1 on success.
@@ -472,8 +464,7 @@ void oob_data_handler(TCP_Client_Connection *con, tcp_oob_data_cb *oob_data_call
* @retval 0 if could not send packet. * @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed). * @retval -1 on failure (connection must be killed).
*/ */
non_null() static int client_send_disconnect_notification(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, uint8_t id)
static int client_send_disconnect_notification(const Logger *logger, TCP_Client_Connection *con, uint8_t id)
{ {
uint8_t packet[1 + 1]; uint8_t packet[1 + 1];
packet[0] = TCP_PACKET_DISCONNECT_NOTIFICATION; packet[0] = TCP_PACKET_DISCONNECT_NOTIFICATION;
@@ -486,7 +477,7 @@ static int client_send_disconnect_notification(const Logger *logger, TCP_Client_
* @retval 0 if could not send packet. * @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed). * @retval -1 on failure (connection must be killed).
*/ */
static int tcp_send_ping_request(const Logger *logger, TCP_Client_Connection *con) static int tcp_send_ping_request(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con)
{ {
if (con->ping_request_id == 0) { if (con->ping_request_id == 0) {
return 1; return 1;
@@ -509,7 +500,7 @@ static int tcp_send_ping_request(const Logger *logger, TCP_Client_Connection *co
* @retval 0 if could not send packet. * @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed). * @retval -1 on failure (connection must be killed).
*/ */
static int tcp_send_ping_response(const Logger *logger, TCP_Client_Connection *con) static int tcp_send_ping_response(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con)
{ {
if (con->ping_response_id == 0) { if (con->ping_response_id == 0) {
return 1; return 1;
@@ -595,7 +586,7 @@ void forwarding_handler(TCP_Client_Connection *con, forwarded_response_cb *forwa
TCP_Client_Connection *new_tcp_connection( TCP_Client_Connection *new_tcp_connection(
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns, const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns,
const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key, const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key,
const TCP_Proxy_Info *proxy_info, Net_Profile *net_profile) const TCP_Proxy_Info *proxy_info, Net_Profile *_Nullable net_profile)
{ {
assert(logger != nullptr); assert(logger != nullptr);
assert(mem != nullptr); assert(mem != nullptr);
@@ -699,8 +690,7 @@ TCP_Client_Connection *new_tcp_connection(
return temp; return temp;
} }
non_null() static int handle_tcp_client_routing_response(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
static int handle_tcp_client_routing_response(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
{ {
if (length != 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE) { if (length != 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE) {
return -1; return -1;
@@ -727,8 +717,7 @@ static int handle_tcp_client_routing_response(TCP_Client_Connection *conn, const
return 0; return 0;
} }
non_null() static int handle_tcp_client_connection_notification(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
static int handle_tcp_client_connection_notification(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
{ {
if (length != 1 + 1) { if (length != 1 + 1) {
return -1; return -1;
@@ -754,8 +743,7 @@ static int handle_tcp_client_connection_notification(TCP_Client_Connection *conn
return 0; return 0;
} }
non_null() static int handle_tcp_client_disconnect_notification(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
static int handle_tcp_client_disconnect_notification(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
{ {
if (length != 1 + 1) { if (length != 1 + 1) {
return -1; return -1;
@@ -785,8 +773,7 @@ static int handle_tcp_client_disconnect_notification(TCP_Client_Connection *conn
return 0; return 0;
} }
non_null() static int handle_tcp_client_ping(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
static int handle_tcp_client_ping(const Logger *logger, TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
{ {
if (length != 1 + sizeof(uint64_t)) { if (length != 1 + sizeof(uint64_t)) {
return -1; return -1;
@@ -799,8 +786,7 @@ static int handle_tcp_client_ping(const Logger *logger, TCP_Client_Connection *c
return 0; return 0;
} }
non_null() static int handle_tcp_client_pong(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
static int handle_tcp_client_pong(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
{ {
if (length != 1 + sizeof(uint64_t)) { if (length != 1 + sizeof(uint64_t)) {
return -1; return -1;
@@ -820,8 +806,7 @@ static int handle_tcp_client_pong(TCP_Client_Connection *conn, const uint8_t *da
return -1; return -1;
} }
non_null(1, 2) nullable(4) static int handle_tcp_client_oob_recv(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata)
static int handle_tcp_client_oob_recv(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length, void *userdata)
{ {
if (length <= 1 + CRYPTO_PUBLIC_KEY_SIZE) { if (length <= 1 + CRYPTO_PUBLIC_KEY_SIZE) {
return -1; return -1;
@@ -839,9 +824,8 @@ static int handle_tcp_client_oob_recv(TCP_Client_Connection *conn, const uint8_t
* @retval 0 on success * @retval 0 on success
* @retval -1 on failure * @retval -1 on failure
*/ */
non_null(1, 2, 3) nullable(5) static int handle_tcp_client_packet(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data,
static int handle_tcp_client_packet(const Logger *logger, TCP_Client_Connection *conn, const uint8_t *data, uint16_t length, void *_Nullable userdata)
uint16_t length, void *userdata)
{ {
if (length <= 1) { if (length <= 1) {
return -1; return -1;
@@ -899,8 +883,7 @@ static int handle_tcp_client_packet(const Logger *logger, TCP_Client_Connection
return 0; return 0;
} }
non_null(1, 2) nullable(3) static bool tcp_process_packet(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull conn, void *_Nullable userdata)
static bool tcp_process_packet(const Logger *logger, TCP_Client_Connection *conn, void *userdata)
{ {
uint8_t packet[MAX_PACKET_SIZE]; uint8_t packet[MAX_PACKET_SIZE];
const int len = read_packet_tcp_secure_connection(logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, sizeof(packet), const int len = read_packet_tcp_secure_connection(logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, sizeof(packet),
@@ -923,9 +906,8 @@ static bool tcp_process_packet(const Logger *logger, TCP_Client_Connection *conn
return true; return true;
} }
non_null(1, 2, 3) nullable(4) static int do_confirmed_tcp(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull conn, const Mono_Time *_Nonnull mono_time,
static int do_confirmed_tcp(const Logger *logger, TCP_Client_Connection *conn, const Mono_Time *mono_time, void *_Nullable userdata)
void *userdata)
{ {
send_pending_data(logger, &conn->con); send_pending_data(logger, &conn->con);
tcp_send_ping_response(logger, conn); tcp_send_ping_response(logger, conn);

View File

@@ -44,78 +44,56 @@ typedef enum TCP_Client_Status {
typedef struct TCP_Client_Connection TCP_Client_Connection; typedef struct TCP_Client_Connection TCP_Client_Connection;
non_null() const uint8_t *_Nonnull tcp_con_public_key(const TCP_Client_Connection *_Nonnull con);
const uint8_t *tcp_con_public_key(const TCP_Client_Connection *con); IP_Port tcp_con_ip_port(const TCP_Client_Connection *_Nonnull con);
non_null() TCP_Client_Status tcp_con_status(const TCP_Client_Connection *_Nonnull con);
IP_Port tcp_con_ip_port(const TCP_Client_Connection *con);
non_null()
TCP_Client_Status tcp_con_status(const TCP_Client_Connection *con);
non_null() void *_Nullable tcp_con_custom_object(const TCP_Client_Connection *_Nonnull con);
void *tcp_con_custom_object(const TCP_Client_Connection *con); uint32_t tcp_con_custom_uint(const TCP_Client_Connection *_Nonnull con);
non_null() void tcp_con_set_custom_object(TCP_Client_Connection *_Nonnull con, void *_Nonnull object);
uint32_t tcp_con_custom_uint(const TCP_Client_Connection *con); void tcp_con_set_custom_uint(TCP_Client_Connection *_Nonnull con, uint32_t value);
non_null()
void tcp_con_set_custom_object(TCP_Client_Connection *con, void *object);
non_null()
void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value);
/** Create new TCP connection to ip_port/public_key */ /** Create new TCP connection to ip_port/public_key */
non_null(1, 2, 3, 4, 5, 6, 7, 8, 9) nullable(10, 11) TCP_Client_Connection *_Nullable new_tcp_connection(
TCP_Client_Connection *new_tcp_connection( const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Mono_Time *_Nonnull mono_time, const Random *_Nonnull rng, const Network *_Nonnull ns,
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull self_public_key, const uint8_t *_Nonnull self_secret_key,
const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key, const TCP_Proxy_Info *_Nullable proxy_info, Net_Profile *_Nullable net_profile);
const TCP_Proxy_Info *proxy_info, Net_Profile *net_profile);
/** Run the TCP connection */ /** Run the TCP connection */
non_null(1, 2, 3) nullable(4) void do_tcp_connection(const Logger *_Nonnull logger, const Mono_Time *_Nonnull mono_time,
void do_tcp_connection(const Logger *logger, const Mono_Time *mono_time, TCP_Client_Connection *_Nonnull tcp_connection, void *_Nullable userdata);
TCP_Client_Connection *tcp_connection, void *userdata);
/** Kill the TCP connection */ /** Kill the TCP connection */
nullable(1) void kill_tcp_connection(TCP_Client_Connection *_Nullable tcp_connection);
void kill_tcp_connection(TCP_Client_Connection *tcp_connection); typedef int tcp_onion_response_cb(void *_Nonnull object, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
typedef int tcp_onion_response_cb(void *object, const uint8_t *data, uint16_t length, void *userdata);
/** /**
* @retval 1 on success. * @retval 1 on success.
* @retval 0 if could not send packet. * @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed). * @retval -1 on failure (connection must be killed).
*/ */
non_null() int send_onion_request(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, const uint8_t *_Nonnull data, uint16_t length);
int send_onion_request(const Logger *logger, TCP_Client_Connection *con, const uint8_t *data, uint16_t length); void onion_response_handler(TCP_Client_Connection *_Nonnull con, tcp_onion_response_cb *_Nonnull onion_callback, void *_Nonnull object);
non_null()
void onion_response_handler(TCP_Client_Connection *con, tcp_onion_response_cb *onion_callback, void *object);
non_null() int send_forward_request_tcp(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, const IP_Port *_Nonnull dest, const uint8_t *_Nonnull data, uint16_t length);
int send_forward_request_tcp(const Logger *logger, TCP_Client_Connection *con, const IP_Port *dest, const uint8_t *data, void forwarding_handler(TCP_Client_Connection *_Nonnull con, forwarded_response_cb *_Nonnull forwarded_response_callback, void *_Nonnull object);
uint16_t length);
non_null()
void forwarding_handler(TCP_Client_Connection *con, forwarded_response_cb *forwarded_response_callback, void *object);
typedef int tcp_routing_response_cb(void *object, uint8_t connection_id, const uint8_t *public_key); typedef int tcp_routing_response_cb(void *_Nonnull object, uint8_t connection_id, const uint8_t *_Nonnull public_key);
typedef int tcp_routing_status_cb(void *object, uint32_t number, uint8_t connection_id, uint8_t status); typedef int tcp_routing_status_cb(void *_Nonnull object, uint32_t number, uint8_t connection_id, uint8_t status);
/** /**
* @retval 1 on success. * @retval 1 on success.
* @retval 0 if could not send packet. * @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed). * @retval -1 on failure (connection must be killed).
*/ */
non_null() int send_routing_request(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, const uint8_t *_Nonnull public_key);
int send_routing_request(const Logger *logger, TCP_Client_Connection *con, const uint8_t *public_key); void routing_response_handler(TCP_Client_Connection *_Nonnull con, tcp_routing_response_cb *_Nonnull response_callback, void *_Nonnull object);
non_null() void routing_status_handler(TCP_Client_Connection *_Nonnull con, tcp_routing_status_cb *_Nonnull status_callback, void *_Nonnull object);
void routing_response_handler(TCP_Client_Connection *con, tcp_routing_response_cb *response_callback, void *object);
non_null()
void routing_status_handler(TCP_Client_Connection *con, tcp_routing_status_cb *status_callback, void *object);
/** /**
* @retval 1 on success. * @retval 1 on success.
* @retval 0 if could not send packet. * @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed). * @retval -1 on failure (connection must be killed).
*/ */
non_null() int send_disconnect_request(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, uint8_t con_id);
int send_disconnect_request(const Logger *logger, TCP_Client_Connection *con, uint8_t con_id);
/** @brief Set the number that will be used as an argument in the callbacks related to con_id. /** @brief Set the number that will be used as an argument in the callbacks related to con_id.
* *
@@ -124,34 +102,28 @@ int send_disconnect_request(const Logger *logger, TCP_Client_Connection *con, ui
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() int set_tcp_connection_number(TCP_Client_Connection *_Nonnull con, uint8_t con_id, uint32_t number);
int set_tcp_connection_number(TCP_Client_Connection *con, uint8_t con_id, uint32_t number);
typedef int tcp_routing_data_cb(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, typedef int tcp_routing_data_cb(void *_Nonnull object, uint32_t number, uint8_t connection_id, const uint8_t *_Nonnull data,
uint16_t length, void *userdata); uint16_t length, void *_Nullable userdata);
/** /**
* @retval 1 on success. * @retval 1 on success.
* @retval 0 if could not send packet. * @retval 0 if could not send packet.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() int send_data(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, uint8_t con_id, const uint8_t *_Nonnull data, uint16_t length);
int send_data(const Logger *logger, TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, uint16_t length); void routing_data_handler(TCP_Client_Connection *_Nonnull con, tcp_routing_data_cb *_Nonnull data_callback, void *_Nonnull object);
non_null()
void routing_data_handler(TCP_Client_Connection *con, tcp_routing_data_cb *data_callback, void *object);
typedef int tcp_oob_data_cb(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length, typedef int tcp_oob_data_cb(void *_Nonnull object, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull data, uint16_t length,
void *userdata); void *_Nullable userdata);
/** /**
* @retval 1 on success. * @retval 1 on success.
* @retval 0 if could not send packet. * @retval 0 if could not send packet.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() int send_oob_packet(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull data, uint16_t length);
int send_oob_packet(const Logger *logger, TCP_Client_Connection *con, const uint8_t *public_key, const uint8_t *data, void oob_data_handler(TCP_Client_Connection *_Nonnull con, tcp_oob_data_cb *_Nonnull oob_data_callback, void *_Nonnull object);
uint16_t length);
non_null()
void oob_data_handler(TCP_Client_Connection *con, tcp_oob_data_cb *oob_data_callback, void *object);
#endif /* C_TOXCORE_TOXCORE_TCP_CLIENT_H */ #endif /* C_TOXCORE_TOXCORE_TCP_CLIENT_H */

View File

@@ -97,8 +97,7 @@ int send_pending_data(const Logger *logger, TCP_Connection *con)
* @retval false on failure (only if mem_alloc fails) * @retval false on failure (only if mem_alloc fails)
* @retval true on success * @retval true on success
*/ */
non_null() static bool add_priority(TCP_Connection *_Nonnull con, const uint8_t *_Nonnull packet, uint16_t size, uint16_t sent)
static bool add_priority(TCP_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent)
{ {
TCP_Priority_List *p = con->priority_queue_end; TCP_Priority_List *p = con->priority_queue_end;
TCP_Priority_List *new_list = (TCP_Priority_List *)mem_alloc(con->mem, sizeof(TCP_Priority_List)); TCP_Priority_List *new_list = (TCP_Priority_List *)mem_alloc(con->mem, sizeof(TCP_Priority_List));
@@ -235,8 +234,7 @@ int read_tcp_packet(
* return 0 if nothing has been read from socket. * return 0 if nothing has been read from socket.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() static uint16_t read_tcp_length(const Logger *_Nonnull logger, const Network *_Nonnull ns, Socket sock, const IP_Port *_Nonnull ip_port)
static uint16_t read_tcp_length(const Logger *logger, const Network *ns, Socket sock, const IP_Port *ip_port)
{ {
const uint16_t count = net_socket_data_recv_buffer(ns, sock); const uint16_t count = net_socket_data_recv_buffer(ns, sock);

View File

@@ -15,15 +15,13 @@
typedef struct TCP_Priority_List TCP_Priority_List; typedef struct TCP_Priority_List TCP_Priority_List;
struct TCP_Priority_List { struct TCP_Priority_List {
TCP_Priority_List *next; TCP_Priority_List *_Nullable next;
uint16_t size; uint16_t size;
uint16_t sent; uint16_t sent;
uint8_t *data; uint8_t *_Nonnull data;
}; };
non_null(1) nullable(2) void wipe_priority_list(const Memory *_Nonnull mem, TCP_Priority_List *_Nullable p);
void wipe_priority_list(const Memory *mem, TCP_Priority_List *p);
#define NUM_RESERVED_PORTS 16 #define NUM_RESERVED_PORTS 16
#define NUM_CLIENT_CONNECTIONS (256 - NUM_RESERVED_PORTS) #define NUM_CLIENT_CONNECTIONS (256 - NUM_RESERVED_PORTS)
@@ -54,9 +52,9 @@ typedef enum Tcp_Packet {
#define MAX_PACKET_SIZE 2048 #define MAX_PACKET_SIZE 2048
typedef struct TCP_Connection { typedef struct TCP_Connection {
const Memory *mem; const Memory *_Nonnull mem;
const Random *rng; const Random *_Nonnull rng;
const Network *ns; const Network *_Nonnull ns;
Socket sock; Socket sock;
IP_Port ip_port; // for debugging. IP_Port ip_port; // for debugging.
uint8_t sent_nonce[CRYPTO_NONCE_SIZE]; /* Nonce of sent packets. */ uint8_t sent_nonce[CRYPTO_NONCE_SIZE]; /* Nonce of sent packets. */
@@ -65,57 +63,47 @@ typedef struct TCP_Connection {
uint16_t last_packet_length; uint16_t last_packet_length;
uint16_t last_packet_sent; uint16_t last_packet_sent;
TCP_Priority_List *priority_queue_start; TCP_Priority_List *_Nullable priority_queue_start;
TCP_Priority_List *priority_queue_end; TCP_Priority_List *_Nullable priority_queue_end;
// This is a shared pointer to the parent's respective Net_Profile object // This is a shared pointer to the parent's respective Net_Profile object
// (either TCP_Server for TCP server packets or TCP_Connections for TCP client packets). // (either TCP_Server for TCP server packets or TCP_Connections for TCP client packets).
Net_Profile *net_profile; Net_Profile *_Nullable net_profile;
} TCP_Connection; } TCP_Connection;
/** /**
* @retval 0 if pending data was sent completely * @retval 0 if pending data was sent completely
* @retval -1 if it wasn't * @retval -1 if it wasn't
*/ */
non_null() int send_pending_data_nonpriority(const Logger *_Nonnull logger, TCP_Connection *_Nonnull con);
int send_pending_data_nonpriority(const Logger *logger, TCP_Connection *con);
/** /**
* @retval 0 if pending data was sent completely * @retval 0 if pending data was sent completely
* @retval -1 if it wasn't * @retval -1 if it wasn't
*/ */
non_null() int send_pending_data(const Logger *_Nonnull logger, TCP_Connection *_Nonnull con);
int send_pending_data(const Logger *logger, TCP_Connection *con);
/** /**
* @retval 1 on success. * @retval 1 on success.
* @retval 0 if could not send packet. * @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed). * @retval -1 on failure (connection must be killed).
*/ */
non_null() int write_packet_tcp_secure_connection(const Logger *_Nonnull logger, TCP_Connection *_Nonnull con, const uint8_t *_Nonnull data, uint16_t length, bool priority);
int write_packet_tcp_secure_connection(
const Logger *logger, TCP_Connection *con, const uint8_t *data, uint16_t length,
bool priority);
/** @brief Read length bytes from socket. /** @brief Read length bytes from socket.
* *
* return length on success * return length on success
* return -1 on failure/no data in buffer. * return -1 on failure/no data in buffer.
*/ */
non_null() int read_tcp_packet(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Network *_Nonnull ns, Socket sock, uint8_t *_Nonnull data, uint16_t length,
int read_tcp_packet( const IP_Port *_Nonnull ip_port);
const Logger *logger, const Memory *mem, const Network *ns, Socket sock, uint8_t *data, uint16_t length, const IP_Port *ip_port);
/** /**
* @return length of received packet on success. * @return length of received packet on success.
* @retval 0 if could not read any packet. * @retval 0 if could not read any packet.
* @retval -1 on failure (connection must be killed). * @retval -1 on failure (connection must be killed).
*/ */
non_null() int read_packet_tcp_secure_connection(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Network *_Nonnull ns, Socket sock, uint16_t *_Nonnull next_packet_length,
int read_packet_tcp_secure_connection( const uint8_t *_Nonnull shared_key, uint8_t *_Nonnull recv_nonce, uint8_t *_Nonnull data, uint16_t max_len, const IP_Port *_Nonnull ip_port);
const Logger *logger, const Memory *mem, const Network *ns,
Socket sock, uint16_t *next_packet_length,
const uint8_t *shared_key, uint8_t *recv_nonce, uint8_t *data,
uint16_t max_len, const IP_Port *ip_port);
#endif /* C_TOXCORE_TOXCORE_TCP_COMMON_H */ #endif /* C_TOXCORE_TOXCORE_TCP_COMMON_H */

View File

@@ -80,8 +80,7 @@ uint32_t tcp_connections_count(const TCP_Connections *tcp_c)
* @retval -1 if mem_vrealloc fails. * @retval -1 if mem_vrealloc fails.
* @retval 0 if it succeeds. * @retval 0 if it succeeds.
*/ */
non_null() static int realloc_tcp_connection_to(const Memory *_Nonnull mem, TCP_Connection_to *_Nullable *_Nonnull array, size_t num)
static int realloc_tcp_connection_to(const Memory *mem, TCP_Connection_to **array, size_t num)
{ {
if (num == 0) { if (num == 0) {
mem_delete(mem, *array); mem_delete(mem, *array);
@@ -101,8 +100,7 @@ static int realloc_tcp_connection_to(const Memory *mem, TCP_Connection_to **arra
return 0; return 0;
} }
non_null() static int realloc_tcp_con(const Memory *_Nonnull mem, TCP_con *_Nullable *_Nonnull array, size_t num)
static int realloc_tcp_con(const Memory *mem, TCP_con **array, size_t num)
{ {
if (num == 0) { if (num == 0) {
mem_delete(mem, *array); mem_delete(mem, *array);
@@ -124,8 +122,7 @@ static int realloc_tcp_con(const Memory *mem, TCP_con **array, size_t num)
/** /**
* Return true if the connections_number is valid. * Return true if the connections_number is valid.
*/ */
non_null() static bool connections_number_is_valid(const TCP_Connections *_Nonnull tcp_c, int connections_number)
static bool connections_number_is_valid(const TCP_Connections *tcp_c, int connections_number)
{ {
if ((unsigned int)connections_number >= tcp_c->connections_length) { if ((unsigned int)connections_number >= tcp_c->connections_length) {
return false; return false;
@@ -141,8 +138,7 @@ static bool connections_number_is_valid(const TCP_Connections *tcp_c, int connec
/** /**
* Return true if the tcp_connections_number is valid. * Return true if the tcp_connections_number is valid.
*/ */
non_null() static bool tcp_connections_number_is_valid(const TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
static bool tcp_connections_number_is_valid(const TCP_Connections *tcp_c, int tcp_connections_number)
{ {
if ((uint32_t)tcp_connections_number >= tcp_c->tcp_connections_length) { if ((uint32_t)tcp_connections_number >= tcp_c->tcp_connections_length) {
return false; return false;
@@ -160,8 +156,7 @@ static bool tcp_connections_number_is_valid(const TCP_Connections *tcp_c, int tc
* return -1 on failure. * return -1 on failure.
* return connections_number on success. * return connections_number on success.
*/ */
non_null() static int create_connection(TCP_Connections *_Nonnull tcp_c)
static int create_connection(TCP_Connections *tcp_c)
{ {
for (uint32_t i = 0; i < tcp_c->connections_length; ++i) { for (uint32_t i = 0; i < tcp_c->connections_length; ++i) {
if (tcp_c->connections[i].status == TCP_CONN_NONE) { if (tcp_c->connections[i].status == TCP_CONN_NONE) {
@@ -185,8 +180,7 @@ static int create_connection(TCP_Connections *tcp_c)
* return -1 on failure. * return -1 on failure.
* return tcp_connections_number on success. * return tcp_connections_number on success.
*/ */
non_null() static int create_tcp_connection(TCP_Connections *_Nonnull tcp_c)
static int create_tcp_connection(TCP_Connections *tcp_c)
{ {
for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) { for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
if (tcp_c->tcp_connections[i].status == TCP_CONN_NONE) { if (tcp_c->tcp_connections[i].status == TCP_CONN_NONE) {
@@ -210,8 +204,7 @@ static int create_tcp_connection(TCP_Connections *tcp_c)
* return -1 on failure. * return -1 on failure.
* return 0 on success. * return 0 on success.
*/ */
non_null() static int wipe_connection(TCP_Connections *_Nonnull tcp_c, int connections_number)
static int wipe_connection(TCP_Connections *tcp_c, int connections_number)
{ {
if (!connections_number_is_valid(tcp_c, connections_number)) { if (!connections_number_is_valid(tcp_c, connections_number)) {
return -1; return -1;
@@ -241,8 +234,7 @@ static int wipe_connection(TCP_Connections *tcp_c, int connections_number)
* return -1 on failure. * return -1 on failure.
* return 0 on success. * return 0 on success.
*/ */
non_null() static int wipe_tcp_connection(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_number)
{ {
if (!tcp_connections_number_is_valid(tcp_c, tcp_connections_number)) { if (!tcp_connections_number_is_valid(tcp_c, tcp_connections_number)) {
return -1; return -1;
@@ -268,8 +260,7 @@ static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_numbe
return 0; return 0;
} }
non_null() static TCP_Connection_to *get_connection(const TCP_Connections *_Nonnull tcp_c, int connections_number)
static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int connections_number)
{ {
if (!connections_number_is_valid(tcp_c, connections_number)) { if (!connections_number_is_valid(tcp_c, connections_number)) {
return nullptr; return nullptr;
@@ -278,8 +269,7 @@ static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int conne
return &tcp_c->connections[connections_number]; return &tcp_c->connections[connections_number];
} }
non_null() static TCP_con *get_tcp_connection(const TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
static TCP_con *get_tcp_connection(const TCP_Connections *tcp_c, int tcp_connections_number)
{ {
if (!tcp_connections_number_is_valid(tcp_c, tcp_connections_number)) { if (!tcp_connections_number_is_valid(tcp_c, tcp_connections_number)) {
return nullptr; return nullptr;
@@ -413,8 +403,7 @@ int get_random_tcp_onion_conn_number(const TCP_Connections *tcp_c)
* return TCP connection number on success. * return TCP connection number on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() static int get_conn_number_by_ip_port(const TCP_Connections *_Nonnull tcp_c, const IP_Port *_Nonnull ip_port)
static int get_conn_number_by_ip_port(const TCP_Connections *tcp_c, const IP_Port *ip_port)
{ {
for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) { for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
const IP_Port conn_ip_port = tcp_con_ip_port(tcp_c->tcp_connections[i].connection); const IP_Port conn_ip_port = tcp_con_ip_port(tcp_c->tcp_connections[i].connection);
@@ -526,8 +515,7 @@ int tcp_send_oob_packet(const TCP_Connections *tcp_c, unsigned int tcp_connectio
return -1; return -1;
} }
non_null() static int find_tcp_connection_relay(const TCP_Connections *_Nonnull tcp_c, const uint8_t *_Nonnull relay_pk);
static int find_tcp_connection_relay(const TCP_Connections *tcp_c, const uint8_t *relay_pk);
/** @brief Send an oob packet via the TCP relay corresponding to relay_pk. /** @brief Send an oob packet via the TCP relay corresponding to relay_pk.
* *
@@ -604,8 +592,7 @@ bool ip_port_to_tcp_connections_number(const IP_Port *ip_port, unsigned int *tcp
* return connections_number on success. * return connections_number on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() static int find_tcp_connection_to(const TCP_Connections *_Nonnull tcp_c, const uint8_t *_Nonnull public_key)
static int find_tcp_connection_to(const TCP_Connections *tcp_c, const uint8_t *public_key)
{ {
for (uint32_t i = 0; i < tcp_c->connections_length; ++i) { for (uint32_t i = 0; i < tcp_c->connections_length; ++i) {
const TCP_Connection_to *con_to = get_connection(tcp_c, i); const TCP_Connection_to *con_to = get_connection(tcp_c, i);
@@ -786,8 +773,7 @@ int set_tcp_connection_to_status(const TCP_Connections *tcp_c, int connections_n
return 0; return 0;
} }
non_null() static bool tcp_connection_in_conn(const TCP_Connection_to *_Nonnull con_to, unsigned int tcp_connections_number)
static bool tcp_connection_in_conn(const TCP_Connection_to *con_to, unsigned int tcp_connections_number)
{ {
for (uint32_t i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { for (uint32_t i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
if (con_to->connections[i].tcp_connection == (tcp_connections_number + 1)) { if (con_to->connections[i].tcp_connection == (tcp_connections_number + 1)) {
@@ -802,8 +788,7 @@ static bool tcp_connection_in_conn(const TCP_Connection_to *con_to, unsigned int
* @return index on success. * @return index on success.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() static int add_tcp_connection_to_conn(TCP_Connection_to *_Nonnull con_to, unsigned int tcp_connections_number)
static int add_tcp_connection_to_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number)
{ {
if (tcp_connection_in_conn(con_to, tcp_connections_number)) { if (tcp_connection_in_conn(con_to, tcp_connections_number)) {
return -1; return -1;
@@ -825,8 +810,7 @@ static int add_tcp_connection_to_conn(TCP_Connection_to *con_to, unsigned int tc
* @return index on success. * @return index on success.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() static int rm_tcp_connection_from_conn(TCP_Connection_to *_Nonnull con_to, unsigned int tcp_connections_number)
static int rm_tcp_connection_from_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number)
{ {
for (uint32_t i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { for (uint32_t i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
if (con_to->connections[i].tcp_connection == (tcp_connections_number + 1)) { if (con_to->connections[i].tcp_connection == (tcp_connections_number + 1)) {
@@ -844,8 +828,7 @@ static int rm_tcp_connection_from_conn(TCP_Connection_to *con_to, unsigned int t
* @return number of online connections on success. * @return number of online connections on success.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() static uint32_t online_tcp_connection_from_conn(const TCP_Connection_to *_Nonnull con_to)
static uint32_t online_tcp_connection_from_conn(const TCP_Connection_to *con_to)
{ {
uint32_t count = 0; uint32_t count = 0;
@@ -864,10 +847,7 @@ static uint32_t online_tcp_connection_from_conn(const TCP_Connection_to *con_to)
* @return index on success. * @return index on success.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() static int set_tcp_connection_status(TCP_Connection_to *_Nonnull con_to, unsigned int tcp_connections_number, uint8_t status, uint8_t connection_id)
static int set_tcp_connection_status(TCP_Connection_to *con_to, unsigned int tcp_connections_number,
uint8_t status,
uint8_t connection_id)
{ {
for (uint32_t i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { for (uint32_t i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
if (con_to->connections[i].tcp_connection == (tcp_connections_number + 1)) { if (con_to->connections[i].tcp_connection == (tcp_connections_number + 1)) {
@@ -915,8 +895,7 @@ int kill_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number
return wipe_tcp_connection(tcp_c, tcp_connections_number); return wipe_tcp_connection(tcp_c, tcp_connections_number);
} }
non_null() static int reconnect_tcp_relay_connection(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number)
{ {
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -962,8 +941,7 @@ static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connec
return 0; return 0;
} }
non_null() static int sleep_tcp_relay_connection(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
static int sleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number)
{ {
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -1007,8 +985,7 @@ static int sleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connection
return 0; return 0;
} }
non_null() static int unsleep_tcp_relay_connection(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number)
{ {
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -1043,9 +1020,7 @@ static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connecti
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() static int send_tcp_relay_routing_request(const TCP_Connections *_Nonnull tcp_c, int tcp_connections_number, const uint8_t *_Nonnull public_key)
static int send_tcp_relay_routing_request(const TCP_Connections *tcp_c, int tcp_connections_number,
const uint8_t *public_key)
{ {
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -1064,8 +1039,7 @@ static int send_tcp_relay_routing_request(const TCP_Connections *tcp_c, int tcp_
return 0; return 0;
} }
non_null() static int tcp_response_callback(void *_Nonnull object, uint8_t connection_id, const uint8_t *_Nonnull public_key)
static int tcp_response_callback(void *object, uint8_t connection_id, const uint8_t *public_key)
{ {
const TCP_Client_Connection *tcp_client_con = (const TCP_Client_Connection *)object; const TCP_Client_Connection *tcp_client_con = (const TCP_Client_Connection *)object;
const TCP_Connections *tcp_c = (const TCP_Connections *)tcp_con_custom_object(tcp_client_con); const TCP_Connections *tcp_c = (const TCP_Connections *)tcp_con_custom_object(tcp_client_con);
@@ -1098,8 +1072,7 @@ static int tcp_response_callback(void *object, uint8_t connection_id, const uint
return 0; return 0;
} }
non_null() static int tcp_status_callback(void *_Nonnull object, uint32_t number, uint8_t connection_id, uint8_t status)
static int tcp_status_callback(void *object, uint32_t number, uint8_t connection_id, uint8_t status)
{ {
const TCP_Client_Connection *tcp_client_con = (const TCP_Client_Connection *)object; const TCP_Client_Connection *tcp_client_con = (const TCP_Client_Connection *)object;
const TCP_Connections *tcp_c = (const TCP_Connections *)tcp_con_custom_object(tcp_client_con); const TCP_Connections *tcp_c = (const TCP_Connections *)tcp_con_custom_object(tcp_client_con);
@@ -1137,12 +1110,10 @@ static int tcp_status_callback(void *object, uint32_t number, uint8_t connection
return 0; return 0;
} }
non_null(1, 4) nullable(6) static int tcp_conn_data_callback(void *_Nonnull object, uint32_t number, uint8_t connection_id, const uint8_t *_Nonnull data,
static int tcp_conn_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length, void *_Nullable userdata)
uint16_t length, void *userdata)
{ {
const TCP_Client_Connection *tcp_client_con = (TCP_Client_Connection *)object; const TCP_Client_Connection *tcp_client_con = (TCP_Client_Connection *)object;
if (length == 0) { if (length == 0) {
return -1; return -1;
} }
@@ -1169,9 +1140,7 @@ static int tcp_conn_data_callback(void *object, uint32_t number, uint8_t connect
return 0; return 0;
} }
non_null() static int tcp_conn_oob_callback(void *_Nonnull object, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull data, uint16_t length, void *_Nonnull userdata)
static int tcp_conn_oob_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length,
void *userdata)
{ {
const TCP_Client_Connection *tcp_client_con = (const TCP_Client_Connection *)object; const TCP_Client_Connection *tcp_client_con = (const TCP_Client_Connection *)object;
@@ -1204,8 +1173,7 @@ static int tcp_conn_oob_callback(void *object, const uint8_t *public_key, const
return 0; return 0;
} }
non_null() static int tcp_onion_callback(void *_Nonnull object, const uint8_t *_Nonnull data, uint16_t length, void *_Nonnull userdata)
static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length, void *userdata)
{ {
TCP_Connections *tcp_c = (TCP_Connections *)object; TCP_Connections *tcp_c = (TCP_Connections *)object;
@@ -1216,8 +1184,7 @@ static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length
return 0; return 0;
} }
non_null() static void tcp_forwarding_callback(void *_Nonnull object, const uint8_t *_Nonnull data, uint16_t length, void *_Nonnull userdata)
static void tcp_forwarding_callback(void *object, const uint8_t *data, uint16_t length, void *userdata)
{ {
TCP_Connections *tcp_c = (TCP_Connections *)object; TCP_Connections *tcp_c = (TCP_Connections *)object;
@@ -1231,8 +1198,7 @@ static void tcp_forwarding_callback(void *object, const uint8_t *data, uint16_t
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() static int tcp_relay_set_callbacks(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
static int tcp_relay_set_callbacks(TCP_Connections *tcp_c, int tcp_connections_number)
{ {
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -1254,8 +1220,7 @@ static int tcp_relay_set_callbacks(TCP_Connections *tcp_c, int tcp_connections_n
return 0; return 0;
} }
non_null() static int tcp_relay_on_online(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
static int tcp_relay_on_online(TCP_Connections *tcp_c, int tcp_connections_number)
{ {
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -1295,8 +1260,7 @@ static int tcp_relay_on_online(TCP_Connections *tcp_c, int tcp_connections_numbe
return 0; return 0;
} }
non_null() static int add_tcp_relay_instance(TCP_Connections *_Nonnull tcp_c, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull relay_pk)
static int add_tcp_relay_instance(TCP_Connections *tcp_c, const IP_Port *ip_port, const uint8_t *relay_pk)
{ {
IP_Port ipp_copy = *ip_port; IP_Port ipp_copy = *ip_port;
@@ -1451,8 +1415,7 @@ uint32_t tcp_connection_to_online_tcp_relays(const TCP_Connections *tcp_c, int c
* Returns true if the relay was successfully copied. * Returns true if the relay was successfully copied.
* Returns false if the connection index is invalid, or if the relay is not connected. * Returns false if the connection index is invalid, or if the relay is not connected.
*/ */
non_null() static bool copy_tcp_relay_conn(const TCP_Connections *_Nonnull tcp_c, Node_format *_Nonnull tcp_relay, uint16_t idx)
static bool copy_tcp_relay_conn(const TCP_Connections *tcp_c, Node_format *tcp_relay, uint16_t idx)
{ {
const TCP_con *tcp_con = get_tcp_connection(tcp_c, idx); const TCP_con *tcp_con = get_tcp_connection(tcp_c, idx);
@@ -1628,12 +1591,10 @@ TCP_Connections *new_tcp_connections(const Logger *logger, const Memory *mem, co
return temp; return temp;
} }
non_null(1, 2) nullable(3) static void do_tcp_conns(const Logger *_Nonnull logger, TCP_Connections *_Nonnull tcp_c, void *_Nullable userdata)
static void do_tcp_conns(const Logger *logger, TCP_Connections *tcp_c, void *userdata)
{ {
for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) { for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
TCP_con *tcp_con = get_tcp_connection(tcp_c, i); TCP_con *tcp_con = get_tcp_connection(tcp_c, i);
if (tcp_con == nullptr) { if (tcp_con == nullptr) {
continue; continue;
} }
@@ -1675,9 +1636,12 @@ static void do_tcp_conns(const Logger *logger, TCP_Connections *tcp_c, void *use
} }
} }
non_null() static void kill_nonused_tcp(TCP_Connections *_Nullable tcp_c)
static void kill_nonused_tcp(TCP_Connections *tcp_c)
{ {
if (tcp_c == nullptr) {
return;
}
if (tcp_c->tcp_connections_length <= RECOMMENDED_FRIEND_TCP_CONNECTIONS) { if (tcp_c->tcp_connections_length <= RECOMMENDED_FRIEND_TCP_CONNECTIONS) {
return; return;
} }

View File

@@ -67,7 +67,7 @@ typedef struct TCP_Connection_to {
typedef struct TCP_con { typedef struct TCP_con {
uint8_t status; uint8_t status;
TCP_Client_Connection *connection; TCP_Client_Connection *_Nullable connection;
uint64_t connected_time; uint64_t connected_time;
uint32_t lock_count; uint32_t lock_count;
uint32_t sleep_count; uint32_t sleep_count;
@@ -81,28 +81,22 @@ typedef struct TCP_con {
typedef struct TCP_Connections TCP_Connections; typedef struct TCP_Connections TCP_Connections;
non_null() const uint8_t *_Nonnull tcp_connections_public_key(const TCP_Connections *_Nonnull tcp_c);
const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c);
non_null() uint32_t tcp_connections_count(const TCP_Connections *_Nonnull tcp_c);
uint32_t tcp_connections_count(const TCP_Connections *tcp_c);
/** @brief Returns the number of connected TCP relays. */ /** @brief Returns the number of connected TCP relays. */
non_null() uint32_t tcp_connected_relays_count(const TCP_Connections *_Nonnull tcp_c);
uint32_t tcp_connected_relays_count(const TCP_Connections *tcp_c);
/** @brief Returns true if we know of a valid TCP relay with the passed public key. */ /** @brief Returns true if we know of a valid TCP relay with the passed public key. */
non_null() bool tcp_relay_is_valid(const TCP_Connections *_Nonnull tcp_c, const uint8_t *_Nonnull relay_pk);
bool tcp_relay_is_valid(const TCP_Connections *tcp_c, const uint8_t *relay_pk);
/** @brief Send a packet to the TCP connection. /** @brief Send a packet to the TCP connection.
* *
* return -1 on failure. * return -1 on failure.
* return 0 on success. * return 0 on success.
*/ */
non_null() int send_packet_tcp_connection(const TCP_Connections *_Nonnull tcp_c, int connections_number, const uint8_t *_Nonnull packet, uint16_t length);
int send_packet_tcp_connection(const TCP_Connections *tcp_c, int connections_number, const uint8_t *packet,
uint16_t length);
/** @brief Return a TCP connection number for use in send_tcp_onion_request. /** @brief Return a TCP connection number for use in send_tcp_onion_request.
* *
@@ -112,25 +106,21 @@ int send_packet_tcp_connection(const TCP_Connections *tcp_c, int connections_num
* return TCP connection number on success. * return TCP connection number on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() int get_random_tcp_onion_conn_number(const TCP_Connections *_Nonnull tcp_c);
int get_random_tcp_onion_conn_number(const TCP_Connections *tcp_c);
/** @brief Put IP_Port of a random onion TCP connection in ip_port. /** @brief Put IP_Port of a random onion TCP connection in ip_port.
* *
* return true on success. * return true on success.
* return false on failure. * return false on failure.
*/ */
non_null() bool tcp_get_random_conn_ip_port(const TCP_Connections *_Nonnull tcp_c, IP_Port *_Nonnull ip_port);
bool tcp_get_random_conn_ip_port(const TCP_Connections *tcp_c, IP_Port *ip_port);
/** @brief Send an onion packet via the TCP relay corresponding to tcp_connections_number. /** @brief Send an onion packet via the TCP relay corresponding to tcp_connections_number.
* *
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() int tcp_send_onion_request(TCP_Connections *_Nonnull tcp_c, uint32_t tcp_connections_number, const uint8_t *_Nonnull data, uint16_t length);
int tcp_send_onion_request(TCP_Connections *tcp_c, uint32_t tcp_connections_number, const uint8_t *data,
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.
* *
@@ -139,8 +129,7 @@ int tcp_send_onion_request(TCP_Connections *tcp_c, uint32_t tcp_connections_numb
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() int set_tcp_onion_status(TCP_Connections *_Nonnull tcp_c, bool status);
int set_tcp_onion_status(TCP_Connections *tcp_c, bool status);
/** /**
* Send a forward request to the TCP relay with IP_Port tcp_forwarder, * Send a forward request to the TCP relay with IP_Port tcp_forwarder,
@@ -150,49 +139,37 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status);
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() int tcp_send_forward_request(const Logger *_Nonnull logger, TCP_Connections *_Nonnull tcp_c, const IP_Port *_Nonnull tcp_forwarder, const IP_Port *_Nonnull dht_node,
int tcp_send_forward_request(const Logger *logger, TCP_Connections *tcp_c, const IP_Port *tcp_forwarder, const uint8_t *_Nonnull chain_keys, uint16_t chain_length, const uint8_t *_Nonnull data, uint16_t data_length);
const IP_Port *dht_node,
const uint8_t *chain_keys, uint16_t chain_length,
const uint8_t *data, uint16_t data_length);
/** @brief Send an oob packet via the TCP relay corresponding to tcp_connections_number. /** @brief Send an oob packet via the TCP relay corresponding to tcp_connections_number.
* *
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() int tcp_send_oob_packet(const TCP_Connections *_Nonnull tcp_c, unsigned int tcp_connections_number, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull packet, uint16_t length);
int tcp_send_oob_packet(const TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *public_key,
const uint8_t *packet, uint16_t length);
typedef int tcp_data_cb(void *object, int crypt_connection_id, const uint8_t *packet, uint16_t length, void *userdata); typedef int tcp_data_cb(void *_Nonnull object, int crypt_connection_id, const uint8_t *_Nonnull packet, uint16_t length, void *_Nullable userdata);
non_null() int tcp_send_oob_packet_using_relay(const TCP_Connections *_Nonnull tcp_c, const uint8_t *_Nonnull relay_pk, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull packet,
int tcp_send_oob_packet_using_relay(const TCP_Connections *tcp_c, const uint8_t *relay_pk, const uint8_t *public_key, uint16_t length);
const uint8_t *packet, uint16_t length);
/** @brief Set the callback for TCP data packets. */ /** @brief Set the callback for TCP data packets. */
non_null() void set_packet_tcp_connection_callback(TCP_Connections *_Nonnull tcp_c, tcp_data_cb *_Nonnull tcp_data_callback, void *_Nonnull object);
void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_data_cb *tcp_data_callback, void *object);
typedef int tcp_onion_cb(void *object, const uint8_t *data, uint16_t length, void *userdata); typedef int tcp_onion_cb(void *_Nullable object, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
/** @brief Set the callback for TCP onion packets. */ /** @brief Set the callback for TCP onion packets. */
non_null(1) nullable(2, 3) void set_onion_packet_tcp_connection_callback(TCP_Connections *_Nonnull tcp_c, tcp_onion_cb *_Nullable tcp_onion_callback, void *_Nullable object);
void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_onion_cb *tcp_onion_callback, void *object);
/** @brief Set the callback for TCP forwarding packets. */ /** @brief Set the callback for TCP forwarding packets. */
non_null(1) nullable(2, 3) void set_forwarding_packet_tcp_connection_callback(TCP_Connections *_Nonnull tcp_c,
void set_forwarding_packet_tcp_connection_callback(TCP_Connections *tcp_c, forwarded_response_cb *_Nullable tcp_forwarded_response_callback,
forwarded_response_cb *tcp_forwarded_response_callback, void *_Nullable object);
void *object); typedef int tcp_oob_cb(void *_Nonnull object, const uint8_t *_Nonnull public_key, unsigned int tcp_connections_number,
const uint8_t *_Nonnull packet, uint16_t length, void *_Nullable userdata);
typedef int tcp_oob_cb(void *object, const uint8_t *public_key, unsigned int tcp_connections_number,
const uint8_t *packet, uint16_t length, void *userdata);
/** @brief Set the callback for TCP oob data packets. */ /** @brief Set the callback for TCP oob data packets. */
non_null() void set_oob_packet_tcp_connection_callback(TCP_Connections *_Nonnull tcp_c, tcp_oob_cb *_Nonnull tcp_oob_callback, void *_Nonnull object);
void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_oob_cb *tcp_oob_callback, void *object);
/** @brief Encode tcp_connections_number as a custom ip_port. /** @brief Encode tcp_connections_number as a custom ip_port.
* *
@@ -205,8 +182,7 @@ IP_Port tcp_connections_number_to_ip_port(unsigned int tcp_connections_number);
* return true on success. * return true on success.
* return false if ip_port is invalid. * return false if ip_port is invalid.
*/ */
non_null() bool ip_port_to_tcp_connections_number(const IP_Port *_Nonnull ip_port, unsigned int *_Nonnull tcp_connections_number);
bool ip_port_to_tcp_connections_number(const IP_Port *ip_port, unsigned int *tcp_connections_number);
/** @brief Create a new TCP connection to public_key. /** @brief Create a new TCP connection to public_key.
* *
@@ -217,15 +193,13 @@ bool ip_port_to_tcp_connections_number(const IP_Port *ip_port, unsigned int *tcp
* return connections_number on success. * return connections_number on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() int new_tcp_connection_to(TCP_Connections *_Nonnull tcp_c, const uint8_t *_Nonnull public_key, int id);
int new_tcp_connection_to(TCP_Connections *tcp_c, const uint8_t *public_key, int id);
/** /**
* @retval 0 on success. * @retval 0 on success.
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() int kill_tcp_connection_to(TCP_Connections *_Nonnull tcp_c, int connections_number);
int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number);
/** @brief Set connection status. /** @brief Set connection status.
* *
@@ -237,15 +211,13 @@ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number);
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() int set_tcp_connection_to_status(const TCP_Connections *_Nonnull tcp_c, int connections_number, bool status);
int set_tcp_connection_to_status(const TCP_Connections *tcp_c, int connections_number, bool status);
/** /**
* @return number of online tcp relays tied to the connection on success. * @return number of online tcp relays tied to the connection on success.
* @retval 0 on failure. * @retval 0 on failure.
*/ */
non_null() uint32_t tcp_connection_to_online_tcp_relays(const TCP_Connections *_Nonnull tcp_c, int connections_number);
uint32_t tcp_connection_to_online_tcp_relays(const TCP_Connections *tcp_c, int connections_number);
/** @brief Add a TCP relay tied to a connection. /** @brief Add a TCP relay tied to a connection.
* *
@@ -254,9 +226,7 @@ uint32_t tcp_connection_to_online_tcp_relays(const TCP_Connections *tcp_c, int c
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() int add_tcp_number_relay_connection(const TCP_Connections *_Nonnull tcp_c, int connections_number, unsigned int tcp_connections_number);
int add_tcp_number_relay_connection(const TCP_Connections *tcp_c, int connections_number,
unsigned int tcp_connections_number);
/** @brief Add a TCP relay tied to a connection. /** @brief Add a TCP relay tied to a connection.
* *
@@ -265,17 +235,14 @@ int add_tcp_number_relay_connection(const TCP_Connections *tcp_c, int connection
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() int add_tcp_relay_connection(TCP_Connections *_Nonnull tcp_c, int connections_number, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull relay_pk);
int add_tcp_relay_connection(TCP_Connections *tcp_c, int connections_number, const IP_Port *ip_port,
const uint8_t *relay_pk);
/** @brief Add a TCP relay to the TCP_Connections instance. /** @brief Add a TCP relay to the TCP_Connections instance.
* *
* return 0 on success. * return 0 on success.
* return -1 on failure. * return -1 on failure.
*/ */
non_null() int add_tcp_relay_global(TCP_Connections *_Nonnull tcp_c, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull relay_pk);
int add_tcp_relay_global(TCP_Connections *tcp_c, const IP_Port *ip_port, const uint8_t *relay_pk);
/** @brief Copy a maximum of max_num TCP relays we are connected to to tcp_relays. /** @brief Copy a maximum of max_num TCP relays we are connected to to tcp_relays.
* *
@@ -284,8 +251,7 @@ int add_tcp_relay_global(TCP_Connections *tcp_c, const IP_Port *ip_port, const u
* return number of relays copied to tcp_relays on success. * return number of relays copied to tcp_relays on success.
* return 0 on failure. * return 0 on failure.
*/ */
non_null() uint32_t tcp_copy_connected_relays(const TCP_Connections *_Nonnull tcp_c, Node_format *_Nonnull tcp_relays, uint16_t max_num);
uint32_t tcp_copy_connected_relays(const TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num);
/** @brief Copy a maximum of `max_num` TCP relays we are connected to starting at idx. /** @brief Copy a maximum of `max_num` TCP relays we are connected to starting at idx.
* *
@@ -294,9 +260,7 @@ uint32_t tcp_copy_connected_relays(const TCP_Connections *tcp_c, Node_format *tc
* *
* Returns the number of relays successfully copied. * Returns the number of relays successfully copied.
*/ */
non_null() uint32_t tcp_copy_connected_relays_index(const TCP_Connections *_Nonnull tcp_c, Node_format *_Nonnull tcp_relays, uint16_t max_num, uint32_t idx);
uint32_t tcp_copy_connected_relays_index(const TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num,
uint32_t idx);
/** @brief Returns a new TCP_Connections object associated with the secret_key. /** @brief Returns a new TCP_Connections object associated with the secret_key.
* *
@@ -305,17 +269,11 @@ uint32_t tcp_copy_connected_relays_index(const TCP_Connections *tcp_c, Node_form
* *
* Returns NULL on failure. * Returns NULL on failure.
*/ */
non_null() TCP_Connections *_Nullable new_tcp_connections(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Network *_Nonnull ns, Mono_Time *_Nonnull mono_time,
TCP_Connections *new_tcp_connections(const Logger *logger, const Memory *mem, const Random *rng, const Network *ns, const uint8_t *_Nonnull secret_key, const TCP_Proxy_Info *_Nonnull proxy_info, Net_Profile *_Nonnull tcp_np);
Mono_Time *mono_time, const uint8_t *secret_key, const TCP_Proxy_Info *proxy_info, Net_Profile *tcp_np);
non_null() int kill_tcp_relay_connection(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number);
int kill_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number);
non_null(1, 2) nullable(3)
void do_tcp_connections(const Logger *logger, TCP_Connections *tcp_c, void *userdata);
nullable(1)
void kill_tcp_connections(TCP_Connections *tcp_c);
void do_tcp_connections(const Logger *_Nonnull logger, TCP_Connections *_Nonnull tcp_c, void *_Nullable userdata);
void kill_tcp_connections(TCP_Connections *_Nullable tcp_c);
#endif /* C_TOXCORE_TOXCORE_TCP_CONNECTION_H */ #endif /* C_TOXCORE_TOXCORE_TCP_CONNECTION_H */

View File

@@ -122,8 +122,7 @@ size_t tcp_server_listen_count(const TCP_Server *tcp_server)
* @retval -1 on failure * @retval -1 on failure
* @retval 0 on success. * @retval 0 on success.
*/ */
non_null() static int alloc_new_connections(TCP_Server *_Nonnull tcp_server, uint32_t num)
static int alloc_new_connections(TCP_Server *tcp_server, uint32_t num)
{ {
const uint32_t new_size = tcp_server->size_accepted_connections + num; const uint32_t new_size = tcp_server->size_accepted_connections + num;
@@ -149,8 +148,7 @@ static int alloc_new_connections(TCP_Server *tcp_server, uint32_t num)
return 0; return 0;
} }
non_null() static void wipe_secure_connection(TCP_Secure_Connection *_Nonnull con)
static void wipe_secure_connection(TCP_Secure_Connection *con)
{ {
if (con->status != 0) { if (con->status != 0) {
wipe_priority_list(con->con.mem, con->con.priority_queue_start); wipe_priority_list(con->con.mem, con->con.priority_queue_start);
@@ -158,15 +156,13 @@ static void wipe_secure_connection(TCP_Secure_Connection *con)
} }
} }
non_null() static void move_secure_connection(TCP_Secure_Connection *_Nonnull con_new, TCP_Secure_Connection *_Nonnull con_old)
static void move_secure_connection(TCP_Secure_Connection *con_new, TCP_Secure_Connection *con_old)
{ {
*con_new = *con_old; *con_new = *con_old;
crypto_memzero(con_old, sizeof(TCP_Secure_Connection)); crypto_memzero(con_old, sizeof(TCP_Secure_Connection));
} }
non_null() static void free_accepted_connection_array(TCP_Server *_Nonnull tcp_server)
static void free_accepted_connection_array(TCP_Server *tcp_server)
{ {
if (tcp_server->accepted_connection_array == nullptr) { if (tcp_server->accepted_connection_array == nullptr) {
return; return;
@@ -185,22 +181,19 @@ static void free_accepted_connection_array(TCP_Server *tcp_server)
* @return index corresponding to connection with peer on success * @return index corresponding to connection with peer on success
* @retval -1 on failure. * @retval -1 on failure.
*/ */
non_null() static int get_tcp_connection_index(const TCP_Server *_Nonnull tcp_server, const uint8_t *_Nonnull public_key)
static int get_tcp_connection_index(const TCP_Server *tcp_server, const uint8_t *public_key)
{ {
return bs_list_find(&tcp_server->accepted_key_list, public_key); return bs_list_find(&tcp_server->accepted_key_list, public_key);
} }
non_null() static int kill_accepted(TCP_Server *_Nonnull tcp_server, int index);
static int kill_accepted(TCP_Server *tcp_server, int index);
/** @brief Add accepted TCP connection to the list. /** @brief Add accepted TCP connection to the list.
* *
* @return index on success * @return index on success
* @retval -1 on failure * @retval -1 on failure
*/ */
non_null() static int add_accepted(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time, TCP_Secure_Connection *_Nonnull con)
static int add_accepted(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_Secure_Connection *con)
{ {
int index = get_tcp_connection_index(tcp_server, con->public_key); int index = get_tcp_connection_index(tcp_server, con->public_key);
@@ -250,8 +243,7 @@ static int add_accepted(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_
* @retval 0 on success * @retval 0 on success
* @retval -1 on failure * @retval -1 on failure
*/ */
non_null() static int del_accepted(TCP_Server *_Nonnull tcp_server, int index)
static int del_accepted(TCP_Server *tcp_server, int index)
{ {
if ((uint32_t)index >= tcp_server->size_accepted_connections) { if ((uint32_t)index >= tcp_server->size_accepted_connections) {
return -1; return -1;
@@ -276,15 +268,17 @@ static int del_accepted(TCP_Server *tcp_server, int index)
} }
/** Kill a TCP_Secure_Connection */ /** Kill a TCP_Secure_Connection */
non_null() static void kill_tcp_secure_connection(TCP_Secure_Connection *_Nullable con)
static void kill_tcp_secure_connection(TCP_Secure_Connection *con)
{ {
if (con == nullptr) {
return;
}
kill_sock(con->con.ns, con->con.sock); kill_sock(con->con.ns, con->con.sock);
wipe_secure_connection(con); wipe_secure_connection(con);
} }
non_null() static int rm_connection_index(TCP_Server *_Nonnull tcp_server, TCP_Secure_Connection *_Nonnull con, uint8_t con_number);
static int rm_connection_index(TCP_Server *tcp_server, TCP_Secure_Connection *con, uint8_t con_number);
/** @brief Kill an accepted TCP_Secure_Connection /** @brief Kill an accepted TCP_Secure_Connection
* *
@@ -315,9 +309,7 @@ static int kill_accepted(TCP_Server *tcp_server, int index)
* @retval 1 if everything went well. * @retval 1 if everything went well.
* @retval -1 if the connection must be killed. * @retval -1 if the connection must be killed.
*/ */
non_null() static int handle_tcp_handshake(const Logger *_Nonnull logger, TCP_Secure_Connection *_Nonnull con, const uint8_t *_Nonnull data, uint16_t length, const uint8_t *_Nonnull self_secret_key)
static int handle_tcp_handshake(const Logger *logger, TCP_Secure_Connection *con, const uint8_t *data, uint16_t length,
const uint8_t *self_secret_key)
{ {
if (length != TCP_CLIENT_HANDSHAKE_SIZE) { if (length != TCP_CLIENT_HANDSHAKE_SIZE) {
LOGGER_ERROR(logger, "invalid handshake length: %d != %d", length, TCP_CLIENT_HANDSHAKE_SIZE); LOGGER_ERROR(logger, "invalid handshake length: %d != %d", length, TCP_CLIENT_HANDSHAKE_SIZE);
@@ -380,8 +372,7 @@ static int handle_tcp_handshake(const Logger *logger, TCP_Secure_Connection *con
* @retval 0 if we didn't get it yet. * @retval 0 if we didn't get it yet.
* @retval -1 if the connection must be killed. * @retval -1 if the connection must be killed.
*/ */
non_null() static int read_connection_handshake(const Logger *_Nonnull logger, TCP_Secure_Connection *_Nonnull con, const uint8_t *_Nonnull self_secret_key)
static int read_connection_handshake(const Logger *logger, TCP_Secure_Connection *con, const uint8_t *self_secret_key)
{ {
uint8_t data[TCP_CLIENT_HANDSHAKE_SIZE]; uint8_t data[TCP_CLIENT_HANDSHAKE_SIZE];
const int len = read_tcp_packet(logger, con->con.mem, con->con.ns, con->con.sock, data, TCP_CLIENT_HANDSHAKE_SIZE, &con->con.ip_port); const int len = read_tcp_packet(logger, con->con.mem, con->con.ns, con->con.sock, data, TCP_CLIENT_HANDSHAKE_SIZE, &con->con.ip_port);
@@ -399,9 +390,7 @@ static int read_connection_handshake(const Logger *logger, TCP_Secure_Connection
* @retval 0 if could not send packet. * @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed). * @retval -1 on failure (connection must be killed).
*/ */
non_null() static int send_routing_response(const Logger *_Nonnull logger, TCP_Secure_Connection *_Nonnull con, uint8_t rpid, const uint8_t *_Nonnull public_key)
static int send_routing_response(const Logger *logger, TCP_Secure_Connection *con, uint8_t rpid,
const uint8_t *public_key)
{ {
uint8_t data[2 + CRYPTO_PUBLIC_KEY_SIZE]; uint8_t data[2 + CRYPTO_PUBLIC_KEY_SIZE];
data[0] = TCP_PACKET_ROUTING_RESPONSE; data[0] = TCP_PACKET_ROUTING_RESPONSE;
@@ -416,8 +405,7 @@ static int send_routing_response(const Logger *logger, TCP_Secure_Connection *co
* @retval 0 if could not send packet. * @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed). * @retval -1 on failure (connection must be killed).
*/ */
non_null() static int send_connect_notification(const Logger *_Nonnull logger, TCP_Secure_Connection *_Nonnull con, uint8_t id)
static int send_connect_notification(const Logger *logger, TCP_Secure_Connection *con, uint8_t id)
{ {
uint8_t data[2] = {TCP_PACKET_CONNECTION_NOTIFICATION, (uint8_t)(id + NUM_RESERVED_PORTS)}; uint8_t data[2] = {TCP_PACKET_CONNECTION_NOTIFICATION, (uint8_t)(id + NUM_RESERVED_PORTS)};
return write_packet_tcp_secure_connection(logger, &con->con, data, sizeof(data), true); return write_packet_tcp_secure_connection(logger, &con->con, data, sizeof(data), true);
@@ -428,8 +416,7 @@ static int send_connect_notification(const Logger *logger, TCP_Secure_Connection
* @retval 0 if could not send packet. * @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed). * @retval -1 on failure (connection must be killed).
*/ */
non_null() static int send_disconnect_notification(const Logger *_Nonnull logger, TCP_Secure_Connection *_Nonnull con, uint8_t id)
static int send_disconnect_notification(const Logger *logger, TCP_Secure_Connection *con, uint8_t id)
{ {
uint8_t data[2] = {TCP_PACKET_DISCONNECT_NOTIFICATION, (uint8_t)(id + NUM_RESERVED_PORTS)}; uint8_t data[2] = {TCP_PACKET_DISCONNECT_NOTIFICATION, (uint8_t)(id + NUM_RESERVED_PORTS)};
return write_packet_tcp_secure_connection(logger, &con->con, data, sizeof(data), true); return write_packet_tcp_secure_connection(logger, &con->con, data, sizeof(data), true);
@@ -439,8 +426,7 @@ static int send_disconnect_notification(const Logger *logger, TCP_Secure_Connect
* @retval 0 on success. * @retval 0 on success.
* @retval -1 on failure (connection must be killed). * @retval -1 on failure (connection must be killed).
*/ */
non_null() static int handle_tcp_routing_req(TCP_Server *_Nonnull tcp_server, uint32_t con_id, const uint8_t *_Nonnull public_key)
static int handle_tcp_routing_req(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *public_key)
{ {
uint32_t index = -1; uint32_t index = -1;
TCP_Secure_Connection *con = &tcp_server->accepted_connection_array[con_id]; TCP_Secure_Connection *con = &tcp_server->accepted_connection_array[con_id];
@@ -522,9 +508,7 @@ static int handle_tcp_routing_req(TCP_Server *tcp_server, uint32_t con_id, const
* @retval 0 on success. * @retval 0 on success.
* @retval -1 on failure (connection must be killed). * @retval -1 on failure (connection must be killed).
*/ */
non_null() static int handle_tcp_oob_send(TCP_Server *_Nonnull tcp_server, uint32_t con_id, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull data, uint16_t length)
static int handle_tcp_oob_send(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *public_key, const uint8_t *data,
uint16_t length)
{ {
if (length == 0 || length > TCP_MAX_OOB_DATA_LENGTH) { if (length == 0 || length > TCP_MAX_OOB_DATA_LENGTH) {
return -1; return -1;
@@ -602,8 +586,7 @@ static IP_Port con_id_to_ip_port(uint32_t con_id, uint64_t identifier)
* @retval true on success. * @retval true on success.
* @retval false if ip_port is invalid. * @retval false if ip_port is invalid.
*/ */
non_null() static bool ip_port_to_con_id(const TCP_Server *_Nonnull tcp_server, const IP_Port *_Nonnull ip_port, uint32_t *_Nonnull con_id)
static bool ip_port_to_con_id(const TCP_Server *tcp_server, const IP_Port *ip_port, uint32_t *con_id)
{ {
*con_id = ip_port->ip.ip.v6.uint32[0]; *con_id = ip_port->ip.ip.v6.uint32[0];
@@ -612,8 +595,7 @@ static bool ip_port_to_con_id(const TCP_Server *tcp_server, const IP_Port *ip_po
tcp_server->accepted_connection_array[*con_id].identifier == ip_port->ip.ip.v6.uint64[1]; tcp_server->accepted_connection_array[*con_id].identifier == ip_port->ip.ip.v6.uint64[1];
} }
non_null() static int handle_onion_recv_1(void *_Nonnull object, const IP_Port *_Nonnull dest, const uint8_t *_Nonnull data, uint16_t length)
static int handle_onion_recv_1(void *object, const IP_Port *dest, const uint8_t *data, uint16_t length)
{ {
TCP_Server *tcp_server = (TCP_Server *)object; TCP_Server *tcp_server = (TCP_Server *)object;
uint32_t index; uint32_t index;
@@ -636,9 +618,7 @@ static int handle_onion_recv_1(void *object, const IP_Port *dest, const uint8_t
return 0; return 0;
} }
non_null() static bool handle_forward_reply_tcp(void *_Nonnull object, const uint8_t *_Nonnull sendback_data, uint16_t sendback_data_len, const uint8_t *_Nonnull data, uint16_t length)
static bool handle_forward_reply_tcp(void *object, const uint8_t *sendback_data, uint16_t sendback_data_len,
const uint8_t *data, uint16_t length)
{ {
TCP_Server *tcp_server = (TCP_Server *)object; TCP_Server *tcp_server = (TCP_Server *)object;
@@ -677,8 +657,7 @@ static bool handle_forward_reply_tcp(void *object, const uint8_t *sendback_data,
* @retval 0 on success * @retval 0 on success
* @retval -1 on failure * @retval -1 on failure
*/ */
non_null() static int handle_tcp_packet(TCP_Server *_Nonnull tcp_server, uint32_t con_id, const uint8_t *_Nonnull data, uint16_t length)
static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *data, uint16_t length)
{ {
if (length == 0) { if (length == 0) {
return -1; return -1;
@@ -693,7 +672,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
return -1; return -1;
} }
LOGGER_TRACE(tcp_server->logger, "handling routing request for %d", con_id); LOGGER_TRACE(tcp_server->logger, "handling routing request for %u", con_id);
return handle_tcp_routing_req(tcp_server, con_id, data + 1); return handle_tcp_routing_req(tcp_server, con_id, data + 1);
} }
@@ -702,7 +681,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
return -1; return -1;
} }
LOGGER_TRACE(tcp_server->logger, "handling connection notification for %d", con_id); LOGGER_TRACE(tcp_server->logger, "handling connection notification for %u", con_id);
break; break;
} }
@@ -711,7 +690,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
return -1; return -1;
} }
LOGGER_TRACE(tcp_server->logger, "handling disconnect notification for %d", con_id); LOGGER_TRACE(tcp_server->logger, "handling disconnect notification for %u", con_id);
return rm_connection_index(tcp_server, con, data[1] - NUM_RESERVED_PORTS); return rm_connection_index(tcp_server, con, data[1] - NUM_RESERVED_PORTS);
} }
@@ -720,7 +699,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
return -1; return -1;
} }
LOGGER_TRACE(tcp_server->logger, "handling ping for %d", con_id); LOGGER_TRACE(tcp_server->logger, "handling ping for %u", con_id);
uint8_t response[1 + sizeof(uint64_t)]; uint8_t response[1 + sizeof(uint64_t)];
response[0] = TCP_PACKET_PONG; response[0] = TCP_PACKET_PONG;
@@ -734,7 +713,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
return -1; return -1;
} }
LOGGER_TRACE(tcp_server->logger, "handling pong for %d", con_id); LOGGER_TRACE(tcp_server->logger, "handling pong for %u", con_id);
uint64_t ping_id; uint64_t ping_id;
memcpy(&ping_id, data + 1, sizeof(uint64_t)); memcpy(&ping_id, data + 1, sizeof(uint64_t));
@@ -755,14 +734,14 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
return -1; return -1;
} }
LOGGER_TRACE(tcp_server->logger, "handling oob send for %d", con_id); LOGGER_TRACE(tcp_server->logger, "handling oob send for %u", con_id);
return handle_tcp_oob_send(tcp_server, con_id, data + 1, data + 1 + CRYPTO_PUBLIC_KEY_SIZE, return handle_tcp_oob_send(tcp_server, con_id, data + 1, data + 1 + CRYPTO_PUBLIC_KEY_SIZE,
length - (1 + CRYPTO_PUBLIC_KEY_SIZE)); length - (1 + CRYPTO_PUBLIC_KEY_SIZE));
} }
case TCP_PACKET_ONION_REQUEST: { case TCP_PACKET_ONION_REQUEST: {
LOGGER_TRACE(tcp_server->logger, "handling onion request for %d", con_id); LOGGER_TRACE(tcp_server->logger, "handling onion request for %u", con_id);
if (tcp_server->onion != nullptr) { if (tcp_server->onion != nullptr) {
if (length <= 1 + CRYPTO_NONCE_SIZE + ONION_SEND_BASE * 2) { if (length <= 1 + CRYPTO_NONCE_SIZE + ONION_SEND_BASE * 2) {
@@ -778,7 +757,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
} }
case TCP_PACKET_ONION_RESPONSE: { case TCP_PACKET_ONION_RESPONSE: {
LOGGER_TRACE(tcp_server->logger, "handling onion response for %d", con_id); LOGGER_TRACE(tcp_server->logger, "handling onion response for %u", con_id);
return -1; return -1;
} }
@@ -821,7 +800,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
} }
const uint8_t c_id = data[0] - NUM_RESERVED_PORTS; const uint8_t c_id = data[0] - NUM_RESERVED_PORTS;
LOGGER_TRACE(tcp_server->logger, "handling packet id %d for %d", c_id, con_id); LOGGER_TRACE(tcp_server->logger, "handling packet id %u for %u", c_id, con_id);
if (c_id >= NUM_CLIENT_CONNECTIONS) { if (c_id >= NUM_CLIENT_CONNECTIONS) {
return -1; return -1;
@@ -854,9 +833,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
return 0; return 0;
} }
non_null() static int confirm_tcp_connection(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time, TCP_Secure_Connection *_Nonnull con, const uint8_t *_Nonnull data, uint16_t length)
static int confirm_tcp_connection(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_Secure_Connection *con,
const uint8_t *data, uint16_t length)
{ {
const int index = add_accepted(tcp_server, mono_time, con); const int index = add_accepted(tcp_server, mono_time, con);
@@ -882,8 +859,7 @@ static int confirm_tcp_connection(TCP_Server *tcp_server, const Mono_Time *mono_
* @return index on success * @return index on success
* @retval -1 on failure * @retval -1 on failure
*/ */
non_null() static int accept_connection(TCP_Server *_Nonnull tcp_server, Socket sock)
static int accept_connection(TCP_Server *tcp_server, Socket sock)
{ {
if (!sock_valid(sock)) { if (!sock_valid(sock)) {
return -1; return -1;
@@ -919,8 +895,7 @@ static int accept_connection(TCP_Server *tcp_server, Socket sock)
return index; return index;
} }
non_null() static Socket new_listening_tcp_socket(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Network *_Nonnull ns, Family family, uint16_t port)
static Socket new_listening_tcp_socket(const Logger *logger, const Memory *mem, const Network *ns, Family family, uint16_t port)
{ {
const Socket sock = net_socket(ns, family, TOX_SOCK_STREAM, TOX_PROTO_TCP); const Socket sock = net_socket(ns, family, TOX_SOCK_STREAM, TOX_PROTO_TCP);
@@ -1062,8 +1037,7 @@ TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random
} }
#ifndef TCP_SERVER_USE_EPOLL #ifndef TCP_SERVER_USE_EPOLL
non_null() static void do_tcp_accept_new(TCP_Server *_Nonnull tcp_server)
static void do_tcp_accept_new(TCP_Server *tcp_server)
{ {
for (uint32_t sock_idx = 0; sock_idx < tcp_server->num_listening_socks; ++sock_idx) { for (uint32_t sock_idx = 0; sock_idx < tcp_server->num_listening_socks; ++sock_idx) {
@@ -1078,8 +1052,7 @@ static void do_tcp_accept_new(TCP_Server *tcp_server)
} }
#endif /* TCP_SERVER_USE_EPOLL */ #endif /* TCP_SERVER_USE_EPOLL */
non_null() static int do_incoming(TCP_Server *_Nonnull tcp_server, uint32_t i)
static int do_incoming(TCP_Server *tcp_server, uint32_t i)
{ {
TCP_Secure_Connection *const conn = &tcp_server->incoming_connection_queue[i]; TCP_Secure_Connection *const conn = &tcp_server->incoming_connection_queue[i];
@@ -1087,12 +1060,12 @@ static int do_incoming(TCP_Server *tcp_server, uint32_t i)
return -1; return -1;
} }
LOGGER_TRACE(tcp_server->logger, "handling incoming TCP connection %d", i); LOGGER_TRACE(tcp_server->logger, "handling incoming TCP connection %u", i);
const int ret = read_connection_handshake(tcp_server->logger, conn, tcp_server->secret_key); const int ret = read_connection_handshake(tcp_server->logger, conn, tcp_server->secret_key);
if (ret == -1) { if (ret == -1) {
LOGGER_TRACE(tcp_server->logger, "incoming connection %d dropped due to failed handshake", i); LOGGER_TRACE(tcp_server->logger, "incoming connection %u dropped due to failed handshake", i);
kill_tcp_secure_connection(conn); kill_tcp_secure_connection(conn);
return -1; return -1;
} }
@@ -1106,7 +1079,7 @@ static int do_incoming(TCP_Server *tcp_server, uint32_t i)
TCP_Secure_Connection *conn_new = &tcp_server->unconfirmed_connection_queue[index_new]; TCP_Secure_Connection *conn_new = &tcp_server->unconfirmed_connection_queue[index_new];
if (conn_new->status != TCP_STATUS_NO_STATUS) { if (conn_new->status != TCP_STATUS_NO_STATUS) {
LOGGER_ERROR(tcp_server->logger, "incoming connection %d would overwrite existing", i); LOGGER_ERROR(tcp_server->logger, "incoming connection %u would overwrite existing", i);
kill_tcp_secure_connection(conn_new); kill_tcp_secure_connection(conn_new);
} }
@@ -1116,8 +1089,7 @@ static int do_incoming(TCP_Server *tcp_server, uint32_t i)
return index_new; return index_new;
} }
non_null() static int do_unconfirmed(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time, uint32_t i)
static int do_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time, uint32_t i)
{ {
TCP_Secure_Connection *const conn = &tcp_server->unconfirmed_connection_queue[i]; TCP_Secure_Connection *const conn = &tcp_server->unconfirmed_connection_queue[i];
@@ -1125,7 +1097,7 @@ static int do_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time, ui
return -1; return -1;
} }
LOGGER_TRACE(tcp_server->logger, "handling unconfirmed TCP connection %d", i); LOGGER_TRACE(tcp_server->logger, "handling unconfirmed TCP connection %u", i);
uint8_t packet[MAX_PACKET_SIZE]; uint8_t packet[MAX_PACKET_SIZE];
const int len = read_packet_tcp_secure_connection(tcp_server->logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, const int len = read_packet_tcp_secure_connection(tcp_server->logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet,
@@ -1143,15 +1115,14 @@ static int do_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time, ui
return confirm_tcp_connection(tcp_server, mono_time, conn, packet, len); return confirm_tcp_connection(tcp_server, mono_time, conn, packet, len);
} }
non_null() static bool tcp_process_secure_packet(TCP_Server *_Nonnull tcp_server, uint32_t i)
static bool tcp_process_secure_packet(TCP_Server *tcp_server, uint32_t i)
{ {
TCP_Secure_Connection *const conn = &tcp_server->accepted_connection_array[i]; TCP_Secure_Connection *const conn = &tcp_server->accepted_connection_array[i];
uint8_t packet[MAX_PACKET_SIZE]; uint8_t packet[MAX_PACKET_SIZE];
const int len = read_packet_tcp_secure_connection(tcp_server->logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, const int len = read_packet_tcp_secure_connection(tcp_server->logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet,
sizeof(packet), &conn->con.ip_port); sizeof(packet), &conn->con.ip_port);
LOGGER_TRACE(tcp_server->logger, "processing packet for %d: %d", i, len); LOGGER_TRACE(tcp_server->logger, "processing packet for %u: %d", i, len);
if (len == 0) { if (len == 0) {
return false; return false;
@@ -1163,7 +1134,7 @@ static bool tcp_process_secure_packet(TCP_Server *tcp_server, uint32_t i)
} }
if (handle_tcp_packet(tcp_server, i, packet, len) == -1) { if (handle_tcp_packet(tcp_server, i, packet, len) == -1) {
LOGGER_TRACE(tcp_server->logger, "dropping connection %d: data packet (len=%d) not handled", i, len); LOGGER_TRACE(tcp_server->logger, "dropping connection %u: data packet (len=%d) not handled", i, len);
kill_accepted(tcp_server, i); kill_accepted(tcp_server, i);
return false; return false;
} }
@@ -1171,8 +1142,7 @@ static bool tcp_process_secure_packet(TCP_Server *tcp_server, uint32_t i)
return true; return true;
} }
non_null() static void do_confirmed_recv(TCP_Server *_Nonnull tcp_server, uint32_t i)
static void do_confirmed_recv(TCP_Server *tcp_server, uint32_t i)
{ {
while (tcp_process_secure_packet(tcp_server, i)) { while (tcp_process_secure_packet(tcp_server, i)) {
/* Keep reading until an error occurs or there is no more data to read. */ /* Keep reading until an error occurs or there is no more data to read. */
@@ -1180,16 +1150,14 @@ static void do_confirmed_recv(TCP_Server *tcp_server, uint32_t i)
} }
#ifndef TCP_SERVER_USE_EPOLL #ifndef TCP_SERVER_USE_EPOLL
non_null() static void do_tcp_incoming(TCP_Server *_Nonnull tcp_server)
static void do_tcp_incoming(TCP_Server *tcp_server)
{ {
for (uint32_t i = 0; i < MAX_INCOMING_CONNECTIONS; ++i) { for (uint32_t i = 0; i < MAX_INCOMING_CONNECTIONS; ++i) {
do_incoming(tcp_server, i); do_incoming(tcp_server, i);
} }
} }
non_null() static void do_tcp_unconfirmed(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time)
static void do_tcp_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
{ {
for (uint32_t i = 0; i < MAX_INCOMING_CONNECTIONS; ++i) { for (uint32_t i = 0; i < MAX_INCOMING_CONNECTIONS; ++i) {
do_unconfirmed(tcp_server, mono_time, i); do_unconfirmed(tcp_server, mono_time, i);
@@ -1197,8 +1165,7 @@ static void do_tcp_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_tim
} }
#endif /* TCP_SERVER_USE_EPOLL */ #endif /* TCP_SERVER_USE_EPOLL */
non_null() static void do_tcp_confirmed(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time)
static void do_tcp_confirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
{ {
#ifdef TCP_SERVER_USE_EPOLL #ifdef TCP_SERVER_USE_EPOLL
@@ -1255,8 +1222,7 @@ static void do_tcp_confirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
} }
#ifdef TCP_SERVER_USE_EPOLL #ifdef TCP_SERVER_USE_EPOLL
non_null() static bool tcp_epoll_process(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time)
static bool tcp_epoll_process(TCP_Server *tcp_server, const Mono_Time *mono_time)
{ {
#define MAX_EVENTS 16 #define MAX_EVENTS 16
struct epoll_event events[MAX_EVENTS]; struct epoll_event events[MAX_EVENTS];
@@ -1381,8 +1347,7 @@ static bool tcp_epoll_process(TCP_Server *tcp_server, const Mono_Time *mono_time
return nfds > 0; return nfds > 0;
} }
non_null() static void do_tcp_epoll(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time)
static void do_tcp_epoll(TCP_Server *tcp_server, const Mono_Time *mono_time)
{ {
while (tcp_epoll_process(tcp_server, mono_time)) { while (tcp_epoll_process(tcp_server, mono_time)) {
// Keep processing packets until there are no more FDs ready for reading. // Keep processing packets until there are no more FDs ready for reading.

View File

@@ -34,30 +34,21 @@ typedef enum TCP_Status {
typedef struct TCP_Server TCP_Server; typedef struct TCP_Server TCP_Server;
non_null() const uint8_t *_Nonnull tcp_server_public_key(const TCP_Server *_Nonnull tcp_server);
const uint8_t *tcp_server_public_key(const TCP_Server *tcp_server); size_t tcp_server_listen_count(const TCP_Server *_Nonnull tcp_server);
non_null()
size_t tcp_server_listen_count(const TCP_Server *tcp_server);
/** Create new TCP server instance. */ /** Create new TCP server instance. */
non_null(1, 2, 3, 4, 7, 8) nullable(9, 10) TCP_Server *_Nullable new_tcp_server(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Network *_Nonnull ns,
TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random *rng, const Network *ns, bool ipv6_enabled, uint16_t num_sockets, const uint16_t *_Nonnull ports,
bool ipv6_enabled, uint16_t num_sockets, const uint16_t *ports, const uint8_t *_Nonnull secret_key, Onion *_Nullable onion, Forwarding *_Nullable forwarding);
const uint8_t *secret_key, Onion *onion, Forwarding *forwarding);
/** Run the TCP_server */ /** Run the TCP_server */
non_null() void do_tcp_server(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time);
void do_tcp_server(TCP_Server *tcp_server, const Mono_Time *mono_time);
/** Kill the TCP server */ /** Kill the TCP server */
nullable(1) void kill_tcp_server(TCP_Server *_Nullable tcp_server);
void kill_tcp_server(TCP_Server *tcp_server);
/** @brief Returns a pointer to the net profile associated with `tcp_server`. /** @brief Returns a pointer to the net profile associated with `tcp_server`.
* *
* Returns null if `tcp_server` is null. * Returns null if `tcp_server` is null.
*/ */
nullable(1) const Net_Profile *_Nullable tcp_server_get_net_profile(const TCP_Server *_Nullable tcp_server);
const Net_Profile *tcp_server_get_net_profile(const TCP_Server *tcp_server);
#endif /* C_TOXCORE_TOXCORE_TCP_SERVER_H */ #endif /* C_TOXCORE_TOXCORE_TCP_SERVER_H */

View File

@@ -85,21 +85,18 @@ void announce_set_synch_offset(Announcements *announce, int32_t synch_offset)
* An entry is considered to be "deleted" for the purposes of the protocol * An entry is considered to be "deleted" for the purposes of the protocol
* once it has timed out. * once it has timed out.
*/ */
non_null() static bool entry_is_empty(const Announcements *_Nonnull announce, const Announce_Entry *_Nonnull entry)
static bool entry_is_empty(const Announcements *announce, const Announce_Entry *entry)
{ {
return mono_time_get(announce->mono_time) >= entry->store_until; return mono_time_get(announce->mono_time) >= entry->store_until;
} }
non_null() static void delete_entry(Announce_Entry *_Nonnull entry)
static void delete_entry(Announce_Entry *entry)
{ {
entry->store_until = 0; entry->store_until = 0;
} }
/** Return bits (at most 8) from pk starting at index as uint8_t */ /** Return bits (at most 8) from pk starting at index as uint8_t */
non_null() static uint8_t truncate_pk_at_index(const uint8_t *_Nonnull pk, uint16_t index, uint16_t bits)
static uint8_t truncate_pk_at_index(const uint8_t *pk, uint16_t index, uint16_t bits)
{ {
assert(bits < 8); assert(bits < 8);
const uint8_t i = index / 8; const uint8_t i = index / 8;
@@ -116,14 +113,12 @@ uint16_t announce_get_bucketnum(const uint8_t *base, const uint8_t *pk)
truncate_pk_at_index(pk, index + 1, ANNOUNCE_BUCKET_PREFIX_LENGTH); truncate_pk_at_index(pk, index + 1, ANNOUNCE_BUCKET_PREFIX_LENGTH);
} }
non_null() static Announce_Entry *bucket_of_key(Announcements *_Nonnull announce, const uint8_t *_Nonnull pk)
static Announce_Entry *bucket_of_key(Announcements *announce, const uint8_t *pk)
{ {
return &announce->entries[announce_get_bucketnum(announce->public_key, pk) * ANNOUNCE_BUCKET_SIZE]; return &announce->entries[announce_get_bucketnum(announce->public_key, pk) * ANNOUNCE_BUCKET_SIZE];
} }
non_null() static Announce_Entry *get_stored(Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key)
static Announce_Entry *get_stored(Announcements *announce, const uint8_t *data_public_key)
{ {
Announce_Entry *const bucket = bucket_of_key(announce, data_public_key); Announce_Entry *const bucket = bucket_of_key(announce, data_public_key);
@@ -140,14 +135,12 @@ static Announce_Entry *get_stored(Announcements *announce, const uint8_t *data_p
return nullptr; return nullptr;
} }
non_null() static const Announce_Entry *bucket_of_key_const(const Announcements *_Nonnull announce, const uint8_t *_Nonnull pk)
static const Announce_Entry *bucket_of_key_const(const Announcements *announce, const uint8_t *pk)
{ {
return &announce->entries[announce_get_bucketnum(announce->public_key, pk) * ANNOUNCE_BUCKET_SIZE]; return &announce->entries[announce_get_bucketnum(announce->public_key, pk) * ANNOUNCE_BUCKET_SIZE];
} }
non_null() static const Announce_Entry *get_stored_const(const Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key)
static const Announce_Entry *get_stored_const(const Announcements *announce, const uint8_t *data_public_key)
{ {
const Announce_Entry *const bucket = bucket_of_key_const(announce, data_public_key); const Announce_Entry *const bucket = bucket_of_key_const(announce, data_public_key);
@@ -186,8 +179,7 @@ bool announce_on_stored(const Announcements *announce, const uint8_t *data_publi
* of greatest 2-adic distance greater than that of the key bucket if one * of greatest 2-adic distance greater than that of the key bucket if one
* exists, else nullptr. * exists, else nullptr.
*/ */
non_null() static Announce_Entry *find_entry_slot(Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key)
static Announce_Entry *find_entry_slot(Announcements *announce, const uint8_t *data_public_key)
{ {
Announce_Entry *const bucket = bucket_of_key(announce, data_public_key); Announce_Entry *const bucket = bucket_of_key(announce, data_public_key);
@@ -216,8 +208,7 @@ static Announce_Entry *find_entry_slot(Announcements *announce, const uint8_t *d
return slot; return slot;
} }
non_null() static bool would_accept_store_request(Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key)
static bool would_accept_store_request(Announcements *announce, const uint8_t *data_public_key)
{ {
return find_entry_slot(announce, data_public_key) != nullptr; return find_entry_slot(announce, data_public_key) != nullptr;
} }
@@ -258,8 +249,7 @@ bool announce_store_data(Announcements *announce, const uint8_t *data_public_key
return true; return true;
} }
non_null() static uint32_t calculate_timeout(const Announcements *_Nonnull announce, uint32_t requested_timeout)
static uint32_t calculate_timeout(const Announcements *announce, uint32_t requested_timeout)
{ {
const uint64_t uptime = mono_time_get(announce->mono_time) - announce->start_time; const uint64_t uptime = mono_time_get(announce->mono_time) - announce->start_time;
const uint32_t max_announcement_timeout = max_u32( const uint32_t max_announcement_timeout = max_u32(
@@ -273,11 +263,10 @@ static uint32_t calculate_timeout(const Announcements *announce, uint32_t reques
#define DATA_SEARCH_TO_AUTH_MAX_SIZE (CRYPTO_PUBLIC_KEY_SIZE * 2 + MAX_PACKED_IPPORT_SIZE + MAX_SENDBACK_SIZE) #define DATA_SEARCH_TO_AUTH_MAX_SIZE (CRYPTO_PUBLIC_KEY_SIZE * 2 + MAX_PACKED_IPPORT_SIZE + MAX_SENDBACK_SIZE)
non_null(1, 2, 3, 4, 7) nullable(5) static int create_data_search_to_auth(const Logger *_Nonnull logger, const uint8_t *_Nonnull data_public_key,
static int create_data_search_to_auth(const Logger *logger, const uint8_t *data_public_key, const uint8_t *_Nonnull requester_key,
const uint8_t *requester_key, const IP_Port *_Nonnull source, const uint8_t *_Nullable sendback, uint16_t sendback_length,
const IP_Port *source, const uint8_t *sendback, uint16_t sendback_length, uint8_t *_Nonnull dest, uint16_t max_length)
uint8_t *dest, uint16_t max_length)
{ {
if (max_length < DATA_SEARCH_TO_AUTH_MAX_SIZE if (max_length < DATA_SEARCH_TO_AUTH_MAX_SIZE
|| sendback_length > MAX_SENDBACK_SIZE) { || sendback_length > MAX_SENDBACK_SIZE) {
@@ -303,12 +292,8 @@ static int create_data_search_to_auth(const Logger *logger, const uint8_t *data_
#define DATA_SEARCH_TIMEOUT 60 #define DATA_SEARCH_TIMEOUT 60
non_null() static int create_reply_plain_data_search_request(Announcements *_Nonnull announce, const IP_Port *_Nonnull source, const uint8_t *_Nonnull data, uint16_t length, uint8_t *_Nonnull reply,
static int create_reply_plain_data_search_request(Announcements *announce, uint16_t reply_max_length, const uint8_t *_Nonnull to_auth, uint16_t to_auth_length)
const IP_Port *source,
const uint8_t *data, uint16_t length,
uint8_t *reply, uint16_t reply_max_length,
const uint8_t *to_auth, uint16_t to_auth_length)
{ {
if (length != CRYPTO_PUBLIC_KEY_SIZE && if (length != CRYPTO_PUBLIC_KEY_SIZE &&
length != CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SHA256_SIZE) { length != CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SHA256_SIZE) {
@@ -382,13 +367,8 @@ static int create_reply_plain_data_search_request(Announcements *announce,
return reply_len; return reply_len;
} }
non_null() static int create_reply_plain_data_retrieve_request(const Announcements *_Nonnull announce, const IP_Port *_Nonnull source, const uint8_t *_Nonnull data, uint16_t length,
static int create_reply_plain_data_retrieve_request( uint8_t *_Nonnull reply, uint16_t reply_max_length, const uint8_t *_Nonnull to_auth, uint16_t to_auth_length)
const Announcements *announce,
const IP_Port *source,
const uint8_t *data, uint16_t length,
uint8_t *reply, uint16_t reply_max_length,
const uint8_t *to_auth, uint16_t to_auth_length)
{ {
if (length != CRYPTO_PUBLIC_KEY_SIZE + 1 + TIMED_AUTH_SIZE) { if (length != CRYPTO_PUBLIC_KEY_SIZE + 1 + TIMED_AUTH_SIZE) {
return -1; return -1;
@@ -425,12 +405,8 @@ static int create_reply_plain_data_retrieve_request(
return reply_len; return reply_len;
} }
non_null() static int create_reply_plain_store_announce_request(Announcements *_Nonnull announce, const IP_Port *_Nonnull source, const uint8_t *_Nonnull data, uint16_t length, uint8_t *_Nonnull reply,
static int create_reply_plain_store_announce_request(Announcements *announce, uint16_t reply_max_length, const uint8_t *_Nonnull to_auth, uint16_t to_auth_length)
const IP_Port *source,
const uint8_t *data, uint16_t length,
uint8_t *reply, uint16_t reply_max_length,
const uint8_t *to_auth, uint16_t to_auth_length)
{ {
const int plain_len = (int)length - (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE); const int plain_len = (int)length - (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE);
const int announcement_len = plain_len - (TIMED_AUTH_SIZE + sizeof(uint32_t) + 1); const int announcement_len = plain_len - (TIMED_AUTH_SIZE + sizeof(uint32_t) + 1);
@@ -513,12 +489,11 @@ static int create_reply_plain_store_announce_request(Announcements *announce,
return reply_len; return reply_len;
} }
non_null(1, 2, 3, 7, 9) nullable(5) static int create_reply_plain(Announcements *_Nonnull announce,
static int create_reply_plain(Announcements *announce, const uint8_t *_Nonnull requester_key, const IP_Port *_Nonnull source, uint8_t type,
const uint8_t *requester_key, const IP_Port *source, uint8_t type, const uint8_t *_Nullable sendback, uint16_t sendback_length,
const uint8_t *sendback, uint16_t sendback_length, const uint8_t *_Nonnull data, uint16_t length,
const uint8_t *data, uint16_t length, uint8_t *_Nonnull reply, uint16_t reply_max_length)
uint8_t *reply, uint16_t reply_max_length)
{ {
if (length < CRYPTO_PUBLIC_KEY_SIZE) { if (length < CRYPTO_PUBLIC_KEY_SIZE) {
return -1; return -1;
@@ -552,14 +527,12 @@ static int create_reply_plain(Announcements *announce,
} }
} }
non_null(1, 2, 5, 7) nullable(3) static int create_reply(Announcements *_Nonnull announce, const IP_Port *_Nonnull source,
static int create_reply(Announcements *announce, const IP_Port *source, const uint8_t *_Nullable sendback, uint16_t sendback_length,
const uint8_t *sendback, uint16_t sendback_length, const uint8_t *_Nonnull data, uint16_t length,
const uint8_t *data, uint16_t length, uint8_t *_Nonnull reply, uint16_t reply_max_length)
uint8_t *reply, uint16_t reply_max_length)
{ {
const int plain_len = (int)length - (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE); const int plain_len = (int)length - (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE);
if (plain_len < (int)sizeof(uint64_t)) { if (plain_len < (int)sizeof(uint64_t)) {
return -1; return -1;
} }
@@ -605,13 +578,11 @@ static int create_reply(Announcements *announce, const IP_Port *source,
response_type, plain_reply, plain_reply_len, reply, reply_max_length); response_type, plain_reply, plain_reply_len, reply, reply_max_length);
} }
non_null(1, 2, 3, 5) nullable(7) static void forwarded_request_callback(void *_Nonnull object, const IP_Port *_Nonnull forwarder,
static void forwarded_request_callback(void *object, const IP_Port *forwarder, const uint8_t *_Nonnull sendback, uint16_t sendback_length,
const uint8_t *sendback, uint16_t sendback_length, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata)
const uint8_t *data, uint16_t length, void *userdata)
{ {
Announcements *announce = (Announcements *) object; Announcements *announce = (Announcements *) object;
uint8_t reply[MAX_FORWARD_DATA_SIZE]; uint8_t reply[MAX_FORWARD_DATA_SIZE];
const int len = create_reply(announce, forwarder, const int len = create_reply(announce, forwarder,
@@ -625,12 +596,10 @@ static void forwarded_request_callback(void *object, const IP_Port *forwarder,
forward_reply(announce->net, forwarder, sendback, sendback_length, reply, len); forward_reply(announce->net, forwarder, sendback, sendback_length, reply, len);
} }
non_null(1, 2, 3) nullable(5)
static int handle_dht_announce_request( static int handle_dht_announce_request(
void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata) void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length, void *_Nullable userdata)
{ {
Announcements *announce = (Announcements *)object; Announcements *announce = (Announcements *)object;
uint8_t reply[MAX_FORWARD_DATA_SIZE]; uint8_t reply[MAX_FORWARD_DATA_SIZE];
const int len const int len

View File

@@ -16,45 +16,35 @@
#define MAX_ANNOUNCEMENT_SIZE 512 #define MAX_ANNOUNCEMENT_SIZE 512
typedef void announce_on_retrieve_cb(void *object, const uint8_t *data, uint16_t length); typedef void announce_on_retrieve_cb(void *_Nullable object, const uint8_t *_Nullable data, uint16_t length);
uint8_t announce_response_of_request_type(uint8_t request_type); uint8_t announce_response_of_request_type(uint8_t request_type);
typedef struct Announcements Announcements; typedef struct Announcements Announcements;
non_null() Announcements *_Nullable new_announcements(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Mono_Time *_Nonnull mono_time, Forwarding *_Nonnull forwarding);
Announcements *new_announcements(const Logger *log, const Memory *mem, const Random *rng, const Mono_Time *mono_time,
Forwarding *forwarding);
/** /**
* @brief If data is stored, run `on_retrieve_callback` on it. * @brief If data is stored, run `on_retrieve_callback` on it.
* *
* @return true if data is stored, false otherwise. * @return true if data is stored, false otherwise.
*/ */
non_null(1, 2) nullable(3, 4) bool announce_on_stored(const Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key,
bool announce_on_stored(const Announcements *announce, const uint8_t *data_public_key, announce_on_retrieve_cb *_Nullable on_retrieve_callback, void *_Nullable object);
announce_on_retrieve_cb *on_retrieve_callback, void *object); void announce_set_synch_offset(Announcements *_Nonnull announce, int32_t synch_offset);
non_null()
void announce_set_synch_offset(Announcements *announce, int32_t synch_offset);
nullable(1)
void kill_announcements(Announcements *announce);
void kill_announcements(Announcements *_Nullable announce);
/* The declarations below are not public, they are exposed only for tests. */ /* The declarations below are not public, they are exposed only for tests. */
/** @private /** @private
* Return xor of first ANNOUNCE_BUCKET_PREFIX_LENGTH bits from one bit after * Return xor of first ANNOUNCE_BUCKET_PREFIX_LENGTH bits from one bit after
* base and pk first differ * base and pk first differ
*/ */
non_null() uint16_t announce_get_bucketnum(const uint8_t *_Nonnull base, const uint8_t *_Nonnull pk);
uint16_t announce_get_bucketnum(const uint8_t *base, const uint8_t *pk);
/** @private */ /** @private */
non_null(1, 2) nullable(3) bool announce_store_data(Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key,
bool announce_store_data(Announcements *announce, const uint8_t *data_public_key, const uint8_t *_Nullable data, uint32_t length, uint32_t timeout);
const uint8_t *data, uint32_t length, uint32_t timeout);
/** @private */ /** @private */
#define MAX_MAX_ANNOUNCEMENT_TIMEOUT 900 #define MAX_MAX_ANNOUNCEMENT_TIMEOUT 900
#define MIN_MAX_ANNOUNCEMENT_TIMEOUT 10 #define MIN_MAX_ANNOUNCEMENT_TIMEOUT 10

View File

@@ -18,14 +18,11 @@
#define GNU_PRINTF(f, a) #define GNU_PRINTF(f, a)
#endif #endif
#if defined(__GNUC__) && defined(_DEBUG) #ifndef __clang__
#define non_null(...) __attribute__((__nonnull__(__VA_ARGS__))) #define _Nonnull
#else #define _Nullable
#define non_null(...)
#endif #endif
#define nullable(...)
#ifdef SPARSE #ifdef SPARSE
#define bitwise __attribute__((bitwise)) #define bitwise __attribute__((bitwise))
#define force __attribute__((force)) #define force __attribute__((force))

View File

@@ -19,22 +19,19 @@ struct Bin_Pack {
cmp_ctx_t ctx; cmp_ctx_t ctx;
}; };
non_null() static bool null_reader(cmp_ctx_t *_Nonnull ctx, void *_Nonnull data, size_t limit)
static bool null_reader(cmp_ctx_t *ctx, void *data, size_t limit)
{ {
assert(limit == 0); assert(limit == 0);
return false; return false;
} }
non_null() static bool null_skipper(cmp_ctx_t *_Nonnull ctx, size_t count)
static bool null_skipper(cmp_ctx_t *ctx, size_t count)
{ {
assert(count == 0); assert(count == 0);
return false; return false;
} }
non_null() static size_t buf_writer(cmp_ctx_t *_Nonnull ctx, const void *_Nonnull data, size_t count)
static size_t buf_writer(cmp_ctx_t *ctx, const void *data, size_t count)
{ {
const uint8_t *bytes = (const uint8_t *)data; const uint8_t *bytes = (const uint8_t *)data;
Bin_Pack *bp = (Bin_Pack *)ctx->buf; Bin_Pack *bp = (Bin_Pack *)ctx->buf;
@@ -55,8 +52,7 @@ static size_t buf_writer(cmp_ctx_t *ctx, const void *data, size_t count)
return count; return count;
} }
non_null(1) nullable(2) static void bin_pack_init(Bin_Pack *_Nonnull bp, uint8_t *_Nullable buf, uint32_t buf_size)
static void bin_pack_init(Bin_Pack *bp, uint8_t *buf, uint32_t buf_size)
{ {
bp->bytes = buf; bp->bytes = buf;
bp->bytes_size = buf_size; bp->bytes_size = buf_size;

View File

@@ -44,7 +44,7 @@ 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(const void *obj, const Logger *logger, Bin_Pack *bp); typedef bool bin_pack_cb(const void *_Nullable obj, const Logger *_Nullable logger, Bin_Pack *_Nonnull bp);
/** @brief Function used to pack an array of objects. /** @brief Function used to pack an array of objects.
* *
@@ -54,7 +54,7 @@ typedef bool bin_pack_cb(const void *obj, const Logger *logger, Bin_Pack *bp);
* @param arr is the object array as void pointer. * @param arr is the object array as void pointer.
* @param index is the index in the object array that is currently being packed. * @param index is the index in the object array that is currently being packed.
*/ */
typedef bool bin_pack_array_cb(const void *arr, uint32_t index, const Logger *logger, Bin_Pack *bp); typedef bool bin_pack_array_cb(const void *_Nullable arr, uint32_t index, const Logger *_Nullable logger, Bin_Pack *_Nonnull bp);
/** @brief Determine the serialised size of an object. /** @brief Determine the serialised size of an object.
* *
@@ -65,9 +65,7 @@ typedef bool bin_pack_array_cb(const void *arr, uint32_t index, const Logger *lo
* @return The packed size of the passed object according to the callback. * @return The packed size of the passed object according to the callback.
* @retval UINT32_MAX in case of errors such as buffer overflow. * @retval UINT32_MAX in case of errors such as buffer overflow.
*/ */
non_null(1) nullable(2, 3) uint32_t bin_pack_obj_size(bin_pack_cb *_Nonnull callback, const void *_Nullable obj, const Logger *_Nullable logger);
uint32_t bin_pack_obj_size(bin_pack_cb *callback, const void *obj, const Logger *logger);
/** @brief Pack an object into a buffer of a given size. /** @brief Pack an object into a buffer of a given size.
* *
* This function creates and initialises a `Bin_Pack` packer object, calls the callback with the * This function creates and initialises a `Bin_Pack` packer object, calls the callback with the
@@ -88,9 +86,7 @@ uint32_t bin_pack_obj_size(bin_pack_cb *callback, const void *obj, const Logger
* *
* @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 *_Nonnull callback, const void *_Nullable obj, const Logger *_Nullable logger, uint8_t *_Nonnull buf, uint32_t buf_size);
bool bin_pack_obj(bin_pack_cb *callback, const void *obj, const Logger *logger, uint8_t *buf, uint32_t buf_size);
/** @brief Determine the serialised size of an object array. /** @brief Determine the serialised size of an object array.
* *
* Behaves exactly like `bin_pack_obj_b_array` but doesn't write. * Behaves exactly like `bin_pack_obj_b_array` but doesn't write.
@@ -104,9 +100,7 @@ bool bin_pack_obj(bin_pack_cb *callback, const void *obj, const Logger *logger,
* @return The packed size of the passed object array according to the callback. * @return The packed size of the passed object array according to the callback.
* @retval UINT32_MAX in case of errors such as buffer overflow. * @retval UINT32_MAX in case of errors such as buffer overflow.
*/ */
non_null(1) nullable(2, 4) uint32_t bin_pack_obj_array_b_size(bin_pack_array_cb *_Nonnull callback, const void *_Nullable arr, uint32_t arr_size, const Logger *_Nullable logger);
uint32_t bin_pack_obj_array_b_size(bin_pack_array_cb *callback, const void *arr, uint32_t arr_size, const Logger *logger);
/** @brief Pack an object array into a buffer of a given size. /** @brief Pack an object array into a buffer of a given size.
* *
* Similar to `bin_pack_obj_array` but does not write the array length, so * Similar to `bin_pack_obj_array` but does not write the array length, so
@@ -124,9 +118,7 @@ uint32_t bin_pack_obj_array_b_size(bin_pack_array_cb *callback, const void *arr,
* *
* @retval false if an error occurred (e.g. buffer overflow). * @retval false if an error occurred (e.g. buffer overflow).
*/ */
non_null(1, 5) nullable(2, 4) bool bin_pack_obj_array_b(bin_pack_array_cb *_Nonnull callback, const void *_Nullable arr, uint32_t arr_size, const Logger *_Nullable logger, uint8_t *_Nonnull buf, uint32_t buf_size);
bool bin_pack_obj_array_b(bin_pack_array_cb *callback, const void *arr, uint32_t arr_size, const Logger *logger, uint8_t *buf, uint32_t buf_size);
/** @brief Encode an object array as MessagePack array into a bin packer. /** @brief Encode an object array as MessagePack array into a bin packer.
* *
* Calls the callback `arr_size` times with increasing `index` argument from 0 to * Calls the callback `arr_size` times with increasing `index` argument from 0 to
@@ -150,51 +142,48 @@ bool bin_pack_obj_array_b(bin_pack_array_cb *callback, const void *arr, uint32_t
* *
* @retval false if an error occurred (e.g. buffer overflow). * @retval false if an error occurred (e.g. buffer overflow).
*/ */
non_null(1, 2) nullable(3, 5) bool bin_pack_obj_array(Bin_Pack *_Nonnull bp, bin_pack_array_cb *_Nonnull callback, const void *_Nullable arr, uint32_t arr_size, const Logger *_Nullable logger);
bool bin_pack_obj_array(Bin_Pack *bp, bin_pack_array_cb *callback, const void *arr, uint32_t arr_size, const Logger *logger);
/** @brief Start packing a MessagePack array. /** @brief Start packing a MessagePack array.
* *
* A call to this function must be followed by exactly `size` calls to other functions below. * A call to this function must be followed by exactly `size` calls to other functions below.
*/ */
non_null() bool bin_pack_array(Bin_Pack *_Nonnull bp, uint32_t size);
bool bin_pack_array(Bin_Pack *bp, uint32_t size);
/** @brief Pack a MessagePack bool. */ /** @brief Pack a MessagePack bool. */
non_null() bool bin_pack_bool(Bin_Pack *bp, bool val); bool bin_pack_bool(Bin_Pack *_Nonnull bp, bool val);
/** @brief Pack a `uint8_t` as MessagePack positive integer. */ /** @brief Pack a `uint8_t` as MessagePack positive integer. */
non_null() bool bin_pack_u08(Bin_Pack *bp, uint8_t val); bool bin_pack_u08(Bin_Pack *_Nonnull bp, uint8_t val);
/** @brief Pack a `uint16_t` as MessagePack positive integer. */ /** @brief Pack a `uint16_t` as MessagePack positive integer. */
non_null() bool bin_pack_u16(Bin_Pack *bp, uint16_t val); bool bin_pack_u16(Bin_Pack *_Nonnull bp, uint16_t val);
/** @brief Pack a `uint32_t` as MessagePack positive integer. */ /** @brief Pack a `uint32_t` as MessagePack positive integer. */
non_null() bool bin_pack_u32(Bin_Pack *bp, uint32_t val); bool bin_pack_u32(Bin_Pack *_Nonnull bp, uint32_t val);
/** @brief Pack a `uint64_t` as MessagePack positive integer. */ /** @brief Pack a `uint64_t` as MessagePack positive integer. */
non_null() bool bin_pack_u64(Bin_Pack *bp, uint64_t val); bool bin_pack_u64(Bin_Pack *_Nonnull bp, uint64_t val);
/** @brief Pack an empty array member as a MessagePack nil value. */ /** @brief Pack an empty array member as a MessagePack nil value. */
non_null() bool bin_pack_nil(Bin_Pack *bp); bool bin_pack_nil(Bin_Pack *_Nonnull bp);
/** @brief Pack a byte array as MessagePack bin. */ /** @brief Pack a byte array as MessagePack bin. */
non_null() bool bin_pack_bin(Bin_Pack *bp, const uint8_t *data, uint32_t length); bool bin_pack_bin(Bin_Pack *_Nonnull bp, const uint8_t *_Nonnull data, uint32_t length);
/** @brief Start packing a custom binary representation. /** @brief Start packing a custom binary representation.
* *
* A call to this function must be followed by exactly `size` bytes packed by functions below. * A call to this function must be followed by exactly `size` bytes packed by functions below.
*/ */
non_null() bool bin_pack_bin_marker(Bin_Pack *bp, uint32_t size); bool bin_pack_bin_marker(Bin_Pack *_Nonnull bp, uint32_t size);
/** @brief Write a `uint8_t` directly to the packer in 1 byte. */ /** @brief Write a `uint8_t` directly to the packer in 1 byte. */
non_null() bool bin_pack_u08_b(Bin_Pack *bp, uint8_t val); bool bin_pack_u08_b(Bin_Pack *_Nonnull bp, uint8_t val);
/** @brief Write a `uint16_t` as big endian 16 bit int in 2 bytes. */ /** @brief Write a `uint16_t` as big endian 16 bit int in 2 bytes. */
non_null() bool bin_pack_u16_b(Bin_Pack *bp, uint16_t val); bool bin_pack_u16_b(Bin_Pack *_Nonnull bp, uint16_t val);
/** @brief Write a `uint32_t` as big endian 32 bit int in 4 bytes. */ /** @brief Write a `uint32_t` as big endian 32 bit int in 4 bytes. */
non_null() bool bin_pack_u32_b(Bin_Pack *bp, uint32_t val); bool bin_pack_u32_b(Bin_Pack *_Nonnull bp, uint32_t val);
/** @brief Write a `uint64_t` as big endian 64 bit int in 8 bytes. */ /** @brief Write a `uint64_t` as big endian 64 bit int in 8 bytes. */
non_null() bool bin_pack_u64_b(Bin_Pack *bp, uint64_t val); bool bin_pack_u64_b(Bin_Pack *_Nonnull bp, uint64_t val);
/** @brief Write a byte array directly to the packer in `length` bytes. /** @brief Write a byte array directly to the packer in `length` bytes.
* *
* Note that unless you prepend the array length manually, there is no record of it in the resulting * Note that unless you prepend the array length manually, there is no record of it in the resulting
* serialised representation. * serialised representation.
*/ */
non_null() bool bin_pack_bin_b(Bin_Pack *bp, const uint8_t *data, uint32_t length); bool bin_pack_bin_b(Bin_Pack *_Nonnull bp, const uint8_t *_Nonnull data, uint32_t length);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View File

@@ -20,8 +20,7 @@ struct Bin_Unpack {
cmp_ctx_t ctx; cmp_ctx_t ctx;
}; };
non_null() static bool buf_reader(cmp_ctx_t *_Nonnull ctx, void *_Nonnull data, size_t limit)
static bool buf_reader(cmp_ctx_t *ctx, void *data, size_t limit)
{ {
uint8_t *bytes = (uint8_t *)data; uint8_t *bytes = (uint8_t *)data;
Bin_Unpack *reader = (Bin_Unpack *)ctx->buf; Bin_Unpack *reader = (Bin_Unpack *)ctx->buf;
@@ -35,8 +34,7 @@ static bool buf_reader(cmp_ctx_t *ctx, void *data, size_t limit)
return true; return true;
} }
non_null() static bool buf_skipper(cmp_ctx_t *_Nonnull ctx, size_t count)
static bool buf_skipper(cmp_ctx_t *ctx, size_t count)
{ {
Bin_Unpack *reader = (Bin_Unpack *)ctx->buf; Bin_Unpack *reader = (Bin_Unpack *)ctx->buf;
assert(reader != nullptr && reader->bytes != nullptr); assert(reader != nullptr && reader->bytes != nullptr);
@@ -48,15 +46,13 @@ static bool buf_skipper(cmp_ctx_t *ctx, size_t count)
return true; return true;
} }
non_null() static size_t null_writer(cmp_ctx_t *_Nonnull ctx, const void *_Nonnull data, size_t count)
static size_t null_writer(cmp_ctx_t *ctx, const void *data, size_t count)
{ {
assert(count == 0); assert(count == 0);
return 0; return 0;
} }
non_null() static void bin_unpack_init(Bin_Unpack *_Nonnull bu, const Memory *_Nonnull mem, const uint8_t *_Nonnull buf, uint32_t buf_size)
static void bin_unpack_init(Bin_Unpack *bu, const Memory *mem, const uint8_t *buf, uint32_t buf_size)
{ {
bu->mem = mem; bu->mem = mem;
bu->bytes = buf; bu->bytes = buf;

View File

@@ -29,7 +29,7 @@ typedef struct Bin_Unpack Bin_Unpack;
* 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 unpacking functions. * more appropriately typed unpacking functions.
*/ */
typedef bool bin_unpack_cb(void *obj, Bin_Unpack *bu); typedef bool bin_unpack_cb(void *_Nonnull obj, Bin_Unpack *_Nonnull bu);
/** @brief Unpack an object from a buffer of a given size. /** @brief Unpack an object from a buffer of a given size.
* *
@@ -46,8 +46,7 @@ typedef bool bin_unpack_cb(void *obj, Bin_Unpack *bu);
* *
* @retval false if an error occurred (e.g. buffer overrun). * @retval false if an error occurred (e.g. buffer overrun).
*/ */
non_null() bool bin_unpack_obj(const Memory *_Nonnull mem, bin_unpack_cb *_Nonnull callback, void *_Nonnull obj, const uint8_t *_Nonnull buf, uint32_t buf_size);
bool bin_unpack_obj(const Memory *mem, bin_unpack_cb *callback, void *obj, const uint8_t *buf, uint32_t buf_size);
/** @brief Start unpacking a MessagePack array. /** @brief Start unpacking a MessagePack array.
* *
@@ -55,7 +54,7 @@ bool bin_unpack_obj(const Memory *mem, bin_unpack_cb *callback, void *obj, const
* *
* @param size Will contain the number of array elements following the array marker. * @param size Will contain the number of array elements following the array marker.
*/ */
non_null() bool bin_unpack_array(Bin_Unpack *bu, uint32_t *size); bool bin_unpack_array(Bin_Unpack *_Nonnull bu, uint32_t *_Nonnull size);
/** @brief Start unpacking a fixed size MessagePack array. /** @brief Start unpacking a fixed size MessagePack array.
* *
@@ -64,21 +63,19 @@ non_null() bool bin_unpack_array(Bin_Unpack *bu, uint32_t *size);
* *
* @retval false if the packed array size is not exactly the required size. * @retval false if the packed array size is not exactly the required size.
*/ */
non_null(1) nullable(3) bool bin_unpack_array_fixed(Bin_Unpack *_Nonnull bu, uint32_t required_size, uint32_t *_Nullable actual_size);
bool bin_unpack_array_fixed(Bin_Unpack *bu, uint32_t required_size, uint32_t *actual_size);
/** @brief Unpack a MessagePack bool. */ /** @brief Unpack a MessagePack bool. */
non_null() bool bin_unpack_bool(Bin_Unpack *bu, bool *val); bool bin_unpack_bool(Bin_Unpack *_Nonnull bu, bool *_Nonnull val);
/** @brief Unpack a MessagePack positive int into a `uint8_t`. */ /** @brief Unpack a MessagePack positive int into a `uint8_t`. */
non_null() bool bin_unpack_u08(Bin_Unpack *bu, uint8_t *val); bool bin_unpack_u08(Bin_Unpack *_Nonnull bu, uint8_t *_Nonnull val);
/** @brief Unpack a MessagePack positive int into a `uint16_t`. */ /** @brief Unpack a MessagePack positive int into a `uint16_t`. */
non_null() bool bin_unpack_u16(Bin_Unpack *bu, uint16_t *val); bool bin_unpack_u16(Bin_Unpack *_Nonnull bu, uint16_t *_Nonnull val);
/** @brief Unpack a MessagePack positive int into a `uint32_t`. */ /** @brief Unpack a MessagePack positive int into a `uint32_t`. */
non_null() bool bin_unpack_u32(Bin_Unpack *bu, uint32_t *val); bool bin_unpack_u32(Bin_Unpack *_Nonnull bu, uint32_t *_Nonnull val);
/** @brief Unpack a MessagePack positive int into a `uint64_t`. */ /** @brief Unpack a MessagePack positive int into a `uint64_t`. */
non_null() bool bin_unpack_u64(Bin_Unpack *bu, uint64_t *val); bool bin_unpack_u64(Bin_Unpack *_Nonnull bu, uint64_t *_Nonnull val);
/** @brief Unpack a Messagepack nil value. */ /** @brief Unpack a Messagepack nil value. */
non_null() bool bin_unpack_nil(Bin_Unpack *bu); bool bin_unpack_nil(Bin_Unpack *_Nonnull bu);
/** @brief Unpack a MessagePack bin into a newly allocated byte array. /** @brief Unpack a MessagePack bin into a newly allocated byte array.
* *
@@ -87,37 +84,37 @@ non_null() bool bin_unpack_nil(Bin_Unpack *bu);
* remaining to be unpacked as the bin claims to need, so it's not possible to cause an arbitrarily * remaining to be unpacked as the bin claims to need, so it's not possible to cause an arbitrarily
* large allocation unless the input array was already that large. * large allocation unless the input array was already that large.
*/ */
non_null() bool bin_unpack_bin(Bin_Unpack *bu, uint8_t **data_ptr, uint32_t *data_length_ptr); bool bin_unpack_bin(Bin_Unpack *_Nonnull bu, uint8_t *_Nonnull *_Nonnull data_ptr, uint32_t *_Nonnull data_length_ptr);
/** @brief Unpack a variable size MessagePack bin into a fixed size byte array. /** @brief Unpack a variable size MessagePack bin into a fixed size byte array.
* *
* Stores unpacked data into `data` with its length stored in `data_length_ptr`. This function does * Stores unpacked data into `data` with its length stored in `data_length_ptr`. This function does
* not allocate memory and requires that `max_data_length` is less than or equal to `sizeof(arr)` * not allocate memory and requires that `max_data_length` is less than or equal to `sizeof(arr)`
* when `arr` is passed as `data` pointer. * when `arr` is passed as `data` pointer.
*/ */
non_null() bool bin_unpack_bin_max(Bin_Unpack *bu, uint8_t *data, uint16_t *data_length_ptr, uint16_t max_data_length); bool bin_unpack_bin_max(Bin_Unpack *_Nonnull bu, uint8_t *_Nonnull data, uint16_t *_Nonnull data_length_ptr, uint16_t max_data_length);
/** @brief Unpack a MessagePack bin of a fixed length into a pre-allocated byte array. /** @brief Unpack a MessagePack bin of a fixed length into a pre-allocated byte array.
* *
* Similar to the function above, but doesn't output the data length. * Similar to the function above, but doesn't output the data length.
*/ */
non_null() bool bin_unpack_bin_fixed(Bin_Unpack *bu, uint8_t *data, uint32_t data_length); bool bin_unpack_bin_fixed(Bin_Unpack *_Nonnull bu, uint8_t *_Nonnull data, uint32_t data_length);
/** @brief Start unpacking a custom binary representation. /** @brief Start unpacking a custom binary representation.
* *
* A call to this function must be followed by exactly `size` bytes packed by functions below. * A call to this function must be followed by exactly `size` bytes packed by functions below.
*/ */
non_null() bool bin_unpack_bin_size(Bin_Unpack *bu, uint32_t *size); bool bin_unpack_bin_size(Bin_Unpack *_Nonnull bu, uint32_t *_Nonnull size);
/** @brief Read a `uint8_t` directly from the unpacker, consuming 1 byte. */ /** @brief Read a `uint8_t` directly from the unpacker, consuming 1 byte. */
non_null() bool bin_unpack_u08_b(Bin_Unpack *bu, uint8_t *val); bool bin_unpack_u08_b(Bin_Unpack *_Nonnull bu, uint8_t *_Nonnull val);
/** @brief Read a `uint16_t` as big endian 16 bit int, consuming 2 bytes. */ /** @brief Read a `uint16_t` as big endian 16 bit int, consuming 2 bytes. */
non_null() bool bin_unpack_u16_b(Bin_Unpack *bu, uint16_t *val); bool bin_unpack_u16_b(Bin_Unpack *_Nonnull bu, uint16_t *_Nonnull val);
/** @brief Read a `uint32_t` as big endian 32 bit int, consuming 4 bytes. */ /** @brief Read a `uint32_t` as big endian 32 bit int, consuming 4 bytes. */
non_null() bool bin_unpack_u32_b(Bin_Unpack *bu, uint32_t *val); bool bin_unpack_u32_b(Bin_Unpack *_Nonnull bu, uint32_t *_Nonnull val);
/** @brief Read a `uint64_t` as big endian 64 bit int, consuming 8 bytes. */ /** @brief Read a `uint64_t` as big endian 64 bit int, consuming 8 bytes. */
non_null() bool bin_unpack_u64_b(Bin_Unpack *bu, uint64_t *val); bool bin_unpack_u64_b(Bin_Unpack *_Nonnull bu, uint64_t *_Nonnull val);
/** @brief Read a byte array directly from the packer, consuming `length` bytes. */ /** @brief Read a byte array directly from the packer, consuming `length` bytes. */
non_null() bool bin_unpack_bin_b(Bin_Unpack *bu, uint8_t *data, uint32_t length); bool bin_unpack_bin_b(Bin_Unpack *_Nonnull bu, uint8_t *_Nonnull data, uint32_t length);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View File

@@ -88,8 +88,7 @@ const uint8_t *get_chat_id(const Extended_Public_Key *key)
} }
#if !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) #if !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
non_null() static uint8_t *crypto_malloc(const Memory *_Nonnull mem, size_t bytes)
static uint8_t *crypto_malloc(const Memory *mem, size_t bytes)
{ {
uint8_t *ptr = (uint8_t *)mem_balloc(mem, bytes); uint8_t *ptr = (uint8_t *)mem_balloc(mem, bytes);
@@ -100,8 +99,7 @@ static uint8_t *crypto_malloc(const Memory *mem, size_t bytes)
return ptr; return ptr;
} }
non_null(1) nullable(2) static void crypto_free(const Memory *_Nonnull mem, uint8_t *_Nullable ptr, size_t bytes)
static void crypto_free(const Memory *mem, uint8_t *ptr, size_t bytes)
{ {
if (ptr != nullptr) { if (ptr != nullptr) {
crypto_memzero(ptr, bytes); crypto_memzero(ptr, bytes);
@@ -495,14 +493,12 @@ void crypto_sha512(uint8_t hash[CRYPTO_SHA512_SIZE], const uint8_t *data, size_t
#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ #endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
} }
non_null() static void sys_random_bytes(void *_Nonnull obj, uint8_t *_Nonnull bytes, size_t length)
static void sys_random_bytes(void *obj, uint8_t *bytes, size_t length)
{ {
randombytes(bytes, length); randombytes(bytes, length);
} }
non_null() static uint32_t sys_random_uniform(void *_Nonnull obj, uint32_t upper_bound)
static uint32_t sys_random_uniform(void *obj, uint32_t upper_bound)
{ {
return randombytes_uniform(upper_bound); return randombytes_uniform(upper_bound);
} }

View File

@@ -84,19 +84,19 @@ extern "C" {
* secure pseudo-random number generator (CSPRNG). The security of Tox heavily * secure pseudo-random number generator (CSPRNG). The security of Tox heavily
* depends on the security of this RNG. * depends on the security of this RNG.
*/ */
typedef void crypto_random_bytes_cb(void *obj, uint8_t *bytes, size_t length); typedef void crypto_random_bytes_cb(void *_Nullable obj, uint8_t *_Nonnull bytes, size_t length);
/** @brief Generate a random integer between 0 and @p upper_bound. /** @brief Generate a random integer between 0 and @p upper_bound.
* *
* Should produce a uniform random distribution, but Tox security does not * Should produce a uniform random distribution, but Tox security does not
* depend on this being correct. In principle, it could even be a non-CSPRNG. * depend on this being correct. In principle, it could even be a non-CSPRNG.
*/ */
typedef uint32_t crypto_random_uniform_cb(void *obj, uint32_t upper_bound); typedef uint32_t crypto_random_uniform_cb(void *_Nullable obj, uint32_t upper_bound);
/** @brief Virtual function table for Random. */ /** @brief Virtual function table for Random. */
typedef struct Random_Funcs { typedef struct Random_Funcs {
crypto_random_bytes_cb *random_bytes; crypto_random_bytes_cb *_Nullable random_bytes;
crypto_random_uniform_cb *random_uniform; crypto_random_uniform_cb *_Nullable random_uniform;
} Random_Funcs; } Random_Funcs;
/** @brief Random number generator object. /** @brief Random number generator object.
@@ -106,15 +106,15 @@ typedef struct Random_Funcs {
* CSPRNG and use `os_random` below. * CSPRNG and use `os_random` below.
*/ */
typedef struct Random { typedef struct Random {
const Random_Funcs *funcs; const Random_Funcs *_Nullable funcs;
void *obj; void *_Nullable obj;
} Random; } Random;
/** @brief System random number generator. /** @brief System random number generator.
* *
* Uses libsodium's CSPRNG (on Linux, `/dev/urandom`). * Uses libsodium's CSPRNG (on Linux, `/dev/urandom`).
*/ */
const Random *os_random(void); const Random *_Nullable os_random(void);
/** /**
* @brief The number of bytes in an encryption public key used by DHT group chats. * @brief The number of bytes in an encryption public key used by DHT group chats.
@@ -168,24 +168,21 @@ const Random *os_random(void);
* will be no reads to the written data. Use this function if you want to be * will be no reads to the written data. Use this function if you want to be
* sure the memory is indeed zeroed. * sure the memory is indeed zeroed.
*/ */
non_null() void crypto_memzero(void *_Nonnull data, size_t length);
void crypto_memzero(void *data, size_t length);
/** /**
* @brief Compute a SHA256 hash (32 bytes). * @brief Compute a SHA256 hash (32 bytes).
* *
* @param[out] hash The SHA256 hash of @p data will be written to this byte array. * @param[out] hash The SHA256 hash of @p data will be written to this byte array.
*/ */
non_null() void crypto_sha256(uint8_t hash[_Nonnull CRYPTO_SHA256_SIZE], const uint8_t *_Nonnull data, size_t length);
void crypto_sha256(uint8_t hash[CRYPTO_SHA256_SIZE], const uint8_t *data, size_t length);
/** /**
* @brief Compute a SHA512 hash (64 bytes). * @brief Compute a SHA512 hash (64 bytes).
* *
* @param[out] hash The SHA512 hash of @p data will be written to this byte array. * @param[out] hash The SHA512 hash of @p data will be written to this byte array.
*/ */
non_null() void crypto_sha512(uint8_t hash[_Nonnull CRYPTO_SHA512_SIZE], const uint8_t *_Nonnull data, size_t length);
void crypto_sha512(uint8_t hash[CRYPTO_SHA512_SIZE], const uint8_t *data, size_t length);
/** /**
* @brief Compute an HMAC authenticator (32 bytes). * @brief Compute an HMAC authenticator (32 bytes).
@@ -193,16 +190,12 @@ void crypto_sha512(uint8_t hash[CRYPTO_SHA512_SIZE], const uint8_t *data, size_t
* @param[out] auth Resulting authenticator. * @param[out] auth Resulting authenticator.
* @param key Secret key, as generated by `new_hmac_key()`. * @param key Secret key, as generated by `new_hmac_key()`.
*/ */
non_null() void crypto_hmac(uint8_t auth[_Nonnull CRYPTO_HMAC_SIZE], const uint8_t key[_Nonnull CRYPTO_HMAC_KEY_SIZE], const uint8_t *_Nonnull data, size_t length);
void crypto_hmac(uint8_t auth[CRYPTO_HMAC_SIZE], const uint8_t key[CRYPTO_HMAC_KEY_SIZE],
const uint8_t *data, size_t length);
/** /**
* @brief Verify an HMAC authenticator. * @brief Verify an HMAC authenticator.
*/ */
non_null() bool crypto_hmac_verify(const uint8_t auth[_Nonnull CRYPTO_HMAC_SIZE], const uint8_t key[_Nonnull CRYPTO_HMAC_KEY_SIZE], const uint8_t *_Nonnull data, size_t length);
bool crypto_hmac_verify(const uint8_t auth[CRYPTO_HMAC_SIZE], const uint8_t key[CRYPTO_HMAC_KEY_SIZE],
const uint8_t *data, size_t length);
/** /**
* @brief Compare 2 public keys of length @ref CRYPTO_PUBLIC_KEY_SIZE, not vulnerable to * @brief Compare 2 public keys of length @ref CRYPTO_PUBLIC_KEY_SIZE, not vulnerable to
@@ -211,14 +204,12 @@ bool crypto_hmac_verify(const uint8_t auth[CRYPTO_HMAC_SIZE], const uint8_t key[
* @retval true if both mem locations of length are equal * @retval true if both mem locations of length are equal
* @retval false if they are not * @retval false if they are not
*/ */
non_null() bool pk_equal(const uint8_t pk1[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t pk2[_Nonnull CRYPTO_PUBLIC_KEY_SIZE]);
bool pk_equal(const uint8_t pk1[CRYPTO_PUBLIC_KEY_SIZE], const uint8_t pk2[CRYPTO_PUBLIC_KEY_SIZE]);
/** /**
* @brief Copy a public key from `src` to `dest`. * @brief Copy a public key from `src` to `dest`.
*/ */
non_null() void pk_copy(uint8_t dest[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t src[_Nonnull CRYPTO_PUBLIC_KEY_SIZE]);
void pk_copy(uint8_t dest[CRYPTO_PUBLIC_KEY_SIZE], const uint8_t src[CRYPTO_PUBLIC_KEY_SIZE]);
/** /**
* @brief Compare 2 SHA512 checksums of length CRYPTO_SHA512_SIZE, not vulnerable to * @brief Compare 2 SHA512 checksums of length CRYPTO_SHA512_SIZE, not vulnerable to
@@ -226,8 +217,7 @@ void pk_copy(uint8_t dest[CRYPTO_PUBLIC_KEY_SIZE], const uint8_t src[CRYPTO_PUBL
* *
* @return true if both mem locations of length are equal, false if they are not. * @return true if both mem locations of length are equal, false if they are not.
*/ */
non_null() bool crypto_sha512_eq(const uint8_t cksum1[_Nonnull CRYPTO_SHA512_SIZE], const uint8_t cksum2[_Nonnull CRYPTO_SHA512_SIZE]);
bool crypto_sha512_eq(const uint8_t cksum1[CRYPTO_SHA512_SIZE], const uint8_t cksum2[CRYPTO_SHA512_SIZE]);
/** /**
* @brief Compare 2 SHA256 checksums of length CRYPTO_SHA256_SIZE, not vulnerable to * @brief Compare 2 SHA256 checksums of length CRYPTO_SHA256_SIZE, not vulnerable to
@@ -235,40 +225,34 @@ bool crypto_sha512_eq(const uint8_t cksum1[CRYPTO_SHA512_SIZE], const uint8_t ck
* *
* @return true if both mem locations of length are equal, false if they are not. * @return true if both mem locations of length are equal, false if they are not.
*/ */
non_null() bool crypto_sha256_eq(const uint8_t cksum1[_Nonnull CRYPTO_SHA256_SIZE], const uint8_t cksum2[_Nonnull CRYPTO_SHA256_SIZE]);
bool crypto_sha256_eq(const uint8_t cksum1[CRYPTO_SHA256_SIZE], const uint8_t cksum2[CRYPTO_SHA256_SIZE]);
/** /**
* @brief Return a random 8 bit integer. * @brief Return a random 8 bit integer.
*/ */
non_null() uint8_t random_u08(const Random *_Nonnull rng);
uint8_t random_u08(const Random *rng);
/** /**
* @brief Return a random 16 bit integer. * @brief Return a random 16 bit integer.
*/ */
non_null() uint16_t random_u16(const Random *_Nonnull rng);
uint16_t random_u16(const Random *rng);
/** /**
* @brief Return a random 32 bit integer. * @brief Return a random 32 bit integer.
*/ */
non_null() uint32_t random_u32(const Random *_Nonnull rng);
uint32_t random_u32(const Random *rng);
/** /**
* @brief Return a random 64 bit integer. * @brief Return a random 64 bit integer.
*/ */
non_null() uint64_t random_u64(const Random *_Nonnull rng);
uint64_t random_u64(const Random *rng);
/** /**
* @brief Return a random 32 bit integer between 0 and upper_bound (excluded). * @brief Return a random 32 bit integer between 0 and upper_bound (excluded).
* *
* This function guarantees a uniform distribution of possible outputs. * This function guarantees a uniform distribution of possible outputs.
*/ */
non_null() uint32_t random_range_u32(const Random *_Nonnull rng, uint32_t upper_bound);
uint32_t random_range_u32(const Random *rng, uint32_t upper_bound);
/** /**
* @brief Cryptographically signs a message using the supplied secret key and puts the resulting signature * @brief Cryptographically signs a message using the supplied secret key and puts the resulting signature
@@ -283,10 +267,7 @@ uint32_t random_range_u32(const Random *rng, uint32_t upper_bound);
* *
* @retval true on success. * @retval true on success.
*/ */
non_null() bool crypto_signature_create(uint8_t signature[_Nonnull CRYPTO_SIGNATURE_SIZE], const uint8_t *_Nonnull message, uint64_t message_length, const uint8_t secret_key[_Nonnull SIG_SECRET_KEY_SIZE]);
bool crypto_signature_create(uint8_t signature[CRYPTO_SIGNATURE_SIZE],
const uint8_t *message, uint64_t message_length,
const uint8_t secret_key[SIG_SECRET_KEY_SIZE]);
/** @brief Verifies that the given signature was produced by a given message and public key. /** @brief Verifies that the given signature was produced by a given message and public key.
* *
@@ -298,22 +279,18 @@ bool crypto_signature_create(uint8_t signature[CRYPTO_SIGNATURE_SIZE],
* *
* @retval true on success. * @retval true on success.
*/ */
non_null() bool crypto_signature_verify(const uint8_t signature[_Nonnull CRYPTO_SIGNATURE_SIZE], const uint8_t *_Nonnull message, uint64_t message_length,
bool crypto_signature_verify(const uint8_t signature[CRYPTO_SIGNATURE_SIZE], const uint8_t public_key[_Nonnull SIG_PUBLIC_KEY_SIZE]);
const uint8_t *message, uint64_t message_length,
const uint8_t public_key[SIG_PUBLIC_KEY_SIZE]);
/** /**
* @brief Fill the given nonce with random bytes. * @brief Fill the given nonce with random bytes.
*/ */
non_null() void random_nonce(const Random *_Nonnull rng, uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE]);
void random_nonce(const Random *rng, uint8_t nonce[CRYPTO_NONCE_SIZE]);
/** /**
* @brief Fill an array of bytes with random values. * @brief Fill an array of bytes with random values.
*/ */
non_null() void random_bytes(const Random *_Nonnull rng, uint8_t *_Nonnull bytes, size_t length);
void random_bytes(const Random *rng, uint8_t *bytes, size_t length);
/** /**
* @brief Check if a Tox public key CRYPTO_PUBLIC_KEY_SIZE is valid or not. * @brief Check if a Tox public key CRYPTO_PUBLIC_KEY_SIZE is valid or not.
@@ -322,8 +299,7 @@ void random_bytes(const Random *rng, uint8_t *bytes, size_t length);
* *
* @return false if it isn't, true if it is. * @return false if it isn't, true if it is.
*/ */
non_null() bool public_key_valid(const uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE]);
bool public_key_valid(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]);
typedef struct Extended_Public_Key { typedef struct Extended_Public_Key {
uint8_t enc[CRYPTO_PUBLIC_KEY_SIZE]; uint8_t enc[CRYPTO_PUBLIC_KEY_SIZE];
@@ -348,32 +324,26 @@ typedef struct Extended_Secret_Key {
* *
* @retval true on success. * @retval true on success.
*/ */
non_null() bool create_extended_keypair(Extended_Public_Key *_Nonnull pk, Extended_Secret_Key *_Nonnull sk, const Random *_Nonnull rng);
bool create_extended_keypair(Extended_Public_Key *pk, Extended_Secret_Key *sk, const Random *rng);
/** Functions for groupchat extended keys */ /** Functions for groupchat extended keys */
non_null() const uint8_t *get_enc_key(const Extended_Public_Key *key); const uint8_t *_Nonnull get_enc_key(const Extended_Public_Key *_Nonnull key);
non_null() const uint8_t *get_sig_pk(const Extended_Public_Key *key); const uint8_t *_Nonnull get_sig_pk(const Extended_Public_Key *_Nonnull key);
non_null() void set_sig_pk(Extended_Public_Key *key, const uint8_t *sig_pk); void set_sig_pk(Extended_Public_Key *_Nonnull key, const uint8_t *_Nonnull sig_pk);
non_null() const uint8_t *get_sig_sk(const Extended_Secret_Key *key); const uint8_t *_Nonnull get_sig_sk(const Extended_Secret_Key *_Nonnull key);
non_null() const uint8_t *get_chat_id(const Extended_Public_Key *key); const uint8_t *_Nonnull get_chat_id(const Extended_Public_Key *_Nonnull key);
/** /**
* @brief Generate a new random keypair. * @brief Generate a new random keypair.
* *
* Every call to this function is likely to generate a different keypair. * Every call to this function is likely to generate a different keypair.
*/ */
non_null() int32_t crypto_new_keypair(const Random *_Nonnull rng, uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], uint8_t secret_key[_Nonnull CRYPTO_SECRET_KEY_SIZE]);
int32_t crypto_new_keypair(const Random *rng,
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE]);
/** /**
* @brief Derive the public key from a given secret key. * @brief Derive the public key from a given secret key.
*/ */
non_null() void crypto_derive_public_key(uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t secret_key[_Nonnull CRYPTO_SECRET_KEY_SIZE]);
void crypto_derive_public_key(uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
const uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE]);
/** /**
* @brief Encrypt message to send from secret key to public key. * @brief Encrypt message to send from secret key to public key.
@@ -386,12 +356,8 @@ void crypto_derive_public_key(uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
* @retval -1 if there was a problem. * @retval -1 if there was a problem.
* @return length of encrypted data if everything was fine. * @return length of encrypted data if everything was fine.
*/ */
non_null() int32_t encrypt_data(const Memory *_Nonnull mem, const uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t secret_key[_Nonnull CRYPTO_SECRET_KEY_SIZE],
int32_t encrypt_data(const Memory *mem, const uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE], const uint8_t *_Nonnull plain, size_t length, uint8_t *_Nonnull encrypted);
const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
const uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE],
const uint8_t nonce[CRYPTO_NONCE_SIZE],
const uint8_t *plain, size_t length, uint8_t *encrypted);
/** /**
* @brief Decrypt message from public key to secret key. * @brief Decrypt message from public key to secret key.
@@ -404,12 +370,8 @@ int32_t encrypt_data(const Memory *mem,
* @retval -1 if there was a problem (decryption failed). * @retval -1 if there was a problem (decryption failed).
* @return length of plain text data if everything was fine. * @return length of plain text data if everything was fine.
*/ */
non_null() int32_t decrypt_data(const Memory *_Nonnull mem, const uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t secret_key[_Nonnull CRYPTO_SECRET_KEY_SIZE],
int32_t decrypt_data(const Memory *mem, const uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE], const uint8_t *_Nonnull encrypted, size_t length, uint8_t *_Nonnull plain);
const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
const uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE],
const uint8_t nonce[CRYPTO_NONCE_SIZE],
const uint8_t *encrypted, size_t length, uint8_t *plain);
/** /**
* @brief Fast encrypt/decrypt operations. * @brief Fast encrypt/decrypt operations.
@@ -418,62 +380,51 @@ int32_t decrypt_data(const Memory *mem,
* shared-key generation once so it does not have to be performed on every * shared-key generation once so it does not have to be performed on every
* encrypt/decrypt. * encrypt/decrypt.
*/ */
non_null() int32_t encrypt_precompute(const uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t secret_key[_Nonnull CRYPTO_SECRET_KEY_SIZE],
int32_t encrypt_precompute(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], uint8_t shared_key[_Nonnull CRYPTO_SHARED_KEY_SIZE]);
const uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE],
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]);
/** /**
* @brief Encrypt message with precomputed shared key. * @brief Encrypt message with precomputed shared key.
* *
* Encrypts plain of length length to encrypted of length + @ref CRYPTO_MAC_SIZE * Encrypts plain of length length to encrypted of length + @ref CRYPTO_MAC_SIZE
* using a shared key @ref CRYPTO_SHARED_KEY_SIZE big and a @ref CRYPTO_NONCE_SIZE * using a shared key @ref CRYPTO_SYMMETRIC_KEY_SIZE big and a @ref CRYPTO_NONCE_SIZE
* byte nonce. * byte nonce.
* *
* @retval -1 if there was a problem. * @retval -1 if there was a problem.
* @return length of encrypted data if everything was fine. * @return length of encrypted data if everything was fine.
*/ */
non_null() int32_t encrypt_data_symmetric(const Memory *_Nonnull mem, const uint8_t shared_key[_Nonnull CRYPTO_SHARED_KEY_SIZE], const uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE],
int32_t encrypt_data_symmetric(const Memory *mem, const uint8_t *_Nonnull plain, size_t length, uint8_t *_Nonnull encrypted);
const uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE],
const uint8_t nonce[CRYPTO_NONCE_SIZE],
const uint8_t *plain, size_t length, uint8_t *encrypted);
/** /**
* @brief Decrypt message with precomputed shared key. * @brief Decrypt message with precomputed shared key.
* *
* Decrypts encrypted of length length to plain of length * Decrypts encrypted of length length to plain of length
* `length - CRYPTO_MAC_SIZE` using a shared key @ref CRYPTO_SHARED_KEY_SIZE * `length - CRYPTO_MAC_SIZE` using a shared key @ref CRYPTO_SYMMETRIC_KEY_SIZE
* big and a @ref CRYPTO_NONCE_SIZE byte nonce. * big and a @ref CRYPTO_NONCE_SIZE byte nonce.
* *
* @retval -1 if there was a problem (decryption failed). * @retval -1 if there was a problem (decryption failed).
* @return length of plain data if everything was fine. * @return length of plain data if everything was fine.
*/ */
non_null() int32_t decrypt_data_symmetric(const Memory *_Nonnull mem, const uint8_t shared_key[_Nonnull CRYPTO_SHARED_KEY_SIZE], const uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE],
int32_t decrypt_data_symmetric(const Memory *mem, const uint8_t *_Nonnull encrypted, size_t length, uint8_t *_Nonnull plain);
const uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE],
const uint8_t nonce[CRYPTO_NONCE_SIZE],
const uint8_t *encrypted, size_t length, uint8_t *plain);
/** /**
* @brief Increment the given nonce by 1 in big endian (rightmost byte incremented first). * @brief Increment the given nonce by 1 in big endian (rightmost byte incremented first).
*/ */
non_null() void increment_nonce(uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE]);
void increment_nonce(uint8_t nonce[CRYPTO_NONCE_SIZE]);
/** /**
* @brief Increment the given nonce by a given number. * @brief Increment the given nonce by a given number.
* *
* The number should be in host byte order. * The number should be in host byte order.
*/ */
non_null() void increment_nonce_number(uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE], uint32_t increment);
void increment_nonce_number(uint8_t nonce[CRYPTO_NONCE_SIZE], uint32_t increment);
/** /**
* @brief Fill a key @ref CRYPTO_SYMMETRIC_KEY_SIZE big with random bytes. * @brief Fill a key @ref CRYPTO_SYMMETRIC_KEY_SIZE big with random bytes.
*/ */
non_null() void new_symmetric_key(const Random *_Nonnull rng, uint8_t key[_Nonnull CRYPTO_SYMMETRIC_KEY_SIZE]);
void new_symmetric_key(const Random *rng, uint8_t key[CRYPTO_SYMMETRIC_KEY_SIZE]);
/** /**
* @brief Locks `length` bytes of memory pointed to by `data`. * @brief Locks `length` bytes of memory pointed to by `data`.
@@ -483,8 +434,7 @@ void new_symmetric_key(const Random *rng, uint8_t key[CRYPTO_SYMMETRIC_KEY_SIZE]
* *
* @return true on success. * @return true on success.
*/ */
non_null() bool crypto_memlock(void *_Nonnull data, size_t length);
bool crypto_memlock(void *data, size_t length);
/** /**
* @brief Unlocks `length` bytes of memory pointed to by `data`. * @brief Unlocks `length` bytes of memory pointed to by `data`.
@@ -497,14 +447,12 @@ bool crypto_memlock(void *data, size_t length);
* *
* @return true on success. * @return true on success.
*/ */
non_null() bool crypto_memunlock(void *_Nonnull data, size_t length);
bool crypto_memunlock(void *data, size_t length);
/** /**
* @brief Generate a random secret HMAC key. * @brief Generate a random secret HMAC key.
*/ */
non_null() void new_hmac_key(const Random *_Nonnull rng, uint8_t key[_Nonnull CRYPTO_HMAC_KEY_SIZE]);
void new_hmac_key(const Random *rng, uint8_t key[CRYPTO_HMAC_KEY_SIZE]);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View File

@@ -12,7 +12,7 @@
#include "ccompat.h" #include "ccompat.h"
#include "crypto_core.h" #include "crypto_core.h"
bool pack_extended_public_key(const Extended_Public_Key *key, Bin_Pack *bp) bool pack_extended_public_key(const Extended_Public_Key *_Nonnull key, Bin_Pack *_Nonnull bp)
{ {
uint8_t ext_key[EXT_PUBLIC_KEY_SIZE]; uint8_t ext_key[EXT_PUBLIC_KEY_SIZE];
static_assert(sizeof(ext_key) == sizeof(key->enc) + sizeof(key->sig), static_assert(sizeof(ext_key) == sizeof(key->enc) + sizeof(key->sig),
@@ -23,7 +23,7 @@ bool pack_extended_public_key(const Extended_Public_Key *key, Bin_Pack *bp)
return bin_pack_bin(bp, ext_key, sizeof(ext_key)); return bin_pack_bin(bp, ext_key, sizeof(ext_key));
} }
bool pack_extended_secret_key(const Extended_Secret_Key *key, Bin_Pack *bp) bool pack_extended_secret_key(const Extended_Secret_Key *_Nonnull key, Bin_Pack *_Nonnull bp)
{ {
uint8_t ext_key[EXT_SECRET_KEY_SIZE]; uint8_t ext_key[EXT_SECRET_KEY_SIZE];
static_assert(sizeof(ext_key) == sizeof(key->enc) + sizeof(key->sig), static_assert(sizeof(ext_key) == sizeof(key->enc) + sizeof(key->sig),
@@ -36,7 +36,7 @@ bool pack_extended_secret_key(const Extended_Secret_Key *key, Bin_Pack *bp)
return result; return result;
} }
bool unpack_extended_public_key(Extended_Public_Key *key, Bin_Unpack *bu) bool unpack_extended_public_key(Extended_Public_Key *_Nonnull key, Bin_Unpack *_Nonnull bu)
{ {
uint8_t ext_key[EXT_PUBLIC_KEY_SIZE]; uint8_t ext_key[EXT_PUBLIC_KEY_SIZE];
@@ -50,7 +50,7 @@ bool unpack_extended_public_key(Extended_Public_Key *key, Bin_Unpack *bu)
return true; return true;
} }
bool unpack_extended_secret_key(Extended_Secret_Key *key, Bin_Unpack *bu) bool unpack_extended_secret_key(Extended_Secret_Key *_Nonnull key, Bin_Unpack *_Nonnull bu)
{ {
uint8_t ext_key[EXT_SECRET_KEY_SIZE]; uint8_t ext_key[EXT_SECRET_KEY_SIZE];

View File

@@ -19,10 +19,10 @@
extern "C" { extern "C" {
#endif #endif
non_null() bool pack_extended_public_key(const Extended_Public_Key *key, Bin_Pack *bp); bool pack_extended_public_key(const Extended_Public_Key *_Nonnull key, Bin_Pack *_Nonnull bp);
non_null() bool pack_extended_secret_key(const Extended_Secret_Key *key, Bin_Pack *bp); bool pack_extended_secret_key(const Extended_Secret_Key *_Nonnull key, Bin_Pack *_Nonnull bp);
non_null() bool unpack_extended_public_key(Extended_Public_Key *key, Bin_Unpack *bu); bool unpack_extended_public_key(Extended_Public_Key *_Nonnull key, Bin_Unpack *_Nonnull bu);
non_null() bool unpack_extended_secret_key(Extended_Secret_Key *key, Bin_Unpack *bu); bool unpack_extended_secret_key(Extended_Secret_Key *_Nonnull key, Bin_Unpack *_Nonnull bu);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View File

@@ -25,9 +25,7 @@ struct Tox_Event_Conference_Connected {
uint32_t conference_number; uint32_t conference_number;
}; };
non_null() static void tox_event_conference_connected_set_conference_number(Tox_Event_Conference_Connected *_Nonnull conference_connected, uint32_t conference_number)
static void tox_event_conference_connected_set_conference_number(Tox_Event_Conference_Connected *conference_connected,
uint32_t conference_number)
{ {
assert(conference_connected != nullptr); assert(conference_connected != nullptr);
conference_connected->conference_number = conference_number; conference_connected->conference_number = conference_number;
@@ -38,15 +36,13 @@ uint32_t tox_event_conference_connected_get_conference_number(const Tox_Event_Co
return conference_connected->conference_number; return conference_connected->conference_number;
} }
non_null() static void tox_event_conference_connected_construct(Tox_Event_Conference_Connected *_Nonnull conference_connected)
static void tox_event_conference_connected_construct(Tox_Event_Conference_Connected *conference_connected)
{ {
*conference_connected = (Tox_Event_Conference_Connected) { *conference_connected = (Tox_Event_Conference_Connected) {
0 0
}; };
} }
non_null() static void tox_event_conference_connected_destruct(Tox_Event_Conference_Connected *_Nonnull conference_connected, const Memory *_Nonnull mem)
static void tox_event_conference_connected_destruct(Tox_Event_Conference_Connected *conference_connected, const Memory *mem)
{ {
return; return;
} }
@@ -57,9 +53,7 @@ bool tox_event_conference_connected_pack(
return bin_pack_u32(bp, event->conference_number); return bin_pack_u32(bp, event->conference_number);
} }
non_null() static bool tox_event_conference_connected_unpack_into(Tox_Event_Conference_Connected *_Nonnull event, Bin_Unpack *_Nonnull bu)
static bool tox_event_conference_connected_unpack_into(
Tox_Event_Conference_Connected *event, Bin_Unpack *bu)
{ {
assert(event != nullptr); assert(event != nullptr);
return bin_unpack_u32(bu, &event->conference_number); return bin_unpack_u32(bu, &event->conference_number);
@@ -97,8 +91,7 @@ void tox_event_conference_connected_free(Tox_Event_Conference_Connected *confere
mem_delete(mem, conference_connected); mem_delete(mem, conference_connected);
} }
non_null() static Tox_Event_Conference_Connected *tox_events_add_conference_connected(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
static Tox_Event_Conference_Connected *tox_events_add_conference_connected(Tox_Events *events, const Memory *mem)
{ {
Tox_Event_Conference_Connected *const conference_connected = tox_event_conference_connected_new(mem); Tox_Event_Conference_Connected *const conference_connected = tox_event_conference_connected_new(mem);
@@ -131,8 +124,7 @@ bool tox_event_conference_connected_unpack(
return tox_event_conference_connected_unpack_into(*event, bu); return tox_event_conference_connected_unpack_into(*event, bu);
} }
non_null() static Tox_Event_Conference_Connected *tox_event_conference_connected_alloc(void *_Nonnull user_data)
static Tox_Event_Conference_Connected *tox_event_conference_connected_alloc(void *user_data)
{ {
Tox_Events_State *state = tox_events_alloc(user_data); Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr); assert(state != nullptr);

View File

@@ -32,9 +32,7 @@ struct Tox_Event_Conference_Invite {
uint32_t cookie_length; uint32_t cookie_length;
}; };
non_null() static void tox_event_conference_invite_set_friend_number(Tox_Event_Conference_Invite *_Nonnull conference_invite, uint32_t friend_number)
static void tox_event_conference_invite_set_friend_number(Tox_Event_Conference_Invite *conference_invite,
uint32_t friend_number)
{ {
assert(conference_invite != nullptr); assert(conference_invite != nullptr);
conference_invite->friend_number = friend_number; conference_invite->friend_number = friend_number;
@@ -45,9 +43,7 @@ uint32_t tox_event_conference_invite_get_friend_number(const Tox_Event_Conferenc
return conference_invite->friend_number; return conference_invite->friend_number;
} }
non_null() static void tox_event_conference_invite_set_type(Tox_Event_Conference_Invite *_Nonnull conference_invite, Tox_Conference_Type type)
static void tox_event_conference_invite_set_type(Tox_Event_Conference_Invite *conference_invite,
Tox_Conference_Type type)
{ {
assert(conference_invite != nullptr); assert(conference_invite != nullptr);
conference_invite->type = type; conference_invite->type = type;
@@ -58,12 +54,10 @@ Tox_Conference_Type tox_event_conference_invite_get_type(const Tox_Event_Confere
return conference_invite->type; return conference_invite->type;
} }
non_null(1) nullable(2) static bool tox_event_conference_invite_set_cookie(Tox_Event_Conference_Invite *_Nonnull conference_invite,
static bool tox_event_conference_invite_set_cookie(Tox_Event_Conference_Invite *conference_invite, const uint8_t *_Nullable cookie, uint32_t cookie_length)
const uint8_t *cookie, uint32_t cookie_length)
{ {
assert(conference_invite != nullptr); assert(conference_invite != nullptr);
if (conference_invite->cookie != nullptr) { if (conference_invite->cookie != nullptr) {
free(conference_invite->cookie); free(conference_invite->cookie);
conference_invite->cookie = nullptr; conference_invite->cookie = nullptr;
@@ -97,15 +91,13 @@ const uint8_t *tox_event_conference_invite_get_cookie(const Tox_Event_Conference
return conference_invite->cookie; return conference_invite->cookie;
} }
non_null() static void tox_event_conference_invite_construct(Tox_Event_Conference_Invite *_Nonnull conference_invite)
static void tox_event_conference_invite_construct(Tox_Event_Conference_Invite *conference_invite)
{ {
*conference_invite = (Tox_Event_Conference_Invite) { *conference_invite = (Tox_Event_Conference_Invite) {
0 0
}; };
} }
non_null() static void tox_event_conference_invite_destruct(Tox_Event_Conference_Invite *_Nonnull conference_invite, const Memory *_Nonnull mem)
static void tox_event_conference_invite_destruct(Tox_Event_Conference_Invite *conference_invite, const Memory *mem)
{ {
free(conference_invite->cookie); free(conference_invite->cookie);
} }
@@ -119,9 +111,7 @@ bool tox_event_conference_invite_pack(
&& bin_pack_bin(bp, event->cookie, event->cookie_length); && bin_pack_bin(bp, event->cookie, event->cookie_length);
} }
non_null() static bool tox_event_conference_invite_unpack_into(Tox_Event_Conference_Invite *_Nonnull event, Bin_Unpack *_Nonnull bu)
static bool tox_event_conference_invite_unpack_into(
Tox_Event_Conference_Invite *event, Bin_Unpack *bu)
{ {
assert(event != nullptr); assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 3, nullptr)) { if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
@@ -165,8 +155,7 @@ void tox_event_conference_invite_free(Tox_Event_Conference_Invite *conference_in
mem_delete(mem, conference_invite); mem_delete(mem, conference_invite);
} }
non_null() static Tox_Event_Conference_Invite *tox_events_add_conference_invite(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
static Tox_Event_Conference_Invite *tox_events_add_conference_invite(Tox_Events *events, const Memory *mem)
{ {
Tox_Event_Conference_Invite *const conference_invite = tox_event_conference_invite_new(mem); Tox_Event_Conference_Invite *const conference_invite = tox_event_conference_invite_new(mem);
@@ -199,8 +188,7 @@ bool tox_event_conference_invite_unpack(
return tox_event_conference_invite_unpack_into(*event, bu); return tox_event_conference_invite_unpack_into(*event, bu);
} }
non_null() static Tox_Event_Conference_Invite *tox_event_conference_invite_alloc(void *_Nonnull user_data)
static Tox_Event_Conference_Invite *tox_event_conference_invite_alloc(void *user_data)
{ {
Tox_Events_State *state = tox_events_alloc(user_data); Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr); assert(state != nullptr);

View File

@@ -33,9 +33,7 @@ struct Tox_Event_Conference_Message {
uint32_t message_length; uint32_t message_length;
}; };
non_null() static void tox_event_conference_message_set_conference_number(Tox_Event_Conference_Message *_Nonnull conference_message, uint32_t conference_number)
static void tox_event_conference_message_set_conference_number(Tox_Event_Conference_Message *conference_message,
uint32_t conference_number)
{ {
assert(conference_message != nullptr); assert(conference_message != nullptr);
conference_message->conference_number = conference_number; conference_message->conference_number = conference_number;
@@ -46,9 +44,7 @@ uint32_t tox_event_conference_message_get_conference_number(const Tox_Event_Conf
return conference_message->conference_number; return conference_message->conference_number;
} }
non_null() static void tox_event_conference_message_set_peer_number(Tox_Event_Conference_Message *_Nonnull conference_message, uint32_t peer_number)
static void tox_event_conference_message_set_peer_number(Tox_Event_Conference_Message *conference_message,
uint32_t peer_number)
{ {
assert(conference_message != nullptr); assert(conference_message != nullptr);
conference_message->peer_number = peer_number; conference_message->peer_number = peer_number;
@@ -59,9 +55,7 @@ uint32_t tox_event_conference_message_get_peer_number(const Tox_Event_Conference
return conference_message->peer_number; return conference_message->peer_number;
} }
non_null() static void tox_event_conference_message_set_type(Tox_Event_Conference_Message *_Nonnull conference_message, Tox_Message_Type type)
static void tox_event_conference_message_set_type(Tox_Event_Conference_Message *conference_message,
Tox_Message_Type type)
{ {
assert(conference_message != nullptr); assert(conference_message != nullptr);
conference_message->type = type; conference_message->type = type;
@@ -72,12 +66,10 @@ Tox_Message_Type tox_event_conference_message_get_type(const Tox_Event_Conferenc
return conference_message->type; return conference_message->type;
} }
non_null(1) nullable(2) static bool tox_event_conference_message_set_message(Tox_Event_Conference_Message *_Nonnull conference_message,
static bool tox_event_conference_message_set_message(Tox_Event_Conference_Message *conference_message, const uint8_t *_Nullable message, uint32_t message_length)
const uint8_t *message, uint32_t message_length)
{ {
assert(conference_message != nullptr); assert(conference_message != nullptr);
if (conference_message->message != nullptr) { if (conference_message->message != nullptr) {
free(conference_message->message); free(conference_message->message);
conference_message->message = nullptr; conference_message->message = nullptr;
@@ -111,15 +103,13 @@ const uint8_t *tox_event_conference_message_get_message(const Tox_Event_Conferen
return conference_message->message; return conference_message->message;
} }
non_null() static void tox_event_conference_message_construct(Tox_Event_Conference_Message *_Nonnull conference_message)
static void tox_event_conference_message_construct(Tox_Event_Conference_Message *conference_message)
{ {
*conference_message = (Tox_Event_Conference_Message) { *conference_message = (Tox_Event_Conference_Message) {
0 0
}; };
} }
non_null() static void tox_event_conference_message_destruct(Tox_Event_Conference_Message *_Nonnull conference_message, const Memory *_Nonnull mem)
static void tox_event_conference_message_destruct(Tox_Event_Conference_Message *conference_message, const Memory *mem)
{ {
free(conference_message->message); free(conference_message->message);
} }
@@ -134,9 +124,7 @@ bool tox_event_conference_message_pack(
&& bin_pack_bin(bp, event->message, event->message_length); && bin_pack_bin(bp, event->message, event->message_length);
} }
non_null() static bool tox_event_conference_message_unpack_into(Tox_Event_Conference_Message *_Nonnull event, Bin_Unpack *_Nonnull bu)
static bool tox_event_conference_message_unpack_into(
Tox_Event_Conference_Message *event, Bin_Unpack *bu)
{ {
assert(event != nullptr); assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 4, nullptr)) { if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
@@ -181,8 +169,7 @@ void tox_event_conference_message_free(Tox_Event_Conference_Message *conference_
mem_delete(mem, conference_message); mem_delete(mem, conference_message);
} }
non_null() static Tox_Event_Conference_Message *tox_events_add_conference_message(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
static Tox_Event_Conference_Message *tox_events_add_conference_message(Tox_Events *events, const Memory *mem)
{ {
Tox_Event_Conference_Message *const conference_message = tox_event_conference_message_new(mem); Tox_Event_Conference_Message *const conference_message = tox_event_conference_message_new(mem);
@@ -215,8 +202,7 @@ bool tox_event_conference_message_unpack(
return tox_event_conference_message_unpack_into(*event, bu); return tox_event_conference_message_unpack_into(*event, bu);
} }
non_null() static Tox_Event_Conference_Message *tox_event_conference_message_alloc(void *_Nonnull user_data)
static Tox_Event_Conference_Message *tox_event_conference_message_alloc(void *user_data)
{ {
Tox_Events_State *state = tox_events_alloc(user_data); Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr); assert(state != nullptr);

View File

@@ -25,9 +25,7 @@ struct Tox_Event_Conference_Peer_List_Changed {
uint32_t conference_number; uint32_t conference_number;
}; };
non_null() static void tox_event_conference_peer_list_changed_set_conference_number(Tox_Event_Conference_Peer_List_Changed *_Nonnull conference_peer_list_changed, uint32_t conference_number)
static void tox_event_conference_peer_list_changed_set_conference_number(Tox_Event_Conference_Peer_List_Changed *conference_peer_list_changed,
uint32_t conference_number)
{ {
assert(conference_peer_list_changed != nullptr); assert(conference_peer_list_changed != nullptr);
conference_peer_list_changed->conference_number = conference_number; conference_peer_list_changed->conference_number = conference_number;
@@ -38,15 +36,13 @@ uint32_t tox_event_conference_peer_list_changed_get_conference_number(const Tox_
return conference_peer_list_changed->conference_number; return conference_peer_list_changed->conference_number;
} }
non_null() static void tox_event_conference_peer_list_changed_construct(Tox_Event_Conference_Peer_List_Changed *_Nonnull conference_peer_list_changed)
static void tox_event_conference_peer_list_changed_construct(Tox_Event_Conference_Peer_List_Changed *conference_peer_list_changed)
{ {
*conference_peer_list_changed = (Tox_Event_Conference_Peer_List_Changed) { *conference_peer_list_changed = (Tox_Event_Conference_Peer_List_Changed) {
0 0
}; };
} }
non_null() static void tox_event_conference_peer_list_changed_destruct(Tox_Event_Conference_Peer_List_Changed *_Nonnull conference_peer_list_changed, const Memory *_Nonnull mem)
static void tox_event_conference_peer_list_changed_destruct(Tox_Event_Conference_Peer_List_Changed *conference_peer_list_changed, const Memory *mem)
{ {
return; return;
} }
@@ -57,9 +53,7 @@ bool tox_event_conference_peer_list_changed_pack(
return bin_pack_u32(bp, event->conference_number); return bin_pack_u32(bp, event->conference_number);
} }
non_null() static bool tox_event_conference_peer_list_changed_unpack_into(Tox_Event_Conference_Peer_List_Changed *_Nonnull event, Bin_Unpack *_Nonnull bu)
static bool tox_event_conference_peer_list_changed_unpack_into(
Tox_Event_Conference_Peer_List_Changed *event, Bin_Unpack *bu)
{ {
assert(event != nullptr); assert(event != nullptr);
return bin_unpack_u32(bu, &event->conference_number); return bin_unpack_u32(bu, &event->conference_number);
@@ -97,8 +91,7 @@ void tox_event_conference_peer_list_changed_free(Tox_Event_Conference_Peer_List_
mem_delete(mem, conference_peer_list_changed); mem_delete(mem, conference_peer_list_changed);
} }
non_null() static Tox_Event_Conference_Peer_List_Changed *tox_events_add_conference_peer_list_changed(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
static Tox_Event_Conference_Peer_List_Changed *tox_events_add_conference_peer_list_changed(Tox_Events *events, const Memory *mem)
{ {
Tox_Event_Conference_Peer_List_Changed *const conference_peer_list_changed = tox_event_conference_peer_list_changed_new(mem); Tox_Event_Conference_Peer_List_Changed *const conference_peer_list_changed = tox_event_conference_peer_list_changed_new(mem);
@@ -131,8 +124,7 @@ bool tox_event_conference_peer_list_changed_unpack(
return tox_event_conference_peer_list_changed_unpack_into(*event, bu); return tox_event_conference_peer_list_changed_unpack_into(*event, bu);
} }
non_null() static Tox_Event_Conference_Peer_List_Changed *tox_event_conference_peer_list_changed_alloc(void *_Nonnull user_data)
static Tox_Event_Conference_Peer_List_Changed *tox_event_conference_peer_list_changed_alloc(void *user_data)
{ {
Tox_Events_State *state = tox_events_alloc(user_data); Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr); assert(state != nullptr);

View File

@@ -30,9 +30,7 @@ struct Tox_Event_Conference_Peer_Name {
uint32_t name_length; uint32_t name_length;
}; };
non_null() static void tox_event_conference_peer_name_set_conference_number(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name, uint32_t conference_number)
static void tox_event_conference_peer_name_set_conference_number(Tox_Event_Conference_Peer_Name *conference_peer_name,
uint32_t conference_number)
{ {
assert(conference_peer_name != nullptr); assert(conference_peer_name != nullptr);
conference_peer_name->conference_number = conference_number; conference_peer_name->conference_number = conference_number;
@@ -43,9 +41,7 @@ uint32_t tox_event_conference_peer_name_get_conference_number(const Tox_Event_Co
return conference_peer_name->conference_number; return conference_peer_name->conference_number;
} }
non_null() static void tox_event_conference_peer_name_set_peer_number(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name, uint32_t peer_number)
static void tox_event_conference_peer_name_set_peer_number(Tox_Event_Conference_Peer_Name *conference_peer_name,
uint32_t peer_number)
{ {
assert(conference_peer_name != nullptr); assert(conference_peer_name != nullptr);
conference_peer_name->peer_number = peer_number; conference_peer_name->peer_number = peer_number;
@@ -56,12 +52,10 @@ uint32_t tox_event_conference_peer_name_get_peer_number(const Tox_Event_Conferen
return conference_peer_name->peer_number; return conference_peer_name->peer_number;
} }
non_null(1) nullable(2) static bool tox_event_conference_peer_name_set_name(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name,
static bool tox_event_conference_peer_name_set_name(Tox_Event_Conference_Peer_Name *conference_peer_name, const uint8_t *_Nullable name, uint32_t name_length)
const uint8_t *name, uint32_t name_length)
{ {
assert(conference_peer_name != nullptr); assert(conference_peer_name != nullptr);
if (conference_peer_name->name != nullptr) { if (conference_peer_name->name != nullptr) {
free(conference_peer_name->name); free(conference_peer_name->name);
conference_peer_name->name = nullptr; conference_peer_name->name = nullptr;
@@ -95,15 +89,13 @@ const uint8_t *tox_event_conference_peer_name_get_name(const Tox_Event_Conferenc
return conference_peer_name->name; return conference_peer_name->name;
} }
non_null() static void tox_event_conference_peer_name_construct(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name)
static void tox_event_conference_peer_name_construct(Tox_Event_Conference_Peer_Name *conference_peer_name)
{ {
*conference_peer_name = (Tox_Event_Conference_Peer_Name) { *conference_peer_name = (Tox_Event_Conference_Peer_Name) {
0 0
}; };
} }
non_null() static void tox_event_conference_peer_name_destruct(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name, const Memory *_Nonnull mem)
static void tox_event_conference_peer_name_destruct(Tox_Event_Conference_Peer_Name *conference_peer_name, const Memory *mem)
{ {
free(conference_peer_name->name); free(conference_peer_name->name);
} }
@@ -117,9 +109,7 @@ bool tox_event_conference_peer_name_pack(
&& bin_pack_bin(bp, event->name, event->name_length); && bin_pack_bin(bp, event->name, event->name_length);
} }
non_null() static bool tox_event_conference_peer_name_unpack_into(Tox_Event_Conference_Peer_Name *_Nonnull event, Bin_Unpack *_Nonnull bu)
static bool tox_event_conference_peer_name_unpack_into(
Tox_Event_Conference_Peer_Name *event, Bin_Unpack *bu)
{ {
assert(event != nullptr); assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 3, nullptr)) { if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
@@ -163,8 +153,7 @@ void tox_event_conference_peer_name_free(Tox_Event_Conference_Peer_Name *confere
mem_delete(mem, conference_peer_name); mem_delete(mem, conference_peer_name);
} }
non_null() static Tox_Event_Conference_Peer_Name *tox_events_add_conference_peer_name(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
static Tox_Event_Conference_Peer_Name *tox_events_add_conference_peer_name(Tox_Events *events, const Memory *mem)
{ {
Tox_Event_Conference_Peer_Name *const conference_peer_name = tox_event_conference_peer_name_new(mem); Tox_Event_Conference_Peer_Name *const conference_peer_name = tox_event_conference_peer_name_new(mem);
@@ -197,8 +186,7 @@ bool tox_event_conference_peer_name_unpack(
return tox_event_conference_peer_name_unpack_into(*event, bu); return tox_event_conference_peer_name_unpack_into(*event, bu);
} }
non_null() static Tox_Event_Conference_Peer_Name *tox_event_conference_peer_name_alloc(void *_Nonnull user_data)
static Tox_Event_Conference_Peer_Name *tox_event_conference_peer_name_alloc(void *user_data)
{ {
Tox_Events_State *state = tox_events_alloc(user_data); Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr); assert(state != nullptr);

View File

@@ -30,9 +30,7 @@ struct Tox_Event_Conference_Title {
uint32_t title_length; uint32_t title_length;
}; };
non_null() static void tox_event_conference_title_set_conference_number(Tox_Event_Conference_Title *_Nonnull conference_title, uint32_t conference_number)
static void tox_event_conference_title_set_conference_number(Tox_Event_Conference_Title *conference_title,
uint32_t conference_number)
{ {
assert(conference_title != nullptr); assert(conference_title != nullptr);
conference_title->conference_number = conference_number; conference_title->conference_number = conference_number;
@@ -43,9 +41,7 @@ uint32_t tox_event_conference_title_get_conference_number(const Tox_Event_Confer
return conference_title->conference_number; return conference_title->conference_number;
} }
non_null() static void tox_event_conference_title_set_peer_number(Tox_Event_Conference_Title *_Nonnull conference_title, uint32_t peer_number)
static void tox_event_conference_title_set_peer_number(Tox_Event_Conference_Title *conference_title,
uint32_t peer_number)
{ {
assert(conference_title != nullptr); assert(conference_title != nullptr);
conference_title->peer_number = peer_number; conference_title->peer_number = peer_number;
@@ -56,12 +52,10 @@ uint32_t tox_event_conference_title_get_peer_number(const Tox_Event_Conference_T
return conference_title->peer_number; return conference_title->peer_number;
} }
non_null(1) nullable(2) static bool tox_event_conference_title_set_title(Tox_Event_Conference_Title *_Nonnull conference_title,
static bool tox_event_conference_title_set_title(Tox_Event_Conference_Title *conference_title, const uint8_t *_Nullable title, uint32_t title_length)
const uint8_t *title, uint32_t title_length)
{ {
assert(conference_title != nullptr); assert(conference_title != nullptr);
if (conference_title->title != nullptr) { if (conference_title->title != nullptr) {
free(conference_title->title); free(conference_title->title);
conference_title->title = nullptr; conference_title->title = nullptr;
@@ -95,15 +89,13 @@ const uint8_t *tox_event_conference_title_get_title(const Tox_Event_Conference_T
return conference_title->title; return conference_title->title;
} }
non_null() static void tox_event_conference_title_construct(Tox_Event_Conference_Title *_Nonnull conference_title)
static void tox_event_conference_title_construct(Tox_Event_Conference_Title *conference_title)
{ {
*conference_title = (Tox_Event_Conference_Title) { *conference_title = (Tox_Event_Conference_Title) {
0 0
}; };
} }
non_null() static void tox_event_conference_title_destruct(Tox_Event_Conference_Title *_Nonnull conference_title, const Memory *_Nonnull mem)
static void tox_event_conference_title_destruct(Tox_Event_Conference_Title *conference_title, const Memory *mem)
{ {
free(conference_title->title); free(conference_title->title);
} }
@@ -117,9 +109,7 @@ bool tox_event_conference_title_pack(
&& bin_pack_bin(bp, event->title, event->title_length); && bin_pack_bin(bp, event->title, event->title_length);
} }
non_null() static bool tox_event_conference_title_unpack_into(Tox_Event_Conference_Title *_Nonnull event, Bin_Unpack *_Nonnull bu)
static bool tox_event_conference_title_unpack_into(
Tox_Event_Conference_Title *event, Bin_Unpack *bu)
{ {
assert(event != nullptr); assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 3, nullptr)) { if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
@@ -163,8 +153,7 @@ void tox_event_conference_title_free(Tox_Event_Conference_Title *conference_titl
mem_delete(mem, conference_title); mem_delete(mem, conference_title);
} }
non_null() static Tox_Event_Conference_Title *tox_events_add_conference_title(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
static Tox_Event_Conference_Title *tox_events_add_conference_title(Tox_Events *events, const Memory *mem)
{ {
Tox_Event_Conference_Title *const conference_title = tox_event_conference_title_new(mem); Tox_Event_Conference_Title *const conference_title = tox_event_conference_title_new(mem);
@@ -197,8 +186,7 @@ bool tox_event_conference_title_unpack(
return tox_event_conference_title_unpack_into(*event, bu); return tox_event_conference_title_unpack_into(*event, bu);
} }
non_null() static Tox_Event_Conference_Title *tox_event_conference_title_alloc(void *_Nonnull user_data)
static Tox_Event_Conference_Title *tox_event_conference_title_alloc(void *user_data)
{ {
Tox_Events_State *state = tox_events_alloc(user_data); Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr); assert(state != nullptr);

View File

@@ -30,20 +30,17 @@ struct Tox_Event_Dht_Nodes_Response {
uint16_t port; uint16_t port;
}; };
non_null() static bool tox_event_dht_nodes_response_set_public_key(Tox_Event_Dht_Nodes_Response *_Nonnull dht_nodes_response, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE])
static bool tox_event_dht_nodes_response_set_public_key(Tox_Event_Dht_Nodes_Response *dht_nodes_response, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE])
{ {
memcpy(dht_nodes_response->public_key, public_key, TOX_PUBLIC_KEY_SIZE); memcpy(dht_nodes_response->public_key, public_key, TOX_PUBLIC_KEY_SIZE);
return true; return true;
} }
const uint8_t *tox_event_dht_nodes_response_get_public_key(const Tox_Event_Dht_Nodes_Response *dht_nodes_response) const uint8_t *_Nonnull tox_event_dht_nodes_response_get_public_key(const Tox_Event_Dht_Nodes_Response *dht_nodes_response)
{ {
return dht_nodes_response->public_key; return dht_nodes_response->public_key;
} }
non_null() static bool tox_event_dht_nodes_response_set_ip(Tox_Event_Dht_Nodes_Response *_Nonnull dht_nodes_response, const char *_Nonnull ip, uint32_t ip_length, const Memory *_Nonnull mem)
static bool tox_event_dht_nodes_response_set_ip(Tox_Event_Dht_Nodes_Response *dht_nodes_response,
const char *ip, uint32_t ip_length, const Memory *mem)
{ {
if (dht_nodes_response->ip != nullptr) { if (dht_nodes_response->ip != nullptr) {
mem_delete(mem, dht_nodes_response->ip); mem_delete(mem, dht_nodes_response->ip);
@@ -71,8 +68,7 @@ const uint8_t *tox_event_dht_nodes_response_get_ip(const Tox_Event_Dht_Nodes_Res
return dht_nodes_response->ip; return dht_nodes_response->ip;
} }
non_null() static bool tox_event_dht_nodes_response_set_port(Tox_Event_Dht_Nodes_Response *_Nonnull dht_nodes_response, uint16_t port)
static bool tox_event_dht_nodes_response_set_port(Tox_Event_Dht_Nodes_Response *dht_nodes_response, uint16_t port)
{ {
dht_nodes_response->port = port; dht_nodes_response->port = port;
return true; return true;
@@ -82,8 +78,7 @@ uint16_t tox_event_dht_nodes_response_get_port(const Tox_Event_Dht_Nodes_Respons
return dht_nodes_response->port; return dht_nodes_response->port;
} }
non_null() static void tox_event_dht_nodes_response_construct(Tox_Event_Dht_Nodes_Response *_Nonnull dht_nodes_response)
static void tox_event_dht_nodes_response_construct(Tox_Event_Dht_Nodes_Response *dht_nodes_response)
{ {
*dht_nodes_response = (Tox_Event_Dht_Nodes_Response) { *dht_nodes_response = (Tox_Event_Dht_Nodes_Response) {
{ {
@@ -91,8 +86,7 @@ static void tox_event_dht_nodes_response_construct(Tox_Event_Dht_Nodes_Response
} }
}; };
} }
non_null() static void tox_event_dht_nodes_response_destruct(Tox_Event_Dht_Nodes_Response *_Nonnull dht_nodes_response, const Memory *_Nonnull mem)
static void tox_event_dht_nodes_response_destruct(Tox_Event_Dht_Nodes_Response *dht_nodes_response, const Memory *mem)
{ {
mem_delete(mem, dht_nodes_response->ip); mem_delete(mem, dht_nodes_response->ip);
} }
@@ -106,9 +100,7 @@ bool tox_event_dht_nodes_response_pack(
&& bin_pack_u16(bp, event->port); && bin_pack_u16(bp, event->port);
} }
non_null() static bool tox_event_dht_nodes_response_unpack_into(Tox_Event_Dht_Nodes_Response *_Nonnull event, Bin_Unpack *_Nonnull bu)
static bool tox_event_dht_nodes_response_unpack_into(
Tox_Event_Dht_Nodes_Response *event, Bin_Unpack *bu)
{ {
if (!bin_unpack_array_fixed(bu, 3, nullptr)) { if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
return false; return false;
@@ -146,8 +138,7 @@ void tox_event_dht_nodes_response_free(Tox_Event_Dht_Nodes_Response *dht_nodes_r
mem_delete(mem, dht_nodes_response); mem_delete(mem, dht_nodes_response);
} }
non_null() static Tox_Event_Dht_Nodes_Response *tox_events_add_dht_nodes_response(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
static Tox_Event_Dht_Nodes_Response *tox_events_add_dht_nodes_response(Tox_Events *events, const Memory *mem)
{ {
Tox_Event_Dht_Nodes_Response *const dht_nodes_response = tox_event_dht_nodes_response_new(mem); Tox_Event_Dht_Nodes_Response *const dht_nodes_response = tox_event_dht_nodes_response_new(mem);
@@ -178,8 +169,7 @@ bool tox_event_dht_nodes_response_unpack(
return tox_event_dht_nodes_response_unpack_into(*event, bu); return tox_event_dht_nodes_response_unpack_into(*event, bu);
} }
non_null() static Tox_Event_Dht_Nodes_Response *tox_event_dht_nodes_response_alloc(void *_Nonnull user_data)
static Tox_Event_Dht_Nodes_Response *tox_event_dht_nodes_response_alloc(void *user_data)
{ {
Tox_Events_State *state = tox_events_alloc(user_data); Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr); assert(state != nullptr);

View File

@@ -16,17 +16,17 @@ extern "C" {
#endif #endif
struct Tox_Events { struct Tox_Events {
Tox_Event *events; Tox_Event *_Nonnull events;
uint32_t events_size; uint32_t events_size;
uint32_t events_capacity; uint32_t events_capacity;
const Memory *mem; const Memory *_Nonnull mem;
}; };
typedef struct Tox_Events_State { typedef struct Tox_Events_State {
Tox_Err_Events_Iterate error; Tox_Err_Events_Iterate error;
const Memory *mem; const Memory *_Nonnull mem;
Tox_Events *events; Tox_Events *_Nonnull events;
} Tox_Events_State; } Tox_Events_State;
tox_conference_connected_cb tox_events_handle_conference_connected; tox_conference_connected_cb tox_events_handle_conference_connected;
@@ -70,11 +70,9 @@ tox_group_self_join_cb tox_events_handle_group_self_join;
tox_group_join_fail_cb tox_events_handle_group_join_fail; tox_group_join_fail_cb tox_events_handle_group_join_fail;
tox_group_moderation_cb tox_events_handle_group_moderation; tox_group_moderation_cb tox_events_handle_group_moderation;
non_null() Tox_Events_State *_Nonnull tox_events_alloc(void *_Nonnull user_data);
Tox_Events_State *tox_events_alloc(void *user_data);
non_null() bool tox_events_add(Tox_Events *_Nonnull events, const Tox_Event *_Nonnull event);
bool tox_events_add(Tox_Events *events, const Tox_Event *event);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View File

@@ -28,9 +28,7 @@ struct Tox_Event_File_Chunk_Request {
uint16_t length; uint16_t length;
}; };
non_null() static void tox_event_file_chunk_request_set_friend_number(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, uint32_t friend_number)
static void tox_event_file_chunk_request_set_friend_number(Tox_Event_File_Chunk_Request *file_chunk_request,
uint32_t friend_number)
{ {
assert(file_chunk_request != nullptr); assert(file_chunk_request != nullptr);
file_chunk_request->friend_number = friend_number; file_chunk_request->friend_number = friend_number;
@@ -41,9 +39,7 @@ uint32_t tox_event_file_chunk_request_get_friend_number(const Tox_Event_File_Chu
return file_chunk_request->friend_number; return file_chunk_request->friend_number;
} }
non_null() static void tox_event_file_chunk_request_set_file_number(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, uint32_t file_number)
static void tox_event_file_chunk_request_set_file_number(Tox_Event_File_Chunk_Request *file_chunk_request,
uint32_t file_number)
{ {
assert(file_chunk_request != nullptr); assert(file_chunk_request != nullptr);
file_chunk_request->file_number = file_number; file_chunk_request->file_number = file_number;
@@ -54,9 +50,7 @@ uint32_t tox_event_file_chunk_request_get_file_number(const Tox_Event_File_Chunk
return file_chunk_request->file_number; return file_chunk_request->file_number;
} }
non_null() static void tox_event_file_chunk_request_set_position(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, uint64_t position)
static void tox_event_file_chunk_request_set_position(Tox_Event_File_Chunk_Request *file_chunk_request,
uint64_t position)
{ {
assert(file_chunk_request != nullptr); assert(file_chunk_request != nullptr);
file_chunk_request->position = position; file_chunk_request->position = position;
@@ -67,9 +61,7 @@ uint64_t tox_event_file_chunk_request_get_position(const Tox_Event_File_Chunk_Re
return file_chunk_request->position; return file_chunk_request->position;
} }
non_null() static void tox_event_file_chunk_request_set_length(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, uint16_t length)
static void tox_event_file_chunk_request_set_length(Tox_Event_File_Chunk_Request *file_chunk_request,
uint16_t length)
{ {
assert(file_chunk_request != nullptr); assert(file_chunk_request != nullptr);
file_chunk_request->length = length; file_chunk_request->length = length;
@@ -80,15 +72,13 @@ uint16_t tox_event_file_chunk_request_get_length(const Tox_Event_File_Chunk_Requ
return file_chunk_request->length; return file_chunk_request->length;
} }
non_null() static void tox_event_file_chunk_request_construct(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request)
static void tox_event_file_chunk_request_construct(Tox_Event_File_Chunk_Request *file_chunk_request)
{ {
*file_chunk_request = (Tox_Event_File_Chunk_Request) { *file_chunk_request = (Tox_Event_File_Chunk_Request) {
0 0
}; };
} }
non_null() static void tox_event_file_chunk_request_destruct(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, const Memory *_Nonnull mem)
static void tox_event_file_chunk_request_destruct(Tox_Event_File_Chunk_Request *file_chunk_request, const Memory *mem)
{ {
return; return;
} }
@@ -103,9 +93,7 @@ bool tox_event_file_chunk_request_pack(
&& bin_pack_u16(bp, event->length); && bin_pack_u16(bp, event->length);
} }
non_null() static bool tox_event_file_chunk_request_unpack_into(Tox_Event_File_Chunk_Request *_Nonnull event, Bin_Unpack *_Nonnull bu)
static bool tox_event_file_chunk_request_unpack_into(
Tox_Event_File_Chunk_Request *event, Bin_Unpack *bu)
{ {
assert(event != nullptr); assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 4, nullptr)) { if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
@@ -150,8 +138,7 @@ void tox_event_file_chunk_request_free(Tox_Event_File_Chunk_Request *file_chunk_
mem_delete(mem, file_chunk_request); mem_delete(mem, file_chunk_request);
} }
non_null() static Tox_Event_File_Chunk_Request *tox_events_add_file_chunk_request(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
static Tox_Event_File_Chunk_Request *tox_events_add_file_chunk_request(Tox_Events *events, const Memory *mem)
{ {
Tox_Event_File_Chunk_Request *const file_chunk_request = tox_event_file_chunk_request_new(mem); Tox_Event_File_Chunk_Request *const file_chunk_request = tox_event_file_chunk_request_new(mem);
@@ -184,8 +171,7 @@ bool tox_event_file_chunk_request_unpack(
return tox_event_file_chunk_request_unpack_into(*event, bu); return tox_event_file_chunk_request_unpack_into(*event, bu);
} }
non_null() static Tox_Event_File_Chunk_Request *tox_event_file_chunk_request_alloc(void *_Nonnull user_data)
static Tox_Event_File_Chunk_Request *tox_event_file_chunk_request_alloc(void *user_data)
{ {
Tox_Events_State *state = tox_events_alloc(user_data); Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr); assert(state != nullptr);

View File

@@ -32,9 +32,7 @@ struct Tox_Event_File_Recv {
uint32_t filename_length; uint32_t filename_length;
}; };
non_null() static void tox_event_file_recv_set_friend_number(Tox_Event_File_Recv *_Nonnull file_recv, uint32_t friend_number)
static void tox_event_file_recv_set_friend_number(Tox_Event_File_Recv *file_recv,
uint32_t friend_number)
{ {
assert(file_recv != nullptr); assert(file_recv != nullptr);
file_recv->friend_number = friend_number; file_recv->friend_number = friend_number;
@@ -45,9 +43,7 @@ uint32_t tox_event_file_recv_get_friend_number(const Tox_Event_File_Recv *file_r
return file_recv->friend_number; return file_recv->friend_number;
} }
non_null() static void tox_event_file_recv_set_file_number(Tox_Event_File_Recv *_Nonnull file_recv, uint32_t file_number)
static void tox_event_file_recv_set_file_number(Tox_Event_File_Recv *file_recv,
uint32_t file_number)
{ {
assert(file_recv != nullptr); assert(file_recv != nullptr);
file_recv->file_number = file_number; file_recv->file_number = file_number;
@@ -58,9 +54,7 @@ uint32_t tox_event_file_recv_get_file_number(const Tox_Event_File_Recv *file_rec
return file_recv->file_number; return file_recv->file_number;
} }
non_null() static void tox_event_file_recv_set_kind(Tox_Event_File_Recv *_Nonnull file_recv, uint32_t kind)
static void tox_event_file_recv_set_kind(Tox_Event_File_Recv *file_recv,
uint32_t kind)
{ {
assert(file_recv != nullptr); assert(file_recv != nullptr);
file_recv->kind = kind; file_recv->kind = kind;
@@ -71,9 +65,7 @@ uint32_t tox_event_file_recv_get_kind(const Tox_Event_File_Recv *file_recv)
return file_recv->kind; return file_recv->kind;
} }
non_null() static void tox_event_file_recv_set_file_size(Tox_Event_File_Recv *_Nonnull file_recv, uint64_t file_size)
static void tox_event_file_recv_set_file_size(Tox_Event_File_Recv *file_recv,
uint64_t file_size)
{ {
assert(file_recv != nullptr); assert(file_recv != nullptr);
file_recv->file_size = file_size; file_recv->file_size = file_size;
@@ -84,12 +76,10 @@ uint64_t tox_event_file_recv_get_file_size(const Tox_Event_File_Recv *file_recv)
return file_recv->file_size; return file_recv->file_size;
} }
non_null(1) nullable(2) static bool tox_event_file_recv_set_filename(Tox_Event_File_Recv *_Nonnull file_recv,
static bool tox_event_file_recv_set_filename(Tox_Event_File_Recv *file_recv, const uint8_t *_Nullable filename, uint32_t filename_length)
const uint8_t *filename, uint32_t filename_length)
{ {
assert(file_recv != nullptr); assert(file_recv != nullptr);
if (file_recv->filename != nullptr) { if (file_recv->filename != nullptr) {
free(file_recv->filename); free(file_recv->filename);
file_recv->filename = nullptr; file_recv->filename = nullptr;
@@ -123,15 +113,13 @@ const uint8_t *tox_event_file_recv_get_filename(const Tox_Event_File_Recv *file_
return file_recv->filename; return file_recv->filename;
} }
non_null() static void tox_event_file_recv_construct(Tox_Event_File_Recv *_Nonnull file_recv)
static void tox_event_file_recv_construct(Tox_Event_File_Recv *file_recv)
{ {
*file_recv = (Tox_Event_File_Recv) { *file_recv = (Tox_Event_File_Recv) {
0 0
}; };
} }
non_null() static void tox_event_file_recv_destruct(Tox_Event_File_Recv *_Nonnull file_recv, const Memory *_Nonnull mem)
static void tox_event_file_recv_destruct(Tox_Event_File_Recv *file_recv, const Memory *mem)
{ {
free(file_recv->filename); free(file_recv->filename);
} }
@@ -147,9 +135,7 @@ bool tox_event_file_recv_pack(
&& bin_pack_bin(bp, event->filename, event->filename_length); && bin_pack_bin(bp, event->filename, event->filename_length);
} }
non_null() static bool tox_event_file_recv_unpack_into(Tox_Event_File_Recv *_Nonnull event, Bin_Unpack *_Nonnull bu)
static bool tox_event_file_recv_unpack_into(
Tox_Event_File_Recv *event, Bin_Unpack *bu)
{ {
assert(event != nullptr); assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 5, nullptr)) { if (!bin_unpack_array_fixed(bu, 5, nullptr)) {
@@ -195,8 +181,7 @@ void tox_event_file_recv_free(Tox_Event_File_Recv *file_recv, const Memory *mem)
mem_delete(mem, file_recv); mem_delete(mem, file_recv);
} }
non_null() static Tox_Event_File_Recv *tox_events_add_file_recv(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
static Tox_Event_File_Recv *tox_events_add_file_recv(Tox_Events *events, const Memory *mem)
{ {
Tox_Event_File_Recv *const file_recv = tox_event_file_recv_new(mem); Tox_Event_File_Recv *const file_recv = tox_event_file_recv_new(mem);
@@ -229,8 +214,7 @@ bool tox_event_file_recv_unpack(
return tox_event_file_recv_unpack_into(*event, bu); return tox_event_file_recv_unpack_into(*event, bu);
} }
non_null() static Tox_Event_File_Recv *tox_event_file_recv_alloc(void *_Nonnull user_data)
static Tox_Event_File_Recv *tox_event_file_recv_alloc(void *user_data)
{ {
Tox_Events_State *state = tox_events_alloc(user_data); Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr); assert(state != nullptr);

View File

@@ -31,9 +31,7 @@ struct Tox_Event_File_Recv_Chunk {
uint32_t data_length; uint32_t data_length;
}; };
non_null() static void tox_event_file_recv_chunk_set_friend_number(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk, uint32_t friend_number)
static void tox_event_file_recv_chunk_set_friend_number(Tox_Event_File_Recv_Chunk *file_recv_chunk,
uint32_t friend_number)
{ {
assert(file_recv_chunk != nullptr); assert(file_recv_chunk != nullptr);
file_recv_chunk->friend_number = friend_number; file_recv_chunk->friend_number = friend_number;
@@ -44,9 +42,7 @@ uint32_t tox_event_file_recv_chunk_get_friend_number(const Tox_Event_File_Recv_C
return file_recv_chunk->friend_number; return file_recv_chunk->friend_number;
} }
non_null() static void tox_event_file_recv_chunk_set_file_number(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk, uint32_t file_number)
static void tox_event_file_recv_chunk_set_file_number(Tox_Event_File_Recv_Chunk *file_recv_chunk,
uint32_t file_number)
{ {
assert(file_recv_chunk != nullptr); assert(file_recv_chunk != nullptr);
file_recv_chunk->file_number = file_number; file_recv_chunk->file_number = file_number;
@@ -57,9 +53,7 @@ uint32_t tox_event_file_recv_chunk_get_file_number(const Tox_Event_File_Recv_Chu
return file_recv_chunk->file_number; return file_recv_chunk->file_number;
} }
non_null() static void tox_event_file_recv_chunk_set_position(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk, uint64_t position)
static void tox_event_file_recv_chunk_set_position(Tox_Event_File_Recv_Chunk *file_recv_chunk,
uint64_t position)
{ {
assert(file_recv_chunk != nullptr); assert(file_recv_chunk != nullptr);
file_recv_chunk->position = position; file_recv_chunk->position = position;
@@ -70,12 +64,10 @@ uint64_t tox_event_file_recv_chunk_get_position(const Tox_Event_File_Recv_Chunk
return file_recv_chunk->position; return file_recv_chunk->position;
} }
non_null(1) nullable(2) static bool tox_event_file_recv_chunk_set_data(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk,
static bool tox_event_file_recv_chunk_set_data(Tox_Event_File_Recv_Chunk *file_recv_chunk, const uint8_t *_Nullable data, uint32_t data_length)
const uint8_t *data, uint32_t data_length)
{ {
assert(file_recv_chunk != nullptr); assert(file_recv_chunk != nullptr);
if (file_recv_chunk->data != nullptr) { if (file_recv_chunk->data != nullptr) {
free(file_recv_chunk->data); free(file_recv_chunk->data);
file_recv_chunk->data = nullptr; file_recv_chunk->data = nullptr;
@@ -109,15 +101,13 @@ const uint8_t *tox_event_file_recv_chunk_get_data(const Tox_Event_File_Recv_Chun
return file_recv_chunk->data; return file_recv_chunk->data;
} }
non_null() static void tox_event_file_recv_chunk_construct(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk)
static void tox_event_file_recv_chunk_construct(Tox_Event_File_Recv_Chunk *file_recv_chunk)
{ {
*file_recv_chunk = (Tox_Event_File_Recv_Chunk) { *file_recv_chunk = (Tox_Event_File_Recv_Chunk) {
0 0
}; };
} }
non_null() static void tox_event_file_recv_chunk_destruct(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk, const Memory *_Nonnull mem)
static void tox_event_file_recv_chunk_destruct(Tox_Event_File_Recv_Chunk *file_recv_chunk, const Memory *mem)
{ {
free(file_recv_chunk->data); free(file_recv_chunk->data);
} }
@@ -132,9 +122,7 @@ bool tox_event_file_recv_chunk_pack(
&& bin_pack_bin(bp, event->data, event->data_length); && bin_pack_bin(bp, event->data, event->data_length);
} }
non_null() static bool tox_event_file_recv_chunk_unpack_into(Tox_Event_File_Recv_Chunk *_Nonnull event, Bin_Unpack *_Nonnull bu)
static bool tox_event_file_recv_chunk_unpack_into(
Tox_Event_File_Recv_Chunk *event, Bin_Unpack *bu)
{ {
assert(event != nullptr); assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 4, nullptr)) { if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
@@ -179,8 +167,7 @@ void tox_event_file_recv_chunk_free(Tox_Event_File_Recv_Chunk *file_recv_chunk,
mem_delete(mem, file_recv_chunk); mem_delete(mem, file_recv_chunk);
} }
non_null() static Tox_Event_File_Recv_Chunk *tox_events_add_file_recv_chunk(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
static Tox_Event_File_Recv_Chunk *tox_events_add_file_recv_chunk(Tox_Events *events, const Memory *mem)
{ {
Tox_Event_File_Recv_Chunk *const file_recv_chunk = tox_event_file_recv_chunk_new(mem); Tox_Event_File_Recv_Chunk *const file_recv_chunk = tox_event_file_recv_chunk_new(mem);
@@ -213,8 +200,7 @@ bool tox_event_file_recv_chunk_unpack(
return tox_event_file_recv_chunk_unpack_into(*event, bu); return tox_event_file_recv_chunk_unpack_into(*event, bu);
} }
non_null() static Tox_Event_File_Recv_Chunk *tox_event_file_recv_chunk_alloc(void *_Nonnull user_data)
static Tox_Event_File_Recv_Chunk *tox_event_file_recv_chunk_alloc(void *user_data)
{ {
Tox_Events_State *state = tox_events_alloc(user_data); Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr); assert(state != nullptr);

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