mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-23 12:31:57 +00:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a579ff818a | ||
|
6fa9dfc2f5 | ||
|
cad6d04295 | ||
|
215fa08cc8 | ||
|
834a15ddca | ||
|
33172f5850 | ||
|
6519e0ebd7 | ||
|
8341249aa6 | ||
|
4eed2700b0 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libp2p-swarm",
|
||||
"version": "0.19.3",
|
||||
"version": "0.19.5",
|
||||
"description": "libp2p swarm implementation in JavaScript",
|
||||
"main": "lib/index.js",
|
||||
"jsnext:main": "src/index.js",
|
||||
@@ -37,7 +37,7 @@
|
||||
"node": "^4.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"aegir": "^3.0.4",
|
||||
"aegir": "^3.2.0",
|
||||
"bl": "^1.1.2",
|
||||
"buffer-loader": "0.0.1",
|
||||
"chai": "^3.5.0",
|
||||
@@ -55,7 +55,7 @@
|
||||
"dependencies": {
|
||||
"babel-runtime": "^6.6.1",
|
||||
"browserify-zlib": "github:ipfs/browserify-zlib",
|
||||
"duplex-passthrough": "github:diasdavid/duplex-passthrough",
|
||||
"duplexify": "^3.4.3",
|
||||
"ip-address": "^5.8.0",
|
||||
"lodash.contains": "^2.4.3",
|
||||
"multiaddr": "^2.0.0",
|
||||
|
@@ -27,6 +27,7 @@ module.exports = function connection (swarm) {
|
||||
}
|
||||
}
|
||||
|
||||
// If identify happened, when we have the Id of the conn
|
||||
if (swarm.identify) {
|
||||
return gotId()
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const multistream = require('multistream-select')
|
||||
const DuplexPassThrough = require('duplex-passthrough')
|
||||
const Duplexify = require('duplexify')
|
||||
|
||||
const connHandler = require('./default-handler')
|
||||
|
||||
@@ -16,7 +16,7 @@ module.exports = function dial (swarm) {
|
||||
callback = function noop () {}
|
||||
}
|
||||
|
||||
const pt = new DuplexPassThrough()
|
||||
const pt = new Duplexify()
|
||||
|
||||
const b58Id = pi.id.toB58String()
|
||||
|
||||
@@ -169,7 +169,8 @@ module.exports = function dial (swarm) {
|
||||
return callback(err)
|
||||
}
|
||||
|
||||
pt.wrapStream(conn)
|
||||
pt.setReadable(conn)
|
||||
pt.setWritable(conn)
|
||||
pt.peerId = pi.id
|
||||
callback(null, pt)
|
||||
})
|
||||
|
@@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const contains = require('lodash.contains')
|
||||
const DuplexPassThrough = require('duplex-passthrough')
|
||||
const Duplexify = require('duplexify')
|
||||
|
||||
const connHandler = require('./default-handler')
|
||||
|
||||
@@ -47,13 +47,15 @@ module.exports = function (swarm) {
|
||||
|
||||
// c) multiaddrs should already be a filtered list
|
||||
// specific for the transport we are using
|
||||
const pt = new DuplexPassThrough()
|
||||
const pt = new Duplexify()
|
||||
|
||||
next(multiaddrs.shift())
|
||||
return pt
|
||||
function next (multiaddr) {
|
||||
const conn = t.dial(multiaddr, {ready: () => {
|
||||
pt.wrapStream(conn)
|
||||
pt.setReadable(conn)
|
||||
pt.setWritable(conn)
|
||||
pt.getObservedAddrs = conn.getObservedAddrs.bind(conn)
|
||||
const cb = callback
|
||||
callback = noop // this is done to avoid connection drops as connect errors
|
||||
cb(null, pt)
|
||||
|
@@ -19,11 +19,14 @@ describe('stream muxing with spdy (on TCP)', function () {
|
||||
var peerB
|
||||
var swarmC
|
||||
var peerC
|
||||
var swarmD
|
||||
var peerD
|
||||
|
||||
before((done) => {
|
||||
peerA = new Peer()
|
||||
peerB = new Peer()
|
||||
peerC = new Peer()
|
||||
peerD = new Peer()
|
||||
|
||||
// console.log('peer A', peerA.id.toB58String())
|
||||
// console.log('peer B', peerB.id.toB58String())
|
||||
@@ -32,27 +35,32 @@ describe('stream muxing with spdy (on TCP)', function () {
|
||||
peerA.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9001'))
|
||||
peerB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9002'))
|
||||
peerC.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9003'))
|
||||
peerD.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9004'))
|
||||
|
||||
swarmA = new Swarm(peerA)
|
||||
swarmB = new Swarm(peerB)
|
||||
swarmC = new Swarm(peerC)
|
||||
swarmD = new Swarm(peerD)
|
||||
|
||||
swarmA.transport.add('tcp', new TCP())
|
||||
swarmB.transport.add('tcp', new TCP())
|
||||
swarmC.transport.add('tcp', new TCP())
|
||||
swarmD.transport.add('tcp', new TCP())
|
||||
|
||||
parallel([
|
||||
(cb) => swarmA.transport.listen('tcp', {}, null, cb),
|
||||
(cb) => swarmB.transport.listen('tcp', {}, null, cb),
|
||||
(cb) => swarmC.transport.listen('tcp', {}, null, cb)
|
||||
(cb) => swarmC.transport.listen('tcp', {}, null, cb),
|
||||
(cb) => swarmD.transport.listen('tcp', {}, null, cb)
|
||||
], done)
|
||||
})
|
||||
|
||||
after((done) => {
|
||||
parallel([
|
||||
(cb) => swarmA.close(cb),
|
||||
(cb) => swarmB.close(cb)
|
||||
(cb) => swarmB.close(cb),
|
||||
// (cb) => swarmC.close(cb)
|
||||
(cb) => swarmD.close(cb)
|
||||
], done)
|
||||
})
|
||||
|
||||
@@ -60,6 +68,7 @@ describe('stream muxing with spdy (on TCP)', function () {
|
||||
swarmA.connection.addStreamMuxer(spdy)
|
||||
swarmB.connection.addStreamMuxer(spdy)
|
||||
swarmC.connection.addStreamMuxer(spdy)
|
||||
swarmD.connection.addStreamMuxer(spdy)
|
||||
})
|
||||
|
||||
it('handle + dial on protocol', (done) => {
|
||||
@@ -116,6 +125,25 @@ describe('stream muxing with spdy (on TCP)', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('leave a stream open, make sure it does not blow up when the socket is closed', (done) => {
|
||||
swarmD.connection.reuse()
|
||||
|
||||
let count = 0
|
||||
const destroyed = () => ++count === 2 ? done() : null
|
||||
|
||||
swarmD.handle('/banana/1.0.0', (conn) => {
|
||||
conn.on('error', destroyed)
|
||||
conn.pipe(conn)
|
||||
})
|
||||
|
||||
swarmA.dial(peerD, '/banana/1.0.0', (err, conn) => {
|
||||
expect(err).to.not.exist
|
||||
conn.on('error', destroyed)
|
||||
|
||||
swarmD.muxedConns[peerA.id.toB58String()].conn.destroy()
|
||||
})
|
||||
})
|
||||
|
||||
it('close one end, make sure the other does not blow', (done) => {
|
||||
swarmC.close((err) => {
|
||||
if (err) throw err
|
||||
|
Reference in New Issue
Block a user