fix: do not return self on peerstore.peers

This commit is contained in:
Vasco Santos
2020-07-15 14:34:51 +02:00
committed by Jacob Heun
parent dab1c8b2a5
commit 15613ccf19
6 changed files with 44 additions and 42 deletions

View File

@ -38,9 +38,11 @@ class PeerStore extends EventEmitter {
/**
* @constructor
*/
constructor () {
constructor ({ peerId } = {}) {
super()
this._peerId = peerId
/**
* AddressBook containing a map of peerIdStr to Address.
*/
@ -73,7 +75,7 @@ class PeerStore extends EventEmitter {
stop () {}
/**
* Get all the stored information of every peer.
* Get all the stored information of every peer known.
* @returns {Map<string, Peer>}
*/
get peers () {
@ -84,6 +86,9 @@ class PeerStore extends EventEmitter {
...this.metadataBook.data.keys()
])
// Remove self peer if present
this._peerId && storedPeers.delete(this._peerId.toB58String())
const peersData = new Map()
storedPeers.forEach((idStr) => {
peersData.set(idStr, this.get(PeerId.createFromCID(idStr)))