Skip to content

Commit

Permalink
Merge pull request #552 from oceanprotocol/feature/p2p_connection_man…
Browse files Browse the repository at this point in the history
…ager_min_max_envs

add min/max no of connections
  • Loading branch information
alexcos20 authored Jul 13, 2024
2 parents ffad481 + 2cd5a79 commit 3989943
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
7 changes: 6 additions & 1 deletion env.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ Environmental variables are also tracked in `ENVIRONMENT_VARIABLES` within `src/
- `P2P_ENABLE_CIRCUIT_RELAY_CLIENT`: Enable connections through relay servers. Default: `True`
- `P2P_CIRCUIT_RELAYS`: Numbers of relay servers. Default: `1`
- `P2P_BOOTSTRAP_NODES` : List of bootstrap nodes. Defults to OPF nodes. Example: ["/dns4/node3.oceanprotocol.com/tcp/9000/p2p/"]
- `P2P_FILTER_ANNOUNCED_ADDRESSES`: CIDR filters to filter announced addresses. Default: []. Example: ["192.168.0.1/27"]
- `P2P_FILTER_ANNOUNCED_ADDRESSES`: CIDR filters to filter announced addresses. Default: ["172.15.0.0/24"] (docker ip range). Example: ["192.168.0.1/27"]
- `P2P_MIN_CONNECTIONS`: The minimum number of connections below which libp2p will start to dial peers from the peer book. Setting this to 0 disables this behaviour. Default: 1
- `P2P_MAX_CONNECTIONS`: The maximum number of connections libp2p is willing to have before it starts pruning connections to reduce resource usage. Default: 300
- `P2P_AUTODIALPEERRETRYTHRESHOLD`: When we've failed to dial a peer, do not autodial them again within this number of ms. Default: 1000 \* 120
- `P2P_AUTODIALCONCURRENCY`: When dialling peers from the peer book to keep the number of open connections, add dials for this many peers to the dial queue at once. Default: 5
- `P2P_MAXPEERADDRSTODIAL`: Maximum number of addresses allowed for a given peer before giving up. Default: 5

## Additional Nodes (Test Environments)

Expand Down
5 changes: 5 additions & 0 deletions src/@types/OceanNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export interface OceanNodeP2PConfig {
enableCircuitRelayClient: boolean
circuitRelays: number
announcePrivateIp: boolean
minConnections: number
maxConnections: number
autoDialPeerRetryThreshold: number
autoDialConcurrency: number
maxPeerAddrsToDial: number
}

export interface OceanNodeConfig {
Expand Down
9 changes: 7 additions & 2 deletions src/components/P2P/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,12 @@ export class OceanP2P extends EventEmitter {
services: servicesConfig,
connectionManager: {
maxParallelDials: config.p2pConfig.connectionsMaxParallelDials, // 150 total parallel multiaddr dials
dialTimeout: config.p2pConfig.connectionsDialTimeout // 10 second dial timeout per peer dial
dialTimeout: config.p2pConfig.connectionsDialTimeout, // 10 second dial timeout per peer dial
minConnections: config.p2pConfig.minConnections,
maxConnections: config.p2pConfig.maxConnections,
autoDialPeerRetryThreshold: config.p2pConfig.autoDialPeerRetryThreshold,
autoDialConcurrency: config.p2pConfig.autoDialConcurrency,
maxPeerAddrsToDial: config.p2pConfig.maxPeerAddrsToDial
}
}
if (config.p2pConfig.bootstrapNodes && config.p2pConfig.bootstrapNodes.length > 0) {
Expand All @@ -338,7 +343,7 @@ export class OceanP2P extends EventEmitter {
peerDiscovery: [
bootstrap({
list: config.p2pConfig.bootstrapNodes,
timeout: 1000, // in ms,
timeout: 20000, // in ms,
tagName: 'bootstrap',
tagValue: 50,
tagTTL: 10000000000
Expand Down
13 changes: 11 additions & 2 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,17 @@ async function getEnvConfig(isStartup?: boolean): Promise<OceanNodeConfig> {
announcePrivateIp: getBoolEnvValue('P2P_ANNOUNCE_PRIVATE', false),
filterAnnouncedAddresses: readListFromEnvVariable(
ENVIRONMENT_VARIABLES.P2P_FILTER_ANNOUNCED_ADDRESSES,
isStartup
)
isStartup,
['172.15.0.0/24']
),
minConnections: getIntEnvValue(process.env.P2P_MIN_CONNECTIONS, 1),
maxConnections: getIntEnvValue(process.env.P2P_MAX_CONNECTIONS, 300),
autoDialPeerRetryThreshold: getIntEnvValue(
process.env.P2P_AUTODIALPEERRETRYTHRESHOLD,
1000 * 120
),
autoDialConcurrency: getIntEnvValue(process.env.P2P_AUTODIALCONCURRENCY, 5),
maxPeerAddrsToDial: getIntEnvValue(process.env.P2P_MAXPEERADDRSTODIAL, 5)
},
// Only enable provider if we have a DB_URL
hasProvider: !!getEnvValue(process.env.DB_URL, ''),
Expand Down

0 comments on commit 3989943

Please sign in to comment.