Skip to content

Commit

Permalink
fix: don't dial on relay if not enabled (libp2p#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov authored and daviddias committed Oct 27, 2017
1 parent 3183025 commit 94b00dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/dial.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ function dial (swarm) {
function dialCircuit (cb) {
log(`Falling back to dialing over circuit`)
pi.multiaddrs.add(`/p2p-circuit/ipfs/${pi.id.toB58String()}`)
if (!swarm.transports[Circuit.tag]) {
return cb(new Error(`Circuit not enabled!`))
}

swarm.transport.dial(Circuit.tag, pi, (err, conn) => {
if (err) {
log(err)
Expand Down
12 changes: 12 additions & 0 deletions test/circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe(`circuit`, function () {
let peerA
let swarmB // WS
let peerB
let swarmC // no transports
let peerC // just a peer
let dialSpyA

Expand All @@ -39,6 +40,7 @@ describe(`circuit`, function () {

swarmA = new Swarm(peerA, new PeerBook())
swarmB = new Swarm(peerB, new PeerBook())
swarmC = new Swarm(peerC, new PeerBook())

swarmA.transport.add('tcp', new TCP())
swarmA.transport.add('WebSockets', new WS())
Expand Down Expand Up @@ -100,6 +102,16 @@ describe(`circuit`, function () {
})
})

it(`should not try circuit if not enabled`, function (done) {
swarmC.dial(peerA, (err, conn) => {
expect(err).to.exist()
expect(conn).to.not.exist()

expect(err).to.match(/Could not dial in any of the transports or relays/)
done()
})
})

it(`should not dial circuit if other transport succeed`, function (done) {
swarmA.dial(peerB, (err) => {
expect(err).not.to.exist()
Expand Down

0 comments on commit 94b00dd

Please sign in to comment.