Skip to content

Commit 94b00dd

Browse files
dryajovdaviddias
authored andcommitted
fix: don't dial on relay if not enabled (libp2p#234)
1 parent 3183025 commit 94b00dd

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/dial.js

+4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ function dial (swarm) {
130130
function dialCircuit (cb) {
131131
log(`Falling back to dialing over circuit`)
132132
pi.multiaddrs.add(`/p2p-circuit/ipfs/${pi.id.toB58String()}`)
133+
if (!swarm.transports[Circuit.tag]) {
134+
return cb(new Error(`Circuit not enabled!`))
135+
}
136+
133137
swarm.transport.dial(Circuit.tag, pi, (err, conn) => {
134138
if (err) {
135139
log(err)

test/circuit.js

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe(`circuit`, function () {
2121
let peerA
2222
let swarmB // WS
2323
let peerB
24+
let swarmC // no transports
2425
let peerC // just a peer
2526
let dialSpyA
2627

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

4041
swarmA = new Swarm(peerA, new PeerBook())
4142
swarmB = new Swarm(peerB, new PeerBook())
43+
swarmC = new Swarm(peerC, new PeerBook())
4244

4345
swarmA.transport.add('tcp', new TCP())
4446
swarmA.transport.add('WebSockets', new WS())
@@ -100,6 +102,16 @@ describe(`circuit`, function () {
100102
})
101103
})
102104

105+
it(`should not try circuit if not enabled`, function (done) {
106+
swarmC.dial(peerA, (err, conn) => {
107+
expect(err).to.exist()
108+
expect(conn).to.not.exist()
109+
110+
expect(err).to.match(/Could not dial in any of the transports or relays/)
111+
done()
112+
})
113+
})
114+
103115
it(`should not dial circuit if other transport succeed`, function (done) {
104116
swarmA.dial(peerB, (err) => {
105117
expect(err).not.to.exist()

0 commit comments

Comments
 (0)