|
1 | 1 | # Ocean Node Networking |
2 | 2 |
|
3 | | -## Networking in cloud environments or DMZ |
| 3 | +For other nodes (and browsers) to reach your node, it must be reachable at a stable, publicly routable address. Work through the options below in order — stop at the first one that applies to your setup. |
4 | 4 |
|
5 | | -In order for your node to join the network, the others nodes needs to be able to connect to it. |
6 | | -All options can be controlled using [environment |
7 | | -variables](env.md#p2p) |
| 5 | +## Option 1: Static Public IP |
8 | 6 |
|
9 | | -To quickly start your node, you can keep all of the default values,but most likely it will hurt performance. If you want a customised approach, here are the full steps: |
| 7 | +If your machine has a static public IP directly assigned to it (common in VPS/cloud environments), set `P2P_ANNOUNCE_ADDRESSES` to announce that address. The quickstart script does this automatically when you provide your IP or domain name. |
10 | 8 |
|
11 | | -- decide what IP version to use (IPV4 or/and IPv6). You should use both if available. |
12 | | -- decide if you want to filter private ips (if you run multiple nodes in a LAN or cloud environment, leave them on) |
13 | | -- if you already have an external ip configured on your machine, you are good to go. |
14 | | -- if you have a private ip, but an UPNP gateway, you should be fine as well. |
15 | | -- if you have a private ip and you can forward external ports from your gateway, use P2P_ANNOUNCE_ADDRESSES and let other nodes know your external IP/port. |
16 | | -- if you cannot forward ports on your gateway, the only choice is to use a circuit relay server (then all traffic will go through that node and it will proxy) |
| 9 | +Example for a node with public IP `1.2.3.4`, using ports 9000 (TCP) and 9001 (WebSocket/TLS): |
| 10 | + |
| 11 | +```bash |
| 12 | +P2P_ANNOUNCE_ADDRESSES='[ |
| 13 | + "/ip4/1.2.3.4/tcp/9000", |
| 14 | + "/ip4/1.2.3.4/tcp/9001/ws", |
| 15 | + "/ip4/1.2.3.4/tcp/9001/tls/ws" |
| 16 | +]' |
| 17 | +``` |
| 18 | + |
| 19 | +The `/tls/ws` entry enables [AutoTLS](#tls-and-sni-server-name-indication) for node-to-browser communication. AutoTLS provisions a certificate and serves TLS at the transport layer on the WebSocket port, making it browser-compatible — no DNS setup required on your part. |
| 20 | + |
| 21 | +## Option 2: Dynamic DNS (no static IP) |
| 22 | + |
| 23 | +If your public IP changes (residential ISP, dynamic VPS), use a Dynamic DNS (DDNS) service to get a stable hostname that always resolves to your current IP. |
| 24 | + |
| 25 | +Popular free DDNS providers: [DuckDNS](https://www.duckdns.org/), [No-IP](https://www.noip.com/), [Dynu](https://www.dynu.com/). |
| 26 | + |
| 27 | +Once you have a hostname (e.g. `mynode.duckdns.org`), set up the DDNS client on your machine to keep it updated, then use the hostname in your announce addresses: |
| 28 | + |
| 29 | +```bash |
| 30 | +P2P_ANNOUNCE_ADDRESSES='[ |
| 31 | + "/dns4/mynode.duckdns.org/tcp/9000", |
| 32 | + "/dns4/mynode.duckdns.org/tcp/9001/ws", |
| 33 | + "/dns4/mynode.duckdns.org/tcp/9001/tls/ws" |
| 34 | +]' |
| 35 | +``` |
| 36 | + |
| 37 | +## Option 3: Port Forwarding |
| 38 | + |
| 39 | +If you are behind a NAT router (home network), you need to forward the P2P ports from your router to the machine running the node. |
| 40 | + |
| 41 | +1. Find the local IP of your machine (e.g. `192.168.1.50`). |
| 42 | +2. Log in to your router admin panel and add port forwarding rules: |
| 43 | + - External TCP port `9000` → `192.168.1.50:9000` |
| 44 | + - External TCP port `9001` → `192.168.1.50:9001` |
| 45 | +3. Find your public IP (e.g. via `curl ifconfig.me`) or set up a DDNS hostname (see Option 2). |
| 46 | +4. Set `P2P_ANNOUNCE_ADDRESSES` to your public IP or DDNS hostname as shown above. |
| 47 | + |
| 48 | +If your router supports UPnP, the node can attempt to configure port forwarding automatically. Enable it with: |
| 49 | + |
| 50 | +```bash |
| 51 | +P2P_ENABLE_UPNP=true |
| 52 | +``` |
| 53 | + |
| 54 | +UPnP is not reliable on all routers and should not be relied on as the sole method. |
| 55 | + |
| 56 | +## Option 4: Circuit Relay (fallback) |
| 57 | + |
| 58 | +If none of the above options are available (strict NAT, no port forwarding, no public IP), use a circuit relay. A relay node proxies traffic between peers, allowing your node to participate in the network without being directly reachable. |
| 59 | + |
| 60 | +Enable the circuit relay client: |
| 61 | + |
| 62 | +```bash |
| 63 | +P2P_ENABLE_CIRCUIT_RELAY_CLIENT=true |
| 64 | +P2P_CIRCUIT_RELAYS=1 |
| 65 | +``` |
| 66 | + |
| 67 | +Note: circuit relay increases latency and bandwidth usage on the relay node. It should be a last resort — a node running only via relay is a burden on the network and will have degraded performance. |
| 68 | + |
| 69 | +Do not enable `P2P_ENABLE_CIRCUIT_RELAY_SERVER` on edge nodes; that setting is for well-connected nodes that want to help others. |
| 70 | + |
| 71 | +--- |
17 | 72 |
|
18 | 73 | ## TLS and SNI (Server Name Indication) |
19 | 74 |
|
20 | | -AutoTLS is used to provision TLS certificates for your node in order to allow P2P node-to-browser communication. |
21 | | -To enable SNI with Ocean Node's autoTLS feature, include `/tls/ws` or `/tls/wss` addresses in `P2P_ANNOUNCE_ADDRESSES`: |
| 75 | +AutoTLS provisions TLS certificates for your node automatically, enabling P2P node-to-browser communication. It is always active internally — no DNS or certificate setup required on your part. For it to work, you must include a `/tls/ws` entry in `P2P_ANNOUNCE_ADDRESSES`, which the quickstart script does automatically. |
22 | 76 |
|
23 | | -Add to .env file |
| 77 | +AutoTLS serves TLS at the transport layer on the WebSocket port, making it standard browser-compatible WSS — no separate port is needed. |
| 78 | + |
| 79 | +Example `.env` / docker-compose entry: |
24 | 80 |
|
25 | 81 | ```bash |
26 | | -export P2P_ANNOUNCE_ADDRESSES='[ |
27 | | - "/ip4/<your-ip-addr>/tcp/9000", |
28 | | - "/ip4/<your-ip-addr>/tcp/9001/tls/ws", |
29 | | - "/ip4/<your-ip-addr>/tcp/9005/tls/wss", |
| 82 | +P2P_ANNOUNCE_ADDRESSES='[ |
| 83 | + "/ip4/<your-ip>/tcp/9000", |
| 84 | + "/ip4/<your-ip>/tcp/9001/ws", |
| 85 | + "/ip4/<your-ip>/tcp/9001/tls/ws" |
30 | 86 | ]' |
31 | 87 | ``` |
32 | 88 |
|
33 | | -Or in config.json file: |
| 89 | +Or in `config.json`: |
34 | 90 |
|
35 | 91 | ```json |
36 | 92 | { |
37 | 93 | "p2pConfig": { |
38 | 94 | "announceAddresses": [ |
39 | | - "/ip4/<your-ip-addr>/tcp/9000", |
40 | | - "/ip4/<your-ip-addr>/tcp/9001/tls/ws", |
41 | | - "/ip4/<your-ip-addr>/tcp/9005/tls/wss" |
| 95 | + "/ip4/<your-ip>/tcp/9000", |
| 96 | + "/ip4/<your-ip>/tcp/9001/ws", |
| 97 | + "/ip4/<your-ip>/tcp/9001/tls/ws" |
42 | 98 | ] |
43 | 99 | } |
44 | 100 | } |
45 | 101 | ``` |
46 | 102 |
|
47 | | -When TLS certificates are provisioned, you should see logs like: |
| 103 | +When a TLS certificate is provisioned successfully, you will see logs like: |
48 | 104 |
|
49 | 105 | ``` |
50 | 106 | ----- A TLS certificate was provisioned ----- |
51 | 107 | ----- TLS addresses: ----- |
52 | | -/ip4/<your-ip-addr>/tcp/9001/sni/... |
53 | | -/ip4/<your-ip-addr>/tcp/9005/sni/... |
| 108 | +/ip4/<your-ip>/tcp/9001/sni/... |
| 109 | +/ip4/<your-ip>/tcp/9001/sni/... |
54 | 110 | ----- End of TLS addresses ----- |
55 | 111 | ``` |
56 | 112 |
|
57 | | -In order to check connectivity, you can do the following: |
| 113 | +## Verifying Connectivity |
58 | 114 |
|
59 | | -### On your node, check and observe how your node sees itself: |
| 115 | +### Check how your node sees itself |
60 | 116 |
|
61 | 117 | ```bash |
62 | | -curl http://localhost:8000/getP2pPeer?peerId=16Uiu2HAkwWe6BFQXZWg6zE9X7ExynvXEe9BRTR5Wn3udNs7JpUDx |
| 118 | +curl http://localhost:8000/getP2pPeer?peerId=<your-peer-id> |
63 | 119 | ``` |
64 | 120 |
|
65 | | -and observe the addresses section: |
| 121 | +Look at the `addresses` array in the response. Are any of those IPs/hostnames reachable from outside your network? |
66 | 122 |
|
67 | 123 | ```json |
68 | 124 | { |
69 | 125 | "addresses": [ |
70 | | - { "multiaddr": "/ip4/127.0.0.1/tcp/34227", "isCertified": false }, |
71 | | - { "multiaddr": "/ip4/127.0.0.1/tcp/36913/ws", "isCertified": false }, |
72 | | - { "multiaddr": "/ip4/172.15.0.1/tcp/34227", "isCertified": false }, |
73 | | - { "multiaddr": "/ip4/172.15.0.1/tcp/36913/ws", "isCertified": false }, |
74 | | - { "multiaddr": "/ip4/172.26.53.25/tcp/34227", "isCertified": false }, |
75 | | - { "multiaddr": "/ip4/172.26.53.25/tcp/36913/ws", "isCertified": false }, |
76 | | - { "multiaddr": "/ip6/::1/tcp/41157", "isCertified": false } |
77 | | - ], |
78 | | - "protocols": [ |
79 | | - "/floodsub/1.0.0", |
80 | | - "/ipfs/id/1.0.0", |
81 | | - "/ipfs/id/push/1.0.0", |
82 | | - "/ipfs/ping/1.0.0", |
83 | | - "/libp2p/autonat/1.0.0", |
84 | | - "/libp2p/circuit/relay/0.2.0/hop", |
85 | | - "/libp2p/circuit/relay/0.2.0/stop", |
86 | | - "/libp2p/dcutr", |
87 | | - "/meshsub/1.0.0", |
88 | | - "/meshsub/1.1.0", |
89 | | - "/ocean/nodes/1.0.0", |
90 | | - "/ocean/nodes/1.0.0/kad/1.0.0", |
91 | | - "/ocean/nodes/1.0.0/lan/kad/1.0.0" |
92 | | - ], |
93 | | - "metadata": {}, |
94 | | - "tags": {}, |
95 | | - "id": "16Uiu2HAkwWe6BFQXZWg6zE9X7ExynvXEe9BRTR5Wn3udNs7JpUDx", |
96 | | - "publicKey": "08021221021efd24150c233d689ade0f9f467aa6a5a2969a5f52d70c85caac8681925093e3" |
| 126 | + { "multiaddr": "/ip4/1.2.3.4/tcp/9000", "isCertified": false }, |
| 127 | + { "multiaddr": "/ip4/1.2.3.4/tcp/9001/ws", "isCertified": false }, |
| 128 | + { "multiaddr": "/ip4/1.2.3.4/tcp/9001/tls/ws", "isCertified": false } |
| 129 | + ] |
97 | 130 | } |
98 | 131 | ``` |
99 | 132 |
|
100 | | -Are any of those IPs reachable from other nodes? |
| 133 | +### Check how your node is seen by the network |
101 | 134 |
|
102 | | -### To observe how your node is seen by others, start your node, wait a bit and then ask another node to give you details about you: |
| 135 | +Ask a known public node to report back what it knows about you: |
103 | 136 |
|
104 | 137 | ```bash |
105 | | - curl http://node2.oceanprotocol.com:8000/getP2pPeer?peerId=16Uiu2HAk |
106 | | -wWe6BFQXZWg6zE9X7ExynvXEe9BRTR5Wn3udNs7JpUDx |
| 138 | +curl https://cp1.oncompute.ai/getP2pPeer?peerId=<your-peer-id> |
107 | 139 | ``` |
| 140 | + |
| 141 | +If the response is empty or missing your public address, the node is not reachable from the outside. |
| 142 | + |
| 143 | +## All P2P Environment Variables |
| 144 | + |
| 145 | +See [env.md](env.md#p2p) for the full list of P2P configuration options. |
0 commit comments