Skip to content

Commit

Permalink
detecting innactive multiaddresses after starting
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte committed Nov 28, 2017
1 parent 9f6b3ff commit 2eb9fb3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -177,14 +177,6 @@ class Node extends EventEmitter {
}
})

// detect which multiaddrs we don't have a transport for and remove them
multiaddrs.forEach((multiaddr) => {
if (!multiaddr.toString().match(/\/p2p-circuit($|\/)/) &&
!transports.find((transport) => transport.filter(multiaddr).length > 0)) {
this.peerInfo.multiaddrs.delete(multiaddr)
}
})

series([
(cb) => this.swarm.listen(cb),
(cb) => {
Expand All @@ -208,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()
Expand Down
2 changes: 1 addition & 1 deletion test/nodejs-bundle/multiaddr-trim.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ chai.use(require('dirty-chai'))
const expect = chai.expect
const createNode = require('./utils').createNode

describe.only('multiaddr trim', () => {
describe('multiaddr trim', () => {
let node
it('can create a test node with an irrelevant multiaddr', (done) => {
createNode(
Expand Down

0 comments on commit 2eb9fb3

Please sign in to comment.