Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Do not expose new or tried peers from P2P library - Close #4044 #4125

Merged
merged 9 commits into from
Aug 26, 2019
34 changes: 26 additions & 8 deletions elements/lisk-p2p/src/p2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import {
P2PConfig,
P2PDiscoveredPeerInfo,
P2PMessagePacket,
P2PNetworkStatus,
P2PNodeInfo,
P2PPeerInfo,
P2PPenalty,
Expand Down Expand Up @@ -531,13 +530,32 @@ export class P2P extends EventEmitter {
}
}

public getNetworkStatus(): P2PNetworkStatus {
return {
newPeers: [...this._peerBook.newPeers],
triedPeers: [...this._peerBook.triedPeers],
connectedPeers: this._peerPool.getAllConnectedPeerInfos(),
connectedUniquePeers: this._peerPool.getUniqueConnectedPeers(),
};
public getConnectedPeers(): ReadonlyArray<P2PDiscoveredPeerInfo> {
return this._peerPool.getAllConnectedPeerInfos();
}

public getUniqueConnectedPeers(): ReadonlyArray<P2PDiscoveredPeerInfo> {
return this._peerPool.getUniqueConnectedPeers();
}

public getDisconnectedPeers(): ReadonlyArray<P2PDiscoveredPeerInfo> {
const allPeers = this._peerBook.getAllPeers();
const connectedPeers = this.getConnectedPeers();
const disconnectedPeers = allPeers.filter(peer => {
if (
connectedPeers.find(
connectedPeer =>
peer.ipAddress === connectedPeer.ipAddress &&
peer.wsPort === connectedPeer.wsPort,
)
) {
return false;
}

return true;
});

return disconnectedPeers as P2PDiscoveredPeerInfo[];
}

public async request(packet: P2PRequestPacket): Promise<P2PResponsePacket> {
Expand Down
8 changes: 0 additions & 8 deletions elements/lisk-p2p/src/p2p_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ export interface P2PConfig {
readonly secret?: number;
}

// Network info exposed by the P2P library.
export interface P2PNetworkStatus {
readonly newPeers: ReadonlyArray<P2PPeerInfo>;
readonly triedPeers: ReadonlyArray<P2PDiscoveredPeerInfo>;
readonly connectedPeers: ReadonlyArray<P2PDiscoveredPeerInfo>;
readonly connectedUniquePeers: ReadonlyArray<P2PDiscoveredPeerInfo>;
}

// TODO later: Switch to LIP protocol format.
// This is a representation of the outbound peer object according to the current protocol.
export interface ProtocolNodeInfo {
Expand Down
Loading