Skip to content

Latest commit

 

History

History
81 lines (51 loc) · 5.89 KB

freebsd_ton_dht_config.md

File metadata and controls

81 lines (51 loc) · 5.89 KB

FreeBSD Telegram Open Network dht server configuration guide

What is DHT Server

DHT stands for Distributed Hash Table. [TODO]: Describe why TON needs it...

Configuration and initialization of TON dht server

This guide outlines process of conifguration and initialization of dht server for Telegram Open Network based blockchain networks on FreeBSD host, based on example of Newton Blockchain Testnet.

Following this guide you should be able to spawn dht servers for other networks as well, even on the same machine / virtual host if you desire.

Prerequesites / assumptions

Completion of chapter 1 of FreeBSD Telegram Open Network installation guide and as a result:

  • Compiled and installed distribution under /usr/local/opt/ton
  • Presence of /var/db/ton data directory
  • Access to internet from the host

We also assume that you chose to create a dedicated user called tond and this user has read/write access to /var/db/ton directory. You can substitute this username for any other user, just make sure that this account can access /var/db/ton.

Chapter 1: Create work directory for your server

In our example server work directory will be named: /var/db/ton/newton-testnet-dht.

sudo -u tond mkdir -p /var/db/ton/newton-testnet-dht/{etc,db,log}
sudo -u tond chmod -R 700 /var/db/ton/newton-testnet-dht

This should work if you have a user tond and this user has r/w rights to /var/db/ton

Result

We have created a work directory for our ton dht server.

Chapter 2: Download global network configuration

Configuration of each TON dht server begins with downloading of global configuration file for your network. This file contains some basic information about network, for example it specifies at least one dht server. [TODO]: Why? What's the point here?

Each network (Newton testnet, TFC testnet, TON testnet2, Freeton etc.) has it's own global configuration file. Source of those files depends on the network. We will be using Newton Blockchain testnet global configuration file:

sudo -u tond fetch https://raw.githubusercontent.com/newton-blockchain/newton-blockchain.github.io/master/newton-test.global.config.json -o /var/db/ton/newton-testnet-dht/etc/global_config.json

After this file you should have a file /var/db/ton/newton-testnet-dht/etc/global_config.json with some data in it. Please do not edit this file, there is nothing what you as dht server operator need to change there.

Result

We have downloaded global configuration file for our dht server, and can generate local configuration.

Chapter 3: Initialize local configuration

Next step is to create local configuration using global configuration file downloaded in previous step.

sudo -u tond /usr/local/opt/ton/bin/dht-server --global-config /var/db/ton/newton-testnet-dht/etc/global_config.json --db /var/db/ton/newton-testnet-dht/db --ip IP:PORT --logname /var/db/ton/newton-testnet-dht/log/init.log

Replace IP and PORT with fixed public IP of your dht server and PORT number of your choice, I would advise to use high port number beginning from 20000.

This command will run and exit without any output but if execution was success then local configuration file /var/db/ton/newton-testnet-dht/db/config.json would be generated. If the file is not there then something went wrong, check log files.

Important: Please note that the command used here is pretty much identical to the one that is used to run actual dht server. If the local configuration file already exists then you will start a dht server. (command will not exit automatically). This is not a problem, just break it off (ctrl_c).

Result

We have generated a local configuration file /var/db/ton/newton-testnet-dht/db/config.json for our dht server. This file contains quite a few things: our IP address, network port, generated adnl address etc. This is the holy grail of our dht server instance.

Essentially, this is it: your machine can operate as a dht server, you can try and start it by running:

sudo -u tond /usr/local/opt/ton/bin/dht-server --global-config /var/db/ton/newton-testnet-dht/etc/global_config.json --db /var/db/ton/newton-testnet-dht/db --logname /var/db/ton/newton-testnet-dht/log/server.log

If all went well then this command should stay in foreground as long as you do not kill it. Check out the log files for information on what is going on.

Automate the dht server

It is at this step that I advise you to automate start/stop of the dht server as a system service, I strongly advise to utilize daemontools do do that, please consult Chapter 3 of FreeBSD Telegram Open Network installation guide.

Log files

dht-server produces logs in same format as validator-engine, please consult FreeBSD Telegram Open Network full node configuration guide on how the logs are named.

Step 4: Making signed network record

If you want to define your DHT server in network configuration file you must create a signed dht record.

To do so, I have added a helpful mkdht.sh script. This script takes three arguments:

  • db directory of your dht server, this is same path you specify with --db parameter for dht-server
  • public ip address of your dht server in decimal notation! you can read it out in /var/db/ton/newton-testnet-node/db/config.json
  • port number of your dht server

Example:

sudo -u tond ./mkdht.sh /var/db/ton/newton-testnet-dht/db 1243007544 22222

If all went ok you should be presented with JSON structure identical to other dht records in network config. Inject it into the config or send to the people wo can do so.