Skip to content

Commit 5ce0b36

Browse files
authored
chore: update deps and fix lint (libp2p#342)
* chore: update deps and fix lint * test: fix tests after webrtc-star upgrade
1 parent f64c73b commit 5ce0b36

File tree

14 files changed

+52
-38
lines changed

14 files changed

+52
-38
lines changed

.aegir.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ function pre (done) {
6464
}
6565

6666
parallel([
67-
(cb) => {
68-
sigS = sigServer.start(sigOptions, cb)
67+
async () => {
68+
sigS = await sigServer.start(sigOptions)
6969
},
7070
(cb) => createA(cb),
7171
(cb) => createB(cb)
@@ -76,7 +76,9 @@ function post (done) {
7676
parallel([
7777
(cb) => switchA.stop(cb),
7878
(cb) => switchB.stop(cb),
79-
(cb) => sigS.stop(cb)
79+
async () => {
80+
await sigS.stop()
81+
}
8082
], done)
8183
}
8284

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"npm": ">=3.0.0"
4141
},
4242
"devDependencies": {
43-
"aegir": "^18.2.1",
43+
"aegir": "^20.0.0",
4444
"chai": "^4.2.0",
4545
"chai-checkmark": "^1.0.1",
4646
"dirty-chai": "^2.0.1",
@@ -49,14 +49,14 @@
4949
"libp2p-secio": "~0.11.1",
5050
"libp2p-spdy": "~0.13.3",
5151
"libp2p-tcp": "~0.13.0",
52-
"libp2p-webrtc-star": "~0.15.8",
52+
"libp2p-webrtc-star": "~0.16.1",
5353
"libp2p-websockets": "~0.12.2",
5454
"peer-book": "~0.9.1",
5555
"portfinder": "^1.0.20",
56-
"pull-length-prefixed": "^1.3.2",
56+
"pull-length-prefixed": "^1.3.3",
5757
"pull-mplex": "~0.1.2",
5858
"pull-pair": "^1.1.0",
59-
"sinon": "^7.3.1",
59+
"sinon": "^7.3.2",
6060
"webrtcsupport": "^2.2.0"
6161
},
6262
"dependencies": {
@@ -71,12 +71,12 @@
7171
"libp2p-circuit": "~0.3.6",
7272
"libp2p-identify": "~0.7.6",
7373
"moving-average": "^1.0.0",
74-
"multiaddr": "^6.0.6",
75-
"multistream-select": "~0.14.4",
74+
"multiaddr": "^6.1.0",
75+
"multistream-select": "~0.14.6",
7676
"once": "^1.4.0",
7777
"peer-id": "~0.12.2",
7878
"peer-info": "~0.15.1",
79-
"pull-stream": "^3.6.9",
79+
"pull-stream": "^3.6.13",
8080
"retimer": "^2.0.0"
8181
},
8282
"contributors": [

src/connection/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class ConnectionFSM extends BaseConnection {
215215
}
216216

217217
const nextTransport = (key) => {
218-
let transport = key
218+
const transport = key
219219
if (!transport) {
220220
if (!circuitEnabled) {
221221
return this.close(
@@ -271,7 +271,7 @@ class ConnectionFSM extends BaseConnection {
271271

272272
delete this.switch.conns[this.theirB58Id]
273273

274-
let tasks = []
274+
const tasks = []
275275

276276
// Clean up stored connections
277277
if (this.muxer) {

src/dialer/queue.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Queue {
7373
this.isRunning = false
7474
this.onStopped = onStopped
7575
}
76+
7677
get length () {
7778
return this._queue.length
7879
}
@@ -139,7 +140,7 @@ class Queue {
139140
*/
140141
abort () {
141142
while (this.length > 0) {
142-
let dial = this._queue.shift()
143+
const dial = this._queue.shift()
143144
dial.callback(DIAL_ABORTED())
144145
}
145146
this.stop()
@@ -223,8 +224,8 @@ class Queue {
223224
})
224225

225226
const peerInfo = this.switch._peerBook.get(this.id)
226-
let queuedDial = this._queue.shift()
227-
let { connectionFSM, didCreate } = this._getOrCreateConnection(peerInfo)
227+
const queuedDial = this._queue.shift()
228+
const { connectionFSM, didCreate } = this._getOrCreateConnection(peerInfo)
228229

229230
// If the dial expects a ConnectionFSM, we can provide that back now
230231
if (queuedDial.useFSM) {

src/dialer/queueManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class DialQueueManager {
171171
return
172172
}
173173

174-
let targetQueue = this._queues[nextQueue.value]
174+
const targetQueue = this._queues[nextQueue.value]
175175

176176
if (!targetQueue) {
177177
log('missing queue %s, maybe it was aborted?', nextQueue.value)

src/limit-dialer/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class LimitDialer {
3838
// we use a token to track if we want to cancel following dials
3939
const token = { cancel: false }
4040

41-
let errors = []
41+
const errors = []
4242
const tasks = addrs.map((m) => {
4343
return (cb) => this.dialSingle(peer, transport, m, token, (err, result) => {
4444
if (err) {

src/stats/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ module.exports = (observer, _options) => {
124124

125125
globalStats.start()
126126

127-
for (let peerStat of peerStats.values()) {
127+
for (const peerStat of peerStats.values()) {
128128
peerStat.start()
129129
}
130-
for (let transportStat of transportStats.values()) {
130+
for (const transportStat of transportStats.values()) {
131131
transportStat.start()
132132
}
133133
}
@@ -136,10 +136,10 @@ module.exports = (observer, _options) => {
136136
observer.removeListener('message', onMessage)
137137
globalStats.stop()
138138

139-
for (let peerStat of peerStats.values()) {
139+
for (const peerStat of peerStats.values()) {
140140
peerStat.stop()
141141
}
142-
for (let transportStat of transportStats.values()) {
142+
for (const transportStat of transportStats.values()) {
143143
transportStat.stop()
144144
}
145145
}

src/stats/stat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class Stats extends EventEmitter {
222222

223223
let n
224224

225-
if (!this._stats.hasOwnProperty(key)) {
225+
if (!Object.prototype.hasOwnProperty.call(this._stats, key)) {
226226
n = this._stats[key] = Big(0)
227227
} else {
228228
n = this._stats[key]

test/dialSelf.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ class MockTransport extends EventEmitter {
2020
super()
2121
this.conn = Duplex()
2222
}
23+
2324
dial (addr, cb) {
24-
let c = this.conn[0]
25+
const c = this.conn[0]
2526
this.emit('connection', this.conn[1])
2627
setImmediate(() => cb(null, c))
2728
return c
2829
}
30+
2931
listen (addr, cb) {
3032
return cb()
3133
}
34+
3235
filter (mas) {
3336
return Array.isArray(mas) ? mas : [mas]
3437
}

test/get-peer-info.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,27 @@ describe('Get peer info', () => {
3333
})
3434

3535
it('should be able get peer info from multiaddr', () => {
36-
let _peerInfo = getPeerInfo(multiaddrA, peerBook)
36+
const _peerInfo = getPeerInfo(multiaddrA, peerBook)
3737
expect(peerBook.has(_peerInfo)).to.equal(true)
3838
expect(peerInfoA).to.deep.equal(_peerInfo)
3939
})
4040

4141
it('should return a new PeerInfo with a multiAddr not in the PeerBook', () => {
42-
let wrongMultiAddr = MultiAddr('/ipfs/QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi')
43-
let _peerInfo = getPeerInfo(wrongMultiAddr, peerBook)
42+
const wrongMultiAddr = MultiAddr('/ipfs/QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi')
43+
const _peerInfo = getPeerInfo(wrongMultiAddr, peerBook)
4444
expect(PeerInfo.isPeerInfo(_peerInfo)).to.equal(true)
4545
expect(peerBook.has(_peerInfo)).to.equal(false)
4646
})
4747

4848
it('should be able get peer info from peer id', () => {
49-
let _peerInfo = getPeerInfo(multiaddrA, peerBook)
49+
const _peerInfo = getPeerInfo(multiaddrA, peerBook)
5050
expect(peerBook.has(_peerInfo)).to.equal(true)
5151
expect(peerInfoA).to.deep.equal(_peerInfo)
5252
})
5353

5454
it('should not be able to get the peer info for a wrong peer id', (done) => {
5555
PeerId.createFromJSON(TestPeerInfos[1].id, (err, id) => {
56-
let func = () => {
56+
const func = () => {
5757
getPeerInfo(id, peerBook)
5858
}
5959

@@ -93,7 +93,7 @@ describe('Get peer info', () => {
9393
})
9494

9595
it('an invalid peer type should throw an error', () => {
96-
let func = () => {
96+
const func = () => {
9797
getPeerInfo('/ip4/127.0.0.1/tcp/1234', peerBook)
9898
}
9999

test/identify.node.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('Identify', () => {
8989
switchB.dial(switchA._peerInfo, '/id-test/1.0.0', (err, conn) => {
9090
expect(err).to.not.exist()
9191

92-
let data = Buffer.from('data that can be had')
92+
const data = Buffer.from('data that can be had')
9393
pull(
9494
pull.values([data]),
9595
conn,
@@ -105,7 +105,7 @@ describe('Identify', () => {
105105
it('should get protocols for one another', (done) => {
106106
// We need to reset the PeerInfo objects we use,
107107
// since we share memory we can receive a false positive if not
108-
let peerA = new PeerInfo(switchA._peerInfo.id)
108+
const peerA = new PeerInfo(switchA._peerInfo.id)
109109
switchA._peerInfo.multiaddrs.toArray().forEach((m) => {
110110
peerA.multiaddrs.add(m)
111111
})
@@ -142,7 +142,7 @@ describe('Identify', () => {
142142
observedAddrs = observedAddrs[0]
143143

144144
// pretend to be another peer
145-
let publicKey = switchC._peerInfo.id.pubKey.bytes
145+
const publicKey = switchC._peerInfo.id.pubKey.bytes
146146

147147
const msgSend = identify.message.encode({
148148
protocolVersion: 'ipfs/0.1.0',

test/stats.node.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe('Stats', () => {
106106
expect(err).to.not.exist()
107107

108108
switches.forEach((swtch) => {
109-
let snapshot = swtch.stats.global.snapshot
109+
const snapshot = swtch.stats.global.snapshot
110110
expect(snapshot.dataReceived.toFixed()).to.equal('2210')
111111
expect(snapshot.dataSent.toFixed()).to.equal('2210')
112112
})
@@ -161,7 +161,7 @@ describe('Stats', () => {
161161
setup((err, switches) => {
162162
expect(err).to.not.exist()
163163
switches.forEach((swtch) => {
164-
let snapshot = swtch.stats.forTransport('tcp').snapshot
164+
const snapshot = swtch.stats.forTransport('tcp').snapshot
165165
expect(snapshot.dataReceived.toFixed()).to.equal('2210')
166166
expect(snapshot.dataSent.toFixed()).to.equal('2210')
167167
})
@@ -173,7 +173,7 @@ describe('Stats', () => {
173173
setup((err, switches) => {
174174
expect(err).to.not.exist()
175175
switches.forEach((swtch) => {
176-
let snapshot = swtch.stats.forProtocol('/echo/1.0.0').snapshot
176+
const snapshot = swtch.stats.forProtocol('/echo/1.0.0').snapshot
177177
expect(snapshot.dataReceived.toFixed()).to.equal('8')
178178
expect(snapshot.dataSent.toFixed()).to.equal('8')
179179
})
@@ -186,7 +186,7 @@ describe('Stats', () => {
186186
expect(err).to.not.exist()
187187
switches.forEach((swtch, index) => {
188188
const other = selectOther(switches, index)
189-
let snapshot = swtch.stats.forPeer(other._peerInfo.id.toB58String()).snapshot
189+
const snapshot = swtch.stats.forPeer(other._peerInfo.id.toB58String()).snapshot
190190
expect(snapshot.dataReceived.toFixed()).to.equal('2210')
191191
expect(snapshot.dataSent.toFixed()).to.equal('2210')
192192
})
@@ -199,7 +199,7 @@ describe('Stats', () => {
199199
expect(err).to.not.exist()
200200
switches.forEach((swtch, index) => {
201201
const other = selectOther(switches, index)
202-
let ma = swtch.stats.forPeer(other._peerInfo.id.toB58String()).movingAverages
202+
const ma = swtch.stats.forPeer(other._peerInfo.id.toB58String()).movingAverages
203203
const intervals = [60000, 300000, 900000]
204204
intervals.forEach((interval) => {
205205
const average = ma.dataReceived[interval].movingAverage()

test/swarm-muxing+webrtc-star.browser.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const series = require('async/series')
1515
const pull = require('pull-stream')
1616
const PeerBook = require('peer-book')
1717
const tryEcho = require('./utils').tryEcho
18+
const sinon = require('sinon')
1819

1920
const Switch = require('../src')
2021

@@ -52,6 +53,10 @@ describe('Switch (webrtc-star)', () => {
5253
done()
5354
}))
5455

56+
afterEach(() => {
57+
sinon.restore()
58+
})
59+
5560
it('add WebRTCStar transport to switch 1', () => {
5661
wstar1 = new WebRTCStar()
5762
switch1.transport.add('wstar', wstar1)
@@ -119,6 +124,8 @@ describe('Switch (webrtc-star)', () => {
119124

120125
wstar1.discovery.on('peer', (peerInfo) => switch1.dial(peerInfo, check))
121126
wstar2.discovery.on('peer', (peerInfo) => switch2.dial(peerInfo, check))
127+
sinon.stub(wstar1.discovery, '_isStarted').value(true)
128+
sinon.stub(wstar2.discovery, '_isStarted').value(true)
122129

123130
peerId.create((err, id3) => {
124131
expect(err).to.not.exist()
@@ -129,6 +136,7 @@ describe('Switch (webrtc-star)', () => {
129136

130137
switch3 = new Switch(peer3, new PeerBook())
131138
const wstar3 = new WebRTCStar()
139+
sinon.stub(wstar3.discovery, '_isStarted').value(true)
132140
switch3.transport.add('wstar', wstar3)
133141
switch3.connection.addStreamMuxer(spdy)
134142
switch3.connection.reuse()

test/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ exports.doneAfter = (n, willFinish, done) => {
6464
}
6565

6666
let count = 0
67-
let errors = []
67+
const errors = []
6868
return (err) => {
6969
count++
7070
if (err) errors.push(err)

0 commit comments

Comments
 (0)