Skip to content

Tunnel relay reference

Reference for the tunnel-node binary from the adnl-tunnel repository. Deployment and operation are covered in How to run a tunnel relay.

The file config.json is generated automatically on first launch.

FieldTypeDefaultDescription
TunnelServerKeybytesauto-generatedEd25519 private key seed. Defines the ADNL identity.
TunnelListenAddrstring0.0.0.0:17330UDP listen address
TunnelThreadsuintCPU countPacket processing threads
NetworkConfigUrlstringhttps://ton-blockchain.github.io/global.config.jsonTON network configuration URL
ExternalIPstringauto-detectedPublic IP announced to DHT
PaymentsEnabledboolfalseEnable payment channel support
FieldTypeDefaultDescription
ADNLServerKeybytesauto-generatedEd25519 seed for the payment ADNL server
PaymentsNodeKeybytesauto-generatedEd25519 seed for the payment node identity
WalletPrivateKeybytesauto-generatedEd25519 seed for the TON wallet
DBPathstring./payments-db/LevelDB path for payment state
SecureProofPolicyboolfalseUse secure (slower) proof verification instead of fast
MinPricePerPacketRouteuint640Minimum nanoTON per routed packet
MinPricePerPacketInOutuint640Minimum nanoTON per packet traversing the out node (ingress/egress)

Channel configuration (Payments.ChannelsConfig)

Section titled “Channel configuration (Payments.ChannelsConfig)”
FieldDefaultDescription
BufferTimeToCommit10,800 s (3 h)Buffer time before committing channel state
QuarantineDurationSec21,600 s (6 h)Quarantine period after channel dispute
ConditionalCloseDurationSec10,800 s (3 h)Conditional close window
MinSafeVirtualChannelTimeoutSec300 s (5 min)Minimum virtual channel lifetime
ParameterServerClient
MisbehaviorFine3 TON3 TON
ExcessFeeTon0.25 TON0.25 TON
WithdrawWhenAmountReached5 TON0 TON
DepositWhenAmountLessThan0 TON1 TON
DepositUpToAmount0 TON3 TON

Disabled by default.

ParameterValue
Jetton master addressEQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs
Decimals6
SymbolUSDT
ParameterServerClient
Enabledfalsefalse
MisbehaviorFine12 USDT12 USDT
ExcessFeeTon0.35 TON0.35 TON
WithdrawWhenAmountReached15 USDT0 USDT
DepositWhenAmountLessThan0 USDT5 USDT
DepositUpToAmount0 USDT10 USDT

Used by the C library and external integrations.

FieldTypeDefaultDescription
TunnelServerKeybytesauto-generatedEd25519 private key seed
TunnelThreadsuintCPU countPacket processing threads
TunnelSectionsNumuint1Number of relay hops
NodesPoolConfigPathstringemptyPath to shared configuration file
PaymentsEnabledboolfalseEnable payment support
PaymentsobjectClient payment configuration (see below)
FieldTypeDefaultDescription
ADNLServerKeybytesauto-generatedEd25519 seed for the payment ADNL server
PaymentsNodeKeybytesauto-generatedEd25519 seed for the payment node identity
WalletPrivateKeybytesauto-generatedEd25519 seed for the TON wallet
DBPathstring./payments-db/LevelDB path for payment state
SecureProofPolicyboolfalseSecure (slower) proof verification
ChannelsConfigobjectSame structure as the server Payments.ChannelsConfig, with client-specific balance-control defaults
FlagDefaultDescription
-configconfig.jsonConfiguration file path
-v2Verbosity level
-payment-nodeemptyHex-encoded payment node public key for channel deployment
-gen-shared-configemptyGenerate a shared configuration file at the given path and exit
-metrics-listen-addrdisabledPrometheus metrics endpoint
-profile-listen-addrdisabledpprof profiling endpoint
-log-filenametunnel.logLog file path
-log-max-size1024Maximum log file size (MB) before rotation
-log-max-backups16Maximum number of rotated log files to keep
-log-max-age180Maximum age (days) for rotated log files
-log-compressfalseCompress rotated log files
-log-disable-filefalseDisable file logging, write to console only
-v valueLevelNotes
0Error
1Warn
2InfoDefault
3Debug
4DebugEnables chain scanner debug output
5DebugEnables DHT debug logs
6DebugEnables raw ADNL packet logs

Exposed when -metrics-listen-addr is set. Namespace: tunnel_.

MetricTypeLabelsDescription
tunnel_active_inbound_sectionsGaugeActive inbound tunnel sections
tunnel_active_routesGaugeVecpaidActive routing paths
tunnel_active_out_gatewaysGaugeVecpaidActive outbound gateways
tunnel_packets_counterCounterVectype (routed, in, out)Packets processed (in thousands)
tunnel_packets_paid_counterCounterVectype (route, out)Prepaid packets consumed

Packet counters are updated every 5 seconds and reported in units of 1,000.

Available in TTY mode. In non-interactive mode (systemd, Docker), the relay blocks without a command prompt.

CommandDescription
speedToggle per-section packets-per-second display (run again to stop)
statsShow cumulative routing statistics per section
balanceShow earned balance across all payment channels
capacityShow remaining deposit from payment node
wallet-ton-balanceShow on-chain wallet balance
wallet-ton-transferInteractive TON transfer from the relay wallet (3-second confirmation delay)
ConstantValueDescription
Default UDP port17330Relay listen port
Section inactivity timeout120 sIdle sections are closed
Peer inactivity timeout10 sIdle peer connections are dropped
Ping interval3 sKeep-alive frequency
Tunnel reconfigure threshold15 sIdle time before the client silently reconfigures the same path
Tunnel reroute threshold45 sIdle time after which the client calls AskReroute() (60 s cooldown)
Free packet rate10 packets/s (burst 20)Rate limit for unpaid traffic per route
Free startup allowance20,000 packetsPackets allowed before payment enforcement
Max routes per section3Maximum concurrent routes on a single section
Prepay batch size200,000 packetsClient payment batch size
Channel capacity multiplier30 paymentsVirtual channel sized for 30 prepay cycles
Replay window512 bitsSliding-window replay filter per section (8 × uint64)

The tunnel-node binary exposes no on-chain get-methods. All interaction is via the CLI flags, config.json, and the interactive TTY commands listed above.

Build with make library to produce build/libtunnel.a.

Initializes a tunnel client. Reads ClientConfig from the given path, connects to relays listed in SharedConfig, and starts routing.

Parameters: logger callback, receive-batch callback, reinit callback, config path, TON network config JSON.

Returns a Tunnel struct:

typedef struct {
size_t index;
int ip;
int port;
} Tunnel;

The receive callback fires when 100 packets accumulate or after 10 ms, whichever comes first.

Sends a batch of packets through the tunnel.

Parameters: tunnel index, data buffer, packet count. Returns 1 on success, 0 if the index is invalid, -1 on write error.

Each packet in a batch is prefixed with a 16-byte sockaddr_in structure (AF_INET, port in big-endian, IPv4 address) followed by a 2-byte big-endian size field and the payload bytes.

TargetOutputDescription
make binarybuild/tunnel-nodeServer binary for the host platform
make librarybuild/libtunnel.aC static library
make all5 binariesCross-compile: tunnel-node-linux-amd64, tunnel-node-linux-arm64, tunnel-node-mac-amd64, tunnel-node-mac-arm64, tunnel-node-x64.exe