From 0c5eff2a98d412e835e41d02f3198314b489ff5e Mon Sep 17 00:00:00 2001 From: Oleg Baranov Date: Mon, 3 Mar 2025 14:36:52 +0400 Subject: [PATCH] CMake flag define for adnl tunnel --- CMakeLists.txt | 1 + README.md | 16 +++++++++------- tdnet/td/net/UdpServer.cpp | 10 ++++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a9bb13a..9cb2b2b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,7 @@ if (TON_USE_GO_TUNNEL) add_library(tunnel STATIC IMPORTED) set_target_properties(tunnel PROPERTIES IMPORTED_LOCATION "${TUNNEL_GO_LIB_PATH}") set(TUNNEL_LIB_IF_USED "tunnel") + add_compile_definitions(TON_USE_GO_TUNNEL) else() message(FATAL_ERROR "Missing ADNL Tunnel library (Go), but enabled: ${TUNNEL_GO_LIB_PATH}") endif() diff --git a/README.md b/README.md index 32f0f4fe..8376f486 100644 --- a/README.md +++ b/README.md @@ -152,16 +152,18 @@ Tests are executed by running `ctest` in the build directory. See `doc/Tests.md` ## Using ADNL tunnel -### Before node compilation -1. Clone https://github.com/ton-blockchain/adnl-tunnel and install golang 1.23 or newer +### At node compilation +1. Clone https://github.com/ton-blockchain/adnl-tunnel and install golang 1.23.3 or newer * `cd adnl-tunnel` * `make library` * It will build `libtunnel.a` -2. Copy `libtunnel.a` to ton src directory root (usually `/usr/src/ton`) +2. Copy `libtunnel.a` to ton src directory root (usually `/usr/src/ton`). 3. On the first step of ton node compilation run cmake with option `-DTON_USE_GO_TUNNEL=ON` to enable tunnel. 4. Build ton node as usual. -### Before startup -1. Create `tunnel-config.json` in any place. -2. Fill it with desired tunnel configuration and wallet keys. See example. -3Add `--tunnel-config /path/to/tunnel-config.json` argument to validator-engine startup command. \ No newline at end of file +### At node startup +1. Run validator-engine with `--tunnel-config /path/to/tunnel-config.json` startup argument. +2. It will create example tunnel config file at specified path (`/path/to/tunnel-config.json`). +3. Fill it with desired tunnel configuration, enable payments and top up wallet address if needed. +4. Run validator-engine `--tunnel-config /path/to/tunnel-config.json` again, and follow instructions in console if any. +5. When setup is completed and node started, you can stop it and run in daemon mode as usual. \ No newline at end of file diff --git a/tdnet/td/net/UdpServer.cpp b/tdnet/td/net/UdpServer.cpp index f75dd85b..fdb94da7 100644 --- a/tdnet/td/net/UdpServer.cpp +++ b/tdnet/td/net/UdpServer.cpp @@ -20,7 +20,9 @@ #include "td/net/FdListener.h" #include "td/net/TcpListener.h" +#ifdef TON_USE_GO_TUNNEL #include "td/net/tunnel/libtunnel.h" +#endif #include "td/utils/BufferedFd.h" #include "td/utils/filesystem.h" @@ -90,8 +92,10 @@ void UdpServerTunnelImpl::send(td::UdpMessage &&message) { if (out_buf_msg_num_ == TUNNEL_BUFFER_SZ_PACKETS) { +#ifdef TON_USE_GO_TUNNEL WriteTunnel(tunnel_index_, out_buf_, out_buf_msg_num_); LOG(DEBUG) << "Sending messages by fulfillment " << TUNNEL_BUFFER_SZ_PACKETS; +#endif out_buf_offset_ = 0; out_buf_msg_num_ = 0; @@ -101,8 +105,10 @@ void UdpServerTunnelImpl::send(td::UdpMessage &&message) { void UdpServerTunnelImpl::alarm() { if (out_buf_msg_num_ > 0 && Time::now()-last_batch_at_ >= TUNNEL_ALARM_EVERY) { +#ifdef TON_USE_GO_TUNNEL WriteTunnel(tunnel_index_, out_buf_, out_buf_msg_num_); LOG(DEBUG) << "Sending messages by alarm " << out_buf_msg_num_; +#endif out_buf_offset_ = 0; out_buf_msg_num_ = 0; @@ -113,6 +119,7 @@ void UdpServerTunnelImpl::alarm() { } void UdpServerTunnelImpl::start_up() { +#ifdef TON_USE_GO_TUNNEL auto global_conf_data_R = td::read_file(global_config_); if (global_conf_data_R.is_error()) { LOG(FATAL) << global_conf_data_R.move_as_error_prefix("failed to read global config: "); @@ -135,6 +142,9 @@ void UdpServerTunnelImpl::start_up() { on_ready_.set_value(std::move(ip)); alarm_timestamp() = td::Timestamp::in(TUNNEL_ALARM_EVERY); +#else + LOG(FATAL) << "Tunnel was not enabled during node building, rebuild with cmake flag -DTON_USE_GO_TUNNEL=ON"; +#endif } void UdpServerTunnelImpl::on_recv_batch(void *next, uint8_t *data, size_t num) {