Skip to content

Commit

Permalink
chore: update deps and fix lint (libp2p#342)
Browse files Browse the repository at this point in the history
* chore: update deps and fix lint

* test: fix tests after webrtc-star upgrade
  • Loading branch information
jacobheun authored Aug 1, 2019
1 parent f64c73b commit 5ce0b36
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 38 deletions.
8 changes: 5 additions & 3 deletions .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}

Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand All @@ -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": [
Expand Down
4 changes: 2 additions & 2 deletions src/connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class ConnectionFSM extends BaseConnection {
}

const nextTransport = (key) => {
let transport = key
const transport = key
if (!transport) {
if (!circuitEnabled) {
return this.close(
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions src/dialer/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Queue {
this.isRunning = false
this.onStopped = onStopped
}

get length () {
return this._queue.length
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/dialer/queueManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/limit-dialer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/stats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand All @@ -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()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/stats/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 4 additions & 1 deletion test/dialSelf.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
12 changes: 6 additions & 6 deletions test/get-peer-info.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions test/identify.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
})
Expand Down Expand Up @@ -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',
Expand Down
10 changes: 5 additions & 5 deletions test/stats.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down Expand Up @@ -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')
})
Expand All @@ -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')
})
Expand All @@ -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')
})
Expand All @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions test/swarm-muxing+webrtc-star.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ exports.doneAfter = (n, willFinish, done) => {
}

let count = 0
let errors = []
const errors = []
return (err) => {
count++
if (err) errors.push(err)
Expand Down

0 comments on commit 5ce0b36

Please sign in to comment.