From 955d19b8b3e61598f259745ac36d32bdad33e70c Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 3 Apr 2019 11:37:48 +0100 Subject: [PATCH 1/8] fix: stop IPNS asap This PR refactors the stop logic to perform stop actions in parallel for various components (where it is safe to do so). This means that libp2p gets stopped at the same time as the republisher. When libp2p stops it closes all connections meaning that the republsher is able to complete a running republish sooner. Before, we had to wait for republish to complete before stop happens (since there's no way to cancel a DHT put right now). License: MIT Signed-off-by: Alan Shaw --- src/core/components/stop.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/core/components/stop.js b/src/core/components/stop.js index 2981e66842..5f2ddc7959 100644 --- a/src/core/components/stop.js +++ b/src/core/components/stop.js @@ -1,6 +1,6 @@ 'use strict' -const series = require('async/series') +const parallel = require('async/parallel') const promisify = require('promisify-es6') module.exports = (self) => { @@ -17,30 +17,30 @@ module.exports = (self) => { return callback(new Error('Not able to stop from state: ' + self.state.state())) } - const done = (err) => { - if (err) { - self.emit('error', err) - return callback(err) - } - self.state.stopped() - self.emit('stop') - callback() - } - self.state.stop() self._blockService.unsetExchange() self._bitswap.stop() self._preload.stop() - series([ - (cb) => self._ipns.republisher.stop(cb), - (cb) => self._mfsPreload.stop(cb), - (cb) => { + parallel([ + cb => self._ipns.republisher.stop(cb), + cb => self._mfsPreload.stop(cb), + cb => { const libp2p = self.libp2p self.libp2p = null libp2p.stop(cb) - }, - (cb) => self._repo.close(cb) - ], done) + } + ], err => { + self._repo.close(closeErr => { + if (err || closeErr) { + self.emit('error', err || closeErr) + return callback(err || closeErr) + } + + self.state.stopped() + self.emit('stop') + callback() + }) + }) }) } From cc58c2bae77ef9fe51e5dcd1f142ba5a07f4bd4f Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 3 Apr 2019 15:18:18 +0100 Subject: [PATCH 2/8] fix: no bootstrap for key tests License: MIT Signed-off-by: Alan Shaw --- test/core/interface.spec.js | 13 ++++++++++++- test/http-api/interface.js | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index 21531d294e..0be4e605b5 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -79,7 +79,18 @@ describe('interface-ipfs-core tests', function () { tests.key(CommonFactory.create({ spawnOptions: { args: ['--pass ipfs-is-awesome-software'], - initOptions: { bits: 512 } + initOptions: { bits: 512 }, + config: { + Bootstrap: [], + Discovery: { + MDNS: { + Enabled: false + }, + webRTCStar: { + Enabled: false + } + } + } } })) diff --git a/test/http-api/interface.js b/test/http-api/interface.js index 3ff76c65c8..96c948e4f9 100644 --- a/test/http-api/interface.js +++ b/test/http-api/interface.js @@ -59,9 +59,22 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => { tests.key(CommonFactory.create({ spawnOptions: { args: ['--pass ipfs-is-awesome-software'], - initOptions: { bits: 512 } + initOptions: { bits: 512 }, + config: { + Bootstrap: [], + Discovery: { + MDNS: { + Enabled: false + }, + webRTCStar: { + Enabled: false + } + } + } } - })) + }), { + only: true + }) tests.miscellaneous(CommonFactory.create({ // No need to stop, because the test suite does a 'stop' test. From 45443bdf8678410ed7e749aa3c213e54190cd6dc Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 3 Apr 2019 15:19:34 +0100 Subject: [PATCH 3/8] chore: remove .only License: MIT Signed-off-by: Alan Shaw --- test/http-api/interface.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/http-api/interface.js b/test/http-api/interface.js index 96c948e4f9..3e3e798469 100644 --- a/test/http-api/interface.js +++ b/test/http-api/interface.js @@ -72,9 +72,7 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => { } } } - }), { - only: true - }) + })) tests.miscellaneous(CommonFactory.create({ // No need to stop, because the test suite does a 'stop' test. From 795ef9e2f6f1a2672ec7a5538482042f551fb41d Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 4 Apr 2019 08:58:16 +0100 Subject: [PATCH 4/8] fix: swarm.addrs test License: MIT Signed-off-by: Alan Shaw --- package.json | 2 +- test/core/interface.spec.js | 12 ++++++++++++ test/http-api/interface.js | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f7600f3248..fe94833a5b 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "execa": "^1.0.0", "form-data": "^2.3.3", "hat": "0.0.3", - "interface-ipfs-core": "~0.99.0", + "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#fix/swarm-addrs-test", "ipfsd-ctl": "~0.42.0", "libp2p-websocket-star": "~0.10.2", "ncp": "^2.0.0", diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index 0be4e605b5..8134ffc702 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -194,6 +194,18 @@ describe('interface-ipfs-core tests', function () { config = null } + config = config || { + Bootstrap: [], + Discovery: { + MDNS: { + Enabled: false + }, + webRTCStar: { + Enabled: false + } + } + } + const spawnOptions = { repoPath, config, initOptions: { bits: 512 } } ipfsFactory.spawn(spawnOptions, (err, _ipfsd) => { diff --git a/test/http-api/interface.js b/test/http-api/interface.js index 3e3e798469..c72a6529b5 100644 --- a/test/http-api/interface.js +++ b/test/http-api/interface.js @@ -130,6 +130,18 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => { config = undefined } + config = config || { + Bootstrap: [], + Discovery: { + MDNS: { + Enabled: false + }, + webRTCStar: { + Enabled: false + } + } + } + const spawnOptions = { repoPath, config, initOptions: { bits: 512 } } ipfsFactory.spawn(spawnOptions, (err, _ipfsd) => { From cab58e116559f89fd8255dace0d4a60886bfa353 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 4 Apr 2019 09:55:44 +0100 Subject: [PATCH 5/8] chore: increase preload test timeouts License: MIT Signed-off-by: Alan Shaw --- test/core/preload.spec.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/core/preload.spec.js b/test/core/preload.spec.js index 4d4bd4848f..95e905089f 100644 --- a/test/core/preload.spec.js +++ b/test/core/preload.spec.js @@ -353,9 +353,15 @@ describe('preload disabled', function () { afterEach((done) => MockPreloadNode.clearPreloadCids(done)) - after((done) => ipfs.stop(done)) + after(function (done) { + this.timeout(50 * 1000) + ipfs.stop(done) + }) - after((done) => repo.teardown(done)) + after(function (done) { + this.timeout(50 * 1000) + repo.teardown(done) + }) it('should not preload if disabled', (done) => { ipfs.add(Buffer.from(hat()), (err, res) => { From 7a5473463dad728bd50e7ec6371bb9edc3e28dba Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 4 Apr 2019 10:21:42 +0100 Subject: [PATCH 6/8] chore: remove bootstrap from prelaod disabled tests License: MIT Signed-off-by: Alan Shaw --- test/core/preload.spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/core/preload.spec.js b/test/core/preload.spec.js index 95e905089f..edb3c2153b 100644 --- a/test/core/preload.spec.js +++ b/test/core/preload.spec.js @@ -340,7 +340,8 @@ describe('preload disabled', function () { config: { Addresses: { Swarm: [] - } + }, + Bootstrap: [] }, preload: { enabled: false, From 3c63b3ae5d5d64c846130b50bbfdd4eef2301669 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 4 Apr 2019 11:52:14 +0100 Subject: [PATCH 7/8] chore: update dependencies License: MIT Signed-off-by: Alan Shaw --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fe94833a5b..4622d26644 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "execa": "^1.0.0", "form-data": "^2.3.3", "hat": "0.0.3", - "interface-ipfs-core": "github:ipfs/interface-js-ipfs-core#fix/swarm-addrs-test", + "interface-ipfs-core": "^0.99.1", "ipfsd-ctl": "~0.42.0", "libp2p-websocket-star": "~0.10.2", "ncp": "^2.0.0", @@ -130,7 +130,7 @@ "libp2p": "~0.25.0-rc.5", "libp2p-bootstrap": "~0.9.3", "libp2p-crypto": "~0.16.0", - "libp2p-kad-dht": "~0.14.11", + "libp2p-kad-dht": "~0.14.12", "libp2p-keychain": "~0.4.1", "libp2p-mdns": "~0.12.0", "libp2p-mplex": "~0.8.4", From c8ecea7aebec5166fd4a132c5ce4911c99d8f6db Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 4 Apr 2019 11:58:08 +0100 Subject: [PATCH 8/8] chore: appease linter License: MIT Signed-off-by: Alan Shaw --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4622d26644..d18da53b4a 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "execa": "^1.0.0", "form-data": "^2.3.3", "hat": "0.0.3", - "interface-ipfs-core": "^0.99.1", + "interface-ipfs-core": "~0.99.1", "ipfsd-ctl": "~0.42.0", "libp2p-websocket-star": "~0.10.2", "ncp": "^2.0.0",