Squashed 'external/toxcore/c-toxcore/' changes from e2c01e457b..b03b571272

b03b571272 fix: flaky tcp test This only fixes the symptoms, not the real problem. Sometimes or consistently on some platforms a socket might need a moment before it can be written to.
32e67ab4c2 cleanup: use typedef for private message ID's in callback
7b1db6adc1 feat: add message IDs to private group messages
99e0bcc27d refactor: Observers/ignored peers can now send and receive custom packets
b3c3c49d26 fix: Disable IPv6 in Windows cross-compilation tests
e742deddff feat: Check hashes of Windows dependencies when cross-compiling
dfb9a0b02b fix: Test the current Windows Dockerfile, not an old Dockerhub image
14de93ccec chore: Use WineHQ's Wine as Debian Bookworm's crashes
ed37616249 docs: Update the Windows cross-compilation section
9bb79c174f cleanup: Remove a couple of unnecessary misc_tools dependencies
19475adb70 chore: Statically link OpenMP into the cracker fun util on Windows
1be311e51f feat: Build the fun utils when cross-compiling to Windows
88133f8446 chore: Strip Windows binaries
3cc0ae7535 refactor: Copy over all of the required static dependencies
c4fa8f7fb1 feat: Generate .def, .exp and .lib files when building for Windows
74bbac5363 feat: Let CMake create the dll instead of doing so ourselves
246642e9ae feat: Harden Windows cross-compilation
8d431c0d11 chore: Bump Windows build dependency versions
e519f7998b fix: Remove unnecessary wsock32 dependency on Windows
ed2b60c217 chore: Use a specific non-broken slimcc version.
d7f21010a1 chore: Update github actions.
e71a68b7f2 docs: Update the list of CMake options
77e08876ff chore: Remove mod and founder from group API naming scheme
12bc042767 docs: add the experimental api build option to INSTALL.md
e1fa5cae96 refactor: Rename Queries to Query to align with other enums.
be82a3ea30 fix: Correct type for conference offline peer numbers.
0627c36716 test: Add pkgsrc build.
92578afe4b test: Add FreeBSD VM action on GitHub.
52ece0f57b test: Build toxcore on NetBSD (VM).
3fe8ee2c11 chore: Only install tox_private.h on request.
9a8dfa06ab fix: save_compatibility_test failing on big-endian systems
86f5e55578 fix: Don't serve files from websockify.
710eb674a5 fix: Correctly pass extended public keys to group moderation code.
021db7031c refactor: Use `struct`s for extended public/secret keys.
a1e999fd80 chore: Compile libsodium reference implementation with compcert.
fbe3c19cf5 cleanup: correct a few nullable annotations
623e3ee5c3 cleanup: Don't use `memcpy` to cast arbitrary `struct`s to `uint8_t[]`.
c71567dc18 fix: Pass array, not array pointer, to `memcmp`.
9b46a08144 cleanup: Never pass `void*` directly to `memcpy`.
5d7b7a7bbc refactor: Use tox rng to seed the keypair generation.
961891d568 cleanup: Small improvements found by PVS Studio.
8201019f0d chore: Disable NGC saving by default, enable through Tox_Options.
5dd9ee3f65 cleanup: Replace pointer arithmetic with explicit `&arr[i]`.
ca4606d49d refactor: Use strong typedef for NGC peer id.
442213b722 cleanup: Simplify custom packet length check in NGC.
08d3393def fix: Correct a few potential null derefs in bootstrap daemon.
b9877b32b0 fix: Add missing memunlock of local variable when it goes out of scope.
dab5fe44b9 fix: Zero out stack-allocated secret key before return.
f058103299 refactor: Make prune_gc_sanctions_list more obviously correct.
3ba7a0dec9 docs: Add static analysis tool list to README.
8d0811a0f3 docs: Run prettier-markdown on markdown files.
969e3a2bfc refactor: Fix network test not using the strong typedef
93c83fbc7c refactor: Use strong typedef instead of struct for `Socket`.
9fe18b176f fix: Fix some false positive from PVS Studio.
7c44379ccb cleanup: Check that WINXP macro exists before comparing it.
5c93231bef refactor: Make tox mutex non-recursive.
aacff73939 docs: Fix up doxyfile.
d55fc85ff5 docs: Add more documentation to crypto_core.
5bdaaaedb6 refactor: Remove `Tox *` from `tox_dispatch`.
e202341e76 refactor: Don't rely on tox_dispatch passing tox in tests.
34df938f52 chore: Use C++ mode for clang-tidy.
8b05296a78 chore: Check that both gtest and gmock exist for tests.
42010660e1 test: Add slimcc compiler compatibility test.
b473630321 chore: Add some comments to the astyle config.
b7404f24f6 cleanup: Remove implicit bool conversions.
4e2dba4d9f chore: Reformat sources with astyle.
4359e3a6bc chore: Rename C++ headers to .hh suffixes.
0c05566e58 cleanup: Further `#include` cleanups.
8d29935b7a chore: Only check the bootstrap daemon checksum on release.
f70e588bc6 cleanup: Add more `const` where possible.
511bfe39c8 cleanup: Use Bazel modules to enforce proper `#include` hygiene.
1710a0d091 refactor: Move pack/unpack `IP_Port` from DHT into network module.
a975943564 chore: Really fix coverage docker image build.
c08409390f chore: Fix post-submit coverage image.
39aadf8922 fix: Don't use `memcmp` to compare `IP_Port`s.
d94246a906 fix: partially fix a bug that prevented group part messages from sending.
eeaa039222 chore: Fix rpm build; add a CI check for it.
8328449c1a chore: Speed up docker builds a bit by reducing layer count.
d6d67d56f3 cleanup: Add `const` where possible in auto tests.
6aa9e6850d cleanup: Minor cleanup of event unpack code.
bdf460a3a9 refactor: Rename `system_{memory,...}` to `os_{memory,...}`.
203e1af81e fix: a few off by one errors in group autotests
5c093c4888 cleanup: Remove all uses of `SIZEOF_VLA`.
662c2140f3 test: Add goblint static analyser.
8f07755834 cleanup: Use `memzero(x, s)` instead of `memset(x, 0, s)`.
a7258e40cf cleanup: Use explicit 0 instead of `PACKET_ID_PADDING`.
6370d0f15d cleanup: Expand the `Tox_Options` accessor macros.
14a1a0b9bd cleanup: Remove plan9 support.
a05dccad13 test: Add a simple new/delete test for Tox.
1cdcf938b9 cleanup: Add comment after every `#endif`.
ba99d4dc4b test: Fix comment I broke in the events test PR.
e07248debb refactor: Migrate auto_tests to new events API.
bdd42b5452 refactor: Add common msgpack array packer with callback.
3c659f5288 cleanup: Rename group to conference in groupav documentation.
89957be230 cleanup: Ensure handler params are named after callback params.
c650d9d345 refactor: Pass `this` pointer as first param to s11n callbacks.
e7fb91ddb8 refactor: Allow NULL pointers for byte arrays in events.
5e2c8cabc1 cleanup: make some improvements to group moderation test
259de4867e cleanup: Remove `bin_pack_{new,free}`.
21a8ff5895 cleanup: skip a do_gc iteration before removing peers marked for deletion
16809dc36e feat: Add dht_get_nodes_response event to the events system.

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: b03b5712720de9a9901ea12fd741f177327a7021
This commit is contained in:
2024-03-07 23:12:55 +01:00
parent 61accfe184
commit aae086cc65
358 changed files with 8093 additions and 5229 deletions

View File

