mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-05-09 01:12:14 +00:00
Merge pull request #25 from diasdavid/fix/silly-passthrough-bug
silly passthrough bug
This commit is contained in:
commit
d65a0901b9
@ -43,7 +43,7 @@
|
|||||||
"stream-pair": "^1.0.3"
|
"stream-pair": "^1.0.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^1.3.0",
|
"duplex-passthrough": "github:diasdavid/duplex-passthrough",
|
||||||
"ip-address": "^5.0.2",
|
"ip-address": "^5.0.2",
|
||||||
"multistream-select": "^0.6.1",
|
"multistream-select": "^0.6.1",
|
||||||
"protocol-buffers-stream": "^1.2.0"
|
"protocol-buffers-stream": "^1.2.0"
|
||||||
|
12
src/index.js
12
src/index.js
@ -1,7 +1,6 @@
|
|||||||
const multistream = require('multistream-select')
|
const multistream = require('multistream-select')
|
||||||
// const async = require('async')
|
|
||||||
const identify = require('./identify')
|
const identify = require('./identify')
|
||||||
const PassThrough = require('stream').PassThrough
|
const DuplexPassThrough = require('duplex-passthrough')
|
||||||
|
|
||||||
exports = module.exports = Swarm
|
exports = module.exports = Swarm
|
||||||
|
|
||||||
@ -60,13 +59,13 @@ function Swarm (peerInfo) {
|
|||||||
|
|
||||||
// c) multiaddrs should already be a filtered list
|
// c) multiaddrs should already be a filtered list
|
||||||
// specific for the transport we are using
|
// specific for the transport we are using
|
||||||
const pt = new PassThrough()
|
const pt = new DuplexPassThrough()
|
||||||
|
|
||||||
next(multiaddrs.shift())
|
next(multiaddrs.shift())
|
||||||
return pt
|
return pt
|
||||||
function next (multiaddr) {
|
function next (multiaddr) {
|
||||||
const conn = t.dial(multiaddr, {ready: () => {
|
const conn = t.dial(multiaddr, {ready: () => {
|
||||||
pt.pipe(conn).pipe(pt)
|
pt.wrapStream(conn)
|
||||||
const cb = callback
|
const cb = callback
|
||||||
callback = noop // this is done to avoid connection drops as connect errors
|
callback = noop // this is done to avoid connection drops as connect errors
|
||||||
cb(null, pt)
|
cb(null, pt)
|
||||||
@ -180,7 +179,7 @@ function Swarm (peerInfo) {
|
|||||||
callback = protocol
|
callback = protocol
|
||||||
protocol = null
|
protocol = null
|
||||||
} else {
|
} else {
|
||||||
pt = new PassThrough()
|
pt = new DuplexPassThrough()
|
||||||
}
|
}
|
||||||
|
|
||||||
const b58Id = pi.id.toB58String()
|
const b58Id = pi.id.toB58String()
|
||||||
@ -293,7 +292,8 @@ function Swarm (peerInfo) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
pt.pipe(conn).pipe(pt)
|
|
||||||
|
pt.wrapStream(conn)
|
||||||
callback(null, pt)
|
callback(null, pt)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -257,6 +257,7 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function (
|
|||||||
swarmA.dial(peerB, '/pineapple/1.0.0', (err, conn) => {
|
swarmA.dial(peerB, '/pineapple/1.0.0', (err, conn) => {
|
||||||
expect(err).to.not.exist
|
expect(err).to.not.exist
|
||||||
conn.end()
|
conn.end()
|
||||||
|
conn.on('data', () => {}) // let it flow.. let it flooooow
|
||||||
conn.on('end', done)
|
conn.on('end', done)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -272,6 +273,7 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function (
|
|||||||
swarmA.dial(peerB, '/bananas/1.0.0', (err, conn) => {
|
swarmA.dial(peerB, '/bananas/1.0.0', (err, conn) => {
|
||||||
expect(err).to.not.exist
|
expect(err).to.not.exist
|
||||||
conn.end()
|
conn.end()
|
||||||
|
conn.on('data', () => {}) // let it flow.. let it flooooow
|
||||||
conn.on('end', done)
|
conn.on('end', done)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -363,6 +365,8 @@ describe('stream muxing (on TCP)', function () {
|
|||||||
expect(err).to.not.exist
|
expect(err).to.not.exist
|
||||||
expect(Object.keys(swarmA.muxedConns).length).to.equal(1)
|
expect(Object.keys(swarmA.muxedConns).length).to.equal(1)
|
||||||
conn.end()
|
conn.end()
|
||||||
|
|
||||||
|
conn.on('data', () => {}) // let it flow.. let it flooooow
|
||||||
conn.on('end', done)
|
conn.on('end', done)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -386,6 +390,8 @@ describe('stream muxing (on TCP)', function () {
|
|||||||
expect(Object.keys(swarmB.conns).length).to.equal(0)
|
expect(Object.keys(swarmB.conns).length).to.equal(0)
|
||||||
expect(Object.keys(swarmB.muxedConns).length).to.equal(1)
|
expect(Object.keys(swarmB.muxedConns).length).to.equal(1)
|
||||||
conn.end()
|
conn.end()
|
||||||
|
|
||||||
|
conn.on('data', () => {}) // let it flow.. let it flooooow
|
||||||
conn.on('end', done)
|
conn.on('end', done)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -406,7 +412,6 @@ describe('stream muxing (on TCP)', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
|
||||||
describe('conn upgrades', function () {
|
describe('conn upgrades', function () {
|
||||||
this.timeout(20000)
|
this.timeout(20000)
|
||||||
|
|
||||||
@ -439,4 +444,3 @@ describe('high level API - with everything mixed all together!', function () {
|
|||||||
it.skip('add websockets', (done) => {})
|
it.skip('add websockets', (done) => {})
|
||||||
it.skip('dial', (done) => {})
|
it.skip('dial', (done) => {})
|
||||||
})
|
})
|
||||||
*/
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user