This commit is contained in:
David Dias
2016-03-11 14:47:39 +00:00
parent 69bd386afc
commit 412bda731b
3 changed files with 13 additions and 9 deletions

View File

@ -1,7 +1,6 @@
const multistream = require('multistream-select')
// const async = require('async')
const identify = require('./identify')
const PassThrough = require('stream').PassThrough
const DuplexPassThrough = require('duplex-passthrough')
exports = module.exports = Swarm
@ -60,13 +59,13 @@ function Swarm (peerInfo) {
// c) multiaddrs should already be a filtered list
// specific for the transport we are using
const pt = new PassThrough()
const pt = new DuplexPassThrough()
next(multiaddrs.shift())
return pt
function next (multiaddr) {
const conn = t.dial(multiaddr, {ready: () => {
pt.pipe(conn).pipe(pt)
pt.wrapStream(conn)
const cb = callback
callback = noop // this is done to avoid connection drops as connect errors
cb(null, pt)
@ -180,7 +179,7 @@ function Swarm (peerInfo) {
callback = protocol
protocol = null
} else {
pt = new PassThrough()
pt = new DuplexPassThrough()
}
const b58Id = pi.id.toB58String()
@ -293,7 +292,8 @@ function Swarm (peerInfo) {
if (err) {
return callback(err)
}
pt.pipe(conn).pipe(pt)
pt.wrapStream(conn)
callback(null, pt)
})
})