update toxcore Merge commit '3b6bb15e867a5f3895773554b1cfa928fcfd3e8f'
This commit is contained in:
commit
a61e84dfa4
19
external/toxcore/c-toxcore/.circleci/config.yml
vendored
19
external/toxcore/c-toxcore/.circleci/config.yml
vendored
@ -6,7 +6,8 @@ workflows:
|
|||||||
circleci:
|
circleci:
|
||||||
jobs:
|
jobs:
|
||||||
- bazel-asan
|
- bazel-asan
|
||||||
- bazel-msan
|
- bazel-dbg
|
||||||
|
- bazel-opt
|
||||||
- clang-analyze
|
- clang-analyze
|
||||||
- cpplint
|
- cpplint
|
||||||
- static-analysis
|
- static-analysis
|
||||||
@ -24,15 +25,25 @@ jobs:
|
|||||||
- run: .circleci/bazel-test
|
- run: .circleci/bazel-test
|
||||||
//c-toxcore/...
|
//c-toxcore/...
|
||||||
|
|
||||||
bazel-msan:
|
bazel-dbg:
|
||||||
working_directory: /tmp/cirrus-ci-build
|
working_directory: /tmp/cirrus-ci-build
|
||||||
docker:
|
docker:
|
||||||
- image: toxchat/toktok-stack:latest-msan
|
- image: toxchat/toktok-stack:latest-debug
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- run: .circleci/bazel-test
|
- run: .circleci/bazel-test
|
||||||
//c-toxcore/auto_tests:lossless_packet_test
|
//c-toxcore/...
|
||||||
|
|
||||||
|
bazel-opt:
|
||||||
|
working_directory: /tmp/cirrus-ci-build
|
||||||
|
docker:
|
||||||
|
- image: toxchat/toktok-stack:latest-release
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: .circleci/bazel-test
|
||||||
|
//c-toxcore/...
|
||||||
|
|
||||||
static-analysis:
|
static-analysis:
|
||||||
working_directory: ~/work
|
working_directory: ~/work
|
||||||
|
39
external/toxcore/c-toxcore/.cirrus.yml
vendored
39
external/toxcore/c-toxcore/.cirrus.yml
vendored
@ -1,18 +1,16 @@
|
|||||||
---
|
---
|
||||||
bazel-opt_task:
|
bazel-opt_task:
|
||||||
timeout_in: 5m
|
timeout_in: 10m
|
||||||
container:
|
container:
|
||||||
image: toxchat/toktok-stack:latest-release
|
image: toxchat/toktok-stack:latest-release
|
||||||
cpu: 2
|
cpu: 8
|
||||||
memory: 2G
|
memory: 2G
|
||||||
configure_script:
|
configure_script:
|
||||||
- git submodule update --init --recursive
|
- git submodule update --init --recursive
|
||||||
- /src/workspace/tools/inject-repo c-toxcore
|
- /src/workspace/tools/inject-repo c-toxcore
|
||||||
test_all_script:
|
test_all_script:
|
||||||
- cd /src/workspace && bazel
|
- cd /src/workspace && tools/retry 5 bazel
|
||||||
--max_idle_secs=5
|
|
||||||
test -k
|
test -k
|
||||||
--remote_cache=http://$CIRRUS_HTTP_CACHE_HOST
|
|
||||||
--build_tag_filters=-haskell
|
--build_tag_filters=-haskell
|
||||||
--test_tag_filters=-haskell
|
--test_tag_filters=-haskell
|
||||||
--
|
--
|
||||||
@ -20,25 +18,38 @@ bazel-opt_task:
|
|||||||
-//c-toxcore/auto_tests:tcp_relay_test # Cirrus doesn't allow external network connections.
|
-//c-toxcore/auto_tests:tcp_relay_test # Cirrus doesn't allow external network connections.
|
||||||
|
|
||||||
bazel-dbg_task:
|
bazel-dbg_task:
|
||||||
timeout_in: 5m
|
timeout_in: 10m
|
||||||
container:
|
container:
|
||||||
image: toxchat/toktok-stack:latest-debug
|
image: toxchat/toktok-stack:latest-debug
|
||||||
cpu: 2
|
cpu: 8
|
||||||
memory: 2G
|
memory: 2G
|
||||||
configure_script:
|
configure_script:
|
||||||
- git submodule update --init --recursive
|
- git submodule update --init --recursive
|
||||||
- /src/workspace/tools/inject-repo c-toxcore
|
- /src/workspace/tools/inject-repo c-toxcore
|
||||||
test_all_script:
|
test_all_script:
|
||||||
- cd /src/workspace && bazel
|
- cd /src/workspace && tools/retry 5 bazel
|
||||||
--max_idle_secs=5
|
|
||||||
test -k
|
test -k
|
||||||
--remote_cache=http://$CIRRUS_HTTP_CACHE_HOST
|
|
||||||
--build_tag_filters=-haskell
|
--build_tag_filters=-haskell
|
||||||
--test_tag_filters=-haskell
|
--test_tag_filters=-haskell
|
||||||
--
|
--
|
||||||
//c-toxcore/...
|
//c-toxcore/...
|
||||||
-//c-toxcore/auto_tests:tcp_relay_test # Cirrus doesn't allow external network connections.
|
-//c-toxcore/auto_tests:tcp_relay_test # Cirrus doesn't allow external network connections.
|
||||||
|
|
||||||
|
bazel-msan_task:
|
||||||
|
timeout_in: 10m
|
||||||
|
container:
|
||||||
|
image: toxchat/toktok-stack:latest-msan
|
||||||
|
cpu: 4
|
||||||
|
memory: 2G
|
||||||
|
configure_script:
|
||||||
|
- git submodule update --init --recursive
|
||||||
|
- /src/workspace/tools/inject-repo c-toxcore
|
||||||
|
test_all_script:
|
||||||
|
- cd /src/workspace && tools/retry 5 bazel
|
||||||
|
test -k
|
||||||
|
--
|
||||||
|
//c-toxcore/auto_tests:lossless_packet_test
|
||||||
|
|
||||||
cimple_task:
|
cimple_task:
|
||||||
timeout_in: 5m
|
timeout_in: 5m
|
||||||
container:
|
container:
|
||||||
@ -50,9 +61,7 @@ cimple_task:
|
|||||||
- /src/workspace/tools/inject-repo c-toxcore
|
- /src/workspace/tools/inject-repo c-toxcore
|
||||||
test_all_script:
|
test_all_script:
|
||||||
- cd /src/workspace && bazel
|
- cd /src/workspace && bazel
|
||||||
--max_idle_secs=5
|
|
||||||
test -k
|
test -k
|
||||||
--remote_cache=http://$CIRRUS_HTTP_CACHE_HOST
|
|
||||||
--build_tag_filters=haskell
|
--build_tag_filters=haskell
|
||||||
--test_tag_filters=haskell
|
--test_tag_filters=haskell
|
||||||
--
|
--
|
||||||
@ -71,6 +80,7 @@ freebsd_task:
|
|||||||
libconfig
|
libconfig
|
||||||
libsodium
|
libsodium
|
||||||
libvpx
|
libvpx
|
||||||
|
ninja
|
||||||
opus
|
opus
|
||||||
pkgconf
|
pkgconf
|
||||||
- git submodule update --init --recursive
|
- git submodule update --init --recursive
|
||||||
@ -84,6 +94,7 @@ freebsd_task:
|
|||||||
-DNON_HERMETIC_TESTS=OFF \
|
-DNON_HERMETIC_TESTS=OFF \
|
||||||
-DTEST_TIMEOUT_SECONDS=50 \
|
-DTEST_TIMEOUT_SECONDS=50 \
|
||||||
-DUSE_IPV6=OFF \
|
-DUSE_IPV6=OFF \
|
||||||
-DAUTOTEST=ON
|
-DAUTOTEST=ON \
|
||||||
|
-GNinja
|
||||||
cmake --build . --target install
|
cmake --build . --target install
|
||||||
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6
|
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:3 || ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:3
|
||||||
|
@ -42,6 +42,7 @@ RUN "cmake -B_build -Hc-toxcore \
|
|||||||
-DCMAKE_EXE_LINKER_FLAGS='$LD_FLAGS' \
|
-DCMAKE_EXE_LINKER_FLAGS='$LD_FLAGS' \
|
||||||
-DCMAKE_SHARED_LINKER_FLAGS='$LD_FLAGS' \
|
-DCMAKE_SHARED_LINKER_FLAGS='$LD_FLAGS' \
|
||||||
-DCMAKE_INSTALL_PREFIX:PATH='_install' \
|
-DCMAKE_INSTALL_PREFIX:PATH='_install' \
|
||||||
|
-DENABLE_SHARED=OFF \
|
||||||
-DMIN_LOGGER_LEVEL=TRACE \
|
-DMIN_LOGGER_LEVEL=TRACE \
|
||||||
-DMUST_BUILD_TOXAV=ON \
|
-DMUST_BUILD_TOXAV=ON \
|
||||||
-DNON_HERMETIC_TESTS=ON \
|
-DNON_HERMETIC_TESTS=ON \
|
||||||
|
@ -127,6 +127,7 @@ jobs:
|
|||||||
libopus
|
libopus
|
||||||
libsodium
|
libsodium
|
||||||
libvpx
|
libvpx
|
||||||
|
ninja
|
||||||
pkg-config
|
pkg-config
|
||||||
|
|
||||||
run: |
|
run: |
|
||||||
@ -138,7 +139,8 @@ jobs:
|
|||||||
-DNON_HERMETIC_TESTS=ON \
|
-DNON_HERMETIC_TESTS=ON \
|
||||||
-DTEST_TIMEOUT_SECONDS=90 \
|
-DTEST_TIMEOUT_SECONDS=90 \
|
||||||
-DUSE_IPV6=OFF \
|
-DUSE_IPV6=OFF \
|
||||||
-DAUTOTEST=ON
|
-DAUTOTEST=ON \
|
||||||
|
-GNinja
|
||||||
cmake --build . --target install
|
cmake --build . --target install
|
||||||
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6
|
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6
|
||||||
|
|
||||||
@ -163,6 +165,7 @@ jobs:
|
|||||||
libconfig
|
libconfig
|
||||||
libsodium
|
libsodium
|
||||||
libvpx
|
libvpx
|
||||||
|
ninja
|
||||||
opus
|
opus
|
||||||
pkgconf
|
pkgconf
|
||||||
|
|
||||||
@ -175,7 +178,8 @@ jobs:
|
|||||||
-DNON_HERMETIC_TESTS=ON \
|
-DNON_HERMETIC_TESTS=ON \
|
||||||
-DTEST_TIMEOUT_SECONDS=50 \
|
-DTEST_TIMEOUT_SECONDS=50 \
|
||||||
-DUSE_IPV6=OFF \
|
-DUSE_IPV6=OFF \
|
||||||
-DAUTOTEST=ON
|
-DAUTOTEST=ON \
|
||||||
|
-GNinja
|
||||||
cmake --build . --target install
|
cmake --build . --target install
|
||||||
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6
|
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6
|
||||||
|
|
||||||
|
1
external/toxcore/c-toxcore/.gitignore
vendored
1
external/toxcore/c-toxcore/.gitignore
vendored
@ -36,6 +36,7 @@ testing/data
|
|||||||
|
|
||||||
# Vim
|
# Vim
|
||||||
*.swp
|
*.swp
|
||||||
|
*.nvimlog
|
||||||
|
|
||||||
# Object files
|
# Object files
|
||||||
*.o
|
*.o
|
||||||
|
6
external/toxcore/c-toxcore/BUILD.bazel
vendored
6
external/toxcore/c-toxcore/BUILD.bazel
vendored
@ -8,18 +8,24 @@ genrule(
|
|||||||
srcs = [
|
srcs = [
|
||||||
"//c-toxcore/toxav:toxav.h",
|
"//c-toxcore/toxav:toxav.h",
|
||||||
"//c-toxcore/toxcore:tox.h",
|
"//c-toxcore/toxcore:tox.h",
|
||||||
|
"//c-toxcore/toxcore:tox_dispatch.h",
|
||||||
|
"//c-toxcore/toxcore:tox_events.h",
|
||||||
"//c-toxcore/toxcore:tox_private.h",
|
"//c-toxcore/toxcore:tox_private.h",
|
||||||
"//c-toxcore/toxencryptsave:toxencryptsave.h",
|
"//c-toxcore/toxencryptsave:toxencryptsave.h",
|
||||||
],
|
],
|
||||||
outs = [
|
outs = [
|
||||||
"tox/toxav.h",
|
"tox/toxav.h",
|
||||||
"tox/tox.h",
|
"tox/tox.h",
|
||||||
|
"tox/tox_dispatch.h",
|
||||||
|
"tox/tox_events.h",
|
||||||
"tox/tox_private.h",
|
"tox/tox_private.h",
|
||||||
"tox/toxencryptsave.h",
|
"tox/toxencryptsave.h",
|
||||||
],
|
],
|
||||||
cmd = """
|
cmd = """
|
||||||
cp $(location //c-toxcore/toxav:toxav.h) $(GENDIR)/c-toxcore/tox/toxav.h
|
cp $(location //c-toxcore/toxav:toxav.h) $(GENDIR)/c-toxcore/tox/toxav.h
|
||||||
cp $(location //c-toxcore/toxcore:tox.h) $(GENDIR)/c-toxcore/tox/tox.h
|
cp $(location //c-toxcore/toxcore:tox.h) $(GENDIR)/c-toxcore/tox/tox.h
|
||||||
|
cp $(location //c-toxcore/toxcore:tox_dispatch.h) $(GENDIR)/c-toxcore/tox/tox_dispatch.h
|
||||||
|
cp $(location //c-toxcore/toxcore:tox_events.h) $(GENDIR)/c-toxcore/tox/tox_events.h
|
||||||
cp $(location //c-toxcore/toxcore:tox_private.h) $(GENDIR)/c-toxcore/tox/tox_private.h
|
cp $(location //c-toxcore/toxcore:tox_private.h) $(GENDIR)/c-toxcore/tox/tox_private.h
|
||||||
cp $(location //c-toxcore/toxencryptsave:toxencryptsave.h) $(GENDIR)/c-toxcore/tox/toxencryptsave.h
|
cp $(location //c-toxcore/toxencryptsave:toxencryptsave.h) $(GENDIR)/c-toxcore/tox/toxencryptsave.h
|
||||||
""",
|
""",
|
||||||
|
2
external/toxcore/c-toxcore/CMakeLists.txt
vendored
2
external/toxcore/c-toxcore/CMakeLists.txt
vendored
@ -309,6 +309,8 @@ set(toxcore_SOURCES
|
|||||||
toxcore/mono_time.h
|
toxcore/mono_time.h
|
||||||
toxcore/net_crypto.c
|
toxcore/net_crypto.c
|
||||||
toxcore/net_crypto.h
|
toxcore/net_crypto.h
|
||||||
|
toxcore/net_profile.c
|
||||||
|
toxcore/net_profile.h
|
||||||
toxcore/network.c
|
toxcore/network.c
|
||||||
toxcore/network.h
|
toxcore/network.h
|
||||||
toxcore/onion_announce.c
|
toxcore/onion_announce.c
|
||||||
|
@ -71,6 +71,7 @@ auto_test(invalid_udp_proxy)
|
|||||||
auto_test(lan_discovery)
|
auto_test(lan_discovery)
|
||||||
auto_test(lossless_packet)
|
auto_test(lossless_packet)
|
||||||
auto_test(lossy_packet)
|
auto_test(lossy_packet)
|
||||||
|
auto_test(netprof)
|
||||||
auto_test(network)
|
auto_test(network)
|
||||||
auto_test(onion)
|
auto_test(onion)
|
||||||
auto_test(overflow_recvq)
|
auto_test(overflow_recvq)
|
||||||
|
54
external/toxcore/c-toxcore/auto_tests/TCP_test.c
vendored
54
external/toxcore/c-toxcore/auto_tests/TCP_test.c
vendored
@ -8,7 +8,7 @@
|
|||||||
#include "../toxcore/TCP_server.h"
|
#include "../toxcore/TCP_server.h"
|
||||||
#include "../toxcore/crypto_core.h"
|
#include "../toxcore/crypto_core.h"
|
||||||
#include "../toxcore/mono_time.h"
|
#include "../toxcore/mono_time.h"
|
||||||
#include "../toxcore/util.h"
|
#include "../toxcore/network.h"
|
||||||
#include "auto_test_support.h"
|
#include "auto_test_support.h"
|
||||||
|
|
||||||
#define NUM_PORTS 3
|
#define NUM_PORTS 3
|
||||||
@ -74,8 +74,9 @@ static void test_basic(void)
|
|||||||
for (uint8_t i = 0; i < NUM_PORTS; i++) {
|
for (uint8_t i = 0; i < NUM_PORTS; i++) {
|
||||||
sock = net_socket(ns, net_family_ipv6(), TOX_SOCK_STREAM, TOX_PROTO_TCP);
|
sock = net_socket(ns, net_family_ipv6(), TOX_SOCK_STREAM, TOX_PROTO_TCP);
|
||||||
localhost.port = net_htons(ports[i]);
|
localhost.port = net_htons(ports[i]);
|
||||||
bool ret = net_connect(ns, mem, logger, sock, &localhost);
|
Net_Err_Connect err;
|
||||||
ck_assert_msg(ret, "Failed to connect to created TCP relay server on port %d (%d).", ports[i], errno);
|
bool ret = net_connect(ns, mem, logger, sock, &localhost, &err);
|
||||||
|
ck_assert_msg(ret, "Failed to connect to created TCP relay server on port %d (%d, %s).", ports[i], errno, net_err_connect_to_string(err));
|
||||||
|
|
||||||
// Leave open one connection for the next test.
|
// Leave open one connection for the next test.
|
||||||
if (i + 1 < NUM_PORTS) {
|
if (i + 1 < NUM_PORTS) {
|
||||||
@ -111,12 +112,12 @@ static void test_basic(void)
|
|||||||
|
|
||||||
// Sending the handshake
|
// Sending the handshake
|
||||||
ck_assert_msg(net_send(ns, logger, sock, handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
ck_assert_msg(net_send(ns, logger, sock, handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
||||||
&localhost) == TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
&localhost, nullptr) == TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
||||||
"An attempt to send the initial handshake minus last byte failed.");
|
"An attempt to send the initial handshake minus last byte failed.");
|
||||||
|
|
||||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||||
|
|
||||||
ck_assert_msg(net_send(ns, logger, sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, &localhost) == 1,
|
ck_assert_msg(net_send(ns, logger, sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, &localhost, nullptr) == 1,
|
||||||
"The attempt to send the last byte of handshake failed.");
|
"The attempt to send the last byte of handshake failed.");
|
||||||
|
|
||||||
free(handshake);
|
free(handshake);
|
||||||
@ -155,7 +156,7 @@ static void test_basic(void)
|
|||||||
msg_length = sizeof(r_req) - i;
|
msg_length = sizeof(r_req) - i;
|
||||||
}
|
}
|
||||||
|
|
||||||
ck_assert_msg(net_send(ns, logger, sock, r_req + i, msg_length, &localhost) == msg_length,
|
ck_assert_msg(net_send(ns, logger, sock, r_req + i, msg_length, &localhost, nullptr) == msg_length,
|
||||||
"Failed to send request after completing the handshake.");
|
"Failed to send request after completing the handshake.");
|
||||||
i += msg_length;
|
i += msg_length;
|
||||||
|
|
||||||
@ -165,7 +166,9 @@ static void test_basic(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Receiving the second response and verifying its validity
|
// Receiving the second response and verifying its validity
|
||||||
uint8_t packet_resp[4096];
|
const size_t max_packet_size = 4096;
|
||||||
|
uint8_t *packet_resp = (uint8_t *)malloc(max_packet_size);
|
||||||
|
ck_assert(packet_resp != nullptr);
|
||||||
int recv_data_len = net_recv(ns, logger, sock, packet_resp, 2 + 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE, &localhost);
|
int recv_data_len = net_recv(ns, logger, sock, packet_resp, 2 + 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE, &localhost);
|
||||||
ck_assert_msg(recv_data_len == 2 + 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE,
|
ck_assert_msg(recv_data_len == 2 + 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE,
|
||||||
"Failed to receive server response to request. %d", recv_data_len);
|
"Failed to receive server response to request. %d", recv_data_len);
|
||||||
@ -173,7 +176,8 @@ static void test_basic(void)
|
|||||||
ck_assert_msg(net_ntohs(size) == 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE,
|
ck_assert_msg(net_ntohs(size) == 2 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE,
|
||||||
"Wrong packet size for request response.");
|
"Wrong packet size for request response.");
|
||||||
|
|
||||||
uint8_t packet_resp_plain[4096];
|
uint8_t *packet_resp_plain = (uint8_t *)malloc(max_packet_size);
|
||||||
|
ck_assert(packet_resp_plain != nullptr);
|
||||||
ret = decrypt_data_symmetric(mem, f_shared_key, f_nonce_r, packet_resp + 2, recv_data_len - 2, packet_resp_plain);
|
ret = decrypt_data_symmetric(mem, f_shared_key, f_nonce_r, packet_resp + 2, recv_data_len - 2, packet_resp_plain);
|
||||||
ck_assert_msg(ret != -1, "Failed to decrypt the TCP server's response.");
|
ck_assert_msg(ret != -1, "Failed to decrypt the TCP server's response.");
|
||||||
increment_nonce(f_nonce_r);
|
increment_nonce(f_nonce_r);
|
||||||
@ -183,6 +187,9 @@ static void test_basic(void)
|
|||||||
ck_assert_msg(packet_resp_plain[1] == 0, "Server did not refuse the connection.");
|
ck_assert_msg(packet_resp_plain[1] == 0, "Server did not refuse the connection.");
|
||||||
ck_assert_msg(pk_equal(packet_resp_plain + 2, f_public_key), "Server sent the wrong public key.");
|
ck_assert_msg(pk_equal(packet_resp_plain + 2, f_public_key), "Server sent the wrong public key.");
|
||||||
|
|
||||||
|
free(packet_resp_plain);
|
||||||
|
free(packet_resp);
|
||||||
|
|
||||||
// Closing connections.
|
// Closing connections.
|
||||||
kill_sock(ns, sock);
|
kill_sock(ns, sock);
|
||||||
kill_tcp_server(tcp_s);
|
kill_tcp_server(tcp_s);
|
||||||
@ -213,8 +220,9 @@ static struct sec_TCP_con *new_tcp_con(const Logger *logger, const Memory *mem,
|
|||||||
localhost.ip = get_loopback();
|
localhost.ip = get_loopback();
|
||||||
localhost.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
localhost.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
||||||
|
|
||||||
bool ok = net_connect(ns, mem, logger, sock, &localhost);
|
Net_Err_Connect err;
|
||||||
ck_assert_msg(ok, "Failed to connect to the test TCP relay server.");
|
bool ok = net_connect(ns, mem, logger, sock, &localhost, &err);
|
||||||
|
ck_assert_msg(ok, "Failed to connect to the test TCP relay server: %s.", net_err_connect_to_string(err));
|
||||||
|
|
||||||
uint8_t f_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
uint8_t f_secret_key[CRYPTO_SECRET_KEY_SIZE];
|
||||||
crypto_new_keypair(rng, sec_c->public_key, f_secret_key);
|
crypto_new_keypair(rng, sec_c->public_key, f_secret_key);
|
||||||
@ -234,12 +242,12 @@ static struct sec_TCP_con *new_tcp_con(const Logger *logger, const Memory *mem,
|
|||||||
"Failed to encrypt the outgoing handshake.");
|
"Failed to encrypt the outgoing handshake.");
|
||||||
|
|
||||||
ck_assert_msg(net_send(ns, logger, sock, handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
ck_assert_msg(net_send(ns, logger, sock, handshake, TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
||||||
&localhost) == TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
&localhost, nullptr) == TCP_CLIENT_HANDSHAKE_SIZE - 1,
|
||||||
"Failed to send the first portion of the handshake to the TCP relay server.");
|
"Failed to send the first portion of the handshake to the TCP relay server.");
|
||||||
|
|
||||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||||
|
|
||||||
ck_assert_msg(net_send(ns, logger, sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, &localhost) == 1,
|
ck_assert_msg(net_send(ns, logger, sock, handshake + (TCP_CLIENT_HANDSHAKE_SIZE - 1), 1, &localhost, nullptr) == 1,
|
||||||
"Failed to send last byte of handshake.");
|
"Failed to send last byte of handshake.");
|
||||||
|
|
||||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||||
@ -283,7 +291,7 @@ static int write_packet_tcp_test_connection(const Logger *logger, struct sec_TCP
|
|||||||
localhost.ip = get_loopback();
|
localhost.ip = get_loopback();
|
||||||
localhost.port = 0;
|
localhost.port = 0;
|
||||||
|
|
||||||
ck_assert_msg(net_send(con->ns, logger, con->sock, packet, packet_size, &localhost) == packet_size,
|
ck_assert_msg(net_send(con->ns, logger, con->sock, packet, packet_size, &localhost, nullptr) == packet_size,
|
||||||
"Failed to send a packet.");
|
"Failed to send a packet.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -337,7 +345,8 @@ static void test_some(void)
|
|||||||
do_tcp_server_delay(tcp_s, mono_time, 50);
|
do_tcp_server_delay(tcp_s, mono_time, 50);
|
||||||
|
|
||||||
// Testing response from connection 1
|
// Testing response from connection 1
|
||||||
uint8_t data[2048];
|
const size_t max_packet_size = 4096;
|
||||||
|
uint8_t *data = (uint8_t *)malloc(max_packet_size);
|
||||||
int len = read_packet_sec_tcp(logger, con1, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE);
|
int len = read_packet_sec_tcp(logger, con1, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE);
|
||||||
ck_assert_msg(len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE, "Wrong response packet length of %d.", len);
|
ck_assert_msg(len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE, "Wrong response packet length of %d.", len);
|
||||||
ck_assert_msg(data[0] == TCP_PACKET_ROUTING_RESPONSE, "Wrong response packet id of %d.", data[0]);
|
ck_assert_msg(data[0] == TCP_PACKET_ROUTING_RESPONSE, "Wrong response packet id of %d.", data[0]);
|
||||||
@ -351,7 +360,7 @@ static void test_some(void)
|
|||||||
ck_assert_msg(data[1] == 16, "Server didn't refuse connection using wrong public key.");
|
ck_assert_msg(data[1] == 16, "Server didn't refuse connection using wrong public key.");
|
||||||
ck_assert_msg(pk_equal(data + 2, con1->public_key), "Key in response packet wrong.");
|
ck_assert_msg(pk_equal(data + 2, con1->public_key), "Key in response packet wrong.");
|
||||||
|
|
||||||
uint8_t test_packet[512] = {16, 17, 16, 86, 99, 127, 255, 189, 78}; // What is this packet????
|
const uint8_t test_packet[512] = {16, 17, 16, 86, 99, 127, 255, 189, 78}; // What is this packet????
|
||||||
|
|
||||||
write_packet_tcp_test_connection(logger, con3, test_packet, sizeof(test_packet));
|
write_packet_tcp_test_connection(logger, con3, test_packet, sizeof(test_packet));
|
||||||
write_packet_tcp_test_connection(logger, con3, test_packet, sizeof(test_packet));
|
write_packet_tcp_test_connection(logger, con3, test_packet, sizeof(test_packet));
|
||||||
@ -406,6 +415,8 @@ static void test_some(void)
|
|||||||
ck_assert_msg(data[0] == TCP_PACKET_PONG, "wrong packet id %u", data[0]);
|
ck_assert_msg(data[0] == TCP_PACKET_PONG, "wrong packet id %u", data[0]);
|
||||||
ck_assert_msg(memcmp(ping_packet + 1, data + 1, sizeof(uint64_t)) == 0, "wrong packet data");
|
ck_assert_msg(memcmp(ping_packet + 1, data + 1, sizeof(uint64_t)) == 0, "wrong packet data");
|
||||||
|
|
||||||
|
free(data);
|
||||||
|
|
||||||
// Kill off the connections
|
// Kill off the connections
|
||||||
kill_tcp_server(tcp_s);
|
kill_tcp_server(tcp_s);
|
||||||
kill_tcp_con(con1);
|
kill_tcp_con(con1);
|
||||||
@ -524,7 +535,8 @@ static void test_client(void)
|
|||||||
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
||||||
ip_port_tcp_s.ip = get_loopback();
|
ip_port_tcp_s.ip = get_loopback();
|
||||||
|
|
||||||
TCP_Client_Connection *conn = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr);
|
TCP_Client_Connection *conn = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr, nullptr);
|
||||||
|
ck_assert_msg(conn != nullptr, "Failed to create a TCP client connection.");
|
||||||
// TCP sockets might need a moment before they can be written to.
|
// TCP sockets might need a moment before they can be written to.
|
||||||
c_sleep(50);
|
c_sleep(50);
|
||||||
do_tcp_connection(logger, mono_time, conn, nullptr);
|
do_tcp_connection(logger, mono_time, conn, nullptr);
|
||||||
@ -560,7 +572,8 @@ static void test_client(void)
|
|||||||
crypto_new_keypair(rng, f2_public_key, f2_secret_key);
|
crypto_new_keypair(rng, f2_public_key, f2_secret_key);
|
||||||
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
||||||
TCP_Client_Connection *conn2 = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f2_public_key,
|
TCP_Client_Connection *conn2 = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s, self_public_key, f2_public_key,
|
||||||
f2_secret_key, nullptr);
|
f2_secret_key, nullptr, nullptr);
|
||||||
|
ck_assert_msg(conn2 != nullptr, "Failed to create a second TCP client connection.");
|
||||||
c_sleep(50);
|
c_sleep(50);
|
||||||
|
|
||||||
// The client should call this function (defined earlier) during the routing process.
|
// The client should call this function (defined earlier) during the routing process.
|
||||||
@ -657,7 +670,8 @@ static void test_client_invalid(void)
|
|||||||
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
ip_port_tcp_s.port = net_htons(ports[random_u32(rng) % NUM_PORTS]);
|
||||||
ip_port_tcp_s.ip = get_loopback();
|
ip_port_tcp_s.ip = get_loopback();
|
||||||
TCP_Client_Connection *conn = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s,
|
TCP_Client_Connection *conn = new_tcp_connection(logger, mem, mono_time, rng, ns, &ip_port_tcp_s,
|
||||||
self_public_key, f_public_key, f_secret_key, nullptr);
|
self_public_key, f_public_key, f_secret_key, nullptr, nullptr);
|
||||||
|
ck_assert_msg(conn != nullptr, "Failed to create a TCP client connection.");
|
||||||
|
|
||||||
// Run the client's main loop but not the server.
|
// Run the client's main loop but not the server.
|
||||||
mono_time_update(mono_time);
|
mono_time_update(mono_time);
|
||||||
@ -734,10 +748,12 @@ static void test_tcp_connection(void)
|
|||||||
proxy_info.proxy_type = TCP_PROXY_NONE;
|
proxy_info.proxy_type = TCP_PROXY_NONE;
|
||||||
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
||||||
TCP_Connections *tc_1 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
|
TCP_Connections *tc_1 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
|
||||||
|
ck_assert_msg(tc_1 != nullptr, "Failed to create TCP connections");
|
||||||
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_1), self_public_key), "Wrong public key");
|
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_1), self_public_key), "Wrong public key");
|
||||||
|
|
||||||
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
||||||
TCP_Connections *tc_2 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
|
TCP_Connections *tc_2 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
|
||||||
|
ck_assert_msg(tc_2 != nullptr, "Failed to create TCP connections");
|
||||||
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_2), self_public_key), "Wrong public key");
|
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_2), self_public_key), "Wrong public key");
|
||||||
|
|
||||||
IP_Port ip_port_tcp_s;
|
IP_Port ip_port_tcp_s;
|
||||||
@ -849,10 +865,12 @@ static void test_tcp_connection2(void)
|
|||||||
proxy_info.proxy_type = TCP_PROXY_NONE;
|
proxy_info.proxy_type = TCP_PROXY_NONE;
|
||||||
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
||||||
TCP_Connections *tc_1 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
|
TCP_Connections *tc_1 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
|
||||||
|
ck_assert_msg(tc_1 != nullptr, "Failed to create TCP connections");
|
||||||
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_1), self_public_key), "Wrong public key");
|
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_1), self_public_key), "Wrong public key");
|
||||||
|
|
||||||
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
crypto_new_keypair(rng, self_public_key, self_secret_key);
|
||||||
TCP_Connections *tc_2 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
|
TCP_Connections *tc_2 = new_tcp_connections(logger, mem, rng, ns, mono_time, self_secret_key, &proxy_info);
|
||||||
|
ck_assert_msg(tc_2 != nullptr, "Failed to create TCP connections");
|
||||||
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_2), self_public_key), "Wrong public key");
|
ck_assert_msg(pk_equal(tcp_connections_public_key(tc_2), self_public_key), "Wrong public key");
|
||||||
|
|
||||||
IP_Port ip_port_tcp_s;
|
IP_Port ip_port_tcp_s;
|
||||||
|
@ -66,7 +66,7 @@ static void test_store_data(void)
|
|||||||
ck_assert(net != nullptr);
|
ck_assert(net != nullptr);
|
||||||
DHT *dht = new_dht(log, mem, rng, ns, mono_time, net, true, true);
|
DHT *dht = new_dht(log, mem, rng, ns, mono_time, net, true, true);
|
||||||
ck_assert(dht != nullptr);
|
ck_assert(dht != nullptr);
|
||||||
Forwarding *forwarding = new_forwarding(log, rng, mono_time, dht);
|
Forwarding *forwarding = new_forwarding(log, mem, rng, mono_time, dht);
|
||||||
ck_assert(forwarding != nullptr);
|
ck_assert(forwarding != nullptr);
|
||||||
Announcements *announce = new_announcements(log, mem, rng, mono_time, forwarding);
|
Announcements *announce = new_announcements(log, mem, rng, mono_time, forwarding);
|
||||||
ck_assert(announce != nullptr);
|
ck_assert(announce != nullptr);
|
||||||
|
@ -444,9 +444,9 @@ void print_debug_log(Tox *m, Tox_Log_Level level, const char *file, uint32_t lin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_debug_logger(void *context, Logger_Level level, const char *file, int line, const char *func, const char *message, void *userdata)
|
void print_debug_logger(void *context, Logger_Level level, const char *file, uint32_t line, const char *func, const char *message, void *userdata)
|
||||||
{
|
{
|
||||||
print_debug_log(nullptr, (Tox_Log_Level) level, file, (uint32_t) line, func, message, userdata);
|
print_debug_log(nullptr, (Tox_Log_Level) level, file, line, func, message, userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tox *tox_new_log_lan(struct Tox_Options *options, Tox_Err_New *err, void *log_user_data, bool lan_discovery)
|
Tox *tox_new_log_lan(struct Tox_Options *options, Tox_Err_New *err, void *log_user_data, bool lan_discovery)
|
||||||
|
@ -60,7 +60,7 @@ void print_debug_log(Tox *m, Tox_Log_Level level, const char *file, uint32_t lin
|
|||||||
const char *message, void *user_data);
|
const char *message, void *user_data);
|
||||||
|
|
||||||
// Use this function when setting the log callback on a Logger object
|
// Use this function when setting the log callback on a Logger object
|
||||||
void print_debug_logger(void *context, Logger_Level level, const char *file, int line,
|
void print_debug_logger(void *context, Logger_Level level, const char *file, uint32_t line,
|
||||||
const char *func, const char *message, void *userdata);
|
const char *func, const char *message, void *userdata);
|
||||||
|
|
||||||
Tox *tox_new_log(struct Tox_Options *options, Tox_Err_New *err, void *log_user_data);
|
Tox *tox_new_log(struct Tox_Options *options, Tox_Err_New *err, void *log_user_data);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2016 Tox project.
|
* Copyright © 2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ static Forwarding_Subtox *new_forwarding_subtox(const Memory *mem, bool no_udp,
|
|||||||
const TCP_Proxy_Info inf = {{{{0}}}};
|
const TCP_Proxy_Info inf = {{{{0}}}};
|
||||||
subtox->c = new_net_crypto(subtox->log, mem, rng, ns, subtox->mono_time, subtox->dht, &inf);
|
subtox->c = new_net_crypto(subtox->log, mem, rng, ns, subtox->mono_time, subtox->dht, &inf);
|
||||||
|
|
||||||
subtox->forwarding = new_forwarding(subtox->log, rng, subtox->mono_time, subtox->dht);
|
subtox->forwarding = new_forwarding(subtox->log, mem, rng, subtox->mono_time, subtox->dht);
|
||||||
ck_assert(subtox->forwarding != nullptr);
|
ck_assert(subtox->forwarding != nullptr);
|
||||||
|
|
||||||
subtox->announce = new_announcements(subtox->log, mem, rng, subtox->mono_time, subtox->forwarding);
|
subtox->announce = new_announcements(subtox->log, mem, rng, subtox->mono_time, subtox->forwarding);
|
||||||
|
@ -392,9 +392,9 @@ static void group_announce_test(AutoTox *autotoxes)
|
|||||||
ck_assert(s_err == TOX_ERR_GROUP_SELF_STATUS_SET_OK);
|
ck_assert(s_err == TOX_ERR_GROUP_SELF_STATUS_SET_OK);
|
||||||
|
|
||||||
fprintf(stderr, "Peer 0 reconnecting...\n");
|
fprintf(stderr, "Peer 0 reconnecting...\n");
|
||||||
Tox_Err_Group_Reconnect r_err;
|
Tox_Err_Group_Join err_rejoin;
|
||||||
tox_group_reconnect(tox0, groupnumber, &r_err);
|
tox_group_join(tox0, chat_id, (const uint8_t *)PEER0_NICK, PEER0_NICK_LEN, nullptr, 0, &err_rejoin);
|
||||||
ck_assert(r_err == TOX_ERR_GROUP_RECONNECT_OK);
|
ck_assert(err_rejoin == TOX_ERR_GROUP_JOIN_OK);
|
||||||
|
|
||||||
while (state1->peer_joined_count != 2 && state0->self_joined_count == 2) {
|
while (state1->peer_joined_count != 2 && state0->self_joined_count == 2) {
|
||||||
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
|
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
|
||||||
|
134
external/toxcore/c-toxcore/auto_tests/netprof_test.c
vendored
Normal file
134
external/toxcore/c-toxcore/auto_tests/netprof_test.c
vendored
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
/** Auto Tests: basic network profile functionality test (UDP only)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "../toxcore/tox_private.h"
|
||||||
|
#include "../toxcore/util.h"
|
||||||
|
|
||||||
|
#include "auto_test_support.h"
|
||||||
|
#include "check_compat.h"
|
||||||
|
|
||||||
|
#define NUM_TOXES 2
|
||||||
|
|
||||||
|
static void test_netprof(AutoTox *autotoxes)
|
||||||
|
{
|
||||||
|
// Send some messages to create fake traffic
|
||||||
|
for (size_t i = 0; i < 256; ++i) {
|
||||||
|
for (uint32_t j = 0; j < NUM_TOXES; ++j) {
|
||||||
|
tox_friend_send_message(autotoxes[j].tox, 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"test", 4, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
iterate_all_wait(autotoxes, NUM_TOXES, ITERATION_INTERVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// idle traffic for a while
|
||||||
|
for (size_t i = 0; i < 100; ++i) {
|
||||||
|
iterate_all_wait(autotoxes, NUM_TOXES, ITERATION_INTERVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Tox *tox1 = autotoxes[0].tox;
|
||||||
|
|
||||||
|
const uint64_t UDP_count_sent1 = tox_netprof_get_packet_total_count(tox1, TOX_NETPROF_PACKET_TYPE_UDP,
|
||||||
|
TOX_NETPROF_DIRECTION_SENT);
|
||||||
|
const uint64_t UDP_count_recv1 = tox_netprof_get_packet_total_count(tox1, TOX_NETPROF_PACKET_TYPE_UDP,
|
||||||
|
TOX_NETPROF_DIRECTION_RECV);
|
||||||
|
const uint64_t TCP_count_sent1 = tox_netprof_get_packet_total_count(tox1, TOX_NETPROF_PACKET_TYPE_TCP,
|
||||||
|
TOX_NETPROF_DIRECTION_SENT);
|
||||||
|
const uint64_t TCP_count_recv1 = tox_netprof_get_packet_total_count(tox1, TOX_NETPROF_PACKET_TYPE_TCP,
|
||||||
|
TOX_NETPROF_DIRECTION_RECV);
|
||||||
|
|
||||||
|
const uint64_t UDP_bytes_sent1 = tox_netprof_get_packet_total_bytes(tox1, TOX_NETPROF_PACKET_TYPE_UDP,
|
||||||
|
TOX_NETPROF_DIRECTION_SENT);
|
||||||
|
const uint64_t UDP_bytes_recv1 = tox_netprof_get_packet_total_bytes(tox1, TOX_NETPROF_PACKET_TYPE_UDP,
|
||||||
|
TOX_NETPROF_DIRECTION_RECV);
|
||||||
|
const uint64_t TCP_bytes_sent1 = tox_netprof_get_packet_total_bytes(tox1, TOX_NETPROF_PACKET_TYPE_TCP,
|
||||||
|
TOX_NETPROF_DIRECTION_SENT);
|
||||||
|
const uint64_t TCP_bytes_recv1 = tox_netprof_get_packet_total_bytes(tox1, TOX_NETPROF_PACKET_TYPE_TCP,
|
||||||
|
TOX_NETPROF_DIRECTION_RECV);
|
||||||
|
|
||||||
|
ck_assert(UDP_count_recv1 > 0 && UDP_count_sent1 > 0);
|
||||||
|
ck_assert(UDP_bytes_recv1 > 0 && UDP_bytes_sent1 > 0);
|
||||||
|
|
||||||
|
(void)TCP_count_sent1;
|
||||||
|
(void)TCP_bytes_sent1;
|
||||||
|
(void)TCP_bytes_recv1;
|
||||||
|
(void)TCP_count_recv1;
|
||||||
|
|
||||||
|
uint64_t total_sent_count = 0;
|
||||||
|
uint64_t total_recv_count = 0;
|
||||||
|
uint64_t total_sent_bytes = 0;
|
||||||
|
uint64_t total_recv_bytes = 0;
|
||||||
|
|
||||||
|
// tox1 makes sure the sum value of all packet ID's is equal to the totals
|
||||||
|
for (size_t i = 0; i < 256; ++i) {
|
||||||
|
// this id isn't valid for UDP packets but we still want to call the
|
||||||
|
// functions and make sure they return some non-zero value
|
||||||
|
if (i == TOX_NETPROF_PACKET_ID_TCP_DATA) {
|
||||||
|
ck_assert(tox_netprof_get_packet_id_count(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||||
|
TOX_NETPROF_DIRECTION_SENT) > 0);
|
||||||
|
ck_assert(tox_netprof_get_packet_id_bytes(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||||
|
TOX_NETPROF_DIRECTION_SENT) > 0);
|
||||||
|
ck_assert(tox_netprof_get_packet_id_bytes(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||||
|
TOX_NETPROF_DIRECTION_SENT) > 0);
|
||||||
|
ck_assert(tox_netprof_get_packet_id_bytes(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||||
|
TOX_NETPROF_DIRECTION_RECV) > 0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
total_sent_count += tox_netprof_get_packet_id_count(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||||
|
TOX_NETPROF_DIRECTION_SENT);
|
||||||
|
total_recv_count += tox_netprof_get_packet_id_count(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||||
|
TOX_NETPROF_DIRECTION_RECV);
|
||||||
|
|
||||||
|
total_sent_bytes += tox_netprof_get_packet_id_bytes(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||||
|
TOX_NETPROF_DIRECTION_SENT);
|
||||||
|
total_recv_bytes += tox_netprof_get_packet_id_bytes(tox1, TOX_NETPROF_PACKET_TYPE_UDP, i,
|
||||||
|
TOX_NETPROF_DIRECTION_RECV);
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint64_t total_packets = total_sent_count + total_recv_count;
|
||||||
|
ck_assert_msg(total_packets == UDP_count_sent1 + UDP_count_recv1,
|
||||||
|
"%" PRIu64 "does not match %" PRIu64 "\n", total_packets, UDP_count_sent1 + UDP_count_recv1);
|
||||||
|
|
||||||
|
ck_assert_msg(total_sent_count == UDP_count_sent1, "%" PRIu64 " does not match %" PRIu64 "\n", total_sent_count, UDP_count_sent1);
|
||||||
|
ck_assert_msg(total_recv_count == UDP_count_recv1, "%" PRIu64 " does not match %" PRIu64"\n", total_recv_count, UDP_count_recv1);
|
||||||
|
|
||||||
|
|
||||||
|
const uint64_t total_bytes = total_sent_bytes + total_recv_bytes;
|
||||||
|
ck_assert_msg(total_bytes == UDP_bytes_sent1 + UDP_bytes_recv1,
|
||||||
|
"%" PRIu64 "does not match %" PRIu64 "\n", total_bytes, UDP_bytes_sent1 + UDP_bytes_recv1);
|
||||||
|
|
||||||
|
ck_assert_msg(total_sent_bytes == UDP_bytes_sent1, "%" PRIu64 " does not match %" PRIu64 "\n", total_sent_bytes, UDP_bytes_sent1);
|
||||||
|
ck_assert_msg(total_recv_bytes == UDP_bytes_recv1, "%" PRIu64 " does not match %" PRIu64 "\n", total_recv_bytes, UDP_bytes_recv1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
tox_options_default(tox_opts);
|
||||||
|
tox_options_set_udp_enabled(tox_opts, true);
|
||||||
|
|
||||||
|
Run_Auto_Options autotox_opts = default_run_auto_options();
|
||||||
|
autotox_opts.graph = GRAPH_COMPLETE;
|
||||||
|
|
||||||
|
run_auto_test(tox_opts, NUM_TOXES, test_netprof, 0, &autotox_opts);
|
||||||
|
|
||||||
|
// TODO(Jfreegman): uncomment this when TCP autotests are fixed
|
||||||
|
// tox_options_set_udp_enabled(tox_opts, false);
|
||||||
|
// run_auto_test(tox_opts, NUM_TOXES, test_netprof, 0, &autotox_opts);
|
||||||
|
|
||||||
|
tox_options_free(tox_opts);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef NUM_TOXES
|
@ -1,9 +1,9 @@
|
|||||||
/* Tests that we can send messages to friends.
|
/* Tests that we can send messages to friends.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "auto_test_support.h"
|
#include "auto_test_support.h"
|
||||||
|
|
||||||
|
@ -71,22 +71,22 @@ static uint8_t *read_save(const char *save_path, size_t *length)
|
|||||||
|
|
||||||
static void test_save_compatibility(const char *save_path)
|
static void test_save_compatibility(const char *save_path)
|
||||||
{
|
{
|
||||||
struct Tox_Options options = {0};
|
Tox_Options *options = tox_options_new(nullptr);
|
||||||
tox_options_default(&options);
|
ck_assert(options != nullptr);
|
||||||
|
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
uint8_t *save_data = read_save(save_path, &size);
|
uint8_t *save_data = read_save(save_path, &size);
|
||||||
ck_assert_msg(save_data != nullptr, "error while reading save file '%s'", save_path);
|
ck_assert_msg(save_data != nullptr, "error while reading save file '%s'", save_path);
|
||||||
|
|
||||||
options.savedata_data = save_data;
|
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
|
||||||
options.savedata_length = size;
|
tox_options_set_savedata_data(options, save_data, size);
|
||||||
options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE;
|
|
||||||
|
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
Tox_Err_New err;
|
Tox_Err_New err;
|
||||||
Tox *tox = tox_new_log(&options, &err, &index);
|
Tox *tox = tox_new_log(options, &err, &index);
|
||||||
ck_assert_msg(tox, "failed to create tox, error number: %d", err);
|
ck_assert_msg(tox, "failed to create tox, error number: %d", err);
|
||||||
|
|
||||||
|
tox_options_free(options);
|
||||||
free(save_data);
|
free(save_data);
|
||||||
|
|
||||||
const size_t name_size = tox_self_get_name_size(tox);
|
const size_t name_size = tox_self_get_name_size(tox);
|
||||||
@ -145,7 +145,10 @@ static bool is_little_endian(void)
|
|||||||
// cppcheck-suppress constParameter
|
// cppcheck-suppress constParameter
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char base_path[4096] = {0};
|
const size_t base_path_size = 4096;
|
||||||
|
char *base_path = (char *)malloc(base_path_size);
|
||||||
|
ck_assert(base_path != nullptr);
|
||||||
|
memset(base_path, 0, 4096);
|
||||||
|
|
||||||
if (argc <= 1) {
|
if (argc <= 1) {
|
||||||
const char *srcdir = getenv("srcdir");
|
const char *srcdir = getenv("srcdir");
|
||||||
@ -154,21 +157,29 @@ int main(int argc, char *argv[])
|
|||||||
srcdir = ".";
|
srcdir = ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(base_path, sizeof(base_path), "%s", srcdir);
|
snprintf(base_path, base_path_size, "%s", srcdir);
|
||||||
} else {
|
} else {
|
||||||
snprintf(base_path, sizeof(base_path), "%s", argv[1]);
|
snprintf(base_path, base_path_size, "%s", argv[1]);
|
||||||
base_path[strrchr(base_path, '/') - base_path] = '\0';
|
base_path[strrchr(base_path, '/') - base_path] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_little_endian()) {
|
if (is_little_endian()) {
|
||||||
char save_path[4096 + sizeof(LOADED_SAVE_FILE_LITTLE)];
|
const size_t save_path_size = 4096 + sizeof(LOADED_SAVE_FILE_LITTLE);
|
||||||
snprintf(save_path, sizeof(save_path), "%s/%s", base_path, LOADED_SAVE_FILE_LITTLE);
|
char *save_path = (char *)malloc(save_path_size);
|
||||||
|
ck_assert(save_path != nullptr);
|
||||||
|
snprintf(save_path, save_path_size, "%s/%s", base_path, LOADED_SAVE_FILE_LITTLE);
|
||||||
test_save_compatibility(save_path);
|
test_save_compatibility(save_path);
|
||||||
|
free(save_path);
|
||||||
} else {
|
} else {
|
||||||
char save_path[4096 + sizeof(LOADED_SAVE_FILE_BIG)];
|
const size_t save_path_size = 4096 + sizeof(LOADED_SAVE_FILE_BIG);
|
||||||
snprintf(save_path, sizeof(save_path), "%s/%s", base_path, LOADED_SAVE_FILE_BIG);
|
char *save_path = (char *)malloc(save_path_size);
|
||||||
|
ck_assert(save_path != nullptr);
|
||||||
|
snprintf(save_path, save_path_size, "%s/%s", base_path, LOADED_SAVE_FILE_BIG);
|
||||||
test_save_compatibility(save_path);
|
test_save_compatibility(save_path);
|
||||||
|
free(save_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(base_path);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,19 @@
|
|||||||
|
|
||||||
#include "auto_test_support.h"
|
#include "auto_test_support.h"
|
||||||
|
|
||||||
|
#ifndef USE_IPV6
|
||||||
|
#define USE_IPV6 1
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||||
|
|
||||||
struct Tox_Options *opts = tox_options_new(nullptr);
|
struct Tox_Options *opts = tox_options_new(nullptr);
|
||||||
tox_options_set_udp_enabled(opts, false);
|
tox_options_set_udp_enabled(opts, false);
|
||||||
|
#if !USE_IPV6
|
||||||
|
tox_options_set_ipv6_enabled(opts, false);
|
||||||
|
#endif
|
||||||
Tox *tox_tcp = tox_new_log(opts, nullptr, nullptr);
|
Tox *tox_tcp = tox_new_log(opts, nullptr, nullptr);
|
||||||
tox_options_free(opts);
|
tox_options_free(opts);
|
||||||
|
|
||||||
|
12
external/toxcore/c-toxcore/other/DHT_bootstrap.c
vendored
12
external/toxcore/c-toxcore/other/DHT_bootstrap.c
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -117,10 +117,10 @@ static const char *strlevel(Logger_Level level)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_log(void *context, Logger_Level level, const char *file, int line,
|
static void print_log(void *context, Logger_Level level, const char *file, uint32_t line,
|
||||||
const char *func, const char *message, void *userdata)
|
const char *func, const char *message, void *userdata)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "[%s] %s:%d(%s) %s\n", strlevel(level), file, line, func, message);
|
fprintf(stderr, "[%s] %s:%u(%s) %s\n", strlevel(level), file, line, func, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@ -159,8 +159,8 @@ int main(int argc, char *argv[])
|
|||||||
const uint16_t end_port = start_port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM);
|
const uint16_t end_port = start_port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM);
|
||||||
DHT *dht = new_dht(logger, mem, rng, ns, mono_time, new_networking_ex(logger, mem, ns, &ip, start_port, end_port, nullptr), true, true);
|
DHT *dht = new_dht(logger, mem, rng, ns, mono_time, new_networking_ex(logger, mem, ns, &ip, start_port, end_port, nullptr), true, true);
|
||||||
Onion *onion = new_onion(logger, mem, mono_time, rng, dht);
|
Onion *onion = new_onion(logger, mem, mono_time, rng, dht);
|
||||||
Forwarding *forwarding = new_forwarding(logger, rng, mono_time, dht);
|
Forwarding *forwarding = new_forwarding(logger, mem, rng, mono_time, dht);
|
||||||
GC_Announces_List *gc_announces_list = new_gca_list();
|
GC_Announces_List *gc_announces_list = new_gca_list(mem);
|
||||||
Onion_Announce *onion_a = new_onion_announce(logger, mem, rng, mono_time, dht);
|
Onion_Announce *onion_a = new_onion_announce(logger, mem, rng, mono_time, dht);
|
||||||
|
|
||||||
#ifdef DHT_NODE_EXTRA_PACKETS
|
#ifdef DHT_NODE_EXTRA_PACKETS
|
||||||
@ -245,7 +245,7 @@ int main(int argc, char *argv[])
|
|||||||
bool is_waiting_for_dht_connection = true;
|
bool is_waiting_for_dht_connection = true;
|
||||||
|
|
||||||
uint64_t last_lan_discovery = 0;
|
uint64_t last_lan_discovery = 0;
|
||||||
const Broadcast_Info *broadcast = lan_discovery_init(ns);
|
const Broadcast_Info *broadcast = lan_discovery_init(mem, ns);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
mono_time_update(mono_time);
|
mono_time_update(mono_time);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2024 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2015-2016 Tox project.
|
* Copyright © 2015-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2015-2016 Tox project.
|
* Copyright © 2015-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2024 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2014-2016 Tox project.
|
* Copyright © 2014-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2024 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2014-2016 Tox project.
|
* Copyright © 2014-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2024 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2014-2016 Tox project.
|
* Copyright © 2014-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2014-2016 Tox project.
|
* Copyright © 2014-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2015-2016 Tox project.
|
* Copyright © 2015-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2015-2016 Tox project.
|
* Copyright © 2015-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2015-2016 Tox project.
|
* Copyright © 2015-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2015-2016 Tox project.
|
* Copyright © 2015-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2015-2016 Tox project.
|
* Copyright © 2015-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2015-2016 Tox project.
|
* Copyright © 2015-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2024 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2014-2016 Tox project.
|
* Copyright © 2014-2016 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -200,10 +200,10 @@ static LOG_LEVEL logger_level_to_log_level(Logger_Level level)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void toxcore_logger_callback(void *context, Logger_Level level, const char *file, int line,
|
static void toxcore_logger_callback(void *context, Logger_Level level, const char *file, uint32_t line,
|
||||||
const char *func, const char *message, void *userdata)
|
const char *func, const char *message, void *userdata)
|
||||||
{
|
{
|
||||||
log_write(logger_level_to_log_level(level), "%s:%d(%s) %s\n", file, line, func, message);
|
log_write(logger_level_to_log_level(level), "%s:%u(%s) %s\n", file, line, func, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static volatile sig_atomic_t caught_signal = 0;
|
static volatile sig_atomic_t caught_signal = 0;
|
||||||
@ -348,7 +348,7 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Forwarding *forwarding = new_forwarding(logger, rng, mono_time, dht);
|
Forwarding *forwarding = new_forwarding(logger, mem, rng, mono_time, dht);
|
||||||
|
|
||||||
if (forwarding == nullptr) {
|
if (forwarding == nullptr) {
|
||||||
log_write(LOG_LEVEL_ERROR, "Couldn't initialize forwarding. Exiting.\n");
|
log_write(LOG_LEVEL_ERROR, "Couldn't initialize forwarding. Exiting.\n");
|
||||||
@ -377,7 +377,7 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
GC_Announces_List *group_announce = new_gca_list();
|
GC_Announces_List *group_announce = new_gca_list(mem);
|
||||||
|
|
||||||
if (group_announce == nullptr) {
|
if (group_announce == nullptr) {
|
||||||
log_write(LOG_LEVEL_ERROR, "Couldn't initialize group announces. Exiting.\n");
|
log_write(LOG_LEVEL_ERROR, "Couldn't initialize group announces. Exiting.\n");
|
||||||
@ -563,7 +563,7 @@ int main(int argc, char *argv[])
|
|||||||
Broadcast_Info *broadcast = nullptr;
|
Broadcast_Info *broadcast = nullptr;
|
||||||
|
|
||||||
if (enable_lan_discovery) {
|
if (enable_lan_discovery) {
|
||||||
broadcast = lan_discovery_init(ns);
|
broadcast = lan_discovery_init(mem, ns);
|
||||||
log_write(LOG_LEVEL_INFO, "Initialized LAN discovery successfully.\n");
|
log_write(LOG_LEVEL_INFO, "Initialized LAN discovery successfully.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module github.com/TokTok/c-toxcore/other/bootstrap_daemon/websocket/websockify
|
module github.com/TokTok/c-toxcore/other/bootstrap_daemon/websocket/websockify
|
||||||
|
|
||||||
go 1.17
|
go 1.20
|
||||||
|
|
||||||
require github.com/gorilla/websocket v1.5.1
|
require github.com/gorilla/websocket v1.5.3
|
||||||
|
|
||||||
require golang.org/x/net v0.23.0 // indirect
|
require golang.org/x/net v0.33.0 // indirect
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
// - Proper error handling in general.
|
// - Proper error handling in general.
|
||||||
// - Support both websocket and regular GET requests on /.
|
// - Support both websocket and regular GET requests on /.
|
||||||
//
|
//
|
||||||
// Copyright 2022 The TokTok team.
|
// Copyright 2022-2025 The TokTok team.
|
||||||
// Copyright 2021 Michael.liu.
|
// Copyright 2021 Michael.liu.
|
||||||
// See LICENSE for licensing conditions.
|
// See LICENSE for licensing conditions.
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2015 Tox project.
|
* Copyright © 2015 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
// Copyright © 2023-2024 The TokTok team.
|
// Copyright © 2023-2025 The TokTok team.
|
||||||
|
|
||||||
// this file can be used to generate event.c files
|
// this file can be used to generate event.c files
|
||||||
// requires c++17
|
// requires c++17
|
||||||
@ -156,7 +156,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
|
|||||||
}
|
}
|
||||||
|
|
||||||
f << R"(/* SPDX-License-Identifier: GPL-3.0-or-later
|
f << R"(/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2023-2024 The TokTok team.
|
* Copyright © 2023-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "events_alloc.h"
|
#include "events_alloc.h"
|
||||||
@ -178,6 +178,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
|
|||||||
#include "../ccompat.h"
|
#include "../ccompat.h"
|
||||||
#include "../mem.h"
|
#include "../mem.h"
|
||||||
#include "../tox.h"
|
#include "../tox.h"
|
||||||
|
#include "../tox_event.h"
|
||||||
#include "../tox_events.h")";
|
#include "../tox_events.h")";
|
||||||
if (need_tox_unpack_h) {
|
if (need_tox_unpack_h) {
|
||||||
f << R"(
|
f << R"(
|
||||||
@ -843,4 +844,3 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,3 +89,10 @@ cc_binary(
|
|||||||
"//c-toxcore/toxcore:mono_time",
|
"//c-toxcore/toxcore:mono_time",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cc_binary(
|
||||||
|
name = "decrypt_save",
|
||||||
|
testonly = 1,
|
||||||
|
srcs = ["decrypt_save.c"],
|
||||||
|
deps = ["//c-toxcore/toxencryptsave"],
|
||||||
|
)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
72
external/toxcore/c-toxcore/testing/decrypt_save.c
vendored
Normal file
72
external/toxcore/c-toxcore/testing/decrypt_save.c
vendored
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
* Copyright © 2025 The TokTok team.
|
||||||
|
*/
|
||||||
|
#include "../toxencryptsave/toxencryptsave.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
// ./decrypt_save <password> <encrypted input> <decrypted output>
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
if (argc != 4) {
|
||||||
|
printf("Usage: %s <password> <encrypted input> <decrypted output>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
FILE *fp = fopen(argv[2], "rb");
|
||||||
|
if (!fp) {
|
||||||
|
printf("Could not open %s\n", argv[2]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fseek(fp, 0, SEEK_END);
|
||||||
|
size_t len = ftell(fp);
|
||||||
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
uint8_t *data = (uint8_t *)malloc(len);
|
||||||
|
if (!data) {
|
||||||
|
printf("Could not allocate memory\n");
|
||||||
|
fclose(fp);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fread(data, 1, len, fp) != len) {
|
||||||
|
printf("Could not read %s\n", argv[2]);
|
||||||
|
free(data);
|
||||||
|
fclose(fp);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
uint8_t *plaintext = (uint8_t *)malloc(len);
|
||||||
|
if (!plaintext) {
|
||||||
|
printf("Could not allocate memory\n");
|
||||||
|
free(data);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
Tox_Err_Decryption error;
|
||||||
|
if (!tox_pass_decrypt(data, len, (uint8_t *)argv[1], strlen(argv[1]), plaintext, &error)) {
|
||||||
|
printf("Could not decrypt: %s\n", tox_err_decryption_to_string(error));
|
||||||
|
free(data);
|
||||||
|
free(plaintext);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fp = fopen(argv[3], "wb");
|
||||||
|
if (!fp) {
|
||||||
|
printf("Could not open %s\n", argv[3]);
|
||||||
|
free(data);
|
||||||
|
free(plaintext);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (fwrite(plaintext, 1, len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH, fp) != len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH) {
|
||||||
|
printf("Could not write %s\n", argv[3]);
|
||||||
|
free(data);
|
||||||
|
free(plaintext);
|
||||||
|
fclose(fp);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
free(data);
|
||||||
|
free(plaintext);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2022 The TokTok team.
|
* Copyright © 2022-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef C_TOXCORE_TESTING_FUZZING_FUNC_CONVERSION_H
|
#ifndef C_TOXCORE_TESTING_FUZZING_FUNC_CONVERSION_H
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2021-2022 The TokTok team.
|
* Copyright © 2021-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "fuzz_support.hh"
|
#include "fuzz_support.hh"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2021-2022 The TokTok team.
|
* Copyright © 2021-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef C_TOXCORE_TESTING_FUZZING_FUZZ_SUPPORT_H
|
#ifndef C_TOXCORE_TESTING_FUZZING_FUZZ_SUPPORT_H
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2022-2024 The TokTok team.
|
* Copyright © 2022-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef C_TOXCORE_TESTING_FUZZING_FUZZ_TOX_H
|
#ifndef C_TOXCORE_TESTING_FUZZING_FUZZ_TOX_H
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
4
external/toxcore/c-toxcore/toxav/audio.c
vendored
4
external/toxcore/c-toxcore/toxav/audio.c
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013-2015 Tox project.
|
* Copyright © 2013-2015 Tox project.
|
||||||
*/
|
*/
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
@ -195,7 +195,7 @@ void ac_iterate(ACSession *ac)
|
|||||||
free(temp_audio_buffer);
|
free(temp_audio_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ac_queue_message(Mono_Time *mono_time, void *cs, struct RTPMessage *msg)
|
int ac_queue_message(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg)
|
||||||
{
|
{
|
||||||
ACSession *ac = (ACSession *)cs;
|
ACSession *ac = (ACSession *)cs;
|
||||||
|
|
||||||
|
4
external/toxcore/c-toxcore/toxav/audio.h
vendored
4
external/toxcore/c-toxcore/toxav/audio.h
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013-2015 Tox project.
|
* Copyright © 2013-2015 Tox project.
|
||||||
*/
|
*/
|
||||||
#ifndef C_TOXCORE_TOXAV_AUDIO_H
|
#ifndef C_TOXCORE_TOXAV_AUDIO_H
|
||||||
@ -67,7 +67,7 @@ ACSession *ac_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t f
|
|||||||
toxav_audio_receive_frame_cb *cb, void *cb_data);
|
toxav_audio_receive_frame_cb *cb, void *cb_data);
|
||||||
void ac_kill(ACSession *ac);
|
void ac_kill(ACSession *ac);
|
||||||
void ac_iterate(ACSession *ac);
|
void ac_iterate(ACSession *ac);
|
||||||
int ac_queue_message(Mono_Time *mono_time, void *cs, struct RTPMessage *msg);
|
int ac_queue_message(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg);
|
||||||
int ac_reconfigure_encoder(ACSession *ac, uint32_t bit_rate, uint32_t sampling_rate, uint8_t channels);
|
int ac_reconfigure_encoder(ACSession *ac, uint32_t bit_rate, uint32_t sampling_rate, uint8_t channels);
|
||||||
|
|
||||||
#endif /* C_TOXCORE_TOXAV_AUDIO_H */
|
#endif /* C_TOXCORE_TOXAV_AUDIO_H */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013-2015 Tox project.
|
* Copyright © 2013-2015 Tox project.
|
||||||
*/
|
*/
|
||||||
#include "bwcontroller.h"
|
#include "bwcontroller.h"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013-2015 Tox project.
|
* Copyright © 2013-2015 Tox project.
|
||||||
*/
|
*/
|
||||||
#ifndef C_TOXCORE_TOXAV_BWCONTROLLER_H
|
#ifndef C_TOXCORE_TOXAV_BWCONTROLLER_H
|
||||||
|
2
external/toxcore/c-toxcore/toxav/groupav.c
vendored
2
external/toxcore/c-toxcore/toxav/groupav.c
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2014 Tox project.
|
* Copyright © 2014 Tox project.
|
||||||
*/
|
*/
|
||||||
#include "groupav.h"
|
#include "groupav.h"
|
||||||
|
2
external/toxcore/c-toxcore/toxav/groupav.h
vendored
2
external/toxcore/c-toxcore/toxav/groupav.h
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2014 Tox project.
|
* Copyright © 2014 Tox project.
|
||||||
*/
|
*/
|
||||||
#ifndef C_TOXCORE_TOXAV_GROUPAV_H
|
#ifndef C_TOXCORE_TOXAV_GROUPAV_H
|
||||||
|
2
external/toxcore/c-toxcore/toxav/msi.c
vendored
2
external/toxcore/c-toxcore/toxav/msi.c
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013-2015 Tox project.
|
* Copyright © 2013-2015 Tox project.
|
||||||
*/
|
*/
|
||||||
#include "msi.h"
|
#include "msi.h"
|
||||||
|
2
external/toxcore/c-toxcore/toxav/msi.h
vendored
2
external/toxcore/c-toxcore/toxav/msi.h
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013-2015 Tox project.
|
* Copyright © 2013-2015 Tox project.
|
||||||
*/
|
*/
|
||||||
#ifndef C_TOXCORE_TOXAV_MSI_H
|
#ifndef C_TOXCORE_TOXAV_MSI_H
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
* Copyright © 2013 plutooo
|
* Copyright © 2013 plutooo
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
* Copyright © 2013 plutooo
|
* Copyright © 2013 plutooo
|
||||||
*/
|
*/
|
||||||
|
36
external/toxcore/c-toxcore/toxav/rtp.c
vendored
36
external/toxcore/c-toxcore/toxav/rtp.c
vendored
@ -1,11 +1,10 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013-2015 Tox project.
|
* Copyright © 2013-2015 Tox project.
|
||||||
*/
|
*/
|
||||||
#include "rtp.h"
|
#include "rtp.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -768,22 +767,35 @@ void rtp_stop_receiving(Tox *tox)
|
|||||||
tox_callback_friend_lossy_packet_per_pktid(tox, nullptr, RTP_TYPE_VIDEO);
|
tox_callback_friend_lossy_packet_per_pktid(tox, nullptr, RTP_TYPE_VIDEO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log the neterror error if any.
|
||||||
|
*
|
||||||
|
* @param error the error from rtp_send_custom_lossy_packet.
|
||||||
|
* @param rdata_size The package length to be shown in the log.
|
||||||
|
*/
|
||||||
|
static void rtp_report_error_maybe(const Logger *log, Tox_Err_Friend_Custom_Packet error, uint16_t rdata_size)
|
||||||
|
{
|
||||||
|
if (error != TOX_ERR_FRIEND_CUSTOM_PACKET_OK) {
|
||||||
|
char *netstrerror = net_new_strerror(net_error());
|
||||||
|
const char *toxerror = tox_err_friend_custom_packet_to_string(error);
|
||||||
|
LOGGER_WARNING(log, "RTP send failed (len: %u)! tox error: %s net error: %s",
|
||||||
|
rdata_size, toxerror, netstrerror);
|
||||||
|
net_kill_strerror(netstrerror);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void rtp_send_piece(const Logger *log, Tox *tox, uint32_t friend_number, const struct RTPHeader *header,
|
static void rtp_send_piece(const Logger *log, Tox *tox, uint32_t friend_number, const struct RTPHeader *header,
|
||||||
const uint8_t *data, uint8_t *rdata, uint16_t length)
|
const uint8_t *data, uint8_t *rdata, uint16_t length)
|
||||||
{
|
{
|
||||||
rtp_header_pack(rdata + 1, header);
|
rtp_header_pack(rdata + 1, header);
|
||||||
memcpy(rdata + 1 + RTP_HEADER_SIZE, data, length);
|
memcpy(rdata + 1 + RTP_HEADER_SIZE, data, length);
|
||||||
|
|
||||||
Tox_Err_Friend_Custom_Packet error;
|
const uint16_t rdata_size = length + RTP_HEADER_SIZE + 1;
|
||||||
tox_friend_send_lossy_packet(tox, friend_number,
|
|
||||||
rdata, length + RTP_HEADER_SIZE + 1, &error);
|
|
||||||
|
|
||||||
if (error != TOX_ERR_FRIEND_CUSTOM_PACKET_OK) {
|
Tox_Err_Friend_Custom_Packet error;
|
||||||
char *netstrerror = net_new_strerror(net_error());
|
tox_friend_send_lossy_packet(tox, friend_number, rdata, rdata_size, &error);
|
||||||
LOGGER_WARNING(log, "RTP send failed (len: %d)! tox error: %d, net error: %s",
|
|
||||||
length + RTP_HEADER_SIZE + 1, error, netstrerror);
|
rtp_report_error_maybe(log, error, rdata_size);
|
||||||
net_kill_strerror(netstrerror);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct RTPHeader rtp_default_header(const RTPSession *session, uint32_t length, bool is_keyframe)
|
static struct RTPHeader rtp_default_header(const RTPSession *session, uint32_t length, bool is_keyframe)
|
||||||
@ -811,7 +823,7 @@ static struct RTPHeader rtp_default_header(const RTPSession *session, uint32_t l
|
|||||||
header.ma = 0;
|
header.ma = 0;
|
||||||
header.pt = session->payload_type % 128;
|
header.pt = session->payload_type % 128;
|
||||||
header.sequnum = session->sequnum;
|
header.sequnum = session->sequnum;
|
||||||
Mono_Time *mt = toxav_get_av_mono_time(session->toxav);
|
const Mono_Time *mt = toxav_get_av_mono_time(session->toxav);
|
||||||
if (mt != nullptr) {
|
if (mt != nullptr) {
|
||||||
header.timestamp = current_time_monotonic(mt);
|
header.timestamp = current_time_monotonic(mt);
|
||||||
} else {
|
} else {
|
||||||
|
4
external/toxcore/c-toxcore/toxav/rtp.h
vendored
4
external/toxcore/c-toxcore/toxav/rtp.h
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013-2015 Tox project.
|
* Copyright © 2013-2015 Tox project.
|
||||||
*/
|
*/
|
||||||
#ifndef C_TOXCORE_TOXAV_RTP_H
|
#ifndef C_TOXCORE_TOXAV_RTP_H
|
||||||
@ -147,7 +147,7 @@ struct RTPWorkBufferList {
|
|||||||
|
|
||||||
#define DISMISS_FIRST_LOST_VIDEO_PACKET_COUNT 10
|
#define DISMISS_FIRST_LOST_VIDEO_PACKET_COUNT 10
|
||||||
|
|
||||||
typedef int rtp_m_cb(Mono_Time *mono_time, void *cs, struct RTPMessage *msg);
|
typedef int rtp_m_cb(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RTP control session.
|
* RTP control session.
|
||||||
|
7
external/toxcore/c-toxcore/toxav/toxav.c
vendored
7
external/toxcore/c-toxcore/toxav/toxav.c
vendored
@ -1,11 +1,10 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013-2015 Tox project.
|
* Copyright © 2013-2015 Tox project.
|
||||||
*/
|
*/
|
||||||
#include "toxav.h"
|
#include "toxav.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -21,7 +20,7 @@
|
|||||||
#include "../toxcore/network.h"
|
#include "../toxcore/network.h"
|
||||||
#include "../toxcore/tox.h"
|
#include "../toxcore/tox.h"
|
||||||
#include "../toxcore/tox_private.h"
|
#include "../toxcore/tox_private.h"
|
||||||
#include "../toxcore/tox_struct.h"
|
#include "../toxcore/tox_struct.h" // IWYU pragma: keep
|
||||||
#include "../toxcore/util.h"
|
#include "../toxcore/util.h"
|
||||||
|
|
||||||
// TODO(zoff99): don't hardcode this, let the application choose it
|
// TODO(zoff99): don't hardcode this, let the application choose it
|
||||||
@ -342,7 +341,7 @@ uint32_t toxav_iteration_interval(const ToxAV *av)
|
|||||||
* @param frame_time the duration of the current frame in ms
|
* @param frame_time the duration of the current frame in ms
|
||||||
* @param start_time the timestamp when decoding of this frame started
|
* @param start_time the timestamp when decoding of this frame started
|
||||||
*/
|
*/
|
||||||
static void calc_interval(ToxAV *av, DecodeTimeStats *stats, int32_t frame_time, uint64_t start_time)
|
static void calc_interval(const ToxAV *av, DecodeTimeStats *stats, int32_t frame_time, uint64_t start_time)
|
||||||
{
|
{
|
||||||
stats->interval = frame_time < stats->average ? 0 : (frame_time - stats->average);
|
stats->interval = frame_time < stats->average ? 0 : (frame_time - stats->average);
|
||||||
stats->total += current_time_monotonic(av->toxav_mono_time) - start_time;
|
stats->total += current_time_monotonic(av->toxav_mono_time) - start_time;
|
||||||
|
2
external/toxcore/c-toxcore/toxav/toxav.h
vendored
2
external/toxcore/c-toxcore/toxav/toxav.h
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2024 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013-2015 Tox project.
|
* Copyright © 2013-2015 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013-2015 Tox project.
|
* Copyright © 2013-2015 Tox project.
|
||||||
*/
|
*/
|
||||||
#ifndef C_TOXCORE_TOXAV_HACKS_H
|
#ifndef C_TOXCORE_TOXAV_HACKS_H
|
||||||
|
2
external/toxcore/c-toxcore/toxav/toxav_old.c
vendored
2
external/toxcore/c-toxcore/toxav/toxav_old.c
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013-2015 Tox project.
|
* Copyright © 2013-2015 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
8
external/toxcore/c-toxcore/toxav/video.c
vendored
8
external/toxcore/c-toxcore/toxav/video.c
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013-2015 Tox project.
|
* Copyright © 2013-2015 Tox project.
|
||||||
*/
|
*/
|
||||||
#include "video.h"
|
#include "video.h"
|
||||||
@ -8,14 +8,12 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "msi.h"
|
|
||||||
#include "ring_buffer.h"
|
#include "ring_buffer.h"
|
||||||
#include "rtp.h"
|
#include "rtp.h"
|
||||||
|
|
||||||
#include "../toxcore/ccompat.h"
|
#include "../toxcore/ccompat.h"
|
||||||
#include "../toxcore/logger.h"
|
#include "../toxcore/logger.h"
|
||||||
#include "../toxcore/mono_time.h"
|
#include "../toxcore/mono_time.h"
|
||||||
#include "../toxcore/network.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Soft deadline the decoder should attempt to meet, in "us" (microseconds).
|
* Soft deadline the decoder should attempt to meet, in "us" (microseconds).
|
||||||
@ -143,7 +141,7 @@ static void vc_init_encoder_cfg(const Logger *log, vpx_codec_enc_cfg_t *cfg, int
|
|||||||
#endif /* 0 */
|
#endif /* 0 */
|
||||||
}
|
}
|
||||||
|
|
||||||
VCSession *vc_new(const Logger *log, Mono_Time *mono_time, ToxAV *av, uint32_t friend_number,
|
VCSession *vc_new(const Logger *log, const Mono_Time *mono_time, ToxAV *av, uint32_t friend_number,
|
||||||
toxav_video_receive_frame_cb *cb, void *cb_data)
|
toxav_video_receive_frame_cb *cb, void *cb_data)
|
||||||
{
|
{
|
||||||
VCSession *vc = (VCSession *)calloc(1, sizeof(VCSession));
|
VCSession *vc = (VCSession *)calloc(1, sizeof(VCSession));
|
||||||
@ -346,7 +344,7 @@ void vc_iterate(VCSession *vc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int vc_queue_message(Mono_Time *mono_time, void *cs, struct RTPMessage *msg)
|
int vc_queue_message(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg)
|
||||||
{
|
{
|
||||||
VCSession *vc = (VCSession *)cs;
|
VCSession *vc = (VCSession *)cs;
|
||||||
|
|
||||||
|
6
external/toxcore/c-toxcore/toxav/video.h
vendored
6
external/toxcore/c-toxcore/toxav/video.h
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013-2015 Tox project.
|
* Copyright © 2013-2015 Tox project.
|
||||||
*/
|
*/
|
||||||
#ifndef C_TOXCORE_TOXAV_VIDEO_H
|
#ifndef C_TOXCORE_TOXAV_VIDEO_H
|
||||||
@ -44,11 +44,11 @@ typedef struct VCSession {
|
|||||||
const Logger *log;
|
const Logger *log;
|
||||||
} VCSession;
|
} VCSession;
|
||||||
|
|
||||||
VCSession *vc_new(const Logger *log, Mono_Time *mono_time, ToxAV *av, uint32_t friend_number,
|
VCSession *vc_new(const Logger *log, const Mono_Time *mono_time, ToxAV *av, uint32_t friend_number,
|
||||||
toxav_video_receive_frame_cb *cb, void *cb_data);
|
toxav_video_receive_frame_cb *cb, void *cb_data);
|
||||||
void vc_kill(VCSession *vc);
|
void vc_kill(VCSession *vc);
|
||||||
void vc_iterate(VCSession *vc);
|
void vc_iterate(VCSession *vc);
|
||||||
int vc_queue_message(Mono_Time *mono_time, void *cs, struct RTPMessage *msg);
|
int vc_queue_message(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg);
|
||||||
int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uint16_t height, int16_t kf_max_dist);
|
int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uint16_t height, int16_t kf_max_dist);
|
||||||
|
|
||||||
#endif /* C_TOXCORE_TOXAV_VIDEO_H */
|
#endif /* C_TOXCORE_TOXAV_VIDEO_H */
|
||||||
|
29
external/toxcore/c-toxcore/toxcore/BUILD.bazel
vendored
29
external/toxcore/c-toxcore/toxcore/BUILD.bazel
vendored
@ -4,6 +4,8 @@ load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test")
|
|||||||
exports_files(
|
exports_files(
|
||||||
srcs = [
|
srcs = [
|
||||||
"tox.h",
|
"tox.h",
|
||||||
|
"tox_dispatch.h",
|
||||||
|
"tox_events.h",
|
||||||
"tox_private.h",
|
"tox_private.h",
|
||||||
],
|
],
|
||||||
visibility = ["//c-toxcore:__subpackages__"],
|
visibility = ["//c-toxcore:__subpackages__"],
|
||||||
@ -268,6 +270,7 @@ cc_library(
|
|||||||
deps = [
|
deps = [
|
||||||
":attributes",
|
":attributes",
|
||||||
":ccompat",
|
":ccompat",
|
||||||
|
":mem",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -277,6 +280,7 @@ cc_test(
|
|||||||
srcs = ["list_test.cc"],
|
srcs = ["list_test.cc"],
|
||||||
deps = [
|
deps = [
|
||||||
":list",
|
":list",
|
||||||
|
":mem",
|
||||||
"@com_google_googletest//:gtest",
|
"@com_google_googletest//:gtest",
|
||||||
"@com_google_googletest//:gtest_main",
|
"@com_google_googletest//:gtest_main",
|
||||||
],
|
],
|
||||||
@ -346,6 +350,18 @@ cc_library(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "net_profile",
|
||||||
|
srcs = ["net_profile.c"],
|
||||||
|
hdrs = ["net_profile.h"],
|
||||||
|
deps = [
|
||||||
|
":attributes",
|
||||||
|
":ccompat",
|
||||||
|
":logger",
|
||||||
|
":mem",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "network",
|
name = "network",
|
||||||
srcs = ["network.c"],
|
srcs = ["network.c"],
|
||||||
@ -365,6 +381,7 @@ cc_library(
|
|||||||
":logger",
|
":logger",
|
||||||
":mem",
|
":mem",
|
||||||
":mono_time",
|
":mono_time",
|
||||||
|
":net_profile",
|
||||||
":util",
|
":util",
|
||||||
"@libsodium",
|
"@libsodium",
|
||||||
"@psocket",
|
"@psocket",
|
||||||
@ -450,6 +467,7 @@ cc_library(
|
|||||||
":attributes",
|
":attributes",
|
||||||
":ccompat",
|
":ccompat",
|
||||||
":crypto_core",
|
":crypto_core",
|
||||||
|
":mem",
|
||||||
":network",
|
":network",
|
||||||
":util",
|
":util",
|
||||||
"@psocket",
|
"@psocket",
|
||||||
@ -575,6 +593,7 @@ cc_library(
|
|||||||
":ccompat",
|
":ccompat",
|
||||||
":crypto_core",
|
":crypto_core",
|
||||||
":logger",
|
":logger",
|
||||||
|
":mem",
|
||||||
":mono_time",
|
":mono_time",
|
||||||
":network",
|
":network",
|
||||||
":timed_auth",
|
":timed_auth",
|
||||||
@ -629,6 +648,7 @@ cc_library(
|
|||||||
":crypto_core",
|
":crypto_core",
|
||||||
":logger",
|
":logger",
|
||||||
":mem",
|
":mem",
|
||||||
|
":net_profile",
|
||||||
":network",
|
":network",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -656,6 +676,7 @@ cc_library(
|
|||||||
":logger",
|
":logger",
|
||||||
":mem",
|
":mem",
|
||||||
":mono_time",
|
":mono_time",
|
||||||
|
":net_profile",
|
||||||
":network",
|
":network",
|
||||||
":onion",
|
":onion",
|
||||||
":util",
|
":util",
|
||||||
@ -677,6 +698,7 @@ cc_library(
|
|||||||
":logger",
|
":logger",
|
||||||
":mem",
|
":mem",
|
||||||
":mono_time",
|
":mono_time",
|
||||||
|
":net_profile",
|
||||||
":network",
|
":network",
|
||||||
":util",
|
":util",
|
||||||
],
|
],
|
||||||
@ -699,6 +721,7 @@ cc_library(
|
|||||||
":logger",
|
":logger",
|
||||||
":mem",
|
":mem",
|
||||||
":mono_time",
|
":mono_time",
|
||||||
|
":net_profile",
|
||||||
":network",
|
":network",
|
||||||
":onion",
|
":onion",
|
||||||
":util",
|
":util",
|
||||||
@ -736,6 +759,7 @@ cc_library(
|
|||||||
":logger",
|
":logger",
|
||||||
":mem",
|
":mem",
|
||||||
":mono_time",
|
":mono_time",
|
||||||
|
":net_profile",
|
||||||
":network",
|
":network",
|
||||||
":util",
|
":util",
|
||||||
"@pthread",
|
"@pthread",
|
||||||
@ -785,6 +809,7 @@ cc_library(
|
|||||||
":ccompat",
|
":ccompat",
|
||||||
":crypto_core",
|
":crypto_core",
|
||||||
":logger",
|
":logger",
|
||||||
|
":mem",
|
||||||
":mono_time",
|
":mono_time",
|
||||||
":network",
|
":network",
|
||||||
":util",
|
":util",
|
||||||
@ -886,6 +911,7 @@ cc_library(
|
|||||||
":ccompat",
|
":ccompat",
|
||||||
":crypto_core",
|
":crypto_core",
|
||||||
":logger",
|
":logger",
|
||||||
|
":mem",
|
||||||
":mono_time",
|
":mono_time",
|
||||||
":net_crypto",
|
":net_crypto",
|
||||||
":network",
|
":network",
|
||||||
@ -910,6 +936,7 @@ cc_library(
|
|||||||
":ccompat",
|
":ccompat",
|
||||||
":crypto_core",
|
":crypto_core",
|
||||||
":friend_connection",
|
":friend_connection",
|
||||||
|
":mem",
|
||||||
":network",
|
":network",
|
||||||
":onion",
|
":onion",
|
||||||
":onion_announce",
|
":onion_announce",
|
||||||
@ -1060,6 +1087,7 @@ cc_library(
|
|||||||
":DHT",
|
":DHT",
|
||||||
":Messenger",
|
":Messenger",
|
||||||
":TCP_client",
|
":TCP_client",
|
||||||
|
":TCP_server",
|
||||||
":attributes",
|
":attributes",
|
||||||
":ccompat",
|
":ccompat",
|
||||||
":crypto_core",
|
":crypto_core",
|
||||||
@ -1070,6 +1098,7 @@ cc_library(
|
|||||||
":mem",
|
":mem",
|
||||||
":mono_time",
|
":mono_time",
|
||||||
":net_crypto",
|
":net_crypto",
|
||||||
|
":net_profile",
|
||||||
":network",
|
":network",
|
||||||
":onion_client",
|
":onion_client",
|
||||||
":state",
|
":state",
|
||||||
|
2
external/toxcore/c-toxcore/toxcore/DHT.c
vendored
2
external/toxcore/c-toxcore/toxcore/DHT.c
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
2
external/toxcore/c-toxcore/toxcore/DHT.h
vendored
2
external/toxcore/c-toxcore/toxcore/DHT.h
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -8,8 +8,6 @@
|
|||||||
*/
|
*/
|
||||||
#include "LAN_discovery.h"
|
#include "LAN_discovery.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
||||||
// The mingw32/64 Windows library warns about including winsock2.h after
|
// The mingw32/64 Windows library warns about including winsock2.h after
|
||||||
// windows.h even though with the above it's a valid thing to do. So, to make
|
// windows.h even though with the above it's a valid thing to do. So, to make
|
||||||
@ -41,11 +39,14 @@
|
|||||||
#include "attributes.h"
|
#include "attributes.h"
|
||||||
#include "ccompat.h"
|
#include "ccompat.h"
|
||||||
#include "crypto_core.h"
|
#include "crypto_core.h"
|
||||||
|
#include "mem.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
#define MAX_INTERFACES 16
|
#define MAX_INTERFACES 16
|
||||||
|
|
||||||
struct Broadcast_Info {
|
struct Broadcast_Info {
|
||||||
|
const Memory *mem;
|
||||||
|
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
IP ips[MAX_INTERFACES];
|
IP ips[MAX_INTERFACES];
|
||||||
};
|
};
|
||||||
@ -53,29 +54,31 @@ struct Broadcast_Info {
|
|||||||
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
||||||
|
|
||||||
non_null()
|
non_null()
|
||||||
static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
|
||||||
{
|
{
|
||||||
Broadcast_Info *broadcast = (Broadcast_Info *)calloc(1, sizeof(Broadcast_Info));
|
Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info));
|
||||||
|
|
||||||
if (broadcast == nullptr) {
|
if (broadcast == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
IP_ADAPTER_INFO *adapter_info = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
|
broadcast->mem = mem;
|
||||||
|
|
||||||
|
IP_ADAPTER_INFO *adapter_info = (IP_ADAPTER_INFO *)mem_balloc(mem, sizeof(IP_ADAPTER_INFO));
|
||||||
|
|
||||||
if (adapter_info == nullptr) {
|
if (adapter_info == nullptr) {
|
||||||
free(broadcast);
|
mem_delete(mem, broadcast);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long out_buf_len = sizeof(IP_ADAPTER_INFO);
|
unsigned long out_buf_len = sizeof(IP_ADAPTER_INFO);
|
||||||
|
|
||||||
if (GetAdaptersInfo(adapter_info, &out_buf_len) == ERROR_BUFFER_OVERFLOW) {
|
if (GetAdaptersInfo(adapter_info, &out_buf_len) == ERROR_BUFFER_OVERFLOW) {
|
||||||
free(adapter_info);
|
mem_delete(mem, adapter_info);
|
||||||
IP_ADAPTER_INFO *new_adapter_info = (IP_ADAPTER_INFO *)malloc(out_buf_len);
|
IP_ADAPTER_INFO *new_adapter_info = (IP_ADAPTER_INFO *)mem_balloc(mem, out_buf_len);
|
||||||
|
|
||||||
if (new_adapter_info == nullptr) {
|
if (new_adapter_info == nullptr) {
|
||||||
free(broadcast);
|
mem_delete(mem, broadcast);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +116,7 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (adapter_info != nullptr) {
|
if (adapter_info != nullptr) {
|
||||||
free(adapter_info);
|
mem_delete(mem, adapter_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
return broadcast;
|
return broadcast;
|
||||||
@ -122,14 +125,19 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
|||||||
#elif !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && (defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__))
|
#elif !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && (defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__))
|
||||||
|
|
||||||
non_null()
|
non_null()
|
||||||
static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
static bool ip4_is_local(const IP4 *ip4);
|
||||||
|
|
||||||
|
non_null()
|
||||||
|
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
|
||||||
{
|
{
|
||||||
Broadcast_Info *broadcast = (Broadcast_Info *)calloc(1, sizeof(Broadcast_Info));
|
Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info));
|
||||||
|
|
||||||
if (broadcast == nullptr) {
|
if (broadcast == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
broadcast->mem = mem;
|
||||||
|
|
||||||
/* Not sure how many platforms this will run on,
|
/* Not sure how many platforms this will run on,
|
||||||
* so it's wrapped in `__linux__` for now.
|
* so it's wrapped in `__linux__` for now.
|
||||||
* Definitely won't work like this on Windows...
|
* Definitely won't work like this on Windows...
|
||||||
@ -137,7 +145,7 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
|||||||
const Socket sock = net_socket(ns, net_family_ipv4(), TOX_SOCK_STREAM, 0);
|
const Socket sock = net_socket(ns, net_family_ipv4(), TOX_SOCK_STREAM, 0);
|
||||||
|
|
||||||
if (!sock_valid(sock)) {
|
if (!sock_valid(sock)) {
|
||||||
free(broadcast);
|
mem_delete(mem, broadcast);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +158,7 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
|||||||
|
|
||||||
if (ioctl(net_socket_to_native(sock), SIOCGIFCONF, &ifc) < 0) {
|
if (ioctl(net_socket_to_native(sock), SIOCGIFCONF, &ifc) < 0) {
|
||||||
kill_sock(ns, sock);
|
kill_sock(ns, sock);
|
||||||
free(broadcast);
|
mem_delete(mem, broadcast);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +170,8 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
|||||||
const int n = ifc.ifc_len / sizeof(struct ifreq);
|
const int n = ifc.ifc_len / sizeof(struct ifreq);
|
||||||
|
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
/* there are interfaces with are incapable of broadcast */
|
/* there are interfaces with are incapable of broadcast
|
||||||
|
* on Linux, `lo` has no broadcast address, but this function returns `>=0` */
|
||||||
if (ioctl(net_socket_to_native(sock), SIOCGIFBRDADDR, &i_faces[i]) < 0) {
|
if (ioctl(net_socket_to_native(sock), SIOCGIFBRDADDR, &i_faces[i]) < 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -172,7 +181,7 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct sockaddr_in *sock4 = (const struct sockaddr_in *)(void *)&i_faces[i].ifr_broadaddr;
|
const struct sockaddr_in *broadaddr4 = (const struct sockaddr_in *)(void *)&i_faces[i].ifr_broadaddr;
|
||||||
|
|
||||||
if (broadcast->count >= MAX_INTERFACES) {
|
if (broadcast->count >= MAX_INTERFACES) {
|
||||||
break;
|
break;
|
||||||
@ -180,10 +189,27 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
|||||||
|
|
||||||
IP *ip = &broadcast->ips[broadcast->count];
|
IP *ip = &broadcast->ips[broadcast->count];
|
||||||
ip->family = net_family_ipv4();
|
ip->family = net_family_ipv4();
|
||||||
ip->ip.v4.uint32 = sock4->sin_addr.s_addr;
|
ip->ip.v4.uint32 = broadaddr4->sin_addr.s_addr;
|
||||||
|
|
||||||
|
// if no broadcast address
|
||||||
if (ip->ip.v4.uint32 == 0) {
|
if (ip->ip.v4.uint32 == 0) {
|
||||||
continue;
|
if (ioctl(net_socket_to_native(sock), SIOCGIFADDR, &i_faces[i]) < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct sockaddr_in *addr4 = (const struct sockaddr_in *)(void *)&i_faces[i].ifr_addr;
|
||||||
|
|
||||||
|
|
||||||
|
IP4 ip4_staging;
|
||||||
|
ip4_staging.uint32 = addr4->sin_addr.s_addr;
|
||||||
|
|
||||||
|
if (ip4_is_local(&ip4_staging)) {
|
||||||
|
// this is 127.x.x.x
|
||||||
|
ip->ip.v4.uint32 = ip4_staging.uint32;
|
||||||
|
} else {
|
||||||
|
// give up.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
++broadcast->count;
|
++broadcast->count;
|
||||||
@ -197,9 +223,17 @@ static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
|||||||
#else // TODO(irungentoo): Other platforms?
|
#else // TODO(irungentoo): Other platforms?
|
||||||
|
|
||||||
non_null()
|
non_null()
|
||||||
static Broadcast_Info *fetch_broadcast_info(const Network *ns)
|
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
|
||||||
{
|
{
|
||||||
return (Broadcast_Info *)calloc(1, sizeof(Broadcast_Info));
|
Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info));
|
||||||
|
|
||||||
|
if (broadcast == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
broadcast->mem = mem;
|
||||||
|
|
||||||
|
return broadcast;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* platforms */
|
#endif /* platforms */
|
||||||
@ -375,12 +409,16 @@ bool lan_discovery_send(const Networking_Core *net, const Broadcast_Info *broadc
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Broadcast_Info *lan_discovery_init(const Network *ns)
|
Broadcast_Info *lan_discovery_init(const Memory *mem, const Network *ns)
|
||||||
{
|
{
|
||||||
return fetch_broadcast_info(ns);
|
return fetch_broadcast_info(mem, ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lan_discovery_kill(Broadcast_Info *broadcast)
|
void lan_discovery_kill(Broadcast_Info *broadcast)
|
||||||
{
|
{
|
||||||
free(broadcast);
|
if (broadcast == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mem_delete(broadcast->mem, broadcast);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -10,6 +10,7 @@
|
|||||||
#define C_TOXCORE_TOXCORE_LAN_DISCOVERY_H
|
#define C_TOXCORE_TOXCORE_LAN_DISCOVERY_H
|
||||||
|
|
||||||
#include "attributes.h"
|
#include "attributes.h"
|
||||||
|
#include "mem.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +33,7 @@ bool lan_discovery_send(const Networking_Core *net, const Broadcast_Info *broadc
|
|||||||
* Discovers broadcast devices and IP addresses.
|
* Discovers broadcast devices and IP addresses.
|
||||||
*/
|
*/
|
||||||
non_null()
|
non_null()
|
||||||
Broadcast_Info *lan_discovery_init(const Network *ns);
|
Broadcast_Info *lan_discovery_init(const Memory *mem, const Network *ns);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free all resources associated with the broadcast info.
|
* Free all resources associated with the broadcast info.
|
||||||
|
@ -74,6 +74,8 @@ libtoxcore_la_SOURCES = ../third_party/cmp/cmp.c \
|
|||||||
../toxcore/ping_array.c \
|
../toxcore/ping_array.c \
|
||||||
../toxcore/net_crypto.h \
|
../toxcore/net_crypto.h \
|
||||||
../toxcore/net_crypto.c \
|
../toxcore/net_crypto.c \
|
||||||
|
../toxcore/net_profile.c \
|
||||||
|
../toxcore/net_profile.h \
|
||||||
../toxcore/friend_requests.h \
|
../toxcore/friend_requests.h \
|
||||||
../toxcore/friend_requests.c \
|
../toxcore/friend_requests.c \
|
||||||
../toxcore/LAN_discovery.h \
|
../toxcore/LAN_discovery.h \
|
||||||
|
16
external/toxcore/c-toxcore/toxcore/Messenger.c
vendored
16
external/toxcore/c-toxcore/toxcore/Messenger.c
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ void getaddress(const Messenger *m, uint8_t *address)
|
|||||||
}
|
}
|
||||||
|
|
||||||
non_null()
|
non_null()
|
||||||
static bool send_online_packet(Messenger *m, int friendcon_id)
|
static bool send_online_packet(const Messenger *m, int friendcon_id)
|
||||||
{
|
{
|
||||||
const uint8_t packet[1] = {PACKET_ID_ONLINE};
|
const uint8_t packet[1] = {PACKET_ID_ONLINE};
|
||||||
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet,
|
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet,
|
||||||
@ -145,7 +145,7 @@ static bool send_online_packet(Messenger *m, int friendcon_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
non_null()
|
non_null()
|
||||||
static bool send_offline_packet(Messenger *m, int friendcon_id)
|
static bool send_offline_packet(const Messenger *m, int friendcon_id)
|
||||||
{
|
{
|
||||||
const uint8_t packet[1] = {PACKET_ID_OFFLINE};
|
const uint8_t packet[1] = {PACKET_ID_OFFLINE};
|
||||||
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet,
|
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet,
|
||||||
@ -2515,7 +2515,7 @@ static bool self_announce_group(const Messenger *m, GC_Chat *chat, Onion_Friend
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gca_add_announce(m->mono_time, m->group_announce, &announce) == nullptr) {
|
if (gca_add_announce(m->mem, m->mono_time, m->group_announce, &announce) == nullptr) {
|
||||||
onion_friend_set_gc_data(onion_friend, nullptr, 0);
|
onion_friend_set_gc_data(onion_friend, nullptr, 0);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -3475,7 +3475,7 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
|||||||
m->rng = rng;
|
m->rng = rng;
|
||||||
m->ns = ns;
|
m->ns = ns;
|
||||||
|
|
||||||
m->fr = friendreq_new();
|
m->fr = friendreq_new(mem);
|
||||||
|
|
||||||
if (m->fr == nullptr) {
|
if (m->fr == nullptr) {
|
||||||
mem_delete(mem, m);
|
mem_delete(mem, m);
|
||||||
@ -3544,7 +3544,7 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
m->group_announce = new_gca_list();
|
m->group_announce = new_gca_list(m->mem);
|
||||||
|
|
||||||
if (m->group_announce == nullptr) {
|
if (m->group_announce == nullptr) {
|
||||||
LOGGER_WARNING(m->log, "DHT group chats initialisation failed");
|
LOGGER_WARNING(m->log, "DHT group chats initialisation failed");
|
||||||
@ -3559,7 +3559,7 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options->dht_announcements_enabled) {
|
if (options->dht_announcements_enabled) {
|
||||||
m->forwarding = new_forwarding(m->log, m->rng, m->mono_time, m->dht);
|
m->forwarding = new_forwarding(m->log, m->mem, m->rng, m->mono_time, m->dht);
|
||||||
if (m->forwarding != nullptr) {
|
if (m->forwarding != nullptr) {
|
||||||
m->announce = new_announcements(m->log, m->mem, m->rng, m->mono_time, m->forwarding);
|
m->announce = new_announcements(m->log, m->mem, m->rng, m->mono_time, m->forwarding);
|
||||||
} else {
|
} else {
|
||||||
@ -3574,7 +3574,7 @@ Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *
|
|||||||
m->onion_a = new_onion_announce(m->log, m->mem, m->rng, m->mono_time, m->dht);
|
m->onion_a = new_onion_announce(m->log, m->mem, m->rng, m->mono_time, m->dht);
|
||||||
m->onion_c = new_onion_client(m->log, m->mem, m->rng, m->mono_time, m->net_crypto);
|
m->onion_c = new_onion_client(m->log, m->mem, m->rng, m->mono_time, m->net_crypto);
|
||||||
if (m->onion_c != nullptr) {
|
if (m->onion_c != nullptr) {
|
||||||
m->fr_c = new_friend_connections(m->log, m->mono_time, m->ns, m->onion_c, options->local_discovery_enabled);
|
m->fr_c = new_friend_connections(m->log, m->mem, m->mono_time, m->ns, m->onion_c, options->local_discovery_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((options->dht_announcements_enabled && (m->forwarding == nullptr || m->announce == nullptr)) ||
|
if ((options->dht_announcements_enabled && (m->forwarding == nullptr || m->announce == nullptr)) ||
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
40
external/toxcore/c-toxcore/toxcore/TCP_client.c
vendored
40
external/toxcore/c-toxcore/toxcore/TCP_client.c
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2014 Tox project.
|
* Copyright © 2014 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -20,6 +20,7 @@
|
|||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "mono_time.h"
|
#include "mono_time.h"
|
||||||
|
#include "net_profile.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
@ -109,11 +110,23 @@ void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value)
|
|||||||
non_null()
|
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 *ns, const Logger *logger, const Memory *mem, Socket sock, const IP_Port *ip_port, const TCP_Proxy_Info *proxy_info)
|
||||||
{
|
{
|
||||||
|
Net_Err_Connect err;
|
||||||
if (proxy_info->proxy_type != TCP_PROXY_NONE) {
|
if (proxy_info->proxy_type != TCP_PROXY_NONE) {
|
||||||
return net_connect(ns, mem, logger, sock, &proxy_info->ip_port);
|
net_connect(ns, mem, logger, sock, &proxy_info->ip_port, &err);
|
||||||
} else {
|
} else {
|
||||||
return net_connect(ns, mem, logger, sock, ip_port);
|
net_connect(ns, mem, logger, sock, ip_port, &err);
|
||||||
}
|
}
|
||||||
|
switch (err) {
|
||||||
|
case NET_ERR_CONNECT_OK:
|
||||||
|
case NET_ERR_CONNECT_FAILED: {
|
||||||
|
/* nonblocking socket, connect will never return success */
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case NET_ERR_CONNECT_INVALID_FAMILY:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LOGGER_ERROR(logger, "unexpected error code %s from net_connect", net_err_connect_to_string(err));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -582,7 +595,7 @@ void forwarding_handler(TCP_Client_Connection *con, forwarded_response_cb *forwa
|
|||||||
TCP_Client_Connection *new_tcp_connection(
|
TCP_Client_Connection *new_tcp_connection(
|
||||||
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns,
|
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns,
|
||||||
const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key,
|
const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key,
|
||||||
const TCP_Proxy_Info *proxy_info)
|
const TCP_Proxy_Info *proxy_info, Net_Profile *net_profile)
|
||||||
{
|
{
|
||||||
assert(logger != nullptr);
|
assert(logger != nullptr);
|
||||||
assert(mem != nullptr);
|
assert(mem != nullptr);
|
||||||
@ -591,6 +604,7 @@ TCP_Client_Connection *new_tcp_connection(
|
|||||||
assert(ns != nullptr);
|
assert(ns != nullptr);
|
||||||
|
|
||||||
if (!net_family_is_ipv4(ip_port->ip.family) && !net_family_is_ipv6(ip_port->ip.family)) {
|
if (!net_family_is_ipv4(ip_port->ip.family) && !net_family_is_ipv6(ip_port->ip.family)) {
|
||||||
|
LOGGER_ERROR(logger, "Invalid IP family: %d", ip_port->ip.family.value);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -609,15 +623,26 @@ TCP_Client_Connection *new_tcp_connection(
|
|||||||
const Socket sock = net_socket(ns, family, TOX_SOCK_STREAM, TOX_PROTO_TCP);
|
const Socket sock = net_socket(ns, family, TOX_SOCK_STREAM, TOX_PROTO_TCP);
|
||||||
|
|
||||||
if (!sock_valid(sock)) {
|
if (!sock_valid(sock)) {
|
||||||
|
LOGGER_ERROR(logger, "Failed to create TCP socket with family %d", family.value);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!set_socket_nosigpipe(ns, sock)) {
|
if (!set_socket_nosigpipe(ns, sock)) {
|
||||||
|
LOGGER_ERROR(logger, "Failed to set TCP socket to ignore SIGPIPE");
|
||||||
kill_sock(ns, sock);
|
kill_sock(ns, sock);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(set_socket_nonblock(ns, sock) && connect_sock_to(ns, logger, mem, sock, ip_port, proxy_info))) {
|
if (!set_socket_nonblock(ns, sock)) {
|
||||||
|
LOGGER_ERROR(logger, "Failed to set TCP socket to non-blocking");
|
||||||
|
kill_sock(ns, sock);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!connect_sock_to(ns, logger, mem, sock, ip_port, proxy_info)) {
|
||||||
|
Ip_Ntoa ip_ntoa;
|
||||||
|
LOGGER_WARNING(logger, "Failed to connect TCP socket to %s:%u",
|
||||||
|
net_ip_ntoa(&ip_port->ip, &ip_ntoa), net_ntohs(ip_port->port));
|
||||||
kill_sock(ns, sock);
|
kill_sock(ns, sock);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -625,6 +650,7 @@ TCP_Client_Connection *new_tcp_connection(
|
|||||||
TCP_Client_Connection *temp = (TCP_Client_Connection *)mem_alloc(mem, sizeof(TCP_Client_Connection));
|
TCP_Client_Connection *temp = (TCP_Client_Connection *)mem_alloc(mem, sizeof(TCP_Client_Connection));
|
||||||
|
|
||||||
if (temp == nullptr) {
|
if (temp == nullptr) {
|
||||||
|
LOGGER_ERROR(logger, "Failed to allocate memory for TCP_Client_Connection");
|
||||||
kill_sock(ns, sock);
|
kill_sock(ns, sock);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -634,6 +660,7 @@ TCP_Client_Connection *new_tcp_connection(
|
|||||||
temp->con.rng = rng;
|
temp->con.rng = rng;
|
||||||
temp->con.sock = sock;
|
temp->con.sock = sock;
|
||||||
temp->con.ip_port = *ip_port;
|
temp->con.ip_port = *ip_port;
|
||||||
|
temp->con.net_profile = net_profile;
|
||||||
memcpy(temp->public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
memcpy(temp->public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||||
memcpy(temp->self_public_key, self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
memcpy(temp->self_public_key, self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||||
encrypt_precompute(temp->public_key, self_secret_key, temp->con.shared_key);
|
encrypt_precompute(temp->public_key, self_secret_key, temp->con.shared_key);
|
||||||
@ -657,6 +684,7 @@ TCP_Client_Connection *new_tcp_connection(
|
|||||||
temp->status = TCP_CLIENT_CONNECTING;
|
temp->status = TCP_CLIENT_CONNECTING;
|
||||||
|
|
||||||
if (generate_handshake(temp) == -1) {
|
if (generate_handshake(temp) == -1) {
|
||||||
|
LOGGER_ERROR(logger, "Failed to generate handshake");
|
||||||
kill_sock(ns, sock);
|
kill_sock(ns, sock);
|
||||||
mem_delete(mem, temp);
|
mem_delete(mem, temp);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -819,6 +847,8 @@ static int handle_tcp_client_packet(const Logger *logger, TCP_Client_Connection
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
netprof_record_packet(conn->con.net_profile, data[0], length, PACKET_DIRECTION_RECV);
|
||||||
|
|
||||||
switch (data[0]) {
|
switch (data[0]) {
|
||||||
case TCP_PACKET_ROUTING_RESPONSE:
|
case TCP_PACKET_ROUTING_RESPONSE:
|
||||||
return handle_tcp_client_routing_response(conn, data, length);
|
return handle_tcp_client_routing_response(conn, data, length);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2014 Tox project.
|
* Copyright © 2014 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -15,6 +15,7 @@
|
|||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "mono_time.h"
|
#include "mono_time.h"
|
||||||
|
#include "net_profile.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
#define TCP_CONNECTION_TIMEOUT 10
|
#define TCP_CONNECTION_TIMEOUT 10
|
||||||
@ -60,11 +61,11 @@ non_null()
|
|||||||
void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value);
|
void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value);
|
||||||
|
|
||||||
/** Create new TCP connection to ip_port/public_key */
|
/** Create new TCP connection to ip_port/public_key */
|
||||||
non_null(1, 2, 3, 4, 5, 6, 7, 8, 9) nullable(10)
|
non_null(1, 2, 3, 4, 5, 6, 7, 8, 9) nullable(10, 11)
|
||||||
TCP_Client_Connection *new_tcp_connection(
|
TCP_Client_Connection *new_tcp_connection(
|
||||||
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns,
|
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns,
|
||||||
const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key,
|
const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key,
|
||||||
const TCP_Proxy_Info *proxy_info);
|
const TCP_Proxy_Info *proxy_info, Net_Profile *net_profile);
|
||||||
|
|
||||||
/** Run the TCP connection */
|
/** Run the TCP connection */
|
||||||
non_null(1, 2, 3) nullable(4)
|
non_null(1, 2, 3) nullable(4)
|
||||||
|
12
external/toxcore/c-toxcore/toxcore/TCP_common.c
vendored
12
external/toxcore/c-toxcore/toxcore/TCP_common.c
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2014 Tox project.
|
* Copyright © 2014 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -35,7 +35,8 @@ int send_pending_data_nonpriority(const Logger *logger, TCP_Connection *con)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const uint16_t left = con->last_packet_length - con->last_packet_sent;
|
const uint16_t left = con->last_packet_length - con->last_packet_sent;
|
||||||
const int len = net_send(con->ns, logger, con->sock, con->last_packet + con->last_packet_sent, left, &con->ip_port);
|
const int len = net_send(con->ns, logger, con->sock, con->last_packet + con->last_packet_sent, left, &con->ip_port,
|
||||||
|
con->net_profile);
|
||||||
|
|
||||||
if (len <= 0) {
|
if (len <= 0) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -66,7 +67,7 @@ int send_pending_data(const Logger *logger, TCP_Connection *con)
|
|||||||
|
|
||||||
while (p != nullptr) {
|
while (p != nullptr) {
|
||||||
const uint16_t left = p->size - p->sent;
|
const uint16_t left = p->size - p->sent;
|
||||||
const int len = net_send(con->ns, logger, con->sock, p->data + p->sent, left, &con->ip_port);
|
const int len = net_send(con->ns, logger, con->sock, p->data + p->sent, left, &con->ip_port, con->net_profile);
|
||||||
|
|
||||||
if (len != left) {
|
if (len != left) {
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
@ -164,7 +165,8 @@ int write_packet_tcp_secure_connection(const Logger *logger, TCP_Connection *con
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (priority) {
|
if (priority) {
|
||||||
len = sendpriority ? net_send(con->ns, logger, con->sock, packet, packet_size, &con->ip_port) : 0;
|
len = sendpriority ? net_send(con->ns, logger, con->sock, packet, packet_size, &con->ip_port,
|
||||||
|
con->net_profile) : 0;
|
||||||
|
|
||||||
if (len <= 0) {
|
if (len <= 0) {
|
||||||
len = 0;
|
len = 0;
|
||||||
@ -179,7 +181,7 @@ int write_packet_tcp_secure_connection(const Logger *logger, TCP_Connection *con
|
|||||||
return add_priority(con, packet, packet_size, len) ? 1 : 0;
|
return add_priority(con, packet, packet_size, len) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = net_send(con->ns, logger, con->sock, packet, packet_size, &con->ip_port);
|
len = net_send(con->ns, logger, con->sock, packet, packet_size, &con->ip_port, con->net_profile);
|
||||||
|
|
||||||
if (len <= 0) {
|
if (len <= 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2014 Tox project.
|
* Copyright © 2014 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -10,6 +10,7 @@
|
|||||||
#include "crypto_core.h"
|
#include "crypto_core.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
#include "net_profile.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
typedef struct TCP_Priority_List TCP_Priority_List;
|
typedef struct TCP_Priority_List TCP_Priority_List;
|
||||||
@ -66,6 +67,10 @@ typedef struct TCP_Connection {
|
|||||||
|
|
||||||
TCP_Priority_List *priority_queue_start;
|
TCP_Priority_List *priority_queue_start;
|
||||||
TCP_Priority_List *priority_queue_end;
|
TCP_Priority_List *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;
|
||||||
} TCP_Connection;
|
} TCP_Connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2015 Tox project.
|
* Copyright © 2015 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -20,6 +20,7 @@
|
|||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "mono_time.h"
|
#include "mono_time.h"
|
||||||
|
#include "net_profile.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
@ -56,6 +57,9 @@ struct TCP_Connections {
|
|||||||
|
|
||||||
bool onion_status;
|
bool onion_status;
|
||||||
uint16_t onion_num_conns;
|
uint16_t onion_num_conns;
|
||||||
|
|
||||||
|
/* Network profile for all TCP client packets. */
|
||||||
|
Net_Profile *net_profile;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const TCP_Connection_to empty_tcp_connection_to = {0};
|
static const TCP_Connection_to empty_tcp_connection_to = {0};
|
||||||
@ -928,7 +932,8 @@ static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connec
|
|||||||
uint8_t relay_pk[CRYPTO_PUBLIC_KEY_SIZE];
|
uint8_t relay_pk[CRYPTO_PUBLIC_KEY_SIZE];
|
||||||
memcpy(relay_pk, tcp_con_public_key(tcp_con->connection), CRYPTO_PUBLIC_KEY_SIZE);
|
memcpy(relay_pk, tcp_con_public_key(tcp_con->connection), CRYPTO_PUBLIC_KEY_SIZE);
|
||||||
kill_tcp_connection(tcp_con->connection);
|
kill_tcp_connection(tcp_con->connection);
|
||||||
tcp_con->connection = new_tcp_connection(tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &ip_port, relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info);
|
tcp_con->connection = new_tcp_connection(tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &ip_port, relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info,
|
||||||
|
tcp_c->net_profile);
|
||||||
|
|
||||||
if (tcp_con->connection == nullptr) {
|
if (tcp_con->connection == nullptr) {
|
||||||
kill_tcp_relay_connection(tcp_c, tcp_connections_number);
|
kill_tcp_relay_connection(tcp_c, tcp_connections_number);
|
||||||
@ -1017,7 +1022,7 @@ static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connecti
|
|||||||
|
|
||||||
tcp_con->connection = new_tcp_connection(
|
tcp_con->connection = new_tcp_connection(
|
||||||
tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &tcp_con->ip_port,
|
tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &tcp_con->ip_port,
|
||||||
tcp_con->relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info);
|
tcp_con->relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info, tcp_c->net_profile);
|
||||||
|
|
||||||
if (tcp_con->connection == nullptr) {
|
if (tcp_con->connection == nullptr) {
|
||||||
kill_tcp_relay_connection(tcp_c, tcp_connections_number);
|
kill_tcp_relay_connection(tcp_c, tcp_connections_number);
|
||||||
@ -1315,7 +1320,7 @@ static int add_tcp_relay_instance(TCP_Connections *tcp_c, const IP_Port *ip_port
|
|||||||
|
|
||||||
tcp_con->connection = new_tcp_connection(
|
tcp_con->connection = new_tcp_connection(
|
||||||
tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &ipp_copy,
|
tcp_c->logger, tcp_c->mem, tcp_c->mono_time, tcp_c->rng, tcp_c->ns, &ipp_copy,
|
||||||
relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info);
|
relay_pk, tcp_c->self_public_key, tcp_c->self_secret_key, &tcp_c->proxy_info, tcp_c->net_profile);
|
||||||
|
|
||||||
if (tcp_con->connection == nullptr) {
|
if (tcp_con->connection == nullptr) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -1609,6 +1614,14 @@ TCP_Connections *new_tcp_connections(const Logger *logger, const Memory *mem, co
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Net_Profile *np = netprof_new(logger, mem);
|
||||||
|
|
||||||
|
if (np == nullptr) {
|
||||||
|
mem_delete(mem, temp);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp->net_profile = np;
|
||||||
temp->logger = logger;
|
temp->logger = logger;
|
||||||
temp->mem = mem;
|
temp->mem = mem;
|
||||||
temp->rng = rng;
|
temp->rng = rng;
|
||||||
@ -1723,7 +1736,17 @@ void kill_tcp_connections(TCP_Connections *tcp_c)
|
|||||||
|
|
||||||
crypto_memzero(tcp_c->self_secret_key, sizeof(tcp_c->self_secret_key));
|
crypto_memzero(tcp_c->self_secret_key, sizeof(tcp_c->self_secret_key));
|
||||||
|
|
||||||
|
netprof_kill(tcp_c->mem, tcp_c->net_profile);
|
||||||
mem_delete(tcp_c->mem, tcp_c->tcp_connections);
|
mem_delete(tcp_c->mem, tcp_c->tcp_connections);
|
||||||
mem_delete(tcp_c->mem, tcp_c->connections);
|
mem_delete(tcp_c->mem, tcp_c->connections);
|
||||||
mem_delete(tcp_c->mem, tcp_c);
|
mem_delete(tcp_c->mem, tcp_c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Net_Profile *tcp_connection_get_client_net_profile(const TCP_Connections *tcp_c)
|
||||||
|
{
|
||||||
|
if (tcp_c == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tcp_c->net_profile;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2015 Tox project.
|
* Copyright © 2015 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -21,6 +21,7 @@
|
|||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "mono_time.h"
|
#include "mono_time.h"
|
||||||
|
#include "net_profile.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
#define TCP_CONN_NONE 0
|
#define TCP_CONN_NONE 0
|
||||||
@ -317,4 +318,11 @@ void do_tcp_connections(const Logger *logger, TCP_Connections *tcp_c, void *user
|
|||||||
nullable(1)
|
nullable(1)
|
||||||
void kill_tcp_connections(TCP_Connections *tcp_c);
|
void kill_tcp_connections(TCP_Connections *tcp_c);
|
||||||
|
|
||||||
|
/** @brief a pointer to the tcp client net profile associated with tcp_c.
|
||||||
|
*
|
||||||
|
* @retval null if tcp_c is null.
|
||||||
|
*/
|
||||||
|
non_null()
|
||||||
|
const Net_Profile *tcp_connection_get_client_net_profile(const TCP_Connections *tcp_c);
|
||||||
|
|
||||||
#endif /* C_TOXCORE_TOXCORE_TCP_CONNECTION_H */
|
#endif /* C_TOXCORE_TOXCORE_TCP_CONNECTION_H */
|
||||||
|
33
external/toxcore/c-toxcore/toxcore/TCP_server.c
vendored
33
external/toxcore/c-toxcore/toxcore/TCP_server.c
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2014 Tox project.
|
* Copyright © 2014 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -27,6 +27,7 @@
|
|||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "mono_time.h"
|
#include "mono_time.h"
|
||||||
|
#include "net_profile.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "onion.h"
|
#include "onion.h"
|
||||||
|
|
||||||
@ -91,6 +92,9 @@ struct TCP_Server {
|
|||||||
uint64_t counter;
|
uint64_t counter;
|
||||||
|
|
||||||
BS_List accepted_key_list;
|
BS_List accepted_key_list;
|
||||||
|
|
||||||
|
/* Network profile for all TCP server packets. */
|
||||||
|
Net_Profile *net_profile;
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(sizeof(TCP_Server) < 7 * 1024 * 1024,
|
static_assert(sizeof(TCP_Server) < 7 * 1024 * 1024,
|
||||||
@ -236,6 +240,7 @@ static int add_accepted(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_
|
|||||||
tcp_server->accepted_connection_array[index].identifier = ++tcp_server->counter;
|
tcp_server->accepted_connection_array[index].identifier = ++tcp_server->counter;
|
||||||
tcp_server->accepted_connection_array[index].last_pinged = mono_time_get(mono_time);
|
tcp_server->accepted_connection_array[index].last_pinged = mono_time_get(mono_time);
|
||||||
tcp_server->accepted_connection_array[index].ping_id = 0;
|
tcp_server->accepted_connection_array[index].ping_id = 0;
|
||||||
|
tcp_server->accepted_connection_array[index].con.net_profile = tcp_server->net_profile;
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
@ -357,7 +362,7 @@ static int handle_tcp_handshake(const Logger *logger, TCP_Secure_Connection *con
|
|||||||
|
|
||||||
const IP_Port ipp = {{{0}}};
|
const IP_Port ipp = {{{0}}};
|
||||||
|
|
||||||
if (TCP_SERVER_HANDSHAKE_SIZE != net_send(con->con.ns, logger, con->con.sock, response, TCP_SERVER_HANDSHAKE_SIZE, &ipp)) {
|
if (TCP_SERVER_HANDSHAKE_SIZE != net_send(con->con.ns, logger, con->con.sock, response, TCP_SERVER_HANDSHAKE_SIZE, &ipp, con->con.net_profile)) {
|
||||||
crypto_memzero(shared_key, sizeof(shared_key));
|
crypto_memzero(shared_key, sizeof(shared_key));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -680,6 +685,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
|
|||||||
}
|
}
|
||||||
|
|
||||||
TCP_Secure_Connection *const con = &tcp_server->accepted_connection_array[con_id];
|
TCP_Secure_Connection *const con = &tcp_server->accepted_connection_array[con_id];
|
||||||
|
netprof_record_packet(con->con.net_profile, data[0], length, PACKET_DIRECTION_RECV);
|
||||||
|
|
||||||
switch (data[0]) {
|
switch (data[0]) {
|
||||||
case TCP_PACKET_ROUTING_REQUEST: {
|
case TCP_PACKET_ROUTING_REQUEST: {
|
||||||
@ -969,6 +975,14 @@ TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Net_Profile *np = netprof_new(logger, mem);
|
||||||
|
|
||||||
|
if (np == nullptr) {
|
||||||
|
mem_delete(mem, temp);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp->net_profile = np;
|
||||||
temp->logger = logger;
|
temp->logger = logger;
|
||||||
temp->mem = mem;
|
temp->mem = mem;
|
||||||
temp->ns = ns;
|
temp->ns = ns;
|
||||||
@ -978,6 +992,7 @@ TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random
|
|||||||
|
|
||||||
if (socks_listening == nullptr) {
|
if (socks_listening == nullptr) {
|
||||||
LOGGER_ERROR(logger, "socket allocation failed");
|
LOGGER_ERROR(logger, "socket allocation failed");
|
||||||
|
netprof_kill(mem, temp->net_profile);
|
||||||
mem_delete(mem, temp);
|
mem_delete(mem, temp);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -989,6 +1004,7 @@ TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random
|
|||||||
|
|
||||||
if (temp->efd == -1) {
|
if (temp->efd == -1) {
|
||||||
LOGGER_ERROR(logger, "epoll initialisation failed");
|
LOGGER_ERROR(logger, "epoll initialisation failed");
|
||||||
|
netprof_kill(mem, temp->net_profile);
|
||||||
mem_delete(mem, socks_listening);
|
mem_delete(mem, socks_listening);
|
||||||
mem_delete(mem, temp);
|
mem_delete(mem, temp);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -1022,6 +1038,7 @@ TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (temp->num_listening_socks == 0) {
|
if (temp->num_listening_socks == 0) {
|
||||||
|
netprof_kill(mem, temp->net_profile);
|
||||||
mem_delete(mem, temp->socks_listening);
|
mem_delete(mem, temp->socks_listening);
|
||||||
mem_delete(mem, temp);
|
mem_delete(mem, temp);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -1040,7 +1057,7 @@ TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random
|
|||||||
memcpy(temp->secret_key, secret_key, CRYPTO_SECRET_KEY_SIZE);
|
memcpy(temp->secret_key, secret_key, CRYPTO_SECRET_KEY_SIZE);
|
||||||
crypto_derive_public_key(temp->public_key, temp->secret_key);
|
crypto_derive_public_key(temp->public_key, temp->secret_key);
|
||||||
|
|
||||||
bs_list_init(&temp->accepted_key_list, CRYPTO_PUBLIC_KEY_SIZE, 8, memcmp);
|
bs_list_init(&temp->accepted_key_list, mem, CRYPTO_PUBLIC_KEY_SIZE, 8, memcmp);
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
@ -1422,6 +1439,16 @@ void kill_tcp_server(TCP_Server *tcp_server)
|
|||||||
|
|
||||||
crypto_memzero(tcp_server->secret_key, sizeof(tcp_server->secret_key));
|
crypto_memzero(tcp_server->secret_key, sizeof(tcp_server->secret_key));
|
||||||
|
|
||||||
|
netprof_kill(tcp_server->mem, tcp_server->net_profile);
|
||||||
mem_delete(tcp_server->mem, tcp_server->socks_listening);
|
mem_delete(tcp_server->mem, tcp_server->socks_listening);
|
||||||
mem_delete(tcp_server->mem, tcp_server);
|
mem_delete(tcp_server->mem, tcp_server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Net_Profile *tcp_server_get_net_profile(const TCP_Server *tcp_server)
|
||||||
|
{
|
||||||
|
if (tcp_server == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tcp_server->net_profile;
|
||||||
|
}
|
||||||
|
10
external/toxcore/c-toxcore/toxcore/TCP_server.h
vendored
10
external/toxcore/c-toxcore/toxcore/TCP_server.h
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2018 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2014 Tox project.
|
* Copyright © 2014 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -15,6 +15,7 @@
|
|||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "mono_time.h"
|
#include "mono_time.h"
|
||||||
|
#include "net_profile.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "onion.h"
|
#include "onion.h"
|
||||||
|
|
||||||
@ -52,4 +53,11 @@ void do_tcp_server(TCP_Server *tcp_server, const Mono_Time *mono_time);
|
|||||||
nullable(1)
|
nullable(1)
|
||||||
void kill_tcp_server(TCP_Server *tcp_server);
|
void kill_tcp_server(TCP_Server *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);
|
||||||
|
|
||||||
#endif /* C_TOXCORE_TOXCORE_TCP_SERVER_H */
|
#endif /* C_TOXCORE_TOXCORE_TCP_SERVER_H */
|
||||||
|
15
external/toxcore/c-toxcore/toxcore/announce.c
vendored
15
external/toxcore/c-toxcore/toxcore/announce.c
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2020-2021 The TokTok team.
|
* Copyright © 2020-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -9,7 +9,6 @@
|
|||||||
#include "announce.h"
|
#include "announce.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "DHT.h"
|
#include "DHT.h"
|
||||||
@ -239,9 +238,9 @@ bool announce_store_data(Announcements *announce, const uint8_t *data_public_key
|
|||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
assert(data != nullptr);
|
assert(data != nullptr);
|
||||||
|
|
||||||
free(entry->data);
|
mem_delete(announce->mem, entry->data);
|
||||||
|
|
||||||
uint8_t *entry_data = (uint8_t *)malloc(length);
|
uint8_t *entry_data = (uint8_t *)mem_balloc(announce->mem, length);
|
||||||
|
|
||||||
if (entry_data == nullptr) {
|
if (entry_data == nullptr) {
|
||||||
entry->data = nullptr; // TODO(iphydf): Is this necessary?
|
entry->data = nullptr; // TODO(iphydf): Is this necessary?
|
||||||
@ -651,7 +650,7 @@ Announcements *new_announcements(const Logger *log, const Memory *mem, const Ran
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Announcements *announce = (Announcements *)calloc(1, sizeof(Announcements));
|
Announcements *announce = (Announcements *)mem_alloc(mem, sizeof(Announcements));
|
||||||
|
|
||||||
if (announce == nullptr) {
|
if (announce == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -669,7 +668,7 @@ Announcements *new_announcements(const Logger *log, const Memory *mem, const Ran
|
|||||||
new_hmac_key(announce->rng, announce->hmac_key);
|
new_hmac_key(announce->rng, announce->hmac_key);
|
||||||
announce->shared_keys = shared_key_cache_new(log, mono_time, mem, announce->secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
announce->shared_keys = shared_key_cache_new(log, mono_time, mem, announce->secret_key, KEYS_TIMEOUT, MAX_KEYS_PER_SLOT);
|
||||||
if (announce->shared_keys == nullptr) {
|
if (announce->shared_keys == nullptr) {
|
||||||
free(announce);
|
mem_delete(announce->mem, announce);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -700,8 +699,8 @@ void kill_announcements(Announcements *announce)
|
|||||||
shared_key_cache_free(announce->shared_keys);
|
shared_key_cache_free(announce->shared_keys);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < ANNOUNCE_BUCKETS * ANNOUNCE_BUCKET_SIZE; ++i) {
|
for (uint32_t i = 0; i < ANNOUNCE_BUCKETS * ANNOUNCE_BUCKET_SIZE; ++i) {
|
||||||
free(announce->entries[i].data);
|
mem_delete(announce->mem, announce->entries[i].data);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(announce);
|
mem_delete(announce->mem, announce);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2020-2021 The TokTok team.
|
* Copyright © 2020-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef C_TOXCORE_TOXCORE_ANNOUNCE_H
|
#ifndef C_TOXCORE_TOXCORE_ANNOUNCE_H
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2022 The TokTok team.
|
* Copyright © 2022-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2022 The TokTok team.
|
* Copyright © 2022-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "bin_pack.h"
|
#include "bin_pack.h"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2022 The TokTok team.
|
* Copyright © 2022-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
#ifndef C_TOXCORE_TOXCORE_BIN_PACK_H
|
#ifndef C_TOXCORE_TOXCORE_BIN_PACK_H
|
||||||
#define C_TOXCORE_TOXCORE_BIN_PACK_H
|
#define C_TOXCORE_TOXCORE_BIN_PACK_H
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2022 The TokTok team.
|
* Copyright © 2022-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "bin_unpack.h"
|
#include "bin_unpack.h"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2022 The TokTok team.
|
* Copyright © 2022-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef C_TOXCORE_TOXCORE_BIN_UNPACK_H
|
#ifndef C_TOXCORE_TOXCORE_BIN_UNPACK_H
|
||||||
|
2
external/toxcore/c-toxcore/toxcore/ccompat.c
vendored
2
external/toxcore/c-toxcore/toxcore/ccompat.c
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2022 The TokTok team.
|
* Copyright © 2022-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
#include "ccompat.h"
|
#include "ccompat.h"
|
||||||
|
|
||||||
|
2
external/toxcore/c-toxcore/toxcore/ccompat.h
vendored
2
external/toxcore/c-toxcore/toxcore/ccompat.h
vendored
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2021 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2024 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "crypto_core.h"
|
#include "crypto_core.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2024 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2024 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2016-2024 The TokTok team.
|
* Copyright © 2016-2025 The TokTok team.
|
||||||
* Copyright © 2013 Tox project.
|
* Copyright © 2013 Tox project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include "crypto_core_test_util.hh"
|
#include "crypto_core_test_util.hh"
|
||||||
#include "mem_test_util.hh"
|
#include "mem_test_util.hh"
|
||||||
#include "util.h"
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2023-2024 The TokTok team.
|
* Copyright © 2023-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "events_alloc.h"
|
#include "events_alloc.h"
|
||||||
@ -12,6 +12,7 @@
|
|||||||
#include "../ccompat.h"
|
#include "../ccompat.h"
|
||||||
#include "../mem.h"
|
#include "../mem.h"
|
||||||
#include "../tox.h"
|
#include "../tox.h"
|
||||||
|
#include "../tox_event.h"
|
||||||
#include "../tox_events.h"
|
#include "../tox_events.h"
|
||||||
|
|
||||||
/*****************************************************
|
/*****************************************************
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2023-2024 The TokTok team.
|
* Copyright © 2023-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "events_alloc.h"
|
#include "events_alloc.h"
|
||||||
@ -14,6 +14,7 @@
|
|||||||
#include "../ccompat.h"
|
#include "../ccompat.h"
|
||||||
#include "../mem.h"
|
#include "../mem.h"
|
||||||
#include "../tox.h"
|
#include "../tox.h"
|
||||||
|
#include "../tox_event.h"
|
||||||
#include "../tox_events.h"
|
#include "../tox_events.h"
|
||||||
#include "../tox_pack.h"
|
#include "../tox_pack.h"
|
||||||
#include "../tox_unpack.h"
|
#include "../tox_unpack.h"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2023-2024 The TokTok team.
|
* Copyright © 2023-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "events_alloc.h"
|
#include "events_alloc.h"
|
||||||
@ -14,6 +14,7 @@
|
|||||||
#include "../ccompat.h"
|
#include "../ccompat.h"
|
||||||
#include "../mem.h"
|
#include "../mem.h"
|
||||||
#include "../tox.h"
|
#include "../tox.h"
|
||||||
|
#include "../tox_event.h"
|
||||||
#include "../tox_events.h"
|
#include "../tox_events.h"
|
||||||
#include "../tox_pack.h"
|
#include "../tox_pack.h"
|
||||||
#include "../tox_unpack.h"
|
#include "../tox_unpack.h"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2023-2024 The TokTok team.
|
* Copyright © 2023-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "events_alloc.h"
|
#include "events_alloc.h"
|
||||||
@ -12,6 +12,7 @@
|
|||||||
#include "../ccompat.h"
|
#include "../ccompat.h"
|
||||||
#include "../mem.h"
|
#include "../mem.h"
|
||||||
#include "../tox.h"
|
#include "../tox.h"
|
||||||
|
#include "../tox_event.h"
|
||||||
#include "../tox_events.h"
|
#include "../tox_events.h"
|
||||||
|
|
||||||
/*****************************************************
|
/*****************************************************
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2023-2024 The TokTok team.
|
* Copyright © 2023-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "events_alloc.h"
|
#include "events_alloc.h"
|
||||||
@ -14,6 +14,7 @@
|
|||||||
#include "../ccompat.h"
|
#include "../ccompat.h"
|
||||||
#include "../mem.h"
|
#include "../mem.h"
|
||||||
#include "../tox.h"
|
#include "../tox.h"
|
||||||
|
#include "../tox_event.h"
|
||||||
#include "../tox_events.h"
|
#include "../tox_events.h"
|
||||||
|
|
||||||
/*****************************************************
|
/*****************************************************
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: GPL-3.0-or-later
|
/* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
* Copyright © 2023-2024 The TokTok team.
|
* Copyright © 2023-2025 The TokTok team.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "events_alloc.h"
|
#include "events_alloc.h"
|
||||||
@ -14,6 +14,7 @@
|
|||||||
#include "../ccompat.h"
|
#include "../ccompat.h"
|
||||||
#include "../mem.h"
|
#include "../mem.h"
|
||||||
#include "../tox.h"
|
#include "../tox.h"
|
||||||
|
#include "../tox_event.h"
|
||||||
#include "../tox_events.h"
|
#include "../tox_events.h"
|
||||||
|
|
||||||
/*****************************************************
|
/*****************************************************
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user