Skip to content

Commit 5c76907

Browse files
committed
Merge pull request libp2p#52 from diasdavid/fix/warm-a-warm-up-the-other-way-around
make sure it does not try to dial on empty proto and write tests for it
2 parents 20994f5 + 074e7e3 commit 5c76907

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ function Swarm (peerInfo) {
246246
gotWarmedUpConn(conn)
247247
}
248248
} else {
249+
if (!protocol) {
250+
return callback()
251+
}
249252
gotMuxer(this.muxedConns[b58Id].muxer)
250253
}
251254

test/09-swarm-with-muxing.node.js

+21-5
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,7 @@ describe('high level API - with everything mixed all together!', function () {
125125

126126
it.skip('add multiplex', (done) => {})
127127

128-
it('dial from tcp to tcp+ws', (done) => {
129-
swarmB.handle('/anona/1.0.0', (conn) => {
130-
conn.pipe(conn)
131-
})
132-
128+
it('warm up from A to B on tcp to tcp+ws', (done) => {
133129
swarmB.once('peer-mux-established', (peerInfo) => {
134130
expect(peerInfo.id.toB58String()).to.equal(peerA.id.toB58String())
135131
})
@@ -138,6 +134,26 @@ describe('high level API - with everything mixed all together!', function () {
138134
expect(peerInfo.id.toB58String()).to.equal(peerB.id.toB58String())
139135
})
140136

137+
swarmA.dial(peerB, (err) => {
138+
expect(err).to.not.exist
139+
expect(Object.keys(swarmA.muxedConns).length).to.equal(1)
140+
done()
141+
})
142+
})
143+
144+
it('warm up a warmed up, from B to A', (done) => {
145+
swarmB.dial(peerA, (err) => {
146+
expect(err).to.not.exist
147+
expect(Object.keys(swarmA.muxedConns).length).to.equal(1)
148+
done()
149+
})
150+
})
151+
152+
it('dial from tcp to tcp+ws, on protocol', (done) => {
153+
swarmB.handle('/anona/1.0.0', (conn) => {
154+
conn.pipe(conn)
155+
})
156+
141157
swarmA.dial(peerB, '/anona/1.0.0', (err, conn) => {
142158
expect(err).to.not.exist
143159
expect(Object.keys(swarmA.muxedConns).length).to.equal(1)

0 commit comments

Comments
 (0)