Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
fix: ensure circuit listens last on start
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun committed Nov 15, 2018
1 parent f406dd5 commit 7697281
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const FSM = require('fsm-event')
const EventEmitter = require('events').EventEmitter
const each = require('async/each')
const eachSeries = require('async/eachSeries')
const series = require('async/series')
const TransportManager = require('./transport')
const ConnectionManager = require('./connection/manager')
Expand Down Expand Up @@ -230,7 +231,7 @@ class Switch extends EventEmitter {
* @returns {void}
*/
_onStarting () {
each(this.availableTransports(this._peerInfo), (ts, cb) => {
eachSeries(this.availableTransports(this._peerInfo), (ts, cb) => {
// Listen on the given transport
this.transport.listen(ts, {}, null, cb)
}, (err) => {
Expand Down
7 changes: 5 additions & 2 deletions test/circuit-relay.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe(`circuit`, function () {
const peerB = infos[1]
const peerC = infos[2]

peerA.multiaddrs.add('/ip4/127.0.0.1/tcp/9001')
peerA.multiaddrs.add('/ip4/0.0.0.0/tcp/9001')
peerB.multiaddrs.add('/ip4/127.0.0.1/tcp/9002/ws')

swarmA = new Swarm(peerA, new PeerBook())
Expand Down Expand Up @@ -85,7 +85,10 @@ describe(`circuit`, function () {
], (err) => {
expect(err).to.not.exist()
expect(swarmA._peerInfo.multiaddrs.toArray().filter((a) => a.toString()
.includes(`/p2p-circuit`)).length).to.equal(2)
.includes(`/p2p-circuit`)).length).to.equal(3)
// ensure swarmA has had 0.0.0.0 replaced in the addresses
expect(swarmA._peerInfo.multiaddrs.toArray().filter((a) => a.toString()
.includes(`/0.0.0.0`)).length).to.equal(0)
expect(swarmB._peerInfo.multiaddrs.toArray().filter((a) => a.toString()
.includes(`/p2p-circuit`)).length).to.equal(2)
done()
Expand Down

0 comments on commit 7697281

Please sign in to comment.