Skip to content

Commit 879d736

Browse files
committed
Merge pull request libp2p#30 from xicombd/dial-fixes
Dial fixes
2 parents 9d149ca + c726c25 commit 879d736

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"istanbul": "^0.4.2",
3535
"libp2p-spdy": "^0.2.3",
3636
"libp2p-tcp": "^0.4.0",
37-
"libp2p-websockets": "^0.2.0",
37+
"libp2p-websockets": "^0.2.1",
3838
"mocha": "^2.4.5",
3939
"multiaddr": "^1.3.0",
4040
"peer-id": "^0.6.0",

src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ function Swarm (peerInfo) {
197197
gotMuxer(this.muxedConns[b58Id].muxer)
198198
}
199199

200+
return pt
201+
200202
function gotWarmedUpConn (conn) {
201203
attemptMuxerUpgrade(conn, (err, muxer) => {
202204
if (!protocol) {

tests/swarm-test.js

+41
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ describe('transport - websockets', function () {
232232
conn.end()
233233
})
234234

235+
it('dial (conn from callback)', (done) => {
236+
swarmA.transport.dial('ws', multiaddr('/ip4/127.0.0.1/tcp/9999/websockets'), (err, conn) => {
237+
expect(err).to.not.exist
238+
239+
conn.pipe(bl((err, data) => {
240+
expect(err).to.not.exist
241+
done()
242+
}))
243+
conn.write('hey')
244+
conn.end()
245+
})
246+
})
247+
235248
it('close', (done) => {
236249
var count = 0
237250
swarmA.transport.close('ws', closed)
@@ -323,6 +336,19 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function (
323336
})
324337
})
325338

339+
it('dial on protocol (returned conn)', (done) => {
340+
swarmB.handle('/apples/1.0.0', (conn) => {
341+
conn.pipe(conn)
342+
})
343+
344+
const conn = swarmA.dial(peerB, '/apples/1.0.0', (err) => {
345+
expect(err).to.not.exist
346+
})
347+
conn.end()
348+
conn.on('data', () => {}) // let it flow.. let it flooooow
349+
conn.on('end', done)
350+
})
351+
326352
it('dial to warm a conn', (done) => {
327353
swarmA.dial(peerB, (err) => {
328354
expect(err).to.not.exist
@@ -605,6 +631,21 @@ describe('high level API - with everything mixed all together!', function () {
605631
})
606632
})
607633

634+
it('dial from tcp to tcp+ws (returned conn)', (done) => {
635+
swarmB.handle('/grapes/1.0.0', (conn) => {
636+
conn.pipe(conn)
637+
})
638+
639+
const conn = swarmA.dial(peerB, '/grapes/1.0.0', (err, conn) => {
640+
expect(err).to.not.exist
641+
expect(Object.keys(swarmA.muxedConns).length).to.equal(1)
642+
})
643+
conn.end()
644+
645+
conn.on('data', () => {}) // let it flow.. let it flooooow
646+
conn.on('end', done)
647+
})
648+
608649
it('dial from tcp+ws to tcp+ws', (done) => {
609650
swarmC.handle('/mamao/1.0.0', (conn) => {
610651
conn.pipe(conn)

0 commit comments

Comments
 (0)