mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-27 16:01:32 +00:00
feat: use libp2p-switch
This commit is contained in:
@ -39,7 +39,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^2.6.0",
|
"async": "^2.6.0",
|
||||||
"libp2p-ping": "~0.6.0",
|
"libp2p-ping": "~0.6.0",
|
||||||
"libp2p-swarm": "~0.35.1",
|
"libp2p-switch": "~0.36.0",
|
||||||
"mafmt": "^3.0.2",
|
"mafmt": "^3.0.2",
|
||||||
"multiaddr": "^3.0.2",
|
"multiaddr": "^3.0.2",
|
||||||
"peer-book": "~0.5.4",
|
"peer-book": "~0.5.4",
|
||||||
@ -53,13 +53,13 @@
|
|||||||
"dirty-chai": "^2.0.1",
|
"dirty-chai": "^2.0.1",
|
||||||
"electron-webrtc": "~0.3.0",
|
"electron-webrtc": "~0.3.0",
|
||||||
"libp2p-circuit": "~0.1.4",
|
"libp2p-circuit": "~0.1.4",
|
||||||
"libp2p-kad-dht": "~0.6.0",
|
"libp2p-kad-dht": "~0.6.3",
|
||||||
"libp2p-mdns": "~0.9.1",
|
"libp2p-mdns": "~0.9.2",
|
||||||
"libp2p-multiplex": "~0.5.1",
|
"libp2p-multiplex": "~0.5.1",
|
||||||
"libp2p-railing": "~0.7.1",
|
"libp2p-railing": "~0.7.1",
|
||||||
"libp2p-secio": "~0.9.1",
|
"libp2p-secio": "~0.9.1",
|
||||||
"libp2p-spdy": "~0.11.0",
|
"libp2p-spdy": "~0.11.0",
|
||||||
"libp2p-tcp": "~0.11.2",
|
"libp2p-tcp": "~0.11.5",
|
||||||
"libp2p-webrtc-star": "~0.13.3",
|
"libp2p-webrtc-star": "~0.13.3",
|
||||||
"libp2p-websockets": "~0.10.4",
|
"libp2p-websockets": "~0.10.4",
|
||||||
"libp2p-websocket-star": "~0.7.2",
|
"libp2p-websocket-star": "~0.7.2",
|
||||||
|
38
src/index.js
38
src/index.js
@ -8,7 +8,7 @@ const each = require('async/each')
|
|||||||
const series = require('async/series')
|
const series = require('async/series')
|
||||||
|
|
||||||
const Ping = require('libp2p-ping')
|
const Ping = require('libp2p-ping')
|
||||||
const Swarm = require('libp2p-swarm')
|
const Switch = require('libp2p-switch')
|
||||||
const PeerId = require('peer-id')
|
const PeerId = require('peer-id')
|
||||||
const PeerInfo = require('peer-info')
|
const PeerInfo = require('peer-info')
|
||||||
const PeerBook = require('peer-book')
|
const PeerBook = require('peer-book')
|
||||||
@ -31,28 +31,28 @@ class Node extends EventEmitter {
|
|||||||
|
|
||||||
this._isStarted = false
|
this._isStarted = false
|
||||||
|
|
||||||
this.swarm = new Swarm(this.peerInfo, this.peerBook)
|
this.switch = new Switch(this.peerInfo, this.peerBook)
|
||||||
|
|
||||||
// Attach stream multiplexers
|
// Attach stream multiplexers
|
||||||
if (this.modules.connection && this.modules.connection.muxer) {
|
if (this.modules.connection && this.modules.connection.muxer) {
|
||||||
let muxers = this.modules.connection.muxer
|
let muxers = this.modules.connection.muxer
|
||||||
muxers = Array.isArray(muxers) ? muxers : [muxers]
|
muxers = Array.isArray(muxers) ? muxers : [muxers]
|
||||||
muxers.forEach((muxer) => this.swarm.connection.addStreamMuxer(muxer))
|
muxers.forEach((muxer) => this.switch.connection.addStreamMuxer(muxer))
|
||||||
|
|
||||||
// If muxer exists, we can use Identify
|
// If muxer exists, we can use Identify
|
||||||
this.swarm.connection.reuse()
|
this.switch.connection.reuse()
|
||||||
|
|
||||||
// If muxer exists, we can use Relay for listening/dialing
|
// If muxer exists, we can use Relay for listening/dialing
|
||||||
this.swarm.connection.enableCircuitRelay(_options.relay)
|
this.switch.connection.enableCircuitRelay(_options.relay)
|
||||||
|
|
||||||
// Received incommind dial and muxer upgrade happened,
|
// Received incommind dial and muxer upgrade happened,
|
||||||
// reuse this muxed connection
|
// reuse this muxed connection
|
||||||
this.swarm.on('peer-mux-established', (peerInfo) => {
|
this.switch.on('peer-mux-established', (peerInfo) => {
|
||||||
this.emit('peer:connect', peerInfo)
|
this.emit('peer:connect', peerInfo)
|
||||||
this.peerBook.put(peerInfo)
|
this.peerBook.put(peerInfo)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.swarm.on('peer-mux-closed', (peerInfo) => {
|
this.switch.on('peer-mux-closed', (peerInfo) => {
|
||||||
this.emit('peer:disconnect', peerInfo)
|
this.emit('peer:disconnect', peerInfo)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ class Node extends EventEmitter {
|
|||||||
let cryptos = this.modules.connection.crypto
|
let cryptos = this.modules.connection.crypto
|
||||||
cryptos = Array.isArray(cryptos) ? cryptos : [cryptos]
|
cryptos = Array.isArray(cryptos) ? cryptos : [cryptos]
|
||||||
cryptos.forEach((crypto) => {
|
cryptos.forEach((crypto) => {
|
||||||
this.swarm.connection.crypto(crypto.tag, crypto.encrypt)
|
this.switch.connection.crypto(crypto.tag, crypto.encrypt)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,11 +77,11 @@ class Node extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mount default protocols
|
// Mount default protocols
|
||||||
Ping.mount(this.swarm)
|
Ping.mount(this.switch)
|
||||||
|
|
||||||
// dht provided components (peerRouting, contentRouting, dht)
|
// dht provided components (peerRouting, contentRouting, dht)
|
||||||
if (_modules.DHT) {
|
if (_modules.DHT) {
|
||||||
this._dht = new this.modules.DHT(this.swarm, {
|
this._dht = new this.modules.DHT(this.switch, {
|
||||||
kBucketSize: 20,
|
kBucketSize: 20,
|
||||||
datastore: _options.DHT && _options.DHT.datastore
|
datastore: _options.DHT && _options.DHT.datastore
|
||||||
})
|
})
|
||||||
@ -167,7 +167,7 @@ class Node extends EventEmitter {
|
|||||||
const multiaddrs = this.peerInfo.multiaddrs.toArray()
|
const multiaddrs = this.peerInfo.multiaddrs.toArray()
|
||||||
transports.forEach((transport) => {
|
transports.forEach((transport) => {
|
||||||
if (transport.filter(multiaddrs).length > 0) {
|
if (transport.filter(multiaddrs).length > 0) {
|
||||||
this.swarm.transport.add(
|
this.switch.transport.add(
|
||||||
transport.tag || transport.constructor.name, transport)
|
transport.tag || transport.constructor.name, transport)
|
||||||
} else if (transport.constructor &&
|
} else if (transport.constructor &&
|
||||||
transport.constructor.name === 'WebSockets') {
|
transport.constructor.name === 'WebSockets') {
|
||||||
@ -178,11 +178,11 @@ class Node extends EventEmitter {
|
|||||||
})
|
})
|
||||||
|
|
||||||
series([
|
series([
|
||||||
(cb) => this.swarm.listen(cb),
|
(cb) => this.switch.start(cb),
|
||||||
(cb) => {
|
(cb) => {
|
||||||
if (ws) {
|
if (ws) {
|
||||||
// always add dialing on websockets
|
// always add dialing on websockets
|
||||||
this.swarm.transport.add(ws.tag || ws.constructor.name, ws)
|
this.switch.transport.add(ws.tag || ws.constructor.name, ws)
|
||||||
}
|
}
|
||||||
|
|
||||||
// all transports need to be setup before discover starts
|
// all transports need to be setup before discover starts
|
||||||
@ -237,7 +237,7 @@ class Node extends EventEmitter {
|
|||||||
}
|
}
|
||||||
cb()
|
cb()
|
||||||
},
|
},
|
||||||
(cb) => this.swarm.close(cb),
|
(cb) => this.switch.stop(cb),
|
||||||
(cb) => {
|
(cb) => {
|
||||||
this.emit('stop')
|
this.emit('stop')
|
||||||
cb()
|
cb()
|
||||||
@ -259,7 +259,7 @@ class Node extends EventEmitter {
|
|||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null, new Ping(this.swarm, peerInfo))
|
callback(null, new Ping(this.switch, peerInfo))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +276,7 @@ class Node extends EventEmitter {
|
|||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.swarm.dial(peerInfo, protocol, (err, conn) => {
|
this.switch.dial(peerInfo, protocol, (err, conn) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
@ -294,16 +294,16 @@ class Node extends EventEmitter {
|
|||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.swarm.hangUp(peerInfo, callback)
|
this.switch.hangUp(peerInfo, callback)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
handle (protocol, handlerFunc, matchFunc) {
|
handle (protocol, handlerFunc, matchFunc) {
|
||||||
this.swarm.handle(protocol, handlerFunc, matchFunc)
|
this.switch.handle(protocol, handlerFunc, matchFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
unhandle (protocol) {
|
unhandle (protocol) {
|
||||||
this.swarm.unhandle(protocol)
|
this.switch.unhandle(protocol)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -39,7 +39,7 @@ describe('circuit relay', function () {
|
|||||||
node.start((err) => {
|
node.start((err) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
|
|
||||||
handlerSpies.push(sinon.spy(node.swarm.transports[Circuit.tag].listeners[0].hopHandler, 'handle'))
|
handlerSpies.push(sinon.spy(node.switch.transports[Circuit.tag].listeners[0].hopHandler, 'handle'))
|
||||||
cb(node)
|
cb(node)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -200,12 +200,12 @@ describe('stream muxing', () => {
|
|||||||
(cb) => setup(cb),
|
(cb) => setup(cb),
|
||||||
(cb) => {
|
(cb) => {
|
||||||
// it will just 'warm up a conn'
|
// it will just 'warm up a conn'
|
||||||
expect(Object.keys(nodeA.swarm.muxers)).to.have.length(1)
|
expect(Object.keys(nodeA.switch.muxers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeB.swarm.muxers)).to.have.length(1)
|
expect(Object.keys(nodeB.switch.muxers)).to.have.length(1)
|
||||||
|
|
||||||
nodeA.dial(nodeB.peerInfo, (err) => {
|
nodeA.dial(nodeB.peerInfo, (err) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
expect(Object.keys(nodeA.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(0)
|
||||||
cb()
|
cb()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -105,7 +105,7 @@ describe('transports', () => {
|
|||||||
function check () {
|
function check () {
|
||||||
const peers = nodeA.peerBook.getAll()
|
const peers = nodeA.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeA.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(0)
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -153,7 +153,7 @@ describe('transports', () => {
|
|||||||
const peers = nodeA.peerBook.getAll()
|
const peers = nodeA.peerBook.getAll()
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeA.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(0)
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -280,7 +280,7 @@ describe('transports', () => {
|
|||||||
function check () {
|
function check () {
|
||||||
const peers = node1.peerBook.getAll()
|
const peers = node1.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(node1.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(node1.switch.muxedConns)).to.have.length(0)
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -291,8 +291,8 @@ describe('transports', () => {
|
|||||||
|
|
||||||
function check () {
|
function check () {
|
||||||
if (++counter === 3) {
|
if (++counter === 3) {
|
||||||
expect(Object.keys(node1.swarm.muxedConns).length).to.equal(1)
|
expect(Object.keys(node1.switch.muxedConns).length).to.equal(1)
|
||||||
expect(Object.keys(node2.swarm.muxedConns).length).to.equal(1)
|
expect(Object.keys(node2.switch.muxedConns).length).to.equal(1)
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -389,7 +389,7 @@ describe('transports', () => {
|
|||||||
function check () {
|
function check () {
|
||||||
const peers = node1.peerBook.getAll()
|
const peers = node1.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(node1.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(node1.switch.muxedConns)).to.have.length(0)
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -400,8 +400,8 @@ describe('transports', () => {
|
|||||||
|
|
||||||
function check () {
|
function check () {
|
||||||
if (++counter === 3) {
|
if (++counter === 3) {
|
||||||
expect(Object.keys(node1.swarm.muxedConns).length).to.equal(1)
|
expect(Object.keys(node1.switch.muxedConns).length).to.equal(1)
|
||||||
expect(Object.keys(node2.swarm.muxedConns).length).to.equal(1)
|
expect(Object.keys(node2.switch.muxedConns).length).to.equal(1)
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,14 +98,14 @@ describe('transports', () => {
|
|||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeA.peerBook.getAll()
|
const peers = nodeA.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeA.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(0)
|
||||||
cb()
|
cb()
|
||||||
},
|
},
|
||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeB.peerBook.getAll()
|
const peers = nodeB.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
|
|
||||||
expect(Object.keys(nodeB.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(nodeB.switch.muxedConns)).to.have.length(0)
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
], done)
|
], done)
|
||||||
@ -125,14 +125,14 @@ describe('transports', () => {
|
|||||||
const peers = nodeA.peerBook.getAll()
|
const peers = nodeA.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
|
|
||||||
expect(Object.keys(nodeA.swarm.muxedConns)).to.have.length(1)
|
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(1)
|
||||||
cb()
|
cb()
|
||||||
},
|
},
|
||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeB.peerBook.getAll()
|
const peers = nodeB.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
|
|
||||||
expect(Object.keys(nodeA.swarm.muxedConns)).to.have.length(1)
|
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(1)
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
], () => {
|
], () => {
|
||||||
@ -161,14 +161,14 @@ describe('transports', () => {
|
|||||||
const peers = nodeA.peerBook.getAll()
|
const peers = nodeA.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
|
|
||||||
expect(Object.keys(nodeA.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(0)
|
||||||
cb()
|
cb()
|
||||||
},
|
},
|
||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeB.peerBook.getAll()
|
const peers = nodeB.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
|
|
||||||
expect(Object.keys(nodeB.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(nodeB.switch.muxedConns)).to.have.length(0)
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
], done)
|
], done)
|
||||||
@ -187,13 +187,13 @@ describe('transports', () => {
|
|||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeA.peerBook.getAll()
|
const peers = nodeA.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeA.swarm.muxedConns)).to.have.length(1)
|
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(1)
|
||||||
cb()
|
cb()
|
||||||
},
|
},
|
||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeB.peerBook.getAll()
|
const peers = nodeB.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeA.swarm.muxedConns)).to.have.length(1)
|
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(1)
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
], () => {
|
], () => {
|
||||||
@ -221,13 +221,13 @@ describe('transports', () => {
|
|||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeA.peerBook.getAll()
|
const peers = nodeA.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeA.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(0)
|
||||||
cb()
|
cb()
|
||||||
},
|
},
|
||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeB.peerBook.getAll()
|
const peers = nodeB.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeB.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(nodeB.switch.muxedConns)).to.have.length(0)
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
], done)
|
], done)
|
||||||
@ -291,13 +291,13 @@ describe('transports', () => {
|
|||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeTCP.peerBook.getAll()
|
const peers = nodeTCP.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeTCP.swarm.muxedConns)).to.have.length(1)
|
expect(Object.keys(nodeTCP.switch.muxedConns)).to.have.length(1)
|
||||||
cb()
|
cb()
|
||||||
},
|
},
|
||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeTCPnWS.peerBook.getAll()
|
const peers = nodeTCPnWS.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeTCPnWS.swarm.muxedConns)).to.have.length(1)
|
expect(Object.keys(nodeTCPnWS.switch.muxedConns)).to.have.length(1)
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
], done)
|
], done)
|
||||||
@ -315,14 +315,14 @@ describe('transports', () => {
|
|||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeTCP.peerBook.getAll()
|
const peers = nodeTCP.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeTCP.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(nodeTCP.switch.muxedConns)).to.have.length(0)
|
||||||
|
|
||||||
cb()
|
cb()
|
||||||
},
|
},
|
||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeTCPnWS.peerBook.getAll()
|
const peers = nodeTCPnWS.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeTCPnWS.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(nodeTCPnWS.switch.muxedConns)).to.have.length(0)
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
], done)
|
], done)
|
||||||
@ -342,13 +342,13 @@ describe('transports', () => {
|
|||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeTCPnWS.peerBook.getAll()
|
const peers = nodeTCPnWS.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(2)
|
expect(Object.keys(peers)).to.have.length(2)
|
||||||
expect(Object.keys(nodeTCPnWS.swarm.muxedConns)).to.have.length(1)
|
expect(Object.keys(nodeTCPnWS.switch.muxedConns)).to.have.length(1)
|
||||||
cb()
|
cb()
|
||||||
},
|
},
|
||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeWS.peerBook.getAll()
|
const peers = nodeWS.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeWS.swarm.muxedConns)).to.have.length(1)
|
expect(Object.keys(nodeWS.switch.muxedConns)).to.have.length(1)
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
], done)
|
], done)
|
||||||
@ -366,14 +366,14 @@ describe('transports', () => {
|
|||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeTCPnWS.peerBook.getAll()
|
const peers = nodeTCPnWS.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(2)
|
expect(Object.keys(peers)).to.have.length(2)
|
||||||
expect(Object.keys(nodeTCPnWS.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(nodeTCPnWS.switch.muxedConns)).to.have.length(0)
|
||||||
|
|
||||||
cb()
|
cb()
|
||||||
},
|
},
|
||||||
(cb) => {
|
(cb) => {
|
||||||
const peers = nodeWS.peerBook.getAll()
|
const peers = nodeWS.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeWS.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(nodeWS.switch.muxedConns)).to.have.length(0)
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
], done)
|
], done)
|
||||||
@ -481,7 +481,7 @@ describe('transports', () => {
|
|||||||
let i = 1;
|
let i = 1;
|
||||||
[nodeAll, otherNode].forEach((node) => {
|
[nodeAll, otherNode].forEach((node) => {
|
||||||
expect(Object.keys(node.peerBook.getAll())).to.have.length(i-- ? peers : 1)
|
expect(Object.keys(node.peerBook.getAll())).to.have.length(i-- ? peers : 1)
|
||||||
expect(Object.keys(node.swarm.muxedConns)).to.have.length(muxed)
|
expect(Object.keys(node.switch.muxedConns)).to.have.length(muxed)
|
||||||
})
|
})
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
@ -624,7 +624,7 @@ describe('transports', () => {
|
|||||||
let i = 1;
|
let i = 1;
|
||||||
[nodeAll, otherNode].forEach((node) => {
|
[nodeAll, otherNode].forEach((node) => {
|
||||||
expect(Object.keys(node.peerBook.getAll())).to.have.length(i-- ? peers : 1)
|
expect(Object.keys(node.peerBook.getAll())).to.have.length(i-- ? peers : 1)
|
||||||
expect(Object.keys(node.swarm.muxedConns)).to.have.length(muxed)
|
expect(Object.keys(node.switch.muxedConns)).to.have.length(muxed)
|
||||||
})
|
})
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ describe('Turbolence tests', () => {
|
|||||||
function check () {
|
function check () {
|
||||||
const peers = nodeA.peerBook.getAll()
|
const peers = nodeA.peerBook.getAll()
|
||||||
expect(Object.keys(peers)).to.have.length(1)
|
expect(Object.keys(peers)).to.have.length(1)
|
||||||
expect(Object.keys(nodeA.swarm.muxedConns)).to.have.length(0)
|
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(0)
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user