diff --git a/src/components/P2P/index.ts b/src/components/P2P/index.ts index ca0d308aa..3013d8c8c 100644 --- a/src/components/P2P/index.ts +++ b/src/components/P2P/index.ts @@ -436,6 +436,14 @@ export class OceanP2P extends EventEmitter { // } } + async getNetworkingStats() { + const ret: any = {} + ret.addrs = await this._libp2p.components.transportManager.getAddrs() + ret.observing = await this._libp2p.components.addressManager.getObservedAddrs() + ret.connections = await this._libp2p.getConnections() + return ret + } + async getRunningOceanPeers() { return await this.getOceanPeers(true, false) } diff --git a/src/components/httpRoutes/getOceanPeers.ts b/src/components/httpRoutes/getOceanPeers.ts index 57bdd248e..54104b730 100644 --- a/src/components/httpRoutes/getOceanPeers.ts +++ b/src/components/httpRoutes/getOceanPeers.ts @@ -5,6 +5,18 @@ import { hasP2PInterface, sendMissingP2PResponse } from './index.js' export const getOceanPeersRoute = express.Router() +getOceanPeersRoute.get( + '/getP2pNetworkStats', + async (req: Request, res: Response): Promise => { + if (hasP2PInterface) { + const stats = await req.oceanNode.getP2PNode().getNetworkingStats() + P2P_LOGGER.log(getDefaultLevel(), `getP2pNetworkStats: ${stats}`, true) + res.json(stats) + } else { + sendMissingP2PResponse(res) + } + } +) getOceanPeersRoute.get( '/getOceanPeers', async (req: Request, res: Response): Promise => {