Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Dial fixes #30

Merged
merged 2 commits into from
Mar 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ function Swarm (peerInfo) {
gotMuxer(this.muxedConns[b58Id].muxer)
}

return pt

function gotWarmedUpConn (conn) {
attemptMuxerUpgrade(conn, (err, muxer) => {
if (!protocol) {
Expand Down
41 changes: 41 additions & 0 deletions tests/swarm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -323,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
Expand Down Expand Up @@ -605,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)
Expand Down