Skip to content

Commit

Permalink
Merge pull request #449 from oceanprotocol/feature/p2p_peers_fixes
Browse files Browse the repository at this point in the history
fix p2p peers
  • Loading branch information
alexcos20 authored May 22, 2024
2 parents d250cd3 + 8b00e1b commit 01c0dd7
Show file tree
Hide file tree
Showing 10 changed files with 385 additions and 162 deletions.
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,70 @@ npm run start
```

The dashboard will be made available at: `http://localhost:8000/dashboard/`

## Networking in cloud environments or DMZ

In order for your node to join the network, the others nodes needs to be able to connect to it.
All options can be controlled using [environment
variables](docs/environment-variables.md#p2p)

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:

- decide what IP version to use (IPV4 or/and IPv6). You should use both if available.
- decide if you want to filter private ips (if you run multiple nodes in a LAN or cloud environment, leave them on)
- if you already have an external ip configured on your machine, you are good to go.
- if you have a private ip, but an UPNP gateway, you should be fine as well.
- 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.
- 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)

In order to check connectivity, you can do the following:

### On your node, check and observe how your node sees itself:

```bash
curl http://localhost:8000/getP2pPeer?peerId=16Uiu2HAkwWe6BFQXZWg6zE9X7ExynvXEe9BRTR5Wn3udNs7JpUDx
```

and observe the addresses section:

```json
{
"addresses": [
{ "multiaddr": "/ip4/127.0.0.1/tcp/34227", "isCertified": false },
{ "multiaddr": "/ip4/127.0.0.1/tcp/36913/ws", "isCertified": false },
{ "multiaddr": "/ip4/172.15.0.1/tcp/34227", "isCertified": false },
{ "multiaddr": "/ip4/172.15.0.1/tcp/36913/ws", "isCertified": false },
{ "multiaddr": "/ip4/172.26.53.25/tcp/34227", "isCertified": false },
{ "multiaddr": "/ip4/172.26.53.25/tcp/36913/ws", "isCertified": false },
{ "multiaddr": "/ip6/::1/tcp/41157", "isCertified": false }
],
"protocols": [
"/floodsub/1.0.0",
"/ipfs/id/1.0.0",
"/ipfs/id/push/1.0.0",
"/ipfs/ping/1.0.0",
"/libp2p/autonat/1.0.0",
"/libp2p/circuit/relay/0.2.0/hop",
"/libp2p/circuit/relay/0.2.0/stop",
"/libp2p/dcutr",
"/meshsub/1.0.0",
"/meshsub/1.1.0",
"/ocean/nodes/1.0.0",
"/ocean/nodes/1.0.0/kad/1.0.0",
"/ocean/nodes/1.0.0/lan/kad/1.0.0"
],
"metadata": {},
"tags": {},
"id": "16Uiu2HAkwWe6BFQXZWg6zE9X7ExynvXEe9BRTR5Wn3udNs7JpUDx",
"publicKey": "08021221021efd24150c233d689ade0f9f467aa6a5a2969a5f52d70c85caac8681925093e3"
}
```

Are any of those IPs reachable from other nodes?

### 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:

