1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

CMake flag define for adnl tunnel

This commit is contained in:
Oleg Baranov 2025-03-03 14:36:52 +04:00
parent a4c73c10b9
commit 0c5eff2a98
3 changed files with 20 additions and 7 deletions

View file

@ -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()

View file

@ -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.
### 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.

View file

@ -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) {