diff --git a/.aegir.js b/.aegir.js index da39d22ae0..1d2f9c9798 100644 --- a/.aegir.js +++ b/.aegir.js @@ -64,8 +64,8 @@ function pre (done) { } parallel([ - (cb) => { - sigS = sigServer.start(sigOptions, cb) + async () => { + sigS = await sigServer.start(sigOptions) }, (cb) => createA(cb), (cb) => createB(cb) @@ -76,7 +76,9 @@ function post (done) { parallel([ (cb) => switchA.stop(cb), (cb) => switchB.stop(cb), - (cb) => sigS.stop(cb) + async () => { + await sigS.stop() + } ], done) } diff --git a/package.json b/package.json index 7e62c692f3..81f51f9aed 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "npm": ">=3.0.0" }, "devDependencies": { - "aegir": "^18.2.1", + "aegir": "^20.0.0", "chai": "^4.2.0", "chai-checkmark": "^1.0.1", "dirty-chai": "^2.0.1", @@ -49,14 +49,14 @@ "libp2p-secio": "~0.11.1", "libp2p-spdy": "~0.13.3", "libp2p-tcp": "~0.13.0", - "libp2p-webrtc-star": "~0.15.8", + "libp2p-webrtc-star": "~0.16.1", "libp2p-websockets": "~0.12.2", "peer-book": "~0.9.1", "portfinder": "^1.0.20", - "pull-length-prefixed": "^1.3.2", + "pull-length-prefixed": "^1.3.3", "pull-mplex": "~0.1.2", "pull-pair": "^1.1.0", - "sinon": "^7.3.1", + "sinon": "^7.3.2", "webrtcsupport": "^2.2.0" }, "dependencies": { @@ -71,12 +71,12 @@ "libp2p-circuit": "~0.3.6", "libp2p-identify": "~0.7.6", "moving-average": "^1.0.0", - "multiaddr": "^6.0.6", - "multistream-select": "~0.14.4", + "multiaddr": "^6.1.0", + "multistream-select": "~0.14.6", "once": "^1.4.0", "peer-id": "~0.12.2", "peer-info": "~0.15.1", - "pull-stream": "^3.6.9", + "pull-stream": "^3.6.13", "retimer": "^2.0.0" }, "contributors": [ diff --git a/src/connection/index.js b/src/connection/index.js index a2df251a2d..b4f21a4642 100644 --- a/src/connection/index.js +++ b/src/connection/index.js @@ -215,7 +215,7 @@ class ConnectionFSM extends BaseConnection { } const nextTransport = (key) => { - let transport = key + const transport = key if (!transport) { if (!circuitEnabled) { return this.close( @@ -271,7 +271,7 @@ class ConnectionFSM extends BaseConnection { delete this.switch.conns[this.theirB58Id] - let tasks = [] + const tasks = [] // Clean up stored connections if (this.muxer) { diff --git a/src/dialer/queue.js b/src/dialer/queue.js index 3261ad6c10..976f9ccc34 100644 --- a/src/dialer/queue.js +++ b/src/dialer/queue.js @@ -73,6 +73,7 @@ class Queue { this.isRunning = false this.onStopped = onStopped } + get length () { return this._queue.length } @@ -139,7 +140,7 @@ class Queue { */ abort () { while (this.length > 0) { - let dial = this._queue.shift() + const dial = this._queue.shift() dial.callback(DIAL_ABORTED()) } this.stop() @@ -223,8 +224,8 @@ class Queue { }) const peerInfo = this.switch._peerBook.get(this.id) - let queuedDial = this._queue.shift() - let { connectionFSM, didCreate } = this._getOrCreateConnection(peerInfo) + const queuedDial = this._queue.shift() + const { connectionFSM, didCreate } = this._getOrCreateConnection(peerInfo) // If the dial expects a ConnectionFSM, we can provide that back now if (queuedDial.useFSM) { diff --git a/src/dialer/queueManager.js b/src/dialer/queueManager.js index 2c0a56873f..0239a482bc 100644 --- a/src/dialer/queueManager.js +++ b/src/dialer/queueManager.js @@ -171,7 +171,7 @@ class DialQueueManager { return } - let targetQueue = this._queues[nextQueue.value] + const targetQueue = this._queues[nextQueue.value] if (!targetQueue) { log('missing queue %s, maybe it was aborted?', nextQueue.value) diff --git a/src/limit-dialer/index.js b/src/limit-dialer/index.js index d911a75dd2..1702e89ae0 100644 --- a/src/limit-dialer/index.js +++ b/src/limit-dialer/index.js @@ -38,7 +38,7 @@ class LimitDialer { // we use a token to track if we want to cancel following dials const token = { cancel: false } - let errors = [] + const errors = [] const tasks = addrs.map((m) => { return (cb) => this.dialSingle(peer, transport, m, token, (err, result) => { if (err) { diff --git a/src/stats/index.js b/src/stats/index.js index 0948e05392..b79af19841 100644 --- a/src/stats/index.js +++ b/src/stats/index.js @@ -124,10 +124,10 @@ module.exports = (observer, _options) => { globalStats.start() - for (let peerStat of peerStats.values()) { + for (const peerStat of peerStats.values()) { peerStat.start() } - for (let transportStat of transportStats.values()) { + for (const transportStat of transportStats.values()) { transportStat.start() } } @@ -136,10 +136,10 @@ module.exports = (observer, _options) => { observer.removeListener('message', onMessage) globalStats.stop() - for (let peerStat of peerStats.values()) { + for (const peerStat of peerStats.values()) { peerStat.stop() } - for (let transportStat of transportStats.values()) { + for (const transportStat of transportStats.values()) { transportStat.stop() } } diff --git a/src/stats/stat.js b/src/stats/stat.js index 18b4a66bad..e90c9f83a7 100644 --- a/src/stats/stat.js +++ b/src/stats/stat.js @@ -222,7 +222,7 @@ class Stats extends EventEmitter { let n - if (!this._stats.hasOwnProperty(key)) { + if (!Object.prototype.hasOwnProperty.call(this._stats, key)) { n = this._stats[key] = Big(0) } else { n = this._stats[key] diff --git a/test/dialSelf.spec.js b/test/dialSelf.spec.js index 844979e28a..18daff2066 100644 --- a/test/dialSelf.spec.js +++ b/test/dialSelf.spec.js @@ -20,15 +20,18 @@ class MockTransport extends EventEmitter { super() this.conn = Duplex() } + dial (addr, cb) { - let c = this.conn[0] + const c = this.conn[0] this.emit('connection', this.conn[1]) setImmediate(() => cb(null, c)) return c } + listen (addr, cb) { return cb() } + filter (mas) { return Array.isArray(mas) ? mas : [mas] } diff --git a/test/get-peer-info.spec.js b/test/get-peer-info.spec.js index 1678dad6b1..3ac81a21e0 100644 --- a/test/get-peer-info.spec.js +++ b/test/get-peer-info.spec.js @@ -33,27 +33,27 @@ describe('Get peer info', () => { }) it('should be able get peer info from multiaddr', () => { - let _peerInfo = getPeerInfo(multiaddrA, peerBook) + const _peerInfo = getPeerInfo(multiaddrA, peerBook) expect(peerBook.has(_peerInfo)).to.equal(true) expect(peerInfoA).to.deep.equal(_peerInfo) }) it('should return a new PeerInfo with a multiAddr not in the PeerBook', () => { - let wrongMultiAddr = MultiAddr('/ipfs/QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi') - let _peerInfo = getPeerInfo(wrongMultiAddr, peerBook) + const wrongMultiAddr = MultiAddr('/ipfs/QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi') + const _peerInfo = getPeerInfo(wrongMultiAddr, peerBook) expect(PeerInfo.isPeerInfo(_peerInfo)).to.equal(true) expect(peerBook.has(_peerInfo)).to.equal(false) }) it('should be able get peer info from peer id', () => { - let _peerInfo = getPeerInfo(multiaddrA, peerBook) + const _peerInfo = getPeerInfo(multiaddrA, peerBook) expect(peerBook.has(_peerInfo)).to.equal(true) expect(peerInfoA).to.deep.equal(_peerInfo) }) it('should not be able to get the peer info for a wrong peer id', (done) => { PeerId.createFromJSON(TestPeerInfos[1].id, (err, id) => { - let func = () => { + const func = () => { getPeerInfo(id, peerBook) } @@ -93,7 +93,7 @@ describe('Get peer info', () => { }) it('an invalid peer type should throw an error', () => { - let func = () => { + const func = () => { getPeerInfo('/ip4/127.0.0.1/tcp/1234', peerBook) } diff --git a/test/identify.node.js b/test/identify.node.js index dc85d3e28e..16291a0235 100644 --- a/test/identify.node.js +++ b/test/identify.node.js @@ -89,7 +89,7 @@ describe('Identify', () => { switchB.dial(switchA._peerInfo, '/id-test/1.0.0', (err, conn) => { expect(err).to.not.exist() - let data = Buffer.from('data that can be had') + const data = Buffer.from('data that can be had') pull( pull.values([data]), conn, @@ -105,7 +105,7 @@ describe('Identify', () => { it('should get protocols for one another', (done) => { // We need to reset the PeerInfo objects we use, // since we share memory we can receive a false positive if not - let peerA = new PeerInfo(switchA._peerInfo.id) + const peerA = new PeerInfo(switchA._peerInfo.id) switchA._peerInfo.multiaddrs.toArray().forEach((m) => { peerA.multiaddrs.add(m) }) @@ -142,7 +142,7 @@ describe('Identify', () => { observedAddrs = observedAddrs[0] // pretend to be another peer - let publicKey = switchC._peerInfo.id.pubKey.bytes + const publicKey = switchC._peerInfo.id.pubKey.bytes const msgSend = identify.message.encode({ protocolVersion: 'ipfs/0.1.0', diff --git a/test/stats.node.js b/test/stats.node.js index e284f02b64..5ac24a067b 100644 --- a/test/stats.node.js +++ b/test/stats.node.js @@ -106,7 +106,7 @@ describe('Stats', () => { expect(err).to.not.exist() switches.forEach((swtch) => { - let snapshot = swtch.stats.global.snapshot + const snapshot = swtch.stats.global.snapshot expect(snapshot.dataReceived.toFixed()).to.equal('2210') expect(snapshot.dataSent.toFixed()).to.equal('2210') }) @@ -161,7 +161,7 @@ describe('Stats', () => { setup((err, switches) => { expect(err).to.not.exist() switches.forEach((swtch) => { - let snapshot = swtch.stats.forTransport('tcp').snapshot + const snapshot = swtch.stats.forTransport('tcp').snapshot expect(snapshot.dataReceived.toFixed()).to.equal('2210') expect(snapshot.dataSent.toFixed()).to.equal('2210') }) @@ -173,7 +173,7 @@ describe('Stats', () => { setup((err, switches) => { expect(err).to.not.exist() switches.forEach((swtch) => { - let snapshot = swtch.stats.forProtocol('/echo/1.0.0').snapshot + const snapshot = swtch.stats.forProtocol('/echo/1.0.0').snapshot expect(snapshot.dataReceived.toFixed()).to.equal('8') expect(snapshot.dataSent.toFixed()).to.equal('8') }) @@ -186,7 +186,7 @@ describe('Stats', () => { expect(err).to.not.exist() switches.forEach((swtch, index) => { const other = selectOther(switches, index) - let snapshot = swtch.stats.forPeer(other._peerInfo.id.toB58String()).snapshot + const snapshot = swtch.stats.forPeer(other._peerInfo.id.toB58String()).snapshot expect(snapshot.dataReceived.toFixed()).to.equal('2210') expect(snapshot.dataSent.toFixed()).to.equal('2210') }) @@ -199,7 +199,7 @@ describe('Stats', () => { expect(err).to.not.exist() switches.forEach((swtch, index) => { const other = selectOther(switches, index) - let ma = swtch.stats.forPeer(other._peerInfo.id.toB58String()).movingAverages + const ma = swtch.stats.forPeer(other._peerInfo.id.toB58String()).movingAverages const intervals = [60000, 300000, 900000] intervals.forEach((interval) => { const average = ma.dataReceived[interval].movingAverage() diff --git a/test/swarm-muxing+webrtc-star.browser.js b/test/swarm-muxing+webrtc-star.browser.js index 6ecf25ba5c..0861ec006d 100644 --- a/test/swarm-muxing+webrtc-star.browser.js +++ b/test/swarm-muxing+webrtc-star.browser.js @@ -15,6 +15,7 @@ const series = require('async/series') const pull = require('pull-stream') const PeerBook = require('peer-book') const tryEcho = require('./utils').tryEcho +const sinon = require('sinon') const Switch = require('../src') @@ -52,6 +53,10 @@ describe('Switch (webrtc-star)', () => { done() })) + afterEach(() => { + sinon.restore() + }) + it('add WebRTCStar transport to switch 1', () => { wstar1 = new WebRTCStar() switch1.transport.add('wstar', wstar1) @@ -119,6 +124,8 @@ describe('Switch (webrtc-star)', () => { wstar1.discovery.on('peer', (peerInfo) => switch1.dial(peerInfo, check)) wstar2.discovery.on('peer', (peerInfo) => switch2.dial(peerInfo, check)) + sinon.stub(wstar1.discovery, '_isStarted').value(true) + sinon.stub(wstar2.discovery, '_isStarted').value(true) peerId.create((err, id3) => { expect(err).to.not.exist() @@ -129,6 +136,7 @@ describe('Switch (webrtc-star)', () => { switch3 = new Switch(peer3, new PeerBook()) const wstar3 = new WebRTCStar() + sinon.stub(wstar3.discovery, '_isStarted').value(true) switch3.transport.add('wstar', wstar3) switch3.connection.addStreamMuxer(spdy) switch3.connection.reuse() diff --git a/test/utils.js b/test/utils.js index a518d73ea4..0348bcb5b9 100644 --- a/test/utils.js +++ b/test/utils.js @@ -64,7 +64,7 @@ exports.doneAfter = (n, willFinish, done) => { } let count = 0 - let errors = [] + const errors = [] return (err) => { count++ if (err) errors.push(err)