mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-24 06:21:32 +00:00
fix: remove innactive multiaddrs (#131)
This commit is contained in:
committed by
David Dias
parent
67ca37c356
commit
1b7360fcfa
17
src/index.js
17
src/index.js
@ -156,15 +156,15 @@ class Node extends EventEmitter {
|
||||
// so that we can have webrtc-star addrs without adding manually the id
|
||||
const maOld = []
|
||||
const maNew = []
|
||||
this.peerInfo.multiaddrs.forEach((ma) => {
|
||||
this.peerInfo.multiaddrs.toArray().forEach((ma) => {
|
||||
if (!ma.getPeerId()) {
|
||||
maOld.push(ma)
|
||||
maNew.push(ma.encapsulate('/ipfs/' + this.peerInfo.id.toB58String()))
|
||||
}
|
||||
})
|
||||
this.peerInfo.multiaddrs.replace(maOld, maNew)
|
||||
const multiaddrs = this.peerInfo.multiaddrs.toArray()
|
||||
|
||||
const multiaddrs = this.peerInfo.multiaddrs.toArray()
|
||||
transports.forEach((transport) => {
|
||||
if (transport.filter(multiaddrs).length > 0) {
|
||||
this.swarm.transport.add(
|
||||
@ -200,6 +200,19 @@ class Node extends EventEmitter {
|
||||
}
|
||||
cb()
|
||||
},
|
||||
(cb) => {
|
||||
// detect which multiaddrs we don't have a transport for and remove them
|
||||
const multiaddrs = this.peerInfo.multiaddrs.toArray()
|
||||
transports.forEach((transport) => {
|
||||
multiaddrs.forEach((multiaddr) => {
|
||||
if (!multiaddr.toString().match(/\/p2p-circuit($|\/)/) &&
|
||||
!transports.find((transport) => transport.filter(multiaddr).length > 0)) {
|
||||
this.peerInfo.multiaddrs.delete(multiaddr)
|
||||
}
|
||||
})
|
||||
})
|
||||
cb()
|
||||
},
|
||||
(cb) => {
|
||||
this.emit('start')
|
||||
cb()
|
||||
|
Reference in New Issue
Block a user