Return conn on swarm.dial

This commit is contained in:
Francisco Baio Dias 2016-03-20 18:11:16 +00:00
parent f2df5586d5
commit c726c252df
2 changed files with 30 additions and 0 deletions

View File

@ -197,6 +197,8 @@ function Swarm (peerInfo) {
gotMuxer(this.muxedConns[b58Id].muxer)
}
return pt
function gotWarmedUpConn (conn) {
attemptMuxerUpgrade(conn, (err, muxer) => {
if (!protocol) {

View File

@ -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)