Skip to content

Commit e91ab66

Browse files
committed
refactor: Add file/line to tox-bootstrapd logging.
Also, allow trace logging in bootstrapd (disabled by default, but enabled on the websockify docker image so we can debug things there).
1 parent f1991aa commit e91ab66

File tree

31 files changed

+295
-155
lines changed

31 files changed

+295
-155
lines changed

other/bootstrap_daemon/docker/Dockerfile

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
###########################################################
22
# Builder image: we compile the code here (static build)
3-
FROM alpine:3.19.0 AS build
3+
FROM alpine:3.21.0 AS build
44

55
RUN ["apk", "--no-cache", "add",\
66
"clang",\
@@ -26,33 +26,32 @@ COPY other/bootstrap_node_packets.[ch] other/
2626
COPY other/DHT_bootstrap.c other/
2727
COPY other/pkgconfig other/pkgconfig
2828
COPY other/rpm other/rpm
29-
COPY testing/misc_tools.[ch] testing/
29+
COPY testing testing
3030
COPY toxcore toxcore
3131
COPY toxencryptsave toxencryptsave
3232
COPY third_party third_party
3333
COPY CMakeLists.txt so.version ./
3434
COPY other/bootstrap_daemon/CMakeLists.txt other/bootstrap_daemon/CMakeLists.txt
35-
COPY testing/CMakeLists.txt testing/CMakeLists.txt
3635

3736
RUN CC=clang cmake -B_build -H. \
38-
-GNinja \
39-
-DCMAKE_C_FLAGS="-DTCP_SERVER_USE_EPOLL -fsanitize=alignment,return,returns-nonnull-attribute,vla-bound,unreachable,float-cast-overflow,null -fsanitize-trap=all -fstack-protector-all" \
40-
-DCMAKE_UNITY_BUILD=ON \
41-
-DCMAKE_BUILD_TYPE=Release \
42-
-DFULLY_STATIC=ON \
43-
-DMIN_LOGGER_LEVEL=DEBUG \
44-
-DBUILD_TOXAV=OFF \
45-
-DBOOTSTRAP_DAEMON=ON && \
46-
cmake --build _build --target install
37+
-GNinja \
38+
-DCMAKE_C_FLAGS="-DTCP_SERVER_USE_EPOLL -fsanitize=alignment,return,returns-nonnull-attribute,vla-bound,unreachable,float-cast-overflow,null -fsanitize-trap=all -fstack-protector-all" \
39+
-DCMAKE_UNITY_BUILD=ON \
40+
-DCMAKE_BUILD_TYPE=Release \
41+
-DFULLY_STATIC=ON \
42+
-DMIN_LOGGER_LEVEL=TRACE \
43+
-DBUILD_TOXAV=OFF \
44+
-DBOOTSTRAP_DAEMON=ON \
45+
&& cmake --build _build --target install
4746

4847
# Verify checksum from dev-built binary, so we can be sure Docker Hub doesn't
4948
# mess with your binaries.
5049
COPY other/bootstrap_daemon/docker/tox-bootstrapd.sha256 other/bootstrap_daemon/docker/
5150
ARG CHECK=sha256sum
52-
RUN SHA256="$("$CHECK" /usr/local/bin/tox-bootstrapd)" && \
53-
("$CHECK" -c other/bootstrap_daemon/docker/tox-bootstrapd.sha256 || \
54-
(echo "::error file=other/bootstrap_daemon/docker/tox-bootstrapd.sha256,line=1::$SHA256" && \
55-
false))
51+
RUN SHA256="$("$CHECK" /usr/local/bin/tox-bootstrapd)" \
52+
&& ("$CHECK" -c other/bootstrap_daemon/docker/tox-bootstrapd.sha256 || \
53+
(echo "::error file=other/bootstrap_daemon/docker/tox-bootstrapd.sha256,line=1::$SHA256" \
54+
&& false))
5655

5756
# Remove all the example bootstrap nodes from the config file.
5857
COPY other/bootstrap_daemon/tox-bootstrapd.conf other/bootstrap_daemon/
@@ -69,12 +68,14 @@ FROM debian:bookworm-slim
6968

7069
COPY --from=build /usr/local/bin/tox-bootstrapd /usr/local/bin/
7170
COPY --from=build /src/c-toxcore/other/bootstrap_daemon/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
72-
RUN useradd --home-dir /var/lib/tox-bootstrapd --create-home \
73-
--system --shell /sbin/nologin \
74-
--comment "Account to run the Tox DHT bootstrap daemon" \
75-
--user-group tox-bootstrapd && \
76-
chmod 644 /etc/tox-bootstrapd.conf && \
77-
chmod 700 /var/lib/tox-bootstrapd
71+
RUN useradd \
72+
--home-dir /var/lib/tox-bootstrapd \
73+
--create-home \
74+
--system --shell /sbin/nologin \
75+
--comment "Account to run the Tox DHT bootstrap daemon" \
76+
--user-group tox-bootstrapd \
77+
&& chmod 644 /etc/tox-bootstrapd.conf \
78+
&& chmod 700 /var/lib/tox-bootstrapd
7879

7980
WORKDIR /var/lib/tox-bootstrapd
8081

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Very selectively add files to the image, because we may have random stuff
2+
# lying around. In particular, we don't need to rebuild the docker image when
3+
# toxav changes or the Dockerfile changes down from the build.
4+
**/*
5+
!cmake/*
6+
!other/bootstrap_daemon/bash-completion/*
7+
!other/bootstrap_daemon/docker/get-nodes.py
8+
!other/bootstrap_daemon/docker/tox-bootstrapd.sha256
9+
!other/bootstrap_daemon/src/*
10+
!other/bootstrap_daemon/tox-bootstrapd.conf
11+
!other/bootstrap_node_packets.[ch]
12+
!other/DHT_bootstrap.c
13+
!other/pkgconfig/*
14+
!other/rpm/*
15+
!testing/misc_tools.[ch]
16+
!toxcore/**/*
17+
!toxencryptsave/**/*
18+
!third_party/cmp/cmp.[ch]
19+
!CMakeLists.txt
20+
!so.version
21+
!other/bootstrap_daemon/CMakeLists.txt
22+
!testing/CMakeLists.txt
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
set -eux -o pipefail
4+
5+
GIT_ROOT="$(git rev-parse --show-toplevel)"
6+
cd "$GIT_ROOT"
7+
8+
docker build \
9+
-t toxchat/bootstrap-node \
10+
-f other/bootstrap_daemon/docker/Dockerfile \
11+
--build-arg CHECK=true \
12+
.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9ec2993a28988bd147bf8f4f21a824c2fc5dbf7255e391b3ce517d337ebce5c1 /usr/local/bin/tox-bootstrapd
1+
82b1733dea0f650607da7759ec79c827eede6f4646ac1c1afc832ca924e0e3c3 /usr/local/bin/tox-bootstrapd

other/bootstrap_daemon/src/command_line_arguments.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
#include "command_line_arguments.h"
1111

12-
#include "global.h"
12+
#include "global.h" // IWYU pragma: keep
1313
#include "log.h"
1414

1515
#include "../../../toxcore/ccompat.h"
@@ -26,7 +26,7 @@ static void print_help(void)
2626
// 2 space indent
2727
// Make sure all lines fit into 80 columns
2828
// Make sure options are listed in alphabetical order
29-
log_write(LOG_LEVEL_INFO,
29+
LOG_WRITE(LOG_LEVEL_INFO,
3030
"Usage: tox-bootstrapd [OPTION]... --config=FILE_PATH\n"
3131
"\n"
3232
"Options:\n"
@@ -43,6 +43,7 @@ static void print_help(void)
4343
" Default option when no --log-backend is\n"
4444
" specified.\n"
4545
" stdout Writes log messages to stdout/stderr.\n"
46+
" --trace Enable verbose network trace logging in toxcore.\n"
4647
" --version Print version information.\n");
4748
}
4849

@@ -51,7 +52,7 @@ Cli_Status handle_command_line_arguments(
5152
bool *run_in_foreground)
5253
{
5354
if (argc < 2) {
54-
log_write(LOG_LEVEL_ERROR, "Error: No arguments provided.\n\n");
55+
LOG_WRITE(LOG_LEVEL_ERROR, "Error: No arguments provided.\n\n");
5556
print_help();
5657
return CLI_STATUS_ERROR;
5758
}
@@ -64,6 +65,7 @@ Cli_Status handle_command_line_arguments(
6465
{"help", no_argument, nullptr, 'h'},
6566
{"log-backend", required_argument, nullptr, 'l'}, // optional, defaults to syslog
6667
{"version", no_argument, nullptr, 'v'},
68+
{"trace", no_argument, nullptr, 't'},
6769
{nullptr, 0, nullptr, 0 }
6870
};
6971

@@ -99,24 +101,29 @@ Cli_Status handle_command_line_arguments(
99101
*log_backend = LOG_BACKEND_STDOUT;
100102
log_backend_set = true;
101103
} else {
102-
log_write(LOG_LEVEL_ERROR, "Error: Invalid BACKEND value for --log-backend option passed: %s\n\n", optarg);
104+
LOG_WRITE(LOG_LEVEL_ERROR, "Error: Invalid BACKEND value for --log-backend option passed: %s\n\n", optarg);
103105
print_help();
104106
return CLI_STATUS_ERROR;
105107
}
106108

107109
break;
108110

109111
case 'v':
110-
log_write(LOG_LEVEL_INFO, "Version: %lu\n", DAEMON_VERSION_NUMBER);
112+
LOG_WRITE(LOG_LEVEL_INFO, "Version: %lu\n", DAEMON_VERSION_NUMBER);
111113
return CLI_STATUS_DONE;
112114

115+
case 't':
116+
LOG_WRITE(LOG_LEVEL_INFO, "Enabling trace logging in toxcore.\n");
117+
log_enable_trace(true);
118+
break;
119+
113120
case '?':
114-
log_write(LOG_LEVEL_ERROR, "Error: Unrecognized option %s\n\n", argv[optind - 1]);
121+
LOG_WRITE(LOG_LEVEL_ERROR, "Error: Unrecognized option %s\n\n", argv[optind - 1]);
115122
print_help();
116123
return CLI_STATUS_ERROR;
117124

118125
case ':':
119-
log_write(LOG_LEVEL_ERROR, "Error: No argument provided for option %s\n\n", argv[optind - 1]);
126+
LOG_WRITE(LOG_LEVEL_ERROR, "Error: No argument provided for option %s\n\n", argv[optind - 1]);
120127
print_help();
121128
return CLI_STATUS_ERROR;
122129
}
@@ -127,7 +134,7 @@ Cli_Status handle_command_line_arguments(
127134
}
128135

129136
if (!cfg_file_path_set) {
130-
log_write(LOG_LEVEL_ERROR, "Error: The required --config option wasn't specified\n\n");
137+
LOG_WRITE(LOG_LEVEL_ERROR, "Error: The required --config option wasn't specified\n\n");
131138
print_help();
132139
return CLI_STATUS_ERROR;
133140
}

0 commit comments

Comments
 (0)