From bbdca01782aec112abced9250d0d2a6505bfe775 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 13 Aug 2020 09:49:41 +0100 Subject: [PATCH 1/5] fix: replace node buffers with uint8arrays BREAKING CHANGES: - All use of node Buffers have been replaced with Uint8Arrays - All deps now use Uint8Arrays in place of node Buffers --- package.json | 30 ++++++++++++------------ src/notifications.js | 9 +++---- src/types/message/index.js | 8 +++---- src/utils/index.js | 3 ++- test/bitswap-mock-internals.js | 1 - test/decision-engine/decision-engine.js | 29 ++++++++++++----------- test/network/gen-bitswap-network.node.js | 3 +-- test/notifications.spec.js | 19 ++++++++------- test/types/message.spec.js | 21 +++++++++-------- test/utils.spec.js | 16 ++++++------- test/utils/make-block.js | 4 ++-- test/wantmanager/msg-queue.spec.js | 1 - 12 files changed, 73 insertions(+), 71 deletions(-) diff --git a/package.json b/package.json index 7ee0e247..c10ac6ce 100644 --- a/package.json +++ b/package.json @@ -45,18 +45,17 @@ "@nodeutils/defaults-deep": "^1.1.0", "aegir": "^25.0.0", "benchmark": "^2.1.4", - "buffer": "^5.6.0", "delay": "^4.3.0", - "ipfs-repo": "^4.0.0", + "ipfs-repo": "^6.0.1", "ipfs-utils": "^2.2.0", "iso-random-stream": "^1.1.1", "it-all": "^1.0.2", "it-drain": "^1.0.1", - "libp2p": "^0.28.0", - "libp2p-kad-dht": "^0.19.1", - "libp2p-mplex": "^0.9.2", - "libp2p-secio": "^0.12.1", - "libp2p-tcp": "^0.14.2", + "libp2p": "libp2p/js-libp2p#fix/replace-node-buffers-with-uint8arrays", + "libp2p-kad-dht": "^0.20.0", + "libp2p-mplex": "^0.10.0", + "libp2p-secio": "^0.13.0", + "libp2p-tcp": "^0.15.0", "lodash.difference": "^4.5.0", "lodash.flatten": "^4.4.0", "lodash.range": "^3.2.0", @@ -65,7 +64,7 @@ "p-defer": "^3.0.0", "p-event": "^4.1.0", "p-wait-for": "^3.1.0", - "peer-id": "^0.13.5", + "peer-id": "^0.14.0", "promisify-es6": "^1.0.3", "rimraf": "^3.0.0", "sinon": "^9.0.0", @@ -76,19 +75,20 @@ "abort-controller": "^3.0.0", "any-signal": "^1.1.0", "bignumber.js": "^9.0.0", - "cids": "^0.8.3", + "cids": "^1.0.0", "debug": "^4.1.0", - "ipld-block": "^0.9.1", + "ipld-block": "^0.10.0", "it-length-prefixed": "^3.0.0", "it-pipe": "^1.1.0", "just-debounce-it": "^1.1.0", - "libp2p-interfaces": "^0.3.0", + "libp2p-interfaces": "^0.4.1", "moving-average": "^1.0.0", - "multicodec": "^1.0.3", - "multihashing-async": "^1.0.0", - "protons": "^1.0.1", + "multicodec": "^2.0.0", + "multihashing-async": "^2.0.1", + "protons": "^2.0.0", "streaming-iterables": "^5.0.2", - "varint-decoder": "^0.4.0" + "uint8arrays": "^1.1.0", + "varint-decoder": "^1.0.0" }, "pre-push": [ "lint", diff --git a/src/notifications.js b/src/notifications.js index 57fb063a..2243fec3 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -2,13 +2,14 @@ const EventEmitter = require('events').EventEmitter const Block = require('ipld-block') +const uint8ArrayEquals = require('uint8arrays/equals') +const uint8ArrayToString = require('uint8arrays/to-string') const CONSTANTS = require('./constants') const logger = require('./utils').logger -const cidToMultihashString = (cid) => cid.multihash.toString('base64') -const unwantEvent = (cid) => `unwant:${cidToMultihashString(cid)}` -const blockEvent = (cid) => `block:${cidToMultihashString(cid)}` +const unwantEvent = (cid) => `unwant:${uint8ArrayToString(cid.multihash, 'base64')}` +const blockEvent = (cid) => `block:${uint8ArrayToString(cid.multihash, 'base64')}` /** * Internal module used to track events about incoming blocks, @@ -67,7 +68,7 @@ class Notifications extends EventEmitter { const onBlock = (block) => { this.removeListener(unwantEvt, onUnwant) - if (!cid.multihash.equals(block.cid.multihash)) { + if (!uint8ArrayEquals(cid.multihash, block.cid.multihash)) { // wrong block return reject(new Error(`Incorrect block received for ${cid}`)) } else if (cid.version !== block.cid.version || cid.codec !== block.cid.codec) { diff --git a/src/types/message/index.js b/src/types/message/index.js index 0263a7ca..c4be0c58 100644 --- a/src/types/message/index.js +++ b/src/types/message/index.js @@ -91,7 +91,7 @@ class BitswapMessage { wantlist: { entries: Array.from(this.wantlist.values()).map((entry) => { return { - block: entry.cid.buffer, // cid + block: entry.cid.bytes, // cid priority: Number(entry.priority), cancel: Boolean(entry.cancel) } @@ -117,7 +117,7 @@ class BitswapMessage { wantlist: { entries: Array.from(this.wantlist.values()).map((entry) => { return { - block: entry.cid.buffer, // cid + block: entry.cid.bytes, // cid priority: Number(entry.priority), wantType: entry.wantType, cancel: Boolean(entry.cancel), @@ -142,7 +142,7 @@ class BitswapMessage { for (const [cidStr, bpType] of this.blockPresences) { msg.blockPresences.push({ - cid: new CID(cidStr).buffer, + cid: new CID(cidStr).bytes, type: bpType }) } @@ -237,7 +237,7 @@ BitswapMessage.blockPresenceSize = (cid) => { // the HAVE / DONT_HAVE on the wire, but when doing that calculation we leave // plenty of padding under the maximum message size. // (It's more important for this to be fast). - return cid.buffer.length + 1 + return cid.bytes.length + 1 } BitswapMessage.Entry = Entry diff --git a/src/utils/index.js b/src/utils/index.js index a5f7eb26..334bd17a 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,6 +1,7 @@ 'use strict' const debug = require('debug') +const uint8ArrayEquals = require('uint8arrays/equals') /** * Creates a logger for the given subsystem @@ -103,7 +104,7 @@ const isMapEqual = (a, b) => { return false } // Support Blocks - if (valueA._data && !valueA._data.equals(valueB._data)) { + if (valueA._data && !uint8ArrayEquals(valueA._data, valueB._data)) { return false } } diff --git a/test/bitswap-mock-internals.js b/test/bitswap-mock-internals.js index 048b2c7e..07f91b76 100644 --- a/test/bitswap-mock-internals.js +++ b/test/bitswap-mock-internals.js @@ -332,7 +332,6 @@ describe('bitswap with mocks', function () { setTimeout(() => { bs2.put(block, () => {}) }, 1000) - const b1 = await p1 expect(b1).to.eql(block) diff --git a/test/decision-engine/decision-engine.js b/test/decision-engine/decision-engine.js index 4c9b45ff..04b7f8c6 100644 --- a/test/decision-engine/decision-engine.js +++ b/test/decision-engine/decision-engine.js @@ -9,7 +9,8 @@ const flatten = require('lodash.flatten') const Block = require('ipld-block') const CID = require('cids') const multihashing = require('multihashing-async') -const { Buffer } = require('buffer') +const uint8ArrayFromString = require('uint8arrays/from-string') +const uint8ArrayToString = require('uint8arrays/to-string') const drain = require('it-drain') const Message = require('../../src/types/message') @@ -23,7 +24,7 @@ const sum = (nums) => nums.reduce((a, b) => a + b, 0) function messageToString (m) { return Array.from(m[1].blocks.values()) - .map((b) => b.data.toString()) + .map((b) => uint8ArrayToString(b.data)) } function stringifyMessages (messages) { @@ -53,7 +54,7 @@ describe('Engine', () => { const receiver = res[1] await Promise.all(range(1000).map(async (i) => { - const data = Buffer.from(`this is message ${i}`) + const data = uint8ArrayFromString(`this is message ${i}`) const hash = await multihashing(data, 'sha2-256') const m = new Message(false) @@ -110,7 +111,7 @@ describe('Engine', () => { async function partnerWants (dEngine, values, partner) { const message = new Message(false) - const hashes = await Promise.all(values.map((v) => multihashing(Buffer.from(v), 'sha2-256'))) + const hashes = await Promise.all(values.map((v) => multihashing(uint8ArrayFromString(v), 'sha2-256'))) hashes.forEach((hash, i) => { message.addEntry(new CID(hash), Math.pow(2, 32) - 1 - i) }) @@ -120,7 +121,7 @@ describe('Engine', () => { async function partnerCancels (dEngine, values, partner) { const message = new Message(false) - const hashes = await Promise.all(values.map((v) => multihashing(Buffer.from(v), 'sha2-256'))) + const hashes = await Promise.all(values.map((v) => multihashing(uint8ArrayFromString(v), 'sha2-256'))) hashes.forEach((hash) => { message.cancel(new CID(hash)) }) @@ -134,8 +135,8 @@ describe('Engine', () => { await dEngine.receivedBlocks(blocks) } - const hashes = await Promise.all(alphabet.map(v => multihashing(Buffer.from(v), 'sha2-256'))) - const blocks = hashes.map((h, i) => new Block(Buffer.from(alphabet[i]), new CID(h))) + const hashes = await Promise.all(alphabet.map(v => multihashing(uint8ArrayFromString(v), 'sha2-256'))) + const blocks = hashes.map((h, i) => new Block(uint8ArrayFromString(alphabet[i]), new CID(h))) const partner = await PeerId.create({ bits: 512 }) const somePeer = await PeerId.create({ bits: 512 }) @@ -349,8 +350,8 @@ describe('Engine', () => { const vowels = 'aeiou' const alphabetLs = alphabet.split('') - const hashes = await Promise.all(alphabetLs.map(v => multihashing(Buffer.from(v), 'sha2-256'))) - const blocks = hashes.map((h, i) => new Block(Buffer.from(alphabetLs[i]), new CID(h))) + const hashes = await Promise.all(alphabetLs.map(v => multihashing(uint8ArrayFromString(v), 'sha2-256'))) + const blocks = hashes.map((h, i) => new Block(uint8ArrayFromString(alphabetLs[i]), new CID(h))) let testCases = [ // Just send want-blocks @@ -603,7 +604,7 @@ describe('Engine', () => { let i = wantBlks.length + wantHaves.length const message = new Message(false) for (const [wants, type] of wantTypes) { - const hashes = await Promise.all(wants.map((v) => multihashing(Buffer.from(v), 'sha2-256'))) + const hashes = await Promise.all(wants.map((v) => multihashing(uint8ArrayFromString(v), 'sha2-256'))) for (const hash of hashes) { message.addEntry(new CID(hash), i--, type, false, sendDontHave) } @@ -661,13 +662,13 @@ describe('Engine', () => { // Expect the correct block contents for (const expBlk of expBlks) { - const hash = await multihashing(Buffer.from(expBlk), 'sha2-256') + const hash = await multihashing(uint8ArrayFromString(expBlk), 'sha2-256') expect(msg.blocks.has(new CID(hash).toString())) } // Expect the correct HAVEs for (const expHave of expHaves) { - const hash = await multihashing(Buffer.from(expHave), 'sha2-256') + const hash = await multihashing(uint8ArrayFromString(expHave), 'sha2-256') const cid = new CID(hash).toString() expect(msg.blockPresences.has(cid)).to.eql(true) expect(msg.blockPresences.get(cid)).to.eql(Message.BlockPresenceType.Have) @@ -675,7 +676,7 @@ describe('Engine', () => { // Expect the correct DONT_HAVEs for (const expDontHave of expDontHaves) { - const hash = await multihashing(Buffer.from(expDontHave), 'sha2-256') + const hash = await multihashing(uint8ArrayFromString(expDontHave), 'sha2-256') const cid = new CID(hash).toString() expect(msg.blockPresences.has(cid)).to.eql(true) expect(msg.blockPresences.get(cid)).to.eql(Message.BlockPresenceType.DontHave) @@ -700,7 +701,7 @@ describe('Engine', () => { const them = await newEngine() // add a block to our blockstore - const data = Buffer.from(`this is message ${Date.now()}`) + const data = uint8ArrayFromString(`this is message ${Date.now()}`) const hash = await multihashing(data, 'sha2-256') const cid = new CID(hash) const block = new Block(data, cid) diff --git a/test/network/gen-bitswap-network.node.js b/test/network/gen-bitswap-network.node.js index 4fb1087d..89a7a0bc 100644 --- a/test/network/gen-bitswap-network.node.js +++ b/test/network/gen-bitswap-network.node.js @@ -4,7 +4,6 @@ const { expect } = require('aegir/utils/chai') const Block = require('ipld-block') -const { Buffer } = require('buffer') const crypto = require('crypto') const CID = require('cids') const multihashing = require('multihashing-async') @@ -21,7 +20,7 @@ describe('gen Bitswap network', function () { const node = nodes[0] const blocks = await Promise.all(range(100).map(async (k) => { - const b = Buffer.alloc(1024) + const b = new Uint8Array(1024) b.fill(k) const hash = await multihashing(b, 'sha2-256') const cid = new CID(hash) diff --git a/test/notifications.spec.js b/test/notifications.spec.js index eef19818..2f31826e 100644 --- a/test/notifications.spec.js +++ b/test/notifications.spec.js @@ -5,6 +5,7 @@ const { expect } = require('aegir/utils/chai') const CID = require('cids') const Block = require('ipld-block') const AbortController = require('abort-controller') +const uint8ArrayToString = require('uint8arrays/to-string') const Notifications = require('../src/notifications') @@ -23,7 +24,7 @@ describe('Notifications', () => { it('hasBlock', (done) => { const n = new Notifications(peerId) const b = blocks[0] - n.once(`block:${b.cid.multihash.toString('base64')}`, (block) => { + n.once(`block:${uint8ArrayToString(b.cid.multihash, 'base64')}`, (block) => { expect(b).to.eql(block) done() }) @@ -38,8 +39,8 @@ describe('Notifications', () => { const p = n.wantBlock(b.cid) // check that listeners have been set up - expect(n.listenerCount(`block:${b.cid.multihash.toString('base64')}`)).to.equal(1) - expect(n.listenerCount(`unwant:${b.cid.multihash.toString('base64')}`)).to.equal(1) + expect(n.listenerCount(`block:${uint8ArrayToString(b.cid.multihash, 'base64')}`)).to.equal(1) + expect(n.listenerCount(`unwant:${uint8ArrayToString(b.cid.multihash, 'base64')}`)).to.equal(1) n.hasBlock(b) @@ -48,8 +49,8 @@ describe('Notifications', () => { expect(b).to.eql(block) // check that internal cleanup works as expected - expect(n.listenerCount(`block:${b.cid.multihash.toString('base64')}`)).to.equal(0) - expect(n.listenerCount(`unwant:${b.cid.multihash.toString('base64')}`)).to.equal(0) + expect(n.listenerCount(`block:${uint8ArrayToString(b.cid.multihash, 'base64')}`)).to.equal(0) + expect(n.listenerCount(`unwant:${uint8ArrayToString(b.cid.multihash, 'base64')}`)).to.equal(0) }) it('unwant block', async () => { @@ -89,16 +90,16 @@ describe('Notifications', () => { const p = n.wantBlock(cid2) // check that listeners have been set up - expect(n.listenerCount(`block:${cid2.multihash.toString('base64')}`)).to.equal(1) - expect(n.listenerCount(`unwant:${cid2.multihash.toString('base64')}`)).to.equal(1) + expect(n.listenerCount(`block:${uint8ArrayToString(cid2.multihash, 'base64')}`)).to.equal(1) + expect(n.listenerCount(`unwant:${uint8ArrayToString(cid2.multihash, 'base64')}`)).to.equal(1) n.hasBlock(b) await expect(p).to.eventually.be.eql(b) // check that internal cleanup works as expected - expect(n.listenerCount(`block:${cid2.multihash.toString('base64')}`)).to.equal(0) - expect(n.listenerCount(`unwant:${cid2.multihash.toString('base64')}`)).to.equal(0) + expect(n.listenerCount(`block:${uint8ArrayToString(cid2.multihash, 'base64')}`)).to.equal(0) + expect(n.listenerCount(`unwant:${uint8ArrayToString(cid2.multihash, 'base64')}`)).to.equal(0) }) it('unwant block', async () => { diff --git a/test/types/message.spec.js b/test/types/message.spec.js index bb31f615..d3a3f551 100644 --- a/test/types/message.spec.js +++ b/test/types/message.spec.js @@ -3,7 +3,8 @@ const { expect } = require('aegir/utils/chai') const CID = require('cids') -const { Buffer } = require('buffer') +const uint8ArrayFromString = require('uint8arrays/from-string') +const uint8ArrayEquals = require('uint8arrays/equals') const loadFixture = require('aegir/fixtures') const testDataPath = 'test/fixtures/serialized-from-go' const rawMessageFullWantlist = loadFixture(testDataPath + '/bitswap110-message-full-wantlist') @@ -31,7 +32,7 @@ describe('BitswapMessage', () => { const serialized = msg.serializeToBitswap100() expect(Message.decode(serialized).wantlist.entries[0]).to.be.eql({ - block: cid.buffer, + block: cid.bytes, priority: 1, cancel: false, sendDontHave: false, @@ -118,9 +119,9 @@ describe('BitswapMessage', () => { expect(decoded.blockPresences.length).to.eql(2) for (const bp of decoded.blockPresences) { if (bp.type === BitswapMessage.BlockPresenceType.Have) { - expect(bp.cid.equals(cids[1].buffer)).to.eql(true) + expect(uint8ArrayEquals(bp.cid, cids[1].bytes)).to.eql(true) } else { - expect(bp.cid.equals(cids[2].buffer)).to.eql(true) + expect(uint8ArrayEquals(bp.cid, cids[2].bytes)).to.eql(true) } } }) @@ -136,7 +137,7 @@ describe('BitswapMessage', () => { const raw = Message.encode({ wantlist: { entries: [{ - block: cid0.buffer, + block: cid0.bytes, cancel: false }], full: true @@ -175,7 +176,7 @@ describe('BitswapMessage', () => { const raw = Message.encode({ wantlist: { entries: [{ - block: cid0.buffer, + block: cid0.bytes, cancel: false, wantType: BitswapMessage.WantType.Block, sendDontHave: true @@ -190,7 +191,7 @@ describe('BitswapMessage', () => { prefix: cid2.prefix }], blockPresences: [{ - cid: cid3.buffer, + cid: cid3.bytes, type: BitswapMessage.BlockPresenceType.Have }], pendingBytes: 10 @@ -278,8 +279,8 @@ describe('BitswapMessage', () => { it('true, same cid derived from distinct encoding', () => { const b = blocks[0] const cid = cids[0].toV1() - const cid1 = new CID(cid.toBaseEncodedString('base32')) - const cid2 = new CID(cid.toBaseEncodedString('base64')) + const cid1 = new CID(cid.toString('base32')) + const cid2 = new CID(cid.toString('base64')) const m1 = new BitswapMessage(true) const m2 = new BitswapMessage(true) @@ -325,7 +326,7 @@ describe('BitswapMessage', () => { describe('go interop', () => { it('bitswap 1.0.0 message', async () => { - const goEncoded = Buffer.from('CioKKAoiEiAs8k26X7CjDiboOyrFueKeGxYeXB+nQl5zBDNik4uYJBAKGAA=', 'base64') + const goEncoded = uint8ArrayFromString('CioKKAoiEiAs8k26X7CjDiboOyrFueKeGxYeXB+nQl5zBDNik4uYJBAKGAA=', 'base64pad') const msg = new BitswapMessage(false) const cid = new CID('QmRN6wdp1S2A5EtjW9A3M1vKSBuQQGcgvuhoMUoEz4iiT5') diff --git a/test/utils.spec.js b/test/utils.spec.js index d9394b03..46b8863a 100644 --- a/test/utils.spec.js +++ b/test/utils.spec.js @@ -4,9 +4,9 @@ const { expect } = require('aegir/utils/chai') const CID = require('cids') const Block = require('ipld-block') -const { Buffer } = require('buffer') const multihashing = require('multihashing-async') const BitswapMessageEntry = require('../src/types/message/entry') +const uint8ArrayFromString = require('uint8arrays/from-string') const { groupBy, uniqWith, pullAllWith, includesWith, sortBy, isMapEqual } = require('../src/utils') const SortedMap = require('../src/utils/sorted-map') @@ -123,7 +123,7 @@ describe('utils spec', function () { }) it('should on be false if BitswapMessageEntry dont match', async () => { - const hash1 = await multihashing(Buffer.from('OMG!1'), 'sha2-256') + const hash1 = await multihashing(uint8ArrayFromString('OMG!1'), 'sha2-256') const cid1 = new CID(1, 'dag-pb', hash1) expect(isMapEqual( @@ -133,7 +133,7 @@ describe('utils spec', function () { }) it('should on be true if BitswapMessageEntry match', async () => { - const hash1 = await multihashing(Buffer.from('OMG!1'), 'sha2-256') + const hash1 = await multihashing(uint8ArrayFromString('OMG!1'), 'sha2-256') const cid1 = new CID(1, 'dag-pb', hash1) expect(isMapEqual( @@ -143,10 +143,10 @@ describe('utils spec', function () { }) it('should on be false if Blocks dont match', async () => { - const hash1 = await multihashing(Buffer.from('OMG!1'), 'sha2-256') + const hash1 = await multihashing(uint8ArrayFromString('OMG!1'), 'sha2-256') const cid1 = new CID(1, 'dag-pb', hash1) - const block1 = new Block(Buffer.from('hello world'), cid1) - const block2 = new Block(Buffer.from('hello world 2'), cid1) + const block1 = new Block(uint8ArrayFromString('hello world'), cid1) + const block2 = new Block(uint8ArrayFromString('hello world 2'), cid1) expect(isMapEqual( new Map([['key1', block1], ['key2', block1]]), @@ -155,9 +155,9 @@ describe('utils spec', function () { }) it('should on be true if Blocks match', async () => { - const hash1 = await multihashing(Buffer.from('OMG!1'), 'sha2-256') + const hash1 = await multihashing(uint8ArrayFromString('OMG!1'), 'sha2-256') const cid1 = new CID(1, 'dag-pb', hash1) - const block1 = new Block(Buffer.from('hello world'), cid1) + const block1 = new Block(uint8ArrayFromString('hello world'), cid1) expect(isMapEqual( new Map([['key1', block1], ['key2', block1]]), diff --git a/test/utils/make-block.js b/test/utils/make-block.js index 8848fc8b..81dfc3fc 100644 --- a/test/utils/make-block.js +++ b/test/utils/make-block.js @@ -5,13 +5,13 @@ const CID = require('cids') const Block = require('ipld-block') const randomBytes = require('iso-random-stream/src/random') const range = require('lodash.range') -const { Buffer } = require('buffer') +const uint8ArrayFromString = require('uint8arrays/from-string') const { v4: uuid } = require('uuid') module.exports = async (count, size) => { const blocks = await Promise.all( range(count || 1).map(async () => { - const data = size ? randomBytes(size) : Buffer.from(`hello world ${uuid()}`) + const data = size ? randomBytes(size) : uint8ArrayFromString(`hello world ${uuid()}`) const hash = await multihashing(data, 'sha2-256') return new Block(data, new CID(hash)) }) diff --git a/test/wantmanager/msg-queue.spec.js b/test/wantmanager/msg-queue.spec.js index 7f1d22c8..fda8cf24 100644 --- a/test/wantmanager/msg-queue.spec.js +++ b/test/wantmanager/msg-queue.spec.js @@ -5,7 +5,6 @@ const { expect } = require('aegir/utils/chai') const PeerId = require('peer-id') const CID = require('cids') const multihashing = require('multihashing-async') -const { Buffer } = require('buffer') const Message = require('../../src/types/message') const MsgQueue = require('../../src/want-manager/msg-queue') From 1963ddd0dd68533d84dcea4cc82916fb0b9ac3a4 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 17 Aug 2020 08:57:25 +0100 Subject: [PATCH 2/5] chore: stop libp2p before closing repos --- package.json | 2 +- test/bitswap-stats.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index c10ac6ce..30bcdb2f 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "homepage": "https://github.com/ipfs/js-ipfs-bitswap#readme", "devDependencies": { "@nodeutils/defaults-deep": "^1.1.0", - "aegir": "^25.0.0", + "aegir": "^26.0.0", "benchmark": "^2.1.4", "delay": "^4.3.0", "ipfs-repo": "^6.0.1", diff --git a/test/bitswap-stats.js b/test/bitswap-stats.js index 82dfe9b7..c6499851 100644 --- a/test/bitswap-stats.js +++ b/test/bitswap-stats.js @@ -73,10 +73,10 @@ describe('bitswap stats', () => { bitswaps.map((bs) => bs.stop()) ) await Promise.all( - repos.map(repo => repo.teardown()) + libp2pNodes.map((n) => n.stop()) ) await Promise.all( - libp2pNodes.map((n) => n.stop()) + repos.map(repo => repo.teardown()) ) }) From 760811c36fbfe2fa911cd202b81f9e12798f9228 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 17 Aug 2020 09:17:59 +0100 Subject: [PATCH 3/5] chore: test on latest node and do not build twice --- .travis.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index f435392a..2398cfd5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,20 @@ language: node_js cache: npm +branches: + only: + - master + - /^release\/.*$/ + +node_js: + - 'lts/*' + - 'node' + stages: - check - test - cov -node_js: - - '12' - - '10' - os: - linux - osx From 333c34c7c758ad0e627f67edae81dfed57cc0437 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 24 Aug 2020 12:18:33 +0100 Subject: [PATCH 4/5] chore: switch to 0.29.x libp2p branch --- package.json | 4 ++-- test/utils/mocks.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 30bcdb2f..f57e8125 100644 --- a/package.json +++ b/package.json @@ -47,11 +47,11 @@ "benchmark": "^2.1.4", "delay": "^4.3.0", "ipfs-repo": "^6.0.1", - "ipfs-utils": "^2.2.0", + "ipfs-utils": "^3.0.0", "iso-random-stream": "^1.1.1", "it-all": "^1.0.2", "it-drain": "^1.0.1", - "libp2p": "libp2p/js-libp2p#fix/replace-node-buffers-with-uint8arrays", + "libp2p": "libp2p/js-libp2p#0.29.x", "libp2p-kad-dht": "^0.20.0", "libp2p-mplex": "^0.10.0", "libp2p-secio": "^0.13.0", diff --git a/test/utils/mocks.js b/test/utils/mocks.js index a0635211..696e608a 100644 --- a/test/utils/mocks.js +++ b/test/utils/mocks.js @@ -43,7 +43,7 @@ exports.mockLibp2pNode = () => { swarm: { setMaxListeners () {} }, - peerStore: new PeerStore() + peerStore: new PeerStore({ peerId }) }) } From 89b74630ad9ccf3a33cccb19ffe2a98152e9728d Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 24 Aug 2020 13:16:09 +0100 Subject: [PATCH 5/5] chore: fix NaN in moving averages and race condition in test --- src/stats/stat.js | 8 +++++--- test/bitswap-stats.js | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/stats/stat.js b/src/stats/stat.js index 15e146f7..da3e461e 100644 --- a/src/stats/stat.js +++ b/src/stats/stat.js @@ -91,9 +91,11 @@ class Stats extends EventEmitter { _updateFrequency (latestTime) { const timeDiff = latestTime - this._frequencyLastTime - Object.keys(this._stats).forEach((key) => { - this._updateFrequencyFor(key, timeDiff, latestTime) - }) + if (timeDiff) { + Object.keys(this._stats).forEach((key) => { + this._updateFrequencyFor(key, timeDiff, latestTime) + }) + } this._frequencyLastTime = latestTime } diff --git a/test/bitswap-stats.js b/test/bitswap-stats.js index c6499851..f61ea766 100644 --- a/test/bitswap-stats.js +++ b/test/bitswap-stats.js @@ -216,10 +216,13 @@ describe('bitswap stats', () => { const peerStats = bs2.stat().forPeer(libp2pNodes[0].peerId) expect(peerStats).to.exist() + // trigger an update + peerStats.push('dataReceived', 1) + const stats = await pEvent(peerStats, 'update') expect(stats.blocksReceived.toNumber()).to.equal(1) - expect(stats.dataReceived.toNumber()).to.equal(48) + expect(stats.dataReceived.toNumber()).to.equal(49) expect(stats.dupBlksReceived.toNumber()).to.equal(0) expect(stats.dupDataReceived.toNumber()).to.equal(0) expect(stats.blocksSent.toNumber()).to.equal(0)