UNPKG

@sangaman/xud

Version:
47 lines 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class PeerList { constructor() { this.peers = new Map(); this.get = (nodePubKey) => { return this.peers.get(nodePubKey); }; this.has = (nodePubKey) => { return this.peers.has(nodePubKey); }; /** * Add a peer to the list. * @returns `true` if the peer was added, `false` if it could not be added due to a missing or duplicate nodePubKey */ this.add = (peer) => { if (!peer.nodePubKey || this.has(peer.nodePubKey)) { return false; } else { this.peers.set(peer.nodePubKey, peer); return true; } }; /** * Remove a peer from the list by its nodePubKey. * @returns `true` if the peer was removed, `false` if no peer was removed */ this.remove = (nodePubKey) => { return this.peers.delete(nodePubKey); }; this.forEach = (callback) => { this.peers.forEach(callback); }; } get length() { let length = 0; this.forEach((peer) => { if (peer.connected) { length = length + 1; } }); return length; } } exports.default = PeerList; //# sourceMappingURL=PeerList.js.map