From 0f0eab1479978d68b38b7bec1f750c12961650b4 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 23 Apr 2020 20:13:51 +0100 Subject: [PATCH 1/4] fix: really remove node globals --- package.json | 6 ++++-- src/decision-engine/index.js | 2 +- test/utils/make-block.js | 4 ++-- test/utils/mocks.js | 8 ++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 048d5e95..47dbffcd 100644 --- a/package.json +++ b/package.json @@ -46,10 +46,13 @@ "aegir": "^21.9.0", "async-iterator-all": "^1.0.0", "benchmark": "^2.1.4", + "buffer": "^5.6.0", "chai": "^4.2.0", "delay": "^4.3.0", "dirty-chai": "^2.0.1", "ipfs-repo": "^2.0.0", + "ipfs-utils": "^2.2.0", + "iso-random-stream": "^1.1.1", "libp2p": "^0.27.0", "libp2p-kad-dht": "^0.18.3", "libp2p-mplex": "^0.9.2", @@ -68,7 +71,6 @@ "peer-info": "^0.17.0", "promisify-es6": "^1.0.3", "rimraf": "^3.0.0", - "buffer": "^5.6.0", "stats-lite": "^2.2.0", "uuid": "^3.3.2" }, @@ -85,7 +87,7 @@ "multihashing-async": "^0.8.0", "protons": "^1.0.1", "streaming-iterables": "^4.1.1", - "varint-decoder": "~0.1.1" + "varint-decoder": "hugomrdias/varint-decoder#fix/is-buffer" }, "pre-push": [ "lint", diff --git a/src/decision-engine/index.js b/src/decision-engine/index.js index 7364bb15..2211a6eb 100644 --- a/src/decision-engine/index.js +++ b/src/decision-engine/index.js @@ -50,7 +50,7 @@ class DecisionEngine { } _scheduleProcessTasks () { - setImmediate(() => this._processTasks()) + this._processTasks() } // Pull tasks off the request queue and send a message to the corresponding diff --git a/test/utils/make-block.js b/test/utils/make-block.js index 50d59713..bb3bb94b 100644 --- a/test/utils/make-block.js +++ b/test/utils/make-block.js @@ -3,7 +3,7 @@ const multihashing = require('multihashing-async') const CID = require('cids') const Block = require('ipld-block') -const crypto = require('crypto') +const randomBytes = require('iso-random-stream/src/random') const range = require('lodash.range') const { Buffer } = require('buffer') const uuid = require('uuid/v4') @@ -11,7 +11,7 @@ const uuid = require('uuid/v4') module.exports = async (count, size) => { const blocks = await Promise.all( range(count || 1).map(async () => { - const data = size ? crypto.randomBytes(size) : Buffer.from(`hello world ${uuid()}`) + const data = size ? randomBytes(size) : Buffer.from(`hello world ${uuid()}`) const hash = await multihashing(data, 'sha2-256') return new Block(data, new CID(hash)) }) diff --git a/test/utils/mocks.js b/test/utils/mocks.js index 36d71ccf..2179b371 100644 --- a/test/utils/mocks.js +++ b/test/utils/mocks.js @@ -5,7 +5,7 @@ const PeerId = require('peer-id') const PeerInfo = require('peer-info') const PeerStore = require('libp2p/src/peer-store') const Node = require('./create-libp2p-node').bundle -const os = require('os') +const tmpdir = require('ipfs-utils/src/temp-dir') const Repo = require('ipfs-repo') const EventEmitter = require('events') @@ -59,14 +59,14 @@ exports.mockNetwork = (calls, done, onMsg) => { messages, connects, connectTo (p) { - setImmediate(() => { + setTimeout(() => { connects.push(p) }) }, sendMessage (p, msg) { messages.push([p, msg]) - setImmediate(() => { + setTimeout(() => { finish([p, msg]) }) @@ -182,7 +182,7 @@ exports.genBitswapNetwork = async (n, enableDHT = false) => { }) // create the repos - const tmpDir = os.tmpdir() + const tmpDir = tmpdir() netArray.forEach((net, i) => { const repoPath = tmpDir + '/' + net.peerInfo.id.toB58String() net.repo = new Repo(repoPath) From 0a97eaedde8de8049d77b3bb92bd9474036990cc Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 23 Apr 2020 20:26:54 +0100 Subject: [PATCH 2/4] fix: fix scheduleProcessTasks --- src/decision-engine/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/decision-engine/index.js b/src/decision-engine/index.js index 2211a6eb..90565a8a 100644 --- a/src/decision-engine/index.js +++ b/src/decision-engine/index.js @@ -50,7 +50,9 @@ class DecisionEngine { } _scheduleProcessTasks () { - this._processTasks() + setTimeout(() => { + this._processTasks() + }) } // Pull tasks off the request queue and send a message to the corresponding From d7ba1fc9a5967d3c9d6ccfabdc9eda51875c0309 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Fri, 24 Apr 2020 15:11:35 +0100 Subject: [PATCH 3/4] fix: bump varint --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47dbffcd..ce8aaa78 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "multihashing-async": "^0.8.0", "protons": "^1.0.1", "streaming-iterables": "^4.1.1", - "varint-decoder": "hugomrdias/varint-decoder#fix/is-buffer" + "varint-decoder": "daviddias/varint-decoder#master" }, "pre-push": [ "lint", From 64e57d16a7d48f00c9237b4feeae9b146940cfb0 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Fri, 24 Apr 2020 15:39:45 +0100 Subject: [PATCH 4/4] fix: bump varint --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ce8aaa78..dee15816 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "multihashing-async": "^0.8.0", "protons": "^1.0.1", "streaming-iterables": "^4.1.1", - "varint-decoder": "daviddias/varint-decoder#master" + "varint-decoder": "^0.4.0" }, "pre-push": [ "lint",