Skip to content

Commit d6557ca

Browse files
committed
make it configurable
1 parent edf33cc commit d6557ca

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

docs/env.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Environmental variables are also tracked in `ENVIRONMENT_VARIABLES` within `src/
6969
- `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
7070
- `P2P_MAXPEERADDRSTODIAL`: Maximum number of addresses allowed for a given peer before giving up. Default: 5
7171
- `P2P_AUTODIALINTERVAL`: Auto dial interval (miliseconds). Amount of time between close and open of new peer connection. Default: 5000
72+
- `P2P_ENABLE_NETWORK_STATS`: Enables 'getP2pNetworkStats' http endpoint. Since this contains private informations (like your ip addresses), this is disabled by default
7273

7374
## Additional Nodes (Test Environments)
7475

src/components/P2P/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,10 @@ export class OceanP2P extends EventEmitter {
438438

439439
async getNetworkingStats() {
440440
const ret: any = {}
441-
ret.addrs = await this._libp2p.components.transportManager.getAddrs()
441+
ret.binds = await this._libp2p.components.addressManager.getListenAddrs()
442+
ret.listen = await this._libp2p.components.transportManager.getAddrs()
442443
ret.observing = await this._libp2p.components.addressManager.getObservedAddrs()
444+
ret.announce = await this._libp2p.components.addressManager.getAnnounceAddrs()
443445
ret.connections = await this._libp2p.getConnections()
444446
return ret
445447
}

src/components/httpRoutes/getOceanPeers.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ import express, { Request, Response } from 'express'
22
import { getDefaultLevel } from '../../utils/logging/Logger.js'
33
import { P2P_LOGGER } from '../../utils/logging/common.js'
44
import { hasP2PInterface, sendMissingP2PResponse } from './index.js'
5-
5+
import { getBoolEnvValue } from '../../utils/config.js'
66
export const getOceanPeersRoute = express.Router()
77

88
getOceanPeersRoute.get(
99
'/getP2pNetworkStats',
1010
async (req: Request, res: Response): Promise<void> => {
11-
if (hasP2PInterface) {
11+
// only return values if env P2P_ENABLE_NETWORK_STATS is explicitly allowed
12+
if (hasP2PInterface && getBoolEnvValue('P2P_ENABLE_NETWORK_STATS', false)) {
1213
const stats = await req.oceanNode.getP2PNode().getNetworkingStats()
1314
P2P_LOGGER.log(getDefaultLevel(), `getP2pNetworkStats: ${stats}`, true)
1415
res.json(stats)
1516
} else {
16-
sendMissingP2PResponse(res)
17+
res.status(400).send('Not enabled or unavailable')
1718
}
1819
}
1920
)

src/utils/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function getIntEnvValue(env: any, defaultValue: number) {
5757
return isNaN(num) ? defaultValue : num
5858
}
5959

60-
function getBoolEnvValue(envName: string, defaultValue: boolean): boolean {
60+
export function getBoolEnvValue(envName: string, defaultValue: boolean): boolean {
6161
if (!(envName in process.env)) {
6262
return defaultValue
6363
}

0 commit comments

Comments
 (0)