SendingNetwork
Search
K

Public Node Deployment

Edge nodes construct the underlying P2P messaging network. They play the role of relaying messages, providing verifiable storage, supporting video streaming, and serving as network entries for client applications.
Public nodes operate in a completely decentralized manner. The network does not persist any user data, including message history, contact list, etc.
The edge node communication meets the requirements of the libp2p specification, supporting protocols like TCP, UDP, WS, WSS, etc. We offer diverse options for configuring your node.

System Requirements

  • OS: ubuntu 20.04 LTS
  • CPU: Intel Core i3 or equivalent
  • Storage: 200 GB internal storage drive
  • Memory: 8 GB RAM
  • Internet Speed: 10 Mbps
  • A public IP address is needed

Costs of Hosting

Edge nodes can be hosted on any cloud server or local device that meets the system requirements. Depending on the network traffic, the monthly hosting expense could vary. Under the typical situation, running the node on Amazon Web services costs around 200 USD per month.

Preparation

Install PostgreSQL

Edge Node uses a local PostgreSQL database. For setting up a public node for the first time, you need to install the database and configure the login credentials. Take Ubuntu as an example:
sudo apt-get install postgresql postgresql-client
sudo su postgres
psql
\password postgres # replace "password" with your password
If the database didn't start up automatically after installation, do it manually:
sudo pg_ctlcluster 12 main start # 12 is the version number
Now we have set the default username, password, and database name.
Create a new user credential (you may omit the following steps if keep using postgres):
CREATE USER storenode WITH PASSWORD '123456';
Create a database for new user:
CREATE DATABASE db_storenode OWNER storenode;
Grant full access to the database:
GRANT ALL PRIVILEGES ON DATABASE db_storenode to storenode;
For detailed database installation info, please refer to this blog.

Install Docker Engine

Please install the docker engine following the instructions here.

Note

Be sure to set PostgreSQL and Docker server to automatically restart on boot. The commands are as follows:
systemctl enable postgresql-12.service
systemctl enable docker.service
If using a Docker deployment solution, in order to establish a connection with the PostgreSQL server, you must set the listen_addresses = '*' in either /etc/postgresql/*/main/postgresql.conf or /var/lib/pgsql/12/data/postgresql.conf.
Please note that you need to restart the PostgresSQL, otherwise the Docker bridge may not be accessible:
sudo systemctl restart postgresql-12.service

Run the Public Node

Step 1. Get the docker image

docker pull jack0818/network:latest

Step 2. Run public node application

sudo docker run -d -p 9082:9082 -p 9085:9085 -p 2112:2112 -p 12345:12345 -p 9702:9702 -e offPgHost=172.17.0.1 -e offPgUser=postgres -e offPgPasswd=123456 -e offPgDb=postgres -e port=-1 -e listen=9082 -e listenWs=9085 -e ipfs=false -e offProKv=true -e public=true -e offMode=true -e offserver=true -e disableFileLog=true -e peer=/ip4/54.251.110.107/tcp/8082/ws/p2p/12D3KooWESGJGtydLPQ9ki6ikchMDGBrCyGHSKjhTAqiWGRhjbzG,/ip4/44.195.250.124/tcp/8082/ws/p2p/12D3KooWAC2FgzLwi6b2zyRkE6aCPY7f6H2Cn5RLYbkDsLuTcp2d -e disableMdns=true -e internalPrometheusPort=2112 -e publicIP=170.64.130.140 -e additionalPort1=12345 -e additionalPort2=9703 -e additionalPort3=9702 -e mainNet=true -e domain=node5.sending.network -e wssport=443 -v /p2pnode/run/dendrite-p2p:/p2pnode/run/dendrite-p2p -v /p2pnode/.offfiledir:/p2pnode/.offfiledir jack0818/network:latest
Parameter Description
-p command refers to docker and server port mappings, while -e command refers to the command-line argument.
-listenWs Specify the WebSocket listen port if you want to use the WS protocol; otherwise, set it to -1. Make sure you set at least one of the -listenWs or -listen.
-listen Specify the port used for TCP and UDP if these protocols are in use; otherwise, set it to -1. Make sure you set at least one of the -listenWs or -listen.
-port Specify the port for receiving API requests. Set to -1 in most cases since the edge node is seldom used as a client.
-ipfs Set true to support the IPFS feature.
offPgHostThe address of the PostgreSQL server.
offPgUser Specify the database login user name.
offPgPasswd Specify the database login password.
offPgDb Specify the database name.
public Must be true, enforced as an external network p2p node.
offMode Must be true, supports decentralized storage protocol.
offserver Must be true, indicating it's a decentralized storage node.
peer Specify the bootstrapping node(s) addresses, separated with commas. Nodes with public IP and the "public" set to true can all serve as entry nodes.
disableMdns Disable MDNS service. MDNS is used to find and connect to edge nodes inside the intranet.
publicIP Specify the public IP address.
mainNet Set true if it has public IP address.
domain Specify the node domain name.
offProKv Set true to support DID document storage; otherwise, set false.
disableFileLog Set true to disable log recording; otherwise, set false.
announce Specify the public IP addresses and ports explicitly if applicable, separated by commas. If -public is set to false and no -announce value is provided, the node can only be reached by relays, leading to reduced performance and connectivity.
internalPrometheusPort Monitoring reporting port, not modifiable. Currently set to 2112.
additionalPort1 Specify the webSocket persistent connection port, used to notify clients of new messages to fetch, currently set to 12345 and is not modifiable, will support customization in the future.
additionalPort3 Specify the port for client actively accessing the HTTP request. Currently set to 9702.

Verify the Deployment

When you check the Docker logs, you will find the following log messages, confirming a successful startup, along with your peer ID and peer addresses. You can get the peerID by searching in the log file:
sudo docker inspect {container_id} | grep -i LogPath.
cat {container_id}.log | grep "offSrvInit storeMgr.GetCountCodeByAddrsByPeer"
The output looks like this:
{"log":"time=\"2023-06-13T11:41:00.237779796Z\" level=info msg=\"offSrvInit storeMgr.GetCountCodeByAddrsByPeer country:US, localPeerId:12D3KooWBmx5of7TDHmLjc2eycuXKj9h9PuXuMUYKK6j7WTM7zck\"\n","stream":"stdout","time":"2023-06-13T11:41:00.244691536Z"}
In this case, 12D3KooWBmx5of7TDHmLjc2eycuXKj9h9PuXuMUYKK6j7WTM7zck is the peerID.