@ -50,7 +50,6 @@ static const char *motd_str = ""; //Change this to anything within 256 bytes(but
#define PORT 33445
static bool manage_keys(DHT *dht)
{
enum { KEYS_SIZE = CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE };
@ -61,7 +60,7 @@ static bool manage_keys(DHT *dht)
if (keys_file != nullptr) {
/* If file was opened successfully -- load keys,
otherwise save new keys */
size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file);
const size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file);
if (read_size != KEYS_SIZE) {
printf("Error while reading the key file\nExiting.\n");
@ -126,7 +125,7 @@ static void print_log(void *context, Logger_Level level, const char *file, int l
int main(int argc, char *argv[])
{
if (argc == 2 && !tox_strncasecmp(argv[1], "-h", 3)) {
if (argc == 2 && tox_strncasecmp(argv[1], "-h", 3) == 0) {
printf("Usage (connected) : %s [--ipv4|--ipv6] IP PORT KEY\n", argv[0]);
printf("Usage (unconnected): %s [--ipv4|--ipv6]\n", argv[0]);
return 0;
@ -134,7 +133,7 @@ int main(int argc, char *argv[])
/* let user override default by cmdline */
bool ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
const int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled);
if (argvoffset < 0) {
return 1;
@ -151,9 +150,9 @@ int main(int argc, char *argv[])
logger_callback_log(logger, print_log, nullptr, nullptr);
}
const Random *rng = system_random();
const Network *ns = system_network();
const Memory *mem = system_memory();
const Random *rng = os_random();
const Network *ns = os_network();
const Memory *mem = os_memory();
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
const uint16_t start_port = PORT;
@ -165,11 +164,12 @@ int main(int argc, char *argv[])
Onion_Announce *onion_a = new_onion_announce(logger, mem, rng, mono_time, dht);
#ifdef DHT_NODE_EXTRA_PACKETS
bootstrap_set_callbacks(dht_get_net(dht), (uint32_t)DAEMON_VERSION_NUMBER, (const uint8_t *) motd_str, strlen(motd_str)+1);
bootstrap_set_callbacks(dht_get_net(dht), (uint32_t)DAEMON_VERSION_NUMBER, (const uint8_t *) motd_str, strlen(motd_str) + 1);
#endif
if (!(onion && forwarding && onion_a)) {
if (onion == nullptr || forwarding == nullptr || onion_a == nullptr) {
printf("Something failed to initialize.\n");
// cppcheck-suppress resourceLeak
return 1;
}
@ -178,17 +178,19 @@ int main(int argc, char *argv[])
perror("Initialization");
if (!manage_keys(dht)) {
// cppcheck-suppress resourceLeak
return 1;
}
printf("Public key: ");
#ifdef TCP_RELAY_ENABLED
#define NUM_PORTS 3
uint16_t ports[NUM_PORTS] = {443, 3389, PORT};
const uint16_t ports[NUM_PORTS] = {443, 3389, PORT};
TCP_Server *tcp_s = new_tcp_server(logger, mem, rng, ns, ipv6enabled, NUM_PORTS, ports, dht_get_self_secret_key(dht), onion, forwarding);
if (tcp_s == nullptr) {
printf("TCP server failed to initialize.\n");
// cppcheck-suppress resourceLeak
return 1;
}
@ -199,6 +201,7 @@ int main(int argc, char *argv[])
if (file == nullptr) {
printf("Could not open file \"%s\" for writing. Exiting...\n", public_id_filename);
// cppcheck-suppress resourceLeak
return 1;
}
@ -226,8 +229,8 @@ int main(int argc, char *argv[])
const uint16_t port = net_htons((uint16_t)port_conv);
uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
int res = dht_bootstrap_from_address(dht, argv[argvoffset + 1],
ipv6enabled, port, bootstrap_key);
const bool res = dht_bootstrap_from_address(dht, argv[argvoffset + 1],
ipv6enabled, port, bootstrap_key);
free(bootstrap_key);
if (!res) {
@ -236,17 +239,17 @@ int main(int argc, char *argv[])
}
}
int is_waiting_for_dht_connection = 1;
bool is_waiting_for_dht_connection = true;
uint64_t last_lan_discovery = 0;
const Broadcast_Info *broadcast = lan_discovery_init(ns);
while (1) {
while (true) {
mono_time_update(mono_time);
if (is_waiting_for_dht_connection && dht_isconnected(dht)) {
printf("Connected to other bootstrap node successfully.\n");
is_waiting_for_dht_connection = 0;
is_waiting_for_dht_connection = false;
}
do_dht(dht);

View File

@ -3,17 +3,20 @@
CHECKS="*"
ERRORS="*"
# Can't fix this, because winsock has different HANDLE type than posix.
# Still good to occasionally look at.
ERRORS="$ERRORS,-google-readability-casting"
# Need to investigate or disable and document these.
# =========================================================
# TODO(iphydf): Fix these.
ERRORS="$ERRORS,-cert-err34-c"
ERRORS="$ERRORS,-readability-suspicious-call-argument"
CHECKS="$CHECKS,-cppcoreguidelines-avoid-goto,-hicpp-avoid-goto"
CHECKS="$CHECKS,-bugprone-incorrect-roundings"
# TODO(iphydf): Fix once cimple 0.0.19 is released.
CHECKS="$CHECKS,-google-readability-casting"
# TODO(iphydf): Fix these.
# TODO(iphydf): Fix this by making more functions set error code enums.
CHECKS="$CHECKS,-bugprone-switch-missing-default-case"
# TODO(iphydf): We might want some of these. For the ones we don't want, add a
@ -30,17 +33,22 @@ CHECKS="$CHECKS,-misc-no-recursion"
CHECKS="$CHECKS,-cppcoreguidelines-avoid-non-const-global-variables"
# TODO(iphydf): Probably fix these.
CHECKS="$CHECKS,-cert-err33-c"
CHECKS="$CHECKS,-cppcoreguidelines-avoid-magic-numbers"
CHECKS="$CHECKS,-readability-magic-numbers"
# TODO(iphydf): We're using a lot of macros for constants. Should we convert
# all of them to enum?
CHECKS="$CHECKS,-modernize-macro-to-enum"
CHECKS="$CHECKS,-cert-err33-c,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers"
# Documented disabled checks. We don't want these for sure.
# =========================================================
# We want to decay many arrays to pointers. In C, we do that all the time.
CHECKS="$CHECKS,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay"
# enum{} breaks comparisons and arithmetic in C++.
CHECKS="$CHECKS,-modernize-macro-to-enum"
# For most things, we do want this, but for some we want to ensure (with msan)
# that struct members are actually initialised with useful non-zero values.
# Initialising them by default takes away that validation.
CHECKS="$CHECKS,-cppcoreguidelines-pro-type-member-init,-hicpp-member-init"
# https://stackoverflow.com/questions/58672959/why-does-clang-tidy-say-vsnprintf-has-an-uninitialized-va-list-argument
CHECKS="$CHECKS,-clang-analyzer-valist.Uninitialized"
@ -115,8 +123,7 @@ CHECKS="$CHECKS,-readability-redundant-control-flow"
# ^
# Trip the checker, which is true, because of integer promotion, but also not
# very helpful as a diagnostic.
CHECKS="$CHECKS,-bugprone-narrowing-conversions"
CHECKS="$CHECKS,-cppcoreguidelines-narrowing-conversions"
CHECKS="$CHECKS,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions"
# Mistakenly thinks that
# const int a = 0, b = 1;
@ -135,9 +142,51 @@ CHECKS="$CHECKS,-cppcoreguidelines-narrowing-conversions"
# - Turning 'a' and 'b' into pre-processor macros is the only option left, but
# #defines and #undefs in the middle of a function hurt the readability and
# are less idiomatic than simply using 'const int'.
CHECKS="$CHECKS,-cert-dcl03-c"
CHECKS="$CHECKS,-hicpp-static-assert"
CHECKS="$CHECKS,-misc-static-assert"
CHECKS="$CHECKS,-cert-dcl03-c,-hicpp-static-assert,-misc-static-assert"
# Doesn't consider use of preprocessor macros as needing a header, breaking
# struct definitions that depend on size macros from e.g. crypto_core.h.
CHECKS="$CHECKS,-misc-include-cleaner"
# A bunch of checks only valid for C++, we turn off for C.
# =========================================================
# We don't use Google's int typedefs.
CHECKS="$CHECKS,-google-runtime-int"
# We write C code, so we use C arrays.
CHECKS="$CHECKS,-cppcoreguidelines-avoid-c-arrays,-hicpp-avoid-c-arrays,-modernize-avoid-c-arrays"
# C loops are ok. This one tells us to use range-for.
CHECKS="$CHECKS,-modernize-loop-convert"
# No auto in C.
CHECKS="$CHECKS,-hicpp-use-auto,-modernize-use-auto"
# Only C style casts in C.
CHECKS="$CHECKS,-cppcoreguidelines-pro-type-cstyle-cast"
# We use malloc (for now), and MISRA checks this too.
CHECKS="$CHECKS,-cppcoreguidelines-no-malloc,-hicpp-no-malloc"
# No owning_ptr<> in C.
CHECKS="$CHECKS,-cppcoreguidelines-owning-memory"
# void foo(void) is good in C.
CHECKS="$CHECKS,-modernize-redundant-void-arg"
# No using-typedefs in C.
CHECKS="$CHECKS,-modernize-use-using"
# No namespaces in C.
CHECKS="$CHECKS,-misc-use-anonymous-namespace"
# No trailing return type in C.
CHECKS="$CHECKS,-modernize-use-trailing-return-type"
# No <cstdint> and friends in C.
CHECKS="$CHECKS,-hicpp-deprecated-headers,-modernize-deprecated-headers"
# We use varargs for logging (we could reconsider, but right now we do).
CHECKS="$CHECKS,-cppcoreguidelines-pro-type-vararg,-hicpp-vararg,-cert-dcl50-cpp"
# We do want to use the array index operator, even when the index is non-constant.
CHECKS="$CHECKS,-cppcoreguidelines-pro-bounds-constant-array-index"
# We don't want to use pointer arithmetic, but this one includes array index
# operators, which we do want to use.
CHECKS="$CHECKS,-cppcoreguidelines-pro-bounds-pointer-arithmetic"
# Can't use constexpr, yet. C will have it eventually, but it'll be years
# until we can use it across all the compilers.
CHECKS="$CHECKS,-cppcoreguidelines-macro-usage"
# These are all very C++ and/or LLVM specific.
CHECKS="$CHECKS,-llvmlibc-*"
set -eux
@ -154,7 +203,7 @@ copy_files() {
find "${DIRS[@]}" \
-maxdepth 1 -type d -exec mkdir -p "$1/{}" \;
find "${DIRS[@]}" \
-maxdepth 1 -name "*.c" -exec cp "{}" "$1/{}" \;
-maxdepth 1 -name "*.[ch]" -exec cp "{}" "$1/{}" \;
}
run() {
@ -166,7 +215,7 @@ run() {
ls .clang-tidy
copy_files a
if ! find "${DIRS[@]}" \
-maxdepth 1 -name "*.c" -print0 \
-maxdepth 1 -name "*.[ch]" -print0 \
| xargs -0 -n15 -P"$(nproc)" clang-tidy \
-p="$PWD/_build" \
--extra-arg=-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE \
@ -184,5 +233,6 @@ run() {
}
cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
sed -i -e 's/-std=c11/-xc++/' _build/compile_commands.json
. other/analysis/variants.sh

View File

@ -1,5 +1,6 @@
# Bracket Style Options
--style=kr
--attach-namespaces
# Tab Options
--indent=spaces=4
@ -9,15 +10,21 @@
# Padding Options
--pad-header
--break-blocks
--pad-oper
# Not supported in restyled's astyle.
#--unpad-brackets
--unpad-paren
--align-pointer=name
--align-reference=name
# Disabled because it causes very large changes and it's unclear whether we
# want all of those.
#--squeeze-ws
# Formatting Options
--add-braces
--convert-tabs
--max-code-length=120
--max-code-length=200
--attach-return-type
# Other Options
--preserve-date

View File

@ -2,36 +2,6 @@
set -ex
SOURCE_DIR="$1"
ASTYLE="$2"
# Go to the source root.
if [ -z "$SOURCE_DIR" ]; then
SOURCE_DIR=.
fi
cd "$SOURCE_DIR"
if [ -z "$ASTYLE" ] || ! which "$ASTYLE"; then
ASTYLE=astyle
fi
if ! which "$ASTYLE"; then
# If we couldn't find or install an astyle binary, don't do anything.
echo "Could not find an astyle binary; please install astyle."
exit 1
fi
readarray -t CC_SOURCES <<<"$(find . '(' -name '*.cc' ')')"
CC_SOURCES+=(toxcore/crypto_core.c)
CC_SOURCES+=(toxcore/ping_array.c)
for bin in clang-format-11 clang-format-7 clang-format-6.0 clang-format-5.0 clang-format; do
if which "$bin"; then
"$bin" -i -style='{BasedOnStyle: Google, ColumnLimit: 100}' "${CC_SOURCES[@]}"
break
fi
done
FIND="find ."
FIND="$FIND '(' -name '*.[ch]' ')'"
FIND="$FIND -and -not -name '*.api.h'"
@ -40,7 +10,15 @@ FIND="$FIND -and -not -wholename './third_party/*'"
FIND="$FIND -and -not -wholename './toxencryptsave/crypto_pwhash*'"
readarray -t C_SOURCES <<<"$(eval "$FIND")"
readarray -t CC_SOURCES <<<"$(find . '(' -name '*.cc' -or -name '*.hh' ')')"
#CC_SOURCES+=(toxcore/crypto_core.c)
#CC_SOURCES+=(toxcore/ping_array.c)
"$ASTYLE" -n --options=other/astyle/astylerc "${C_SOURCES[@]}"
# Format C++ sources with clang-format.
clang-format -i "${CC_SOURCES[@]}"
# Format C sources with astyle. We can't use clang-format, because it strongly
# messes up formatting of non_null annotations.
astyle -n --options=other/astyle/astylerc "${C_SOURCES[@]}"
git diff --color=always --exit-code

View File

@ -48,8 +48,9 @@ RUN CC=clang cmake -B_build -H. \
# Verify checksum from dev-built binary, so we can be sure Docker Hub doesn't
# mess with your binaries.
COPY other/bootstrap_daemon/docker/tox-bootstrapd.sha256 other/bootstrap_daemon/docker/
RUN SHA256="$(sha256sum /usr/local/bin/tox-bootstrapd)" && \
(sha256sum -c other/bootstrap_daemon/docker/tox-bootstrapd.sha256 || \
ARG CHECK=sha256sum
RUN SHA256="$("$CHECK" /usr/local/bin/tox-bootstrapd)" && \
("$CHECK" -c other/bootstrap_daemon/docker/tox-bootstrapd.sha256 || \
(echo "::error file=other/bootstrap_daemon/docker/tox-bootstrapd.sha256,line=1::$SHA256" && \
false))

View File

@ -1 +1 @@
0b904988d79b9576bb88c6c7316d107b5a61bd6119a0992ebd7c1fa43db70abf /usr/local/bin/tox-bootstrapd
af58a125e5c80d7a19bc7f32868c1edfdf80f366e3bf778728961a50ce63ee26 /usr/local/bin/tox-bootstrapd

View File

@ -18,7 +18,6 @@
#include <string.h>
/**
* Prints --help message
*/
@ -48,8 +47,8 @@ static void print_help(void)
}
Cli_Status handle_command_line_arguments(
int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend,
bool *run_in_foreground)
int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend,
bool *run_in_foreground)
{
if (argc < 2) {
log_write(LOG_LEVEL_ERROR, "Error: No arguments provided.\n\n");

View File

@ -32,7 +32,7 @@ typedef enum Cli_Status {
* @param run_in_foreground Sets to the provided by the user foreground option.
*/
Cli_Status handle_command_line_arguments(
int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend,
bool *run_in_foreground);
int argc, char *argv[], char **cfg_file_path, LOG_BACKEND *log_backend,
bool *run_in_foreground);
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_COMMAND_LINE_ARGUMENTS_H

View File

@ -44,13 +44,13 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
log_write(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file.\n", NAME_TCP_RELAY_PORTS);
log_write(LOG_LEVEL_WARNING, "Using default '%s':\n", NAME_TCP_RELAY_PORTS);
uint16_t default_ports[] = {DEFAULT_TCP_RELAY_PORTS};
const uint16_t default_ports[] = {DEFAULT_TCP_RELAY_PORTS};
// Check to avoid calling malloc(0) later on
// NOLINTNEXTLINE, clang-tidy: error: suspicious comparison of 'sizeof(expr)' to a constant [bugprone-sizeof-expression,-warnings-as-errors]
static_assert(sizeof(default_ports) > 0, "At least one default TCP relay port should be provided");
const size_t default_ports_count = sizeof(default_ports)/sizeof(*default_ports);
const size_t default_ports_count = sizeof(default_ports) / sizeof(*default_ports);
for (size_t i = 0; i < default_ports_count; ++i) {
log_write(LOG_LEVEL_INFO, "Port #%zu: %u\n", i, default_ports[i]);
@ -58,6 +58,10 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
// Similar procedure to the one of reading config file below
*tcp_relay_ports = (uint16_t *)malloc(default_ports_count * sizeof(uint16_t));
if (*tcp_relay_ports == nullptr) {
log_write(LOG_LEVEL_ERROR, "Allocation failure.\n");
return;
}
for (size_t i = 0; i < default_ports_count; ++i) {
@ -73,10 +77,8 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
++*tcp_relay_port_count;
}
// The loop above skips invalid ports, so we adjust the allocated memory size
if ((*tcp_relay_port_count) > 0) {
*tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t));
} else {
// No ports, so we free the array.
if (*tcp_relay_port_count == 0) {
free(*tcp_relay_ports);
*tcp_relay_ports = nullptr;
}
@ -90,7 +92,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
return;
}
int config_port_count = config_setting_length(ports_array);
const int config_port_count = config_setting_length(ports_array);
if (config_port_count == 0) {
log_write(LOG_LEVEL_ERROR, "'%s' is empty.\n", NAME_TCP_RELAY_PORTS);
@ -98,6 +100,10 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
}
*tcp_relay_ports = (uint16_t *)malloc(config_port_count * sizeof(uint16_t));
if (*tcp_relay_ports == nullptr) {
log_write(LOG_LEVEL_ERROR, "Allocation failure.\n");
return;
}
for (int i = 0; i < config_port_count; ++i) {
config_setting_t *elem = config_setting_get_elem(ports_array, i);
@ -125,18 +131,16 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
++*tcp_relay_port_count;
}
// The loop above skips invalid ports, so we adjust the allocated memory size
if ((*tcp_relay_port_count) > 0) {
*tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t));
} else {
// No ports, so we free the array.
if (*tcp_relay_port_count == 0) {
free(*tcp_relay_ports);
*tcp_relay_ports = nullptr;
}
}
int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay,
uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd)
bool get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay,
uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd)
{
config_t cfg;
@ -156,7 +160,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) {
log_write(LOG_LEVEL_ERROR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
config_destroy(&cfg);
return 0;
return false;
}
// Get port
@ -177,6 +181,10 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
const size_t pid_file_path_len = strlen(tmp_pid_file) + 1;
*pid_file_path = (char *)malloc(pid_file_path_len);
if (*pid_file_path == nullptr) {
log_write(LOG_LEVEL_ERROR, "Allocation failure.\n");
return false;
}
memcpy(*pid_file_path, tmp_pid_file, pid_file_path_len);
// Get keys file location
@ -190,6 +198,10 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
const size_t keys_file_path_len = strlen(tmp_keys_file) + 1;
*keys_file_path = (char *)malloc(keys_file_path_len);
if (*keys_file_path == nullptr) {
log_write(LOG_LEVEL_ERROR, "Allocation failure.\n");
return false;
}
memcpy(*keys_file_path, tmp_keys_file, keys_file_path_len);
// Get IPv6 option
@ -223,7 +235,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
*enable_tcp_relay = DEFAULT_ENABLE_TCP_RELAY;
}
if (*enable_tcp_relay) {
if (*enable_tcp_relay != 0) {
parse_tcp_relay_ports_config(&cfg, tcp_relay_ports, tcp_relay_port_count);
} else {
*tcp_relay_port_count = 0;
@ -237,7 +249,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
*enable_motd = DEFAULT_ENABLE_MOTD;
}
if (*enable_motd) {
if (*enable_motd != 0) {
// Get MOTD
const char *tmp_motd;
@ -247,8 +259,8 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
tmp_motd = DEFAULT_MOTD;
}
size_t tmp_motd_length = strlen(tmp_motd) + 1;
size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length;
const size_t tmp_motd_length = strlen(tmp_motd) + 1;
const size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length;
*motd = (char *)malloc(motd_length);
snprintf(*motd, motd_length, "%s", tmp_motd);
}
@ -259,14 +271,14 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_PID_FILE_PATH, *pid_file_path);
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_KEYS_FILE_PATH, *keys_file_path);
log_write(LOG_LEVEL_INFO, "'%s': %d\n", NAME_PORT, *port);
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 != 0 ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback != 0 ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery != 0 ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay != 0 ? "true" : "false");
// Show info about tcp ports only if tcp relay is enabled
if (*enable_tcp_relay) {
if (*enable_tcp_relay != 0) {
if (*tcp_relay_port_count == 0) {
log_write(LOG_LEVEL_ERROR, "No TCP ports could be read.\n");
} else {
@ -278,13 +290,13 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
}
}
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd ? "true" : "false");
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd != 0 ? "true" : "false");
if (*enable_motd) {
if (*enable_motd != 0) {
log_write(LOG_LEVEL_INFO, "'%s': %s\n", NAME_MOTD, *motd);
}
return 1;
return true;
}
/**
@ -302,8 +314,12 @@ static uint8_t *bootstrap_hex_string_to_bin(const char *hex_string)
return nullptr;
}
size_t len = strlen(hex_string) / 2;
const size_t len = strlen(hex_string) / 2;
uint8_t *ret = (uint8_t *)malloc(len);
if (ret == nullptr) {
log_write(LOG_LEVEL_ERROR, "Allocation failure.\n");
return nullptr;
}
const char *pos = hex_string;
@ -316,7 +332,7 @@ static uint8_t *bootstrap_hex_string_to_bin(const char *hex_string)
return ret;
}
int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
bool bootstrap_from_config(const char *cfg_file_path, DHT *dht, bool enable_ipv6)
{
const char *const NAME_BOOTSTRAP_NODES = "bootstrap_nodes";
@ -331,7 +347,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
if (config_read_file(&cfg, cfg_file_path) == CONFIG_FALSE) {
log_write(LOG_LEVEL_ERROR, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
config_destroy(&cfg);
return 0;
return false;
}
config_setting_t *node_list = config_lookup(&cfg, NAME_BOOTSTRAP_NODES);
@ -340,13 +356,13 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
log_write(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n",
NAME_BOOTSTRAP_NODES);
config_destroy(&cfg);
return 1;
return true;
}
if (config_setting_length(node_list) == 0) {
log_write(LOG_LEVEL_WARNING, "No bootstrap nodes found. Skipping bootstrapping.\n");
config_destroy(&cfg);
return 1;
return true;
}
int bs_port;
@ -357,15 +373,15 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
int i = 0;
while (config_setting_length(node_list)) {
int address_resolved;
while (config_setting_length(node_list) != 0) {
bool address_resolved;
uint8_t *bs_public_key_bin;
node = config_setting_get_elem(node_list, 0);
if (node == nullptr) {
config_destroy(&cfg);
return 0;
return false;
}
// Check that all settings are present
@ -421,5 +437,5 @@ next:
config_destroy(&cfg);
return 1;
return true;
}

View File

@ -19,19 +19,19 @@
* also, iff `tcp_relay_ports_count` > 0, then you are responsible for freeing `tcp_relay_ports`
* and also `motd` iff `enable_motd` is set.
*
* @return 1 on success,
* 0 on failure, doesn't modify any data pointed by arguments.
* @return true on success,
* false on failure, doesn't modify any data pointed by arguments.
*/
int get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay,
uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd);
bool get_general_config(const char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port,
int *enable_ipv6, int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay,
uint16_t **tcp_relay_ports, int *tcp_relay_port_count, int *enable_motd, char **motd);
/**
* Bootstraps off nodes listed in the config file.
*
* @return 1 on success, some or no bootstrap nodes were added
* 0 on failure, an error occurred while parsing the config file.
* @return true on success, some or no bootstrap nodes were added
* false on failure, an error occurred while parsing the config file.
*/
int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6);
bool bootstrap_from_config(const char *cfg_file_path, DHT *dht, bool enable_ipv6);
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_CONFIG_H

