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:
@@ -125,15 +125,12 @@ jobs:
|
||||
cimple:
|
||||
working_directory: /tmp/cirrus-ci-build
|
||||
docker:
|
||||
- image: toxchat/toktok-stack:latest-release
|
||||
- image: toxchat/toktok-stack:latest
|
||||
|
||||
steps:
|
||||
- checkout
|
||||
- run: git submodule update --init --recursive
|
||||
- run: /src/workspace/tools/inject-repo c-toxcore
|
||||
- run: cd /src/workspace &&
|
||||
bazel test
|
||||
-k
|
||||
- run:
|
||||
CIRCLE_JOB=release bash <(curl -s https://raw.githubusercontent.com/TokTok/ci-tools/refs/heads/master/tools/circleci-bazel-test)
|
||||
--build_tag_filters=haskell
|
||||
--test_tag_filters=haskell
|
||||
--
|
||||
|
8
.github/scripts/cmake-osx
vendored
8
.github/scripts/cmake-osx
vendored
@@ -23,6 +23,7 @@ add_flag -Werror
|
||||
# C99-only compilers we test against anyway. Anything that passes all the
|
||||
# compilers we use is fine.
|
||||
add_c_flag -Wno-c11-extensions
|
||||
add_c_flag -Wno-pre-c11-compat
|
||||
|
||||
cmake -B_build -H. \
|
||||
-DCMAKE_C_FLAGS="$C_FLAGS" \
|
||||
@@ -39,6 +40,9 @@ cmake -B_build -H. \
|
||||
|
||||
cd _build # pushd
|
||||
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
|
||||
|
7
.github/scripts/flags-clang.sh
vendored
7
.github/scripts/flags-clang.sh
vendored
@@ -9,6 +9,11 @@ add_flag -Weverything
|
||||
|
||||
# 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
|
||||
# conversions that change sign without a cast and narrowing conversions.
|
||||
add_flag -Wno-conversion
|
||||
@@ -30,6 +35,8 @@ add_flag -Wno-missing-braces
|
||||
add_flag -Wno-missing-field-initializers
|
||||
# We don't use this attribute. It appears in the non-NDEBUG stderr logger.
|
||||
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.
|
||||
# Reordering fields to avoid padding will reduce readability.
|
||||
add_flag -Wno-padded
|
||||
|
1
.github/scripts/sonar-prepare
vendored
1
.github/scripts/sonar-prepare
vendored
@@ -17,6 +17,7 @@ add_ld_flag -Wl,-z,defs
|
||||
add_flag -Werror
|
||||
|
||||
cmake -B_build -H. -GNinja \
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
||||
-DCMAKE_C_FLAGS="$C_FLAGS" \
|
||||
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
|
||||
-DCMAKE_EXE_LINKER_FLAGS="$LD_FLAGS" \
|
||||
|
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@@ -72,7 +72,7 @@ jobs:
|
||||
build-windows-msvc:
|
||||
strategy:
|
||||
matrix:
|
||||
version: [2019, 2022]
|
||||
version: [2022, 2025]
|
||||
runs-on: windows-${{ matrix.version }}
|
||||
env:
|
||||
VCPKG_ROOT: "C:/vcpkg"
|
||||
@@ -116,12 +116,12 @@ jobs:
|
||||
libopus
|
||||
libsodium
|
||||
libvpx
|
||||
ninja
|
||||
ninja-build
|
||||
pkg-config
|
||||
|
||||
run: |
|
||||
# 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 . \
|
||||
-DMIN_LOGGER_LEVEL=TRACE \
|
||||
-DMUST_BUILD_TOXAV=ON \
|
||||
|
12
.github/workflows/deploy.yml
vendored
12
.github/workflows/deploy.yml
vendored
@@ -345,14 +345,12 @@ jobs:
|
||||
uses: TokTok/ci-tools/.github/workflows/deploy-artifact.yml@master
|
||||
with:
|
||||
project-name: toxcore
|
||||
artifact-source: tox-*.tar.{gz,xz}
|
||||
artifact-versioned: $VERSION.tar.{gz,xz}
|
||||
artifact-source: toxcore.tar.{gz,xz}
|
||||
artifact-versioned: c-toxcore-$VERSION.tar.{gz,xz}
|
||||
build: tarball
|
||||
run: |
|
||||
sudo apt-get install -y --no-install-recommends libsodium-dev
|
||||
autoreconf -fi
|
||||
./configure
|
||||
make dist
|
||||
for f in tox-*.tar.gz; do
|
||||
gunzip -c "$f" | xz -z - >"${f%.gz}.xz"
|
||||
done
|
||||
touch toxcore.tar.gz # prevent error of file changes
|
||||
tar --exclude-vcs --exclude='toxcore.tar.gz' --exclude='third_party/ci-tools' --exclude='*.github' --exclude='autom4te.cache' -zcvf toxcore.tar.gz .
|
||||
gunzip -c toxcore.tar.gz | xz -z - >"toxcore.tar.xz"
|
||||
|
38
.github/workflows/sonar-scan.yml
vendored
38
.github/workflows/sonar-scan.yml
vendored
@@ -8,50 +8,34 @@ on:
|
||||
|
||||
# Cancel old PR builds when pushing new commits.
|
||||
concurrency:
|
||||
group: scan-${{ github.event.pull_request.number || github.ref }}
|
||||
group: sonar-scan-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
sonar-scan:
|
||||
runs-on: ubuntu-latest
|
||||
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
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||
submodules: recursive
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v2
|
||||
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 Build Wrapper
|
||||
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v6
|
||||
- name: Install dependencies and prepare build
|
||||
run: |
|
||||
.github/scripts/sonar-prepare
|
||||
- name: Run build-wrapper
|
||||
- name: Run Build Wrapper
|
||||
run: |
|
||||
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'
|
||||
uses: SonarSource/sonarqube-scan-action@v6
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_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"
|
||||
|
@@ -544,8 +544,8 @@ static void test_client(void)
|
||||
|
||||
// The connection status should be unconfirmed here because we have finished
|
||||
// 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.",
|
||||
TCP_CLIENT_UNCONFIRMED, tcp_con_status(conn));
|
||||
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_UNCONFIRMED, "Wrong connection status. Expected: %u, is: %u.",
|
||||
(unsigned int)TCP_CLIENT_UNCONFIRMED, tcp_con_status(conn));
|
||||
|
||||
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.
|
||||
|
||||
// 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",
|
||||
TCP_CLIENT_CONFIRMED, tcp_con_status(conn));
|
||||
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONFIRMED, "Wrong connection status. Expected: %u, is: %u",
|
||||
(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.
|
||||
}
|
||||
@@ -565,7 +565,7 @@ static void test_client(void)
|
||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||
|
||||
// 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));
|
||||
|
||||
uint8_t f2_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
@@ -680,20 +680,20 @@ static void test_client_invalid(void)
|
||||
c_sleep(50);
|
||||
|
||||
// After 50ms of no response...
|
||||
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %d, is: %d.",
|
||||
TCP_CLIENT_CONNECTING, tcp_con_status(conn));
|
||||
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %u, is: %u.",
|
||||
(unsigned int)TCP_CLIENT_CONNECTING, tcp_con_status(conn));
|
||||
// After 5s...
|
||||
c_sleep(5000);
|
||||
mono_time_update(mono_time);
|
||||
do_tcp_connection(logger, mono_time, conn, nullptr);
|
||||
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %d, is: %d.",
|
||||
TCP_CLIENT_CONNECTING, tcp_con_status(conn));
|
||||
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %u, is: %u.",
|
||||
(unsigned int)TCP_CLIENT_CONNECTING, tcp_con_status(conn));
|
||||
// 11s... (Should wait for 10 before giving up.)
|
||||
c_sleep(6000);
|
||||
mono_time_update(mono_time);
|
||||
do_tcp_connection(logger, mono_time, conn, nullptr);
|
||||
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %d, is: %d.",
|
||||
TCP_CLIENT_DISCONNECTED, tcp_con_status(conn));
|
||||
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %u, is: %u.",
|
||||
(unsigned int)TCP_CLIENT_DISCONNECTED, tcp_con_status(conn));
|
||||
|
||||
kill_tcp_connection(conn);
|
||||
|
||||
|
@@ -79,14 +79,14 @@ void bootstrap_tox_live_network(Tox *tox, bool enable_tcp)
|
||||
tox_bootstrap(tox, ip, port, key, &err);
|
||||
|
||||
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) {
|
||||
tox_add_tcp_relay(tox, ip, port, key, &err);
|
||||
|
||||
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);
|
||||
autotest_opts->tcp_port = 0;
|
||||
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 {
|
||||
// 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) {
|
||||
@@ -259,7 +259,7 @@ static void initialise_autotox(struct Tox_Options *options, AutoTox *autotox, ui
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -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) {
|
||||
Tox_Err_Bootstrap 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) {
|
||||
|
@@ -25,8 +25,8 @@ int main(void)
|
||||
|
||||
const Tox_Connection status = tox_self_get_connection_status(tox_udp);
|
||||
ck_assert_msg(status == TOX_CONNECTION_UDP,
|
||||
"expected connection status to be UDP, but got %d", status);
|
||||
printf("Connection (UDP): %d\n", tox_self_get_connection_status(tox_udp));
|
||||
"expected connection status to be UDP, but got %u", status);
|
||||
printf("Connection (UDP): %u\n", tox_self_get_connection_status(tox_udp));
|
||||
|
||||
tox_kill(tox_udp);
|
||||
|
||||
|
@@ -83,7 +83,7 @@ static void handle_conference_invite(
|
||||
const uint8_t *cookie = tox_event_conference_invite_get_cookie(event);
|
||||
const size_t length = tox_event_conference_invite_get_cookie_length(event);
|
||||
|
||||
ck_assert_msg(type == TOX_CONFERENCE_TYPE_AV, "tox #%u: wrong conference type: %d", autotox->index, type);
|
||||
ck_assert_msg(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,
|
||||
"tox #%u: failed to join group", autotox->index);
|
||||
@@ -101,7 +101,7 @@ static void handle_conference_connected(
|
||||
|
||||
Tox_Err_Conference_Invite 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);
|
||||
printf("tox #%u: invited next friend\n", autotox->index);
|
||||
state->invited_next = true;
|
||||
|
@@ -22,7 +22,7 @@ static void handle_conference_invite(
|
||||
const uint8_t *cookie = tox_event_conference_invite_get_cookie(event);
|
||||
const size_t length = tox_event_conference_invite_get_cookie_length(event);
|
||||
|
||||
fprintf(stderr, "handle_conference_invite(#%u, %u, %d, uint8_t[%u], _)\n",
|
||||
fprintf(stderr, "handle_conference_invite(#%u, %u, %u, uint8_t[%u], _)\n",
|
||||
autotox->index, friend_number, type, (unsigned)length);
|
||||
fprintf(stderr, "tox%u joining conference\n", autotox->index);
|
||||
|
||||
@@ -32,7 +32,7 @@ static void handle_conference_invite(
|
||||
Tox_Err_Conference_Join err;
|
||||
state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK,
|
||||
"attempting to join the conference returned with an error: %d", err);
|
||||
"attempting to join the conference returned with an error: %u", err);
|
||||
fprintf(stderr, "tox%u joined conference %u\n", autotox->index, state->conference);
|
||||
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]->joined = true;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ static void conference_double_invite_test(AutoTox *autotoxes)
|
||||
Tox_Err_Conference_Invite err;
|
||||
tox_conference_invite(autotoxes[0].tox, 0, state[0]->conference, &err);
|
||||
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");
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,7 @@ static void handle_conference_invite(
|
||||
Tox_Err_Conference_Join err;
|
||||
state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK,
|
||||
"attempting to join the conference returned with an error: %d", err);
|
||||
"attempting to join the conference returned with an error: %u", err);
|
||||
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_conference_invite(inviter->tox, friendnum, ((State *)inviter->state)->conference, &err);
|
||||
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);
|
||||
|
||||
do {
|
||||
@@ -110,7 +110,7 @@ static void conference_invite_merge_test(AutoTox *autotoxes)
|
||||
state2->conference = tox_conference_new(autotoxes[2].tox, &err);
|
||||
state2->connected = true;
|
||||
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);
|
||||
}
|
||||
|
||||
|
@@ -23,14 +23,14 @@ static void handle_conference_invite(
|
||||
const uint8_t *cookie = tox_event_conference_invite_get_cookie(event);
|
||||
const size_t length = tox_event_conference_invite_get_cookie_length(event);
|
||||
|
||||
fprintf(stderr, "handle_conference_invite(#%u, %u, %d, uint8_t[%u], _)\n",
|
||||
fprintf(stderr, "handle_conference_invite(#%u, %u, %u, uint8_t[%u], _)\n",
|
||||
autotox->index, friend_number, type, (unsigned)length);
|
||||
fprintf(stderr, "tox%u joining conference\n", autotox->index);
|
||||
|
||||
Tox_Err_Conference_Join err;
|
||||
state->conference = tox_conference_join(autotox->tox, friend_number, cookie, length, &err);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK,
|
||||
"attempting to join the conference returned with an error: %d", err);
|
||||
"attempting to join the conference returned with an error: %u", err);
|
||||
fprintf(stderr, "tox%u joined conference %u\n", autotox->index, state->conference);
|
||||
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;
|
||||
uint32_t const count = tox_conference_peer_count(autotox->tox, conference_number, &err);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
|
||||
"failed to get conference peer count: err = %d", err);
|
||||
"failed to get conference peer count: err = %u", err);
|
||||
printf("tox%u has %u peers\n", autotox->index, count);
|
||||
state->friend_in_group = count == 2;
|
||||
}
|
||||
@@ -60,18 +60,18 @@ static void rebuild_peer_list(Tox *tox)
|
||||
Tox_Err_Conference_Peer_Query err;
|
||||
uint32_t const count = tox_conference_peer_count(tox, conference_number, &err);
|
||||
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++) {
|
||||
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,
|
||||
"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);
|
||||
ck_assert(name != nullptr);
|
||||
tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -99,7 +99,7 @@ static void conference_peer_nick_test(AutoTox *autotoxes)
|
||||
state[0]->conference = tox_conference_new(autotoxes[0].tox, &err);
|
||||
state[0]->joined = true;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ static void conference_peer_nick_test(AutoTox *autotoxes)
|
||||
Tox_Err_Conference_Invite err;
|
||||
tox_conference_invite(autotoxes[0].tox, 0, state[0]->conference, &err);
|
||||
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");
|
||||
}
|
||||
|
||||
|
@@ -28,7 +28,7 @@ static void handle_self_connection_status(const Tox_Event_Self_Connection_Status
|
||||
State *state = (State *)user_data;
|
||||
|
||||
const Tox_Connection connection_status = tox_event_self_connection_status_get_connection_status(event);
|
||||
fprintf(stderr, "self_connection_status(#%u, %d, _)\n", state->id, connection_status);
|
||||
fprintf(stderr, "self_connection_status(#%u, %u, _)\n", state->id, connection_status);
|
||||
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 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;
|
||||
}
|
||||
|
||||
@@ -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 uint8_t *cookie = tox_event_conference_invite_get_cookie(event);
|
||||
const size_t length = tox_event_conference_invite_get_cookie_length(event);
|
||||
fprintf(stderr, "handle_conference_invite(#%u, %u, %d, uint8_t[%u], _)\n",
|
||||
fprintf(stderr, "handle_conference_invite(#%u, %u, %u, uint8_t[%u], _)\n",
|
||||
state->id, friend_number, type, (unsigned)length);
|
||||
fprintf(stderr, "tox%u joining conference\n", state->id);
|
||||
|
||||
{
|
||||
Tox_Err_Conference_Join err;
|
||||
state->conference = tox_conference_join(state->tox, friend_number, cookie, length, &err);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "failed to join a conference: err = %d", err);
|
||||
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);
|
||||
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 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);
|
||||
|
||||
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);
|
||||
|
||||
if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
|
||||
fprintf(stderr, "ERROR: %d\n", err);
|
||||
fprintf(stderr, "ERROR: %u\n", err);
|
||||
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) {
|
||||
Tox_Err_Conference_Invite err;
|
||||
tox_conference_invite(state->tox, 1, state->conference, &err);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox2 failed to invite tox3: err = %d", err);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox2 failed to invite tox3: err = %u", err);
|
||||
|
||||
state->invited_next = true;
|
||||
fprintf(stderr, "tox2 invited tox3\n");
|
||||
@@ -209,7 +209,7 @@ int main(void)
|
||||
Tox_Err_Conference_New err;
|
||||
state1.conference = tox_conference_new(state1.tox, &err);
|
||||
state1.joined = true;
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create a conference: err = %d", err);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ int main(void)
|
||||
// Invite friend.
|
||||
Tox_Err_Conference_Invite err;
|
||||
tox_conference_invite(state1.tox, 0, state1.conference, &err);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "failed to invite a friend: err = %d", err);
|
||||
ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "failed to invite a friend: err = %u", err);
|
||||
state1.invited_next = true;
|
||||
fprintf(stderr, "tox1 invited tox2\n");
|
||||
}
|
||||
@@ -245,7 +245,7 @@ int main(void)
|
||||
(const uint8_t *)"hello!", 7, &err);
|
||||
|
||||
if (err != TOX_ERR_CONFERENCE_SEND_MESSAGE_OK) {
|
||||
fprintf(stderr, "ERROR: %d\n", err);
|
||||
fprintf(stderr, "ERROR: %u\n", err);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
@@ -53,12 +53,12 @@ static void handle_conference_invite(
|
||||
const uint8_t *data, size_t length, void *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;
|
||||
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);
|
||||
|
||||
// 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_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);
|
||||
printf("tox #%u: invited next friend\n", autotox->index);
|
||||
state->invited_next = true;
|
||||
@@ -206,7 +206,7 @@ static void run_conference_tests(AutoTox *autotoxes)
|
||||
Tox_Err_Conference_Set_Max_Offline err;
|
||||
tox_conference_set_max_offline(autotoxes[i].tox, 0, max_frozen, &err);
|
||||
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");
|
||||
|
@@ -17,9 +17,9 @@ int main(void)
|
||||
// Create two conferences and then exit.
|
||||
Tox_Err_Conference_New 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);
|
||||
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);
|
||||
|
||||
|
@@ -48,7 +48,7 @@ static void test_save_friend(void)
|
||||
ck_assert(enc_data != nullptr);
|
||||
Tox_Err_Encryption 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");
|
||||
|
||||
struct Tox_Options *options = tox_options_new(nullptr);
|
||||
@@ -58,17 +58,17 @@ static void test_save_friend(void)
|
||||
|
||||
Tox_Err_New err2;
|
||||
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,
|
||||
TOX_ERR_NEW_LOAD_ENCRYPTED);
|
||||
ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %d", err2,
|
||||
(int)TOX_ERR_NEW_LOAD_ENCRYPTED);
|
||||
ck_assert_msg(tox3 == nullptr, "tox_new with error should return NULL");
|
||||
uint8_t *dec_data = (uint8_t *)malloc(size);
|
||||
ck_assert(dec_data != nullptr);
|
||||
Tox_Err_Decryption 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);
|
||||
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];
|
||||
ret = tox_friend_get_public_key(tox3, 0, address2, nullptr);
|
||||
ck_assert_msg(ret, "no friends!");
|
||||
@@ -87,7 +87,7 @@ static void test_save_friend(void)
|
||||
uint8_t *encdata2 = (uint8_t *)malloc(size2);
|
||||
ck_assert(encdata2 != nullptr);
|
||||
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");
|
||||
|
||||
uint8_t *out1 = (uint8_t *)malloc(size);
|
||||
@@ -95,9 +95,9 @@ static void test_save_friend(void)
|
||||
uint8_t *out2 = (uint8_t *)malloc(size);
|
||||
ck_assert(out2 != nullptr);
|
||||
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);
|
||||
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");
|
||||
|
||||
// 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;
|
||||
const uint8_t *key_char = (const uint8_t *)"123qweasdzxc";
|
||||
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
|
||||
|
||||
uint8_t encrypted[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
|
||||
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.
|
||||
int size_large = 30 * 1024 * 1024;
|
||||
@@ -153,13 +153,13 @@ static void test_keys(void)
|
||||
ck_assert(rng != nullptr);
|
||||
random_bytes(rng, in_plaintext2a, plaintext_length2a);
|
||||
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.
|
||||
uint8_t *out_plaintext2a = (uint8_t *)malloc(plaintext_length2a);
|
||||
ck_assert(out_plaintext2a != nullptr);
|
||||
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");
|
||||
free(encrypted2a);
|
||||
free(in_plaintext2a);
|
||||
@@ -167,28 +167,28 @@ static void test_keys(void)
|
||||
|
||||
uint8_t encrypted2[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
|
||||
ret = tox_pass_encrypt(string, 44, key_char, 12, encrypted2, &encerr);
|
||||
ck_assert_msg(ret, "generic failure 3: %d", encerr);
|
||||
ck_assert_msg(ret, "generic failure 3: %u", encerr);
|
||||
|
||||
uint8_t out1[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);
|
||||
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");
|
||||
|
||||
ret = tox_pass_decrypt(encrypted2, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)"123qweasdzxc", 12, out2,
|
||||
&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");
|
||||
|
||||
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(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
|
||||
ret = tox_pass_decrypt(encrypted, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)"123qweasdzxc", 12, out1,
|
||||
&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");
|
||||
|
||||
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(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);
|
||||
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");
|
||||
tox_pass_key_free(key2);
|
||||
tox_pass_key_free(key);
|
||||
|
@@ -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,
|
||||
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);
|
||||
printf("written written_value = %u of %u\n", (unsigned)written_value, (unsigned)size);
|
||||
|
@@ -75,7 +75,7 @@ static void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_num
|
||||
Tox_Err_File_Control error;
|
||||
|
||||
ck_assert_msg(tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error),
|
||||
"tox_file_control failed. %i", error);
|
||||
"tox_file_control failed. %u", error);
|
||||
++file_accepted;
|
||||
|
||||
Tox_Err_File_Seek err_s;
|
||||
@@ -189,7 +189,7 @@ static void file_transfer_test(void)
|
||||
tox_iterate(tox2, 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(tox2),
|
||||
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
|
||||
&& 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,
|
||||
(unsigned long)totalf_size, (unsigned long)file_size,
|
||||
(unsigned long)size_recv, (unsigned long)sending_pos);
|
||||
|
@@ -89,7 +89,7 @@ static void tox_file_receive(const Tox_Event_File_Recv *event, void *userdata)
|
||||
Tox_Err_File_Control 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;
|
||||
|
||||
Tox_Err_File_Seek err_s;
|
||||
@@ -238,7 +238,7 @@ static void file_transfer_test(void)
|
||||
iterate_and_dispatch(dispatch2, tox2);
|
||||
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(tox2),
|
||||
tox_self_get_connection_status(tox3),
|
||||
@@ -285,7 +285,7 @@ static void file_transfer_test(void)
|
||||
if (file_sending_done) {
|
||||
ck_assert_msg(sendf_ok && file_recv && totalf_size == file_size && size_recv == file_size && sending_pos == size_recv
|
||||
&& 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,
|
||||
file_accepted == 1, (unsigned long)totalf_size, (unsigned long)size_recv,
|
||||
(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 "
|
||||
"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",
|
||||
(unsigned int)max_iterations, sendf_ok, file_recv,
|
||||
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
|
||||
&& 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,
|
||||
(unsigned long long)totalf_size, (unsigned long long)size_recv,
|
||||
(unsigned long long)sending_pos);
|
||||
|
@@ -49,7 +49,7 @@ static void test_friend_request(AutoTox *autotoxes)
|
||||
for (uint32_t i = 2; i < FR_TOX_COUNT; ++i) {
|
||||
Tox_Err_Friend_Add 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) {
|
||||
|
@@ -39,7 +39,7 @@ static void accept_friend_request(const Tox_Event_Friend_Request *event, void *u
|
||||
Tox_Err_Friend_Add 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)
|
||||
@@ -108,7 +108,7 @@ static void test_friend_request(const uint8_t *message, uint16_t length)
|
||||
Tox_Err_Friend_Add 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);
|
||||
|
||||
do {
|
||||
|
@@ -48,13 +48,13 @@ static void print_ip(const Tox *tox, uint32_t groupnumber, uint32_t peer_id)
|
||||
Tox_Err_Group_Peer_Query err;
|
||||
size_t length = tox_group_peer_get_ip_address_size(tox, groupnumber, peer_id, &err);
|
||||
|
||||
ck_assert_msg(err == TOX_ERR_GROUP_PEER_QUERY_OK, "failed to get ip address size: error %d", err);
|
||||
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];
|
||||
tox_group_peer_get_ip_address(tox, groupnumber, peer_id, ip_str, &err);
|
||||
ip_str[length] = '\0';
|
||||
|
||||
ck_assert_msg(err == TOX_ERR_GROUP_PEER_QUERY_OK, "failed to get ip address: error %d", err);
|
||||
ck_assert_msg(err == TOX_ERR_GROUP_PEER_QUERY_OK, "failed to get ip address: error %u", err);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
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);
|
||||
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
|
||||
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) {
|
||||
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(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0);
|
||||
} 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(memcmp(peer_name, PEER0_NICK2, peer_name_len) == 0);
|
||||
}
|
||||
} 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(memcmp(peer_name, PEER1_NICK, peer_name_len) == 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 {
|
||||
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_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);
|
||||
|
||||
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);
|
||||
|
||||
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_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);
|
||||
|
||||
state->peer_status = true;
|
||||
@@ -300,7 +300,7 @@ static void group_announce_test(AutoTox *autotoxes)
|
||||
// changes the state (for sync check purposes)
|
||||
Tox_Err_Group_Set_Peer_Limit limit_set_err;
|
||||
tox_group_set_peer_limit(tox0, groupnumber, PEER_LIMIT, &limit_set_err);
|
||||
ck_assert_msg(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK, "failed to set peer limit: %d", limit_set_err);
|
||||
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_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(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) {
|
||||
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
|
||||
|
@@ -130,7 +130,7 @@ static void group_invite_test(AutoTox *autotoxes)
|
||||
Tox_Err_Group_New new_err;
|
||||
uint32_t groupnumber = tox_group_new(tox0, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *)"test", 4,
|
||||
(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);
|
||||
|
||||
@@ -138,12 +138,12 @@ static void group_invite_test(AutoTox *autotoxes)
|
||||
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
|
||||
|
||||
tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err);
|
||||
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_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
|
||||
Tox_Err_Group_Join 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) {
|
||||
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
|
||||
@@ -154,13 +154,13 @@ static void group_invite_test(AutoTox *autotoxes)
|
||||
// founder sets a password
|
||||
Tox_Err_Group_Set_Password pass_set_err;
|
||||
tox_group_set_password(tox0, groupnumber, (const uint8_t *)PASSWORD, PASS_LEN, &pass_set_err);
|
||||
ck_assert_msg(pass_set_err == TOX_ERR_GROUP_SET_PASSWORD_OK, "%d", pass_set_err);
|
||||
ck_assert_msg(pass_set_err == TOX_ERR_GROUP_SET_PASSWORD_OK, "%u", pass_set_err);
|
||||
|
||||
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 5000);
|
||||
|
||||
// peer 2 attempts to join with no password
|
||||
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) {
|
||||
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
|
||||
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) {
|
||||
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
|
||||
Tox_Err_Group_Set_Peer_Limit limit_set_err;
|
||||
tox_group_set_peer_limit(tox0, groupnumber, 1, &limit_set_err);
|
||||
ck_assert_msg(limit_set_err == TOX_ERR_GROUP_SET_PEER_LIMIT_OK, "%d", limit_set_err);
|
||||
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);
|
||||
|
||||
// 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);
|
||||
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) {
|
||||
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
|
||||
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);
|
||||
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);
|
||||
|
||||
// peer 5 attempts to join group
|
||||
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) {
|
||||
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
|
||||
@@ -217,13 +217,13 @@ static void group_invite_test(AutoTox *autotoxes)
|
||||
// founder makes group private
|
||||
Tox_Err_Group_Set_Privacy_State priv_err;
|
||||
tox_group_set_privacy_state(tox0, groupnumber, TOX_GROUP_PRIVACY_STATE_PRIVATE, &priv_err);
|
||||
ck_assert_msg(priv_err == TOX_ERR_GROUP_SET_PRIVACY_STATE_OK, "%d", priv_err);
|
||||
ck_assert_msg(priv_err == TOX_ERR_GROUP_SET_PRIVACY_STATE_OK, "%u", priv_err);
|
||||
|
||||
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 5000);
|
||||
|
||||
// peer 6 attempts to join group via chat ID
|
||||
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
|
||||
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, 20000);
|
||||
@@ -234,7 +234,7 @@ static void group_invite_test(AutoTox *autotoxes)
|
||||
|
||||
// founder makes group public again
|
||||
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);
|
||||
|
||||
@@ -243,7 +243,7 @@ static void group_invite_test(AutoTox *autotoxes)
|
||||
|
||||
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);
|
||||
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;
|
||||
|
@@ -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)
|
||||
{
|
||||
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)
|
||||
@@ -448,7 +448,7 @@ static void group_message_test(AutoTox *autotoxes)
|
||||
// tox0 ignores tox1
|
||||
Tox_Err_Group_Set_Ignore 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);
|
||||
|
||||
@@ -460,7 +460,7 @@ static void group_message_test(AutoTox *autotoxes)
|
||||
|
||||
// tox0 unignores tox1
|
||||
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");
|
||||
|
||||
@@ -470,7 +470,7 @@ static void group_message_test(AutoTox *autotoxes)
|
||||
TOX_MESSAGE_TYPE_ACTION, (const uint8_t *)TEST_PRIVATE_MESSAGE,
|
||||
TEST_PRIVATE_MESSAGE_LEN, &m_err);
|
||||
|
||||
ck_assert_msg(m_err == TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_OK, "%d", m_err);
|
||||
ck_assert_msg(m_err == TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_OK, "%u", m_err);
|
||||
|
||||
while (!state0->private_message_received) {
|
||||
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_group_send_custom_packet(tox1, group_number, true, (const uint8_t *)TEST_CUSTOM_PACKET, TEST_CUSTOM_PACKET_LEN,
|
||||
&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,
|
||||
&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");
|
||||
|
||||
@@ -499,13 +499,13 @@ static void group_message_test(AutoTox *autotoxes)
|
||||
(const uint8_t *)TEST_CUSTOM_PRIVATE_PACKET,
|
||||
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,
|
||||
(const uint8_t *)TEST_CUSTOM_PRIVATE_PACKET,
|
||||
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) {
|
||||
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,
|
||||
&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) {
|
||||
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
|
||||
|
@@ -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)
|
||||
{
|
||||
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)
|
||||
@@ -268,7 +268,7 @@ static void group_mod_event_handler(const Tox_Event_Group_Moderation *event, voi
|
||||
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);
|
||||
|
||||
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(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),
|
||||
tox_group_role_to_string(role));
|
||||
|
||||
@@ -306,7 +306,7 @@ static void group_mod_event_handler(const Tox_Event_Group_Moderation *event, voi
|
||||
}
|
||||
|
||||
default: {
|
||||
ck_assert_msg(0, "Got invalid moderator event %d", mod_type);
|
||||
ck_assert_msg(0, "Got invalid moderator event %u", mod_type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -354,7 +354,7 @@ static void voice_state_message_test(AutoTox *autotox, Tox_Group_Voice_State voi
|
||||
case TOX_GROUP_ROLE_USER: {
|
||||
if (voice_state != TOX_GROUP_VOICE_STATE_ALL) {
|
||||
ck_assert_msg(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS,
|
||||
"%d", msg_err);
|
||||
"%u", msg_err);
|
||||
} else {
|
||||
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,
|
||||
&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 */
|
||||
Tox_Err_Group_State_Query id_err;
|
||||
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
|
||||
tox_group_get_chat_id(tox0, state0->group_number, chat_id, &id_err);
|
||||
|
||||
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_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");
|
||||
|
||||
@@ -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->self_name_length,
|
||||
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);
|
||||
|
||||
c_sleep(100);
|
||||
@@ -527,7 +527,7 @@ static void group_moderation_test(AutoTox *autotoxes)
|
||||
|
||||
Tox_Err_Group_Set_Role role_err;
|
||||
tox_group_set_role(tox0, state0->group_number, state0->peers[0].peer_id, TOX_GROUP_ROLE_MODERATOR, &role_err);
|
||||
ck_assert_msg(role_err == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set moderator. error: %d", role_err);
|
||||
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
|
||||
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);
|
||||
|
||||
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_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);
|
||||
|
||||
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_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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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_event_count;
|
||||
@@ -624,7 +624,7 @@ static void group_moderation_test(AutoTox *autotoxes)
|
||||
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);
|
||||
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;
|
||||
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");
|
||||
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_event_count;
|
||||
|
@@ -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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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_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) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t my_peer_limit = tox_group_get_peer_limit(tox, groupnumber, &query_err);
|
||||
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_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) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
size_t my_pass_len = tox_group_get_password_size(tox, groupnumber, &query_err);
|
||||
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_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) {
|
||||
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];
|
||||
tox_group_get_password(tox, groupnumber, my_pass, &query_err);
|
||||
my_pass[my_pass_len] = 0;
|
||||
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_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) {
|
||||
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 */
|
||||
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) {
|
||||
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);
|
||||
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) {
|
||||
return -9;
|
||||
}
|
||||
|
||||
Tox_Group_Voice_State current_voice_state = tox_group_get_voice_state(tox, groupnumber, &query_err);
|
||||
ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_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) {
|
||||
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_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_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_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_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);
|
||||
|
||||
Tox_Err_Group_Set_Voice_State voice_set_err;
|
||||
tox_group_set_voice_state(tox, groupnumber, voice_state, &voice_set_err);
|
||||
ck_assert_msg(voice_set_err == TOX_ERR_GROUP_SET_VOICE_STATE_OK, "failed to set voice state: %d",
|
||||
ck_assert_msg(voice_set_err == TOX_ERR_GROUP_SET_VOICE_STATE_OK, "failed to set voice state: %u",
|
||||
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,
|
||||
(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 */
|
||||
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];
|
||||
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 */
|
||||
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_group_join(autotoxes[i].tox, 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, "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");
|
||||
@@ -344,7 +344,7 @@ static void group_state_test(AutoTox *autotoxes)
|
||||
for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) {
|
||||
Tox_Err_Group_Leave 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");
|
||||
|
@@ -364,12 +364,12 @@ static void group_sync_test(AutoTox *autotoxes)
|
||||
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
|
||||
|
||||
tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err);
|
||||
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_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) {
|
||||
Tox_Err_Group_Join 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);
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ static void group_sync_test(AutoTox *autotoxes)
|
||||
|
||||
Tox_Err_Group_Set_Topic_Lock lock_set_err;
|
||||
tox_group_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err);
|
||||
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to disable topic lock: %d",
|
||||
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to disable topic lock: %u",
|
||||
lock_set_err);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
do {
|
||||
@@ -407,7 +407,7 @@ static void group_sync_test(AutoTox *autotoxes)
|
||||
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,
|
||||
&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");
|
||||
@@ -425,7 +425,7 @@ static void group_sync_test(AutoTox *autotoxes)
|
||||
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,
|
||||
&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 {
|
||||
|
@@ -156,7 +156,7 @@ static void group_tcp_test(AutoTox *autotoxes)
|
||||
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,
|
||||
(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);
|
||||
|
||||
@@ -164,14 +164,14 @@ static void group_tcp_test(AutoTox *autotoxes)
|
||||
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
|
||||
|
||||
tox_group_get_chat_id(autotoxes[0].tox, groupnumber, chat_id, &id_err);
|
||||
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_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");
|
||||
|
||||
for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) {
|
||||
Tox_Err_Group_Join 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);
|
||||
}
|
||||
|
||||
@@ -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_MESSAGE_TYPE_NORMAL,
|
||||
(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))
|
||||
|
@@ -241,7 +241,7 @@ static void group_topic_test(AutoTox *autotoxes)
|
||||
GROUP_NAME_LEN,
|
||||
(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);
|
||||
|
||||
@@ -254,7 +254,7 @@ static void group_topic_test(AutoTox *autotoxes)
|
||||
uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE];
|
||||
tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err);
|
||||
|
||||
ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_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 */
|
||||
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_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);
|
||||
}
|
||||
@@ -276,7 +276,7 @@ static void group_topic_test(AutoTox *autotoxes)
|
||||
/* Founder disables topic lock */
|
||||
Tox_Err_Group_Set_Topic_Lock lock_set_err;
|
||||
tox_group_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err);
|
||||
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to disable topic lock: %d",
|
||||
ck_assert_msg(lock_set_err == TOX_ERR_GROUP_SET_TOPIC_LOCK_OK, "failed to disable topic lock: %u",
|
||||
lock_set_err);
|
||||
|
||||
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 */
|
||||
Tox_Err_Group_Set_Role merr;
|
||||
tox_group_set_role(tox0, groupnumber, state0->peer_id, TOX_GROUP_ROLE_OBSERVER, &merr);
|
||||
ck_assert_msg(merr == TOX_ERR_GROUP_SET_ROLE_OK, "Failed to set %u to observer role: %d", state0->peer_id, merr);
|
||||
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");
|
||||
|
||||
@@ -305,7 +305,7 @@ static void group_topic_test(AutoTox *autotoxes)
|
||||
|
||||
/* 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);
|
||||
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);
|
||||
|
||||
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) {
|
||||
Tox_Err_Group_Leave 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");
|
||||
|
@@ -32,7 +32,7 @@ int main(void)
|
||||
// None of the iterations should have a connection.
|
||||
const Tox_Connection status = tox_self_get_connection_status(tox);
|
||||
ck_assert_msg(status == TOX_CONNECTION_NONE,
|
||||
"unexpectedly got a connection (%d)", status);
|
||||
"unexpectedly got a connection (%u)", status);
|
||||
}
|
||||
|
||||
tox_kill(tox);
|
||||
|
@@ -32,7 +32,7 @@ int main(void)
|
||||
// None of the iterations should have a connection.
|
||||
const Tox_Connection status = tox_self_get_connection_status(tox);
|
||||
ck_assert_msg(status == TOX_CONNECTION_NONE,
|
||||
"unexpectedly got a connection (%d)", status);
|
||||
"unexpectedly got a connection (%u)", status);
|
||||
}
|
||||
|
||||
tox_kill(tox);
|
||||
|
@@ -43,7 +43,7 @@ int main(void)
|
||||
} while (tox_self_get_connection_status(tox1) == 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(tox2));
|
||||
|
||||
|
@@ -112,7 +112,7 @@ int main(void)
|
||||
Tox_Err_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_set_udp_enabled(tox_opts, true);
|
||||
|
@@ -43,7 +43,7 @@ static void net_crypto_overflow_test(AutoTox *autotoxes)
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
// every time we try to send.
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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(tox3) != 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(tox2),
|
||||
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);
|
||||
|
||||
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(tox2),
|
||||
tox_self_get_connection_status(tox3),
|
||||
|
@@ -84,7 +84,7 @@ static void test_save_compatibility(const char *save_path)
|
||||
size_t index = 0;
|
||||
Tox_Err_New err;
|
||||
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);
|
||||
free(save_data);
|
||||
|
@@ -54,7 +54,7 @@ static void tox_connection_status(const Tox_Event_Self_Connection_Status *event,
|
||||
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;
|
||||
}
|
||||
@@ -153,7 +153,7 @@ static void test_few_clients(void)
|
||||
tox_options_set_tcp_port(opts1, TCP_RELAY_PORT);
|
||||
Tox_Err_New t_n_error;
|
||||
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_events_init(tox1);
|
||||
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_local_discovery_enabled(opts2, false);
|
||||
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_Dispatch *dispatch2 = tox_dispatch_new(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_local_discovery_enabled(opts3, false);
|
||||
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");
|
||||
|
||||
|
@@ -50,10 +50,10 @@ static void send_message_test(AutoTox *autotoxes)
|
||||
|
||||
Tox_Err_Friend_Send_Message 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);
|
||||
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);
|
||||
|
||||
|
@@ -92,7 +92,7 @@ static void test_set_name(void)
|
||||
tox_events_callback_friend_name(dispatch2, nickchange_callback);
|
||||
Tox_Err_Set_Info 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;
|
||||
|
||||
|
@@ -93,7 +93,7 @@ static void test_set_status_message(void)
|
||||
Tox_Err_Set_Info err_n;
|
||||
bool ret = tox_self_set_status_message(tox1, (const uint8_t *)STATUS_MESSAGE, sizeof(STATUS_MESSAGE),
|
||||
&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;
|
||||
|
||||
|
@@ -35,8 +35,8 @@ int main(void)
|
||||
|
||||
const Tox_Connection status = tox_self_get_connection_status(tox_tcp);
|
||||
ck_assert_msg(status == TOX_CONNECTION_TCP,
|
||||
"expected TCP connection, but got %d", status);
|
||||
printf("Connection (TCP): %d\n", status);
|
||||
"expected TCP connection, but got %u", status);
|
||||
printf("Connection (TCP): %u\n", status);
|
||||
|
||||
tox_kill(tox_tcp);
|
||||
|
||||
|
@@ -88,7 +88,7 @@ static void test_many_clients_tcp(void)
|
||||
uint8_t dpk[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_dht_id(toxes[0], dpk);
|
||||
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);
|
||||
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");
|
||||
@@ -128,7 +128,7 @@ 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) {
|
||||
@@ -233,7 +233,7 @@ 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;
|
||||
|
@@ -90,7 +90,7 @@ loop_top:
|
||||
|
||||
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) {
|
||||
|
@@ -27,7 +27,7 @@
|
||||
Toxav_Err_Call_Control cc_err; \
|
||||
bool ok = toxav_call_control(a, b, c, &cc_err); \
|
||||
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(cc_err == TOXAV_ERR_CALL_CONTROL_OK); \
|
||||
@@ -115,7 +115,7 @@ static void regular_call_flow(
|
||||
Toxav_Err_Call 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);
|
||||
|
||||
@@ -124,7 +124,7 @@ static void regular_call_flow(
|
||||
Toxav_Err_Answer 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;
|
||||
} else { /* TODO(mannol): rtp */
|
||||
@@ -133,7 +133,7 @@ static void regular_call_flow(
|
||||
Toxav_Err_Call_Control 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_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 {
|
||||
@@ -265,7 +265,7 @@ static void test_av_flows(void)
|
||||
Toxav_Err_Call_Control 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 {
|
||||
@@ -285,7 +285,7 @@ static void test_av_flows(void)
|
||||
Toxav_Err_Call 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 {
|
||||
@@ -297,7 +297,7 @@ static void test_av_flows(void)
|
||||
Toxav_Err_Call_Control 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 */
|
||||
@@ -319,7 +319,7 @@ static void test_av_flows(void)
|
||||
Toxav_Err_Call 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 {
|
||||
@@ -338,7 +338,7 @@ static void test_av_flows(void)
|
||||
Toxav_Err_Answer 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);
|
||||
@@ -380,7 +380,7 @@ static void test_av_flows(void)
|
||||
Toxav_Err_Call_Control 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);
|
||||
@@ -400,7 +400,7 @@ static void test_av_flows(void)
|
||||
Toxav_Err_Call 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 {
|
||||
@@ -411,7 +411,7 @@ static void test_av_flows(void)
|
||||
Toxav_Err_Answer 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);
|
||||
@@ -439,7 +439,7 @@ static void test_av_flows(void)
|
||||
Toxav_Err_Call_Control 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);
|
||||
@@ -459,7 +459,7 @@ static void test_av_flows(void)
|
||||
Toxav_Err_Call 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 {
|
||||
@@ -470,7 +470,7 @@ static void test_av_flows(void)
|
||||
Toxav_Err_Answer 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);
|
||||
@@ -488,7 +488,7 @@ static void test_av_flows(void)
|
||||
Toxav_Err_Call_Control 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);
|
||||
|
@@ -297,7 +297,7 @@ static void test_av_three_calls(void)
|
||||
toxav_call(alice_av, tds[i].friend_number, 48, 3000, &rc);
|
||||
|
||||
if (rc != TOXAV_ERR_CALL_OK) {
|
||||
printf("toxav_call failed: %d\n", rc);
|
||||
printf("toxav_call failed: %u\n", rc);
|
||||
ck_assert(0);
|
||||
}
|
||||
}
|
||||
@@ -316,7 +316,7 @@ static void test_av_three_calls(void)
|
||||
toxav_answer(bobs_av[i], 0, 8, 500, &rc);
|
||||
|
||||
if (rc != TOXAV_ERR_ANSWER_OK) {
|
||||
printf("toxav_answer failed: %d\n", rc);
|
||||
printf("toxav_answer failed: %u\n", rc);
|
||||
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);
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -25,15 +25,18 @@ run() {
|
||||
-Wno-missing-braces \
|
||||
-Wno-missing-field-initializers \
|
||||
-Wno-missing-noreturn \
|
||||
-Wno-nullability-completeness \
|
||||
-Wno-nullability-extension \
|
||||
-Wno-nullable-to-nonnull-conversion \
|
||||
-Wno-old-style-cast \
|
||||
-Wno-padded \
|
||||
-Wno-source-uses-openmp \
|
||||
-Wno-switch-default \
|
||||
-Wno-tautological-pointer-compare \
|
||||
-Wno-unreachable-code-return \
|
||||
-Wno-unsafe-buffer-usage \
|
||||
-Wno-unused-parameter \
|
||||
-Wno-used-but-marked-unused \
|
||||
-Wno-source-uses-openmp
|
||||
-Wno-used-but-marked-unused
|
||||
}
|
||||
|
||||
. other/analysis/variants.sh
|
||||
|
@@ -7,6 +7,11 @@ ERRORS="*"
|
||||
# Still good to occasionally look at.
|
||||
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.
|
||||
# =========================================================
|
||||
|
||||
|
@@ -12,8 +12,12 @@ CPPCHECK+=("--check-level=exhaustive")
|
||||
CPPCHECK+=("--inline-suppr")
|
||||
CPPCHECK+=("--library=other/docker/cppcheck/toxcore.cfg")
|
||||
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.
|
||||
CPPCHECK+=("--suppress=constParameterCallback")
|
||||
# This disagrees with clang's warnings.
|
||||
CPPCHECK+=("--suppress=invalidPrintfArgType_uint")
|
||||
# False positives in switch statements.
|
||||
CPPCHECK+=("--suppress=knownConditionTrueFalse")
|
||||
# Cppcheck does not need standard library headers to get proper results.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
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 && \
|
||||
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
|
||||
|
@@ -216,17 +216,6 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
|
||||
// gen setters and getters
|
||||
for (const auto& t : event_types) {
|
||||
// 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_";
|
||||
std::visit(
|
||||
overloaded{
|
||||
@@ -239,15 +228,14 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
|
||||
},
|
||||
t
|
||||
);
|
||||
f << "(Tox_Event_" << event_name << " *" << event_name_l << ",\n";
|
||||
f << " ";
|
||||
f << "(Tox_Event_" << event_name << " *_Nonnull " << event_name_l << ",";
|
||||
std::visit(
|
||||
overloaded{
|
||||
[&](const EventTypeTrivial& t) {
|
||||
f << t.type << " " << t.name << ")\n";
|
||||
f << " " << t.type << " " << t.name << ")\n";
|
||||
},
|
||||
[&](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
|
||||
@@ -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";
|
||||
},
|
||||
[&](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 << " " << event_name_l << "->" << t.name_data << " = nullptr;\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
|
||||
f << "non_null()\n";
|
||||
f << "static void tox_event_" << event_name_l << "_construct(Tox_Event_" << event_name << " *" << event_name_l << ")\n{\n";
|
||||
f << "static void tox_event_" << event_name_l << "_construct(Tox_Event_" << event_name << " *_Nonnull " << event_name_l << ")\n{\n";
|
||||
// TODO: initialize all members properly
|
||||
// TODO: check if _NONE is universal
|
||||
// str_toupper(
|
||||
f << " *" << event_name_l << " = (Tox_Event_" << event_name << ") {\n 0\n };\n}\n";
|
||||
|
||||
// gen destruct
|
||||
f << "non_null()\n";
|
||||
f << "static void tox_event_" << event_name_l << "_destruct(Tox_Event_" << event_name << " *" << event_name_l << ", const Memory *mem)\n{\n";
|
||||
f << "static void tox_event_" << event_name_l << "_destruct(Tox_Event_" << event_name << " *_Nonnull " << event_name_l << ", const Memory *_Nonnull mem)\n{\n";
|
||||
size_t data_count = 0;
|
||||
for (const auto& t : event_types) {
|
||||
std::visit(
|
||||
@@ -375,9 +361,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
|
||||
f << ";\n}\n\n";
|
||||
|
||||
// unpack
|
||||
f << "non_null()\n";
|
||||
f << "static bool tox_event_" << event_name_l << "_unpack_into(\n";
|
||||
f << " Tox_Event_" << event_name << " *event, Bin_Unpack *bu)\n{\n";
|
||||
f << "static bool tox_event_" << event_name_l << "_unpack_into(Tox_Event_" << event_name << " *_Nonnull event, Bin_Unpack *_Nonnull bu)\n{\n";
|
||||
f << " assert(event != nullptr);\n";
|
||||
if (event_types.size() > 1) {
|
||||
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";
|
||||
|
||||
// add
|
||||
f << "non_null()\n";
|
||||
f << "static Tox_Event_" << event_name << " *tox_events_add_" << event_name_l << "(Tox_Events *events, const Memory *mem)\n{\n";
|
||||
f << "static Tox_Event_" << event_name << " *tox_events_add_" << event_name_l << "(Tox_Events *_Nonnull events, const Memory *_Nonnull 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 << " 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";
|
||||
|
||||
// alloc
|
||||
f << "non_null()\n";
|
||||
f << "static Tox_Event_" << event_name << " *tox_event_" << event_name_l << "_alloc(void *user_data)\n{\n";
|
||||
f << "static Tox_Event_" << event_name << " *tox_event_" << event_name_l << "_alloc(void *_Nonnull user_data)\n{\n";
|
||||
f << " Tox_Events_State *state = tox_events_alloc(user_data);\n";
|
||||
f << " assert(state != nullptr);\n\n";
|
||||
f << " if (state->events == nullptr) {\n return nullptr;\n }\n\n";
|
||||
|
@@ -46,7 +46,7 @@ static bool bootstrap_tox(Tox *tox)
|
||||
free(key);
|
||||
|
||||
if (err != TOX_ERR_BOOTSTRAP_OK) {
|
||||
printf("Failed to bootstrap. Error number: %d", err);
|
||||
printf("Failed to bootstrap. Error number: %u", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -128,13 +128,13 @@ int main(int argc, char *argv[])
|
||||
tox_self_set_name(tox, name, strlen((const char *)name), &err);
|
||||
|
||||
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);
|
||||
|
||||
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
|
||||
@@ -145,7 +145,7 @@ int main(int argc, char *argv[])
|
||||
free(address);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -110,7 +110,7 @@ void TestBootstrap(Fuzz_Data &input)
|
||||
const char *message, void *user_data) {
|
||||
// Log to stdout.
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
@@ -144,7 +144,7 @@ void TestEndToEnd(Fuzz_Data &input)
|
||||
const char *message, void *user_data) {
|
||||
// Log to stdout.
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
@@ -489,7 +489,7 @@ static bool reconfigure_audio_encoder(const Logger *log, OpusEncoder **e, uint32
|
||||
*old_sr = new_sr;
|
||||
*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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -515,7 +515,7 @@ static bool reconfigure_audio_decoder(ACSession *ac, uint32_t sampling_rate, uin
|
||||
opus_decoder_destroy(ac->decoder);
|
||||
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;
|
||||
|
@@ -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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
16
toxav/msi.c
16
toxav/msi.c
@@ -183,7 +183,7 @@ bool check_peer_offline_status(const Logger *log, const Tox *tox, MSISession *se
|
||||
|
||||
if (f_con_status == TOX_CONNECTION_NONE) {
|
||||
/* 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);
|
||||
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);
|
||||
|
||||
/* 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;
|
||||
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)
|
||||
{
|
||||
MSISession *session = call->session;
|
||||
LOGGER_DEBUG(log, "invoking callback function: %d", id);
|
||||
LOGGER_DEBUG(log, "invoking callback function: %u", id);
|
||||
|
||||
switch (id) {
|
||||
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);
|
||||
}
|
||||
|
||||
LOGGER_FATAL(log, "invalid callback id: %d", id);
|
||||
LOGGER_FATAL(log, "invalid callback id: %u", id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -803,7 +803,7 @@ static void handle_init(const Logger *log, MSICall *call, const MSIMessage *msg)
|
||||
{
|
||||
assert(call != nullptr);
|
||||
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)) {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
if (!msg->capabilities.exists) {
|
||||
@@ -871,13 +871,13 @@ static void handle_pop(const Logger *log, MSICall *call, const MSIMessage *msg)
|
||||
{
|
||||
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);
|
||||
|
||||
/* callback errors are ignored */
|
||||
|
||||
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;
|
||||
invoke_callback(log, call, MSI_ON_ERROR);
|
||||
} else {
|
||||
|
@@ -308,7 +308,7 @@ static void update_bwc_values(RTPSession *session, const struct RTPMessage *msg)
|
||||
bwc_add_recv(session->bwc, 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);
|
||||
}
|
||||
}
|
||||
|
@@ -78,9 +78,9 @@ struct RTPHeader {
|
||||
uint64_t flags;
|
||||
|
||||
/**
|
||||
* The full 32 bit data offset of the current data chunk. The @ref
|
||||
* offset_lower data member contains the lower 16 bits of this value. For
|
||||
* frames smaller than 64KiB, @ref offset_full and @ref offset_lower are
|
||||
* The full 32 bit data offset of the current data chunk. The
|
||||
* @ref offset_lower data member contains the lower 16 bits of this value.
|
||||
* For frames smaller than 64KiB, @ref offset_full and @ref offset_lower are
|
||||
* equal.
|
||||
*/
|
||||
uint32_t offset_full;
|
||||
|
@@ -737,10 +737,10 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_ra
|
||||
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) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
} 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;
|
||||
@@ -810,10 +810,10 @@ bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_ra
|
||||
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) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
} 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;
|
||||
@@ -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) {
|
||||
// Key frame flag for first frames
|
||||
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;
|
||||
} else if (call->video_rtp->ssrc == VIDEO_SEND_X_KEYFRAMES_FIRST) {
|
||||
// normal keyframe placement
|
||||
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;
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
// 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,
|
||||
call->video->frame_counter, 1, vpx_encode_flags, deadline);
|
||||
call->video->frame_counter, 1, vpx_encode_flags, VPX_DL_REALTIME);
|
||||
|
||||
vpx_img_free(&img);
|
||||
|
||||
|
@@ -14,22 +14,16 @@
|
||||
typedef struct ToxAVCall ToxAVCall;
|
||||
#endif /* TOXAV_CALL_DEFINED */
|
||||
|
||||
non_null()
|
||||
ToxAVCall *call_get(ToxAV *av, uint32_t friend_number);
|
||||
ToxAVCall *_Nullable call_get(ToxAV *_Nonnull av, uint32_t friend_number);
|
||||
|
||||
non_null()
|
||||
RTPSession *rtp_session_get(ToxAVCall *call, int payload_type);
|
||||
RTPSession *_Nullable rtp_session_get(ToxAVCall *_Nonnull call, int payload_type);
|
||||
|
||||
non_null()
|
||||
MSISession *tox_av_msi_get(const ToxAV *av);
|
||||
MSISession *_Nullable tox_av_msi_get(const ToxAV *_Nonnull av);
|
||||
|
||||
non_null()
|
||||
BWController *bwc_controller_get(const ToxAVCall *call);
|
||||
BWController *_Nullable bwc_controller_get(const ToxAVCall *_Nonnull call);
|
||||
|
||||
non_null()
|
||||
Mono_Time *toxav_get_av_mono_time(const ToxAV *av);
|
||||
Mono_Time *_Nullable toxav_get_av_mono_time(const ToxAV *_Nonnull av);
|
||||
|
||||
non_null()
|
||||
const Logger *toxav_get_logger(const ToxAV *av);
|
||||
const Logger *_Nonnull toxav_get_logger(const ToxAV *_Nonnull av);
|
||||
|
||||
#endif /* C_TOXCORE_TOXAV_HACKS_H */
|
||||
|
@@ -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) {
|
||||
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 {
|
||||
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
|
||||
@@ -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
|
||||
* 0: off, 1: OnYOnly, 2: OnYUV, 3: OnYUVAggressive, 4: Adaptive
|
||||
*/
|
||||
|
227
toxcore/DHT.c
227
toxcore/DHT.c
@@ -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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool assoc_timeout(uint64_t cur_time, const IPPTsPng *assoc)
|
||||
static bool assoc_timeout(uint64_t cur_time, const IPPTsPng *_Nonnull assoc)
|
||||
{
|
||||
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.
|
||||
*/
|
||||
non_null()
|
||||
static IP_Port ip_port_normalize(const IP_Port *ip_port)
|
||||
static IP_Port ip_port_normalize(const IP_Port *_Nonnull 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.
|
||||
*/
|
||||
non_null()
|
||||
static bool bin_pack_node_handler(const void *arr, uint32_t index, const Logger *logger, Bin_Pack *bp)
|
||||
static bool bin_pack_node_handler(const void *_Nonnull arr, uint32_t index, const Logger *_Nonnull logger, Bin_Pack *_Nonnull bp)
|
||||
{
|
||||
const Node_format *nodes = (const Node_format *)arr;
|
||||
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.
|
||||
*/
|
||||
non_null(3) nullable(1)
|
||||
static uint32_t index_of_client_pk(const Client_data *array, uint32_t size, const uint8_t *pk)
|
||||
static uint32_t index_of_client_pk(const Client_data *_Nullable array, uint32_t size, const uint8_t *_Nonnull pk)
|
||||
{
|
||||
assert(size == 0 || array != nullptr);
|
||||
|
||||
for (uint32_t i = 0; i < size; ++i) {
|
||||
if (pk_equal(array[i].public_key, pk)) {
|
||||
return i;
|
||||
@@ -479,11 +474,9 @@ static uint32_t index_of_client_pk(const Client_data *array, uint32_t size, cons
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
non_null(3) nullable(1)
|
||||
static uint32_t index_of_friend_pk(const DHT_Friend *array, uint32_t size, const uint8_t *pk)
|
||||
static uint32_t index_of_friend_pk(const DHT_Friend *_Nullable array, uint32_t size, const uint8_t *_Nonnull pk)
|
||||
{
|
||||
assert(size == 0 || array != nullptr);
|
||||
|
||||
for (uint32_t i = 0; i < size; ++i) {
|
||||
if (pk_equal(array[i].public_key, pk)) {
|
||||
return i;
|
||||
@@ -493,11 +486,9 @@ static uint32_t index_of_friend_pk(const DHT_Friend *array, uint32_t size, const
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
non_null(3) nullable(1)
|
||||
static uint32_t index_of_node_pk(const Node_format *array, uint32_t size, const uint8_t *pk)
|
||||
static uint32_t index_of_node_pk(const Node_format *_Nullable array, uint32_t size, const uint8_t *_Nonnull pk)
|
||||
{
|
||||
assert(size == 0 || array != nullptr);
|
||||
|
||||
for (uint32_t i = 0; i < size; ++i) {
|
||||
if (pk_equal(array[i].public_key, pk)) {
|
||||
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.
|
||||
*/
|
||||
non_null(3) nullable(1)
|
||||
static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size, const IP_Port *ip_port)
|
||||
static uint32_t index_of_client_ip_port(const Client_data *_Nullable array, uint32_t size, const IP_Port *_Nonnull ip_port)
|
||||
{
|
||||
assert(size == 0 || array != nullptr);
|
||||
|
||||
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)) ||
|
||||
(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. */
|
||||
non_null()
|
||||
static void update_client(const Logger *log, const Mono_Time *mono_time, int index, Client_data *client,
|
||||
const IP_Port *ip_port)
|
||||
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)
|
||||
{
|
||||
IPPTsPng *assoc;
|
||||
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_to;
|
||||
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_ntohs(assoc->ip_port.port),
|
||||
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.
|
||||
* TODO(irungentoo): Maybe optimize this.
|
||||
*/
|
||||
non_null()
|
||||
static bool client_or_ip_port_in_list(const Logger *log, const Mono_Time *mono_time, Client_data *list, uint16_t length,
|
||||
const uint8_t *public_key, const IP_Port *ip_port)
|
||||
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,
|
||||
const IP_Port *_Nonnull ip_port)
|
||||
{
|
||||
const uint64_t temp_time = mono_time_get(mono_time);
|
||||
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
|
||||
*/
|
||||
non_null()
|
||||
static void get_close_nodes_inner(
|
||||
uint64_t cur_time, const uint8_t *public_key,
|
||||
Node_format *nodes_list, uint32_t *num_nodes_ptr,
|
||||
Family sa_family, const Client_data *client_list, uint32_t client_list_length,
|
||||
bool is_lan, bool want_announce)
|
||||
static void get_close_nodes_inner(uint64_t cur_time, const uint8_t *_Nonnull public_key, Node_format *_Nonnull nodes_list, uint32_t *_Nonnull num_nodes_ptr, Family sa_family,
|
||||
const Client_data *_Nonnull 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)) {
|
||||
return;
|
||||
@@ -717,12 +699,8 @@ static void get_close_nodes_inner(
|
||||
*
|
||||
* want_announce: return only nodes which implement the dht announcements protocol.
|
||||
*/
|
||||
non_null()
|
||||
static int get_somewhat_close_nodes(
|
||||
uint64_t cur_time, const uint8_t *public_key, Node_format nodes_list[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)
|
||||
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,
|
||||
const Client_data *_Nonnull close_clientlist, const DHT_Friend *_Nonnull friends_list, uint16_t friends_list_size, bool is_lan, bool want_announce)
|
||||
{
|
||||
for (uint16_t i = 0; i < MAX_SENT_NODES; ++i) {
|
||||
nodes_list[i] = empty_node_format;
|
||||
@@ -761,8 +739,7 @@ int get_close_nodes(
|
||||
}
|
||||
|
||||
#ifdef CHECK_ANNOUNCE_NODE
|
||||
non_null()
|
||||
static void set_announce_node_in_list(Client_data *list, uint32_t list_len, const uint8_t *public_key)
|
||||
static void set_announce_node_in_list(Client_data *_Nonnull list, uint32_t list_len, const uint8_t *_Nonnull 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. */
|
||||
non_null()
|
||||
static bool send_announce_ping(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port)
|
||||
static bool send_announce_ping(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port)
|
||||
{
|
||||
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. */
|
||||
non_null(1, 2, 3) nullable(5)
|
||||
static int handle_data_search_response(void *object, const IP_Port *source,
|
||||
const uint8_t *packet, uint16_t length,
|
||||
void *userdata)
|
||||
static int handle_data_search_response(void *_Nonnull object, const IP_Port *_Nonnull source,
|
||||
const uint8_t *_Nonnull packet, uint16_t length,
|
||||
void *_Nullable userdata)
|
||||
{
|
||||
DHT *dht = (DHT *) object;
|
||||
|
||||
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))) {
|
||||
@@ -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 true if it can.
|
||||
*/
|
||||
non_null()
|
||||
static bool store_node_ok(const Client_data *client, uint64_t cur_time, const uint8_t *public_key,
|
||||
const uint8_t *comp_public_key)
|
||||
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)
|
||||
{
|
||||
return (assoc_timeout(cur_time, &client->assoc4)
|
||||
&& assoc_timeout(cur_time, &client->assoc6))
|
||||
@@ -882,8 +854,7 @@ typedef struct Client_data_Cmp {
|
||||
const uint8_t *comp_public_key;
|
||||
} Client_data_Cmp;
|
||||
|
||||
non_null()
|
||||
static int client_data_cmp(const Client_data_Cmp *cmp, const Client_data *entry1, const Client_data *entry2)
|
||||
static int client_data_cmp(const Client_data_Cmp *_Nonnull cmp, const Client_data *_Nonnull entry1, const Client_data *_Nonnull entry2)
|
||||
{
|
||||
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);
|
||||
@@ -913,8 +884,7 @@ static int client_data_cmp(const Client_data_Cmp *cmp, const Client_data *entry1
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool client_data_less_handler(const void *object, const void *a, const void *b)
|
||||
static bool client_data_less_handler(const void *_Nonnull object, const void *_Nonnull a, const void *_Nonnull b)
|
||||
{
|
||||
const Client_data_Cmp *cmp = (const Client_data_Cmp *)object;
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static const void *client_data_get_handler(const void *arr, uint32_t index)
|
||||
static const void *client_data_get_handler(const void *_Nonnull arr, uint32_t index)
|
||||
{
|
||||
const Client_data *entries = (const Client_data *)arr;
|
||||
return &entries[index];
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void client_data_set_handler(void *arr, uint32_t index, const void *val)
|
||||
static void client_data_set_handler(void *_Nonnull arr, uint32_t index, const void *_Nonnull val)
|
||||
{
|
||||
Client_data *entries = (Client_data *)arr;
|
||||
const Client_data *entry = (const Client_data *)val;
|
||||
entries[index] = *entry;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void *client_data_subarr_handler(void *arr, uint32_t index, uint32_t size)
|
||||
static void *client_data_subarr_handler(void *_Nonnull arr, uint32_t index, uint32_t size)
|
||||
{
|
||||
Client_data *entries = (Client_data *)arr;
|
||||
return &entries[index];
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void *client_data_alloc_handler(const void *object, uint32_t size)
|
||||
static void *client_data_alloc_handler(const void *_Nonnull object, uint32_t size)
|
||||
{
|
||||
const Client_data_Cmp *cmp = (const Client_data_Cmp *)object;
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void client_data_delete_handler(const void *object, void *arr, uint32_t size)
|
||||
static void client_data_delete_handler(const void *_Nonnull object, void *_Nonnull arr, uint32_t size)
|
||||
{
|
||||
const Client_data_Cmp *cmp = (const Client_data_Cmp *)object;
|
||||
mem_delete(cmp->mem, arr);
|
||||
@@ -974,9 +939,7 @@ static const Sort_Funcs client_data_cmp_funcs = {
|
||||
client_data_delete_handler,
|
||||
};
|
||||
|
||||
non_null()
|
||||
static void sort_client_list(const Memory *mem, Client_data *list, uint64_t cur_time, unsigned int length,
|
||||
const uint8_t *comp_public_key)
|
||||
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)
|
||||
{
|
||||
// Pass comp_public_key to merge_sort with each Client_data entry, so the
|
||||
// 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void update_client_with_reset(const Mono_Time *mono_time, Client_data *client, const IP_Port *ip_port)
|
||||
static void update_client_with_reset(const Mono_Time *_Nonnull mono_time, Client_data *_Nonnull client, const IP_Port *_Nonnull ip_port)
|
||||
{
|
||||
IPPTsPng *ipptp_write = 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
|
||||
*/
|
||||
non_null()
|
||||
static bool replace_all(const DHT *dht,
|
||||
Client_data *list,
|
||||
uint16_t length,
|
||||
const uint8_t *public_key,
|
||||
const IP_Port *ip_port,
|
||||
const uint8_t *comp_public_key)
|
||||
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,
|
||||
const uint8_t *_Nonnull comp_public_key)
|
||||
{
|
||||
if (!net_family_is_ipv4(ip_port->ip.family) && !net_family_is_ipv6(ip_port->ip.family)) {
|
||||
return false;
|
||||
@@ -1064,8 +1021,7 @@ static bool replace_all(const DHT *dht,
|
||||
* return false on failure.
|
||||
* return true on success.
|
||||
*/
|
||||
non_null()
|
||||
static bool add_to_close(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port, bool simulate)
|
||||
static bool add_to_close(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port, bool simulate)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
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)
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool is_pk_in_close_list(const DHT *dht, const uint8_t *public_key, const IP_Port *ip_port)
|
||||
static bool is_pk_in_close_list(const DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port)
|
||||
{
|
||||
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 true if it should.
|
||||
*/
|
||||
non_null()
|
||||
static bool ping_node_from_nodes_response_ok(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port)
|
||||
static bool ping_node_from_nodes_response_ok(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
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)
|
||||
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)
|
||||
{
|
||||
const uint64_t temp_time = mono_time_get(mono_time);
|
||||
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
|
||||
* nodepublic_key is the id of the node that sent us this info.
|
||||
*/
|
||||
non_null()
|
||||
static void returnedip_ports(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *nodepublic_key)
|
||||
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)
|
||||
{
|
||||
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 */
|
||||
non_null()
|
||||
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 *sendback_data, uint16_t length, const uint8_t *shared_encryption_key)
|
||||
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,
|
||||
const uint8_t *_Nonnull sendback_data, uint16_t length, const uint8_t *_Nonnull shared_encryption_key)
|
||||
{
|
||||
/* Check if packet is going to be sent to ourself. */
|
||||
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))
|
||||
|
||||
non_null()
|
||||
static int handle_nodes_request(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
|
||||
static int handle_nodes_request(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length, void *_Nonnull userdata)
|
||||
{
|
||||
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. */
|
||||
non_null()
|
||||
static bool sent_nodes_request_to_node(DHT *dht, const uint8_t *public_key, const IP_Port *node_ip_port, uint64_t ping_id)
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool handle_nodes_response_core(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
|
||||
Node_format *plain_nodes, uint16_t size_plain_nodes, uint32_t *num_nodes_out)
|
||||
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,
|
||||
uint16_t size_plain_nodes, uint32_t *_Nonnull num_nodes_out)
|
||||
{
|
||||
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;
|
||||
@@ -1536,9 +1481,7 @@ static bool handle_nodes_response_core(void *object, const IP_Port *source, cons
|
||||
return true;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int handle_nodes_response(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
|
||||
void *userdata)
|
||||
static int handle_nodes_response(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length, void *_Nonnull userdata)
|
||||
{
|
||||
DHT *const dht = (DHT *)object;
|
||||
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--------------------------*/
|
||||
|
||||
non_null(1) nullable(2, 3)
|
||||
static uint32_t dht_friend_lock(DHT_Friend *const dht_friend, dht_ip_cb *ip_callback,
|
||||
void *data, int32_t number)
|
||||
static uint32_t dht_friend_lock(DHT_Friend *_Nonnull dht_friend, dht_ip_cb *_Nullable ip_callback,
|
||||
void *_Nullable data, int32_t number)
|
||||
{
|
||||
// find first free slot
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void dht_friend_unlock(DHT_Friend *const dht_friend, uint32_t lock_token)
|
||||
static void dht_friend_unlock(DHT_Friend *_Nonnull dht_friend, uint32_t lock_token)
|
||||
{
|
||||
// If this triggers, there was a double free
|
||||
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 */
|
||||
non_null()
|
||||
static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, const uint8_t *public_key,
|
||||
Client_data *list, uint32_t list_count, uint32_t *bootstrap_times, bool sortable)
|
||||
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,
|
||||
uint32_t *_Nonnull bootstrap_times, bool sortable)
|
||||
{
|
||||
uint8_t not_kill = 0;
|
||||
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
|
||||
* node for each "friend" in our "friends" list.
|
||||
*/
|
||||
non_null()
|
||||
static void do_dht_friends(DHT *dht)
|
||||
static void do_dht_friends(DHT *_Nonnull dht)
|
||||
{
|
||||
for (size_t i = 0; i < dht->num_friends; ++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.
|
||||
*/
|
||||
non_null()
|
||||
static void do_close(DHT *dht)
|
||||
static void do_close(DHT *_Nonnull dht)
|
||||
{
|
||||
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);
|
||||
@@ -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 -1 if no such friend.
|
||||
*/
|
||||
non_null()
|
||||
static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_num)
|
||||
static int friend_iplist(const DHT *_Nonnull dht, IP_Port *_Nonnull ip_portlist, uint16_t friend_num)
|
||||
{
|
||||
if (friend_num >= dht->num_friends) {
|
||||
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 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.
|
||||
@@ -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 userdata Extra pointer passed to the callback.
|
||||
*/
|
||||
non_null()
|
||||
static uint32_t foreach_ip_port(const DHT *dht, const DHT_Friend *dht_friend,
|
||||
foreach_ip_port_cb *callback, void *userdata)
|
||||
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)
|
||||
{
|
||||
uint32_t n = 0;
|
||||
|
||||
@@ -2076,8 +2011,7 @@ static uint32_t foreach_ip_port(const DHT *dht, const DHT_Friend *dht_friend,
|
||||
return n;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool send_packet_to_friend(const DHT *dht, const IP_Port *ip_port, uint32_t *n, void *userdata)
|
||||
static bool send_packet_to_friend(const DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, uint32_t *_Nonnull n, void *_Nonnull userdata)
|
||||
{
|
||||
const Packet *packet = (const Packet *)userdata;
|
||||
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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool get_ip_port(const DHT *dht, const IP_Port *ip_port, uint32_t *n, void *userdata)
|
||||
static bool get_ip_port(const DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, uint32_t *_Nonnull n, void *_Nonnull userdata)
|
||||
{
|
||||
IP_Port *ip_list = (IP_Port *)userdata;
|
||||
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.
|
||||
*/
|
||||
non_null()
|
||||
static uint32_t routeone_to_friend(const DHT *dht, const uint8_t *friend_id, const Packet *packet)
|
||||
static uint32_t routeone_to_friend(const DHT *_Nonnull dht, const uint8_t *_Nonnull friend_id, const Packet *_Nonnull packet)
|
||||
{
|
||||
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--------------------------*/
|
||||
|
||||
non_null()
|
||||
static int send_nat_ping(const DHT *dht, const uint8_t *public_key, uint64_t ping_id, uint8_t type)
|
||||
static int send_nat_ping(const DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, uint64_t ping_id, uint8_t type)
|
||||
{
|
||||
uint8_t data[sizeof(uint64_t) + 1];
|
||||
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. */
|
||||
non_null()
|
||||
static int handle_nat_ping(void *object, const IP_Port *source, const uint8_t *source_pubkey, const uint8_t *packet,
|
||||
uint16_t length, void *userdata)
|
||||
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,
|
||||
void *_Nonnull userdata)
|
||||
{
|
||||
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.
|
||||
*/
|
||||
non_null()
|
||||
static IP nat_commonip(const IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
|
||||
static IP nat_commonip(const IP_Port *_Nonnull ip_portlist, uint16_t len, uint16_t min_num)
|
||||
{
|
||||
IP 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.
|
||||
*/
|
||||
non_null()
|
||||
static uint16_t nat_getports(uint16_t *portlist, const IP_Port *ip_portlist, uint16_t len, const IP *ip)
|
||||
static uint16_t nat_getports(uint16_t *_Nonnull portlist, const IP_Port *_Nonnull ip_portlist, uint16_t len, const IP *_Nonnull ip)
|
||||
{
|
||||
uint16_t num = 0;
|
||||
|
||||
@@ -2291,8 +2219,7 @@ static uint16_t nat_getports(uint16_t *portlist, const IP_Port *ip_portlist, uin
|
||||
return num;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void punch_holes(DHT *dht, const IP *ip, const uint16_t *port_list, uint16_t numports, uint16_t friend_num)
|
||||
static void punch_holes(DHT *_Nonnull dht, const IP *_Nonnull ip, const uint16_t *_Nonnull port_list, uint16_t numports, uint16_t friend_num)
|
||||
{
|
||||
if (!dht->hole_punching_enabled) {
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void do_nat(DHT *dht)
|
||||
static void do_nat(DHT *_Nonnull dht)
|
||||
{
|
||||
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.
|
||||
*/
|
||||
non_null()
|
||||
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)
|
||||
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)
|
||||
{
|
||||
if (max_num == 0) {
|
||||
return 0;
|
||||
@@ -2490,9 +2414,7 @@ void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_c
|
||||
dht->cryptopackethandlers[byte].object = object;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int cryptopacket_handle(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
|
||||
void *userdata)
|
||||
static int cryptopacket_handle(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length, void *_Nonnull userdata)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
non_null(1, 2, 3) nullable(5)
|
||||
static int handle_lan_discovery(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
|
||||
void *userdata)
|
||||
static int handle_lan_discovery(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length,
|
||||
void *_Nullable userdata)
|
||||
{
|
||||
DHT *dht = (DHT *)object;
|
||||
|
||||
if (!dht->lan_discovery_enabled) {
|
||||
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));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -2826,8 +2746,7 @@ int dht_connect_after_load(DHT *dht)
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type)
|
||||
static State_Load_Status dht_load_state_callback(void *_Nonnull outer, const uint8_t *_Nonnull data, uint32_t length, uint16_t type)
|
||||
{
|
||||
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));
|
||||
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
175
toxcore/DHT.h
175
toxcore/DHT.h
@@ -98,10 +98,8 @@ extern "C" {
|
||||
* @retval -1 on failure.
|
||||
* @return the length of the created packet on success.
|
||||
*/
|
||||
non_null()
|
||||
int create_request(const Memory *mem, const Random *rng, const uint8_t *send_public_key, const uint8_t *send_secret_key,
|
||||
uint8_t *packet, const uint8_t *recv_public_key,
|
||||
const uint8_t *data, uint32_t data_length, uint8_t request_id);
|
||||
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,
|
||||
const uint8_t *_Nonnull recv_public_key, const uint8_t *_Nonnull data, uint32_t data_length, uint8_t request_id);
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* @return the length of the unpacked data.
|
||||
*/
|
||||
non_null()
|
||||
int handle_request(
|
||||
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);
|
||||
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,
|
||||
uint8_t *_Nonnull request_id, const uint8_t *_Nonnull packet, uint16_t packet_length);
|
||||
|
||||
typedef struct IPPTs {
|
||||
IP_Port ip_port;
|
||||
@@ -182,8 +178,8 @@ extern const Node_format empty_node_format;
|
||||
|
||||
typedef struct DHT_Friend DHT_Friend;
|
||||
|
||||
non_null() const uint8_t *dht_friend_public_key(const DHT_Friend *dht_friend);
|
||||
non_null() const Client_data *dht_friend_client(const DHT_Friend *dht_friend, size_t index);
|
||||
const uint8_t *_Nonnull dht_friend_public_key(const DHT_Friend *_Nonnull dht_friend);
|
||||
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.
|
||||
* @retval -1 on failure.
|
||||
@@ -195,20 +191,15 @@ int packed_node_size(Family ip_family);
|
||||
* @return size of packet on success.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int dht_create_packet(const Memory *mem, const Random *rng,
|
||||
const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
|
||||
const uint8_t *shared_key, uint8_t type,
|
||||
const uint8_t *plain, size_t plain_length,
|
||||
uint8_t *packet, size_t length);
|
||||
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,
|
||||
const uint8_t *_Nonnull plain, size_t plain_length, uint8_t *_Nonnull packet, size_t length);
|
||||
|
||||
/** @brief Pack number of nodes into data of maxlength length.
|
||||
*
|
||||
* @return length of packed nodes on success.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int pack_nodes(const Logger *logger, uint8_t *data, uint16_t length, const Node_format *nodes, uint16_t number);
|
||||
int pack_nodes(const Logger *_Nonnull logger, uint8_t *_Nonnull data, uint16_t length, const Node_format *_Nonnull nodes, uint16_t number);
|
||||
|
||||
/** @brief Unpack data of length into nodes of size max_num_nodes.
|
||||
* 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.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null(1, 4) nullable(3)
|
||||
int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed_data_len, const uint8_t *data,
|
||||
int unpack_nodes(Node_format *_Nonnull nodes, uint16_t max_num_nodes, uint16_t *_Nullable processed_data_len, const uint8_t *_Nonnull data,
|
||||
uint16_t length, bool tcp_enabled);
|
||||
|
||||
/*----------------------------------------------------------------------------------*/
|
||||
|
||||
typedef int cryptopacket_handler_cb(void *object, const IP_Port *source, const uint8_t *source_pubkey,
|
||||
const uint8_t *packet, uint16_t length, void *userdata);
|
||||
typedef int cryptopacket_handler_cb(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull source_pubkey,
|
||||
const uint8_t *_Nonnull packet, uint16_t length, void *_Nullable userdata);
|
||||
|
||||
typedef struct DHT DHT;
|
||||
|
||||
non_null() const uint8_t *dht_get_self_public_key(const DHT *dht);
|
||||
non_null() const uint8_t *dht_get_self_secret_key(const DHT *dht);
|
||||
non_null() void dht_set_self_public_key(DHT *dht, const uint8_t *key);
|
||||
non_null() void dht_set_self_secret_key(DHT *dht, const uint8_t *key);
|
||||
const uint8_t *_Nonnull dht_get_self_public_key(const DHT *_Nonnull dht);
|
||||
const uint8_t *_Nonnull dht_get_self_secret_key(const DHT *_Nonnull dht);
|
||||
void dht_set_self_public_key(DHT *_Nonnull dht, const uint8_t *_Nonnull 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);
|
||||
non_null() struct Ping *dht_get_ping(const DHT *dht);
|
||||
non_null() const Client_data *dht_get_close_clientlist(const DHT *dht);
|
||||
non_null() const Client_data *dht_get_close_client(const DHT *dht, uint32_t client_num);
|
||||
non_null() uint16_t dht_get_num_friends(const DHT *dht);
|
||||
Networking_Core *_Nonnull dht_get_net(const DHT *_Nonnull dht);
|
||||
struct Ping *_Nonnull dht_get_ping(const DHT *_Nonnull dht);
|
||||
const Client_data *_Nonnull dht_get_close_clientlist(const DHT *_Nonnull dht);
|
||||
const Client_data *_Nonnull dht_get_close_client(const DHT *_Nonnull dht, uint32_t client_num);
|
||||
uint16_t dht_get_num_friends(const DHT *_Nonnull dht);
|
||||
|
||||
non_null() DHT_Friend *dht_get_friend(DHT *dht, uint32_t friend_num);
|
||||
non_null() const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t friend_num);
|
||||
DHT_Friend *_Nonnull dht_get_friend(DHT *_Nonnull 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
|
||||
* for packets that we receive.
|
||||
*/
|
||||
non_null()
|
||||
const uint8_t *dht_get_shared_key_recv(DHT *dht, const uint8_t *public_key);
|
||||
const uint8_t *_Nullable dht_get_shared_key_recv(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key);
|
||||
|
||||
/**
|
||||
* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
|
||||
* for packets that we send.
|
||||
*/
|
||||
non_null()
|
||||
const uint8_t *dht_get_shared_key_sent(DHT *dht, const uint8_t *public_key);
|
||||
const uint8_t *_Nullable dht_get_shared_key_sent(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
non_null()
|
||||
bool dht_send_nodes_request(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *client_id);
|
||||
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);
|
||||
|
||||
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. */
|
||||
non_null(1) nullable(2)
|
||||
void dht_callback_nodes_response(DHT *dht, dht_nodes_response_cb *function);
|
||||
|
||||
void dht_callback_nodes_response(DHT *_Nonnull dht, dht_nodes_response_cb *_Nullable function);
|
||||
/** @brief Add a new friend to the friends list.
|
||||
* @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 -1 if failure (friends list is full).
|
||||
*/
|
||||
non_null(1, 2, 6) nullable(3, 4)
|
||||
int dht_addfriend(DHT *dht, const uint8_t *public_key, dht_ip_cb *ip_callback,
|
||||
void *data, int32_t number, uint32_t *lock_token);
|
||||
|
||||
int dht_addfriend(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, dht_ip_cb *_Nullable ip_callback,
|
||||
void *_Nullable data, int32_t number, uint32_t *_Nonnull lock_token);
|
||||
/** @brief Delete a friend from the friends list.
|
||||
* public_key must be CRYPTO_PUBLIC_KEY_SIZE bytes long.
|
||||
* @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 -1 if failure (public_key not in friends list).
|
||||
*/
|
||||
non_null()
|
||||
int dht_delfriend(DHT *dht, const uint8_t *public_key, uint32_t lock_token);
|
||||
int dht_delfriend(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, uint32_t lock_token);
|
||||
|
||||
/** @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 1 if public_key refers to a friend and we found him
|
||||
*/
|
||||
non_null()
|
||||
int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port);
|
||||
int dht_getfriendip(const DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, IP_Port *_Nonnull ip_port);
|
||||
|
||||
/** @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 2 if pk2 is closer.
|
||||
*/
|
||||
non_null()
|
||||
int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2);
|
||||
int id_closest(const uint8_t *_Nonnull pk, const uint8_t *_Nonnull pk1, const uint8_t *_Nonnull 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 *pk1, const uint8_t *pk2);
|
||||
unsigned int bit_by_bit_cmp(const uint8_t *_Nonnull pk1, const uint8_t *_Nonnull pk2);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
non_null()
|
||||
bool add_to_list(
|
||||
Node_format *nodes_list, uint32_t length, const uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE],
|
||||
const IP_Port *ip_port, const uint8_t cmp_pk[CRYPTO_PUBLIC_KEY_SIZE]);
|
||||
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,
|
||||
const uint8_t cmp_pk[_Nonnull CRYPTO_PUBLIC_KEY_SIZE]);
|
||||
|
||||
/** Return 1 if node can be added to close list, 0 if it can't. */
|
||||
non_null()
|
||||
bool node_addable_to_close_list(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port);
|
||||
bool node_addable_to_close_list(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port);
|
||||
|
||||
#ifdef CHECK_ANNOUNCE_NODE
|
||||
/** Set node as announce node. */
|
||||
non_null()
|
||||
void set_announce_node(DHT *dht, const uint8_t *public_key);
|
||||
void set_announce_node(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key);
|
||||
#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.
|
||||
*/
|
||||
non_null()
|
||||
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);
|
||||
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);
|
||||
|
||||
/** @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.
|
||||
*/
|
||||
non_null()
|
||||
uint16_t randfriends_nodes(const DHT *dht, Node_format *nodes, uint16_t max_num);
|
||||
uint16_t randfriends_nodes(const DHT *_Nonnull dht, Node_format *_Nonnull nodes, uint16_t max_num);
|
||||
|
||||
/** @brief Put up to max_num nodes in nodes from the closelist.
|
||||
*
|
||||
* @return the number of nodes.
|
||||
*/
|
||||
non_null()
|
||||
uint16_t closelist_nodes(const DHT *dht, Node_format *nodes, uint16_t max_num);
|
||||
uint16_t closelist_nodes(const DHT *_Nonnull dht, Node_format *_Nonnull nodes, uint16_t max_num);
|
||||
|
||||
/** Run this function at least a couple times per second (It's the main loop). */
|
||||
non_null()
|
||||
void do_dht(DHT *dht);
|
||||
void do_dht(DHT *_Nonnull dht);
|
||||
|
||||
/*
|
||||
* 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
|
||||
* to setup connections
|
||||
*/
|
||||
non_null()
|
||||
bool dht_bootstrap(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key);
|
||||
bool dht_bootstrap(DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key);
|
||||
|
||||
/** @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 false otherwise
|
||||
*/
|
||||
non_null()
|
||||
bool dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled, bool dns_enabled,
|
||||
uint16_t port, const uint8_t *public_key);
|
||||
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);
|
||||
|
||||
/** @brief Start sending packets after DHT loaded_friends_list and loaded_clients_list are set.
|
||||
*
|
||||
* @retval 0 if successful
|
||||
* @retval -1 otherwise
|
||||
*/
|
||||
non_null()
|
||||
int dht_connect_after_load(DHT *dht);
|
||||
int dht_connect_after_load(DHT *_Nonnull dht);
|
||||
|
||||
/* ROUTING FUNCTIONS */
|
||||
|
||||
@@ -428,8 +391,7 @@ int dht_connect_after_load(DHT *dht);
|
||||
* @return number of bytes sent.
|
||||
* @retval -1 if failure.
|
||||
*/
|
||||
non_null()
|
||||
int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packet, uint16_t length);
|
||||
int route_packet(const DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull packet, uint16_t length);
|
||||
|
||||
/**
|
||||
* 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 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 *dht, const uint8_t *friend_id, const Packet *packet);
|
||||
uint32_t route_to_friend(const DHT *_Nonnull dht, const uint8_t *_Nonnull friend_id, const Packet *_Nonnull packet);
|
||||
|
||||
/** Function to handle crypto packets. */
|
||||
non_null(1) nullable(3, 4)
|
||||
void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_cb *cb, void *object);
|
||||
|
||||
void cryptopacket_registerhandler(DHT *_Nonnull dht, uint8_t byte, cryptopacket_handler_cb *_Nullable cb, void *_Nullable object);
|
||||
/* SAVE/LOAD functions */
|
||||
|
||||
/** Get the size of the DHT (for saving). */
|
||||
non_null()
|
||||
uint32_t dht_size(const DHT *dht);
|
||||
uint32_t dht_size(const DHT *_Nonnull dht);
|
||||
|
||||
/** Save the DHT in data where data is an array of size `dht_size()`. */
|
||||
non_null()
|
||||
void dht_save(const DHT *dht, uint8_t *data);
|
||||
void dht_save(const DHT *_Nonnull dht, uint8_t *_Nonnull data);
|
||||
|
||||
/** @brief Load the DHT from data of size size.
|
||||
*
|
||||
* @retval -1 if failure.
|
||||
* @retval 0 if success.
|
||||
*/
|
||||
non_null()
|
||||
int dht_load(DHT *dht, const uint8_t *data, uint32_t length);
|
||||
int dht_load(DHT *_Nonnull dht, const uint8_t *_Nonnull data, uint32_t length);
|
||||
|
||||
/** Initialize DHT. */
|
||||
non_null()
|
||||
DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Network *ns,
|
||||
Mono_Time *mono_time, Networking_Core *net, bool hole_punching_enabled, bool lan_discovery_enabled);
|
||||
|
||||
nullable(1)
|
||||
void kill_dht(DHT *dht);
|
||||
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,
|
||||
bool hole_punching_enabled, bool lan_discovery_enabled);
|
||||
|
||||
void kill_dht(DHT *_Nullable dht);
|
||||
/**
|
||||
* @retval false if we are not connected to the DHT.
|
||||
* @retval true if we are.
|
||||
*/
|
||||
non_null()
|
||||
bool dht_isconnected(const DHT *dht);
|
||||
bool dht_isconnected(const DHT *_Nonnull dht);
|
||||
|
||||
/**
|
||||
* @retval false if we are not connected or only connected to lan peers with the DHT.
|
||||
* @retval true if we are.
|
||||
*/
|
||||
non_null()
|
||||
bool dht_non_lan_connected(const DHT *dht);
|
||||
bool dht_non_lan_connected(const DHT *_Nonnull dht);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
non_null()
|
||||
uint16_t dht_get_num_closelist(const DHT *dht);
|
||||
uint16_t dht_get_num_closelist(const DHT *_Nonnull dht);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
non_null()
|
||||
uint16_t dht_get_num_closelist_announce_capable(const DHT *dht);
|
||||
uint16_t dht_get_num_closelist_announce_capable(const DHT *_Nonnull dht);
|
||||
|
||||
/** @brief Attempt to add client with ip_port and public_key to the friends client list
|
||||
* and close_clientlist.
|
||||
*
|
||||
* @return 1+ if the item is used in any list, 0 else
|
||||
*/
|
||||
non_null()
|
||||
uint32_t addto_lists(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key);
|
||||
uint32_t addto_lists(DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key);
|
||||
|
||||
/** @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 2 if IP is a LAN address.
|
||||
*/
|
||||
non_null()
|
||||
unsigned int ipport_self_copy(const DHT *dht, IP_Port *dest);
|
||||
unsigned int ipport_self_copy(const DHT *_Nonnull dht, IP_Port *_Nonnull dest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
@@ -53,8 +53,7 @@ struct Broadcast_Info {
|
||||
|
||||
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
||||
|
||||
non_null()
|
||||
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
|
||||
static Broadcast_Info *fetch_broadcast_info(const Memory *_Nonnull mem, const Network *_Nonnull ns)
|
||||
{
|
||||
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__))
|
||||
|
||||
non_null()
|
||||
static bool ip4_is_local(const IP4 *ip4);
|
||||
static bool ip4_is_local(const IP4 *_Nonnull ip4);
|
||||
|
||||
non_null()
|
||||
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
|
||||
static Broadcast_Info *fetch_broadcast_info(const Memory *_Nonnull mem, const Network *_Nonnull ns)
|
||||
{
|
||||
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?
|
||||
|
||||
non_null()
|
||||
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
|
||||
static Broadcast_Info *fetch_broadcast_info(const Memory *_Nonnull mem, const Network *_Nonnull ns)
|
||||
{
|
||||
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 false on failure to find any valid broadcast target.
|
||||
*/
|
||||
non_null()
|
||||
static bool send_broadcasts(const Networking_Core *net, const Broadcast_Info *broadcast, uint16_t port,
|
||||
const uint8_t *data, uint16_t length)
|
||||
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)
|
||||
{
|
||||
if (broadcast->count == 0) {
|
||||
return false;
|
||||
@@ -288,8 +282,7 @@ static IP broadcast_ip(Family family_socket, Family family_broadcast)
|
||||
return ip;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool ip4_is_local(const IP4 *ip4)
|
||||
static bool ip4_is_local(const IP4 *_Nonnull ip4)
|
||||
{
|
||||
/* Loopback. */
|
||||
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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool ip4_is_lan(const IP4 *ip4)
|
||||
static bool ip4_is_lan(const IP4 *_Nonnull ip4)
|
||||
{
|
||||
/* 10.0.0.0 to 10.255.255.255 range. */
|
||||
if (ip4->uint8[0] == 10) {
|
||||
|
@@ -25,34 +25,27 @@ typedef struct Broadcast_Info Broadcast_Info;
|
||||
*
|
||||
* @return true on success, false on failure.
|
||||
*/
|
||||
non_null()
|
||||
bool lan_discovery_send(const Networking_Core *net, const Broadcast_Info *broadcast, const uint8_t *dht_pk,
|
||||
uint16_t port);
|
||||
bool lan_discovery_send(const Networking_Core *_Nonnull net, const Broadcast_Info *_Nonnull broadcast, const uint8_t *_Nonnull dht_pk, uint16_t port);
|
||||
|
||||
/**
|
||||
* Discovers broadcast devices and IP addresses.
|
||||
*/
|
||||
non_null()
|
||||
Broadcast_Info *lan_discovery_init(const Memory *mem, const Network *ns);
|
||||
Broadcast_Info *_Nullable lan_discovery_init(const Memory *_Nonnull mem, const Network *_Nonnull ns);
|
||||
|
||||
/**
|
||||
* Free all resources associated with the broadcast info.
|
||||
*/
|
||||
nullable(1)
|
||||
void lan_discovery_kill(Broadcast_Info *broadcast);
|
||||
|
||||
void lan_discovery_kill(Broadcast_Info *_Nullable broadcast);
|
||||
/**
|
||||
* Is IP a local ip or not.
|
||||
*/
|
||||
non_null()
|
||||
bool ip_is_local(const IP *ip);
|
||||
bool ip_is_local(const IP *_Nonnull ip);
|
||||
|
||||
/**
|
||||
* Checks if a given IP isn't routable.
|
||||
*
|
||||
* @return true if ip is a LAN ip, false if it is not.
|
||||
*/
|
||||
non_null()
|
||||
bool ip_is_lan(const IP *ip);
|
||||
bool ip_is_lan(const IP *_Nonnull ip);
|
||||
|
||||
#endif /* C_TOXCORE_TOXCORE_LAN_DISCOVERY_H */
|
||||
|
@@ -61,8 +61,7 @@ bool friend_is_valid(const Messenger *m, int32_t friendnumber)
|
||||
*
|
||||
* @retval -1 if mem_vrealloc fails.
|
||||
*/
|
||||
non_null()
|
||||
static int realloc_friendlist(Messenger *m, uint32_t num)
|
||||
static int realloc_friendlist(Messenger *_Nonnull m, uint32_t num)
|
||||
{
|
||||
if (num == 0) {
|
||||
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));
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool send_online_packet(const Messenger *m, int friendcon_id)
|
||||
static bool send_online_packet(const Messenger *_Nonnull m, int friendcon_id)
|
||||
{
|
||||
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,
|
||||
sizeof(packet), false) != -1;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool send_offline_packet(const Messenger *m, int friendcon_id)
|
||||
static bool send_offline_packet(const Messenger *_Nonnull m, int friendcon_id)
|
||||
{
|
||||
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,
|
||||
sizeof(packet), false) != -1;
|
||||
}
|
||||
|
||||
non_null(1) nullable(4)
|
||||
static int m_handle_status(void *object, int friendcon_id, bool status, void *userdata);
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata);
|
||||
non_null(1, 3) nullable(5)
|
||||
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)
|
||||
static int m_handle_status(void *_Nonnull object, int friendcon_id, bool status, void *_Nullable userdata);
|
||||
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_lossy_packet(void *_Nonnull object, int friendcon_id, const uint8_t *_Nonnull data, uint16_t length,
|
||||
void *_Nullable userdata);
|
||||
static int32_t init_new_friend(Messenger *_Nonnull m, const uint8_t *_Nonnull real_pk, uint8_t status)
|
||||
{
|
||||
if (m->numfriends == UINT32_MAX) {
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int32_t m_add_friend_contact_norequest(Messenger *m, const uint8_t *real_pk)
|
||||
static int32_t m_add_friend_contact_norequest(Messenger *_Nonnull m, const uint8_t *_Nonnull real_pk)
|
||||
{
|
||||
if (getfriend_id(m, real_pk) != -1) {
|
||||
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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int clear_receipts(Messenger *m, int32_t friendnumber)
|
||||
static int clear_receipts(Messenger *_Nonnull m, int32_t friendnumber)
|
||||
{
|
||||
if (!m_friend_exists(m, friendnumber)) {
|
||||
return -1;
|
||||
@@ -340,8 +330,7 @@ static int clear_receipts(Messenger *m, int32_t friendnumber)
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num, uint32_t msg_id)
|
||||
static int add_receipt(Messenger *_Nonnull m, int32_t friendnumber, uint32_t packet_num, uint32_t msg_id)
|
||||
{
|
||||
if (!m_friend_exists(m, friendnumber)) {
|
||||
return -1;
|
||||
@@ -370,8 +359,7 @@ static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num,
|
||||
* return -1 on failure.
|
||||
* return 0 if packet was received.
|
||||
*/
|
||||
non_null()
|
||||
static int friend_received_packet(const Messenger *m, int32_t friendnumber, uint32_t number)
|
||||
static int friend_received_packet(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t number)
|
||||
{
|
||||
if (!m_friend_exists(m, friendnumber)) {
|
||||
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);
|
||||
}
|
||||
|
||||
non_null(1) nullable(3)
|
||||
static int do_receipts(Messenger *m, int32_t friendnumber, void *userdata)
|
||||
static int do_receipts(Messenger *_Nonnull m, int32_t friendnumber, void *_Nullable userdata)
|
||||
{
|
||||
if (!m_friend_exists(m, friendnumber)) {
|
||||
return -1;
|
||||
@@ -606,9 +593,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
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)
|
||||
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)
|
||||
{
|
||||
if (!m_friend_exists(m, friendnumber)) {
|
||||
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.
|
||||
* length is the length with the NULL terminator.
|
||||
*/
|
||||
non_null()
|
||||
static bool m_sendname(const Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length)
|
||||
static bool m_sendname(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull name, uint16_t length)
|
||||
{
|
||||
if (length > MAX_NAME_LENGTH) {
|
||||
return false;
|
||||
@@ -771,8 +755,7 @@ int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length)
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool userstatus_from_int(uint8_t status, Userstatus *out_enum)
|
||||
static bool userstatus_from_int(uint8_t status, Userstatus *_Nonnull out_enum)
|
||||
{
|
||||
switch (status) {
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool send_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length)
|
||||
static bool send_statusmessage(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull status, uint16_t length)
|
||||
{
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length, false);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool send_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
|
||||
static bool send_userstatus(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t status)
|
||||
{
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &status, sizeof(status), false);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool send_user_istyping(const Messenger *m, int32_t friendnumber, bool is_typing)
|
||||
static bool send_user_istyping(const Messenger *_Nonnull m, int32_t friendnumber, bool is_typing)
|
||||
{
|
||||
const uint8_t typing = is_typing ? 1 : 0;
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing), false);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length)
|
||||
static int set_friend_statusmessage(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull status, uint16_t length)
|
||||
{
|
||||
if (!m_friend_exists(m, friendnumber)) {
|
||||
return -1;
|
||||
@@ -965,14 +944,12 @@ static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, co
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void set_friend_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
|
||||
static void set_friend_userstatus(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t status)
|
||||
{
|
||||
userstatus_from_int(status, &m->friendlist[friendnumber].userstatus);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void set_friend_typing(const Messenger *m, int32_t friendnumber, bool is_typing)
|
||||
static void set_friend_typing(const Messenger *_Nonnull m, int32_t friendnumber, bool 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;
|
||||
}
|
||||
|
||||
non_null(1) nullable(3)
|
||||
static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber, void *userdata)
|
||||
static void check_friend_tcp_udp(Messenger *_Nonnull m, int32_t friendnumber, void *_Nullable userdata)
|
||||
{
|
||||
const int last_connection_udp_tcp = m->friendlist[friendnumber].last_connection_udp_tcp;
|
||||
|
||||
const int ret = m_get_friend_connectionstatus(m, friendnumber);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void break_files(const Messenger *m, int32_t friendnumber);
|
||||
static void break_files(const Messenger *_Nonnull m, int32_t friendnumber);
|
||||
|
||||
non_null(1) nullable(4)
|
||||
static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata)
|
||||
static void check_friend_connectionstatus(Messenger *_Nonnull m, int32_t friendnumber, uint8_t status, void *_Nullable userdata)
|
||||
{
|
||||
if (status == NOFRIEND) {
|
||||
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 *m, int32_t friendnumber, uint8_t status, void *userdata)
|
||||
static void set_friend_status(Messenger *_Nonnull m, int32_t friendnumber, uint8_t status, void *_Nullable userdata)
|
||||
{
|
||||
check_friend_connectionstatus(m, friendnumber, status, userdata);
|
||||
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 0 on failure
|
||||
*/
|
||||
non_null()
|
||||
static bool file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint32_t file_type,
|
||||
uint64_t filesize, const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length)
|
||||
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,
|
||||
const uint8_t *_Nonnull filename, uint16_t filename_length)
|
||||
{
|
||||
if (!m_friend_exists(m, friendnumber)) {
|
||||
return false;
|
||||
@@ -1274,12 +1245,10 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_
|
||||
return i;
|
||||
}
|
||||
|
||||
non_null(1) nullable(6)
|
||||
static bool send_file_control_packet(const Messenger *m, int32_t friendnumber, bool inbound, uint8_t filenumber,
|
||||
uint8_t control_type, const uint8_t *data, uint16_t data_length)
|
||||
static bool send_file_control_packet(const Messenger *_Nonnull m, int32_t friendnumber, bool inbound, uint8_t filenumber,
|
||||
uint8_t control_type, const uint8_t *_Nullable data, uint16_t data_length)
|
||||
{
|
||||
assert(data_length == 0 || data != nullptr);
|
||||
|
||||
if ((unsigned int)(1 + 3 + data_length) > MAX_CRYPTO_DATA_SIZE) {
|
||||
return false;
|
||||
}
|
||||
@@ -1475,12 +1444,10 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
|
||||
/** @return packet number on success.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null(1) nullable(4)
|
||||
static int64_t send_file_data_packet(const Messenger *m, int32_t friendnumber, uint8_t filenumber, const uint8_t *data,
|
||||
static int64_t send_file_data_packet(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t filenumber, const uint8_t *_Nullable data,
|
||||
uint16_t length)
|
||||
{
|
||||
assert(length == 0 || data != nullptr);
|
||||
|
||||
if (!m_friend_exists(m, friendnumber)) {
|
||||
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.
|
||||
*
|
||||
*/
|
||||
non_null()
|
||||
static bool do_all_filetransfers(Messenger *m, int32_t friendnumber, void *userdata, uint32_t *free_slots)
|
||||
static bool do_all_filetransfers(Messenger *_Nonnull m, int32_t friendnumber, void *_Nonnull userdata, uint32_t *_Nonnull free_slots)
|
||||
{
|
||||
Friend *const friendcon = &m->friendlist[friendnumber];
|
||||
|
||||
@@ -1656,8 +1622,7 @@ static bool do_all_filetransfers(Messenger *m, int32_t friendnumber, void *userd
|
||||
return true;
|
||||
}
|
||||
|
||||
non_null(1) nullable(3)
|
||||
static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber, void *userdata)
|
||||
static void do_reqchunk_filecb(Messenger *_Nonnull m, int32_t friendnumber, void *_Nullable userdata)
|
||||
{
|
||||
// We're not currently doing any file transfers.
|
||||
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 *real_filenumber, Friend *sender)
|
||||
static struct File_Transfers *get_file_transfer(bool outbound, uint8_t filenumber, uint32_t *_Nonnull real_filenumber, Friend *_Nonnull sender)
|
||||
{
|
||||
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 0 on success.
|
||||
*/
|
||||
non_null(1, 6) nullable(8)
|
||||
static int handle_filecontrol(Messenger *m, int32_t friendnumber, bool outbound, uint8_t filenumber,
|
||||
uint8_t control_type, const uint8_t *data, uint16_t length, void *userdata)
|
||||
static int handle_filecontrol(Messenger *_Nonnull m, int32_t friendnumber, bool outbound, uint8_t filenumber,
|
||||
uint8_t control_type, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata)
|
||||
{
|
||||
uint32_t real_filenumber;
|
||||
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;
|
||||
|
||||
if (length != sizeof(position)) {
|
||||
LOGGER_DEBUG(m->log, "file control (friend %d, file %d): expected payload of length %d, but got %d",
|
||||
friendnumber, filenumber, (uint32_t)sizeof(position), length);
|
||||
LOGGER_DEBUG(m->log, "file control (friend %d, file %d): expected payload of length %u, but got %d",
|
||||
friendnumber, filenumber, (unsigned int)sizeof(position), length);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1822,7 +1784,7 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, bool outbound,
|
||||
|
||||
if (position >= ft->size) {
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
@@ -1887,12 +1849,10 @@ int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const u
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(5)
|
||||
static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length,
|
||||
void *userdata)
|
||||
static int handle_custom_lossless_packet(void *_Nonnull object, int friend_num, const uint8_t *_Nonnull packet, uint16_t length,
|
||||
void *_Nullable userdata)
|
||||
{
|
||||
Messenger *m = (Messenger *)object;
|
||||
|
||||
if (!m_friend_exists(m, friend_num)) {
|
||||
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*/
|
||||
non_null()
|
||||
static int friend_already_added(void *object, const uint8_t *public_key)
|
||||
static int friend_already_added(void *_Nonnull object, const uint8_t *_Nonnull public_key)
|
||||
{
|
||||
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 t time
|
||||
*/
|
||||
non_null(1) nullable(4)
|
||||
static void check_friend_request_timed_out(Messenger *m, uint32_t friendcon_id, uint64_t t, void *userdata)
|
||||
static void check_friend_request_timed_out(Messenger *_Nonnull m, uint32_t friendcon_id, uint64_t t, void *_Nullable userdata)
|
||||
{
|
||||
Friend *f = &m->friendlist[friendcon_id];
|
||||
|
||||
if (f->friendrequest_lastsent + f->friendrequest_timeout < t) {
|
||||
set_friend_status(m, friendcon_id, FRIEND_ADDED, userdata);
|
||||
/* 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 *object, int friendcon_id, bool status, void *userdata)
|
||||
static int m_handle_status(void *_Nonnull object, int friendcon_id, bool status, void *_Nullable userdata)
|
||||
{
|
||||
Messenger *m = (Messenger *)object;
|
||||
|
||||
if (status) { /* Went online. */
|
||||
send_online_packet(m, m->friendlist[friendcon_id].friendcon_id);
|
||||
} else { /* Went offline. */
|
||||
@@ -1992,8 +1947,7 @@ static int m_handle_status(void *object, int friendcon_id, bool status, void *us
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet_offline(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
|
||||
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)
|
||||
{
|
||||
if (data_length == 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet_nickname(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
|
||||
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)
|
||||
{
|
||||
if (data_length > MAX_NAME_LENGTH) {
|
||||
return 0;
|
||||
@@ -2025,8 +1978,7 @@ static int m_handle_packet_nickname(Messenger *m, const int friendcon_id, const
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet_statusmessage(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
|
||||
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)
|
||||
{
|
||||
if (data_length > MAX_STATUSMESSAGE_LENGTH) {
|
||||
return 0;
|
||||
@@ -2046,8 +1998,7 @@ static int m_handle_packet_statusmessage(Messenger *m, const int friendcon_id, c
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet_userstatus(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
|
||||
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)
|
||||
{
|
||||
if (data_length != 1) {
|
||||
return 0;
|
||||
@@ -2067,8 +2018,7 @@ static int m_handle_packet_userstatus(Messenger *m, const int friendcon_id, cons
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet_typing(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
|
||||
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)
|
||||
{
|
||||
if (data_length != 1) {
|
||||
return 0;
|
||||
@@ -2085,8 +2035,8 @@ static int m_handle_packet_typing(Messenger *m, const int friendcon_id, const ui
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(6)
|
||||
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)
|
||||
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,
|
||||
void *_Nullable userdata)
|
||||
{
|
||||
if (data_length == 0) {
|
||||
return 0;
|
||||
@@ -2107,8 +2057,7 @@ static int m_handle_packet_message(Messenger *m, const int friendcon_id, const u
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet_invite_conference(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
|
||||
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)
|
||||
{
|
||||
if (data_length == 0) {
|
||||
return 0;
|
||||
@@ -2121,11 +2070,9 @@ static int m_handle_packet_invite_conference(Messenger *m, const int friendcon_i
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet_file_sendrequest(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
|
||||
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)
|
||||
{
|
||||
const unsigned int head_length = 1 + sizeof(uint32_t) + sizeof(uint64_t) + FILE_ID_LENGTH;
|
||||
|
||||
if (data_length < head_length) {
|
||||
return 0;
|
||||
}
|
||||
@@ -2186,8 +2133,7 @@ static int m_handle_packet_file_sendrequest(Messenger *m, const int friendcon_id
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet_file_control(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
|
||||
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)
|
||||
{
|
||||
if (data_length < 3) {
|
||||
return 0;
|
||||
@@ -2217,8 +2163,7 @@ static int m_handle_packet_file_control(Messenger *m, const int friendcon_id, co
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet_file_data(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
|
||||
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)
|
||||
{
|
||||
if (data_length < 1) {
|
||||
return 0;
|
||||
@@ -2283,8 +2228,7 @@ static int m_handle_packet_file_data(Messenger *m, const int friendcon_id, const
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet_invite_groupchat(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
|
||||
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)
|
||||
{
|
||||
// first two bytes are messenger packet type and group invite type
|
||||
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;
|
||||
}
|
||||
|
||||
non_null(1, 3) nullable(5)
|
||||
static int m_handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata)
|
||||
static int m_handle_packet(void *_Nonnull object, int friendcon_id, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata)
|
||||
{
|
||||
Messenger *m = (Messenger *)object;
|
||||
|
||||
if (length == 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
non_null(1) nullable(2)
|
||||
static void do_friends(Messenger *m, void *userdata)
|
||||
static void do_friends(Messenger *_Nonnull m, void *_Nullable userdata)
|
||||
{
|
||||
const uint64_t temp_time = mono_time_get(m->mono_time);
|
||||
|
||||
for (uint32_t i = 0; i < m->numfriends; ++i) {
|
||||
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,
|
||||
@@ -2423,11 +2363,9 @@ static void do_friends(Messenger *m, void *userdata)
|
||||
}
|
||||
}
|
||||
|
||||
non_null(1) nullable(2)
|
||||
static void m_connection_status_callback(Messenger *m, void *userdata)
|
||||
static void m_connection_status_callback(Messenger *_Nonnull m, void *_Nullable userdata)
|
||||
{
|
||||
const Onion_Connection_Status conn_status = onion_connection_status(m->onion_c);
|
||||
|
||||
if (conn_status != m->last_connection_status) {
|
||||
if (m->core_connection_change != nullptr) {
|
||||
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)
|
||||
/** id_str should be of length at least IDSTRING_LEN */
|
||||
non_null()
|
||||
static char *id_to_string(const uint8_t *pk, char *id_str, size_t length)
|
||||
static char *id_to_string(const uint8_t *_Nonnull pk, char *_Nonnull id_str, size_t length)
|
||||
{
|
||||
if (length < IDSTRING_LEN) {
|
||||
snprintf(id_str, length, "Bad buf length");
|
||||
@@ -2484,8 +2421,7 @@ uint32_t messenger_run_interval(const Messenger *m)
|
||||
*
|
||||
* @retval true if success.
|
||||
*/
|
||||
non_null()
|
||||
static bool self_announce_group(const Messenger *m, GC_Chat *chat, Onion_Friend *onion_friend)
|
||||
static bool self_announce_group(const Messenger *_Nonnull m, GC_Chat *_Nonnull chat, Onion_Friend *_Nonnull onion_friend)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void do_gc_onion_friends(const Messenger *m)
|
||||
static void do_gc_onion_friends(const Messenger *_Nonnull m)
|
||||
{
|
||||
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) {
|
||||
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,
|
||||
id_to_string(msgfptr->real_pk, id_str, sizeof(id_str)));
|
||||
} else {
|
||||
@@ -2759,8 +2694,7 @@ static uint32_t friend_size(void)
|
||||
return data;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint8_t *friend_save(const struct Saved_Friend *temp, uint8_t *data)
|
||||
static uint8_t *friend_save(const struct Saved_Friend *_Nonnull temp, uint8_t *_Nonnull data)
|
||||
{
|
||||
#define VALUE_MEMBER(data, name) \
|
||||
do { \
|
||||
@@ -2796,8 +2730,7 @@ static uint8_t *friend_save(const struct Saved_Friend *temp, uint8_t *data)
|
||||
return data;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static const uint8_t *friend_load(struct Saved_Friend *temp, const uint8_t *data)
|
||||
static const uint8_t *friend_load(struct Saved_Friend *_Nonnull temp, const uint8_t *_Nonnull data)
|
||||
{
|
||||
#define VALUE_MEMBER(data, name) \
|
||||
do { \
|
||||
@@ -2833,8 +2766,7 @@ static const uint8_t *friend_load(struct Saved_Friend *temp, const uint8_t *data
|
||||
return data;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint32_t m_state_plugins_size(const Messenger *m)
|
||||
static uint32_t m_state_plugins_size(const Messenger *_Nonnull m)
|
||||
{
|
||||
const uint32_t size32 = sizeof(uint32_t);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint32_t m_plugin_size(const Messenger *m, State_Type type)
|
||||
static uint32_t m_plugin_size(const Messenger *_Nonnull m, State_Type type)
|
||||
{
|
||||
for (uint8_t i = 0; i < m->options.state_plugins_length; ++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
|
||||
non_null()
|
||||
static uint32_t nospam_keys_size(const Messenger *m)
|
||||
static uint32_t nospam_keys_size(const Messenger *_Nonnull m)
|
||||
{
|
||||
return sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static State_Load_Status load_nospam_keys(Messenger *m, const uint8_t *data, uint32_t length)
|
||||
static State_Load_Status load_nospam_keys(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
|
||||
{
|
||||
if (length != m_plugin_size(m, STATE_TYPE_NOSPAMKEYS)) {
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint8_t *save_nospam_keys(const Messenger *m, uint8_t *data)
|
||||
static uint8_t *save_nospam_keys(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
|
||||
{
|
||||
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");
|
||||
@@ -2953,14 +2881,12 @@ static uint8_t *save_nospam_keys(const Messenger *m, uint8_t *data)
|
||||
}
|
||||
|
||||
// DHT state plugin
|
||||
non_null()
|
||||
static uint32_t m_dht_size(const Messenger *m)
|
||||
static uint32_t m_dht_size(const Messenger *_Nonnull m)
|
||||
{
|
||||
return dht_size(m->dht);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint8_t *save_dht(const Messenger *m, uint8_t *data)
|
||||
static uint8_t *save_dht(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
|
||||
{
|
||||
const uint32_t len = m_plugin_size(m, 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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static State_Load_Status m_dht_load(Messenger *m, const uint8_t *data, uint32_t length)
|
||||
static State_Load_Status m_dht_load(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
|
||||
{
|
||||
dht_load(m->dht, data, length); // TODO(endoffile78): Should we throw an error if dht_load fails?
|
||||
return STATE_LOAD_STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
// friendlist state plugin
|
||||
non_null()
|
||||
static uint32_t saved_friendslist_size(const Messenger *m)
|
||||
static uint32_t saved_friendslist_size(const Messenger *_Nonnull m)
|
||||
{
|
||||
return count_friendlist(m) * friend_size();
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint8_t *friends_list_save(const Messenger *m, uint8_t *data)
|
||||
static uint8_t *friends_list_save(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
|
||||
{
|
||||
const uint32_t len = m_plugin_size(m, 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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static State_Load_Status friends_list_load(Messenger *m, const uint8_t *data, uint32_t length)
|
||||
static State_Load_Status friends_list_load(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void pack_groupchats(const GC_Session *c, Bin_Pack *bp)
|
||||
static void pack_groupchats(const GC_Session *_Nonnull c, Bin_Pack *_Nonnull bp)
|
||||
{
|
||||
assert(bp != nullptr && c != nullptr);
|
||||
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 *obj, const Logger *logger, Bin_Pack *bp)
|
||||
static bool pack_groupchats_handler(const void *_Nonnull obj, const Logger *_Nonnull logger, Bin_Pack *_Nonnull bp)
|
||||
{
|
||||
const GC_Session *session = (const GC_Session *)obj;
|
||||
pack_groupchats(session, bp);
|
||||
return true; // TODO(iphydf): Return bool from pack functions.
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint32_t saved_groups_size(const Messenger *m)
|
||||
static uint32_t saved_groups_size(const Messenger *_Nonnull m)
|
||||
{
|
||||
const GC_Session *session = m->group_handler;
|
||||
return bin_pack_obj_size(pack_groupchats_handler, session, m->log);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint8_t *groups_save(const Messenger *m, uint8_t *data)
|
||||
static uint8_t *groups_save(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
|
||||
{
|
||||
const GC_Session *c = m->group_handler;
|
||||
|
||||
@@ -3141,8 +3059,7 @@ static uint8_t *groups_save(const Messenger *m, uint8_t *data)
|
||||
return data;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool handle_groups_load(void *obj, Bin_Unpack *bu)
|
||||
static bool handle_groups_load(void *_Nonnull obj, Bin_Unpack *_Nonnull bu)
|
||||
{
|
||||
Messenger *m = (Messenger *)obj;
|
||||
|
||||
@@ -3169,8 +3086,7 @@ static bool handle_groups_load(void *obj, Bin_Unpack *bu)
|
||||
return true;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static State_Load_Status groups_load(Messenger *m, const uint8_t *data, uint32_t length)
|
||||
static State_Load_Status groups_load(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
|
||||
{
|
||||
if (!bin_unpack_obj(m->mem, handle_groups_load, m, data, length)) {
|
||||
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
|
||||
non_null()
|
||||
static uint32_t name_size(const Messenger *m)
|
||||
static uint32_t name_size(const Messenger *_Nonnull m)
|
||||
{
|
||||
return m->name_length;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint8_t *save_name(const Messenger *m, uint8_t *data)
|
||||
static uint8_t *save_name(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
|
||||
{
|
||||
const uint32_t len = m_plugin_size(m, 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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static State_Load_Status load_name(Messenger *m, const uint8_t *data, uint32_t length)
|
||||
static State_Load_Status load_name(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
|
||||
{
|
||||
if (length > 0 && length <= MAX_NAME_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
|
||||
non_null()
|
||||
static uint32_t status_message_size(const Messenger *m)
|
||||
static uint32_t status_message_size(const Messenger *_Nonnull m)
|
||||
{
|
||||
return m->statusmessage_length;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint8_t *save_status_message(const Messenger *m, uint8_t *data)
|
||||
static uint8_t *save_status_message(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
|
||||
{
|
||||
const uint32_t len = m_plugin_size(m, 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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static State_Load_Status load_status_message(Messenger *m, const uint8_t *data, uint32_t length)
|
||||
static State_Load_Status load_status_message(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
|
||||
{
|
||||
if (length > 0 && length <= MAX_STATUSMESSAGE_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
|
||||
non_null()
|
||||
static uint32_t status_size(const Messenger *m)
|
||||
static uint32_t status_size(const Messenger *_Nonnull m)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint8_t *save_status(const Messenger *m, uint8_t *data)
|
||||
static uint8_t *save_status(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
|
||||
{
|
||||
const uint32_t len = m_plugin_size(m, 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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static State_Load_Status load_status(Messenger *m, const uint8_t *data, uint32_t length)
|
||||
static State_Load_Status load_status(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
|
||||
{
|
||||
if (length == 1) {
|
||||
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
|
||||
non_null()
|
||||
static uint32_t tcp_relay_size(const Messenger *m)
|
||||
static uint32_t tcp_relay_size(const Messenger *_Nonnull m)
|
||||
{
|
||||
return NUM_SAVED_TCP_RELAYS * packed_node_size(net_family_tcp_ipv6());
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint8_t *save_tcp_relays(const Messenger *m, uint8_t *data)
|
||||
static uint8_t *save_tcp_relays(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
|
||||
{
|
||||
Node_format relays[NUM_SAVED_TCP_RELAYS] = {{{0}}};
|
||||
uint8_t *temp_data = data;
|
||||
@@ -3293,8 +3198,7 @@ static uint8_t *save_tcp_relays(const Messenger *m, uint8_t *data)
|
||||
return data;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static State_Load_Status load_tcp_relays(Messenger *m, const uint8_t *data, uint32_t length)
|
||||
static State_Load_Status load_tcp_relays(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
|
||||
{
|
||||
if (length > 0) {
|
||||
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
|
||||
non_null()
|
||||
static uint32_t path_node_size(const Messenger *m)
|
||||
static uint32_t path_node_size(const Messenger *_Nonnull m)
|
||||
{
|
||||
return NUM_SAVED_PATH_NODES * packed_node_size(net_family_tcp_ipv6());
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint8_t *save_path_nodes(const Messenger *m, uint8_t *data)
|
||||
static uint8_t *save_path_nodes(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
|
||||
{
|
||||
Node_format nodes[NUM_SAVED_PATH_NODES] = {{{0}}};
|
||||
uint8_t *temp_data = data;
|
||||
@@ -3336,8 +3238,7 @@ static uint8_t *save_path_nodes(const Messenger *m, uint8_t *data)
|
||||
return data;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static State_Load_Status load_path_nodes(Messenger *m, const uint8_t *data, uint32_t length)
|
||||
static State_Load_Status load_path_nodes(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
|
||||
{
|
||||
if (length > 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void m_register_default_plugins(Messenger *m)
|
||||
static void m_register_default_plugins(Messenger *_Nonnull 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_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
|
||||
* 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) {
|
||||
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;
|
||||
non_null(1, 2, 3) nullable(5)
|
||||
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;
|
||||
assert(m != nullptr);
|
||||
|
@@ -54,19 +54,19 @@ typedef struct Messenger Messenger;
|
||||
#endif /* MESSENGER_DEFINED */
|
||||
|
||||
// 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
|
||||
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
|
||||
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 {
|
||||
State_Type type;
|
||||
m_state_size_cb *size;
|
||||
m_state_save_cb *save;
|
||||
m_state_load_cb *load;
|
||||
m_state_size_cb *_Nullable size;
|
||||
m_state_save_cb *_Nullable save;
|
||||
m_state_load_cb *_Nullable load;
|
||||
} Messenger_State_Plugin;
|
||||
|
||||
typedef struct Messenger_Options {
|
||||
@@ -81,11 +81,11 @@ typedef struct Messenger_Options {
|
||||
bool dht_announcements_enabled;
|
||||
bool groups_persistence_enabled;
|
||||
|
||||
logger_cb *log_callback;
|
||||
void *log_context;
|
||||
void *log_user_data;
|
||||
logger_cb *_Nullable log_callback;
|
||||
void *_Nullable log_context;
|
||||
void *_Nullable log_user_data;
|
||||
|
||||
Messenger_State_Plugin *state_plugins;
|
||||
Messenger_State_Plugin *_Nullable state_plugins;
|
||||
uint8_t state_plugins_length;
|
||||
|
||||
bool dns_enabled;
|
||||
@@ -94,7 +94,7 @@ typedef struct Messenger_Options {
|
||||
struct Receipts {
|
||||
uint32_t packet_num;
|
||||
uint32_t msg_id;
|
||||
struct Receipts *next;
|
||||
struct Receipts *_Nullable next;
|
||||
};
|
||||
|
||||
/** Status definitions. */
|
||||
@@ -177,36 +177,36 @@ typedef enum Filekind {
|
||||
FILEKIND_AVATAR,
|
||||
} Filekind;
|
||||
|
||||
typedef void m_self_connection_status_cb(Messenger *m, Onion_Connection_Status connection_status, void *user_data);
|
||||
typedef void m_friend_status_cb(Messenger *m, uint32_t friend_number, unsigned int status, void *user_data);
|
||||
typedef void m_friend_connection_status_cb(Messenger *m, uint32_t friend_number, unsigned int connection_status,
|
||||
void *user_data);
|
||||
typedef void m_friend_message_cb(Messenger *m, uint32_t friend_number, unsigned int message_type,
|
||||
const uint8_t *message, size_t length, void *user_data);
|
||||
typedef void m_file_recv_control_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, unsigned int control,
|
||||
void *user_data);
|
||||
typedef void m_friend_request_cb(Messenger *m, const uint8_t *public_key, const uint8_t *message, size_t length,
|
||||
void *user_data);
|
||||
typedef void m_friend_name_cb(Messenger *m, uint32_t friend_number, const uint8_t *name, size_t length,
|
||||
void *user_data);
|
||||
typedef void m_friend_status_message_cb(Messenger *m, uint32_t friend_number, const uint8_t *message, size_t length,
|
||||
void *user_data);
|
||||
typedef void m_friend_typing_cb(Messenger *m, uint32_t friend_number, bool is_typing, void *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_file_recv_cb(Messenger *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);
|
||||
typedef void m_file_chunk_request_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, uint64_t position,
|
||||
size_t length, void *user_data);
|
||||
typedef void m_file_recv_chunk_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, uint64_t position,
|
||||
const uint8_t *data, size_t length, void *user_data);
|
||||
typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data,
|
||||
size_t length, void *user_data);
|
||||
typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data,
|
||||
size_t length, void *user_data);
|
||||
typedef void m_conference_invite_cb(Messenger *m, uint32_t friend_number, const uint8_t *cookie, uint16_t length,
|
||||
void *user_data);
|
||||
typedef void m_group_invite_cb(const Messenger *m, uint32_t friend_number, const uint8_t *invite_data, size_t length,
|
||||
const uint8_t *group_name, size_t group_name_length, void *user_data);
|
||||
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 *_Nonnull m, uint32_t friend_number, unsigned int status, void *_Nullable user_data);
|
||||
typedef void m_friend_connection_status_cb(Messenger *_Nonnull m, uint32_t friend_number, unsigned int connection_status,
|
||||
void *_Nullable user_data);
|
||||
typedef void m_friend_message_cb(Messenger *_Nonnull m, uint32_t friend_number, unsigned int message_type,
|
||||
const uint8_t *_Nonnull message, size_t length, void *_Nullable user_data);
|
||||
typedef void m_file_recv_control_cb(Messenger *_Nonnull m, uint32_t friend_number, uint32_t file_number, unsigned int control,
|
||||
void *_Nullable user_data);
|
||||
typedef void m_friend_request_cb(Messenger *_Nonnull m, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull message, size_t length,
|
||||
void *_Nullable user_data);
|
||||
typedef void m_friend_name_cb(Messenger *_Nonnull m, uint32_t friend_number, const uint8_t *_Nonnull name, size_t length,
|
||||
void *_Nullable user_data);
|
||||
typedef void m_friend_status_message_cb(Messenger *_Nonnull m, uint32_t friend_number, const uint8_t *_Nonnull message, size_t length,
|
||||
void *_Nullable 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 *_Nonnull m, uint32_t friend_number, uint32_t message_id, void *_Nullable user_data);
|
||||
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 *_Nonnull filename, size_t filename_length, void *_Nullable user_data);
|
||||
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 *_Nullable user_data);
|
||||
typedef void m_file_recv_chunk_cb(Messenger *_Nonnull m, uint32_t friend_number, uint32_t file_number, uint64_t position,
|
||||
const uint8_t *_Nullable data, size_t length, void *_Nullable user_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 *_Nullable user_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 *_Nullable user_data);
|
||||
typedef void m_conference_invite_cb(Messenger *_Nonnull m, uint32_t friend_number, const uint8_t *_Nonnull cookie, uint16_t length,
|
||||
void *_Nullable user_data);
|
||||
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 *_Nullable group_name, size_t group_name_length, void *_Nullable user_data);
|
||||
|
||||
typedef struct Friend {
|
||||
uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
@@ -236,33 +236,33 @@ typedef struct Friend {
|
||||
uint32_t num_sending_files;
|
||||
struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
|
||||
|
||||
struct Receipts *receipts_start;
|
||||
struct Receipts *receipts_end;
|
||||
struct Receipts *_Nullable receipts_start;
|
||||
struct Receipts *_Nullable receipts_end;
|
||||
} Friend;
|
||||
|
||||
struct Messenger {
|
||||
Logger *log;
|
||||
Mono_Time *mono_time;
|
||||
const Memory *mem;
|
||||
const Random *rng;
|
||||
const Network *ns;
|
||||
Logger *_Nullable log;
|
||||
Mono_Time *_Nullable mono_time;
|
||||
const Memory *_Nullable mem;
|
||||
const Random *_Nullable rng;
|
||||
const Network *_Nullable ns;
|
||||
|
||||
Networking_Core *net;
|
||||
Net_Crypto *net_crypto;
|
||||
Net_Profile *tcp_np;
|
||||
DHT *dht;
|
||||
Networking_Core *_Nonnull net;
|
||||
Net_Crypto *_Nonnull net_crypto;
|
||||
Net_Profile *_Nullable tcp_np;
|
||||
DHT *_Nonnull dht;
|
||||
|
||||
Forwarding *forwarding;
|
||||
Announcements *announce;
|
||||
Forwarding *_Nullable forwarding;
|
||||
Announcements *_Nullable announce;
|
||||
|
||||
Onion *onion;
|
||||
Onion_Announce *onion_a;
|
||||
Onion_Client *onion_c;
|
||||
Onion *_Nullable onion;
|
||||
Onion_Announce *_Nullable onion_a;
|
||||
Onion_Client *_Nullable onion_c;
|
||||
|
||||
Friend_Connections *fr_c;
|
||||
Friend_Connections *_Nullable fr_c;
|
||||
|
||||
TCP_Server *tcp_server;
|
||||
Friend_Requests *fr;
|
||||
TCP_Server *_Nullable tcp_server;
|
||||
Friend_Requests *_Nullable fr;
|
||||
uint8_t name[MAX_NAME_LENGTH];
|
||||
uint16_t name_length;
|
||||
|
||||
@@ -271,43 +271,43 @@ struct Messenger {
|
||||
|
||||
Userstatus userstatus;
|
||||
|
||||
Friend *friendlist;
|
||||
Friend *_Nullable friendlist;
|
||||
uint32_t numfriends;
|
||||
|
||||
uint64_t lastdump;
|
||||
uint8_t is_receiving_file;
|
||||
|
||||
GC_Session *group_handler;
|
||||
GC_Announces_List *group_announce;
|
||||
GC_Session *_Nonnull group_handler;
|
||||
GC_Announces_List *_Nonnull group_announce;
|
||||
|
||||
bool has_added_relays; // If the first connection has occurred in do_messenger
|
||||
|
||||
uint16_t num_loaded_relays;
|
||||
Node_format loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config
|
||||
|
||||
m_friend_request_cb *friend_request;
|
||||
m_friend_message_cb *friend_message;
|
||||
m_friend_name_cb *friend_namechange;
|
||||
m_friend_status_message_cb *friend_statusmessagechange;
|
||||
m_friend_status_cb *friend_userstatuschange;
|
||||
m_friend_typing_cb *friend_typingchange;
|
||||
m_friend_read_receipt_cb *read_receipt;
|
||||
m_friend_connection_status_cb *friend_connectionstatuschange;
|
||||
m_friend_request_cb *_Nullable friend_request;
|
||||
m_friend_message_cb *_Nullable friend_message;
|
||||
m_friend_name_cb *_Nullable friend_namechange;
|
||||
m_friend_status_message_cb *_Nullable friend_statusmessagechange;
|
||||
m_friend_status_cb *_Nullable friend_userstatuschange;
|
||||
m_friend_typing_cb *_Nullable friend_typingchange;
|
||||
m_friend_read_receipt_cb *_Nullable read_receipt;
|
||||
m_friend_connection_status_cb *_Nullable friend_connectionstatuschange;
|
||||
|
||||
struct Group_Chats *conferences_object;
|
||||
m_conference_invite_cb *conference_invite;
|
||||
struct Group_Chats *_Nullable conferences_object;
|
||||
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_control_cb *file_filecontrol;
|
||||
m_file_recv_chunk_cb *file_filedata;
|
||||
m_file_chunk_request_cb *file_reqchunk;
|
||||
m_file_recv_cb *_Nullable file_sendrequest;
|
||||
m_file_recv_control_cb *_Nullable file_filecontrol;
|
||||
m_file_recv_chunk_cb *_Nullable file_filedata;
|
||||
m_file_chunk_request_cb *_Nullable file_reqchunk;
|
||||
|
||||
m_friend_lossy_packet_cb *lossy_packethandler;
|
||||
m_friend_lossless_packet_cb *lossless_packethandler;
|
||||
m_friend_lossy_packet_cb *_Nullable lossy_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;
|
||||
|
||||
Messenger_Options options;
|
||||
@@ -318,16 +318,14 @@ struct Messenger {
|
||||
*
|
||||
* @param friendnumber The index in the friend list.
|
||||
*/
|
||||
non_null()
|
||||
bool friend_is_valid(const Messenger *m, int32_t friendnumber);
|
||||
bool friend_is_valid(const Messenger *_Nonnull m, int32_t friendnumber);
|
||||
|
||||
/**
|
||||
* Format: `[real_pk (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]`
|
||||
*
|
||||
* @param[out] address FRIEND_ADDRESS_SIZE byte address to give to others.
|
||||
*/
|
||||
non_null()
|
||||
void getaddress(const Messenger *m, uint8_t *address);
|
||||
void getaddress(const Messenger *_Nonnull m, uint8_t *_Nonnull address);
|
||||
|
||||
/**
|
||||
* 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).
|
||||
* @retval FAERR_NOMEM if increasing the friend list size fails.
|
||||
*/
|
||||
non_null()
|
||||
int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, uint16_t length);
|
||||
int32_t m_addfriend(Messenger *_Nonnull m, const uint8_t *_Nonnull address, const uint8_t *_Nonnull data, uint16_t length);
|
||||
|
||||
/** @brief Add a friend without sending a friendrequest.
|
||||
* @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 -8 if increasing the friend list size fails.
|
||||
*/
|
||||
non_null()
|
||||
int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk);
|
||||
int32_t m_addfriend_norequest(Messenger *_Nonnull m, const uint8_t *_Nonnull real_pk);
|
||||
|
||||
/** @brief Initializes the friend connection and onion connection for a groupchat.
|
||||
*
|
||||
* @retval true on success.
|
||||
*/
|
||||
non_null()
|
||||
bool m_create_group_connection(Messenger *m, GC_Chat *chat);
|
||||
bool m_create_group_connection(Messenger *_Nonnull m, GC_Chat *_Nonnull chat);
|
||||
|
||||
/*
|
||||
* Kills the friend connection for a groupchat.
|
||||
*/
|
||||
non_null()
|
||||
void m_kill_group_connection(Messenger *m, const GC_Chat *chat);
|
||||
void m_kill_group_connection(Messenger *_Nonnull m, const GC_Chat *_Nonnull chat);
|
||||
|
||||
/** @return the friend number associated to that public key.
|
||||
* @retval -1 if no such friend.
|
||||
*/
|
||||
non_null()
|
||||
int32_t getfriend_id(const Messenger *m, const uint8_t *real_pk);
|
||||
int32_t getfriend_id(const Messenger *_Nonnull m, const uint8_t *_Nonnull real_pk);
|
||||
|
||||
/** @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 -1 if failure.
|
||||
*/
|
||||
non_null()
|
||||
int get_real_pk(const Messenger *m, int32_t friendnumber, uint8_t *real_pk);
|
||||
int get_real_pk(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t *_Nonnull real_pk);
|
||||
|
||||
/** @return friend connection id on success.
|
||||
* @retval -1 if failure.
|
||||
*/
|
||||
non_null()
|
||||
int getfriendcon_id(const Messenger *m, int32_t friendnumber);
|
||||
int getfriendcon_id(const Messenger *_Nonnull m, int32_t friendnumber);
|
||||
|
||||
/** @brief Remove a friend.
|
||||
*
|
||||
* @retval 0 if success.
|
||||
* @retval -1 if failure.
|
||||
*/
|
||||
non_null()
|
||||
int m_delfriend(Messenger *m, int32_t friendnumber);
|
||||
int m_delfriend(Messenger *_Nonnull m, int32_t friendnumber);
|
||||
|
||||
/** @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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber);
|
||||
int m_get_friend_connectionstatus(const Messenger *_Nonnull m, int32_t 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 false if friend doesn't exist.
|
||||
*/
|
||||
non_null()
|
||||
bool m_friend_exists(const Messenger *m, int32_t friendnumber);
|
||||
bool m_friend_exists(const Messenger *_Nonnull m, int32_t friendnumber);
|
||||
|
||||
/** @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.
|
||||
*/
|
||||
non_null(1, 4) nullable(6)
|
||||
int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, const uint8_t *message, uint32_t length,
|
||||
uint32_t *message_id);
|
||||
|
||||
int m_send_message_generic(Messenger *_Nonnull m, int32_t friendnumber, uint8_t type, const uint8_t *_Nonnull message, uint32_t length,
|
||||
uint32_t *_Nullable message_id);
|
||||
/** @brief Set the name and name_length of a friend.
|
||||
*
|
||||
* 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 -1 if failure.
|
||||
*/
|
||||
non_null()
|
||||
int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length);
|
||||
int setfriendname(Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull name, uint16_t length);
|
||||
|
||||
/** @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 -1 if failure.
|
||||
*/
|
||||
non_null()
|
||||
int setname(Messenger *m, const uint8_t *name, uint16_t length);
|
||||
int setname(Messenger *_Nonnull m, const uint8_t *_Nonnull name, uint16_t length);
|
||||
|
||||
/**
|
||||
* @brief Get your nickname.
|
||||
@@ -475,8 +459,7 @@ int setname(Messenger *m, const uint8_t *name, uint16_t length);
|
||||
* @return length of the name.
|
||||
* @retval 0 on error.
|
||||
*/
|
||||
non_null()
|
||||
uint16_t getself_name(const Messenger *m, uint8_t *name);
|
||||
uint16_t getself_name(const Messenger *_Nonnull m, uint8_t *_Nonnull 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.
|
||||
* @retval -1 if failure.
|
||||
*/
|
||||
non_null()
|
||||
int getname(const Messenger *m, int32_t friendnumber, uint8_t *name);
|
||||
int getname(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t *_Nonnull name);
|
||||
|
||||
/** @return the length of name, including null on success.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null() int m_get_name_size(const Messenger *m, int32_t friendnumber);
|
||||
non_null() int m_get_self_name_size(const Messenger *m);
|
||||
int m_get_name_size(const Messenger *_Nonnull m, int32_t friendnumber);
|
||||
int m_get_self_name_size(const Messenger *_Nonnull m);
|
||||
|
||||
/** @brief Set our user status.
|
||||
* You are responsible for freeing status after.
|
||||
*
|
||||
* @retval 0 on success.
|
||||
* @retval -1 on failure.
|
||||
* @retval 0 if success.
|
||||
* @retval -1 if failure.
|
||||
*/
|
||||
non_null() int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length);
|
||||
non_null() int m_set_userstatus(Messenger *m, uint8_t status);
|
||||
int m_set_statusmessage(Messenger *_Nonnull m, const uint8_t *_Nonnull status, uint16_t length);
|
||||
int m_set_userstatus(Messenger *_Nonnull m, uint8_t status);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null() int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber);
|
||||
non_null() int m_get_self_statusmessage_size(const Messenger *m);
|
||||
int m_get_statusmessage_size(const Messenger *_Nonnull m, int32_t friendnumber);
|
||||
int m_get_self_statusmessage_size(const Messenger *_Nonnull m);
|
||||
|
||||
/** @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
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null() int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen);
|
||||
non_null() int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf);
|
||||
int m_copy_statusmessage(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t *_Nonnull buf, uint32_t maxlen);
|
||||
int m_copy_self_statusmessage(const Messenger *_Nonnull m, uint8_t *_Nonnull buf);
|
||||
|
||||
/** @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.
|
||||
* If friendnumber is invalid, this shall return USERSTATUS_INVALID.
|
||||
*/
|
||||
non_null() uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber);
|
||||
non_null() uint8_t m_get_self_userstatus(const Messenger *m);
|
||||
uint8_t m_get_userstatus(const Messenger *_Nonnull m, int32_t friendnumber);
|
||||
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.
|
||||
* 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.
|
||||
* 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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int m_set_usertyping(Messenger *m, int32_t friendnumber, bool is_typing);
|
||||
int m_set_usertyping(Messenger *_Nonnull m, int32_t friendnumber, bool is_typing);
|
||||
|
||||
/** @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 1 if friend is typing.
|
||||
*/
|
||||
non_null()
|
||||
int m_get_istyping(const Messenger *m, int32_t friendnumber);
|
||||
int m_get_istyping(const Messenger *_Nonnull m, int32_t friendnumber);
|
||||
|
||||
/** Set the function that will be executed when a friend request is received. */
|
||||
non_null(1) nullable(2)
|
||||
void m_callback_friendrequest(Messenger *m, m_friend_request_cb *function);
|
||||
|
||||
void m_callback_friendrequest(Messenger *_Nonnull m, m_friend_request_cb *_Nullable function);
|
||||
/** 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.
|
||||
* 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.
|
||||
*
|
||||
* 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. */
|
||||
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. */
|
||||
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.
|
||||
*
|
||||
@@ -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.
|
||||
* 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.
|
||||
*
|
||||
@@ -599,29 +577,24 @@ non_null() void m_callback_read_receipt(Messenger *m, m_friend_read_receipt_cb *
|
||||
* "after being previously online" part.
|
||||
* 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. */
|
||||
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 */
|
||||
|
||||
/** @brief Set the callback for conference invites. */
|
||||
non_null(1) nullable(2)
|
||||
void m_callback_conference_invite(Messenger *m, m_conference_invite_cb *function);
|
||||
|
||||
void m_callback_conference_invite(Messenger *_Nonnull m, m_conference_invite_cb *_Nullable function);
|
||||
/* Set the callback for group invites.
|
||||
*/
|
||||
non_null(1) nullable(2)
|
||||
void m_callback_group_invite(Messenger *m, m_group_invite_cb *function);
|
||||
|
||||
void m_callback_group_invite(Messenger *_Nonnull m, m_group_invite_cb *_Nullable function);
|
||||
/** @brief Send a conference invite packet.
|
||||
*
|
||||
* return true on success
|
||||
* return false on failure
|
||||
*/
|
||||
non_null()
|
||||
bool send_conference_invite_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length);
|
||||
bool send_conference_invite_packet(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull data, uint16_t length);
|
||||
|
||||
/* 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
|
||||
*/
|
||||
non_null()
|
||||
bool send_group_invite_packet(const Messenger *m, uint32_t friendnumber, const uint8_t *packet, uint16_t length);
|
||||
bool send_group_invite_packet(const Messenger *_Nonnull m, uint32_t friendnumber, const uint8_t *_Nonnull packet, uint16_t length);
|
||||
|
||||
/*** FILE SENDING */
|
||||
|
||||
/** @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. */
|
||||
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. */
|
||||
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. */
|
||||
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
|
||||
*
|
||||
@@ -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 -2 if filenumber not valid
|
||||
*/
|
||||
non_null()
|
||||
int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint8_t *file_id);
|
||||
int file_get_id(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t filenumber, uint8_t *_Nonnull file_id);
|
||||
|
||||
/** @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 -4 if could not send packet (friend offline).
|
||||
*/
|
||||
non_null()
|
||||
long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize,
|
||||
const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length);
|
||||
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,
|
||||
uint16_t filename_length);
|
||||
|
||||
/** @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 -8 if packet failed to send.
|
||||
*/
|
||||
non_null()
|
||||
int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber, unsigned int control);
|
||||
int file_control(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t filenumber, unsigned int control);
|
||||
|
||||
/** @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 -8 if packet failed to send.
|
||||
*/
|
||||
non_null()
|
||||
int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position);
|
||||
int file_seek(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t filenumber, uint64_t position);
|
||||
|
||||
/** @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 -7 if wrong position.
|
||||
*/
|
||||
non_null(1) nullable(5)
|
||||
int send_file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position,
|
||||
const uint8_t *data, uint16_t length);
|
||||
|
||||
int send_file_data(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t filenumber, uint64_t position,
|
||||
const uint8_t *_Nullable data, uint16_t length);
|
||||
/*** CUSTOM 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.
|
||||
*
|
||||
@@ -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 0 on success.
|
||||
*/
|
||||
non_null()
|
||||
int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
|
||||
int m_send_custom_lossy_packet(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull data, uint32_t length);
|
||||
|
||||
/** @brief Set handlers for custom lossless packets. */
|
||||
non_null()
|
||||
void custom_lossless_packet_registerhandler(Messenger *m, m_friend_lossless_packet_cb *lossless_packethandler);
|
||||
void custom_lossless_packet_registerhandler(Messenger *_Nonnull m, m_friend_lossless_packet_cb *_Nonnull lossless_packethandler);
|
||||
|
||||
/** @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 0 on success.
|
||||
*/
|
||||
non_null()
|
||||
int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
|
||||
int send_custom_lossless_packet(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull data, uint32_t length);
|
||||
|
||||
/*** 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.
|
||||
*/
|
||||
non_null()
|
||||
Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *rng, const Network *ns,
|
||||
Messenger_Options *options, Messenger_Error *error);
|
||||
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_Error *_Nonnull error);
|
||||
|
||||
/** @brief Run this before closing shop.
|
||||
*
|
||||
* Free all datastructures.
|
||||
*/
|
||||
nullable(1)
|
||||
void kill_messenger(Messenger *m);
|
||||
|
||||
void kill_messenger(Messenger *_Nullable m);
|
||||
/** @brief The main loop that needs to be run at least 20 times per second. */
|
||||
non_null(1) nullable(2)
|
||||
void do_messenger(Messenger *m, void *userdata);
|
||||
|
||||
void do_messenger(Messenger *_Nonnull m, void *_Nullable userdata);
|
||||
/**
|
||||
* @brief Return the time in milliseconds before `do_messenger()` should be called again
|
||||
* for optimal performance.
|
||||
*
|
||||
* @return time (in ms) before the next `do_messenger()` needs to be run on success.
|
||||
*/
|
||||
non_null()
|
||||
uint32_t messenger_run_interval(const Messenger *m);
|
||||
uint32_t messenger_run_interval(const Messenger *_Nonnull m);
|
||||
|
||||
/* SAVING AND LOADING FUNCTIONS: */
|
||||
|
||||
@@ -794,19 +751,13 @@ uint32_t messenger_run_interval(const Messenger *m);
|
||||
* @retval true on success
|
||||
* @retval false on error
|
||||
*/
|
||||
non_null()
|
||||
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);
|
||||
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);
|
||||
|
||||
/** return size of the messenger data (for saving). */
|
||||
non_null()
|
||||
uint32_t messenger_size(const Messenger *m);
|
||||
uint32_t messenger_size(const Messenger *_Nonnull m);
|
||||
|
||||
/** Save the messenger in data (must be allocated memory of size at least `Messenger_size()`) */
|
||||
non_null()
|
||||
uint8_t *messenger_save(const Messenger *m, uint8_t *data);
|
||||
uint8_t *_Nonnull messenger_save(const Messenger *_Nonnull m, uint8_t *_Nonnull data);
|
||||
|
||||
/** @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.
|
||||
* @return true iff section handled.
|
||||
*/
|
||||
non_null()
|
||||
bool messenger_load_state_section(Messenger *m, const uint8_t *data, uint32_t length, uint16_t type,
|
||||
State_Load_Status *status);
|
||||
bool messenger_load_state_section(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length, uint16_t type, State_Load_Status *_Nonnull status);
|
||||
|
||||
/** @brief Return the number of friends in the instance m.
|
||||
*
|
||||
* You should use this to determine how much memory to allocate
|
||||
* for copy_friendlist.
|
||||
*/
|
||||
non_null()
|
||||
uint32_t count_friendlist(const Messenger *m);
|
||||
uint32_t count_friendlist(const Messenger *_Nonnull m);
|
||||
|
||||
/** @brief Copy a list of valid friend IDs into the array out_list.
|
||||
* 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
|
||||
* of out_list will be truncated to list_size.
|
||||
*/
|
||||
non_null()
|
||||
uint32_t copy_friendlist(const Messenger *m, uint32_t *out_list, uint32_t list_size);
|
||||
uint32_t copy_friendlist(const Messenger *_Nonnull m, uint32_t *_Nonnull out_list, uint32_t list_size);
|
||||
|
||||
non_null()
|
||||
bool m_is_receiving_file(Messenger *m);
|
||||
bool m_is_receiving_file(Messenger *_Nonnull m);
|
||||
|
||||
#endif /* C_TOXCORE_TOXCORE_MESSENGER_H */
|
||||
|
@@ -107,8 +107,8 @@ void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value)
|
||||
* @retval true on success
|
||||
* @retval false on failure
|
||||
*/
|
||||
non_null()
|
||||
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)
|
||||
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,
|
||||
const TCP_Proxy_Info *_Nonnull proxy_info)
|
||||
{
|
||||
Net_Err_Connect err;
|
||||
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 0 on failure.
|
||||
*/
|
||||
non_null()
|
||||
static int proxy_http_generate_connection_request(TCP_Client_Connection *tcp_conn)
|
||||
static int proxy_http_generate_connection_request(TCP_Client_Connection *_Nonnull tcp_conn)
|
||||
{
|
||||
const char one[] = "CONNECT ";
|
||||
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 -1 on failure (connection refused).
|
||||
*/
|
||||
non_null()
|
||||
static int proxy_http_read_connection_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
|
||||
static int proxy_http_read_connection_response(const Logger *_Nonnull logger, const TCP_Client_Connection *_Nonnull tcp_conn)
|
||||
{
|
||||
const char success[] = "200";
|
||||
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,
|
||||
};
|
||||
|
||||
non_null()
|
||||
static void proxy_socks5_generate_greetings(TCP_Client_Connection *tcp_conn)
|
||||
static void proxy_socks5_generate_greetings(TCP_Client_Connection *_Nonnull tcp_conn)
|
||||
{
|
||||
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;
|
||||
@@ -230,8 +227,7 @@ static void proxy_socks5_generate_greetings(TCP_Client_Connection *tcp_conn)
|
||||
* @retval 0 if no data received.
|
||||
* @retval -1 on failure (connection refused).
|
||||
*/
|
||||
non_null()
|
||||
static int socks5_read_handshake_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
|
||||
static int socks5_read_handshake_response(const Logger *_Nonnull logger, const TCP_Client_Connection *_Nonnull tcp_conn)
|
||||
{
|
||||
uint8_t data[2];
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void proxy_socks5_generate_connection_request(TCP_Client_Connection *tcp_conn)
|
||||
static void proxy_socks5_generate_connection_request(TCP_Client_Connection *_Nonnull tcp_conn)
|
||||
{
|
||||
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;
|
||||
@@ -280,8 +275,7 @@ static void proxy_socks5_generate_connection_request(TCP_Client_Connection *tcp_
|
||||
* @retval 0 if no data received.
|
||||
* @retval -1 on failure (connection refused).
|
||||
*/
|
||||
non_null()
|
||||
static int proxy_socks5_read_connection_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
|
||||
static int proxy_socks5_read_connection_response(const Logger *_Nonnull logger, const TCP_Client_Connection *_Nonnull tcp_conn)
|
||||
{
|
||||
if (net_family_is_ipv4(tcp_conn->ip_port.ip.family)) {
|
||||
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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
static int generate_handshake(TCP_Client_Connection *tcp_conn)
|
||||
static int generate_handshake(TCP_Client_Connection *_Nonnull tcp_conn)
|
||||
{
|
||||
uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE];
|
||||
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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
static int handle_handshake(TCP_Client_Connection *tcp_conn, const uint8_t *data)
|
||||
static int handle_handshake(TCP_Client_Connection *_Nonnull tcp_conn, const uint8_t *_Nonnull data)
|
||||
{
|
||||
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,
|
||||
@@ -385,8 +377,8 @@ void routing_status_handler(TCP_Client_Connection *con, tcp_routing_status_cb *s
|
||||
con->status_callback_object = object;
|
||||
}
|
||||
|
||||
non_null() static int tcp_send_ping_response(const Logger *logger, TCP_Client_Connection *con);
|
||||
non_null() static int tcp_send_ping_request(const Logger *logger, TCP_Client_Connection *con);
|
||||
static int tcp_send_ping_response(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con);
|
||||
static int tcp_send_ping_request(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con);
|
||||
|
||||
/**
|
||||
* @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 -1 on failure (connection must be killed).
|
||||
*/
|
||||
non_null()
|
||||
static int client_send_disconnect_notification(const Logger *logger, TCP_Client_Connection *con, uint8_t id)
|
||||
static int client_send_disconnect_notification(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, uint8_t id)
|
||||
{
|
||||
uint8_t packet[1 + 1];
|
||||
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 -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) {
|
||||
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 -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) {
|
||||
return 1;
|
||||
@@ -595,7 +586,7 @@ void forwarding_handler(TCP_Client_Connection *con, forwarded_response_cb *forwa
|
||||
TCP_Client_Connection *new_tcp_connection(
|
||||
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 TCP_Proxy_Info *proxy_info, Net_Profile *net_profile)
|
||||
const TCP_Proxy_Info *proxy_info, Net_Profile *_Nullable net_profile)
|
||||
{
|
||||
assert(logger != nullptr);
|
||||
assert(mem != nullptr);
|
||||
@@ -699,8 +690,7 @@ TCP_Client_Connection *new_tcp_connection(
|
||||
return temp;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int handle_tcp_client_routing_response(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
|
||||
static int handle_tcp_client_routing_response(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
|
||||
{
|
||||
if (length != 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE) {
|
||||
return -1;
|
||||
@@ -727,8 +717,7 @@ static int handle_tcp_client_routing_response(TCP_Client_Connection *conn, const
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int handle_tcp_client_connection_notification(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
|
||||
static int handle_tcp_client_connection_notification(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
|
||||
{
|
||||
if (length != 1 + 1) {
|
||||
return -1;
|
||||
@@ -754,8 +743,7 @@ static int handle_tcp_client_connection_notification(TCP_Client_Connection *conn
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int handle_tcp_client_disconnect_notification(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
|
||||
static int handle_tcp_client_disconnect_notification(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
|
||||
{
|
||||
if (length != 1 + 1) {
|
||||
return -1;
|
||||
@@ -785,8 +773,7 @@ static int handle_tcp_client_disconnect_notification(TCP_Client_Connection *conn
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int handle_tcp_client_ping(const Logger *logger, TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
|
||||
static int handle_tcp_client_ping(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
|
||||
{
|
||||
if (length != 1 + sizeof(uint64_t)) {
|
||||
return -1;
|
||||
@@ -799,8 +786,7 @@ static int handle_tcp_client_ping(const Logger *logger, TCP_Client_Connection *c
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int handle_tcp_client_pong(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
|
||||
static int handle_tcp_client_pong(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
|
||||
{
|
||||
if (length != 1 + sizeof(uint64_t)) {
|
||||
return -1;
|
||||
@@ -820,8 +806,7 @@ static int handle_tcp_client_pong(TCP_Client_Connection *conn, const uint8_t *da
|
||||
return -1;
|
||||
}
|
||||
|
||||
non_null(1, 2) nullable(4)
|
||||
static int handle_tcp_client_oob_recv(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length, void *userdata)
|
||||
static int handle_tcp_client_oob_recv(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata)
|
||||
{
|
||||
if (length <= 1 + CRYPTO_PUBLIC_KEY_SIZE) {
|
||||
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 -1 on failure
|
||||
*/
|
||||
non_null(1, 2, 3) nullable(5)
|
||||
static int handle_tcp_client_packet(const Logger *logger, TCP_Client_Connection *conn, const uint8_t *data,
|
||||
uint16_t length, void *userdata)
|
||||
static int handle_tcp_client_packet(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data,
|
||||
uint16_t length, void *_Nullable userdata)
|
||||
{
|
||||
if (length <= 1) {
|
||||
return -1;
|
||||
@@ -899,8 +883,7 @@ static int handle_tcp_client_packet(const Logger *logger, TCP_Client_Connection
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null(1, 2) nullable(3)
|
||||
static bool tcp_process_packet(const Logger *logger, TCP_Client_Connection *conn, void *userdata)
|
||||
static bool tcp_process_packet(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull conn, void *_Nullable userdata)
|
||||
{
|
||||
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),
|
||||
@@ -923,9 +906,8 @@ static bool tcp_process_packet(const Logger *logger, TCP_Client_Connection *conn
|
||||
return true;
|
||||
}
|
||||
|
||||
non_null(1, 2, 3) nullable(4)
|
||||
static int do_confirmed_tcp(const Logger *logger, TCP_Client_Connection *conn, const Mono_Time *mono_time,
|
||||
void *userdata)
|
||||
static int do_confirmed_tcp(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull conn, const Mono_Time *_Nonnull mono_time,
|
||||
void *_Nullable userdata)
|
||||
{
|
||||
send_pending_data(logger, &conn->con);
|
||||
tcp_send_ping_response(logger, conn);
|
||||
|
@@ -44,78 +44,56 @@ typedef enum TCP_Client_Status {
|
||||
|
||||
typedef struct TCP_Client_Connection TCP_Client_Connection;
|
||||
|
||||
non_null()
|
||||
const uint8_t *tcp_con_public_key(const TCP_Client_Connection *con);
|
||||
non_null()
|
||||
IP_Port tcp_con_ip_port(const TCP_Client_Connection *con);
|
||||
non_null()
|
||||
TCP_Client_Status tcp_con_status(const TCP_Client_Connection *con);
|
||||
const uint8_t *_Nonnull tcp_con_public_key(const TCP_Client_Connection *_Nonnull con);
|
||||
IP_Port tcp_con_ip_port(const TCP_Client_Connection *_Nonnull con);
|
||||
TCP_Client_Status tcp_con_status(const TCP_Client_Connection *_Nonnull con);
|
||||
|
||||
non_null()
|
||||
void *tcp_con_custom_object(const TCP_Client_Connection *con);
|
||||
non_null()
|
||||
uint32_t tcp_con_custom_uint(const TCP_Client_Connection *con);
|
||||
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);
|
||||
void *_Nullable tcp_con_custom_object(const TCP_Client_Connection *_Nonnull con);
|
||||
uint32_t tcp_con_custom_uint(const TCP_Client_Connection *_Nonnull con);
|
||||
void tcp_con_set_custom_object(TCP_Client_Connection *_Nonnull con, void *_Nonnull object);
|
||||
void tcp_con_set_custom_uint(TCP_Client_Connection *_Nonnull con, uint32_t value);
|
||||
|
||||
/** 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 *new_tcp_connection(
|
||||
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 TCP_Proxy_Info *proxy_info, Net_Profile *net_profile);
|
||||
|
||||
TCP_Client_Connection *_Nullable 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 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 TCP_Proxy_Info *_Nullable proxy_info, Net_Profile *_Nullable net_profile);
|
||||
/** Run the TCP connection */
|
||||
non_null(1, 2, 3) nullable(4)
|
||||
void do_tcp_connection(const Logger *logger, const Mono_Time *mono_time,
|
||||
TCP_Client_Connection *tcp_connection, void *userdata);
|
||||
|
||||
void do_tcp_connection(const Logger *_Nonnull logger, const Mono_Time *_Nonnull mono_time,
|
||||
TCP_Client_Connection *_Nonnull tcp_connection, void *_Nullable userdata);
|
||||
/** Kill the TCP connection */
|
||||
nullable(1)
|
||||
void kill_tcp_connection(TCP_Client_Connection *tcp_connection);
|
||||
|
||||
typedef int tcp_onion_response_cb(void *object, const uint8_t *data, uint16_t length, void *userdata);
|
||||
void kill_tcp_connection(TCP_Client_Connection *_Nullable tcp_connection);
|
||||
typedef int tcp_onion_response_cb(void *_Nonnull object, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
|
||||
|
||||
/**
|
||||
* @retval 1 on success.
|
||||
* @retval 0 if could not send packet.
|
||||
* @retval -1 on failure (connection must be killed).
|
||||
*/
|
||||
non_null()
|
||||
int send_onion_request(const Logger *logger, TCP_Client_Connection *con, const uint8_t *data, uint16_t length);
|
||||
non_null()
|
||||
void onion_response_handler(TCP_Client_Connection *con, tcp_onion_response_cb *onion_callback, void *object);
|
||||
int send_onion_request(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, const uint8_t *_Nonnull 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()
|
||||
int send_forward_request_tcp(const Logger *logger, TCP_Client_Connection *con, const IP_Port *dest, const uint8_t *data,
|
||||
uint16_t length);
|
||||
non_null()
|
||||
void forwarding_handler(TCP_Client_Connection *con, forwarded_response_cb *forwarded_response_callback, void *object);
|
||||
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);
|
||||
void forwarding_handler(TCP_Client_Connection *_Nonnull con, forwarded_response_cb *_Nonnull forwarded_response_callback, void *_Nonnull object);
|
||||
|
||||
typedef int tcp_routing_response_cb(void *object, uint8_t connection_id, const uint8_t *public_key);
|
||||
typedef int tcp_routing_status_cb(void *object, uint32_t number, uint8_t connection_id, uint8_t status);
|
||||
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 *_Nonnull object, uint32_t number, uint8_t connection_id, uint8_t status);
|
||||
|
||||
/**
|
||||
* @retval 1 on success.
|
||||
* @retval 0 if could not send packet.
|
||||
* @retval -1 on failure (connection must be killed).
|
||||
*/
|
||||
non_null()
|
||||
int send_routing_request(const Logger *logger, TCP_Client_Connection *con, const uint8_t *public_key);
|
||||
non_null()
|
||||
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);
|
||||
int send_routing_request(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, const uint8_t *_Nonnull public_key);
|
||||
void routing_response_handler(TCP_Client_Connection *_Nonnull con, tcp_routing_response_cb *_Nonnull response_callback, void *_Nonnull object);
|
||||
void routing_status_handler(TCP_Client_Connection *_Nonnull con, tcp_routing_status_cb *_Nonnull status_callback, void *_Nonnull object);
|
||||
|
||||
/**
|
||||
* @retval 1 on success.
|
||||
* @retval 0 if could not send packet.
|
||||
* @retval -1 on failure (connection must be killed).
|
||||
*/
|
||||
non_null()
|
||||
int send_disconnect_request(const Logger *logger, TCP_Client_Connection *con, uint8_t con_id);
|
||||
int send_disconnect_request(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, uint8_t 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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int set_tcp_connection_number(TCP_Client_Connection *con, uint8_t con_id, uint32_t number);
|
||||
int set_tcp_connection_number(TCP_Client_Connection *_Nonnull 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,
|
||||
uint16_t length, void *userdata);
|
||||
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 *_Nullable userdata);
|
||||
|
||||
/**
|
||||
* @retval 1 on success.
|
||||
* @retval 0 if could not send packet.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int send_data(const Logger *logger, TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, uint16_t length);
|
||||
non_null()
|
||||
void routing_data_handler(TCP_Client_Connection *con, tcp_routing_data_cb *data_callback, void *object);
|
||||
int send_data(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, uint8_t con_id, const uint8_t *_Nonnull data, uint16_t length);
|
||||
void routing_data_handler(TCP_Client_Connection *_Nonnull con, tcp_routing_data_cb *_Nonnull data_callback, void *_Nonnull object);
|
||||
|
||||
typedef int tcp_oob_data_cb(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length,
|
||||
void *userdata);
|
||||
typedef int tcp_oob_data_cb(void *_Nonnull object, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull data, uint16_t length,
|
||||
void *_Nullable userdata);
|
||||
|
||||
/**
|
||||
* @retval 1 on success.
|
||||
* @retval 0 if could not send packet.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int send_oob_packet(const Logger *logger, TCP_Client_Connection *con, const uint8_t *public_key, const uint8_t *data,
|
||||
uint16_t length);
|
||||
non_null()
|
||||
void oob_data_handler(TCP_Client_Connection *con, tcp_oob_data_cb *oob_data_callback, void *object);
|
||||
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);
|
||||
void oob_data_handler(TCP_Client_Connection *_Nonnull con, tcp_oob_data_cb *_Nonnull oob_data_callback, void *_Nonnull object);
|
||||
|
||||
#endif /* C_TOXCORE_TOXCORE_TCP_CLIENT_H */
|
||||
|
@@ -97,8 +97,7 @@ int send_pending_data(const Logger *logger, TCP_Connection *con)
|
||||
* @retval false on failure (only if mem_alloc fails)
|
||||
* @retval true on success
|
||||
*/
|
||||
non_null()
|
||||
static bool add_priority(TCP_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent)
|
||||
static bool add_priority(TCP_Connection *_Nonnull con, const uint8_t *_Nonnull packet, uint16_t size, uint16_t sent)
|
||||
{
|
||||
TCP_Priority_List *p = con->priority_queue_end;
|
||||
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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
static uint16_t read_tcp_length(const Logger *logger, const Network *ns, Socket sock, const IP_Port *ip_port)
|
||||
static uint16_t read_tcp_length(const Logger *_Nonnull logger, const Network *_Nonnull ns, Socket sock, const IP_Port *_Nonnull ip_port)
|
||||
{
|
||||
const uint16_t count = net_socket_data_recv_buffer(ns, sock);
|
||||
|
||||
|
@@ -15,15 +15,13 @@
|
||||
|
||||
typedef struct TCP_Priority_List TCP_Priority_List;
|
||||
struct TCP_Priority_List {
|
||||
TCP_Priority_List *next;
|
||||
TCP_Priority_List *_Nullable next;
|
||||
uint16_t size;
|
||||
uint16_t sent;
|
||||
uint8_t *data;
|
||||
uint8_t *_Nonnull data;
|
||||
};
|
||||
|
||||
non_null(1) nullable(2)
|
||||
void wipe_priority_list(const Memory *mem, TCP_Priority_List *p);
|
||||
|
||||
void wipe_priority_list(const Memory *_Nonnull mem, TCP_Priority_List *_Nullable p);
|
||||
#define NUM_RESERVED_PORTS 16
|
||||
#define NUM_CLIENT_CONNECTIONS (256 - NUM_RESERVED_PORTS)
|
||||
|
||||
@@ -54,9 +52,9 @@ typedef enum Tcp_Packet {
|
||||
#define MAX_PACKET_SIZE 2048
|
||||
|
||||
typedef struct TCP_Connection {
|
||||
const Memory *mem;
|
||||
const Random *rng;
|
||||
const Network *ns;
|
||||
const Memory *_Nonnull mem;
|
||||
const Random *_Nonnull rng;
|
||||
const Network *_Nonnull ns;
|
||||
Socket sock;
|
||||
IP_Port ip_port; // for debugging.
|
||||
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_sent;
|
||||
|
||||
TCP_Priority_List *priority_queue_start;
|
||||
TCP_Priority_List *priority_queue_end;
|
||||
TCP_Priority_List *_Nullable priority_queue_start;
|
||||
TCP_Priority_List *_Nullable priority_queue_end;
|
||||
|
||||
// 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).
|
||||
Net_Profile *net_profile;
|
||||
Net_Profile *_Nullable net_profile;
|
||||
} TCP_Connection;
|
||||
|
||||
/**
|
||||
* @retval 0 if pending data was sent completely
|
||||
* @retval -1 if it wasn't
|
||||
*/
|
||||
non_null()
|
||||
int send_pending_data_nonpriority(const Logger *logger, TCP_Connection *con);
|
||||
int send_pending_data_nonpriority(const Logger *_Nonnull logger, TCP_Connection *_Nonnull con);
|
||||
|
||||
/**
|
||||
* @retval 0 if pending data was sent completely
|
||||
* @retval -1 if it wasn't
|
||||
*/
|
||||
non_null()
|
||||
int send_pending_data(const Logger *logger, TCP_Connection *con);
|
||||
int send_pending_data(const Logger *_Nonnull logger, TCP_Connection *_Nonnull con);
|
||||
|
||||
/**
|
||||
* @retval 1 on success.
|
||||
* @retval 0 if could not send packet.
|
||||
* @retval -1 on failure (connection must be killed).
|
||||
*/
|
||||
non_null()
|
||||
int write_packet_tcp_secure_connection(
|
||||
const Logger *logger, TCP_Connection *con, const uint8_t *data, uint16_t length,
|
||||
bool priority);
|
||||
int write_packet_tcp_secure_connection(const Logger *_Nonnull logger, TCP_Connection *_Nonnull con, const uint8_t *_Nonnull data, uint16_t length, bool priority);
|
||||
|
||||
/** @brief Read length bytes from socket.
|
||||
*
|
||||
* return length on success
|
||||
* return -1 on failure/no data in buffer.
|
||||
*/
|
||||
non_null()
|
||||
int read_tcp_packet(
|
||||
const Logger *logger, const Memory *mem, const Network *ns, Socket sock, uint8_t *data, uint16_t length, const IP_Port *ip_port);
|
||||
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,
|
||||
const IP_Port *_Nonnull ip_port);
|
||||
|
||||
/**
|
||||
* @return length of received packet on success.
|
||||
* @retval 0 if could not read any packet.
|
||||
* @retval -1 on failure (connection must be killed).
|
||||
*/
|
||||
non_null()
|
||||
int read_packet_tcp_secure_connection(
|
||||
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);
|
||||
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,
|
||||
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);
|
||||
|
||||
#endif /* C_TOXCORE_TOXCORE_TCP_COMMON_H */
|
||||
|
@@ -80,8 +80,7 @@ uint32_t tcp_connections_count(const TCP_Connections *tcp_c)
|
||||
* @retval -1 if mem_vrealloc fails.
|
||||
* @retval 0 if it succeeds.
|
||||
*/
|
||||
non_null()
|
||||
static int realloc_tcp_connection_to(const Memory *mem, TCP_Connection_to **array, size_t num)
|
||||
static int realloc_tcp_connection_to(const Memory *_Nonnull mem, TCP_Connection_to *_Nullable *_Nonnull array, size_t num)
|
||||
{
|
||||
if (num == 0) {
|
||||
mem_delete(mem, *array);
|
||||
@@ -101,8 +100,7 @@ static int realloc_tcp_connection_to(const Memory *mem, TCP_Connection_to **arra
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int realloc_tcp_con(const Memory *mem, TCP_con **array, size_t num)
|
||||
static int realloc_tcp_con(const Memory *_Nonnull mem, TCP_con *_Nullable *_Nonnull array, size_t num)
|
||||
{
|
||||
if (num == 0) {
|
||||
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.
|
||||
*/
|
||||
non_null()
|
||||
static bool connections_number_is_valid(const TCP_Connections *tcp_c, int connections_number)
|
||||
static bool connections_number_is_valid(const TCP_Connections *_Nonnull tcp_c, int connections_number)
|
||||
{
|
||||
if ((unsigned int)connections_number >= tcp_c->connections_length) {
|
||||
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.
|
||||
*/
|
||||
non_null()
|
||||
static bool tcp_connections_number_is_valid(const TCP_Connections *tcp_c, int tcp_connections_number)
|
||||
static bool tcp_connections_number_is_valid(const TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
|
||||
{
|
||||
if ((uint32_t)tcp_connections_number >= tcp_c->tcp_connections_length) {
|
||||
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 connections_number on success.
|
||||
*/
|
||||
non_null()
|
||||
static int create_connection(TCP_Connections *tcp_c)
|
||||
static int create_connection(TCP_Connections *_Nonnull tcp_c)
|
||||
{
|
||||
for (uint32_t i = 0; i < tcp_c->connections_length; ++i) {
|
||||
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 tcp_connections_number on success.
|
||||
*/
|
||||
non_null()
|
||||
static int create_tcp_connection(TCP_Connections *tcp_c)
|
||||
static int create_tcp_connection(TCP_Connections *_Nonnull tcp_c)
|
||||
{
|
||||
for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
|
||||
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 0 on success.
|
||||
*/
|
||||
non_null()
|
||||
static int wipe_connection(TCP_Connections *tcp_c, int connections_number)
|
||||
static int wipe_connection(TCP_Connections *_Nonnull tcp_c, int connections_number)
|
||||
{
|
||||
if (!connections_number_is_valid(tcp_c, connections_number)) {
|
||||
return -1;
|
||||
@@ -241,8 +234,7 @@ static int wipe_connection(TCP_Connections *tcp_c, int connections_number)
|
||||
* return -1 on failure.
|
||||
* return 0 on success.
|
||||
*/
|
||||
non_null()
|
||||
static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_number)
|
||||
static int wipe_tcp_connection(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
|
||||
{
|
||||
if (!tcp_connections_number_is_valid(tcp_c, tcp_connections_number)) {
|
||||
return -1;
|
||||
@@ -268,8 +260,7 @@ static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_numbe
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int connections_number)
|
||||
static TCP_Connection_to *get_connection(const TCP_Connections *_Nonnull tcp_c, int connections_number)
|
||||
{
|
||||
if (!connections_number_is_valid(tcp_c, connections_number)) {
|
||||
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];
|
||||
}
|
||||
|
||||
non_null()
|
||||
static TCP_con *get_tcp_connection(const TCP_Connections *tcp_c, int tcp_connections_number)
|
||||
static TCP_con *get_tcp_connection(const TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
|
||||
{
|
||||
if (!tcp_connections_number_is_valid(tcp_c, tcp_connections_number)) {
|
||||
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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
static int get_conn_number_by_ip_port(const TCP_Connections *tcp_c, const IP_Port *ip_port)
|
||||
static int get_conn_number_by_ip_port(const TCP_Connections *_Nonnull tcp_c, const IP_Port *_Nonnull ip_port)
|
||||
{
|
||||
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);
|
||||
@@ -526,8 +515,7 @@ int tcp_send_oob_packet(const TCP_Connections *tcp_c, unsigned int tcp_connectio
|
||||
return -1;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int find_tcp_connection_relay(const TCP_Connections *tcp_c, const uint8_t *relay_pk);
|
||||
static int find_tcp_connection_relay(const TCP_Connections *_Nonnull tcp_c, const uint8_t *_Nonnull 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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
static int find_tcp_connection_to(const TCP_Connections *tcp_c, const uint8_t *public_key)
|
||||
static int find_tcp_connection_to(const TCP_Connections *_Nonnull tcp_c, const uint8_t *_Nonnull public_key)
|
||||
{
|
||||
for (uint32_t i = 0; i < tcp_c->connections_length; ++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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool tcp_connection_in_conn(const TCP_Connection_to *con_to, unsigned int tcp_connections_number)
|
||||
static bool tcp_connection_in_conn(const TCP_Connection_to *_Nonnull con_to, unsigned int tcp_connections_number)
|
||||
{
|
||||
for (uint32_t i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
|
||||
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.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
static int add_tcp_connection_to_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number)
|
||||
static int add_tcp_connection_to_conn(TCP_Connection_to *_Nonnull con_to, unsigned int tcp_connections_number)
|
||||
{
|
||||
if (tcp_connection_in_conn(con_to, tcp_connections_number)) {
|
||||
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.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
static int rm_tcp_connection_from_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number)
|
||||
static int rm_tcp_connection_from_conn(TCP_Connection_to *_Nonnull con_to, unsigned int tcp_connections_number)
|
||||
{
|
||||
for (uint32_t i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
|
||||
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.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
static uint32_t online_tcp_connection_from_conn(const TCP_Connection_to *con_to)
|
||||
static uint32_t online_tcp_connection_from_conn(const TCP_Connection_to *_Nonnull con_to)
|
||||
{
|
||||
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.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
static int set_tcp_connection_status(TCP_Connection_to *con_to, unsigned int tcp_connections_number,
|
||||
uint8_t status,
|
||||
uint8_t connection_id)
|
||||
static int set_tcp_connection_status(TCP_Connection_to *_Nonnull 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) {
|
||||
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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number)
|
||||
static int reconnect_tcp_relay_connection(TCP_Connections *_Nonnull tcp_c, int 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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int sleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number)
|
||||
static int sleep_tcp_relay_connection(TCP_Connections *_Nonnull tcp_c, int 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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number)
|
||||
static int unsleep_tcp_relay_connection(TCP_Connections *_Nonnull tcp_c, int 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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
static int send_tcp_relay_routing_request(const TCP_Connections *tcp_c, int tcp_connections_number,
|
||||
const uint8_t *public_key)
|
||||
static int send_tcp_relay_routing_request(const TCP_Connections *_Nonnull tcp_c, int tcp_connections_number, const uint8_t *_Nonnull public_key)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int tcp_response_callback(void *object, uint8_t connection_id, const uint8_t *public_key)
|
||||
static int tcp_response_callback(void *_Nonnull object, uint8_t connection_id, const uint8_t *_Nonnull public_key)
|
||||
{
|
||||
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);
|
||||
@@ -1098,8 +1072,7 @@ static int tcp_response_callback(void *object, uint8_t connection_id, const uint
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int tcp_status_callback(void *object, uint32_t number, uint8_t connection_id, uint8_t status)
|
||||
static int tcp_status_callback(void *_Nonnull 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_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;
|
||||
}
|
||||
|
||||
non_null(1, 4) nullable(6)
|
||||
static int tcp_conn_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data,
|
||||
uint16_t length, void *userdata)
|
||||
static int tcp_conn_data_callback(void *_Nonnull object, uint32_t number, uint8_t connection_id, const uint8_t *_Nonnull data,
|
||||
uint16_t length, void *_Nullable userdata)
|
||||
{
|
||||
const TCP_Client_Connection *tcp_client_con = (TCP_Client_Connection *)object;
|
||||
|
||||
if (length == 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -1169,9 +1140,7 @@ static int tcp_conn_data_callback(void *object, uint32_t number, uint8_t connect
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int tcp_conn_oob_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length,
|
||||
void *userdata)
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length, void *userdata)
|
||||
static int tcp_onion_callback(void *_Nonnull object, const uint8_t *_Nonnull data, uint16_t length, void *_Nonnull userdata)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tcp_forwarding_callback(void *object, const uint8_t *data, uint16_t length, void *userdata)
|
||||
static void tcp_forwarding_callback(void *_Nonnull object, const uint8_t *_Nonnull data, uint16_t length, void *_Nonnull userdata)
|
||||
{
|
||||
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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
static int tcp_relay_set_callbacks(TCP_Connections *tcp_c, int tcp_connections_number)
|
||||
static int tcp_relay_set_callbacks(TCP_Connections *_Nonnull tcp_c, int 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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int tcp_relay_on_online(TCP_Connections *tcp_c, int tcp_connections_number)
|
||||
static int tcp_relay_on_online(TCP_Connections *_Nonnull tcp_c, int 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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int add_tcp_relay_instance(TCP_Connections *tcp_c, const IP_Port *ip_port, const uint8_t *relay_pk)
|
||||
static int add_tcp_relay_instance(TCP_Connections *_Nonnull tcp_c, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull relay_pk)
|
||||
{
|
||||
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 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 *tcp_c, Node_format *tcp_relay, uint16_t idx)
|
||||
static bool copy_tcp_relay_conn(const TCP_Connections *_Nonnull tcp_c, Node_format *_Nonnull tcp_relay, uint16_t 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;
|
||||
}
|
||||
|
||||
non_null(1, 2) nullable(3)
|
||||
static void do_tcp_conns(const Logger *logger, TCP_Connections *tcp_c, void *userdata)
|
||||
static void do_tcp_conns(const Logger *_Nonnull logger, TCP_Connections *_Nonnull tcp_c, void *_Nullable userdata)
|
||||
{
|
||||
for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
|
||||
TCP_con *tcp_con = get_tcp_connection(tcp_c, i);
|
||||
|
||||
if (tcp_con == nullptr) {
|
||||
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 *tcp_c)
|
||||
static void kill_nonused_tcp(TCP_Connections *_Nullable tcp_c)
|
||||
{
|
||||
if (tcp_c == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tcp_c->tcp_connections_length <= RECOMMENDED_FRIEND_TCP_CONNECTIONS) {
|
||||
return;
|
||||
}
|
||||
|
@@ -67,7 +67,7 @@ typedef struct TCP_Connection_to {
|
||||
|
||||
typedef struct TCP_con {
|
||||
uint8_t status;
|
||||
TCP_Client_Connection *connection;
|
||||
TCP_Client_Connection *_Nullable connection;
|
||||
uint64_t connected_time;
|
||||
uint32_t lock_count;
|
||||
uint32_t sleep_count;
|
||||
@@ -81,28 +81,22 @@ typedef struct TCP_con {
|
||||
|
||||
typedef struct TCP_Connections TCP_Connections;
|
||||
|
||||
non_null()
|
||||
const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c);
|
||||
const uint8_t *_Nonnull tcp_connections_public_key(const TCP_Connections *_Nonnull tcp_c);
|
||||
|
||||
non_null()
|
||||
uint32_t tcp_connections_count(const TCP_Connections *tcp_c);
|
||||
uint32_t tcp_connections_count(const TCP_Connections *_Nonnull tcp_c);
|
||||
|
||||
/** @brief Returns the number of connected TCP relays. */
|
||||
non_null()
|
||||
uint32_t tcp_connected_relays_count(const TCP_Connections *tcp_c);
|
||||
uint32_t tcp_connected_relays_count(const TCP_Connections *_Nonnull tcp_c);
|
||||
|
||||
/** @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 *tcp_c, const uint8_t *relay_pk);
|
||||
bool tcp_relay_is_valid(const TCP_Connections *_Nonnull tcp_c, const uint8_t *_Nonnull relay_pk);
|
||||
|
||||
/** @brief Send a packet to the TCP connection.
|
||||
*
|
||||
* return -1 on failure.
|
||||
* return 0 on success.
|
||||
*/
|
||||
non_null()
|
||||
int send_packet_tcp_connection(const TCP_Connections *tcp_c, int connections_number, const uint8_t *packet,
|
||||
uint16_t length);
|
||||
int send_packet_tcp_connection(const TCP_Connections *_Nonnull tcp_c, int connections_number, const uint8_t *_Nonnull packet, uint16_t length);
|
||||
|
||||
/** @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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int get_random_tcp_onion_conn_number(const TCP_Connections *tcp_c);
|
||||
int get_random_tcp_onion_conn_number(const TCP_Connections *_Nonnull tcp_c);
|
||||
|
||||
/** @brief Put IP_Port of a random onion TCP connection in ip_port.
|
||||
*
|
||||
* return true on success.
|
||||
* return false on failure.
|
||||
*/
|
||||
non_null()
|
||||
bool tcp_get_random_conn_ip_port(const TCP_Connections *tcp_c, IP_Port *ip_port);
|
||||
bool tcp_get_random_conn_ip_port(const TCP_Connections *_Nonnull tcp_c, IP_Port *_Nonnull ip_port);
|
||||
|
||||
/** @brief Send an onion packet via the TCP relay corresponding to tcp_connections_number.
|
||||
*
|
||||
* return 0 on success.
|
||||
* return -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int tcp_send_onion_request(TCP_Connections *tcp_c, uint32_t tcp_connections_number, const uint8_t *data,
|
||||
uint16_t length);
|
||||
int tcp_send_onion_request(TCP_Connections *_Nonnull tcp_c, uint32_t tcp_connections_number, const uint8_t *_Nonnull data, uint16_t length);
|
||||
|
||||
/** @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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int set_tcp_onion_status(TCP_Connections *tcp_c, bool status);
|
||||
int set_tcp_onion_status(TCP_Connections *_Nonnull tcp_c, bool status);
|
||||
|
||||
/**
|
||||
* 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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int tcp_send_forward_request(const Logger *logger, TCP_Connections *tcp_c, const IP_Port *tcp_forwarder,
|
||||
const IP_Port *dht_node,
|
||||
const uint8_t *chain_keys, uint16_t chain_length,
|
||||
const uint8_t *data, uint16_t data_length);
|
||||
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,
|
||||
const uint8_t *_Nonnull chain_keys, uint16_t chain_length, const uint8_t *_Nonnull data, uint16_t data_length);
|
||||
|
||||
/** @brief Send an oob packet via the TCP relay corresponding to tcp_connections_number.
|
||||
*
|
||||
* return 0 on success.
|
||||
* return -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
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);
|
||||
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);
|
||||
|
||||
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 *tcp_c, const uint8_t *relay_pk, const uint8_t *public_key,
|
||||
const uint8_t *packet, uint16_t length);
|
||||
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,
|
||||
uint16_t length);
|
||||
|
||||
/** @brief Set the callback for TCP data packets. */
|
||||
non_null()
|
||||
void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_data_cb *tcp_data_callback, void *object);
|
||||
void set_packet_tcp_connection_callback(TCP_Connections *_Nonnull tcp_c, tcp_data_cb *_Nonnull tcp_data_callback, void *_Nonnull 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. */
|
||||
non_null(1) nullable(2, 3)
|
||||
void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_onion_cb *tcp_onion_callback, void *object);
|
||||
|
||||
void set_onion_packet_tcp_connection_callback(TCP_Connections *_Nonnull tcp_c, tcp_onion_cb *_Nullable tcp_onion_callback, void *_Nullable object);
|
||||
/** @brief Set the callback for TCP forwarding packets. */
|
||||
non_null(1) nullable(2, 3)
|
||||
void set_forwarding_packet_tcp_connection_callback(TCP_Connections *tcp_c,
|
||||
forwarded_response_cb *tcp_forwarded_response_callback,
|
||||
void *object);
|
||||
|
||||
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);
|
||||
void set_forwarding_packet_tcp_connection_callback(TCP_Connections *_Nonnull tcp_c,
|
||||
forwarded_response_cb *_Nullable tcp_forwarded_response_callback,
|
||||
void *_Nullable 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);
|
||||
|
||||
/** @brief Set the callback for TCP oob data packets. */
|
||||
non_null()
|
||||
void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_oob_cb *tcp_oob_callback, void *object);
|
||||
void set_oob_packet_tcp_connection_callback(TCP_Connections *_Nonnull tcp_c, tcp_oob_cb *_Nonnull tcp_oob_callback, void *_Nonnull object);
|
||||
|
||||
/** @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 false if ip_port is invalid.
|
||||
*/
|
||||
non_null()
|
||||
bool ip_port_to_tcp_connections_number(const IP_Port *ip_port, unsigned int *tcp_connections_number);
|
||||
bool ip_port_to_tcp_connections_number(const IP_Port *_Nonnull ip_port, unsigned int *_Nonnull tcp_connections_number);
|
||||
|
||||
/** @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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int new_tcp_connection_to(TCP_Connections *tcp_c, const uint8_t *public_key, int id);
|
||||
int new_tcp_connection_to(TCP_Connections *_Nonnull tcp_c, const uint8_t *_Nonnull public_key, int id);
|
||||
|
||||
/**
|
||||
* @retval 0 on success.
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number);
|
||||
int kill_tcp_connection_to(TCP_Connections *_Nonnull tcp_c, int connections_number);
|
||||
|
||||
/** @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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int set_tcp_connection_to_status(const TCP_Connections *tcp_c, int connections_number, bool status);
|
||||
int set_tcp_connection_to_status(const TCP_Connections *_Nonnull tcp_c, int connections_number, bool status);
|
||||
|
||||
/**
|
||||
* @return number of online tcp relays tied to the connection on success.
|
||||
* @retval 0 on failure.
|
||||
*/
|
||||
non_null()
|
||||
uint32_t tcp_connection_to_online_tcp_relays(const TCP_Connections *tcp_c, int connections_number);
|
||||
uint32_t tcp_connection_to_online_tcp_relays(const TCP_Connections *_Nonnull tcp_c, int connections_number);
|
||||
|
||||
/** @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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int add_tcp_number_relay_connection(const TCP_Connections *tcp_c, int connections_number,
|
||||
unsigned int tcp_connections_number);
|
||||
int add_tcp_number_relay_connection(const TCP_Connections *_Nonnull tcp_c, int connections_number, unsigned int tcp_connections_number);
|
||||
|
||||
/** @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 -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int add_tcp_relay_connection(TCP_Connections *tcp_c, int connections_number, const IP_Port *ip_port,
|
||||
const uint8_t *relay_pk);
|
||||
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);
|
||||
|
||||
/** @brief Add a TCP relay to the TCP_Connections instance.
|
||||
*
|
||||
* return 0 on success.
|
||||
* return -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
int add_tcp_relay_global(TCP_Connections *tcp_c, const IP_Port *ip_port, const uint8_t *relay_pk);
|
||||
int add_tcp_relay_global(TCP_Connections *_Nonnull tcp_c, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull relay_pk);
|
||||
|
||||
/** @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 0 on failure.
|
||||
*/
|
||||
non_null()
|
||||
uint32_t tcp_copy_connected_relays(const TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num);
|
||||
uint32_t tcp_copy_connected_relays(const TCP_Connections *_Nonnull tcp_c, Node_format *_Nonnull tcp_relays, uint16_t max_num);
|
||||
|
||||
/** @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.
|
||||
*/
|
||||
non_null()
|
||||
uint32_t tcp_copy_connected_relays_index(const TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num,
|
||||
uint32_t idx);
|
||||
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);
|
||||
|
||||
/** @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.
|
||||
*/
|
||||
non_null()
|
||||
TCP_Connections *new_tcp_connections(const Logger *logger, const Memory *mem, const Random *rng, const Network *ns,
|
||||
Mono_Time *mono_time, const uint8_t *secret_key, const TCP_Proxy_Info *proxy_info, Net_Profile *tcp_np);
|
||||
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,
|
||||
const uint8_t *_Nonnull secret_key, const TCP_Proxy_Info *_Nonnull proxy_info, Net_Profile *_Nonnull tcp_np);
|
||||
|
||||
non_null()
|
||||
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);
|
||||
int kill_tcp_relay_connection(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number);
|
||||
|
||||
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 */
|
||||
|
@@ -122,8 +122,7 @@ size_t tcp_server_listen_count(const TCP_Server *tcp_server)
|
||||
* @retval -1 on failure
|
||||
* @retval 0 on success.
|
||||
*/
|
||||
non_null()
|
||||
static int alloc_new_connections(TCP_Server *tcp_server, uint32_t num)
|
||||
static int alloc_new_connections(TCP_Server *_Nonnull tcp_server, uint32_t 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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void wipe_secure_connection(TCP_Secure_Connection *con)
|
||||
static void wipe_secure_connection(TCP_Secure_Connection *_Nonnull con)
|
||||
{
|
||||
if (con->status != 0) {
|
||||
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 *con_new, TCP_Secure_Connection *con_old)
|
||||
static void move_secure_connection(TCP_Secure_Connection *_Nonnull con_new, TCP_Secure_Connection *_Nonnull con_old)
|
||||
{
|
||||
*con_new = *con_old;
|
||||
crypto_memzero(con_old, sizeof(TCP_Secure_Connection));
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void free_accepted_connection_array(TCP_Server *tcp_server)
|
||||
static void free_accepted_connection_array(TCP_Server *_Nonnull tcp_server)
|
||||
{
|
||||
if (tcp_server->accepted_connection_array == nullptr) {
|
||||
return;
|
||||
@@ -185,22 +181,19 @@ static void free_accepted_connection_array(TCP_Server *tcp_server)
|
||||
* @return index corresponding to connection with peer on success
|
||||
* @retval -1 on failure.
|
||||
*/
|
||||
non_null()
|
||||
static int get_tcp_connection_index(const TCP_Server *tcp_server, const uint8_t *public_key)
|
||||
static int get_tcp_connection_index(const TCP_Server *_Nonnull tcp_server, const uint8_t *_Nonnull public_key)
|
||||
{
|
||||
return bs_list_find(&tcp_server->accepted_key_list, public_key);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int kill_accepted(TCP_Server *tcp_server, int index);
|
||||
static int kill_accepted(TCP_Server *_Nonnull tcp_server, int index);
|
||||
|
||||
/** @brief Add accepted TCP connection to the list.
|
||||
*
|
||||
* @return index on success
|
||||
* @retval -1 on failure
|
||||
*/
|
||||
non_null()
|
||||
static int add_accepted(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_Secure_Connection *con)
|
||||
static int add_accepted(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time, TCP_Secure_Connection *_Nonnull con)
|
||||
{
|
||||
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 -1 on failure
|
||||
*/
|
||||
non_null()
|
||||
static int del_accepted(TCP_Server *tcp_server, int index)
|
||||
static int del_accepted(TCP_Server *_Nonnull tcp_server, int index)
|
||||
{
|
||||
if ((uint32_t)index >= tcp_server->size_accepted_connections) {
|
||||
return -1;
|
||||
@@ -276,15 +268,17 @@ static int del_accepted(TCP_Server *tcp_server, int index)
|
||||
}
|
||||
|
||||
/** Kill a TCP_Secure_Connection */
|
||||
non_null()
|
||||
static void kill_tcp_secure_connection(TCP_Secure_Connection *con)
|
||||
static void kill_tcp_secure_connection(TCP_Secure_Connection *_Nullable con)
|
||||
{
|
||||
if (con == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
kill_sock(con->con.ns, con->con.sock);
|
||||
wipe_secure_connection(con);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int rm_connection_index(TCP_Server *tcp_server, TCP_Secure_Connection *con, uint8_t con_number);
|
||||
static int rm_connection_index(TCP_Server *_Nonnull tcp_server, TCP_Secure_Connection *_Nonnull con, uint8_t con_number);
|
||||
|
||||
/** @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 the connection must be killed.
|
||||
*/
|
||||
non_null()
|
||||
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)
|
||||
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)
|
||||
{
|
||||
if (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 -1 if the connection must be killed.
|
||||
*/
|
||||
non_null()
|
||||
static int read_connection_handshake(const Logger *logger, TCP_Secure_Connection *con, const uint8_t *self_secret_key)
|
||||
static int read_connection_handshake(const Logger *_Nonnull logger, TCP_Secure_Connection *_Nonnull con, const uint8_t *_Nonnull self_secret_key)
|
||||
{
|
||||
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);
|
||||
@@ -399,9 +390,7 @@ static int read_connection_handshake(const Logger *logger, TCP_Secure_Connection
|
||||
* @retval 0 if could not send packet.
|
||||
* @retval -1 on failure (connection must be killed).
|
||||
*/
|
||||
non_null()
|
||||
static int send_routing_response(const Logger *logger, TCP_Secure_Connection *con, uint8_t rpid,
|
||||
const uint8_t *public_key)
|
||||
static int send_routing_response(const Logger *_Nonnull logger, TCP_Secure_Connection *_Nonnull con, uint8_t rpid, const uint8_t *_Nonnull public_key)
|
||||
{
|
||||
uint8_t data[2 + CRYPTO_PUBLIC_KEY_SIZE];
|
||||
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 -1 on failure (connection must be killed).
|
||||
*/
|
||||
non_null()
|
||||
static int send_connect_notification(const Logger *logger, TCP_Secure_Connection *con, uint8_t id)
|
||||
static int send_connect_notification(const Logger *_Nonnull logger, TCP_Secure_Connection *_Nonnull con, uint8_t id)
|
||||
{
|
||||
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);
|
||||
@@ -428,8 +416,7 @@ static int send_connect_notification(const Logger *logger, TCP_Secure_Connection
|
||||
* @retval 0 if could not send packet.
|
||||
* @retval -1 on failure (connection must be killed).
|
||||
*/
|
||||
non_null()
|
||||
static int send_disconnect_notification(const Logger *logger, TCP_Secure_Connection *con, uint8_t id)
|
||||
static int send_disconnect_notification(const Logger *_Nonnull logger, TCP_Secure_Connection *_Nonnull con, uint8_t id)
|
||||
{
|
||||
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);
|
||||
@@ -439,8 +426,7 @@ static int send_disconnect_notification(const Logger *logger, TCP_Secure_Connect
|
||||
* @retval 0 on success.
|
||||
* @retval -1 on failure (connection must be killed).
|
||||
*/
|
||||
non_null()
|
||||
static int handle_tcp_routing_req(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *public_key)
|
||||
static int handle_tcp_routing_req(TCP_Server *_Nonnull tcp_server, uint32_t con_id, const uint8_t *_Nonnull public_key)
|
||||
{
|
||||
uint32_t index = -1;
|
||||
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 -1 on failure (connection must be killed).
|
||||
*/
|
||||
non_null()
|
||||
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)
|
||||
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)
|
||||
{
|
||||
if (length == 0 || length > TCP_MAX_OOB_DATA_LENGTH) {
|
||||
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 false if ip_port is invalid.
|
||||
*/
|
||||
non_null()
|
||||
static bool ip_port_to_con_id(const TCP_Server *tcp_server, const IP_Port *ip_port, uint32_t *con_id)
|
||||
static bool ip_port_to_con_id(const TCP_Server *_Nonnull tcp_server, const IP_Port *_Nonnull ip_port, uint32_t *_Nonnull con_id)
|
||||
{
|
||||
*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];
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int handle_onion_recv_1(void *object, const IP_Port *dest, const uint8_t *data, uint16_t length)
|
||||
static int handle_onion_recv_1(void *_Nonnull object, const IP_Port *_Nonnull dest, const uint8_t *_Nonnull data, uint16_t length)
|
||||
{
|
||||
TCP_Server *tcp_server = (TCP_Server *)object;
|
||||
uint32_t index;
|
||||
@@ -636,9 +618,7 @@ static int handle_onion_recv_1(void *object, const IP_Port *dest, const uint8_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
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)
|
||||
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)
|
||||
{
|
||||
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 -1 on failure
|
||||
*/
|
||||
non_null()
|
||||
static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *data, uint16_t length)
|
||||
static int handle_tcp_packet(TCP_Server *_Nonnull tcp_server, uint32_t con_id, const uint8_t *_Nonnull data, uint16_t length)
|
||||
{
|
||||
if (length == 0) {
|
||||
return -1;
|
||||
@@ -693,7 +672,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -702,7 +681,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -711,7 +690,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -720,7 +699,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
|
||||
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)];
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
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,
|
||||
length - (1 + CRYPTO_PUBLIC_KEY_SIZE));
|
||||
}
|
||||
|
||||
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 (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: {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
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) {
|
||||
return -1;
|
||||
@@ -854,9 +833,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
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)
|
||||
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)
|
||||
{
|
||||
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
|
||||
* @retval -1 on failure
|
||||
*/
|
||||
non_null()
|
||||
static int accept_connection(TCP_Server *tcp_server, Socket sock)
|
||||
static int accept_connection(TCP_Server *_Nonnull tcp_server, Socket sock)
|
||||
{
|
||||
if (!sock_valid(sock)) {
|
||||
return -1;
|
||||
@@ -919,8 +895,7 @@ static int accept_connection(TCP_Server *tcp_server, Socket sock)
|
||||
return index;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Socket new_listening_tcp_socket(const Logger *logger, const Memory *mem, const Network *ns, Family family, uint16_t port)
|
||||
static Socket new_listening_tcp_socket(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Network *_Nonnull ns, Family family, uint16_t port)
|
||||
{
|
||||
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
|
||||
non_null()
|
||||
static void do_tcp_accept_new(TCP_Server *tcp_server)
|
||||
static void do_tcp_accept_new(TCP_Server *_Nonnull tcp_server)
|
||||
{
|
||||
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 */
|
||||
|
||||
non_null()
|
||||
static int do_incoming(TCP_Server *tcp_server, uint32_t i)
|
||||
static int do_incoming(TCP_Server *_Nonnull tcp_server, uint32_t 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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
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];
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1116,8 +1089,7 @@ static int do_incoming(TCP_Server *tcp_server, uint32_t i)
|
||||
return index_new;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int do_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time, uint32_t i)
|
||||
static int do_unconfirmed(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time, uint32_t 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;
|
||||
}
|
||||
|
||||
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];
|
||||
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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool tcp_process_secure_packet(TCP_Server *tcp_server, uint32_t i)
|
||||
static bool tcp_process_secure_packet(TCP_Server *_Nonnull tcp_server, uint32_t i)
|
||||
{
|
||||
TCP_Secure_Connection *const conn = &tcp_server->accepted_connection_array[i];
|
||||
|
||||
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,
|
||||
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) {
|
||||
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) {
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
@@ -1171,8 +1142,7 @@ static bool tcp_process_secure_packet(TCP_Server *tcp_server, uint32_t i)
|
||||
return true;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void do_confirmed_recv(TCP_Server *tcp_server, uint32_t i)
|
||||
static void do_confirmed_recv(TCP_Server *_Nonnull tcp_server, uint32_t i)
|
||||
{
|
||||
while (tcp_process_secure_packet(tcp_server, i)) {
|
||||
/* 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
|
||||
non_null()
|
||||
static void do_tcp_incoming(TCP_Server *tcp_server)
|
||||
static void do_tcp_incoming(TCP_Server *_Nonnull tcp_server)
|
||||
{
|
||||
for (uint32_t i = 0; i < MAX_INCOMING_CONNECTIONS; ++i) {
|
||||
do_incoming(tcp_server, i);
|
||||
}
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void do_tcp_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
|
||||
static void do_tcp_unconfirmed(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time)
|
||||
{
|
||||
for (uint32_t i = 0; i < MAX_INCOMING_CONNECTIONS; ++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 */
|
||||
|
||||
non_null()
|
||||
static void do_tcp_confirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
|
||||
static void do_tcp_confirmed(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time)
|
||||
{
|
||||
#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
|
||||
non_null()
|
||||
static bool tcp_epoll_process(TCP_Server *tcp_server, const Mono_Time *mono_time)
|
||||
static bool tcp_epoll_process(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time)
|
||||
{
|
||||
#define MAX_EVENTS 16
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void do_tcp_epoll(TCP_Server *tcp_server, const Mono_Time *mono_time)
|
||||
static void do_tcp_epoll(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time)
|
||||
{
|
||||
while (tcp_epoll_process(tcp_server, mono_time)) {
|
||||
// Keep processing packets until there are no more FDs ready for reading.
|
||||
|
@@ -34,30 +34,21 @@ typedef enum TCP_Status {
|
||||
|
||||
typedef struct TCP_Server TCP_Server;
|
||||
|
||||
non_null()
|
||||
const uint8_t *tcp_server_public_key(const TCP_Server *tcp_server);
|
||||
non_null()
|
||||
size_t tcp_server_listen_count(const TCP_Server *tcp_server);
|
||||
const uint8_t *_Nonnull tcp_server_public_key(const TCP_Server *_Nonnull tcp_server);
|
||||
size_t tcp_server_listen_count(const TCP_Server *_Nonnull tcp_server);
|
||||
|
||||
/** Create new TCP server instance. */
|
||||
non_null(1, 2, 3, 4, 7, 8) nullable(9, 10)
|
||||
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 *ports,
|
||||
const uint8_t *secret_key, Onion *onion, Forwarding *forwarding);
|
||||
|
||||
TCP_Server *_Nullable new_tcp_server(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Network *_Nonnull ns,
|
||||
bool ipv6_enabled, uint16_t num_sockets, const uint16_t *_Nonnull ports,
|
||||
const uint8_t *_Nonnull secret_key, Onion *_Nullable onion, Forwarding *_Nullable forwarding);
|
||||
/** Run the TCP_server */
|
||||
non_null()
|
||||
void do_tcp_server(TCP_Server *tcp_server, const Mono_Time *mono_time);
|
||||
void do_tcp_server(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time);
|
||||
|
||||
/** Kill the TCP server */
|
||||
nullable(1)
|
||||
void kill_tcp_server(TCP_Server *tcp_server);
|
||||
|
||||
void kill_tcp_server(TCP_Server *_Nullable tcp_server);
|
||||
/** @brief Returns a pointer to the net profile associated with `tcp_server`.
|
||||
*
|
||||
* Returns null if `tcp_server` is null.
|
||||
*/
|
||||
nullable(1)
|
||||
const Net_Profile *tcp_server_get_net_profile(const TCP_Server *tcp_server);
|
||||
|
||||
const Net_Profile *_Nullable tcp_server_get_net_profile(const TCP_Server *_Nullable tcp_server);
|
||||
#endif /* C_TOXCORE_TOXCORE_TCP_SERVER_H */
|
||||
|
@@ -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
|
||||
* once it has timed out.
|
||||
*/
|
||||
non_null()
|
||||
static bool entry_is_empty(const Announcements *announce, const Announce_Entry *entry)
|
||||
static bool entry_is_empty(const Announcements *_Nonnull announce, const Announce_Entry *_Nonnull entry)
|
||||
{
|
||||
return mono_time_get(announce->mono_time) >= entry->store_until;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void delete_entry(Announce_Entry *entry)
|
||||
static void delete_entry(Announce_Entry *_Nonnull entry)
|
||||
{
|
||||
entry->store_until = 0;
|
||||
}
|
||||
|
||||
/** 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 *pk, uint16_t index, uint16_t bits)
|
||||
static uint8_t truncate_pk_at_index(const uint8_t *_Nonnull pk, uint16_t index, uint16_t bits)
|
||||
{
|
||||
assert(bits < 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Announce_Entry *bucket_of_key(Announcements *announce, const uint8_t *pk)
|
||||
static Announce_Entry *bucket_of_key(Announcements *_Nonnull announce, const uint8_t *_Nonnull pk)
|
||||
{
|
||||
return &announce->entries[announce_get_bucketnum(announce->public_key, pk) * ANNOUNCE_BUCKET_SIZE];
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Announce_Entry *get_stored(Announcements *announce, const uint8_t *data_public_key)
|
||||
static Announce_Entry *get_stored(Announcements *_Nonnull announce, const uint8_t *_Nonnull 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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static const Announce_Entry *bucket_of_key_const(const Announcements *announce, const uint8_t *pk)
|
||||
static const Announce_Entry *bucket_of_key_const(const Announcements *_Nonnull announce, const uint8_t *_Nonnull pk)
|
||||
{
|
||||
return &announce->entries[announce_get_bucketnum(announce->public_key, pk) * ANNOUNCE_BUCKET_SIZE];
|
||||
}
|
||||
|
||||
non_null()
|
||||
static const Announce_Entry *get_stored_const(const Announcements *announce, const uint8_t *data_public_key)
|
||||
static const Announce_Entry *get_stored_const(const Announcements *_Nonnull announce, const uint8_t *_Nonnull 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
|
||||
* exists, else nullptr.
|
||||
*/
|
||||
non_null()
|
||||
static Announce_Entry *find_entry_slot(Announcements *announce, const uint8_t *data_public_key)
|
||||
static Announce_Entry *find_entry_slot(Announcements *_Nonnull announce, const uint8_t *_Nonnull 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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool would_accept_store_request(Announcements *announce, const uint8_t *data_public_key)
|
||||
static bool would_accept_store_request(Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint32_t calculate_timeout(const Announcements *announce, uint32_t requested_timeout)
|
||||
static uint32_t calculate_timeout(const Announcements *_Nonnull announce, uint32_t requested_timeout)
|
||||
{
|
||||
const uint64_t uptime = mono_time_get(announce->mono_time) - announce->start_time;
|
||||
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)
|
||||
|
||||
non_null(1, 2, 3, 4, 7) nullable(5)
|
||||
static int create_data_search_to_auth(const Logger *logger, const uint8_t *data_public_key,
|
||||
const uint8_t *requester_key,
|
||||
const IP_Port *source, const uint8_t *sendback, uint16_t sendback_length,
|
||||
uint8_t *dest, uint16_t max_length)
|
||||
static int create_data_search_to_auth(const Logger *_Nonnull logger, const uint8_t *_Nonnull data_public_key,
|
||||
const uint8_t *_Nonnull requester_key,
|
||||
const IP_Port *_Nonnull source, const uint8_t *_Nullable sendback, uint16_t sendback_length,
|
||||
uint8_t *_Nonnull dest, uint16_t max_length)
|
||||
{
|
||||
if (max_length < DATA_SEARCH_TO_AUTH_MAX_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
|
||||
|
||||
non_null()
|
||||
static int create_reply_plain_data_search_request(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)
|
||||
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,
|
||||
uint16_t reply_max_length, const uint8_t *_Nonnull to_auth, uint16_t to_auth_length)
|
||||
{
|
||||
if (length != CRYPTO_PUBLIC_KEY_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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int create_reply_plain_data_retrieve_request(
|
||||
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)
|
||||
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,
|
||||
uint8_t *_Nonnull reply, uint16_t reply_max_length, const uint8_t *_Nonnull to_auth, uint16_t to_auth_length)
|
||||
{
|
||||
if (length != CRYPTO_PUBLIC_KEY_SIZE + 1 + TIMED_AUTH_SIZE) {
|
||||
return -1;
|
||||
@@ -425,12 +405,8 @@ static int create_reply_plain_data_retrieve_request(
|
||||
return reply_len;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static int create_reply_plain_store_announce_request(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)
|
||||
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,
|
||||
uint16_t reply_max_length, const uint8_t *_Nonnull 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 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;
|
||||
}
|
||||
|
||||
non_null(1, 2, 3, 7, 9) nullable(5)
|
||||
static int create_reply_plain(Announcements *announce,
|
||||
const uint8_t *requester_key, const IP_Port *source, uint8_t type,
|
||||
const uint8_t *sendback, uint16_t sendback_length,
|
||||
const uint8_t *data, uint16_t length,
|
||||
uint8_t *reply, uint16_t reply_max_length)
|
||||
static int create_reply_plain(Announcements *_Nonnull announce,
|
||||
const uint8_t *_Nonnull requester_key, const IP_Port *_Nonnull source, uint8_t type,
|
||||
const uint8_t *_Nullable sendback, uint16_t sendback_length,
|
||||
const uint8_t *_Nonnull data, uint16_t length,
|
||||
uint8_t *_Nonnull reply, uint16_t reply_max_length)
|
||||
{
|
||||
if (length < CRYPTO_PUBLIC_KEY_SIZE) {
|
||||
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 *announce, const IP_Port *source,
|
||||
const uint8_t *sendback, uint16_t sendback_length,
|
||||
const uint8_t *data, uint16_t length,
|
||||
uint8_t *reply, uint16_t reply_max_length)
|
||||
static int create_reply(Announcements *_Nonnull announce, const IP_Port *_Nonnull source,
|
||||
const uint8_t *_Nullable sendback, uint16_t sendback_length,
|
||||
const uint8_t *_Nonnull data, uint16_t length,
|
||||
uint8_t *_Nonnull reply, uint16_t reply_max_length)
|
||||
{
|
||||
const int plain_len = (int)length - (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE);
|
||||
|
||||
if (plain_len < (int)sizeof(uint64_t)) {
|
||||
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);
|
||||
}
|
||||
|
||||
non_null(1, 2, 3, 5) nullable(7)
|
||||
static void forwarded_request_callback(void *object, const IP_Port *forwarder,
|
||||
const uint8_t *sendback, uint16_t sendback_length,
|
||||
const uint8_t *data, uint16_t length, void *userdata)
|
||||
static void forwarded_request_callback(void *_Nonnull object, const IP_Port *_Nonnull forwarder,
|
||||
const uint8_t *_Nonnull sendback, uint16_t sendback_length,
|
||||
const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata)
|
||||
{
|
||||
Announcements *announce = (Announcements *) object;
|
||||
|
||||
uint8_t reply[MAX_FORWARD_DATA_SIZE];
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
non_null(1, 2, 3) nullable(5)
|
||||
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;
|
||||
|
||||
uint8_t reply[MAX_FORWARD_DATA_SIZE];
|
||||
|
||||
const int len
|
||||
|
@@ -16,45 +16,35 @@
|
||||
|
||||
#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);
|
||||
|
||||
typedef struct Announcements Announcements;
|
||||
|
||||
non_null()
|
||||
Announcements *new_announcements(const Logger *log, const Memory *mem, const Random *rng, const Mono_Time *mono_time,
|
||||
Forwarding *forwarding);
|
||||
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);
|
||||
|
||||
/**
|
||||
* @brief If data is stored, run `on_retrieve_callback` on it.
|
||||
*
|
||||
* @return true if data is stored, false otherwise.
|
||||
*/
|
||||
non_null(1, 2) nullable(3, 4)
|
||||
bool announce_on_stored(const Announcements *announce, const uint8_t *data_public_key,
|
||||
announce_on_retrieve_cb *on_retrieve_callback, void *object);
|
||||
|
||||
non_null()
|
||||
void announce_set_synch_offset(Announcements *announce, int32_t synch_offset);
|
||||
|
||||
nullable(1)
|
||||
void kill_announcements(Announcements *announce);
|
||||
bool announce_on_stored(const Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key,
|
||||
announce_on_retrieve_cb *_Nullable on_retrieve_callback, void *_Nullable object);
|
||||
void announce_set_synch_offset(Announcements *_Nonnull announce, int32_t synch_offset);
|
||||
|
||||
void kill_announcements(Announcements *_Nullable announce);
|
||||
/* The declarations below are not public, they are exposed only for tests. */
|
||||
|
||||
/** @private
|
||||
* Return xor of first ANNOUNCE_BUCKET_PREFIX_LENGTH bits from one bit after
|
||||
* base and pk first differ
|
||||
*/
|
||||
non_null()
|
||||
uint16_t announce_get_bucketnum(const uint8_t *base, const uint8_t *pk);
|
||||
uint16_t announce_get_bucketnum(const uint8_t *_Nonnull base, const uint8_t *_Nonnull pk);
|
||||
|
||||
/** @private */
|
||||
non_null(1, 2) nullable(3)
|
||||
bool announce_store_data(Announcements *announce, const uint8_t *data_public_key,
|
||||
const uint8_t *data, uint32_t length, uint32_t timeout);
|
||||
|
||||
bool announce_store_data(Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key,
|
||||
const uint8_t *_Nullable data, uint32_t length, uint32_t timeout);
|
||||
/** @private */
|
||||
#define MAX_MAX_ANNOUNCEMENT_TIMEOUT 900
|
||||
#define MIN_MAX_ANNOUNCEMENT_TIMEOUT 10
|
||||
|
@@ -18,14 +18,11 @@
|
||||
#define GNU_PRINTF(f, a)
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && defined(_DEBUG)
|
||||
#define non_null(...) __attribute__((__nonnull__(__VA_ARGS__)))
|
||||
#else
|
||||
#define non_null(...)
|
||||
#ifndef __clang__
|
||||
#define _Nonnull
|
||||
#define _Nullable
|
||||
#endif
|
||||
|
||||
#define nullable(...)
|
||||
|
||||
#ifdef SPARSE
|
||||
#define bitwise __attribute__((bitwise))
|
||||
#define force __attribute__((force))
|
||||
|
@@ -19,22 +19,19 @@ struct Bin_Pack {
|
||||
cmp_ctx_t ctx;
|
||||
};
|
||||
|
||||
non_null()
|
||||
static bool null_reader(cmp_ctx_t *ctx, void *data, size_t limit)
|
||||
static bool null_reader(cmp_ctx_t *_Nonnull ctx, void *_Nonnull data, size_t limit)
|
||||
{
|
||||
assert(limit == 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool null_skipper(cmp_ctx_t *ctx, size_t count)
|
||||
static bool null_skipper(cmp_ctx_t *_Nonnull ctx, size_t count)
|
||||
{
|
||||
assert(count == 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static size_t buf_writer(cmp_ctx_t *ctx, const void *data, size_t count)
|
||||
static size_t buf_writer(cmp_ctx_t *_Nonnull ctx, const void *_Nonnull data, size_t count)
|
||||
{
|
||||
const uint8_t *bytes = (const uint8_t *)data;
|
||||
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;
|
||||
}
|
||||
|
||||
non_null(1) nullable(2)
|
||||
static void bin_pack_init(Bin_Pack *bp, uint8_t *buf, uint32_t buf_size)
|
||||
static void bin_pack_init(Bin_Pack *_Nonnull bp, uint8_t *_Nullable buf, uint32_t buf_size)
|
||||
{
|
||||
bp->bytes = buf;
|
||||
bp->bytes_size = buf_size;
|
||||
|
@@ -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
|
||||
* 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.
|
||||
*
|
||||
@@ -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 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.
|
||||
*
|
||||
@@ -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.
|
||||
* @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 *callback, const void *obj, const Logger *logger);
|
||||
|
||||
uint32_t bin_pack_obj_size(bin_pack_cb *_Nonnull callback, const void *_Nullable obj, const Logger *_Nullable logger);
|
||||
/** @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
|
||||
@@ -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).
|
||||
*/
|
||||
non_null(1, 4) nullable(2, 3)
|
||||
bool bin_pack_obj(bin_pack_cb *callback, const void *obj, const Logger *logger, uint8_t *buf, uint32_t buf_size);
|
||||
|
||||
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);
|
||||
/** @brief Determine the serialised size of an object array.
|
||||
*
|
||||
* 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.
|
||||
* @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 *callback, const void *arr, uint32_t arr_size, const Logger *logger);
|
||||
|
||||
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);
|
||||
/** @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
|
||||
@@ -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).
|
||||
*/
|
||||
non_null(1, 5) nullable(2, 4)
|
||||
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);
|
||||
|
||||
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);
|
||||
/** @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
|
||||
@@ -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).
|
||||
*/
|
||||
non_null(1, 2) nullable(3, 5)
|
||||
bool bin_pack_obj_array(Bin_Pack *bp, bin_pack_array_cb *callback, const void *arr, uint32_t arr_size, const Logger *logger);
|
||||
|
||||
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);
|
||||
/** @brief Start packing a MessagePack array.
|
||||
*
|
||||
* A call to this function must be followed by exactly `size` calls to other functions below.
|
||||
*/
|
||||
non_null()
|
||||
bool bin_pack_array(Bin_Pack *bp, uint32_t size);
|
||||
bool bin_pack_array(Bin_Pack *_Nonnull bp, uint32_t size);
|
||||
|
||||
/** @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. */
|
||||
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. */
|
||||
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. */
|
||||
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. */
|
||||
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. */
|
||||
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. */
|
||||
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.
|
||||
*
|
||||
* 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. */
|
||||
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. */
|
||||
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. */
|
||||
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. */
|
||||
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.
|
||||
*
|
||||
* Note that unless you prepend the array length manually, there is no record of it in the resulting
|
||||
* 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
|
||||
} /* extern "C" */
|
||||
|
@@ -20,8 +20,7 @@ struct Bin_Unpack {
|
||||
cmp_ctx_t ctx;
|
||||
};
|
||||
|
||||
non_null()
|
||||
static bool buf_reader(cmp_ctx_t *ctx, void *data, size_t limit)
|
||||
static bool buf_reader(cmp_ctx_t *_Nonnull ctx, void *_Nonnull data, size_t limit)
|
||||
{
|
||||
uint8_t *bytes = (uint8_t *)data;
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool buf_skipper(cmp_ctx_t *ctx, size_t count)
|
||||
static bool buf_skipper(cmp_ctx_t *_Nonnull ctx, size_t count)
|
||||
{
|
||||
Bin_Unpack *reader = (Bin_Unpack *)ctx->buf;
|
||||
assert(reader != nullptr && reader->bytes != nullptr);
|
||||
@@ -48,15 +46,13 @@ static bool buf_skipper(cmp_ctx_t *ctx, size_t count)
|
||||
return true;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static size_t null_writer(cmp_ctx_t *ctx, const void *data, size_t count)
|
||||
static size_t null_writer(cmp_ctx_t *_Nonnull ctx, const void *_Nonnull data, size_t count)
|
||||
{
|
||||
assert(count == 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void bin_unpack_init(Bin_Unpack *bu, const Memory *mem, const uint8_t *buf, uint32_t buf_size)
|
||||
static void bin_unpack_init(Bin_Unpack *_Nonnull bu, const Memory *_Nonnull mem, const uint8_t *_Nonnull buf, uint32_t buf_size)
|
||||
{
|
||||
bu->mem = mem;
|
||||
bu->bytes = buf;
|
||||
|
@@ -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
|
||||
* 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.
|
||||
*
|
||||
@@ -46,8 +46,7 @@ typedef bool bin_unpack_cb(void *obj, Bin_Unpack *bu);
|
||||
*
|
||||
* @retval false if an error occurred (e.g. buffer overrun).
|
||||
*/
|
||||
non_null()
|
||||
bool bin_unpack_obj(const Memory *mem, bin_unpack_cb *callback, void *obj, const uint8_t *buf, uint32_t buf_size);
|
||||
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);
|
||||
|
||||
/** @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.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
@@ -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.
|
||||
*/
|
||||
non_null(1) nullable(3)
|
||||
bool bin_unpack_array_fixed(Bin_Unpack *bu, uint32_t required_size, uint32_t *actual_size);
|
||||
|
||||
bool bin_unpack_array_fixed(Bin_Unpack *_Nonnull bu, uint32_t required_size, uint32_t *_Nullable actual_size);
|
||||
/** @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`. */
|
||||
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`. */
|
||||
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`. */
|
||||
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`. */
|
||||
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. */
|
||||
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.
|
||||
*
|
||||
@@ -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
|
||||
* 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.
|
||||
*
|
||||
* 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)`
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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. */
|
||||
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. */
|
||||
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. */
|
||||
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. */
|
||||
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. */
|
||||
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
|
||||
} /* extern "C" */
|
||||
|
@@ -88,8 +88,7 @@ const uint8_t *get_chat_id(const Extended_Public_Key *key)
|
||||
}
|
||||
|
||||
#if !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||
non_null()
|
||||
static uint8_t *crypto_malloc(const Memory *mem, size_t bytes)
|
||||
static uint8_t *crypto_malloc(const Memory *_Nonnull mem, size_t 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;
|
||||
}
|
||||
|
||||
non_null(1) nullable(2)
|
||||
static void crypto_free(const Memory *mem, uint8_t *ptr, size_t bytes)
|
||||
static void crypto_free(const Memory *_Nonnull mem, uint8_t *_Nullable ptr, size_t bytes)
|
||||
{
|
||||
if (ptr != nullptr) {
|
||||
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 */
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void sys_random_bytes(void *obj, uint8_t *bytes, size_t length)
|
||||
static void sys_random_bytes(void *_Nonnull obj, uint8_t *_Nonnull bytes, size_t length)
|
||||
{
|
||||
randombytes(bytes, length);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static uint32_t sys_random_uniform(void *obj, uint32_t upper_bound)
|
||||
static uint32_t sys_random_uniform(void *_Nonnull obj, uint32_t upper_bound)
|
||||
{
|
||||
return randombytes_uniform(upper_bound);
|
||||
}
|
||||
|
@@ -84,19 +84,19 @@ extern "C" {
|
||||
* secure pseudo-random number generator (CSPRNG). The security of Tox heavily
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
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. */
|
||||
typedef struct Random_Funcs {
|
||||
crypto_random_bytes_cb *random_bytes;
|
||||
crypto_random_uniform_cb *random_uniform;
|
||||
crypto_random_bytes_cb *_Nullable random_bytes;
|
||||
crypto_random_uniform_cb *_Nullable random_uniform;
|
||||
} Random_Funcs;
|
||||
|
||||
/** @brief Random number generator object.
|
||||
@@ -106,15 +106,15 @@ typedef struct Random_Funcs {
|
||||
* CSPRNG and use `os_random` below.
|
||||
*/
|
||||
typedef struct Random {
|
||||
const Random_Funcs *funcs;
|
||||
void *obj;
|
||||
const Random_Funcs *_Nullable funcs;
|
||||
void *_Nullable obj;
|
||||
} Random;
|
||||
|
||||
/** @brief System random number generator.
|
||||
*
|
||||
* 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.
|
||||
@@ -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
|
||||
* sure the memory is indeed zeroed.
|
||||
*/
|
||||
non_null()
|
||||
void crypto_memzero(void *data, size_t length);
|
||||
void crypto_memzero(void *_Nonnull data, size_t length);
|
||||
|
||||
/**
|
||||
* @brief Compute a SHA256 hash (32 bytes).
|
||||
*
|
||||
* @param[out] hash The SHA256 hash of @p data will be written to this byte array.
|
||||
*/
|
||||
non_null()
|
||||
void crypto_sha256(uint8_t hash[CRYPTO_SHA256_SIZE], const uint8_t *data, size_t length);
|
||||
void crypto_sha256(uint8_t hash[_Nonnull CRYPTO_SHA256_SIZE], const uint8_t *_Nonnull data, size_t length);
|
||||
|
||||
/**
|
||||
* @brief Compute a SHA512 hash (64 bytes).
|
||||
*
|
||||
* @param[out] hash The SHA512 hash of @p data will be written to this byte array.
|
||||
*/
|
||||
non_null()
|
||||
void crypto_sha512(uint8_t hash[CRYPTO_SHA512_SIZE], const uint8_t *data, size_t length);
|
||||
void crypto_sha512(uint8_t hash[_Nonnull CRYPTO_SHA512_SIZE], const uint8_t *_Nonnull data, size_t length);
|
||||
|
||||
/**
|
||||
* @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 key Secret key, as generated by `new_hmac_key()`.
|
||||
*/
|
||||
non_null()
|
||||
void crypto_hmac(uint8_t auth[CRYPTO_HMAC_SIZE], const uint8_t key[CRYPTO_HMAC_KEY_SIZE],
|
||||
const uint8_t *data, size_t length);
|
||||
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);
|
||||
|
||||
/**
|
||||
* @brief Verify an HMAC authenticator.
|
||||
*/
|
||||
non_null()
|
||||
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);
|
||||
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);
|
||||
|
||||
/**
|
||||
* @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 false if they are not
|
||||
*/
|
||||
non_null()
|
||||
bool pk_equal(const uint8_t pk1[CRYPTO_PUBLIC_KEY_SIZE], const uint8_t pk2[CRYPTO_PUBLIC_KEY_SIZE]);
|
||||
bool pk_equal(const uint8_t pk1[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t pk2[_Nonnull CRYPTO_PUBLIC_KEY_SIZE]);
|
||||
|
||||
/**
|
||||
* @brief Copy a public key from `src` to `dest`.
|
||||
*/
|
||||
non_null()
|
||||
void pk_copy(uint8_t dest[CRYPTO_PUBLIC_KEY_SIZE], const uint8_t src[CRYPTO_PUBLIC_KEY_SIZE]);
|
||||
void pk_copy(uint8_t dest[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t src[_Nonnull CRYPTO_PUBLIC_KEY_SIZE]);
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
non_null()
|
||||
bool crypto_sha512_eq(const uint8_t cksum1[CRYPTO_SHA512_SIZE], const uint8_t cksum2[CRYPTO_SHA512_SIZE]);
|
||||
bool crypto_sha512_eq(const uint8_t cksum1[_Nonnull CRYPTO_SHA512_SIZE], const uint8_t cksum2[_Nonnull CRYPTO_SHA512_SIZE]);
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
non_null()
|
||||
bool crypto_sha256_eq(const uint8_t cksum1[CRYPTO_SHA256_SIZE], const uint8_t cksum2[CRYPTO_SHA256_SIZE]);
|
||||
bool crypto_sha256_eq(const uint8_t cksum1[_Nonnull CRYPTO_SHA256_SIZE], const uint8_t cksum2[_Nonnull CRYPTO_SHA256_SIZE]);
|
||||
|
||||
/**
|
||||
* @brief Return a random 8 bit integer.
|
||||
*/
|
||||
non_null()
|
||||
uint8_t random_u08(const Random *rng);
|
||||
uint8_t random_u08(const Random *_Nonnull rng);
|
||||
|
||||
/**
|
||||
* @brief Return a random 16 bit integer.
|
||||
*/
|
||||
non_null()
|
||||
uint16_t random_u16(const Random *rng);
|
||||
uint16_t random_u16(const Random *_Nonnull rng);
|
||||
|
||||
/**
|
||||
* @brief Return a random 32 bit integer.
|
||||
*/
|
||||
non_null()
|
||||
uint32_t random_u32(const Random *rng);
|
||||
uint32_t random_u32(const Random *_Nonnull rng);
|
||||
|
||||
/**
|
||||
* @brief Return a random 64 bit integer.
|
||||
*/
|
||||
non_null()
|
||||
uint64_t random_u64(const Random *rng);
|
||||
uint64_t random_u64(const Random *_Nonnull rng);
|
||||
|
||||
/**
|
||||
* @brief Return a random 32 bit integer between 0 and upper_bound (excluded).
|
||||
*
|
||||
* This function guarantees a uniform distribution of possible outputs.
|
||||
*/
|
||||
non_null()
|
||||
uint32_t random_range_u32(const Random *rng, uint32_t upper_bound);
|
||||
uint32_t random_range_u32(const Random *_Nonnull rng, uint32_t upper_bound);
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
non_null()
|
||||
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]);
|
||||
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]);
|
||||
|
||||
/** @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.
|
||||
*/
|
||||
non_null()
|
||||
bool crypto_signature_verify(const uint8_t signature[CRYPTO_SIGNATURE_SIZE],
|
||||
const uint8_t *message, uint64_t message_length,
|
||||
const uint8_t public_key[SIG_PUBLIC_KEY_SIZE]);
|
||||
bool crypto_signature_verify(const uint8_t signature[_Nonnull CRYPTO_SIGNATURE_SIZE], const uint8_t *_Nonnull message, uint64_t message_length,
|
||||
const uint8_t public_key[_Nonnull SIG_PUBLIC_KEY_SIZE]);
|
||||
|
||||
/**
|
||||
* @brief Fill the given nonce with random bytes.
|
||||
*/
|
||||
non_null()
|
||||
void random_nonce(const Random *rng, uint8_t nonce[CRYPTO_NONCE_SIZE]);
|
||||
void random_nonce(const Random *_Nonnull rng, uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE]);
|
||||
|
||||
/**
|
||||
* @brief Fill an array of bytes with random values.
|
||||
*/
|
||||
non_null()
|
||||
void random_bytes(const Random *rng, uint8_t *bytes, size_t length);
|
||||
void random_bytes(const Random *_Nonnull rng, uint8_t *_Nonnull bytes, size_t length);
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
non_null()
|
||||
bool public_key_valid(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]);
|
||||
bool public_key_valid(const uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE]);
|
||||
|
||||
typedef struct Extended_Public_Key {
|
||||
uint8_t enc[CRYPTO_PUBLIC_KEY_SIZE];
|
||||
@@ -348,32 +324,26 @@ typedef struct Extended_Secret_Key {
|
||||
*
|
||||
* @retval true on success.
|
||||
*/
|
||||
non_null()
|
||||
bool create_extended_keypair(Extended_Public_Key *pk, Extended_Secret_Key *sk, const Random *rng);
|
||||
bool create_extended_keypair(Extended_Public_Key *_Nonnull pk, Extended_Secret_Key *_Nonnull sk, const Random *_Nonnull rng);
|
||||
|
||||
/** Functions for groupchat extended keys */
|
||||
non_null() const uint8_t *get_enc_key(const Extended_Public_Key *key);
|
||||
non_null() const uint8_t *get_sig_pk(const Extended_Public_Key *key);
|
||||
non_null() void set_sig_pk(Extended_Public_Key *key, const uint8_t *sig_pk);
|
||||
non_null() const uint8_t *get_sig_sk(const Extended_Secret_Key *key);
|
||||
non_null() const uint8_t *get_chat_id(const Extended_Public_Key *key);
|
||||
const uint8_t *_Nonnull get_enc_key(const Extended_Public_Key *_Nonnull key);
|
||||
const uint8_t *_Nonnull get_sig_pk(const Extended_Public_Key *_Nonnull key);
|
||||
void set_sig_pk(Extended_Public_Key *_Nonnull key, const uint8_t *_Nonnull sig_pk);
|
||||
const uint8_t *_Nonnull get_sig_sk(const Extended_Secret_Key *_Nonnull key);
|
||||
const uint8_t *_Nonnull get_chat_id(const Extended_Public_Key *_Nonnull key);
|
||||
|
||||
/**
|
||||
* @brief Generate a new random keypair.
|
||||
*
|
||||
* Every call to this function is likely to generate a different keypair.
|
||||
*/
|
||||
non_null()
|
||||
int32_t crypto_new_keypair(const Random *rng,
|
||||
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
|
||||
uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE]);
|
||||
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]);
|
||||
|
||||
/**
|
||||
* @brief Derive the public key from a given secret key.
|
||||
*/
|
||||
non_null()
|
||||
void crypto_derive_public_key(uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
|
||||
const uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE]);
|
||||
void crypto_derive_public_key(uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t secret_key[_Nonnull CRYPTO_SECRET_KEY_SIZE]);
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* @return length of encrypted data if everything was fine.
|
||||
*/
|
||||
non_null()
|
||||
int32_t encrypt_data(const Memory *mem,
|
||||
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);
|
||||
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],
|
||||
const uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE], const uint8_t *_Nonnull plain, size_t length, uint8_t *_Nonnull encrypted);
|
||||
|
||||
/**
|
||||
* @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).
|
||||
* @return length of plain text data if everything was fine.
|
||||
*/
|
||||
non_null()
|
||||
int32_t decrypt_data(const Memory *mem,
|
||||
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);
|
||||
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],
|
||||
const uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE], const uint8_t *_Nonnull encrypted, size_t length, uint8_t *_Nonnull plain);
|
||||
|
||||
/**
|
||||
* @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
|
||||
* encrypt/decrypt.
|
||||
*/
|
||||
non_null()
|
||||
int32_t encrypt_precompute(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
|
||||
const uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE],
|
||||
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]);
|
||||
int32_t encrypt_precompute(const uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t secret_key[_Nonnull CRYPTO_SECRET_KEY_SIZE],
|
||||
uint8_t shared_key[_Nonnull CRYPTO_SHARED_KEY_SIZE]);
|
||||
|
||||
/**
|
||||
* @brief Encrypt message with precomputed shared key.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @retval -1 if there was a problem.
|
||||
* @return length of encrypted data if everything was fine.
|
||||
*/
|
||||
non_null()
|
||||
int32_t encrypt_data_symmetric(const Memory *mem,
|
||||
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);
|
||||
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],
|
||||
const uint8_t *_Nonnull plain, size_t length, uint8_t *_Nonnull encrypted);
|
||||
|
||||
/**
|
||||
* @brief Decrypt message with precomputed shared key.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @retval -1 if there was a problem (decryption failed).
|
||||
* @return length of plain data if everything was fine.
|
||||
*/
|
||||
non_null()
|
||||
int32_t decrypt_data_symmetric(const Memory *mem,
|
||||
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);
|
||||
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],
|
||||
const uint8_t *_Nonnull encrypted, size_t length, uint8_t *_Nonnull plain);
|
||||
|
||||
/**
|
||||
* @brief Increment the given nonce by 1 in big endian (rightmost byte incremented first).
|
||||
*/
|
||||
non_null()
|
||||
void increment_nonce(uint8_t nonce[CRYPTO_NONCE_SIZE]);
|
||||
void increment_nonce(uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE]);
|
||||
|
||||
/**
|
||||
* @brief Increment the given nonce by a given number.
|
||||
*
|
||||
* The number should be in host byte order.
|
||||
*/
|
||||
non_null()
|
||||
void increment_nonce_number(uint8_t nonce[CRYPTO_NONCE_SIZE], uint32_t increment);
|
||||
void increment_nonce_number(uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE], uint32_t increment);
|
||||
|
||||
/**
|
||||
* @brief Fill a key @ref CRYPTO_SYMMETRIC_KEY_SIZE big with random bytes.
|
||||
*/
|
||||
non_null()
|
||||
void new_symmetric_key(const Random *rng, uint8_t key[CRYPTO_SYMMETRIC_KEY_SIZE]);
|
||||
void new_symmetric_key(const Random *_Nonnull rng, uint8_t key[_Nonnull CRYPTO_SYMMETRIC_KEY_SIZE]);
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
non_null()
|
||||
bool crypto_memlock(void *data, size_t length);
|
||||
bool crypto_memlock(void *_Nonnull data, size_t length);
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
non_null()
|
||||
bool crypto_memunlock(void *data, size_t length);
|
||||
bool crypto_memunlock(void *_Nonnull data, size_t length);
|
||||
|
||||
/**
|
||||
* @brief Generate a random secret HMAC key.
|
||||
*/
|
||||
non_null()
|
||||
void new_hmac_key(const Random *rng, uint8_t key[CRYPTO_HMAC_KEY_SIZE]);
|
||||
void new_hmac_key(const Random *_Nonnull rng, uint8_t key[_Nonnull CRYPTO_HMAC_KEY_SIZE]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
@@ -12,7 +12,7 @@
|
||||
#include "ccompat.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];
|
||||
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));
|
||||
}
|
||||
|
||||
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];
|
||||
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;
|
||||
}
|
||||
|
||||
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];
|
||||
|
||||
@@ -50,7 +50,7 @@ bool unpack_extended_public_key(Extended_Public_Key *key, Bin_Unpack *bu)
|
||||
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];
|
||||
|
||||
|
@@ -19,10 +19,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
non_null() bool pack_extended_public_key(const Extended_Public_Key *key, Bin_Pack *bp);
|
||||
non_null() bool pack_extended_secret_key(const Extended_Secret_Key *key, Bin_Pack *bp);
|
||||
non_null() bool unpack_extended_public_key(Extended_Public_Key *key, Bin_Unpack *bu);
|
||||
non_null() bool unpack_extended_secret_key(Extended_Secret_Key *key, Bin_Unpack *bu);
|
||||
bool pack_extended_public_key(const Extended_Public_Key *_Nonnull key, Bin_Pack *_Nonnull bp);
|
||||
bool pack_extended_secret_key(const Extended_Secret_Key *_Nonnull key, Bin_Pack *_Nonnull bp);
|
||||
bool unpack_extended_public_key(Extended_Public_Key *_Nonnull key, Bin_Unpack *_Nonnull bu);
|
||||
bool unpack_extended_secret_key(Extended_Secret_Key *_Nonnull key, Bin_Unpack *_Nonnull bu);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
@@ -25,9 +25,7 @@ struct Tox_Event_Conference_Connected {
|
||||
uint32_t conference_number;
|
||||
};
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_connected_set_conference_number(Tox_Event_Conference_Connected *conference_connected,
|
||||
uint32_t conference_number)
|
||||
static void tox_event_conference_connected_set_conference_number(Tox_Event_Conference_Connected *_Nonnull conference_connected, uint32_t conference_number)
|
||||
{
|
||||
assert(conference_connected != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_connected_construct(Tox_Event_Conference_Connected *conference_connected)
|
||||
static void tox_event_conference_connected_construct(Tox_Event_Conference_Connected *_Nonnull conference_connected)
|
||||
{
|
||||
*conference_connected = (Tox_Event_Conference_Connected) {
|
||||
0
|
||||
};
|
||||
}
|
||||
non_null()
|
||||
static void tox_event_conference_connected_destruct(Tox_Event_Conference_Connected *conference_connected, const Memory *mem)
|
||||
static void tox_event_conference_connected_destruct(Tox_Event_Conference_Connected *_Nonnull conference_connected, const Memory *_Nonnull mem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -57,9 +53,7 @@ bool tox_event_conference_connected_pack(
|
||||
return bin_pack_u32(bp, event->conference_number);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool tox_event_conference_connected_unpack_into(
|
||||
Tox_Event_Conference_Connected *event, Bin_Unpack *bu)
|
||||
static bool tox_event_conference_connected_unpack_into(Tox_Event_Conference_Connected *_Nonnull event, Bin_Unpack *_Nonnull bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_Conference_Connected *tox_events_add_conference_connected(Tox_Events *events, const Memory *mem)
|
||||
static Tox_Event_Conference_Connected *tox_events_add_conference_connected(Tox_Events *_Nonnull events, const Memory *_Nonnull 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_Conference_Connected *tox_event_conference_connected_alloc(void *user_data)
|
||||
static Tox_Event_Conference_Connected *tox_event_conference_connected_alloc(void *_Nonnull user_data)
|
||||
{
|
||||
Tox_Events_State *state = tox_events_alloc(user_data);
|
||||
assert(state != nullptr);
|
||||
|
@@ -32,9 +32,7 @@ struct Tox_Event_Conference_Invite {
|
||||
uint32_t cookie_length;
|
||||
};
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_invite_set_friend_number(Tox_Event_Conference_Invite *conference_invite,
|
||||
uint32_t friend_number)
|
||||
static void tox_event_conference_invite_set_friend_number(Tox_Event_Conference_Invite *_Nonnull conference_invite, uint32_t friend_number)
|
||||
{
|
||||
assert(conference_invite != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_invite_set_type(Tox_Event_Conference_Invite *conference_invite,
|
||||
Tox_Conference_Type type)
|
||||
static void tox_event_conference_invite_set_type(Tox_Event_Conference_Invite *_Nonnull conference_invite, Tox_Conference_Type type)
|
||||
{
|
||||
assert(conference_invite != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_conference_invite_set_cookie(Tox_Event_Conference_Invite *conference_invite,
|
||||
const uint8_t *cookie, uint32_t cookie_length)
|
||||
static bool tox_event_conference_invite_set_cookie(Tox_Event_Conference_Invite *_Nonnull conference_invite,
|
||||
const uint8_t *_Nullable cookie, uint32_t cookie_length)
|
||||
{
|
||||
assert(conference_invite != nullptr);
|
||||
|
||||
if (conference_invite->cookie != nullptr) {
|
||||
free(conference_invite->cookie);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_invite_construct(Tox_Event_Conference_Invite *conference_invite)
|
||||
static void tox_event_conference_invite_construct(Tox_Event_Conference_Invite *_Nonnull conference_invite)
|
||||
{
|
||||
*conference_invite = (Tox_Event_Conference_Invite) {
|
||||
0
|
||||
};
|
||||
}
|
||||
non_null()
|
||||
static void tox_event_conference_invite_destruct(Tox_Event_Conference_Invite *conference_invite, const Memory *mem)
|
||||
static void tox_event_conference_invite_destruct(Tox_Event_Conference_Invite *_Nonnull conference_invite, const Memory *_Nonnull mem)
|
||||
{
|
||||
free(conference_invite->cookie);
|
||||
}
|
||||
@@ -119,9 +111,7 @@ bool tox_event_conference_invite_pack(
|
||||
&& bin_pack_bin(bp, event->cookie, event->cookie_length);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool tox_event_conference_invite_unpack_into(
|
||||
Tox_Event_Conference_Invite *event, Bin_Unpack *bu)
|
||||
static bool tox_event_conference_invite_unpack_into(Tox_Event_Conference_Invite *_Nonnull event, Bin_Unpack *_Nonnull bu)
|
||||
{
|
||||
assert(event != 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_Conference_Invite *tox_events_add_conference_invite(Tox_Events *events, const Memory *mem)
|
||||
static Tox_Event_Conference_Invite *tox_events_add_conference_invite(Tox_Events *_Nonnull events, const Memory *_Nonnull 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_Conference_Invite *tox_event_conference_invite_alloc(void *user_data)
|
||||
static Tox_Event_Conference_Invite *tox_event_conference_invite_alloc(void *_Nonnull user_data)
|
||||
{
|
||||
Tox_Events_State *state = tox_events_alloc(user_data);
|
||||
assert(state != nullptr);
|
||||
|
@@ -33,9 +33,7 @@ struct Tox_Event_Conference_Message {
|
||||
uint32_t message_length;
|
||||
};
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_message_set_conference_number(Tox_Event_Conference_Message *conference_message,
|
||||
uint32_t conference_number)
|
||||
static void tox_event_conference_message_set_conference_number(Tox_Event_Conference_Message *_Nonnull conference_message, uint32_t conference_number)
|
||||
{
|
||||
assert(conference_message != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_message_set_peer_number(Tox_Event_Conference_Message *conference_message,
|
||||
uint32_t peer_number)
|
||||
static void tox_event_conference_message_set_peer_number(Tox_Event_Conference_Message *_Nonnull conference_message, uint32_t peer_number)
|
||||
{
|
||||
assert(conference_message != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_message_set_type(Tox_Event_Conference_Message *conference_message,
|
||||
Tox_Message_Type type)
|
||||
static void tox_event_conference_message_set_type(Tox_Event_Conference_Message *_Nonnull conference_message, Tox_Message_Type type)
|
||||
{
|
||||
assert(conference_message != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_conference_message_set_message(Tox_Event_Conference_Message *conference_message,
|
||||
const uint8_t *message, uint32_t message_length)
|
||||
static bool tox_event_conference_message_set_message(Tox_Event_Conference_Message *_Nonnull conference_message,
|
||||
const uint8_t *_Nullable message, uint32_t message_length)
|
||||
{
|
||||
assert(conference_message != nullptr);
|
||||
|
||||
if (conference_message->message != nullptr) {
|
||||
free(conference_message->message);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_message_construct(Tox_Event_Conference_Message *conference_message)
|
||||
static void tox_event_conference_message_construct(Tox_Event_Conference_Message *_Nonnull conference_message)
|
||||
{
|
||||
*conference_message = (Tox_Event_Conference_Message) {
|
||||
0
|
||||
};
|
||||
}
|
||||
non_null()
|
||||
static void tox_event_conference_message_destruct(Tox_Event_Conference_Message *conference_message, const Memory *mem)
|
||||
static void tox_event_conference_message_destruct(Tox_Event_Conference_Message *_Nonnull conference_message, const Memory *_Nonnull mem)
|
||||
{
|
||||
free(conference_message->message);
|
||||
}
|
||||
@@ -134,9 +124,7 @@ bool tox_event_conference_message_pack(
|
||||
&& bin_pack_bin(bp, event->message, event->message_length);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool tox_event_conference_message_unpack_into(
|
||||
Tox_Event_Conference_Message *event, Bin_Unpack *bu)
|
||||
static bool tox_event_conference_message_unpack_into(Tox_Event_Conference_Message *_Nonnull event, Bin_Unpack *_Nonnull bu)
|
||||
{
|
||||
assert(event != 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_Conference_Message *tox_events_add_conference_message(Tox_Events *events, const Memory *mem)
|
||||
static Tox_Event_Conference_Message *tox_events_add_conference_message(Tox_Events *_Nonnull events, const Memory *_Nonnull 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_Conference_Message *tox_event_conference_message_alloc(void *user_data)
|
||||
static Tox_Event_Conference_Message *tox_event_conference_message_alloc(void *_Nonnull user_data)
|
||||
{
|
||||
Tox_Events_State *state = tox_events_alloc(user_data);
|
||||
assert(state != nullptr);
|
||||
|
@@ -25,9 +25,7 @@ struct Tox_Event_Conference_Peer_List_Changed {
|
||||
uint32_t conference_number;
|
||||
};
|
||||
|
||||
non_null()
|
||||
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)
|
||||
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)
|
||||
{
|
||||
assert(conference_peer_list_changed != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_peer_list_changed_construct(Tox_Event_Conference_Peer_List_Changed *conference_peer_list_changed)
|
||||
static void tox_event_conference_peer_list_changed_construct(Tox_Event_Conference_Peer_List_Changed *_Nonnull conference_peer_list_changed)
|
||||
{
|
||||
*conference_peer_list_changed = (Tox_Event_Conference_Peer_List_Changed) {
|
||||
0
|
||||
};
|
||||
}
|
||||
non_null()
|
||||
static void tox_event_conference_peer_list_changed_destruct(Tox_Event_Conference_Peer_List_Changed *conference_peer_list_changed, const Memory *mem)
|
||||
static void tox_event_conference_peer_list_changed_destruct(Tox_Event_Conference_Peer_List_Changed *_Nonnull conference_peer_list_changed, const Memory *_Nonnull mem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -57,9 +53,7 @@ bool tox_event_conference_peer_list_changed_pack(
|
||||
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 *event, Bin_Unpack *bu)
|
||||
static bool tox_event_conference_peer_list_changed_unpack_into(Tox_Event_Conference_Peer_List_Changed *_Nonnull event, Bin_Unpack *_Nonnull bu)
|
||||
{
|
||||
assert(event != nullptr);
|
||||
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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_Conference_Peer_List_Changed *tox_events_add_conference_peer_list_changed(Tox_Events *events, const Memory *mem)
|
||||
static Tox_Event_Conference_Peer_List_Changed *tox_events_add_conference_peer_list_changed(Tox_Events *_Nonnull events, const Memory *_Nonnull 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_Conference_Peer_List_Changed *tox_event_conference_peer_list_changed_alloc(void *user_data)
|
||||
static Tox_Event_Conference_Peer_List_Changed *tox_event_conference_peer_list_changed_alloc(void *_Nonnull user_data)
|
||||
{
|
||||
Tox_Events_State *state = tox_events_alloc(user_data);
|
||||
assert(state != nullptr);
|
||||
|
@@ -30,9 +30,7 @@ struct Tox_Event_Conference_Peer_Name {
|
||||
uint32_t name_length;
|
||||
};
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_peer_name_set_conference_number(Tox_Event_Conference_Peer_Name *conference_peer_name,
|
||||
uint32_t conference_number)
|
||||
static void tox_event_conference_peer_name_set_conference_number(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name, uint32_t conference_number)
|
||||
{
|
||||
assert(conference_peer_name != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_peer_name_set_peer_number(Tox_Event_Conference_Peer_Name *conference_peer_name,
|
||||
uint32_t peer_number)
|
||||
static void tox_event_conference_peer_name_set_peer_number(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name, uint32_t peer_number)
|
||||
{
|
||||
assert(conference_peer_name != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_conference_peer_name_set_name(Tox_Event_Conference_Peer_Name *conference_peer_name,
|
||||
const uint8_t *name, uint32_t name_length)
|
||||
static bool tox_event_conference_peer_name_set_name(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name,
|
||||
const uint8_t *_Nullable name, uint32_t name_length)
|
||||
{
|
||||
assert(conference_peer_name != nullptr);
|
||||
|
||||
if (conference_peer_name->name != nullptr) {
|
||||
free(conference_peer_name->name);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_peer_name_construct(Tox_Event_Conference_Peer_Name *conference_peer_name)
|
||||
static void tox_event_conference_peer_name_construct(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name)
|
||||
{
|
||||
*conference_peer_name = (Tox_Event_Conference_Peer_Name) {
|
||||
0
|
||||
};
|
||||
}
|
||||
non_null()
|
||||
static void tox_event_conference_peer_name_destruct(Tox_Event_Conference_Peer_Name *conference_peer_name, const Memory *mem)
|
||||
static void tox_event_conference_peer_name_destruct(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name, const Memory *_Nonnull mem)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool tox_event_conference_peer_name_unpack_into(
|
||||
Tox_Event_Conference_Peer_Name *event, Bin_Unpack *bu)
|
||||
static bool tox_event_conference_peer_name_unpack_into(Tox_Event_Conference_Peer_Name *_Nonnull event, Bin_Unpack *_Nonnull bu)
|
||||
{
|
||||
assert(event != 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_Conference_Peer_Name *tox_events_add_conference_peer_name(Tox_Events *events, const Memory *mem)
|
||||
static Tox_Event_Conference_Peer_Name *tox_events_add_conference_peer_name(Tox_Events *_Nonnull events, const Memory *_Nonnull 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_Conference_Peer_Name *tox_event_conference_peer_name_alloc(void *user_data)
|
||||
static Tox_Event_Conference_Peer_Name *tox_event_conference_peer_name_alloc(void *_Nonnull user_data)
|
||||
{
|
||||
Tox_Events_State *state = tox_events_alloc(user_data);
|
||||
assert(state != nullptr);
|
||||
|
@@ -30,9 +30,7 @@ struct Tox_Event_Conference_Title {
|
||||
uint32_t title_length;
|
||||
};
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_title_set_conference_number(Tox_Event_Conference_Title *conference_title,
|
||||
uint32_t conference_number)
|
||||
static void tox_event_conference_title_set_conference_number(Tox_Event_Conference_Title *_Nonnull conference_title, uint32_t conference_number)
|
||||
{
|
||||
assert(conference_title != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_title_set_peer_number(Tox_Event_Conference_Title *conference_title,
|
||||
uint32_t peer_number)
|
||||
static void tox_event_conference_title_set_peer_number(Tox_Event_Conference_Title *_Nonnull conference_title, uint32_t peer_number)
|
||||
{
|
||||
assert(conference_title != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_conference_title_set_title(Tox_Event_Conference_Title *conference_title,
|
||||
const uint8_t *title, uint32_t title_length)
|
||||
static bool tox_event_conference_title_set_title(Tox_Event_Conference_Title *_Nonnull conference_title,
|
||||
const uint8_t *_Nullable title, uint32_t title_length)
|
||||
{
|
||||
assert(conference_title != nullptr);
|
||||
|
||||
if (conference_title->title != nullptr) {
|
||||
free(conference_title->title);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_conference_title_construct(Tox_Event_Conference_Title *conference_title)
|
||||
static void tox_event_conference_title_construct(Tox_Event_Conference_Title *_Nonnull conference_title)
|
||||
{
|
||||
*conference_title = (Tox_Event_Conference_Title) {
|
||||
0
|
||||
};
|
||||
}
|
||||
non_null()
|
||||
static void tox_event_conference_title_destruct(Tox_Event_Conference_Title *conference_title, const Memory *mem)
|
||||
static void tox_event_conference_title_destruct(Tox_Event_Conference_Title *_Nonnull conference_title, const Memory *_Nonnull mem)
|
||||
{
|
||||
free(conference_title->title);
|
||||
}
|
||||
@@ -117,9 +109,7 @@ bool tox_event_conference_title_pack(
|
||||
&& bin_pack_bin(bp, event->title, event->title_length);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool tox_event_conference_title_unpack_into(
|
||||
Tox_Event_Conference_Title *event, Bin_Unpack *bu)
|
||||
static bool tox_event_conference_title_unpack_into(Tox_Event_Conference_Title *_Nonnull event, Bin_Unpack *_Nonnull bu)
|
||||
{
|
||||
assert(event != 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_Conference_Title *tox_events_add_conference_title(Tox_Events *events, const Memory *mem)
|
||||
static Tox_Event_Conference_Title *tox_events_add_conference_title(Tox_Events *_Nonnull events, const Memory *_Nonnull 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_Conference_Title *tox_event_conference_title_alloc(void *user_data)
|
||||
static Tox_Event_Conference_Title *tox_event_conference_title_alloc(void *_Nonnull user_data)
|
||||
{
|
||||
Tox_Events_State *state = tox_events_alloc(user_data);
|
||||
assert(state != nullptr);
|
||||
|
@@ -30,20 +30,17 @@ struct Tox_Event_Dht_Nodes_Response {
|
||||
uint16_t port;
|
||||
};
|
||||
|
||||
non_null()
|
||||
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])
|
||||
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])
|
||||
{
|
||||
memcpy(dht_nodes_response->public_key, public_key, TOX_PUBLIC_KEY_SIZE);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
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)
|
||||
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)
|
||||
{
|
||||
if (dht_nodes_response->ip != nullptr) {
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool tox_event_dht_nodes_response_set_port(Tox_Event_Dht_Nodes_Response *dht_nodes_response, uint16_t port)
|
||||
static bool tox_event_dht_nodes_response_set_port(Tox_Event_Dht_Nodes_Response *_Nonnull dht_nodes_response, uint16_t port)
|
||||
{
|
||||
dht_nodes_response->port = port;
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_dht_nodes_response_construct(Tox_Event_Dht_Nodes_Response *dht_nodes_response)
|
||||
static void tox_event_dht_nodes_response_construct(Tox_Event_Dht_Nodes_Response *_Nonnull 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 *dht_nodes_response, const Memory *mem)
|
||||
static void tox_event_dht_nodes_response_destruct(Tox_Event_Dht_Nodes_Response *_Nonnull dht_nodes_response, const Memory *_Nonnull mem)
|
||||
{
|
||||
mem_delete(mem, dht_nodes_response->ip);
|
||||
}
|
||||
@@ -106,9 +100,7 @@ bool tox_event_dht_nodes_response_pack(
|
||||
&& bin_pack_u16(bp, event->port);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool tox_event_dht_nodes_response_unpack_into(
|
||||
Tox_Event_Dht_Nodes_Response *event, Bin_Unpack *bu)
|
||||
static bool tox_event_dht_nodes_response_unpack_into(Tox_Event_Dht_Nodes_Response *_Nonnull event, Bin_Unpack *_Nonnull bu)
|
||||
{
|
||||
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
|
||||
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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_Dht_Nodes_Response *tox_events_add_dht_nodes_response(Tox_Events *events, const Memory *mem)
|
||||
static Tox_Event_Dht_Nodes_Response *tox_events_add_dht_nodes_response(Tox_Events *_Nonnull events, const Memory *_Nonnull 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_Dht_Nodes_Response *tox_event_dht_nodes_response_alloc(void *user_data)
|
||||
static Tox_Event_Dht_Nodes_Response *tox_event_dht_nodes_response_alloc(void *_Nonnull user_data)
|
||||
{
|
||||
Tox_Events_State *state = tox_events_alloc(user_data);
|
||||
assert(state != nullptr);
|
||||
|
@@ -16,17 +16,17 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
struct Tox_Events {
|
||||
Tox_Event *events;
|
||||
Tox_Event *_Nonnull events;
|
||||
uint32_t events_size;
|
||||
uint32_t events_capacity;
|
||||
|
||||
const Memory *mem;
|
||||
const Memory *_Nonnull mem;
|
||||
};
|
||||
|
||||
typedef struct Tox_Events_State {
|
||||
Tox_Err_Events_Iterate error;
|
||||
const Memory *mem;
|
||||
Tox_Events *events;
|
||||
const Memory *_Nonnull mem;
|
||||
Tox_Events *_Nonnull events;
|
||||
} Tox_Events_State;
|
||||
|
||||
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_moderation_cb tox_events_handle_group_moderation;
|
||||
|
||||
non_null()
|
||||
Tox_Events_State *tox_events_alloc(void *user_data);
|
||||
Tox_Events_State *_Nonnull tox_events_alloc(void *_Nonnull user_data);
|
||||
|
||||
non_null()
|
||||
bool tox_events_add(Tox_Events *events, const Tox_Event *event);
|
||||
bool tox_events_add(Tox_Events *_Nonnull events, const Tox_Event *_Nonnull event);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
@@ -28,9 +28,7 @@ struct Tox_Event_File_Chunk_Request {
|
||||
uint16_t length;
|
||||
};
|
||||
|
||||
non_null()
|
||||
static void tox_event_file_chunk_request_set_friend_number(Tox_Event_File_Chunk_Request *file_chunk_request,
|
||||
uint32_t friend_number)
|
||||
static void tox_event_file_chunk_request_set_friend_number(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, uint32_t friend_number)
|
||||
{
|
||||
assert(file_chunk_request != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_file_chunk_request_set_file_number(Tox_Event_File_Chunk_Request *file_chunk_request,
|
||||
uint32_t file_number)
|
||||
static void tox_event_file_chunk_request_set_file_number(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, uint32_t file_number)
|
||||
{
|
||||
assert(file_chunk_request != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_file_chunk_request_set_position(Tox_Event_File_Chunk_Request *file_chunk_request,
|
||||
uint64_t position)
|
||||
static void tox_event_file_chunk_request_set_position(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, uint64_t position)
|
||||
{
|
||||
assert(file_chunk_request != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_file_chunk_request_set_length(Tox_Event_File_Chunk_Request *file_chunk_request,
|
||||
uint16_t length)
|
||||
static void tox_event_file_chunk_request_set_length(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, uint16_t length)
|
||||
{
|
||||
assert(file_chunk_request != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_file_chunk_request_construct(Tox_Event_File_Chunk_Request *file_chunk_request)
|
||||
static void tox_event_file_chunk_request_construct(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request)
|
||||
{
|
||||
*file_chunk_request = (Tox_Event_File_Chunk_Request) {
|
||||
0
|
||||
};
|
||||
}
|
||||
non_null()
|
||||
static void tox_event_file_chunk_request_destruct(Tox_Event_File_Chunk_Request *file_chunk_request, const Memory *mem)
|
||||
static void tox_event_file_chunk_request_destruct(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, const Memory *_Nonnull mem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -103,9 +93,7 @@ bool tox_event_file_chunk_request_pack(
|
||||
&& bin_pack_u16(bp, event->length);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool tox_event_file_chunk_request_unpack_into(
|
||||
Tox_Event_File_Chunk_Request *event, Bin_Unpack *bu)
|
||||
static bool tox_event_file_chunk_request_unpack_into(Tox_Event_File_Chunk_Request *_Nonnull event, Bin_Unpack *_Nonnull bu)
|
||||
{
|
||||
assert(event != 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_File_Chunk_Request *tox_events_add_file_chunk_request(Tox_Events *events, const Memory *mem)
|
||||
static Tox_Event_File_Chunk_Request *tox_events_add_file_chunk_request(Tox_Events *_Nonnull events, const Memory *_Nonnull 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_File_Chunk_Request *tox_event_file_chunk_request_alloc(void *user_data)
|
||||
static Tox_Event_File_Chunk_Request *tox_event_file_chunk_request_alloc(void *_Nonnull user_data)
|
||||
{
|
||||
Tox_Events_State *state = tox_events_alloc(user_data);
|
||||
assert(state != nullptr);
|
||||
|
@@ -32,9 +32,7 @@ struct Tox_Event_File_Recv {
|
||||
uint32_t filename_length;
|
||||
};
|
||||
|
||||
non_null()
|
||||
static void tox_event_file_recv_set_friend_number(Tox_Event_File_Recv *file_recv,
|
||||
uint32_t friend_number)
|
||||
static void tox_event_file_recv_set_friend_number(Tox_Event_File_Recv *_Nonnull file_recv, uint32_t friend_number)
|
||||
{
|
||||
assert(file_recv != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_file_recv_set_file_number(Tox_Event_File_Recv *file_recv,
|
||||
uint32_t file_number)
|
||||
static void tox_event_file_recv_set_file_number(Tox_Event_File_Recv *_Nonnull file_recv, uint32_t file_number)
|
||||
{
|
||||
assert(file_recv != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_file_recv_set_kind(Tox_Event_File_Recv *file_recv,
|
||||
uint32_t kind)
|
||||
static void tox_event_file_recv_set_kind(Tox_Event_File_Recv *_Nonnull file_recv, uint32_t kind)
|
||||
{
|
||||
assert(file_recv != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_file_recv_set_file_size(Tox_Event_File_Recv *file_recv,
|
||||
uint64_t file_size)
|
||||
static void tox_event_file_recv_set_file_size(Tox_Event_File_Recv *_Nonnull file_recv, uint64_t file_size)
|
||||
{
|
||||
assert(file_recv != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_file_recv_set_filename(Tox_Event_File_Recv *file_recv,
|
||||
const uint8_t *filename, uint32_t filename_length)
|
||||
static bool tox_event_file_recv_set_filename(Tox_Event_File_Recv *_Nonnull file_recv,
|
||||
const uint8_t *_Nullable filename, uint32_t filename_length)
|
||||
{
|
||||
assert(file_recv != nullptr);
|
||||
|
||||
if (file_recv->filename != nullptr) {
|
||||
free(file_recv->filename);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_file_recv_construct(Tox_Event_File_Recv *file_recv)
|
||||
static void tox_event_file_recv_construct(Tox_Event_File_Recv *_Nonnull file_recv)
|
||||
{
|
||||
*file_recv = (Tox_Event_File_Recv) {
|
||||
0
|
||||
};
|
||||
}
|
||||
non_null()
|
||||
static void tox_event_file_recv_destruct(Tox_Event_File_Recv *file_recv, const Memory *mem)
|
||||
static void tox_event_file_recv_destruct(Tox_Event_File_Recv *_Nonnull file_recv, const Memory *_Nonnull mem)
|
||||
{
|
||||
free(file_recv->filename);
|
||||
}
|
||||
@@ -147,9 +135,7 @@ bool tox_event_file_recv_pack(
|
||||
&& bin_pack_bin(bp, event->filename, event->filename_length);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool tox_event_file_recv_unpack_into(
|
||||
Tox_Event_File_Recv *event, Bin_Unpack *bu)
|
||||
static bool tox_event_file_recv_unpack_into(Tox_Event_File_Recv *_Nonnull event, Bin_Unpack *_Nonnull bu)
|
||||
{
|
||||
assert(event != 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_File_Recv *tox_events_add_file_recv(Tox_Events *events, const Memory *mem)
|
||||
static Tox_Event_File_Recv *tox_events_add_file_recv(Tox_Events *_Nonnull events, const Memory *_Nonnull 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_File_Recv *tox_event_file_recv_alloc(void *user_data)
|
||||
static Tox_Event_File_Recv *tox_event_file_recv_alloc(void *_Nonnull user_data)
|
||||
{
|
||||
Tox_Events_State *state = tox_events_alloc(user_data);
|
||||
assert(state != nullptr);
|
||||
|
@@ -31,9 +31,7 @@ struct Tox_Event_File_Recv_Chunk {
|
||||
uint32_t data_length;
|
||||
};
|
||||
|
||||
non_null()
|
||||
static void tox_event_file_recv_chunk_set_friend_number(Tox_Event_File_Recv_Chunk *file_recv_chunk,
|
||||
uint32_t friend_number)
|
||||
static void tox_event_file_recv_chunk_set_friend_number(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk, uint32_t friend_number)
|
||||
{
|
||||
assert(file_recv_chunk != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_file_recv_chunk_set_file_number(Tox_Event_File_Recv_Chunk *file_recv_chunk,
|
||||
uint32_t file_number)
|
||||
static void tox_event_file_recv_chunk_set_file_number(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk, uint32_t file_number)
|
||||
{
|
||||
assert(file_recv_chunk != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_file_recv_chunk_set_position(Tox_Event_File_Recv_Chunk *file_recv_chunk,
|
||||
uint64_t position)
|
||||
static void tox_event_file_recv_chunk_set_position(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk, uint64_t position)
|
||||
{
|
||||
assert(file_recv_chunk != nullptr);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_file_recv_chunk_set_data(Tox_Event_File_Recv_Chunk *file_recv_chunk,
|
||||
const uint8_t *data, uint32_t data_length)
|
||||
static bool tox_event_file_recv_chunk_set_data(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk,
|
||||
const uint8_t *_Nullable data, uint32_t data_length)
|
||||
{
|
||||
assert(file_recv_chunk != nullptr);
|
||||
|
||||
if (file_recv_chunk->data != nullptr) {
|
||||
free(file_recv_chunk->data);
|
||||
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;
|
||||
}
|
||||
|
||||
non_null()
|
||||
static void tox_event_file_recv_chunk_construct(Tox_Event_File_Recv_Chunk *file_recv_chunk)
|
||||
static void tox_event_file_recv_chunk_construct(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk)
|
||||
{
|
||||
*file_recv_chunk = (Tox_Event_File_Recv_Chunk) {
|
||||
0
|
||||
};
|
||||
}
|
||||
non_null()
|
||||
static void tox_event_file_recv_chunk_destruct(Tox_Event_File_Recv_Chunk *file_recv_chunk, const Memory *mem)
|
||||
static void tox_event_file_recv_chunk_destruct(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk, const Memory *_Nonnull mem)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static bool tox_event_file_recv_chunk_unpack_into(
|
||||
Tox_Event_File_Recv_Chunk *event, Bin_Unpack *bu)
|
||||
static bool tox_event_file_recv_chunk_unpack_into(Tox_Event_File_Recv_Chunk *_Nonnull event, Bin_Unpack *_Nonnull bu)
|
||||
{
|
||||
assert(event != 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_File_Recv_Chunk *tox_events_add_file_recv_chunk(Tox_Events *events, const Memory *mem)
|
||||
static Tox_Event_File_Recv_Chunk *tox_events_add_file_recv_chunk(Tox_Events *_Nonnull events, const Memory *_Nonnull 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);
|
||||
}
|
||||
|
||||
non_null()
|
||||
static Tox_Event_File_Recv_Chunk *tox_event_file_recv_chunk_alloc(void *user_data)
|
||||
static Tox_Event_File_Recv_Chunk *tox_event_file_recv_chunk_alloc(void *_Nonnull user_data)
|
||||
{
|
||||
Tox_Events_State *state = tox_events_alloc(user_data);
|
||||
assert(state != nullptr);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user