Skip to content

Commit

Permalink
add getP2pNetworkStats route
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcos20 committed Aug 15, 2024
1 parent ae99b14 commit edf33cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/components/P2P/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 12 additions & 0 deletions src/components/httpRoutes/getOceanPeers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ import { hasP2PInterface, sendMissingP2PResponse } from './index.js'

export const getOceanPeersRoute = express.Router()

getOceanPeersRoute.get(
'/getP2pNetworkStats',
async (req: Request, res: Response): Promise<void> => {
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<void> => {
Expand Down

0 comments on commit edf33cc

Please sign in to comment.