View File

@ -58,7 +58,6 @@ bool log_close(void)
return true;
}
bool log_write(LOG_LEVEL level, const char *format, ...)
{
if (current_backend == INVALID_BACKEND) {

View File

@ -12,7 +12,7 @@
#include <stdbool.h>
#include "../../../toxcore/ccompat.h"
#include "../../../toxcore/attributes.h"
typedef enum LOG_BACKEND {
LOG_BACKEND_STDOUT,
@ -47,5 +47,4 @@ bool log_close(void);
*/
bool log_write(LOG_LEVEL level, const char *format, ...) GNU_PRINTF(2, 3);
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_H

View File

@ -10,10 +10,11 @@
#ifndef C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_STDOUT_H
#define C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_STDOUT_H
#include "log.h"
#include <stdarg.h>
#include "../../../toxcore/attributes.h"
#include "log.h"
void log_backend_stdout_write(LOG_LEVEL level, const char *format, va_list args) GNU_PRINTF(2, 0);
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_STDOUT_H
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_STDOUT_H

View File

@ -51,7 +51,7 @@ void log_backend_syslog_write(LOG_LEVEL level, const char *format, va_list args)
va_list args2;
va_copy(args2, args);
int size = vsnprintf(nullptr, 0, format, args2);
const int size = vsnprintf(nullptr, 0, format, args2);
va_end(args2);
assert(size >= 0);
@ -61,6 +61,9 @@ void log_backend_syslog_write(LOG_LEVEL level, const char *format, va_list args)
}
char *buf = (char *)malloc(size + 1);
if (buf == nullptr) {
return;
}
vsnprintf(buf, size + 1, format, args);
syslog(log_backend_syslog_level(level), "%s", buf);

View File

@ -10,12 +10,13 @@
#ifndef C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_SYSLOG_H
#define C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_SYSLOG_H
#include "log.h"
#include <stdarg.h>
#include "../../../toxcore/attributes.h"
#include "log.h"
void log_backend_syslog_open(void);
void log_backend_syslog_close(void);
void log_backend_syslog_write(LOG_LEVEL level, const char *format, va_list args) GNU_PRINTF(2, 0);
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_SYSLOG_H
#endif // C_TOXCORE_OTHER_BOOTSTRAP_DAEMON_SRC_LOG_BACKEND_SYSLOG_H

View File

@ -50,7 +50,6 @@
#include "global.h"
#include "log.h"
static void sleep_milliseconds(uint32_t ms)
{
struct timespec req;
@ -61,10 +60,10 @@ static void sleep_milliseconds(uint32_t ms)
// Uses the already existing key or creates one if it didn't exist
//
// returns 1 on success
// 0 on failure - no keys were read or stored
// returns true on success
// false on failure - no keys were read or stored
static int manage_keys(DHT *dht, const char *keys_file_path)
static bool manage_keys(DHT *dht, const char *keys_file_path)
{
enum { KEYS_SIZE = CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE };
uint8_t keys[KEYS_SIZE];
@ -77,7 +76,7 @@ static int manage_keys(DHT *dht, const char *keys_file_path)
if (read_size != KEYS_SIZE) {
fclose(keys_file);
return 0;
return false;
}
dht_set_self_public_key(dht, keys);
@ -89,21 +88,21 @@ static int manage_keys(DHT *dht, const char *keys_file_path)
keys_file = fopen(keys_file_path, "wb");
if (!keys_file) {
return 0;
if (keys_file == nullptr) {
return false;
}
const size_t write_size = fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file);
if (write_size != KEYS_SIZE) {
fclose(keys_file);
return 0;
return false;
}
}
fclose(keys_file);
return 1;
return true;
}
// Prints public key
@ -164,7 +163,6 @@ static Cli_Status daemonize(LOG_BACKEND log_backend, char *pid_file_path)
return CLI_STATUS_ERROR;
}
// Change the current working directory
if ((chdir("/")) < 0) {
log_write(LOG_LEVEL_ERROR, "Couldn't change working directory to '/'. Exiting.\n");
@ -222,7 +220,7 @@ int main(int argc, char *argv[])
bool run_in_foreground = false;
// Choose backend for printing command line argument parsing output based on whether the daemon is being run from a terminal
LOG_BACKEND log_backend = isatty(STDOUT_FILENO) ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG;
LOG_BACKEND log_backend = isatty(STDOUT_FILENO) != 0 ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG;
log_open(log_backend);
switch (handle_command_line_arguments(argc, argv, &cfg_file_path, &log_backend, &run_in_foreground)) {
@ -283,7 +281,7 @@ int main(int argc, char *argv[])
free(pid_file_path);
IP ip;
ip_init(&ip, enable_ipv6);
ip_init(&ip, enable_ipv6 != 0);
Logger *logger = logger_new();
@ -292,16 +290,16 @@ int main(int argc, char *argv[])
}
const uint16_t end_port = start_port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM);
const Memory *mem = system_memory();
const Random *rng = system_random();
const Network *ns = system_network();
const Memory *mem = os_memory();
const Random *rng = os_random();
const Network *ns = os_network();
Networking_Core *net = new_networking_ex(logger, mem, ns, &ip, start_port, end_port, nullptr);
if (net == nullptr) {
if (enable_ipv6 && enable_ipv4_fallback) {
if (enable_ipv6 != 0 && enable_ipv4_fallback != 0) {
log_write(LOG_LEVEL_WARNING, "Couldn't initialize IPv6 networking. Falling back to using IPv4.\n");
enable_ipv6 = 0;
ip_init(&ip, enable_ipv6);
ip_init(&ip, enable_ipv6 != 0);
net = new_networking_ex(logger, mem, ns, &ip, start_port, end_port, nullptr);
if (net == nullptr) {
@ -336,7 +334,7 @@ int main(int argc, char *argv[])
mono_time_update(mono_time);
DHT *const dht = new_dht(logger, mem, rng, ns, mono_time, net, true, enable_lan_discovery);
DHT *const dht = new_dht(logger, mem, rng, ns, mono_time, net, true, enable_lan_discovery != 0);
if (dht == nullptr) {
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox DHT instance. Exiting.\n");
@ -396,7 +394,7 @@ int main(int argc, char *argv[])
Onion *onion = new_onion(logger, mem, mono_time, rng, dht);
if (!onion) {
if (onion == nullptr) {
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion. Exiting.\n");
kill_gca(group_announce);
kill_announcements(announce);
@ -413,7 +411,7 @@ int main(int argc, char *argv[])
Onion_Announce *onion_a = new_onion_announce(logger, mem, rng, mono_time, dht);
if (!onion_a) {
if (onion_a == nullptr) {
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion Announce. Exiting.\n");
kill_gca(group_announce);
kill_onion(onion);
@ -431,7 +429,7 @@ int main(int argc, char *argv[])
gca_onion_init(group_announce, onion_a);
if (enable_motd) {
if (enable_motd != 0) {
if (bootstrap_set_callbacks(dht_get_net(dht), DAEMON_VERSION_NUMBER, (uint8_t *)motd, strlen(motd) + 1) == 0) {
log_write(LOG_LEVEL_INFO, "Set MOTD successfully.\n");
free(motd);
@ -474,7 +472,7 @@ int main(int argc, char *argv[])
TCP_Server *tcp_server = nullptr;
if (enable_tcp_relay) {
if (enable_tcp_relay != 0) {
if (tcp_relay_port_count == 0) {
log_write(LOG_LEVEL_ERROR, "No TCP relay ports read. Exiting.\n");
kill_onion_announce(onion_a);
@ -490,7 +488,7 @@ int main(int argc, char *argv[])
return 1;
}
tcp_server = new_tcp_server(logger, mem, rng, ns, enable_ipv6,
tcp_server = new_tcp_server(logger, mem, rng, ns, enable_ipv6 != 0,
tcp_relay_port_count, tcp_relay_ports,
dht_get_self_secret_key(dht), onion, forwarding);
@ -506,7 +504,7 @@ int main(int argc, char *argv[])
assert(rlim_suggested >= rlim_min);
if (!getrlimit(RLIMIT_NOFILE, &limit)) {
if (getrlimit(RLIMIT_NOFILE, &limit) == 0) {
if (limit.rlim_cur < limit.rlim_max) {
// Some systems have a hard limit of over 1000000 open file descriptors, so let's cap it at something reasonable
// so that we don't set it to an unreasonably high number.
@ -515,7 +513,7 @@ int main(int argc, char *argv[])
}
}
if (!getrlimit(RLIMIT_NOFILE, &limit) && limit.rlim_cur < rlim_min) {
if (getrlimit(RLIMIT_NOFILE, &limit) == 0 && limit.rlim_cur < rlim_min) {
log_write(LOG_LEVEL_WARNING,
"Current limit on the number of files this process can open (%ju) is rather low for the proper functioning of the TCP server. "
"Consider raising the limit to at least %ju or the recommended %ju. "
@ -537,7 +535,7 @@ int main(int argc, char *argv[])
}
}
if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6)) {
if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6 != 0)) {
log_write(LOG_LEVEL_INFO, "List of bootstrap nodes read successfully.\n");
} else {
log_write(LOG_LEVEL_ERROR, "Couldn't read list of bootstrap nodes in %s. Exiting.\n", cfg_file_path);
@ -559,11 +557,11 @@ int main(int argc, char *argv[])
uint64_t last_lan_discovery = 0;
const uint16_t net_htons_port = net_htons(start_port);
int waiting_for_dht_connection = 1;
bool waiting_for_dht_connection = true;
Broadcast_Info *broadcast = nullptr;
if (enable_lan_discovery) {
if (enable_lan_discovery != 0) {
broadcast = lan_discovery_init(ns);
log_write(LOG_LEVEL_INFO, "Initialized LAN discovery successfully.\n");
}
@ -578,25 +576,25 @@ int main(int argc, char *argv[])
// Prevent the signal handler from being called again before it returns
sigfillset(&sa.sa_mask);
if (sigaction(SIGINT, &sa, nullptr)) {
if (sigaction(SIGINT, &sa, nullptr) != 0) {
log_write(LOG_LEVEL_WARNING, "Couldn't set signal handler for SIGINT. Continuing without the signal handler set.\n");
}
if (sigaction(SIGTERM, &sa, nullptr)) {
if (sigaction(SIGTERM, &sa, nullptr) != 0) {
log_write(LOG_LEVEL_WARNING, "Couldn't set signal handler for SIGTERM. Continuing without the signal handler set.\n");
}
while (!caught_signal) {
while (caught_signal == 0) {
mono_time_update(mono_time);
do_dht(dht);
if (enable_lan_discovery && mono_time_is_timeout(mono_time, last_lan_discovery, LAN_DISCOVERY_INTERVAL)) {
if (enable_lan_discovery != 0 && mono_time_is_timeout(mono_time, last_lan_discovery, LAN_DISCOVERY_INTERVAL)) {
lan_discovery_send(dht_get_net(dht), broadcast, dht_get_self_public_key(dht), net_htons_port);
last_lan_discovery = mono_time_get(mono_time);
}
if (enable_tcp_relay) {
if (enable_tcp_relay != 0) {
do_tcp_server(tcp_server, mono_time);
}
@ -604,7 +602,7 @@ int main(int argc, char *argv[])
if (waiting_for_dht_connection && dht_isconnected(dht)) {
log_write(LOG_LEVEL_INFO, "Connected to another bootstrap node successfully.\n");
waiting_for_dht_connection = 0;
waiting_for_dht_connection = false;
}
sleep_milliseconds(30);

View File

@ -2,6 +2,6 @@ module github.com/TokTok/c-toxcore/other/bootstrap_daemon/websocket/websockify
go 1.17
require (
github.com/gorilla/websocket master
)
require github.com/gorilla/websocket v1.5.1
require golang.org/x/net v0.17.0 // indirect

View File

@ -0,0 +1,42 @@
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -18,6 +18,7 @@ package main
import (
"encoding/hex"
"flag"
"fmt"
"log"
"net"
"net/http"
@ -104,7 +105,10 @@ func main() {
if r.Header.Get("Upgrade") == "websocket" {
serveWs(w, r)
} else {
http.ServeFile(w, r, r.URL.Path[1:])
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "404 Not Found")
}
})
log.Fatal(http.ListenAndServe(*sourceAddr, nil))

View File

@ -35,7 +35,7 @@ static int handle_info_request(void *object, const IP_Port *source, const uint8_
uint8_t data[1 + sizeof(bootstrap_version) + MAX_MOTD_LENGTH];
data[0] = BOOTSTRAP_INFO_PACKET_ID;
memcpy(data + 1, &bootstrap_version, sizeof(bootstrap_version));
uint16_t len = 1 + sizeof(bootstrap_version) + bootstrap_motd_length;
const uint16_t len = 1 + sizeof(bootstrap_version) + bootstrap_motd_length;
memcpy(data + 1 + sizeof(bootstrap_version), bootstrap_motd, bootstrap_motd_length);
if (sendpacket(nc, source, data, len) == len) {

View File

@ -1,5 +1,6 @@
################################################
# autotools-linux
FROM toxchat/c-toxcore:sources AS sources
FROM ubuntu:22.04
RUN apt-get update && \
@ -24,7 +25,12 @@ USER builder
WORKDIR /home/builder
# Copy the sources and run the build.
# Copy autotools-specific build scripts not present in the sources image.
# These change less frequently than the sources, thus are copied first.
COPY --chown=builder:builder . /home/builder/c-toxcore/
# Copy the sources and run the build.
COPY --chown=builder:builder --from=sources /src/ /home/builder/c-toxcore/
WORKDIR /home/builder/c-toxcore
RUN CC=gcc .github/scripts/autotools-linux

View File

@ -0,0 +1,12 @@
**/*
!.github/scripts/autotools-linux
!m4/*
!configure.ac
!*.pc.in
!*.spec.in
!**/Makefile.am
!**/Makefile.inc
!docs/updates/*
!other/DHTnodes
!other/astyle/*
!other/tox.png

View File

@ -2,4 +2,5 @@
set -eux
BUILD=autotools
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
other/docker/sources/build
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .

View File

@ -1,3 +1,4 @@
FROM toxchat/c-toxcore:sources AS sources
FROM alpine:3.19.0
RUN ["apk", "add", "--no-cache", \
@ -16,6 +17,8 @@ RUN ["apk", "add", "--no-cache", \
ENV CC=clang CXX=clang++
COPY . /c-toxcore/
COPY --from=sources /src/ /c-toxcore/
COPY other/analysis/run-clang-tidy other/analysis/variants.sh /c-toxcore/other/analysis/
COPY .clang-tidy /c-toxcore/
WORKDIR /c-toxcore
RUN other/analysis/run-clang-tidy

View File

@ -2,4 +2,5 @@
set -eux
BUILD=clang-tidy
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
other/docker/sources/build
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .

1
other/docker/compcert/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
!/Makefile

View File

@ -1,30 +0,0 @@
FROM toxchat/compcert:latest
WORKDIR /work
COPY auto_tests/ /work/auto_tests/
COPY testing/ /work/testing/
COPY toxav/ /work/toxav/
COPY toxcore/ /work/toxcore/
COPY toxencryptsave/ /work/toxencryptsave/
COPY third_party/ /work/third_party/
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN ccomp \
-o send_message_test \
-Wall -Werror \
-Wno-c11-extensions \
-Wno-unknown-pragmas \
-Wno-unused-variable \
-fstruct-passing -fno-unprototyped -g \
auto_tests/auto_test_support.c \
auto_tests/send_message_test.c \
testing/misc_tools.c \
toxav/*.c \
toxcore/*.c \
toxcore/*/*.c \
toxencryptsave/*.c \
third_party/cmp/*.c \
-D__COMPCERT__ -DDISABLE_VLA -Dinline= \
-lpthread $(pkg-config --cflags --libs libsodium opus vpx) \
&& ./send_message_test | grep 'tox clients connected'

View File

@ -0,0 +1,39 @@
CC := ccomp
CFLAGS := -Wall \
-Wno-c11-extensions \
-Wno-unknown-pragmas \
-Wno-unused-variable \
-fstruct-passing -fno-unprototyped -g \
-Ilibsodium/src/libsodium/include \
$(shell pkg-config --cflags opus vpx)
LDFLAGS := -lpthread $(shell pkg-config --libs opus vpx)
libsodium_SOURCES := $(shell find libsodium/src/libsodium -name "*.c")
libsodium_OBJECTS := $(libsodium_SOURCES:.c=.o)
$(libsodium_OBJECTS): CFLAGS += \
-DDEV_MODE \
-DCONFIGURED \
-D_DEFAULT_SOURCE \
-Ilibsodium/builds/msvc \
-Ilibsodium/src/libsodium/include/sodium
toxcore_SOURCES := $(wildcard \
auto_tests/auto_test_support.c \
auto_tests/send_message_test.c \
testing/misc_tools.c \
toxav/*.c \
toxcore/*.c \
toxcore/*/*.c \
toxencryptsave/*.c \
third_party/cmp/*.c)
toxcore_OBJECTS := $(toxcore_SOURCES:.c=.o)
$(toxcore_OBJECTS): CFLAGS += \
-Werror \
-D__COMPCERT__ \
-DDISABLE_VLA \
-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE \
-Dinline= \
send_message_test: $(libsodium_OBJECTS) $(toxcore_OBJECTS)
$(CC) -o $@ $+ $(LDFLAGS)

View File

@ -0,0 +1,19 @@
FROM toxchat/c-toxcore:sources AS sources
FROM toxchat/compcert:latest
RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
gdb \
make \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /work
COPY --from=sources /src/ /work/
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN git clone --depth=1 https://github.com/jedisct1/libsodium /work/libsodium
COPY other/docker/compcert/Makefile /work/
RUN make "-j$(nproc)"
RUN ./send_message_test | grep 'tox clients connected'

View File

@ -2,4 +2,5 @@
set -eux
BUILD=compcert
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
other/docker/sources/build
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .

View File

@ -1,4 +1,4 @@
FROM toxchat/c-toxcore:sources AS src
FROM toxchat/c-toxcore:sources AS sources
FROM ubuntu:20.04 AS build
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
@ -41,7 +41,7 @@ ENV CC=clang-17 \
PYTHONUNBUFFERED=1 \
PATH=$PATH:/usr/lib/go-1.18/bin
COPY --from=src /src/ /work/
COPY --from=sources /src/ /work/
WORKDIR /work
RUN git clone --depth=1 https://github.com/TokTok/toktok-fuzzer /work/testing/fuzzing/toktok-fuzzer

View File

@ -4,6 +4,8 @@ set -eux
read -a ci_env <<<"$(bash <(curl -s https://codecov.io/env))"
docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile .
docker build -t toxchat/c-toxcore:coverage -f other/docker/coverage/Dockerfile .
BUILD=coverage
other/docker/sources/build
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .
docker run "${ci_env[@]}" -e CI=true --name toxcore-coverage --rm -t toxchat/c-toxcore:coverage /usr/local/bin/codecov

View File

@ -2,7 +2,9 @@
set -eux
docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile .
docker build -t toxchat/c-toxcore:coverage -f other/docker/coverage/Dockerfile .
docker build -t toxchat/c-toxcore:coverage-nginx -f other/docker/coverage/Dockerfile.nginx other/docker/coverage
BUILD=coverage
other/docker/sources/build
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .
docker build -t toxchat/c-toxcore:coverage-nginx -f other/docker/coverage/nginx.Dockerfile other/docker/coverage
docker run --name toxcore-coverage --rm -it -p "28192:80" toxchat/c-toxcore:coverage-nginx

View File

@ -1,30 +0,0 @@
FROM alpine:3.19.0
RUN ["apk", "add", "--no-cache", \
"bash", \
"cppcheck", \
"findutils", \
"libconfig-dev", \
"libsodium-dev", \
"libvpx-dev", \
"linux-headers", \
"make", \
"opus-dev"]
COPY other/bootstrap_daemon/ /src/workspace/c-toxcore/other/bootstrap_daemon/
COPY other/bootstrap_node_packets.* /src/workspace/c-toxcore/other/
COPY other/fun/ /src/workspace/c-toxcore/other/fun/
COPY auto_tests/check_compat.h /src/workspace/c-toxcore/auto_tests/
COPY testing/ /src/workspace/c-toxcore/testing/
COPY toxav/ /src/workspace/c-toxcore/toxav/
COPY toxcore/ /src/workspace/c-toxcore/toxcore/
COPY toxencryptsave/ /src/workspace/c-toxcore/toxencryptsave/
COPY third_party/cmp/cmp.h /src/workspace/c-toxcore/third_party/cmp/
COPY other/analysis/run-cppcheck \
other/analysis/gen-file.sh \
other/analysis/variants.sh \
/src/workspace/c-toxcore/other/analysis/
COPY other/docker/cppcheck/toxcore.cfg \
/src/workspace/c-toxcore/other/docker/cppcheck/
WORKDIR /src/workspace/c-toxcore
RUN ["other/analysis/run-cppcheck"]

View File

@ -0,0 +1,23 @@
FROM toxchat/c-toxcore:sources AS sources
FROM alpine:3.19.0
RUN ["apk", "add", "--no-cache", \
"bash", \
"cppcheck", \
"findutils", \
"libconfig-dev", \
"libsodium-dev", \
"libvpx-dev", \
"linux-headers", \
"make", \
"opus-dev"]
COPY --from=sources /src/ /src/workspace/c-toxcore/
COPY other/analysis/run-cppcheck \
other/analysis/gen-file.sh \
other/analysis/variants.sh \
/src/workspace/c-toxcore/other/analysis/
COPY other/docker/cppcheck/toxcore.cfg \
/src/workspace/c-toxcore/other/docker/cppcheck/
WORKDIR /src/workspace/c-toxcore
RUN ["other/analysis/run-cppcheck"]

View File

@ -2,4 +2,5 @@
set -eux
BUILD=cppcheck
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
other/docker/sources/build
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .

View File

@ -1,18 +0,0 @@
FROM alpine:latest AS build
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US.UTF-8 \
LC_CTYPE=en_US.UTF-8 \
LC_ALL=en_US.UTF-8
RUN apk add --no-cache doxygen git graphviz texlive \
&& git clone --depth=1 https://github.com/jothepro/doxygen-awesome-css.git /work/doxygen-awesome-css
WORKDIR /work
COPY . /work/
RUN cat docs/Doxyfile > Doxyfile \
&& echo "WARN_AS_ERROR = YES" >> Doxyfile \
&& sed -i -e 's/^non_null([^)]*) *//;s/^nullable([^)]*) *//' $(find . -name "*.[ch]") \
&& doxygen Doxyfile
FROM nginx:alpine
COPY --from=build /work/_docs/html/ /usr/share/nginx/html/

View File

@ -0,0 +1,2 @@
# ===== custom =====
!docs/Doxyfile

View File

@ -0,0 +1,20 @@
FROM toxchat/doxygen:latest AS build
RUN ["apk", "add", "--no-cache", \
"gtest-dev", \
"libconfig-dev", \
"libsodium-dev", \
"libvpx-dev", \
"opus-dev"]
RUN git clone --depth=1 https://github.com/jothepro/doxygen-awesome-css.git /work/c-toxcore/doxygen-awesome-css
WORKDIR /work/c-toxcore
COPY . /work/c-toxcore/
RUN cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
&& echo "WARN_AS_ERROR = YES" >> Doxyfile \
&& sed -i -e 's/^non_null([^)]*) *//;s/^nullable([^)]*) *//' $(find . -name "*.[ch]") \
&& doxygen docs/Doxyfile
FROM nginx:alpine
COPY --from=build /work/c-toxcore/_docs/html/ /usr/share/nginx/html/

View File

@ -0,0 +1,25 @@
# ===== common =====
# Ignore everything ...
**/*
# ... except sources
!**/*.[ch]
!**/*.cc
!**/*.hh
!CHANGELOG.md
!LICENSE
!README.md
!auto_tests/data/*
!other/bootstrap_daemon/bash-completion/**
!other/bootstrap_daemon/tox-bootstrapd.*
!other/proxy/*.mod
!other/proxy/*.sum
!other/proxy/*.go
# ... and CMake build files (used by most builds).
!**/CMakeLists.txt
!.github/scripts/flags*.sh
!cmake/*.cmake
!other/pkgconfig/*
!other/rpm/*
!so.version
# ===== custom =====
!docs/Doxyfile

View File

@ -1,6 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
set -eux
docker build -t toxchat/c-toxcore:docs -f other/docker/doxygen/Dockerfile .
docker run --name toxcore-docs --rm -it -p "28192:80" toxchat/c-toxcore:docs
. "$(cd "$(dirname "${BASH_SOURCE[0]}")/../sources" && pwd)/run.sh"
docker run --name toxcore-doxygen --rm -it -p "28192:80" "toxchat/c-toxcore:$BUILD"

View File

@ -2,4 +2,4 @@
set -eux
BUILD=freebsd
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .

View File

@ -0,0 +1,8 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "sodium",
testonly = True,
srcs = ["sodium.c"],
deps = ["@libsodium"],
)

View File

@ -0,0 +1,43 @@
{
"ana": {
"activated": [
"base","mallocWrapper","escape","mutex","mutexEvents","access","assert","expRelation"
],
"arrayoob": true,
"wp": true,
"apron": {
"strengthening": true
},
"base": {
"structs" : {
"domain" : "combined-sk"
},
"arrays": {
"domain": "partitioned"
}
},
"malloc": {
"wrappers": [
"mem_balloc",
"mem_alloc",
"mem_valloc",
"mem_vrealloc"
]
}
},
"warn": {
"behavior": false,
"call": false,
"integer": true,
"float": false,
"race": false,
"deadcode": false,
"unsound": false,
"imprecise": false,
"success": false,
"unknown": false
},
"exp": {
"earlyglobs": true
}
}

View File

@ -0,0 +1,21 @@
FROM toxchat/c-toxcore:sources AS sources
FROM ghcr.io/goblint/analyzer:latest
RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
libsodium-dev \
tcc \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /work
COPY --from=sources /src/ /work/
COPY other/make_single_file /work/other/
RUN other/make_single_file -core auto_tests/tox_new_test.c other/docker/goblint/sodium.c > analysis.c
# Try compiling+linking just to make sure we have all the fake functions.
RUN tcc analysis.c
COPY other/docker/goblint/analysis.json /work/other/docker/goblint/
RUN /opt/goblint/analyzer/bin/goblint --conf /work/other/docker/goblint/analysis.json analysis.c

6
other/docker/goblint/run Executable file
View File

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

View File

@ -0,0 +1,112 @@
#include <sodium.h>
#include <string.h>
int crypto_sign_seed_keypair(unsigned char *pk, unsigned char *sk, const unsigned char *seed)
{
memset(pk, 0, 32);
memset(sk, 0, 32);
return 0;
}
int crypto_sign_ed25519_pk_to_curve25519(unsigned char *curve25519_pk,
const unsigned char *ed25519_pk)
{
memset(curve25519_pk, 0, 32);
return 0;
}
int crypto_sign_ed25519_sk_to_curve25519(unsigned char *curve25519_sk,
const unsigned char *ed25519_sk)
{
memset(curve25519_sk, 0, 32);
return 0;
}
void sodium_memzero(void *const pnt, const size_t len)
{
memset(pnt, 0, len);
}
int sodium_mlock(void *const addr, const size_t len)
{
return 0;
}
int sodium_munlock(void *const addr, const size_t len)
{
return 0;
}
int crypto_verify_32(const unsigned char *x, const unsigned char *y)
{
return memcmp(x, y, 32);
}
int crypto_verify_64(const unsigned char *x, const unsigned char *y)
{
return memcmp(x, y, 64);
}
int crypto_sign_detached(unsigned char *sig, unsigned long long *siglen_p,
const unsigned char *m, unsigned long long mlen,
const unsigned char *sk)
{
return 0;
}
int crypto_sign_verify_detached(const unsigned char *sig,
const unsigned char *m,
unsigned long long mlen,
const unsigned char *pk)
{
return 0;
}
int crypto_box_beforenm(unsigned char *k, const unsigned char *pk,
const unsigned char *sk)
{
memset(k, 0, 32);
return 0;
}
int crypto_box_afternm(unsigned char *c, const unsigned char *m,
unsigned long long mlen, const unsigned char *n,
const unsigned char *k)
{
memset(c, 0, 32);
return 0;
}
int crypto_box_open_afternm(unsigned char *m, const unsigned char *c,
unsigned long long clen, const unsigned char *n,
const unsigned char *k)
{
return 0;
}
int crypto_scalarmult_curve25519_base(unsigned char *q,
const unsigned char *n)
{
memset(q, 0, 32);
return 0;
}
int crypto_auth(unsigned char *out, const unsigned char *in,
unsigned long long inlen, const unsigned char *k)
{
return 0;
}
int crypto_auth_verify(const unsigned char *h, const unsigned char *in,
unsigned long long inlen, const unsigned char *k)
{
return 0;
}
int crypto_hash_sha256(unsigned char *out, const unsigned char *in,
unsigned long long inlen)
{
return 0;
}
int crypto_hash_sha512(unsigned char *out, const unsigned char *in,
unsigned long long inlen)
{
return 0;
}
void randombytes(unsigned char *const buf, const unsigned long long buf_len)
{
memset(buf, 0, buf_len);
}
uint32_t randombytes_uniform(const uint32_t upper_bound)
{
return upper_bound;
}
int sodium_init(void)
{
return 0;
}

View File

@ -1,9 +1,7 @@
FROM toxchat/c-toxcore:sources AS sources
FROM toxchat/infer:latest
COPY toxav/ /work/c-toxcore/toxav/
COPY toxcore/ /work/c-toxcore/toxcore/
COPY toxencryptsave/ /work/c-toxcore/toxencryptsave/
COPY third_party/ /work/c-toxcore/third_party/
COPY --from=sources /src/ /work/c-toxcore/
RUN infer capture -- clang++ -fsyntax-only \
$(pkg-config --cflags libconfig libsodium opus vpx) \
/work/c-toxcore/toxav/*.c \

View File

@ -2,4 +2,5 @@
set -eux
BUILD=infer
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
other/docker/sources/build
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .

View File

@ -126,11 +126,6 @@ SUPPRESSIONS += 19.2
#
# Reason: We believe it should be used when #define is used in block scope.
SUPPRESSIONS += 20.5
# The # and ## preprocessor operators should not be used.
#
# TODO(iphydf): Remove suppression when VLAs are gone. This is only used in
# the SIZEOF_VLA macro.
SUPPRESSIONS += 20.10
# #define and #undef shall not be used on a reserved identifier or reserved macro name.
#
# Reason: Needed for feature test macros like _DEFAULT_SOURCE.
@ -160,7 +155,12 @@ SUPPRESSIONS += 21.10
CPPFLAGS := -DCMP_NO_FLOAT=1 -DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE
SOURCES := $(shell find /src/workspace/c-toxcore -name "*.c")
FIND_FLAGS := -name "*.c" \
-and -not -wholename "*/auto_tests/*" \
-and -not -wholename "*/other/*" \
-and -not -wholename "*/super_donators/*" \
-and -not -wholename "*/third_party/*"
SOURCES := $(shell find /src/workspace/c-toxcore $(FIND_FLAGS))
analyse: $(DUMPS:.dump=.diag)
cppcheck --error-exitcode=1 -j8 --addon=misra --suppress=doubleFree $(patsubst %,--suppress=misra-c2012-%,$(SUPPRESSIONS)) $(CPPFLAGS) $(SOURCES)

View File

@ -1,3 +1,4 @@
FROM toxchat/c-toxcore:sources AS sources
FROM ubuntu:20.04
RUN apt-get update && \
@ -12,10 +13,7 @@ RUN apt-get update && \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY toxav/ /src/workspace/c-toxcore/toxav/
COPY toxcore/ /src/workspace/c-toxcore/toxcore/
COPY toxencryptsave/ /src/workspace/c-toxcore/toxencryptsave/
COPY third_party/cmp/cmp.h /src/workspace/c-toxcore/third_party/cmp/cmp.h
COPY --from=sources /src/ /src/workspace/c-toxcore/
COPY other/docker/misra/Makefile /src/workspace/
WORKDIR /src/workspace
RUN ["make"]

View File

@ -2,4 +2,5 @@
set -eux
BUILD=misra
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
other/docker/sources/build
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .

225
other/docker/modules/check Executable file
View File

@ -0,0 +1,225 @@
#!/usr/bin/env python3
import glob
import os
import subprocess
import sys
from dataclasses import dataclass
from typing import Iterable
from typing import Optional
LIBS = {}
MODS = {}
STD_MODULE = """module std [system] {
textual header "/usr/include/alloca.h"
textual header "/usr/include/assert.h"
textual header "/usr/include/c++/13.2.1/algorithm"
textual header "/usr/include/c++/13.2.1/array"
textual header "/usr/include/c++/13.2.1/chrono"
textual header "/usr/include/c++/13.2.1/cstddef"
textual header "/usr/include/c++/13.2.1/cstdint"
textual header "/usr/include/c++/13.2.1/cstdio"
textual header "/usr/include/c++/13.2.1/cstdlib"
textual header "/usr/include/c++/13.2.1/cstring"
textual header "/usr/include/c++/13.2.1/iomanip"
textual header "/usr/include/c++/13.2.1/iosfwd"
textual header "/usr/include/c++/13.2.1/limits"
textual header "/usr/include/c++/13.2.1/memory"
textual header "/usr/include/c++/13.2.1/ostream"
textual header "/usr/include/c++/13.2.1/random"
textual header "/usr/include/c++/13.2.1/stdlib.h"
textual header "/usr/include/c++/13.2.1/thread"
textual header "/usr/include/c++/13.2.1/type_traits"
textual header "/usr/include/c++/13.2.1/vector"
textual header "/usr/include/errno.h"
textual header "/usr/include/fortify/stdio.h"
textual header "/usr/include/fortify/string.h"
textual header "/usr/include/fortify/unistd.h"
textual header "/usr/include/limits.h"
textual header "/usr/include/stdarg.h"
textual header "/usr/include/stdbool.h"
textual header "/usr/include/stddef.h"
textual header "/usr/include/stdint.h"
textual header "/usr/include/sys/time.h"
textual header "/usr/include/sys/types.h"
textual header "/usr/include/time.h"
}
module "//c-toxcore/third_party:cmp" {
header "third_party/cmp/cmp.h"
use std
}
module "//c-toxcore/toxencryptsave:defines" {
header "toxencryptsave/defines.h"
}
module "@com_google_googletest//:gtest" {
textual header "/usr/include/gmock/gmock.h"
textual header "/usr/include/gtest/gtest.h"
use std
}
module "@libsodium" {
textual header "/usr/include/sodium.h"
}
module "@pthread" {
textual header "/usr/include/pthread.h"
}
module "@psocket" {
textual header "/usr/include/arpa/inet.h"
textual header "/usr/include/fcntl.h"
textual header "/usr/include/fortify/sys/socket.h"
textual header "/usr/include/linux/if.h"
textual header "/usr/include/netdb.h"
textual header "/usr/include/netinet/in.h"
textual header "/usr/include/sys/epoll.h"
textual header "/usr/include/sys/ioctl.h"
}
"""
@dataclass
class Context:
pkg: str
pkg_prefix: str
def bzl_load(self, bzl: str, *syms: str) -> None:
pass
def bzl_exports_files(
self,
srcs: list[str],
visibility: Optional[list[str]] = None,
) -> None:
pass
def bzl_cc_library(
self,
name: str,
srcs: Iterable[str] = tuple(),
hdrs: Iterable[str] = tuple(),
deps: Iterable[str] = tuple(),
visibility: Iterable[str] = tuple(),
testonly: bool = False,
copts: Iterable[str] = tuple(),
) -> None:
LIBS[name] = {
"srcs":
srcs,
"deps": [
f"{self.pkg_prefix}{dep}" if dep[0] == ":" else dep
for dep in deps
],
"hdrs":
hdrs,
}
def bzl_cc_test(
self,
name: str,
srcs: Iterable[str] = tuple(),
hdrs: Iterable[str] = tuple(),
deps: Iterable[str] = tuple(),
**kwargs: list[str],
) -> None:
LIBS[name] = {
"srcs":
srcs,
"deps": [
f"{self.pkg_prefix}{dep}" if dep[0] == ":" else dep
for dep in deps
],
"hdrs":
hdrs,
}
def bzl_cc_fuzz_test(self, name: str, **kwargs: list[str]) -> None:
pass
def bzl_select(self, selector: dict[str, list[str]]) -> list[str]:
return selector["//tools/config:linux"]
def bzl_glob(self, include: list[str]) -> list[str]:
return [
f[len(self.pkg) + 1:] for p in include
for f in glob.glob(os.path.join(self.pkg, p))
]
def bzl_alias(self, name: str, actual: str, visibility: list[str]) -> None:
pass
def bzl_sh_library(self, name: str, **kwargs: list[str]) -> None:
pass
def main() -> None:
srcs: list[str] = []
for pkg in ("toxcore", ):
# TODO(iphydf): Why does this break everything?
# ctx = Context(pkg, "//c-toxcore/{pkg}")
ctx = Context(pkg, "")
with open(os.path.join(pkg, "BUILD.bazel"), "r") as fh:
exec(
fh.read(),
{
"load": ctx.bzl_load,
"exports_files": ctx.bzl_exports_files,
"cc_library": ctx.bzl_cc_library,
"cc_test": ctx.bzl_cc_test,
"cc_fuzz_test": ctx.bzl_cc_fuzz_test,
"select": ctx.bzl_select,
"glob": ctx.bzl_glob,
"alias": ctx.bzl_alias,
"sh_library": ctx.bzl_sh_library,
},
)
with open("module.modulemap", "w") as fh:
fh.write(STD_MODULE)
for name, lib in LIBS.items():
fh.write(f'module "{ctx.pkg_prefix}:{name}"' + " {\n")
for hdr in lib["hdrs"]:
fh.write(f' header "{pkg}/{hdr}"\n')
fh.write(f" use std\n")
for dep in lib.get("deps", []):
fh.write(f' use "{dep}"\n')
fh.write("}\n")
for name, lib in LIBS.items():
for src in lib.get("srcs", []):
MODS[os.path.join(pkg, src)] = name
srcs.extend(
os.path.join(pkg, src) # just within a package for now
for lib in LIBS.values() for src in lib.get("srcs", []))
# subprocess.run(["cat", "module.modulemap"], check=True)
for src in sorted(
set(srcs) - set([
# TODO(iphydf): Figure out what's wrong here.
"toxcore/crypto_core_test.cc",
"toxcore/group_announce_test.cc",
"toxcore/group_moderation_test.cc",
"toxcore/mono_time_test.cc",
"toxcore/network_test.cc",
"toxcore/ping_array_test.cc",
"toxcore/util_test.cc",
])):
print(f"Validating {src}", file=sys.stderr)
subprocess.run(
[
"clang",
"-fsyntax-only",
"-xc++",
"-Wall",
"-Werror",
"-Wno-missing-braces",
"-DTCP_SERVER_USE_EPOLL",
"-std=c++23",
"-fdiagnostics-color=always",
"-fmodules",
"-fmodules-strict-decluse",
"-fmodule-map-file=module.modulemap",
f"-fmodule-name={ctx.pkg_prefix}:{MODS[src]}",
src,
],
check=True,
)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,21 @@
FROM toxchat/c-toxcore:sources AS sources
FROM alpine:3.19.0
RUN ["apk", "add", "--no-cache", \
"bash", \
"clang", \
"gtest-dev", \
"libconfig-dev", \
"libsodium-dev", \
"libvpx-dev", \
"linux-headers", \
"opus-dev", \
"pkgconfig", \
"python3"]
WORKDIR /work
COPY --from=sources /src/ /work/
COPY toxcore/BUILD.bazel /work/toxcore/
COPY other/docker/modules/check /work/other/docker/modules/
RUN ["other/docker/modules/check"]

6
other/docker/modules/run Executable file
View File

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

View File

@ -0,0 +1,10 @@
FROM toxchat/pkgsrc:latest
WORKDIR /work
COPY . /work/c-toxcore-0.2.18
RUN ["tar", "zcf", "c-toxcore.tar.gz", "c-toxcore-0.2.18"]
WORKDIR /work/pkgsrc/chat/toxcore
RUN ["bmake", "clean"]
RUN ["bmake", "DISTFILES=c-toxcore.tar.gz", "DISTDIR=/work", "NO_CHECKSUM=yes"]
RUN ["bmake", "install"]

View File

@ -0,0 +1,23 @@
# ===== common =====
# Ignore everything ...
**/*
# ... except sources
!**/*.[ch]
!**/*.cc
!**/*.hh
!CHANGELOG.md
!LICENSE
!README.md
!auto_tests/data/*
!other/bootstrap_daemon/bash-completion/**
!other/bootstrap_daemon/tox-bootstrapd.*
!other/proxy/*.mod
!other/proxy/*.sum
!other/proxy/*.go
# ... and CMake build files (used by most builds).
!**/CMakeLists.txt
!.github/scripts/flags*.sh
!cmake/*.cmake
!other/pkgconfig/*
!other/rpm/*
!so.version

3
other/docker/pkgsrc/run Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")/../sources" && pwd)/run.sh"

View File

@ -0,0 +1,47 @@
FROM toxchat/c-toxcore:sources AS sources
FROM fedora:39
RUN ["dnf", "install", "-y", \
"cmake", \
"g++", \
"gcc", \
"git", \
"libconfig-devel", \
"libsodium-devel", \
"libvpx-devel", \
"make", \
"opus-devel", \
"rpmdevtools", \
"rpmlint", \
"systemd-units"]
ARG PROJECT_VERSION=master
ARG PROJECT_COMMIT_ID=master
ARG PROJECT_COMMIT_ID_SHORT=master
COPY --from=sources /src/ /work/c-toxcore-${PROJECT_COMMIT_ID}
WORKDIR /work/c-toxcore-${PROJECT_COMMIT_ID}/other/rpm
RUN make toxcore.spec \
PROJECT_VERSION="$PROJECT_VERSION" \
PROJECT_COMMIT_ID="$PROJECT_COMMIT_ID" \
PROJECT_COMMIT_ID_SHORT="$PROJECT_COMMIT_ID_SHORT" \
PROJECT_GIT_ROOT="/work/c-toxcore-$PROJECT_COMMIT_ID_SHORT"
WORKDIR /work
RUN tar zcf "c-toxcore-${PROJECT_COMMIT_ID_SHORT}.tar.gz" "c-toxcore-${PROJECT_COMMIT_ID}" \
&& mv "c-toxcore-${PROJECT_COMMIT_ID_SHORT}.tar.gz" "c-toxcore-${PROJECT_COMMIT_ID}/other/rpm"
WORKDIR /work/c-toxcore-${PROJECT_COMMIT_ID}/other/rpm
RUN make srpm \
PROJECT_VERSION="$PROJECT_VERSION" \
PROJECT_COMMIT_ID="$PROJECT_COMMIT_ID" \
PROJECT_COMMIT_ID_SHORT="$PROJECT_COMMIT_ID_SHORT" \
PROJECT_GIT_ROOT="$PROJECT_GIT_ROOT"
# Build the binary rpms.
RUN rpmbuild --rebuild "toxcore-${PROJECT_VERSION}-1.fc39.src.rpm"
# Install them and try running the bootstrap daemon.
RUN rpm -i /root/rpmbuild/RPMS/x86_64/*.rpm
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN script tox-bootstrapd --help | grep Usage

13
other/docker/rpm/run Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
set -eux
PROJECT_VERSION="$(git describe | sed -e 's/^v//' -e 's/-/_/g')"
PROJECT_COMMIT_ID="$(git rev-parse HEAD)"
PROJECT_COMMIT_ID_SHORT="$(git rev-parse --short HEAD)"
BUILD=rpm
other/docker/sources/build
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" . \
--build-arg="PROJECT_VERSION=$PROJECT_VERSION" \
--build-arg="PROJECT_COMMIT_ID=$PROJECT_COMMIT_ID" \
--build-arg="PROJECT_COMMIT_ID_SHORT=$PROJECT_COMMIT_ID_SHORT"

1
other/docker/slimcc/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
!/Makefile

View File

@ -0,0 +1,13 @@
SOURCES := auto_tests/send_message_test.c \
auto_tests/auto_test_support.c \
testing/misc_tools.c \
$(wildcard tox*/*.c tox*/*/*.c) \
third_party/cmp/cmp.c
OBJECTS := $(SOURCES:.c=.o)
CC := /work/slimcc/slimcc
CFLAGS := $(shell pkg-config --cflags libsodium opus vpx)
LDFLAGS := $(shell pkg-config --libs libsodium opus vpx)
send_message_test: $(OBJECTS)
$(CC) -o $@ $+ $(LDFLAGS)

6
other/docker/slimcc/creduce.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
if ! gcc -I/work/c-toxcore/toxcore -fsyntax-only crash.c; then
exit 1
fi
/work/slimcc/slimcc -I/work/c-toxcore/toxcore -c crash.c 2>&1 | grep "file_exists: Assertion"

6
other/docker/slimcc/run Executable file
View File

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

View File

@ -0,0 +1,44 @@
FROM toxchat/c-toxcore:sources AS sources
FROM ubuntu:22.04
RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
ca-certificates \
gcc \
git \
libc-dev \
libopus-dev \
libsodium-dev \
libvpx-dev \
make \
pkg-config \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Uncomment this to find bugs in slimcc using creduce.
#RUN apt-get update && \
# DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
# creduce \
# && apt-get clean \
# && rm -rf /var/lib/apt/lists/*
WORKDIR /work/slimcc
RUN ["git", "clone", "https://github.com/fuhsnn/slimcc", "/work/slimcc"]
# Comment this to checkout master (e.g. to find bugs using creduce).
RUN ["git", "checkout", "ac9ddf4d39642e6b4880b1a73e19c6f2769d857e"]
RUN ["make", "CFLAGS=-O3", "-j4"]
WORKDIR /work/c-toxcore
COPY --from=sources /src/ /work/c-toxcore
# Uncomment this to find bugs in slimcc using creduce.
#COPY other/docker/slimcc/creduce.sh /work/c-toxcore/other/docker/slimcc/
#RUN cp toxcore/ccompat.h crash.c \
# && other/docker/slimcc/creduce.sh \
# && creduce other/docker/slimcc/creduce.sh crash.c
COPY other/docker/slimcc/Makefile /work/c-toxcore/
RUN ["make"]
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN ./send_message_test | grep "tox clients connected"

View File

@ -1,17 +0,0 @@
FROM scratch
# Roughly in order of change frequency.
COPY third_party/ /src/third_party/
COPY .github/scripts/flags*.sh /src/.github/scripts/
COPY other/proxy/ /src/other/proxy/
COPY cmake/ /src/cmake/
COPY other/bootstrap_daemon/ /src/other/bootstrap_daemon/
COPY other/pkgconfig/ /src/other/pkgconfig/
COPY other/rpm/ /src/other/rpm/
COPY other/*.[ch] /src/other/
COPY CMakeLists.txt so.version /src/
COPY toxencryptsave/ /src/toxencryptsave/
COPY testing/ /src/testing/
COPY toxav/ /src/toxav/
COPY toxcore/ /src/toxcore/
COPY auto_tests/ /src/auto_tests/

5
other/docker/sources/build Executable file
View File

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

View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Common docker build script usable by many builds in the other/docker
# directory. We're using a common dockerignore that ignores everything except
# sources and CMake scripts. Subdirectories can contain a "dockerignore" file
# (note the missing "." at the start) that will be pasted to the end of the
# common dockerignore file. This way, we can use "COPY ." and get all the
# files we need at once, which is much faster, more flexible, and less
# error-prone than manually writing lots of COPY directives.
SOURCESDIR="$(dirname "${BASH_SOURCE[0]}")"
DOCKERDIR="$(dirname "${BASH_SOURCE[1]}")"
BUILD="$(basename "$DOCKERDIR")"
set -eux
cat "$SOURCESDIR/sources.Dockerfile.dockerignore" >"$DOCKERDIR/$BUILD.Dockerfile.dockerignore"
if [ -f "$DOCKERDIR/dockerignore" ]; then
cat "$DOCKERDIR/dockerignore" >>"$DOCKERDIR/$BUILD.Dockerfile.dockerignore"
fi
docker build "${DOCKERFLAGS[@]}" -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .

View File

@ -0,0 +1,2 @@
FROM scratch
COPY . /src/

View File

@ -0,0 +1,23 @@
# ===== common =====
# Ignore everything ...
**/*
# ... except sources
!**/*.[ch]
!**/*.cc
!**/*.hh
!CHANGELOG.md
!LICENSE
!README.md
!auto_tests/data/*
!other/bootstrap_daemon/bash-completion/**
!other/bootstrap_daemon/tox-bootstrapd.*
!other/proxy/*.mod
!other/proxy/*.sum
!other/proxy/*.go
# ... and CMake build files (used by most builds).
!**/CMakeLists.txt
!.github/scripts/flags*.sh
!cmake/*.cmake
!other/pkgconfig/*
!other/rpm/*
!so.version

1
other/docker/sparse/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
!/Makefile

View File

@ -0,0 +1,70 @@
SOURCES := $(wildcard tox*/*.c tox*/*/*.c) \
third_party/cmp/cmp.c
OBJECTS := $(SOURCES:.c=.o)
CFLAGS := $(shell pkg-config --cflags libsodium opus vpx)
CPPFLAGS := -DSPARSE -DTCP_SERVER_USE_EPOLL=1 -DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE
SPARSE_FLAGS := \
-Wsparse-error \
-Wpedantic \
-Waddress \
-Waddress-space \
-Wbitwise \
-Wbitwise-pointer \
-Wcast-from-as \
-Wcast-to-as \
-Wcast-truncate \
-Wconstant-suffix \
-Wconstexpr-not-const \
-Wcontext \
-Wdecl \
-Wdefault-bitfield-sign \
-Wdesignated-init \
-Wdo-while \
-Wenum-mismatch \
-Wexternal-function-has-definition \
-Wflexible-array-array \
-Wflexible-array-nested \
-Wflexible-array-union \
-Wimplicit-int \
-Winit-cstring \
-Wint-to-pointer-cast \
-Wmemcpy-max-count \
-Wnon-pointer-null \
-Wnewline-eof \
-Wold-initializer \
-Wold-style-definition \
-Wone-bit-signed-bitfield \
-Woverride-init \
-Woverride-init-all \
-Wparen-string \
-Wpast-deep-designator \
-Wpedantic \
-Wpointer-to-int-cast \
-Wptr-subtraction-blows \
-Wreturn-void \
-Wshadow \
-Wshift-count-negative \
-Wshift-count-overflow \
-Wsizeof-bool \
-Wstrict-prototypes \
-Wpointer-arith \
-Wsparse-error \
-Wtautological-compare \
-Wtransparent-union \
-Wtypesign \
-Wundef \
-Wuninitialized \
-Wunion-cast \
-Wvla
SMATCH_FLAGS := $(foreach i,$(shell smatch --show-checks | grep -o 'check_.*'),--enable=$i)
analyse: $(OBJECTS)
%.o: %.c
@echo "Processing $<"
@sparse $(CFLAGS) $(CPPFLAGS) $(SPARSE_FLAGS) $<
# @smatch $(CFLAGS) $(CPPFLAGS) $(SMATCH_FLAGS) $<
# @sparse-llvm $(CFLAGS) $(CPPFLAGS) $< > /dev/null

View File

@ -0,0 +1 @@
CFLAGS=-O3 -g -Wno-discarded-qualifiers -Wno-format-truncation -Wno-stringop-truncation -Wno-uninitialized -Wno-unused -Wno-unused-result

6
other/docker/sparse/run Executable file
View File

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

View File

@ -0,0 +1,35 @@
FROM toxchat/c-toxcore:sources AS sources
FROM ubuntu:22.04
RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
ca-certificates \
creduce \
g++ \
gcc \
git \
libc-dev \
libopus-dev \
libsodium-dev \
libsqlite3-dev \
libssl-dev \
libvpx-dev \
llvm-dev \
make \
pkg-config \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /work/smatch
RUN git clone --depth=1 https://repo.or.cz/smatch.git /work/smatch
COPY other/docker/sparse/local.mk /work/smatch/local.mk
RUN make install -j4 PREFIX=/usr/local
WORKDIR /work/c-toxcore
COPY --from=sources /src/ /work/c-toxcore
#COPY other/make_single_file /work/c-toxcore/other/
#RUN other/make_single_file auto_tests/tox_new_test.c > crash.c
#RUN sparsec $(pkg-config --cflags --libs libsodium opus vpx) crash.c
COPY other/docker/sparse/Makefile /work/c-toxcore/
RUN make -j4

View File

@ -2,4 +2,5 @@
set -eux
BUILD=tcc
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
other/docker/sources/build
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .

View File

@ -1,3 +1,4 @@
FROM toxchat/c-toxcore:sources AS sources
FROM ubuntu:22.04
RUN apt-get update && \
@ -12,12 +13,7 @@ RUN apt-get update && \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /work
COPY auto_tests/ /work/auto_tests/
COPY testing/ /work/testing/
COPY toxav/ /work/toxav/
COPY toxcore/ /work/toxcore/
COPY toxencryptsave/ /work/toxencryptsave/
COPY third_party/ /work/third_party/
COPY --from=sources /src/ /work/
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

View File

@ -2,4 +2,5 @@
set -eux
BUILD=tokstyle
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
other/docker/sources/build
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/$BUILD.Dockerfile" .

View File

@ -1,3 +1,4 @@
FROM toxchat/c-toxcore:sources AS sources
FROM toxchat/haskell:hs-tokstyle AS tokstyle
FROM ubuntu:22.04
@ -15,8 +16,11 @@ RUN apt-get update && \
COPY --from=tokstyle /bin/check-c /bin/
RUN ["git", "clone", "--depth=1", "https://github.com/TokTok/hs-tokstyle", "/src/workspace/hs-tokstyle"]
COPY toxav/ /src/workspace/c-toxcore/toxav/
COPY toxcore/ /src/workspace/c-toxcore/toxcore/
COPY toxencryptsave/ /src/workspace/c-toxcore/toxencryptsave/
COPY third_party/cmp/cmp.h /src/workspace/c-toxcore/third_party/cmp/cmp.h
RUN /bin/check-c $(find /src/workspace/c-toxcore -name "*.c")
COPY --from=sources /src/ /src/workspace/c-toxcore/
RUN /bin/check-c $(find /src/workspace/c-toxcore -name "*.c" \
-and -not -wholename "*/auto_tests/*" \
-and -not -wholename "*/other/*" \
-and -not -wholename "*/super_donators/*" \
-and -not -wholename "*/testing/*" \
-and -not -wholename "*/third_party/cmp/examples/*" \
-and -not -wholename "*/third_party/cmp/test/*")

View File

@ -1,10 +1,13 @@
FROM debian:bullseye-slim
FROM debian:bookworm-slim
# When editing, make sure to update /other/windows_build_script_toxcore.sh and
# INSTALL.md to match.
# Build-time environment variables
ARG VERSION_MSGPACK=4.0.0 \
ARG VERSION_OPUS=1.4 \
VERSION_SODIUM=1.0.19 \
VERSION_OPUS=1.3.1 \
VERSION_VPX=1.11.0 \
VERSION_VPX=1.14.0 \
ENABLE_HASH_VERIFICATION=true \
\
SUPPORT_TEST=false \
SUPPORT_ARCH_i686=true \
@ -18,6 +21,7 @@ ENV SUPPORT_TEST=${SUPPORT_TEST} \
CROSS_COMPILE=${CROSS_COMPILE}
WORKDIR /work
COPY check_sha256.sh .
COPY get_packages.sh .
RUN ./get_packages.sh
@ -30,6 +34,6 @@ ENV ENABLE_TEST=false \
ALLOW_TEST_FAILURE=false \
ENABLE_ARCH_i686=true \
ENABLE_ARCH_x86_64=true \
EXTRA_CMAKE_FLAGS="-DTEST_TIMEOUT_SECONDS=90"
EXTRA_CMAKE_FLAGS="-DTEST_TIMEOUT_SECONDS=90 -DUSE_IPV6=OFF"
ENTRYPOINT ["bash", "./build_toxcore.sh"]

View File

@ -7,6 +7,8 @@ fi
#=== Cross-Compile Dependencies ===
. ./check_sha256.sh
build() {
ARCH=${1}
@ -21,7 +23,7 @@ build() {
mkdir -p "$PREFIX_DIR"
export MAKEFLAGS=j"$(nproc)"
export CFLAGS=-O3
export CFLAGS="-O3 -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -ftrivial-auto-var-init=zero -fPIE -pie -fstack-protector-strong -fstack-clash-protection -fcf-protection=full"
CURL_OPTIONS=(-L --connect-timeout 10)
@ -41,19 +43,42 @@ build() {
echo
echo "=== Building Sodium $VERSION_SODIUM $ARCH ==="
curl "${CURL_OPTIONS[@]}" -O "https://github.com/jedisct1/libsodium/releases/download/$VERSION_SODIUM-RELEASE/libsodium-$VERSION_SODIUM.tar.gz"
check_sha256 "018d79fe0a045cca07331d37bd0cb57b2e838c51bc48fd837a1472e50068bbea" "libsodium-$VERSION_SODIUM.tar.gz"
tar -xf "libsodium-$VERSION_SODIUM.tar.gz"
cd "libsodium-stable"
./configure --host="$WINDOWS_TOOLCHAIN" --prefix="$PREFIX_DIR" --disable-shared --enable-static
./configure \
--host="$WINDOWS_TOOLCHAIN" \
--prefix="$PREFIX_DIR" \
--disable-shared \
--enable-static
make
make install
cd ..
echo
echo "=== Building Opus $VERSION_OPUS $ARCH ==="
curl "${CURL_OPTIONS[@]}" -O "https://archive.mozilla.org/pub/opus/opus-$VERSION_OPUS.tar.gz"
if [ "$ARCH" = "i686" ]; then
LIB_OPUS_CFLAGS=""
else
# This makes the build work with -fstack-clash-protection, as otherwise it crashes with:
# silk/float/encode_frame_FLP.c: In function 'silk_encode_frame_FLP':
# silk/float/encode_frame_FLP.c:379:1: internal compiler error: in i386_pe_seh_unwind_emit, at config/i386/winnt.cc:1274
# Should get patched in a future gcc version: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458
LIB_OPUS_CFLAGS="-fno-asynchronous-unwind-tables"
fi
curl "${CURL_OPTIONS[@]}" -O "https://ftp.osuosl.org/pub/xiph/releases/opus/opus-$VERSION_OPUS.tar.gz"
check_sha256 "c9b32b4253be5ae63d1ff16eea06b94b5f0f2951b7a02aceef58e3a3ce49c51f" "opus-$VERSION_OPUS.tar.gz"
tar -xf "opus-$VERSION_OPUS.tar.gz"
cd "opus-$VERSION_OPUS"
./configure --host="$WINDOWS_TOOLCHAIN" --prefix="$PREFIX_DIR" --disable-extra-programs --disable-doc --disable-shared --enable-static
CFLAGS="$CFLAGS $LIB_OPUS_CFLAGS" \
./configure \
--host="$WINDOWS_TOOLCHAIN" \
--prefix="$PREFIX_DIR" \
--disable-extra-programs \
--disable-doc \
--disable-shared \
--enable-static
make
make install
cd ..
@ -72,9 +97,19 @@ build() {
LIB_VPX_CFLAGS="-fno-asynchronous-unwind-tables"
fi
curl "${CURL_OPTIONS[@]}" "https://github.com/webmproject/libvpx/archive/v$VERSION_VPX.tar.gz" -o "libvpx-$VERSION_VPX.tar.gz"
check_sha256 "5f21d2db27071c8a46f1725928a10227ae45c5cd1cad3727e4aafbe476e321fa" "libvpx-$VERSION_VPX.tar.gz"
tar -xf "libvpx-$VERSION_VPX.tar.gz"
cd "libvpx-$VERSION_VPX"
CFLAGS="$LIB_VPX_CFLAGS" CROSS="$WINDOWS_TOOLCHAIN"- ./configure --target="$LIB_VPX_TARGET" --prefix="$PREFIX_DIR" --disable-examples --disable-unit-tests --disable-shared --enable-static
CFLAGS="$CFLAGS $LIB_VPX_CFLAGS" \
CROSS="$WINDOWS_TOOLCHAIN"- \
./configure \
--target="$LIB_VPX_TARGET" \
--prefix="$PREFIX_DIR" \
--disable-examples \
--disable-unit-tests \
--disable-tools \
--disable-shared \
--enable-static
make
make install
cd ..

111
other/docker/windows/build_toxcore.sh Normal file → Executable file
View File

@ -2,6 +2,9 @@
set -e -x
# Note: when modifying this script, don't forget to update the appropriate
# parts of the cross-compilation section of the INSTALL.md.
#=== Cross-Compile Toxcore ===
build() {
@ -23,13 +26,8 @@ build() {
rm -rf /tmp/*
# where to install static/shared toxcores before deciding whether they should be copied over to the user
STATIC_TOXCORE_PREFIX_DIR="/tmp/static_prefix"
SHARED_TOXCORE_PREFIX_DIR="/tmp/shared_prefix"
mkdir -p "$STATIC_TOXCORE_PREFIX_DIR" "$SHARED_TOXCORE_PREFIX_DIR"
export MAKEFLAGS=j"$(nproc)"
export CFLAGS=-O3
export CFLAGS="-D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -ftrivial-auto-var-init=zero -fPIE -pie -fstack-protector-strong -fstack-clash-protection -fcf-protection=full"
echo
echo "=== Building toxcore $ARCH ==="
@ -61,19 +59,39 @@ build() {
echo "SET(CROSSCOMPILING_EMULATOR /usr/bin/wine)" >>windows_toolchain.cmake
fi
if [ "$ARCH" = "i686" ]; then
TOXCORE_CFLAGS=""
else
# This makes the build work with -fstack-clash-protection, as otherwise it crashes with:
#/tmp/toxcore/toxcore/logger.c: In function 'logger_abort':
#/tmp/toxcore/toxcore/logger.c:124:1: internal compiler error: in seh_emit_stackalloc, at config/i386/winnt.cc:1055
# Should get patched in a future gcc version: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458
TOXCORE_CFLAGS="-fno-asynchronous-unwind-tables"
fi
# Patch CMakeLists.txt to make cracker.exe statically link against OpenMP. For some reason
# -DCMAKE_EXE_LINKER_FLAGS="-static" doesn't do it.
sed -i "s|OpenMP::OpenMP_C)|$(realpath -- /usr/lib/gcc/"$WINDOWS_TOOLCHAIN"/*-win32/libgomp.a) \${CMAKE_THREAD_LIBS_INIT})\ntarget_compile_options(cracker PRIVATE -fopenmp)|g" ../other/fun/CMakeLists.txt
# Silly way to bypass a shellharden check
read -ra EXTRA_CMAKE_FLAGS_ARRAY <<<"$EXTRA_CMAKE_FLAGS"
cmake -DCMAKE_TOOLCHAIN_FILE=windows_toolchain.cmake \
-DCMAKE_INSTALL_PREFIX="$STATIC_TOXCORE_PREFIX_DIR" \
-DENABLE_SHARED=OFF \
CFLAGS="$CFLAGS $TOXCORE_CFLAGS" \
cmake \
-DCMAKE_TOOLCHAIN_FILE=windows_toolchain.cmake \
-DCMAKE_INSTALL_PREFIX="$RESULT_PREFIX_DIR" \
-DCMAKE_BUILD_TYPE="Release" \
-DENABLE_SHARED=ON \
-DENABLE_STATIC=ON \
-DCMAKE_C_FLAGS="$CMAKE_C_FLAGS" \
-DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS" \
-DCMAKE_EXE_LINKER_FLAGS="$CMAKE_EXE_LINKER_FLAGS -fstack-protector" \
-DCMAKE_SHARED_LINKER_FLAGS="$CMAKE_SHARED_LINKER_FLAGS" \
-DSTRICT_ABI=ON \
-DEXPERIMENTAL_API=ON \
-DBUILD_FUN_UTILS=ON \
-DCMAKE_EXE_LINKER_FLAGS="-static" \
-DCMAKE_SHARED_LINKER_FLAGS="-static" \
"${EXTRA_CMAKE_FLAGS_ARRAY[@]}" \
-S ..
cmake --build . --target install -- -j"$(nproc)"
cmake --build . --target install --parallel "$(nproc)"
# CMake doesn't install fun utils, so do it manually
cp -a other/fun/*.exe "$RESULT_PREFIX_DIR/bin/"
if [ "$ENABLE_TEST" = "true" ]; then
rm -rf /root/.wine
@ -87,10 +105,12 @@ build() {
winecfg
export CTEST_OUTPUT_ON_FAILURE=1
# add libgcc_s_sjlj-1.dll libwinpthread-1.dll into PATH env var of wine
# we don't have to do this since autotests are statically compiled now,
# but just in case add MinGW-w64 dll locations to the PATH anyway
export WINEPATH="$(
cd /usr/lib/gcc/"$WINDOWS_TOOLCHAIN"/*posix/
cd /usr/lib/gcc/"$WINDOWS_TOOLCHAIN"/*win32/
winepath -w "$PWD"
cd -
)"\;"$(winepath -w /usr/"$WINDOWS_TOOLCHAIN"/lib/)"
if [ "$ALLOW_TEST_FAILURE" = "true" ]; then
@ -102,47 +122,48 @@ build() {
fi
fi
# move static dependencies
cp -a "$STATIC_TOXCORE_PREFIX_DIR"/* "$RESULT_PREFIX_DIR"
cp -a "$DEP_PREFIX_DIR"/* "$RESULT_PREFIX_DIR"
# make libtox.dll
cd "$SHARED_TOXCORE_PREFIX_DIR"
for archive in "$STATIC_TOXCORE_PREFIX_DIR"/lib/libtox*.a; do
"$WINDOWS_TOOLCHAIN"-ar xv "$archive"
# generate def, lib and exp as they supposedly help with linking against the dlls,
# especially the lib is supposed to be of great help when linking on msvc.
# cd in order to keep the object names inside .lib and .dll.a short
cd "$RESULT_PREFIX_DIR"/bin/
for TOX_DLL in *.dll; do
gendef - "$TOX_DLL" >"${TOX_DLL%.*}.def"
# we overwrite the CMake-generated .dll.a for the better
# compatibility with the .lib being generated here
"$WINDOWS_TOOLCHAIN"-dlltool \
--input-def "${TOX_DLL%.*}.def" \
--output-lib "${TOX_DLL%.*}.lib" \
--output-exp "${TOX_DLL%.*}.exp" \
--output-delaylib "../lib/${TOX_DLL%.*}.dll.a" \
--dllname "$TOX_DLL"
done
cd -
# copy over the deps
if [ "$CROSS_COMPILE" = "true" ]; then
LIBWINPTHREAD="/usr/$WINDOWS_TOOLCHAIN/lib/libwinpthread.a"
cd /usr/lib/gcc/"$WINDOWS_TOOLCHAIN"/*win32/
LIBSSP="$PWD/libssp.a"
cd -
else
LIBWINPTHREAD="/usr/$WINDOWS_TOOLCHAIN/sys-root/mingw/lib/libwinpthread.a"
LIBSSP="/usr/$WINDOWS_TOOLCHAIN/sys-root/mingw/lib/libssp.a"
fi
cp -a "$LIBWINPTHREAD" "$LIBSSP" "$RESULT_PREFIX_DIR/lib/"
for STATIC_LIB in "$DEP_PREFIX_DIR"/lib/*.a; do
[[ "$STATIC_LIB" == *.dll.a ]] && continue
cp -a "$STATIC_LIB" "$RESULT_PREFIX_DIR/lib/"
done
cp "$DEP_PREFIX_DIR"/lib/pkgconfig/* "$RESULT_PREFIX_DIR/lib/pkgconfig/"
"$WINDOWS_TOOLCHAIN"-gcc -Wl,--export-all-symbols \
-Wl,--out-implib=libtox.dll.a \
-shared \
-o libtox.dll \
*.obj \
"$STATIC_TOXCORE_PREFIX_DIR"/lib/*.a \
"$DEP_PREFIX_DIR"/lib/*.a \
"$LIBWINPTHREAD" \
-liphlpapi \
-lws2_32 \
-static-libgcc \
-lssp
cp libtox.dll.a "$RESULT_PREFIX_DIR"/lib
mkdir -p "$RESULT_PREFIX_DIR"/bin
cp libtox.dll "$RESULT_PREFIX_DIR"/bin
# strip everything
set +e
"$WINDOWS_TOOLCHAIN"-strip --strip-unneeded "$RESULT_PREFIX_DIR"/bin/*.* "$RESULT_PREFIX_DIR"/lib/*.*
set -e
rm -rf /tmp/*
# remove everything from include directory except tox headers
mv "$RESULT_PREFIX_DIR"/include/tox "$RESULT_PREFIX_DIR"/tox
rm -rf "$RESULT_PREFIX_DIR"/include/*
mv "$RESULT_PREFIX_DIR"/tox "$RESULT_PREFIX_DIR"/include/tox
sed -i "s|^prefix=.*|prefix=$RESULT_PREFIX_DIR|g" "$RESULT_PREFIX_DIR"/lib/pkgconfig/*.pc
sed -i "s|^libdir=.*|libdir=$RESULT_PREFIX_DIR/lib|g" "$RESULT_PREFIX_DIR"/lib/*.la
}
#=== Test Supported vs. Enabled ===

View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
check_sha256() {
[ "$ENABLE_HASH_VERIFICATION" = "true" ] && _check_sha256 "$@"
}
_check_sha256() {
if ! (echo "$1 $2" | sha256sum -c --status -); then
echo "Error: sha256 of $2 doesn't match the known one."
echo "Expected: $1 $2"
echo "Got: $(sha256sum "$2")"
return 1
fi
echo "sha256 matches the expected one: $1"
return 0
}

View File

@ -1,10 +1,11 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
set -e -x
#=== Install Packages ===
apt-get update
apt-get upgrade -y
# Arch-independent packages required for building toxcore's dependencies and toxcore itself
apt-get install -y \
@ -13,9 +14,10 @@ apt-get install -y \
ca-certificates \
cmake \
curl \
libtool \
libc-dev \
libtool \
make \
mingw-w64-tools \
pkg-config \
tree \
yasm
@ -38,12 +40,27 @@ if [ "$SUPPORT_TEST" = "true" ]; then
apt-get install -y \
texinfo
CURL_OPTIONS=(-L --connect-timeout 10)
# While we would prefer to use Debian's Wine packages, use WineHQ's packages
# instead as Debian Bookworm's Wine crashes when creating a 64-bit prefix.
# see https://github.com/TokTok/c-toxcore/pull/2713#issuecomment-1967319113
# for the crash details
curl "${CURL_OPTIONS[@]}" -o /etc/apt/keyrings/winehq-archive.key \
https://dl.winehq.org/wine-builds/winehq.key
curl "${CURL_OPTIONS[@]}" -O --output-dir /etc/apt/sources.list.d/ \
https://dl.winehq.org/wine-builds/debian/dists/bookworm/winehq-bookworm.sources
. ./check_sha256.sh
check_sha256 "78b185fabdb323971d13bd329fefc8038e08559aa51c4996de18db0639a51df6" \
"/etc/apt/keyrings/winehq-archive.key"
check_sha256 "8dd8ef66c749d56e798646674c1c185a99b3ed6727ca0fbb5e493951e66c0f9e" \
"/etc/apt/sources.list.d/winehq-bookworm.sources"
dpkg --add-architecture i386
apt-get update
apt-get install -y \
wine \
wine32 \
wine64
winehq-stable
fi
# Clean up to reduce image size

View File

@ -172,6 +172,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
}
f << R"(
#include "../attributes.h"
#include "../bin_pack.h"
#include "../bin_unpack.h"
#include "../ccompat.h"
@ -185,14 +186,12 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
}
f << R"(
/*****************************************************
*
* :: struct and accessors
*
*****************************************************/
)";
// gen struct
@ -216,7 +215,17 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
// gen setters and getters
for (const auto& t : event_types) {
// setter
f << "non_null()\n";
std::visit(
overloaded{
[&](const EventTypeTrivial& t) {
f << "non_null()\n";
},
[&](const EventTypeByteRange& t) {
f << "non_null(1) nullable(2)\n";
}
},
t
);
f << "static " << (t.index() == 0 ? "void" : "bool") << " tox_event_" << event_name_l << "_set_";
std::visit(
overloaded{
@ -254,6 +263,9 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
f << " " << event_name_l << "->" << t.name_data << " = nullptr;\n";
f << " " << event_name_l << "->" << t.name_length << " = 0;\n";
f << " }\n\n";
f << " if (" << t.name_data << " == nullptr) {\n";
f << " assert(" << t.name_length << " == 0);\n";
f << " return true;\n }\n\n";
f << " uint8_t *" << t.name_data << "_copy = (uint8_t *)malloc(" << t.name_length << ");\n\n";
f << " if (" << t.name_data << "_copy == nullptr) {\n";
f << " return false;\n }\n\n";
@ -395,7 +407,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
);
first = false;
}
f << ";\n}\n\n";
f << ";\n}\n";
f << R"(
/*****************************************************
@ -439,6 +451,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
f << "bool tox_event_" << event_name_l << "_unpack(\n";
f << " Tox_Event_" << event_name << " **event, Bin_Unpack *bu, const Memory *mem)\n{\n";
f << " assert(event != nullptr);\n";
f << " assert(*event == nullptr);\n";
f << " *event = tox_event_" << event_name_l << "_new(mem);\n\n";
f << " if (*event == nullptr) {\n return false;\n }\n\n";
f << " return tox_event_" << event_name_l << "_unpack_into(*event, bu);\n}\n\n";
@ -452,7 +465,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
f << " Tox_Event_" << event_name << " *" << event_name_l << " = tox_events_add_" << event_name_l << "(state->events, state->mem);\n\n";
f << " if (" << event_name_l << " == nullptr) {\n";
f << " state->error = TOX_ERR_EVENTS_ITERATE_MALLOC;\n return nullptr;\n }\n\n";
f << " return " << event_name_l << ";\n}\n\n";
f << " return " << event_name_l << ";\n}\n";
f << R"(
@ -462,9 +475,9 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
*
*****************************************************/
)";
f << "void tox_events_handle_" << event_name_l << "(Tox *tox";
f << "void tox_events_handle_" << event_name_l << "(\n";
f << " Tox *tox";
for (const auto& t : event_types) {
std::visit(
@ -480,7 +493,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
);
}
f << ",\n void *user_data)\n{\n";
f << ",\n void *user_data)\n{\n";
f << " Tox_Event_" << event_name << " *" << event_name_l << " = tox_event_" << event_name_l << "_alloc(user_data);\n\n";
f << " if (" << event_name_l << " == nullptr) {\n return;\n }\n\n";
@ -744,6 +757,7 @@ int main(int argc, char** argv) {
EventTypeTrivial{"uint32_t", "peer_id"},
EventTypeTrivial{"Tox_Message_Type", "type"},
EventTypeByteRange{"message", "message_length", "length"}, // the latter two are ideally the same
EventTypeTrivial{"uint32_t", "message_id"},
}
},
{

View File

@ -6,36 +6,46 @@ function(target_link_toxcore target)
endif()
endfunction()
function(target_link_sodium target)
if(TARGET unofficial-sodium::sodium)
target_link_libraries(${target} PRIVATE unofficial-sodium::sodium)
else()
target_link_libraries(${target} PRIVATE ${LIBSODIUM_LIBRARIES})
target_link_directories(${target} PRIVATE ${LIBSODIUM_LIBRARY_DIRS})
target_include_directories(${target} SYSTEM PRIVATE ${LIBSODIUM_INCLUDE_DIRS})
target_compile_options(${target} PRIVATE ${LIBSODIUM_CFLAGS_OTHER})
endif()
endfunction()
add_executable(save-generator save-generator.c)
target_link_libraries(save-generator PRIVATE misc_tools)
target_link_toxcore(save-generator)
add_executable(strkey strkey.c)
target_link_libraries(strkey PRIVATE ${LIBSODIUM_LIBRARIES})
target_link_toxcore(strkey)
target_link_sodium(strkey)
add_executable(create_bootstrap_keys create_bootstrap_keys.c)
target_link_libraries(create_bootstrap_keys PRIVATE ${LIBSODIUM_LIBRARIES})
target_link_toxcore(create_bootstrap_keys)
target_link_sodium(create_bootstrap_keys)
add_executable(create_minimal_savedata create_minimal_savedata.c)
target_link_libraries(create_minimal_savedata PRIVATE ${LIBSODIUM_LIBRARIES})
target_link_sodium(create_minimal_savedata)
add_executable(create_savedata create_savedata.c)
target_link_libraries(create_savedata PRIVATE ${LIBSODIUM_LIBRARIES})
target_link_sodium(create_savedata)
target_link_toxcore(create_savedata)
add_executable(sign sign.c)
target_link_libraries(sign PRIVATE ${LIBSODIUM_LIBRARIES} misc_tools)
target_link_sodium(sign)
add_executable(cracker_simple cracker_simple.c)
target_link_libraries(cracker_simple ${LIBSODIUM_LIBRARIES} misc_tools)
target_link_sodium(cracker_simple)
# MSVC doesn't support OpenMP
if(NOT MSVC)
find_package(OpenMP)
if(OpenMP_C_FOUND)
add_executable(cracker cracker.c)
target_link_libraries(cracker PRIVATE OpenMP::OpenMP_C ${LIBSODIUM_LIBRARIES})
endif()
find_package(OpenMP)
if(OpenMP_C_FOUND)
add_executable(cracker cracker.c)
target_link_libraries(cracker PRIVATE OpenMP::OpenMP_C)
target_link_sodium(cracker)
else()
add_executable(cracker cracker.c)
target_link_sodium(cracker)
endif()

View File

@ -33,6 +33,7 @@
#include <omp.h>
#define NUM_THREADS() ((unsigned) omp_get_max_threads())
#else
#pragma message("Being built without OpenMP support -- the program will utilize a single thread only.")
#define NUM_THREADS() (1U)
#endif
@ -112,8 +113,9 @@ static size_t match_hex_prefix(const uint8_t *key, const uint8_t *prefix, size_t
static void cracker_core(uint64_t range_start, uint64_t range_end, uint64_t range_offs, uint64_t priv_key_shadow[4],
uint32_t *longest_match, uint8_t hex_prefix[MAX_CRACK_BYTES], size_t prefix_chars_len)
{
#if defined(_OPENMP)
#pragma omp parallel for firstprivate(priv_key_shadow) shared(longest_match, range_start, range_end, range_offs, hex_prefix, prefix_chars_len) schedule(static) default(none)
#endif
for (uint64_t batch = range_start; batch < range_end; ++batch) {
uint8_t *priv_key = (uint8_t *) priv_key_shadow;
/*
@ -134,14 +136,19 @@ static void cracker_core(uint64_t range_start, uint64_t range_end, uint64_t rang
// Global compare and update
uint32_t l_longest_match;
#if defined(_OPENMP)
#pragma omp atomic read
#endif
l_longest_match = *longest_match;
if (matching > l_longest_match) {
#if defined(_OPENMP)
#pragma omp atomic write
#endif
*longest_match = matching;
#if defined(_OPENMP)
#pragma omp critical
#endif
{
printf("%u chars matching: \n", matching);
printf("Public key: ");
@ -198,7 +205,6 @@ int main(int argc, char *argv[])
randombytes(priv_key, KEY_LEN);
uint32_t longest_match = 0;
// Finishes a batch every ~10s on my PC
const uint64_t batch_size = (UINT64_C(1) << 18) * NUM_THREADS();
@ -220,7 +226,6 @@ int main(int argc, char *argv[])
return 0;
}
for (uint64_t tries = 0; tries < rem_start; tries += batch_size) {
cracker_core(tries, tries + batch_size, 0, priv_key_shadow, &longest_match, hex_prefix, prefix_chars_len);

View File

@ -13,11 +13,8 @@
#include <stdio.h>
#include <string.h>
/* Sodium includes*/
#include <sodium/crypto_scalarmult_curve25519.h>
#include <sodium/randombytes.h>
#include <sodium.h>
#include "../../testing/misc_tools.h"
#include "../../toxcore/ccompat.h"
// Secret key and public key length
@ -30,7 +27,6 @@ static void print_key(const uint8_t *client_id)
}
}
int main(int argc, char *argv[])
{
if (argc < 2) {
@ -41,7 +37,13 @@ int main(int argc, char *argv[])
long long unsigned int num_tries = 0;
size_t len = strlen(argv[1]) / 2;
unsigned char *key = hex_string_to_bin(argv[1]);
unsigned char *key = (unsigned char *)malloc(len);
const char *hex_end = nullptr;
if (sodium_hex2bin(key, len, argv[1], strlen(argv[1]), nullptr, nullptr, &hex_end) != 0
|| hex_end != argv[1] + strlen(argv[1])) {
printf("Invalid key provided\n");
return 1;
}
uint8_t pub_key[KEY_LEN], priv_key[KEY_LEN], c_key[KEY_LEN];
if (len > KEY_LEN) {

View File

@ -18,7 +18,6 @@
#include <sodium.h>
#include <string.h>
#include "../../testing/misc_tools.h" // hex_string_to_bin
#include "../../toxcore/ccompat.h"
static int load_file(const char *filename, unsigned char **result)
@ -70,7 +69,12 @@ int main(int argc, char *argv[])
}
if (argc == 5 && argv[1][0] == 's') {
unsigned char *secret_key = hex_string_to_bin(argv[2]);
const char *hex_end = nullptr;
if (sodium_hex2bin(sk, sizeof(sk), argv[2], strlen(argv[2]), nullptr, nullptr, &hex_end) != 0
|| hex_end != argv[2] + strlen(argv[2])) {
printf("Invalid secret key provided.\n");
goto fail;
}
unsigned char *data = nullptr;
int size = load_file(argv[3], &data);
@ -80,9 +84,8 @@ int main(int argc, char *argv[])
unsigned long long smlen;
unsigned char *sm = (unsigned char *)malloc(size + crypto_sign_ed25519_BYTES * 2);
crypto_sign_ed25519(sm, &smlen, data, size, secret_key);
crypto_sign_ed25519(sm, &smlen, data, size, sk);
free(data);
free(secret_key);
if (smlen - size != crypto_sign_ed25519_BYTES) {
free(sm);
@ -110,8 +113,13 @@ int main(int argc, char *argv[])
}
if (argc == 4 && argv[1][0] == 'c') {
unsigned char *public_key = hex_string_to_bin(argv[2]);
unsigned char *data;
const char *hex_end = nullptr;
if (sodium_hex2bin(pk, sizeof(pk), argv[2], strlen(argv[2]), nullptr, nullptr, &hex_end) != 0
|| hex_end != argv[2] + strlen(argv[2])) {
printf("Invalid public key provided.\n");
goto fail;
}
unsigned char *data = nullptr;
int size = load_file(argv[3], &data);
if (size < 0) {
@ -127,7 +135,7 @@ int main(int argc, char *argv[])
unsigned char *m = (unsigned char *)malloc(size);
unsigned long long mlen;
if (crypto_sign_ed25519_open(m, &mlen, signe, size, public_key) == -1) {
if (crypto_sign_ed25519_open(m, &mlen, signe, size, pk) == -1) {
printf("Failed checking sig.\n");
free(m);
free(signe);

View File

@ -1,7 +1,7 @@
%define full_name c-@PROJECT_NAME@
%define commit 0
%if "${commit}" != "0"
%define shortcommit %(c=%{commit}; echo ${c:0:7})
%define shortcommit %(c=%{commit}; echo ${c:0:9})
%endif
Name: @PROJECT_NAME@
@ -18,10 +18,12 @@ Source0: https://github.com/TokTok/%{full_name}/archive/%{commit}/%{full_
%endif
BuildRequires: cmake
BuildRequires: g++
BuildRequires: gcc
BuildRequires: libconfig-devel
BuildRequires: libsodium-devel
BuildRequires: libvpx-devel
BuildRequires: opus-devel
BuildRequires: libsodium-devel
BuildRequires: libconfig-devel
BuildRequires: systemd-units
%description
@ -63,10 +65,10 @@ Tox DHT bootstrap daemon.
%build
%cmake
%{__make} %{?_smp_mflags}
%{__make} -C redhat-linux-build %{?_smp_mflags}
%install
%make_install
%make_install -C redhat-linux-build
mkdir -p %{buildroot}%{_unitdir}
install -m 0644 other/rpm/tox-bootstrapd.service %{buildroot}%{_unitdir}/tox-bootstrapd.service
install -d "%{buildroot}%{_sharedstatedir}/tox-bootstrapd"
@ -74,7 +76,7 @@ mkdir -p %{buildroot}%{_sysconfdir}
install -m 0644 other/bootstrap_daemon/tox-bootstrapd.conf %{buildroot}%{_sysconfdir}/tox-bootstrapd.conf
%check
%{__make} %{?_smp_mflags} test
%{__make} -C redhat-linux-build %{?_smp_mflags} test
%pre -n tox-bootstrapd
getent group tox-bootstrapd >/dev/null || groupadd -r tox-bootstrapd
@ -97,7 +99,7 @@ getent passwd tox-bootstrapd >/dev/null || \
%files
%defattr(-, root, root)
%doc LICENSE.md README.md CHANGELOG.md
%doc LICENSE README.md CHANGELOG.md
%{_libdir}/libtoxcore.so*
%files devel
@ -111,9 +113,10 @@ getent passwd tox-bootstrapd >/dev/null || \
%files -n tox-bootstrapd
%defattr(-, root, root)
%{_bindir}/DHT_bootstrap
%{_bindir}/tox-bootstrapd
%{_unitdir}/tox-bootstrapd.service
%{_sharedstatedir}/tox-bootstrapd
%{_datadir}/bash-completion/completions/tox-bootstrapd
%attr(-,tox-bootstrapd,tox-bootstrapd) %{_sharedstatedir}/tox-bootstrapd/
%config(noreplace) %{_sysconfdir}/tox-bootstrapd.conf

View File

@ -1,8 +1,12 @@
#!/bin/sh
export VERSION_SODIUM="1.0.18"
export VERSION_OPUS="1.3.1"
export VERSION_VPX="1.9.0"
# When editing, make sure to update /other/docker/windows/Dockerfile and
# INSTALL.md to match.
export VERSION_OPUS="1.4"
export VERSION_SODIUM="1.0.19"
export VERSION_VPX="1.14.0"
export ENABLE_HASH_VERIFICATION=true
export SUPPORT_TEST=false
export SUPPORT_ARCH_i686=true
@ -15,6 +19,6 @@ export ENABLE_TEST=false
export ALLOW_TEST_FAILURE=false
export ENABLE_ARCH_i686=true
export ENABLE_ARCH_x86_64=true
export EXTRA_CMAKE_FLAGS="-DTEST_TIMEOUT_SECONDS=90"
export EXTRA_CMAKE_FLAGS="-DTEST_TIMEOUT_SECONDS=90 -DUSE_IPV6=OFF"
sh ./other/docker/windows/build_toxcore.sh