Skip to content

Commit

Permalink
add min/max no of connections
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcos20 committed Jul 12, 2024
1 parent ffad481 commit 78e09ff
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion env.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ 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_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

## Additional Nodes (Test Environments)

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

export interface OceanNodeConfig {
Expand Down
4 changes: 3 additions & 1 deletion src/components/P2P/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ 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
}
}
if (config.p2pConfig.bootstrapNodes && config.p2pConfig.bootstrapNodes.length > 0) {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,9 @@ async function getEnvConfig(isStartup?: boolean): Promise<OceanNodeConfig> {
filterAnnouncedAddresses: readListFromEnvVariable(
ENVIRONMENT_VARIABLES.P2P_FILTER_ANNOUNCED_ADDRESSES,
isStartup
)
),
minConnections: getIntEnvValue(process.env.P2P_MIN_CONNECTIONS, 1),
maxConnections: getIntEnvValue(process.env.P2P_MAX_CONNECTIONS, 300)
},
// Only enable provider if we have a DB_URL
hasProvider: !!getEnvValue(process.env.DB_URL, ''),
Expand Down

0 comments on commit 78e09ff

Please sign in to comment.