From f2df5586d5c4d1c1fdf71a44a01f9fc9ec0f37d0 Mon Sep 17 00:00:00 2001 From: Francisco Baio Dias Date: Sun, 20 Mar 2016 17:57:14 +0000 Subject: [PATCH 1/2] Update libp2p-websockets and add test for callback's conn --- package.json | 2 +- tests/swarm-test.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 60e1aef..3cda3a1 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "istanbul": "^0.4.2", "libp2p-spdy": "^0.2.3", "libp2p-tcp": "^0.4.0", - "libp2p-websockets": "^0.2.0", + "libp2p-websockets": "^0.2.1", "mocha": "^2.4.5", "multiaddr": "^1.3.0", "peer-id": "^0.6.0", diff --git a/tests/swarm-test.js b/tests/swarm-test.js index 03a6333..fbd892c 100644 --- a/tests/swarm-test.js +++ b/tests/swarm-test.js @@ -232,6 +232,19 @@ describe('transport - websockets', function () { conn.end() }) + it('dial (conn from callback)', (done) => { + swarmA.transport.dial('ws', multiaddr('/ip4/127.0.0.1/tcp/9999/websockets'), (err, conn) => { + expect(err).to.not.exist + + conn.pipe(bl((err, data) => { + expect(err).to.not.exist + done() + })) + conn.write('hey') + conn.end() + }) + }) + it('close', (done) => { var count = 0 swarmA.transport.close('ws', closed) From c726c252df4c23849a29eca2af28f1d09eef8a3e Mon Sep 17 00:00:00 2001 From: Francisco Baio Dias Date: Sun, 20 Mar 2016 18:11:16 +0000 Subject: [PATCH 2/2] Return conn on swarm.dial --- src/index.js | 2 ++ tests/swarm-test.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/index.js b/src/index.js index 27eb70b..eddc858 100644 --- a/src/index.js +++ b/src/index.js @@ -197,6 +197,8 @@ function Swarm (peerInfo) { gotMuxer(this.muxedConns[b58Id].muxer) } + return pt + function gotWarmedUpConn (conn) { attemptMuxerUpgrade(conn, (err, muxer) => { if (!protocol) { diff --git a/tests/swarm-test.js b/tests/swarm-test.js index fbd892c..6c0c3b4 100644 --- a/tests/swarm-test.js +++ b/tests/swarm-test.js @@ -336,6 +336,19 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function ( }) }) + it('dial on protocol (returned conn)', (done) => { + swarmB.handle('/apples/1.0.0', (conn) => { + conn.pipe(conn) + }) + + const conn = swarmA.dial(peerB, '/apples/1.0.0', (err) => { + expect(err).to.not.exist + }) + conn.end() + conn.on('data', () => {}) // let it flow.. let it flooooow + conn.on('end', done) + }) + it('dial to warm a conn', (done) => { swarmA.dial(peerB, (err) => { expect(err).to.not.exist @@ -618,6 +631,21 @@ describe('high level API - with everything mixed all together!', function () { }) }) + it('dial from tcp to tcp+ws (returned conn)', (done) => { + swarmB.handle('/grapes/1.0.0', (conn) => { + conn.pipe(conn) + }) + + const conn = swarmA.dial(peerB, '/grapes/1.0.0', (err, conn) => { + expect(err).to.not.exist + expect(Object.keys(swarmA.muxedConns).length).to.equal(1) + }) + conn.end() + + conn.on('data', () => {}) // let it flow.. let it flooooow + conn.on('end', done) + }) + it('dial from tcp+ws to tcp+ws', (done) => { swarmC.handle('/mamao/1.0.0', (conn) => { conn.pipe(conn)