```bash
curl http://node2.oceanprotocol.com:8000/getP2pPeer?peerId=16Uiu2HAk
wWe6BFQXZWg6zE9X7ExynvXEe9BRTR5Wn3udNs7JpUDx
```
2 changes: 1 addition & 1 deletion dashboard/src/components/NodePeers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function NodePeers() {

return (
<div className={styles.nodes}>
<div className={styles.title24}>Node Peers</div>
<div className={styles.title24}>Connected Nodes</div>
{isLoadingNodePeers && (
<div className={styles.loaderContainer}>
<Spinner />
Expand Down
25 changes: 18 additions & 7 deletions docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,40 @@
**Warning**: the names of some of these environment variables might change at some point in the future.

This page lists the environment variables used by `ocean-node` and what effect
they have.

they have.

## Core

- `PRIVATE_KEY` : Private key used by this node (applies to p2p peer id, asset encryption key, etc)
- `RPCS` : List of RPC URL for each chain. Example:
- `RPCS` : List of RPC URL for each chain. Example:

```bash
export RPC="{ \"1\": \"https://rpc.eth.gateway.fm\", \"137\": \"https://polygon.meowrpc.com\", \"80001\": \"https://rpc-mumbai.maticvigil.com\" }"
```

## P2P

- `P2P_ENABLE_IPV4` : Enable IPv4 conectivity. Defaults: True
- `P2P_ENABLE_IPV6` : Enable IPv6 conectivity. Defaults: True
- `P2P_ipV4BindAddress` : Bind address for IPV4. Defaults to `0.0.0.0`
- `P2P_ipV4BindTcpPort` : Port used on IPv4 TCP connections. Defaults to `0` (Use whatever port is free. When running as docker, please set it explicitly)
- `P2P_ipV4BindWsPort` : Port used on IPv4 WS connections. Defaults to `0` (Use whatever port is free. When running as docker, please set it explicitly)
- `P2P_ipV6BindAddress` : Bind address for IPV6. Defaults to `::1`
- `P2P_ipV6BindTcpPort` : Port used on IPv6 TCP connections. Defaults to `0` (Use whatever port is free. When running as docker, please set it explicitly)
- `P2P_ipV6BindWsPort` : Port used on IPv6 WS connections. Defaults to `0` (Use whatever port is free. When running as docker, please set it explicitly)
- `P2P_pubsubPeerDiscoveryInterval` : Interval (in ms) for discovery using pubsub. Defaults to `1000` (one second)
- `P2P_ANNOUNCE_ADDRESSES` : List of addresses to announce to the network. Example: ["/ip4/1.2.3.4/tcp/8000"]
- `P2P_ANNOUNCE_PRIVATE`: Announce private IPs. Default: True
- `P2P_pubsubPeerDiscoveryInterval` : Interval (in ms) for discovery using pubsub. Defaults to `1000` (one second)
- `P2P_dhtMaxInboundStreams` : Maximum no of DHT inbound streams. Defaults to `500`
- `P2P_dhtMaxOutboundStreams` : Maximum no of DHT outbound streams. Defaults to `500`
- `P2P_mDNSInterval` : Interval (in ms) for discovery using mDNS. Defaults to `20000` (20 seconds)
- `P2P_mDNSInterval` : Interval (in ms) for discovery using mDNS. Defaults to `20000` (20 seconds)
- `P2P_connectionsMaxParallelDials` : Maximum no of parallel dials. Defaults to `150`
- `P2P_connectionsDialTimeout`: Timeout for dial commands. Defaults to `10000` (10 seconds)
- `P2P_connectionsDialTimeout`: Timeout for dial commands. Defaults to `10000` (10 seconds)
- `P2P_ENABLE_UPNP`: Enable UPNP gateway discovery. Default: True
- `P2P_ENABLE_AUTONAT`: Enable AutoNAT discovery. Default: True
- `P2P_ENABLE_CIRCUIT_RELAY_SERVER`: Enable Circuit Relay Server. It will help network, but increase your bandwith usage. Should be disabled for edge nodes. Default: True
- `P2P_ENABLE_CIRCUIT_RELAY_CLIENT`: Enable conections through relay servers. Default: True

## HTTP
- `HTTP_API_PORT` : Port used for HTTP interface. Defaults to `8000`

- `HTTP_API_PORT` : Port used for HTTP interface. Defaults to `8000`
8 changes: 8 additions & 0 deletions src/@types/OceanNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface OceanNodeKeys {

export interface OceanNodeP2PConfig {
bootstrapNodes: string[]
enableIPV4: boolean
enableIPV6: boolean
ipV4BindAddress: string | null
ipV4BindTcpPort: number | null
ipV4BindWsPort: number | null
Expand All @@ -36,6 +38,12 @@ export interface OceanNodeP2PConfig {
mDNSInterval: number
connectionsMaxParallelDials: number
connectionsDialTimeout: number
announceAddresses: string[]
autoNat: boolean
upnp: boolean
enableCircuitRelayServer: boolean
enableCircuitRelayClient: boolean
announcePrivateIp: boolean
}

export interface OceanNodeConfig {
Expand Down
52 changes: 0 additions & 52 deletions src/components/P2P/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,2 @@
export * from './handleBroadcasts.js'
export * from './handleProtocolCommands.js'

export function handlePeerConnect(details: any) {
if (details) {
// const peerId = details.detail
// console.log('Connection established to:', peerId.toString()) // Emitted when a peer has been found
/*
try{
this._libp2p.services.pubsub.connect(peerId.toString())
}
catch(e){
console.log(e)
console.log("Failed to connect pubsub")
}
*/
}
// else{
// console.log("Null evt ")
// }
}

export function handlePeerDisconnect(details: any) {
// const peerId = details.detail
// console.log('Connection closed to:', peerId.toString()) // Emitted when a peer has been found
}

export function handlePeerDiscovery(details: any) {
// const peerInfo = details.detail
// console.log('Discovered new peer:', peerInfo.id.toString())
// console.log(details.detail)
/*
try{
//this._libp2p.services.pubsub.connect(peerInfo.id.toString())
this._libp2p.services.dht.connect(peerInfo.id.toString())
}
catch(e){
console.log(e)
console.log("Failed to connect pubsub")
}
*/
}

export function handlePeerJoined(details: any) {
// console.log('New peer joined us:', details)
}

export function handlePeerLeft(details: any) {
// console.log('New peer joined us:', details)
}

export function handleSubscriptionCHange(details: any) {
// console.log('subscription-change:', details.detail)
}
Loading

0 comments on commit 01c0dd7

Please sign in to comment.