Skip to content

Commit

Permalink
make it configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcos20 committed Aug 15, 2024
1 parent edf33cc commit d6557ca
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Environmental variables are also tracked in `ENVIRONMENT_VARIABLES` within `src/
- `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
- `P2P_AUTODIALINTERVAL`: Auto dial interval (miliseconds). Amount of time between close and open of new peer connection. Default: 5000
- `P2P_ENABLE_NETWORK_STATS`: Enables 'getP2pNetworkStats' http endpoint. Since this contains private informations (like your ip addresses), this is disabled by default

## Additional Nodes (Test Environments)

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 @@ -438,8 +438,10 @@ export class OceanP2P extends EventEmitter {

async getNetworkingStats() {
const ret: any = {}
ret.addrs = await this._libp2p.components.transportManager.getAddrs()
ret.binds = await this._libp2p.components.addressManager.getListenAddrs()
ret.listen = await this._libp2p.components.transportManager.getAddrs()
ret.observing = await this._libp2p.components.addressManager.getObservedAddrs()
ret.announce = await this._libp2p.components.addressManager.getAnnounceAddrs()
ret.connections = await this._libp2p.getConnections()
return ret
}
Expand Down
7 changes: 4 additions & 3 deletions src/components/httpRoutes/getOceanPeers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import express, { Request, Response } from 'express'
import { getDefaultLevel } from '../../utils/logging/Logger.js'
import { P2P_LOGGER } from '../../utils/logging/common.js'
import { hasP2PInterface, sendMissingP2PResponse } from './index.js'

import { getBoolEnvValue } from '../../utils/config.js'
export const getOceanPeersRoute = express.Router()

getOceanPeersRoute.get(
'/getP2pNetworkStats',
async (req: Request, res: Response): Promise<void> => {
if (hasP2PInterface) {
// only return values if env P2P_ENABLE_NETWORK_STATS is explicitly allowed
if (hasP2PInterface && getBoolEnvValue('P2P_ENABLE_NETWORK_STATS', false)) {
const stats = await req.oceanNode.getP2PNode().getNetworkingStats()
P2P_LOGGER.log(getDefaultLevel(), `getP2pNetworkStats: ${stats}`, true)
res.json(stats)
} else {
sendMissingP2PResponse(res)
res.status(400).send('Not enabled or unavailable')
}
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function getIntEnvValue(env: any, defaultValue: number) {
return isNaN(num) ? defaultValue : num
}

function getBoolEnvValue(envName: string, defaultValue: boolean): boolean {
export function getBoolEnvValue(envName: string, defaultValue: boolean): boolean {
if (!(envName in process.env)) {
return defaultValue
}
Expand Down

0 comments on commit d6557ca

Please sign in to comment.