diff --git a/app/modules/bma/lib/bma.ts b/app/modules/bma/lib/bma.ts index 6569d3f6033116de7690f40efddc798608fd1f5c..d3e84395fd35c75f0a1ea2ae36eb5201d8987cd6 100644 --- a/app/modules/bma/lib/bma.ts +++ b/app/modules/bma/lib/bma.ts @@ -70,6 +70,7 @@ export const bma = function(server:Server, interfaces:NetworkInterface[], httpLo httpMethods.httpGET( '/network/peering/peers', (req:any) => net.peersGet(req), BMALimitation.limitAsVeryHighUsage()); httpMethods.httpPOST( '/network/peering/peers', (req:any) => net.peersPost(req), BMALimitation.limitAsHighUsage()); httpMethods.httpGET( '/network/peers', (req:any) => net.peers(), BMALimitation.limitAsHighUsage()); + httpMethods.httpGET( '/network/ws2p/info', (req:any) => net.ws2pInfo(), BMALimitation.limitAsHighUsage()); httpMethods.httpPOST( '/wot/add', (req:any) => wot.add(req), BMALimitation.limitAsHighUsage()); httpMethods.httpPOST( '/wot/certify', (req:any) => wot.certify(req), BMALimitation.limitAsHighUsage()); httpMethods.httpPOST( '/wot/revoke', (req:any) => wot.revoke(req), BMALimitation.limitAsHighUsage()); diff --git a/app/modules/bma/lib/controllers/network.ts b/app/modules/bma/lib/controllers/network.ts index 96069b9b15752a27fd1097dc2a155b2a89eb8324..da9f7cb09af4a84e7be68b5565579e851f0ac093 100644 --- a/app/modules/bma/lib/controllers/network.ts +++ b/app/modules/bma/lib/controllers/network.ts @@ -1,6 +1,7 @@ import {AbstractController} from "./AbstractController"; import {BMAConstants} from "../constants"; -import {HttpMerkleOfPeers, HttpPeer, HttpPeers} from "../dtos"; +import {HttpMerkleOfPeers, HttpPeer, HttpPeers, HttpWS2PInfo} from "../dtos"; +import {WS2PDependency} from "../../../ws2p/index" const _ = require('underscore'); const http2raw = require('../http2raw'); @@ -64,4 +65,20 @@ export class NetworkBinding extends AbstractController { }) }; } + + async ws2pInfo(): Promise<HttpWS2PInfo> { + const cluster = this.server.ws2pCluster + let level1 = 0 + let level2 = 0 + if (cluster) { + level1 = await cluster.clientsCount() + level2 = await cluster.servedCount() + } + return { + peers: { + level1, + level2 + } + }; + } } diff --git a/app/modules/bma/lib/dtos.ts b/app/modules/bma/lib/dtos.ts index 6695086a690ba026a7bed222af30c7495bd6d829..dc13172fc72de1e815cf159560eab19633aeaf86 100644 --- a/app/modules/bma/lib/dtos.ts +++ b/app/modules/bma/lib/dtos.ts @@ -395,6 +395,13 @@ export interface HttpPeers { peers: DBPeer2[] } +export interface HttpWS2PInfo { + peers: { + level1: number, + level2: number + } +} + export const MerkleOfPeers = { "depth": Number, "nodesCount": Number, diff --git a/server.ts b/server.ts index b012cd4eed450147df7d5ce477fef1f5086ac419..259276f1b55967f99942f5118a87032834c94e10 100644 --- a/server.ts +++ b/server.ts @@ -22,6 +22,7 @@ import {RevocationDTO} from "./app/lib/dto/RevocationDTO" import {TransactionDTO} from "./app/lib/dto/TransactionDTO" import {PeerDTO} from "./app/lib/dto/PeerDTO" import {OtherConstants} from "./app/lib/other_constants" +import {WS2PCluster} from "./app/modules/ws2p/lib/WS2PCluster" export interface HookableServer { generatorGetJoinData: (...args:any[]) => Promise<any> @@ -48,6 +49,7 @@ export class Server extends stream.Duplex implements HookableServer { private paramsP:Promise<any>|null private endpointsDefinitions:(()=>Promise<string>)[] = [] private wrongEndpointsFilters:((endpoints:string[])=>Promise<string[]>)[] = [] + ws2pCluster:WS2PCluster|undefined conf:ConfDTO dal:FileDAL