# Edge Node Deployment Tutorial

Edge nodes are the backbone of the peer-to-peer messaging framework, tasked with forwarding and temporarily storing messages for clients who aren't online. Operating on a fully decentralized architecture, these nodes ensure complete user privacy by not retaining any personal data, such as message history or contacts. In this guide, we'll walk you through the process of setting up your own Edge Node. Once set up, your node will seamlessly integrate into the SDN network, ready to relay messages. Your SendingNetwork Experience Points (SXP) will be linked to your whitelisted wallet address.

***

## System Requirements

Before diving into the setup process, let's make sure your system meets the necessary requirements to run a edge node efficiently. Here's what you'll need:

* **Hardware:**
  * **CPU:** An x86-64 CPU (AMD or Intel) is required. While a dual-core processor is the minimum, we recommend a quad-core or higher for the best performance.
  * **Memory:** At least 8GB of RAM.
  * **Storage:** A minimum of 100GB of free space. SSDs are preferred over HDDs for faster data access and better performance.
* **Software:**
  * **Operating System:** A stable version of Linux. We recommend Ubuntu 20.04 LTS.
* **Network:**&#x20;
  * A **static public IP address** is needed to facilitate incoming connections.&#x20;
  * Always-on 100 Mbps internet with a minimum 100 GB monthly data plan.

