Skip to content

Commit

Permalink
Return conn on swarm.dial
Browse files Browse the repository at this point in the history
  • Loading branch information
fbaiodias committed Mar 20, 2016
1 parent f2df558 commit c726c25
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
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
28 changes: 28 additions & 0 deletions tests/swarm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c726c25

Please sign in to comment.