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

@ -184,13 +184,14 @@ class IdentifyService {
try {
const envelope = await Envelope.openAndCertify(signedPeerRecord, PeerRecord.DOMAIN)
if (this.peerStore.addressBook.consumePeerRecord(envelope)) {
this.peerStore.protoBook.set(id, protocols)
return
}
} catch (err) {
log('received invalid envelope, discard it and fallback to listenAddrs is available', err)
}
// Update peers data in PeerStore
// LEGACY: Update peers data in PeerStore
try {
this.peerStore.addressBook.set(id, listenAddrs.map((addr) => multiaddr(addr)))
} catch (err) {
@ -290,19 +291,14 @@ class IdentifyService {
try {
const envelope = await Envelope.openAndCertify(message.signedPeerRecord, PeerRecord.DOMAIN)
if (this.peerStore.addressBook.consumePeerRecord(envelope)) {
this.peerStore.protoBook.set(id, message.protocols)
return
}
} catch (err) {
<<<<<<< HEAD
log('received invalid envelope, discard it and fallback to listenAddrs is available', err)
// Try Legacy
addresses = message.listenAddrs
=======
log('received invalid envelope, discard it and fallback to listenAddrs is available')
>>>>>>> chore: add certified peer records to persisted peer store
}
// Update peers data in PeerStore
// LEGACY: Update peers data in PeerStore
try {
this.peerStore.addressBook.set(id, message.listenAddrs.map((addr) => multiaddr(addr)))
} catch (err) {
@ -317,7 +313,7 @@ class IdentifyService {
* Get self signed peer record raw envelope.
* @return {Buffer}
*/
async _getSelfPeerRecord() {
async _getSelfPeerRecord () {
const selfSignedPeerRecord = this.peerStore.addressBook.getRawEnvelope(this.peerId)
// TODO: support invalidation when dynamic multiaddrs are supported