{% hint style="info" %}
You may request a static public IP address through your Internet Service Provider or opt to deploy your node on a Virtual Private Server (VPS) equipped with a static public IP. Many VPS service providers can accommodate this need. For details about setting up the VPS, see [VPS setup guide](https://sending-network.gitbook.io/sending.network/edge-node/vps-setup-guide).
{% endhint %}

With these system requirements in check, you'll be well-prepared to start the deployment of your SDN Edge Node.

***

## VPS Platform Firewall Configuration

If utilizing a VPS, it's essential to open ports **9085**, **15858**, **9702**, **2112** in your VPS platform's firewall to guarantee node connectivity to the network. While our installation script will manage firewall configurations within Linux, you must also manually ensure these ports are accessible on your VPS platform.

For firewall configuration across various VPS providers, see [VPS setup guide](https://sending-network.gitbook.io/sending.network/edge-node/vps-setup-guide).

***

## Installation

Use our provided installation script to quickly launch the service with just a few commands. This script simplifies the setup process for the relay service by automating numerous configuration and installation steps. Actions performed by the script include:

* **Install prerequisites**: Installs essential tools including `net-tools`, `telnet`, and `wget`.
* **Configure firewall ports**: Automatically opens necessary ports (`9085`, `15858`, `9702`, `2112`) and verifies their configuration.
* **Install docker**: Detects the OS and installs Docker.
* **Setup docker compose**: Downloads and customizes `docker-compose.yaml` with the local public IP and wallet address for multi-container Docker applications.
* **Launch relay service**: Deploys and starts the relay service using Docker Compose based on the modified configuration.
* **Service and firewall verification**: Checks the relay service's status and firewall port accessibility, reporting success or failure.

### Step 1: Download the installation script

{% hint style="info" %}
Should you encounter any issues or have questions, refer to the [troubleshooting](#troubleshooting) section at the end of this tutorial or seek support from the SendingNetwork [community](https://t.me/SendingNetworkOfficial/1). Check our [FAQ ](https://sending-network.gitbook.io/sending.network/edge-node/alpha-3-testnet-faqs)docs for common questions.
{% endhint %}

Depending on your system, use the following command to download and install the deployment script:

{% tabs %}
{% tab title="Ubuntu or other Debian-based system" %}
{% code overflow="wrap" fullWidth="false" %}

```bash
sudo apt-get install -y wget && wget -N http://node4.sending.network:8120/edgenode_install.sh -P . && sudo chmod 777 edgenode_install.sh
```

{% endcode %}
{% endtab %}

{% tab title="CentOS or other Red Hat-based system" %}
{% code overflow="wrap" %}

```bash
sudo yum install -y wget && wget -N http://node4.sending.network:8120/edgenode_install.sh -P . && sudo chmod 777 edgenode_install.sh
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Step 2: Execute the installation script

Run the following command to execute the script, replacing *WALLET\_ADDRESS* at the end with your whitelisted wallet address to ensure successful node deployment and avoid missing out on SXP:

```bash
./edgenode_install.sh WALLET_ADDRESS
```

{% hint style="info" %}
Please do **NOT** run the script with `sudo` directly as it will impact the node daemon process. Instead, you can run it under a common user account, or by using `sudo su` or the root account.
{% endhint %}

### **Step 3: Finish Installation**

Once enough gas is enough, you'll see the following output.&#x20;

```
Checking...
{"wallet":"0xYourWalletAddress","status":1}
Installing the node, please wait
```

The command might take a few minutes to complete, displaying progress on installing prerequisites, Docker configuration, database setup, and node deployment along the way. If you see the following output, the service has started successfully:

<pre data-overflow="wrap"><code>...
<strong>Message relay service successfully launched and running.
</strong>Firewall successfully opened for port 9085 
Firewall successfully opened for port 15858
Firewall successfully opened for port 9702
Firewall successfully opened for port 2112
</code></pre>

### Firewall verification

If the firewall fails to open, use the following command structure to double check the failed port:

```bash
telnet `wget -qO- http://ipecho.net/plain -4` <port_number>
```

For example, to check port 15858:

```bash
telnet `wget -qO- http://ipecho.net/plain -4` 15858
```

If the output below appears, it indicates an issue with your firewall setup.&#x20;

<pre><code><strong>Trying 34.125.233.176...
</strong>telnet: Unable to connect to remote host: Connection timed out
</code></pre>

Please ensure you have applied the firewall policy allowing traffic for ports 9085, 15858, 9702, and 2112 to your machine if you are using a VPS. You may refer to the firewall configuration example in our [Google Cloud firewall configuration](https://sending-network.gitbook.io/sending.network/vps-setup-guide/google-cloud-platform-gcp#edge-node-only-step-4-configure-the-firewall).

### Check the status of relay service

Input the following command:

```bash
ps wxau | grep edgenode | grep -v monitor | grep -v grep
```

This command filters the processes related to your edgenode service, excluding any monitoring or irrelevant grep processes.

**Expected Output:**&#x20;

If the service is running properly, you should see output similar to the following:

{% code overflow="wrap" %}

```
root       68004 12.3  6.5 2392224 533208 ?      Sl   08:20  15:45 ./edgenode -name=edgenode -port=-1 -listen=9082 -listenWs=9085 -ipfs=false -offProKv=false -public=true -offMode=true -offserver=true -disableFileLog=true -announce=/ip4/34.125.233.176/tcp/9085/ws,/dns4/sdn_fork_https_34.125.233.176/tcp/9702/quic,/dns4/sdn_fork_wss_34.125.233.176/tcp/15858/quic,/dns4/subnet_10.182.0.3/tcp/8111/quic -
```

{% endcode %}

This output indicates that your relay service is currently running, detailing the process's parameters and configuration. If you do not see any output, it means that your relay service might not be running correctly, and you may need to troubleshoot further or restart the service.

### Check the node ID

To display your node ID, use the following command:

```bash
curl http://127.0.0.1:9702/heart
```

***

### Stop the node

To safely stop your node and associated services, execute the commands below in your terminal. These commands will identify and stop the Docker containers for both the Edge node and its related PostgreSQL database.

Execute the following command to stop the Edge node container:

{% code overflow="wrap" %}

```bash
sudo docker ps -a | grep 'jack0818/network:latest' | awk '{print $1}' | xargs sudo docker stop
```

{% endcode %}

Use this command to stop the PostgreSQL container:

```bash
sudo docker ps -a | grep 'postgres:' | awk '{print $1}' | xargs sudo docker stop
```

If you are stopping the node permanently, please remove any previously applied node-related firewall policies from your machine.

### Restart the node

To restart your Edge node, follow these steps:

1. **Download the latest installation script:** In the original directory, obtain the latest script and run it.
2. **Maintain the original directory:** If you run the node from a new directory other than the original one, it will create a new node ID. Points will be accrued with this new ID, but previous points will remain valid under the original node ID.

## Next Steps

After finishing the installation, interact with our auto-reply bot on the SendingMe app to check your node's stats. SendingMe is an all-in-one web3 instant messaging app built on top of SendingNetwork. Refer to [Check Node Stats with Auto-Reply Bot in SendingMe](https://sending-network.gitbook.io/sending.network/edge-node/check-node-stats-with-auto-reply-bot-in-sendingme-app) for instructions on utilizing the bot to monitor your node's performance.

Should you encounter any issues or have questions, don't hesitate to seek support from the SendingNetwork [community](https://t.me/SendingNetworkOfficial/1).

***

## Troubleshooting

### **Error: Unable to start Edge node**

There are several reasons why you might encounter this error:

1. **Non-whitelisted Wallet Address:**
   * **Log Message:**

     ```plaintext
     Unable to start Edge node.
     Please use a whitelisted wallet address.
     ```
   * **Solution:** \
     Ensure you are using the correct whitelisted wallet address that you submitted in the Discord channel. If you are Alpha-1 testnet runner, please use the same wallet address as before.
2. **Restricted Area Deployment:**
   * **Log Message:**

     ```plaintext
     Unable to start Edge node.
     Node service is not supported in this IP country.
     ```
   * **Solution:** \
     Mining is not supported in mainland China. Please make sure you are deploying the node from a supported location.
3. **Multiple Active Nodes:**
   * **Log Message:**

     ```plaintext
     Unable to start Edge node.
     Only one Edge node can be run per wallet address.
     ```
   * **Solution:** \
     Only one active node is allowed at a time per wallet address. If you run a second node in a new location while the original one is still active, you will see this error. To run a new node in another location (such as a different directory or machine), follow these steps:
     1. Stop the current node according to the [stop instructions](#how-to-stop-the-node).
     2. Wait for 10 minutes.
     3. Start the new node in the desired location.
     4. This will create a new node ID, and points will be accrued with this new ID. Previous points will remain valid under the original node ID.

### **Error: Unable to open ports**

There are several reasons why you might encounter this error.&#x20;

1. **Mistakenly running the script with** `sudo`**:**
   * **Log Message:**

     <pre class="language-plaintext" data-overflow="wrap"><code class="lang-plaintext">SCRIPT_NAME:  edgenode_install.sh  CURRENT_PID:  1983541  CURRENT_PID1:   CURRENT_USER:  root
     Killed: 9
     user@vm:~#  no need to update db
     ...
     telnet: Unable to connect to remote host: Connection refused
     Failed to open the firewall for port 2112
     client_loop: send disconnect: Broken pipe
     </code></pre>
   * **Solution:** \
     Please do NOT run the installation script with `sudo` as it will impact the node daemon process. Instead, you can run it under a common user account, or by using `sudo su` or the root account.<br>

     For Linux, run the script with the following command:

     ```sh
     ./edgenode_install.sh WALLET_ADDRESS
     ```
2. **Firewall Configuration issue:**
   * **Log Message:**

     ```plaintext
     telnet: Unable to connect to remote host: Connection refused
     Failed to open the firewall for port 2112
     ```
   * **Solution:**&#x20;

     This error indicates that the ports on your machine are closed or that the VPS provider's firewall is blocking traffic (if applicable). It's possible for the machine's ports to be open, but the VPS provider's firewall might still restrict traffic. This issue could affect the four ports required for the relay service: 9085, 15858, 9702, and 2112.&#x20;

     1. **Verify Port Status:**

        Run the following command to check if the port is open:

        ```sh
        sudo lsof -i -P -n | grep LISTEN
        ```
     2. **Firewall Configuration:**

        Ensure that your firewall is configured to allow traffic for the ports. For a reference on configuring your firewall, please see the firewall configuration section in [Google Cloud firewall configuration](https://sending-network.gitbook.io/sending.network/vps-setup-guide/google-cloud-platform-gcp#edge-node-only-step-4-configure-the-firewall).
