mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-28 08:21:33 +00:00
update swarm
This commit is contained in:
22
package.json
22
package.json
@ -4,10 +4,9 @@
|
|||||||
"description": "libp2p swarm implementation in Node.js",
|
"description": "libp2p swarm implementation in Node.js",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "./node_modules/.bin/lab tests/*-test.js",
|
"test": "mocha tests/*-test.js",
|
||||||
"coverage": "./node_modules/.bin/lab -t 88 tests/*-test.js",
|
"coverage": "istanbul cover --print both -- _mocha tests/*-test.js",
|
||||||
"lint": "./node_modules/.bin/standard",
|
"lint": "standard"
|
||||||
"validate": "npm ls"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -24,20 +23,20 @@
|
|||||||
"homepage": "https://github.com/diasdavid/js-libp2p-swarm",
|
"homepage": "https://github.com/diasdavid/js-libp2p-swarm",
|
||||||
"pre-commit": [
|
"pre-commit": [
|
||||||
"lint",
|
"lint",
|
||||||
"test",
|
"test"
|
||||||
"coverage"
|
|
||||||
],
|
],
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^4.0.0"
|
"node": "^4.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"code": "^1.4.1",
|
"chai": "^3.5.0",
|
||||||
"lab": "^5.13.0",
|
"istanbul": "^0.4.2",
|
||||||
"libp2p-spdy": "^0.1.0",
|
"libp2p-spdy": "^0.1.0",
|
||||||
"libp2p-tcp": "^0.1.1",
|
"libp2p-tcp": "^0.1.1",
|
||||||
"precommit-hook": "^3.0.0",
|
"mocha": "^2.4.5",
|
||||||
|
"pre-commit": "^1.1.2",
|
||||||
"sinon": "^1.15.4",
|
"sinon": "^1.15.4",
|
||||||
"standard": "^4.5.2",
|
"standard": "^6.0.7",
|
||||||
"stream-pair": "^1.0.3"
|
"stream-pair": "^1.0.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -49,7 +48,6 @@
|
|||||||
"multistream-select": "^0.6.1",
|
"multistream-select": "^0.6.1",
|
||||||
"peer-id": "^0.3.3",
|
"peer-id": "^0.3.3",
|
||||||
"peer-info": "^0.3.2",
|
"peer-info": "^0.3.2",
|
||||||
"protocol-buffers-stream": "^1.2.0",
|
"protocol-buffers-stream": "^1.2.0"
|
||||||
"spdy-stream-muxer": "^0.6.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
342
src/index.js
342
src/index.js
@ -1,3 +1,343 @@
|
|||||||
var Swarm = require('./swarm')
|
var multistream = require('multistream-select')
|
||||||
|
var async = require('async')
|
||||||
|
var identify = require('./identify')
|
||||||
|
|
||||||
exports = module.exports = Swarm
|
exports = module.exports = Swarm
|
||||||
|
|
||||||
|
function Swarm (peerInfo) {
|
||||||
|
var self = this
|
||||||
|
|
||||||
|
if (!(self instanceof Swarm)) {
|
||||||
|
throw new Error('Swarm must be called with new')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!peerInfo) {
|
||||||
|
throw new Error('You must provide a value for `peerInfo`')
|
||||||
|
}
|
||||||
|
|
||||||
|
self.peerInfo = peerInfo
|
||||||
|
|
||||||
|
// peerIdB58: { conn: <conn> }
|
||||||
|
self.conns = {}
|
||||||
|
|
||||||
|
// peerIdB58: {
|
||||||
|
// muxer: <muxer>,
|
||||||
|
// socket: socket // so we can extract the info we need for identify
|
||||||
|
// }
|
||||||
|
self.muxedConns = {}
|
||||||
|
|
||||||
|
// transportName: { transport: transport,
|
||||||
|
// dialOptions: dialOptions,
|
||||||
|
// listenOptions: listenOptions,
|
||||||
|
// listeners: [] }
|
||||||
|
self.transports = {}
|
||||||
|
|
||||||
|
// transportName: listener
|
||||||
|
self.listeners = {}
|
||||||
|
|
||||||
|
// protocolName: handlerFunc
|
||||||
|
self.protocols = {}
|
||||||
|
|
||||||
|
// muxerName: { Muxer: Muxer // Muxer is a constructor
|
||||||
|
// options: options }
|
||||||
|
self.muxers = {}
|
||||||
|
|
||||||
|
// for connection reuse
|
||||||
|
self.identify = false
|
||||||
|
|
||||||
|
// public interface
|
||||||
|
|
||||||
|
self.addTransport = function (name, transport, options, dialOptions, listenOptions, callback) {
|
||||||
|
// set up the transport and add the list of incoming streams
|
||||||
|
// add transport to the list of transports
|
||||||
|
|
||||||
|
var multiaddr = options.multiaddr
|
||||||
|
if (multiaddr) {
|
||||||
|
// no need to pass that to the transports
|
||||||
|
delete options.multiaddr
|
||||||
|
}
|
||||||
|
|
||||||
|
var listener = transport.createListener(options, listen)
|
||||||
|
|
||||||
|
listener.listen(listenOptions, function ready () {
|
||||||
|
self.transports[name] = {
|
||||||
|
transport: transport,
|
||||||
|
options: options,
|
||||||
|
dialOptions: dialOptions,
|
||||||
|
listenOptions: listenOptions,
|
||||||
|
listener: listener
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a known multiaddr is passed, then add to our list of multiaddrs
|
||||||
|
if (multiaddr) {
|
||||||
|
self.peerInfo.multiaddrs.push(multiaddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
callback()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
self.addUpgrade = function (ConnUpgrade, options) {}
|
||||||
|
|
||||||
|
self.addStreamMuxer = function (name, StreamMuxer, options) {
|
||||||
|
self.muxers[name] = {
|
||||||
|
Muxer: StreamMuxer,
|
||||||
|
options: options
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.dial = function (peerInfo, options, protocol, callback) {
|
||||||
|
// 1. check if we have transports we support
|
||||||
|
// 2. check if we have a conn waiting
|
||||||
|
// 3. check if we have a stream muxer available
|
||||||
|
|
||||||
|
if (typeof protocol === 'function') {
|
||||||
|
callback = protocol
|
||||||
|
protocol = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if a conn is waiting
|
||||||
|
// if it is and protocol was selected, jump into multistreamHandshake
|
||||||
|
// if it is and no protocol was selected, do nothing and call and empty callback
|
||||||
|
|
||||||
|
if (self.conns[peerInfo.id.toB58String()]) {
|
||||||
|
if (protocol) {
|
||||||
|
if (self.muxers['spdy']) {
|
||||||
|
// TODO upgrade this conn to a muxer
|
||||||
|
console.log('TODO: upgrade a warm conn to muxer that was added after')
|
||||||
|
} else {
|
||||||
|
multistreamHandshake(self.conns[peerInfo.id.toB58String()])
|
||||||
|
}
|
||||||
|
self.conns[peerInfo.id.toB58String()] = undefined
|
||||||
|
delete self.conns[peerInfo.id.toB58String()]
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
return callback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if a stream muxer for this peer is available
|
||||||
|
if (self.muxedConns[peerInfo.id.toB58String()]) {
|
||||||
|
if (protocol) {
|
||||||
|
return openMuxedStream(self.muxedConns[peerInfo.id.toB58String()].muxer)
|
||||||
|
} else {
|
||||||
|
return callback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Creating a new conn with this peer routine
|
||||||
|
|
||||||
|
// TODO - check if there is a preference in protocol to use on
|
||||||
|
// options.protocol
|
||||||
|
var supportedTransports = Object.keys(self.transports)
|
||||||
|
var multiaddrs = peerInfo.multiaddrs.filter(function (multiaddr) {
|
||||||
|
return multiaddr.protoNames().some(function (proto) {
|
||||||
|
return supportedTransports.indexOf(proto) >= 0
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!multiaddrs.length) {
|
||||||
|
callback(new Error("The swarm doesn't support any of the peer transports"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var conn
|
||||||
|
|
||||||
|
async.eachSeries(multiaddrs, function (multiaddr, next) {
|
||||||
|
if (conn) {
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
|
||||||
|
var transportName = getTransportNameForMultiaddr(multiaddr)
|
||||||
|
var transport = self.transports[transportName]
|
||||||
|
var dialOptions = clone(transport.dialOptions)
|
||||||
|
dialOptions.ready = connected
|
||||||
|
|
||||||
|
var connTry = transport.transport.dial(multiaddr, dialOptions)
|
||||||
|
|
||||||
|
connTry.once('error', function (err) {
|
||||||
|
if (err) {
|
||||||
|
return console.log(err) // TODO handle error
|
||||||
|
}
|
||||||
|
next() // try next multiaddr
|
||||||
|
})
|
||||||
|
|
||||||
|
function connected () {
|
||||||
|
conn = connTry
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTransportNameForMultiaddr (multiaddr) {
|
||||||
|
// this works for all those ip + transport + port tripplets
|
||||||
|
return multiaddr.protoNames()[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
function clone (obj) {
|
||||||
|
var target = {}
|
||||||
|
for (var i in obj) {
|
||||||
|
if (obj.hasOwnProperty(i)) {
|
||||||
|
target[i] = obj[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return target
|
||||||
|
}
|
||||||
|
}, done)
|
||||||
|
|
||||||
|
function done () {
|
||||||
|
// TODO apply upgrades
|
||||||
|
// apply stream muxer
|
||||||
|
// if no protocol is selected, save it in the pool
|
||||||
|
// if protocol is selected, multistream that protocol
|
||||||
|
if (!conn) {
|
||||||
|
callback(new Error('Unable to open a connection'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.muxers['spdy']) {
|
||||||
|
var spdy = new self.muxers['spdy'].Muxer(self.muxers['spdy'].options)
|
||||||
|
spdy.attach(conn, false, function (err, muxer) {
|
||||||
|
if (err) {
|
||||||
|
return console.log(err) // TODO Treat error
|
||||||
|
}
|
||||||
|
|
||||||
|
muxer.on('stream', userProtocolMuxer)
|
||||||
|
|
||||||
|
self.muxedConns[peerInfo.id.toB58String()] = {
|
||||||
|
muxer: muxer,
|
||||||
|
socket: conn
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protocol) {
|
||||||
|
openMuxedStream(muxer)
|
||||||
|
} else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
if (protocol) {
|
||||||
|
multistreamHandshake(conn)
|
||||||
|
} else {
|
||||||
|
self.conns[peerInfo.id.toB58String()] = conn
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function openMuxedStream (muxer) {
|
||||||
|
// 1. create a new stream on this muxedConn and pass that to
|
||||||
|
// multistreamHanshake
|
||||||
|
muxer.dialStream(function (err, conn) {
|
||||||
|
if (err) {
|
||||||
|
return console.log(err) // TODO Treat error
|
||||||
|
}
|
||||||
|
multistreamHandshake(conn)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function multistreamHandshake (conn) {
|
||||||
|
var msI = new multistream.Interactive()
|
||||||
|
msI.handle(conn, function () {
|
||||||
|
msI.select(protocol, callback)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.closeListener = function (transportName, callback) {
|
||||||
|
self.transports[transportName].listener.close(closed)
|
||||||
|
|
||||||
|
// only gets called when all the streams on this transport are closed too
|
||||||
|
function closed () {
|
||||||
|
delete self.transports[transportName]
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterates all the listeners closing them
|
||||||
|
// one by one. It calls back once all are closed.
|
||||||
|
self.closeAllListeners = function (callback) {
|
||||||
|
var transportNames = Object.keys(self.transports)
|
||||||
|
|
||||||
|
async.each(transportNames, self.closeListener, callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
self.closeConns = function (callback) {
|
||||||
|
// close warmed up cons so that the listener can gracefully exit
|
||||||
|
Object.keys(self.conns).forEach(function (conn) {
|
||||||
|
self.conns[conn].destroy()
|
||||||
|
})
|
||||||
|
self.conns = {}
|
||||||
|
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Closes both transport listeners and
|
||||||
|
// connections. It calls back once everything
|
||||||
|
// is closed
|
||||||
|
self.close = function (callback) {
|
||||||
|
async.parallel([
|
||||||
|
self.closeAllListeners,
|
||||||
|
self.closeConns
|
||||||
|
], callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
self.enableIdentify = function () {
|
||||||
|
// set flag to true
|
||||||
|
// add identify to the list of handled protocols
|
||||||
|
self.identify = true
|
||||||
|
|
||||||
|
// we pass muxedConns so that identify can access the socket of the other
|
||||||
|
// peer
|
||||||
|
self.handleProtocol(identify.protoId,
|
||||||
|
identify.getHandlerFunction(self.peerInfo, self.muxedConns))
|
||||||
|
}
|
||||||
|
|
||||||
|
self.handleProtocol = function (protocol, handlerFunction) {
|
||||||
|
self.protocols[protocol] = handlerFunction
|
||||||
|
}
|
||||||
|
|
||||||
|
// internals
|
||||||
|
|
||||||
|
function listen (conn) {
|
||||||
|
// TODO apply upgrades
|
||||||
|
// add StreamMuxer if available (and point streams from muxer to userProtocolMuxer)
|
||||||
|
|
||||||
|
if (self.muxers['spdy']) {
|
||||||
|
var spdy = new self.muxers['spdy'].Muxer(self.muxers['spdy'].options)
|
||||||
|
spdy.attach(conn, true, function (err, muxer) {
|
||||||
|
if (err) {
|
||||||
|
return console.log(err) // TODO treat error
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO This muxer has to be identified!
|
||||||
|
// pass to identify a reference of
|
||||||
|
// our muxedConn list
|
||||||
|
// ourselves (peerInfo)
|
||||||
|
// the conn, which is the socket
|
||||||
|
// and a stream it can send stuff
|
||||||
|
if (self.identify) {
|
||||||
|
muxer.dialStream(function (err, stream) {
|
||||||
|
if (err) {
|
||||||
|
return console.log(err) // TODO Treat error
|
||||||
|
}
|
||||||
|
// conn === socket at this point
|
||||||
|
identify(self.muxedConns, self.peerInfo, conn, stream, muxer)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
muxer.on('stream', userProtocolMuxer)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// if no stream muxer, then
|
||||||
|
userProtocolMuxer(conn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle user given protocols
|
||||||
|
function userProtocolMuxer (conn) {
|
||||||
|
var msS = new multistream.Select()
|
||||||
|
msS.handle(conn)
|
||||||
|
Object.keys(self.protocols).forEach(function (protocol) {
|
||||||
|
msS.addHandler(protocol, self.protocols[protocol])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
343
src/swarm.js
343
src/swarm.js
@ -1,343 +0,0 @@
|
|||||||
var multistream = require('multistream-select')
|
|
||||||
var async = require('async')
|
|
||||||
var identify = require('./identify')
|
|
||||||
|
|
||||||
exports = module.exports = Swarm
|
|
||||||
|
|
||||||
function Swarm (peerInfo) {
|
|
||||||
var self = this
|
|
||||||
|
|
||||||
if (!(self instanceof Swarm)) {
|
|
||||||
throw new Error('Swarm must be called with new')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!peerInfo) {
|
|
||||||
throw new Error('You must provide a value for `peerInfo`')
|
|
||||||
}
|
|
||||||
|
|
||||||
self.peerInfo = peerInfo
|
|
||||||
|
|
||||||
// peerIdB58: { conn: <conn> }
|
|
||||||
self.conns = {}
|
|
||||||
|
|
||||||
// peerIdB58: {
|
|
||||||
// muxer: <muxer>,
|
|
||||||
// socket: socket // so we can extract the info we need for identify
|
|
||||||
// }
|
|
||||||
self.muxedConns = {}
|
|
||||||
|
|
||||||
// transportName: { transport: transport,
|
|
||||||
// dialOptions: dialOptions,
|
|
||||||
// listenOptions: listenOptions,
|
|
||||||
// listeners: [] }
|
|
||||||
self.transports = {}
|
|
||||||
|
|
||||||
// transportName: listener
|
|
||||||
self.listeners = {}
|
|
||||||
|
|
||||||
// protocolName: handlerFunc
|
|
||||||
self.protocols = {}
|
|
||||||
|
|
||||||
// muxerName: { Muxer: Muxer // Muxer is a constructor
|
|
||||||
// options: options }
|
|
||||||
self.muxers = {}
|
|
||||||
|
|
||||||
// for connection reuse
|
|
||||||
self.identify = false
|
|
||||||
|
|
||||||
// public interface
|
|
||||||
|
|
||||||
self.addTransport = function (name, transport, options, dialOptions, listenOptions, callback) {
|
|
||||||
// set up the transport and add the list of incoming streams
|
|
||||||
// add transport to the list of transports
|
|
||||||
|
|
||||||
var multiaddr = options.multiaddr
|
|
||||||
if (multiaddr) {
|
|
||||||
// no need to pass that to the transports
|
|
||||||
delete options.multiaddr
|
|
||||||
}
|
|
||||||
|
|
||||||
var listener = transport.createListener(options, listen)
|
|
||||||
|
|
||||||
listener.listen(listenOptions, function ready () {
|
|
||||||
self.transports[name] = {
|
|
||||||
transport: transport,
|
|
||||||
options: options,
|
|
||||||
dialOptions: dialOptions,
|
|
||||||
listenOptions: listenOptions,
|
|
||||||
listener: listener
|
|
||||||
}
|
|
||||||
|
|
||||||
// If a known multiaddr is passed, then add to our list of multiaddrs
|
|
||||||
if (multiaddr) {
|
|
||||||
self.peerInfo.multiaddrs.push(multiaddr)
|
|
||||||
}
|
|
||||||
|
|
||||||
callback()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
self.addUpgrade = function (ConnUpgrade, options) {}
|
|
||||||
|
|
||||||
self.addStreamMuxer = function (name, StreamMuxer, options) {
|
|
||||||
self.muxers[name] = {
|
|
||||||
Muxer: StreamMuxer,
|
|
||||||
options: options
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.dial = function (peerInfo, options, protocol, callback) {
|
|
||||||
// 1. check if we have transports we support
|
|
||||||
// 2. check if we have a conn waiting
|
|
||||||
// 3. check if we have a stream muxer available
|
|
||||||
|
|
||||||
if (typeof protocol === 'function') {
|
|
||||||
callback = protocol
|
|
||||||
protocol = undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if a conn is waiting
|
|
||||||
// if it is and protocol was selected, jump into multistreamHandshake
|
|
||||||
// if it is and no protocol was selected, do nothing and call and empty callback
|
|
||||||
|
|
||||||
if (self.conns[peerInfo.id.toB58String()]) {
|
|
||||||
if (protocol) {
|
|
||||||
if (self.muxers['spdy']) {
|
|
||||||
// TODO upgrade this conn to a muxer
|
|
||||||
console.log('TODO: upgrade a warm conn to muxer that was added after')
|
|
||||||
} else {
|
|
||||||
multistreamHandshake(self.conns[peerInfo.id.toB58String()])
|
|
||||||
}
|
|
||||||
self.conns[peerInfo.id.toB58String()] = undefined
|
|
||||||
delete self.conns[peerInfo.id.toB58String()]
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
return callback()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if a stream muxer for this peer is available
|
|
||||||
if (self.muxedConns[peerInfo.id.toB58String()]) {
|
|
||||||
if (protocol) {
|
|
||||||
return openMuxedStream(self.muxedConns[peerInfo.id.toB58String()].muxer)
|
|
||||||
} else {
|
|
||||||
return callback()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creating a new conn with this peer routine
|
|
||||||
|
|
||||||
// TODO - check if there is a preference in protocol to use on
|
|
||||||
// options.protocol
|
|
||||||
var supportedTransports = Object.keys(self.transports)
|
|
||||||
var multiaddrs = peerInfo.multiaddrs.filter(function (multiaddr) {
|
|
||||||
return multiaddr.protoNames().some(function (proto) {
|
|
||||||
return supportedTransports.indexOf(proto) >= 0
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!multiaddrs.length) {
|
|
||||||
callback(new Error("The swarm doesn't support any of the peer transports"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var conn
|
|
||||||
|
|
||||||
async.eachSeries(multiaddrs, function (multiaddr, next) {
|
|
||||||
if (conn) {
|
|
||||||
return next()
|
|
||||||
}
|
|
||||||
|
|
||||||
var transportName = getTransportNameForMultiaddr(multiaddr)
|
|
||||||
var transport = self.transports[transportName]
|
|
||||||
var dialOptions = clone(transport.dialOptions)
|
|
||||||
dialOptions.ready = connected
|
|
||||||
|
|
||||||
var connTry = transport.transport.dial(multiaddr, dialOptions)
|
|
||||||
|
|
||||||
connTry.once('error', function (err) {
|
|
||||||
if (err) {
|
|
||||||
return console.log(err) // TODO handle error
|
|
||||||
}
|
|
||||||
next() // try next multiaddr
|
|
||||||
})
|
|
||||||
|
|
||||||
function connected () {
|
|
||||||
conn = connTry
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTransportNameForMultiaddr (multiaddr) {
|
|
||||||
// this works for all those ip + transport + port tripplets
|
|
||||||
return multiaddr.protoNames()[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
function clone (obj) {
|
|
||||||
var target = {}
|
|
||||||
for (var i in obj) {
|
|
||||||
if (obj.hasOwnProperty(i)) {
|
|
||||||
target[i] = obj[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return target
|
|
||||||
}
|
|
||||||
}, done)
|
|
||||||
|
|
||||||
function done () {
|
|
||||||
// TODO apply upgrades
|
|
||||||
// apply stream muxer
|
|
||||||
// if no protocol is selected, save it in the pool
|
|
||||||
// if protocol is selected, multistream that protocol
|
|
||||||
if (!conn) {
|
|
||||||
callback(new Error('Unable to open a connection'))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self.muxers['spdy']) {
|
|
||||||
var spdy = new self.muxers['spdy'].Muxer(self.muxers['spdy'].options)
|
|
||||||
spdy.attach(conn, false, function (err, muxer) {
|
|
||||||
if (err) {
|
|
||||||
return console.log(err) // TODO Treat error
|
|
||||||
}
|
|
||||||
|
|
||||||
muxer.on('stream', userProtocolMuxer)
|
|
||||||
|
|
||||||
self.muxedConns[peerInfo.id.toB58String()] = {
|
|
||||||
muxer: muxer,
|
|
||||||
socket: conn
|
|
||||||
}
|
|
||||||
|
|
||||||
if (protocol) {
|
|
||||||
openMuxedStream(muxer)
|
|
||||||
} else {
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
if (protocol) {
|
|
||||||
multistreamHandshake(conn)
|
|
||||||
} else {
|
|
||||||
self.conns[peerInfo.id.toB58String()] = conn
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function openMuxedStream (muxer) {
|
|
||||||
// 1. create a new stream on this muxedConn and pass that to
|
|
||||||
// multistreamHanshake
|
|
||||||
muxer.dialStream(function (err, conn) {
|
|
||||||
if (err) {
|
|
||||||
return console.log(err) // TODO Treat error
|
|
||||||
}
|
|
||||||
multistreamHandshake(conn)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function multistreamHandshake (conn) {
|
|
||||||
var msI = new multistream.Interactive()
|
|
||||||
msI.handle(conn, function () {
|
|
||||||
msI.select(protocol, callback)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.closeListener = function (transportName, callback) {
|
|
||||||
self.transports[transportName].listener.close(closed)
|
|
||||||
|
|
||||||
// only gets called when all the streams on this transport are closed too
|
|
||||||
function closed () {
|
|
||||||
delete self.transports[transportName]
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Iterates all the listeners closing them
|
|
||||||
// one by one. It calls back once all are closed.
|
|
||||||
self.closeAllListeners = function (callback) {
|
|
||||||
var transportNames = Object.keys(self.transports)
|
|
||||||
|
|
||||||
async.each(transportNames, self.closeListener, callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
self.closeConns = function (callback) {
|
|
||||||
// close warmed up cons so that the listener can gracefully exit
|
|
||||||
Object.keys(self.conns).forEach(function (conn) {
|
|
||||||
self.conns[conn].destroy()
|
|
||||||
})
|
|
||||||
self.conns = {}
|
|
||||||
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Closes both transport listeners and
|
|
||||||
// connections. It calls back once everything
|
|
||||||
// is closed
|
|
||||||
self.close = function (callback) {
|
|
||||||
async.parallel([
|
|
||||||
self.closeAllListeners,
|
|
||||||
self.closeConns
|
|
||||||
], callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
self.enableIdentify = function () {
|
|
||||||
// set flag to true
|
|
||||||
// add identify to the list of handled protocols
|
|
||||||
self.identify = true
|
|
||||||
|
|
||||||
// we pass muxedConns so that identify can access the socket of the other
|
|
||||||
// peer
|
|
||||||
self.handleProtocol(identify.protoId,
|
|
||||||
identify.getHandlerFunction(self.peerInfo, self.muxedConns))
|
|
||||||
}
|
|
||||||
|
|
||||||
self.handleProtocol = function (protocol, handlerFunction) {
|
|
||||||
self.protocols[protocol] = handlerFunction
|
|
||||||
}
|
|
||||||
|
|
||||||
// internals
|
|
||||||
|
|
||||||
function listen (conn) {
|
|
||||||
// TODO apply upgrades
|
|
||||||
// add StreamMuxer if available (and point streams from muxer to userProtocolMuxer)
|
|
||||||
|
|
||||||
if (self.muxers['spdy']) {
|
|
||||||
var spdy = new self.muxers['spdy'].Muxer(self.muxers['spdy'].options)
|
|
||||||
spdy.attach(conn, true, function (err, muxer) {
|
|
||||||
if (err) {
|
|
||||||
return console.log(err) // TODO treat error
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO This muxer has to be identified!
|
|
||||||
// pass to identify a reference of
|
|
||||||
// our muxedConn list
|
|
||||||
// ourselves (peerInfo)
|
|
||||||
// the conn, which is the socket
|
|
||||||
// and a stream it can send stuff
|
|
||||||
if (self.identify) {
|
|
||||||
muxer.dialStream(function (err, stream) {
|
|
||||||
if (err) {
|
|
||||||
return console.log(err) // TODO Treat error
|
|
||||||
}
|
|
||||||
// conn === socket at this point
|
|
||||||
identify(self.muxedConns, self.peerInfo, conn, stream, muxer)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
muxer.on('stream', userProtocolMuxer)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// if no stream muxer, then
|
|
||||||
userProtocolMuxer(conn)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle user given protocols
|
|
||||||
function userProtocolMuxer (conn) {
|
|
||||||
var msS = new multistream.Select()
|
|
||||||
msS.handle(conn)
|
|
||||||
Object.keys(self.protocols).forEach(function (protocol) {
|
|
||||||
msS.addHandler(protocol, self.protocols[protocol])
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,139 +0,0 @@
|
|||||||
var Lab = require('lab')
|
|
||||||
var Code = require('code')
|
|
||||||
var lab = exports.lab = Lab.script()
|
|
||||||
|
|
||||||
var experiment = lab.experiment
|
|
||||||
var test = lab.test
|
|
||||||
var beforeEach = lab.beforeEach
|
|
||||||
var afterEach = lab.afterEach
|
|
||||||
var expect = Code.expect
|
|
||||||
|
|
||||||
var Muxer = require('./../src/stream-muxer.js')
|
|
||||||
var multistream = require('multistream-select')
|
|
||||||
var Interactive = multistream.Interactive
|
|
||||||
var Select = multistream.Select
|
|
||||||
var streamPair = require('stream-pair')
|
|
||||||
|
|
||||||
beforeEach(function (done) {
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(function (done) {
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
|
|
||||||
experiment('MULTISTREAM AND STREAM MUXER', function () {
|
|
||||||
test('Open a socket and multistream-select it into spdy', function (done) {
|
|
||||||
var pair = streamPair.create()
|
|
||||||
|
|
||||||
var msI = new Interactive()
|
|
||||||
var msS = new Select()
|
|
||||||
|
|
||||||
var dialerMuxer = new Muxer()
|
|
||||||
var listenerMuxer = new Muxer()
|
|
||||||
|
|
||||||
msS.handle(pair.other)
|
|
||||||
|
|
||||||
msS.addHandler('/spdy/0.3.1', function (stream) {
|
|
||||||
var listenerConn = listenerMuxer.attach(stream, true)
|
|
||||||
expect(typeof listenerConn).to.be.equal('object')
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
|
|
||||||
msI.handle(pair, function () {
|
|
||||||
msI.select('/spdy/0.3.1', function (err, stream) {
|
|
||||||
expect(err).to.not.be.instanceof(Error)
|
|
||||||
var dialerConn = dialerMuxer.attach(stream, false)
|
|
||||||
expect(typeof dialerConn).to.be.equal('object')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('socket->ms-select into spdy->stream from dialer->ms-select into other protocol', function (done) {
|
|
||||||
var pair = streamPair.create()
|
|
||||||
|
|
||||||
var msI = new Interactive()
|
|
||||||
var msS = new Select()
|
|
||||||
|
|
||||||
var dialerMuxer = new Muxer()
|
|
||||||
var listenerMuxer = new Muxer()
|
|
||||||
|
|
||||||
msS.handle(pair.other)
|
|
||||||
|
|
||||||
msS.addHandler('/spdy/0.3.1', function (stream) {
|
|
||||||
var listenerConn = listenerMuxer.attach(stream, true)
|
|
||||||
listenerConn.on('stream', function (stream) {
|
|
||||||
stream.on('data', function (chunk) {
|
|
||||||
expect(chunk.toString()).to.equal('mux all the streams')
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
msI.handle(pair, function () {
|
|
||||||
msI.select('/spdy/0.3.1', function (err, stream) {
|
|
||||||
expect(err).to.not.be.instanceof(Error)
|
|
||||||
var dialerConn = dialerMuxer.attach(stream, false)
|
|
||||||
dialerConn.dialStream(function (err, stream) {
|
|
||||||
expect(err).to.not.be.instanceof(Error)
|
|
||||||
stream.write('mux all the streams')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test('socket->ms-select into spdy->stream from listener->ms-select into another protocol', function (done) {
|
|
||||||
var pair = streamPair.create()
|
|
||||||
|
|
||||||
var msI = new Interactive()
|
|
||||||
var msS = new Select()
|
|
||||||
|
|
||||||
var dialerMuxer = new Muxer()
|
|
||||||
var listenerMuxer = new Muxer()
|
|
||||||
|
|
||||||
msS.handle(pair.other)
|
|
||||||
|
|
||||||
msS.addHandler('/spdy/0.3.1', function (stream) {
|
|
||||||
var listenerConn = listenerMuxer.attach(stream, true)
|
|
||||||
listenerConn.on('stream', function (stream) {
|
|
||||||
stream.on('data', function (chunk) {
|
|
||||||
expect(chunk.toString()).to.equal('mux all the streams')
|
|
||||||
|
|
||||||
listenerConn.dialStream(function (err, stream) {
|
|
||||||
expect(err).to.not.be.instanceof(Error)
|
|
||||||
var msI2 = new Interactive()
|
|
||||||
msI2.handle(stream, function () {
|
|
||||||
msI2.select('/other/protocol', function (err, stream) {
|
|
||||||
expect(err).to.not.be.instanceof(Error)
|
|
||||||
stream.write('the other protocol')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
msI.handle(pair, function () {
|
|
||||||
msI.select('/spdy/0.3.1', function (err, stream) {
|
|
||||||
expect(err).to.not.be.instanceof(Error)
|
|
||||||
var dialerConn = dialerMuxer.attach(stream, false)
|
|
||||||
dialerConn.dialStream(function (err, stream) {
|
|
||||||
expect(err).to.not.be.instanceof(Error)
|
|
||||||
stream.write('mux all the streams')
|
|
||||||
})
|
|
||||||
|
|
||||||
dialerConn.on('stream', function (stream) {
|
|
||||||
var msS2 = new Select()
|
|
||||||
msS2.handle(stream)
|
|
||||||
msS2.addHandler('/other/protocol', function (stream) {
|
|
||||||
stream.on('data', function (chunk) {
|
|
||||||
expect(chunk.toString()).to.equal('the other protocol')
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,13 +1,7 @@
|
|||||||
var Lab = require('lab')
|
/* eslint-env mocha */
|
||||||
var Code = require('code')
|
|
||||||
var lab = exports.lab = Lab.script()
|
|
||||||
var async = require('async')
|
|
||||||
|
|
||||||
var experiment = lab.experiment
|
var async = require('async')
|
||||||
var test = lab.test
|
var expect = require('chai').expect
|
||||||
var beforeEach = lab.beforeEach
|
|
||||||
var afterEach = lab.afterEach
|
|
||||||
var expect = Code.expect
|
|
||||||
|
|
||||||
var multiaddr = require('multiaddr')
|
var multiaddr = require('multiaddr')
|
||||||
var Id = require('peer-id')
|
var Id = require('peer-id')
|
||||||
@ -21,15 +15,15 @@ process.on('uncaughtException', function (err) {
|
|||||||
console.log('Caught exception: ' + err)
|
console.log('Caught exception: ' + err)
|
||||||
})
|
})
|
||||||
|
|
||||||
experiment('Basics', function () {
|
describe('Basics', function () {
|
||||||
test('enforces creation with new', function (done) {
|
it('enforces creation with new', function (done) {
|
||||||
expect(function () {
|
expect(function () {
|
||||||
Swarm()
|
Swarm()
|
||||||
}).to.throw()
|
}).to.throw()
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('it throws an exception without peerSelf', function (done) {
|
it('it throws an exception without peerSelf', function (done) {
|
||||||
expect(function () {
|
expect(function () {
|
||||||
var sw = new Swarm()
|
var sw = new Swarm()
|
||||||
sw.close()
|
sw.close()
|
||||||
@ -38,24 +32,24 @@ experiment('Basics', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
experiment('When dialing', function () {
|
describe('When dialing', function () {
|
||||||
experiment('if the swarm does add any of the peer transports', function () {
|
describe('if the swarm does add any of the peer transports', function () {
|
||||||
test('it returns an error', function (done) {
|
it('it returns an error', function (done) {
|
||||||
var peerOne = new Peer(Id.create(), [multiaddr('/ip4/127.0.0.1/tcp/8090')])
|
var peerOne = new Peer(Id.create(), [multiaddr('/ip4/127.0.0.1/tcp/8090')])
|
||||||
var peerTwo = new Peer(Id.create(), [multiaddr('/ip4/127.0.0.1/tcp/8091')])
|
var peerTwo = new Peer(Id.create(), [multiaddr('/ip4/127.0.0.1/tcp/8091')])
|
||||||
var swarm = new Swarm(peerOne)
|
var swarm = new Swarm(peerOne)
|
||||||
|
|
||||||
swarm.dial(peerTwo, {}, function (err) {
|
swarm.dial(peerTwo, {}, function (err) {
|
||||||
expect(err).to.exist()
|
expect(err).to.exist
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
experiment('Without a Stream Muxer', function () {
|
describe('Without a Stream Muxer', function () {
|
||||||
experiment('and one swarm over tcp', function () {
|
describe('and one swarm over tcp', function () {
|
||||||
test('add the transport', function (done) {
|
it('add the transport', function (done) {
|
||||||
var mh = multiaddr('/ip4/127.0.0.1/tcp/8010')
|
var mh = multiaddr('/ip4/127.0.0.1/tcp/8010')
|
||||||
var p = new Peer(Id.create(), [])
|
var p = new Peer(Id.create(), [])
|
||||||
var sw = new Swarm(p)
|
var sw = new Swarm(p)
|
||||||
@ -73,7 +67,7 @@ experiment('Without a Stream Muxer', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
experiment('and two swarms over tcp', function () {
|
describe('and two swarms over tcp', function () {
|
||||||
var mh1, p1, sw1, mh2, p2, sw2
|
var mh1, p1, sw1, mh2, p2, sw2
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
@ -99,7 +93,7 @@ experiment('Without a Stream Muxer', function () {
|
|||||||
async.parallel([sw1.close, sw2.close], done)
|
async.parallel([sw1.close, sw2.close], done)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('dial a conn', function (done) {
|
it('dial a conn', function (done) {
|
||||||
sw1.dial(p2, {}, function (err) {
|
sw1.dial(p2, {}, function (err) {
|
||||||
expect(err).to.equal(undefined)
|
expect(err).to.equal(undefined)
|
||||||
expect(Object.keys(sw1.conns).length).to.equal(1)
|
expect(Object.keys(sw1.conns).length).to.equal(1)
|
||||||
@ -107,7 +101,7 @@ experiment('Without a Stream Muxer', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test('dial a conn on a protocol', function (done) {
|
it('dial a conn on a protocol', function (done) {
|
||||||
sw2.handleProtocol('/sparkles/1.0.0', function (conn) {
|
sw2.handleProtocol('/sparkles/1.0.0', function (conn) {
|
||||||
conn.end()
|
conn.end()
|
||||||
conn.on('end', done)
|
conn.on('end', done)
|
||||||
@ -120,7 +114,7 @@ experiment('Without a Stream Muxer', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test('dial a protocol on a previous created conn', function (done) {
|
it('dial a protocol on a previous created conn', function (done) {
|
||||||
sw2.handleProtocol('/sparkles/1.0.0', function (conn) {
|
sw2.handleProtocol('/sparkles/1.0.0', function (conn) {
|
||||||
conn.end()
|
conn.end()
|
||||||
conn.on('end', done)
|
conn.on('end', done)
|
||||||
@ -139,46 +133,46 @@ experiment('Without a Stream Muxer', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// test('add an upgrade', function (done) { done() })
|
// it('add an upgrade', function (done) { done() })
|
||||||
// test('dial a conn on top of a upgrade', function (done) { done() })
|
// it('dial a conn on top of a upgrade', function (done) { done() })
|
||||||
// test('dial a conn on a protocol on top of a upgrade', function (done) { done() })
|
// it('dial a conn on a protocol on top of a upgrade', function (done) { done() })
|
||||||
})
|
})
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
experiment('udp', function () {
|
describe('udp', function () {
|
||||||
test('add the transport', function (done) { done() })
|
it('add the transport', function (done) { done() })
|
||||||
test('dial a conn', function (done) { done() })
|
it('dial a conn', function (done) { done() })
|
||||||
test('dial a conn on a protocol', function (done) { done() })
|
it('dial a conn on a protocol', function (done) { done() })
|
||||||
test('add an upgrade', function (done) { done() })
|
it('add an upgrade', function (done) { done() })
|
||||||
test('dial a conn on top of a upgrade', function (done) { done() })
|
it('dial a conn on top of a upgrade', function (done) { done() })
|
||||||
test('dial a conn on a protocol on top of a upgrade', function (done) { done() })
|
it('dial a conn on a protocol on top of a upgrade', function (done) { done() })
|
||||||
}) */
|
}) */
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
experiment('udt', function () {
|
describe('udt', function () {
|
||||||
test('add the transport', function (done) { done() })
|
it('add the transport', function (done) { done() })
|
||||||
test('dial a conn', function (done) { done() })
|
it('dial a conn', function (done) { done() })
|
||||||
test('dial a conn on a protocol', function (done) { done() })
|
it('dial a conn on a protocol', function (done) { done() })
|
||||||
test('add an upgrade', function (done) { done() })
|
it('add an upgrade', function (done) { done() })
|
||||||
test('dial a conn on top of a upgrade', function (done) { done() })
|
it('dial a conn on top of a upgrade', function (done) { done() })
|
||||||
test('dial a conn on a protocol on top of a upgrade', function (done) { done() })
|
it('dial a conn on a protocol on top of a upgrade', function (done) { done() })
|
||||||
}) */
|
}) */
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
experiment('utp', function () {
|
describe('utp', function () {
|
||||||
test('add the transport', function (done) { done() })
|
it('add the transport', function (done) { done() })
|
||||||
test('dial a conn', function (done) { done() })
|
it('dial a conn', function (done) { done() })
|
||||||
test('dial a conn on a protocol', function (done) { done() })
|
it('dial a conn on a protocol', function (done) { done() })
|
||||||
test('add an upgrade', function (done) { done() })
|
it('add an upgrade', function (done) { done() })
|
||||||
test('dial a conn on top of a upgrade', function (done) { done() })
|
it('dial a conn on top of a upgrade', function (done) { done() })
|
||||||
test('dial a conn on a protocol on top of a upgrade', function (done) { done() })
|
it('dial a conn on a protocol on top of a upgrade', function (done) { done() })
|
||||||
}) */
|
}) */
|
||||||
})
|
})
|
||||||
|
|
||||||
experiment('With a SPDY Stream Muxer', function () {
|
describe('With a SPDY Stream Muxer', function () {
|
||||||
experiment('and one swarm over tcp', function () {
|
describe('and one swarm over tcp', function () {
|
||||||
// TODO: What is the test here?
|
// TODO: What is the it here?
|
||||||
test('add Stream Muxer', function (done) {
|
it('add Stream Muxer', function (done) {
|
||||||
// var mh = multiaddr('/ip4/127.0.0.1/tcp/8010')
|
// var mh = multiaddr('/ip4/127.0.0.1/tcp/8010')
|
||||||
var p = new Peer(Id.create(), [])
|
var p = new Peer(Id.create(), [])
|
||||||
var sw = new Swarm(p)
|
var sw = new Swarm(p)
|
||||||
@ -188,7 +182,7 @@ experiment('With a SPDY Stream Muxer', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
experiment('and two swarms over tcp', function () {
|
describe('and two swarms over tcp', function () {
|
||||||
var mh1, p1, sw1, mh2, p2, sw2
|
var mh1, p1, sw1, mh2, p2, sw2
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
@ -233,7 +227,7 @@ experiment('With a SPDY Stream Muxer', function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test('dial a conn on a protocol', function (done) {
|
it('dial a conn on a protocol', function (done) {
|
||||||
sw2.handleProtocol('/sparkles/1.0.0', function (conn) {
|
sw2.handleProtocol('/sparkles/1.0.0', function (conn) {
|
||||||
// formallity so that the conn starts flowing
|
// formallity so that the conn starts flowing
|
||||||
conn.on('data', function (chunk) {})
|
conn.on('data', function (chunk) {})
|
||||||
@ -254,7 +248,7 @@ experiment('With a SPDY Stream Muxer', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test('dial two conns (transport reuse)', function (done) {
|
it('dial two conns (transport reuse)', function (done) {
|
||||||
sw2.handleProtocol('/sparkles/1.0.0', function (conn) {
|
sw2.handleProtocol('/sparkles/1.0.0', function (conn) {
|
||||||
// formality so that the conn starts flowing
|
// formality so that the conn starts flowing
|
||||||
conn.on('data', function (chunk) {})
|
conn.on('data', function (chunk) {})
|
||||||
@ -287,7 +281,7 @@ experiment('With a SPDY Stream Muxer', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
experiment('and two identity enabled swarms over tcp', function () {
|
describe('and two identity enabled swarms over tcp', function () {
|
||||||
var mh1, p1, sw1, mh2, p2, sw2
|
var mh1, p1, sw1, mh2, p2, sw2
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
@ -337,7 +331,7 @@ experiment('With a SPDY Stream Muxer', function () {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
test('identify', function (done) {
|
it('identify', function (done) {
|
||||||
sw2.handleProtocol('/sparkles/1.0.0', function (conn) {
|
sw2.handleProtocol('/sparkles/1.0.0', function (conn) {
|
||||||
// formallity so that the conn starts flowing
|
// formallity so that the conn starts flowing
|
||||||
conn.on('data', function (chunk) {})
|
conn.on('data', function (chunk) {})
|
||||||
|
Reference in New Issue
Block a user