From ea14bbc942eb53b1a5bb2778e953a8ea166ae901 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 15 Apr 2019 11:39:01 +0100 Subject: [PATCH 1/6] refactor: enable DHT by default License: MIT Signed-off-by: Alan Shaw --- src/core/components/libp2p.js | 5 ++--- src/core/runtime/config-browser.js | 4 ++-- src/core/runtime/libp2p-browser.js | 2 +- src/core/runtime/libp2p-nodejs.js | 4 ++-- test/cli/dht.js | 3 +-- test/core/dht.spec.js | 3 +-- test/core/interface.spec.js | 10 +++++++--- test/core/name.js | 3 +-- test/core/ping.spec.js | 3 +-- test/http-api/inject/dht.js | 3 +-- test/http-api/interface.js | 10 +++++++--- 11 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index 3ca4b525f3..179abfb67b 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -66,10 +66,9 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) { }, dht: { kBucketSize: get(options, 'dht.kBucketSize', 20), - // enabled: !get(options, 'offline', false), // disable if offline, on by default - enabled: false, + enabled: !get(options, 'offline', false), // disable if offline, on by default randomWalk: { - enabled: false // disabled waiting for https://github.com/libp2p/js-libp2p-kad-dht/issues/86 + enabled: true }, validators: { ipns: ipnsUtils.validator diff --git a/src/core/runtime/config-browser.js b/src/core/runtime/config-browser.js index 1ddbc0d717..c6282c01fb 100644 --- a/src/core/runtime/config-browser.js +++ b/src/core/runtime/config-browser.js @@ -28,8 +28,8 @@ module.exports = () => ({ ], Swarm: { ConnMgr: { - LowWater: 200, - HighWater: 500 + LowWater: 20, + HighWater: 50 } } }) diff --git a/src/core/runtime/libp2p-browser.js b/src/core/runtime/libp2p-browser.js index f05f87cebc..3d2f389532 100644 --- a/src/core/runtime/libp2p-browser.js +++ b/src/core/runtime/libp2p-browser.js @@ -62,7 +62,7 @@ class Node extends libp2p { } }, dht: { - enabled: false + enabled: true }, EXPERIMENTAL: { pubsub: false diff --git a/src/core/runtime/libp2p-nodejs.js b/src/core/runtime/libp2p-nodejs.js index eb281a034a..f8612eaad0 100644 --- a/src/core/runtime/libp2p-nodejs.js +++ b/src/core/runtime/libp2p-nodejs.js @@ -62,9 +62,9 @@ class Node extends libp2p { }, dht: { kBucketSize: 20, - enabled: false, + enabled: true, randomWalk: { - enabled: false + enabled: true } }, EXPERIMENTAL: { diff --git a/test/cli/dht.js b/test/cli/dht.js index f772ebc6af..9a1e9923e7 100644 --- a/test/cli/dht.js +++ b/test/cli/dht.js @@ -31,8 +31,7 @@ const daemonOpts = { initOptions: { bits: 512 } } -// TODO: unskip when DHT is enabled in 0.36 -describe.skip('dht', () => { +describe('dht', () => { let nodes = [] let ipfsA let ipfsB diff --git a/test/core/dht.spec.js b/test/core/dht.spec.js index ba437a28bc..b1a3207429 100644 --- a/test/core/dht.spec.js +++ b/test/core/dht.spec.js @@ -12,8 +12,7 @@ const isNode = require('detect-node') const IPFSFactory = require('ipfsd-ctl') const IPFS = require('../../src/core') -// TODO: unskip when DHT is enabled in 0.36 -describe.skip('dht', () => { +describe('dht', () => { describe('enabled', () => { let ipfsd, ipfs diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index df572c19e2..028a691617 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -57,9 +57,13 @@ describe('interface-ipfs-core tests', function () { initOptions: { bits: 512 } } }), { - skip: { - reason: 'TODO: unskip when DHT is enabled in 0.36' - } + skip: isNode ? [ + // dht.get + { + name: 'should get a value after it was put on another node', + reason: 'Needs https://github.com/ipfs/interface-ipfs-core/pull/383' + } + ] : true }) tests.filesRegular(defaultCommonFactory, { diff --git a/test/core/name.js b/test/core/name.js index 99b8257251..1ad7bc3b7b 100644 --- a/test/core/name.js +++ b/test/core/name.js @@ -196,8 +196,7 @@ describe('name', function () { }) }) - // TODO: unskip when DHT is enabled in 0.36 - describe.skip('work with dht', () => { + describe('work with dht', () => { let nodes let nodeA let nodeB diff --git a/test/core/ping.spec.js b/test/core/ping.spec.js index 6d04792013..149f98246c 100644 --- a/test/core/ping.spec.js +++ b/test/core/ping.spec.js @@ -194,8 +194,7 @@ describe('ping', function () { }) }) - // TODO: unskip when DHT enabled in 0.36 - describe.skip('DHT enabled', function () { + describe('DHT enabled', function () { // Our bootstrap process will run 3 IPFS daemons where // A ----> B ----> C // Allowing us to test the ping command using the DHT peer routing diff --git a/test/http-api/inject/dht.js b/test/http-api/inject/dht.js index c57deaecd0..455a4bb8b1 100644 --- a/test/http-api/inject/dht.js +++ b/test/http-api/inject/dht.js @@ -8,8 +8,7 @@ const expect = chai.expect chai.use(dirtyChai) module.exports = (http) => { - // TODO: unskip when DHT is enabled in 0.36 - describe.skip('/dht', () => { + describe('/dht', () => { let api before(() => { diff --git a/test/http-api/interface.js b/test/http-api/interface.js index 43c6ff6a12..2f10f76c67 100644 --- a/test/http-api/interface.js +++ b/test/http-api/interface.js @@ -49,9 +49,13 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => { } } }), { - skip: { - reason: 'TODO: unskip when DHT is enabled in 0.36' - } + skip: [ + // dht.get + { + name: 'should get a value after it was put on another node', + reason: 'Needs https://github.com/ipfs/interface-ipfs-core/pull/383' + } + ] }) tests.filesRegular(defaultCommonFactory) From 656c37553aa6837265d91293fd4f43093baf4b67 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 15 Apr 2019 19:13:28 +0100 Subject: [PATCH 2/6] fix: tests License: MIT Signed-off-by: Alan Shaw --- src/core/ipns/routing/config.js | 2 +- test/core/name.js | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/core/ipns/routing/config.js b/src/core/ipns/routing/config.js index 7faa469258..2407c0d3cb 100644 --- a/src/core/ipns/routing/config.js +++ b/src/core/ipns/routing/config.js @@ -22,7 +22,7 @@ module.exports = (ipfs) => { } // DHT should not be added as routing if we are offline or it is disabled - if (get(ipfs._options, 'offline') || !get(ipfs._options, 'libp2p.dht.enabled', false)) { + if (get(ipfs._options, 'offline') || !get(ipfs._options, 'libp2p.dht.enabled', true)) { const offlineDatastore = new OfflineDatastore(ipfs._repo) ipnsStores.push(offlineDatastore) } else { diff --git a/test/core/name.js b/test/core/name.js index 1ad7bc3b7b..74d8b492b0 100644 --- a/test/core/name.js +++ b/test/core/name.js @@ -537,8 +537,16 @@ describe('name', function () { }) describe('ipns.routing', function () { - it('should use only the offline datastore by default', function (done) { - const ipfs = {} + it('should use offline datastore if DHT is disabled', function (done) { + const ipfs = { + _options: { + libp2p: { + dht: { + enabled: false + } + } + } + } const config = ipnsRouting(ipfs) expect(config.stores).to.have.lengthOf(1) @@ -562,8 +570,11 @@ describe('name', function () { }) it('should use the pubsub datastore if enabled', function (done) { + const dht = {} + const ipfs = { libp2p: { + dht, pubsub: {} }, _peerInfo: { @@ -581,8 +592,8 @@ describe('name', function () { const config = ipnsRouting(ipfs) expect(config.stores).to.have.lengthOf(2) - expect(config.stores[0] instanceof PubsubDatastore).to.eql(true) - expect(config.stores[1] instanceof OfflineDatastore).to.eql(true) + expect(config.stores.some(s => s instanceof PubsubDatastore)).to.eql(true) + expect(config.stores).to.include(dht) done() }) @@ -616,5 +627,16 @@ describe('name', function () { done() }) + + it('should use the dht by default', function (done) { + const dht = {} + const ipfs = { libp2p: { dht } } + const config = ipnsRouting(ipfs) + + expect(config.stores).to.have.lengthOf(1) + expect(config.stores[0]).to.eql(dht) + + done() + }) }) }) From 82175d42c6336ec35ee35a036c0d3016fdc2d6fb Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 31 May 2019 14:57:19 +0100 Subject: [PATCH 3/6] chore: unskip tests License: MIT Signed-off-by: Alan Shaw --- test/core/interface.spec.js | 8 +------- test/http-api/interface.js | 10 +--------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/test/core/interface.spec.js b/test/core/interface.spec.js index 028a691617..c323b1be31 100644 --- a/test/core/interface.spec.js +++ b/test/core/interface.spec.js @@ -57,13 +57,7 @@ describe('interface-ipfs-core tests', function () { initOptions: { bits: 512 } } }), { - skip: isNode ? [ - // dht.get - { - name: 'should get a value after it was put on another node', - reason: 'Needs https://github.com/ipfs/interface-ipfs-core/pull/383' - } - ] : true + skip: !isNode }) tests.filesRegular(defaultCommonFactory, { diff --git a/test/http-api/interface.js b/test/http-api/interface.js index 2f10f76c67..b5fe189bb8 100644 --- a/test/http-api/interface.js +++ b/test/http-api/interface.js @@ -48,15 +48,7 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => { } } } - }), { - skip: [ - // dht.get - { - name: 'should get a value after it was put on another node', - reason: 'Needs https://github.com/ipfs/interface-ipfs-core/pull/383' - } - ] - }) + })) tests.filesRegular(defaultCommonFactory) From 75c3bc49ad130eec1dec63a45719a47837a1878d Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 31 May 2019 14:58:17 +0100 Subject: [PATCH 4/6] chore: update interface-ipfs-core dep 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 bd10e42d64..4743bdea5a 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "execa": "^1.0.0", "form-data": "^2.3.3", "hat": "0.0.3", - "interface-ipfs-core": "~0.104.0", + "interface-ipfs-core": "~0.104.1", "ipfsd-ctl": "~0.42.0", "libp2p-websocket-star": "~0.10.2", "ncp": "^2.0.0", From 7ecdf08e46ed6ac51dd9734ae1320e36173e46a7 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 31 May 2019 16:59:01 +0100 Subject: [PATCH 5/6] chore: update interface-ipfs-core 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 4743bdea5a..7c797de833 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "execa": "^1.0.0", "form-data": "^2.3.3", "hat": "0.0.3", - "interface-ipfs-core": "~0.104.1", + "interface-ipfs-core": "~0.104.2", "ipfsd-ctl": "~0.42.0", "libp2p-websocket-star": "~0.10.2", "ncp": "^2.0.0", From 7e242ece1642fb20efbfb5d5031baa6e73ef8555 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Mon, 29 Apr 2019 12:31:08 +0200 Subject: [PATCH 6/6] fix: update dht config for discovery and performance --- src/core/runtime/libp2p-browser.js | 10 +++++++++- src/core/runtime/libp2p-nodejs.js | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/runtime/libp2p-browser.js b/src/core/runtime/libp2p-browser.js index 3d2f389532..3d2def0df9 100644 --- a/src/core/runtime/libp2p-browser.js +++ b/src/core/runtime/libp2p-browser.js @@ -62,7 +62,15 @@ class Node extends libp2p { } }, dht: { - enabled: true + enabled: true, + concurrency: 3, + kBucketSize: 20, + randomWalk: { + enabled: false, + interval: 600e3, // 10minutes + delay: 10e3, + timeout: 30e3 + } }, EXPERIMENTAL: { pubsub: false diff --git a/src/core/runtime/libp2p-nodejs.js b/src/core/runtime/libp2p-nodejs.js index f8612eaad0..26ee66cb91 100644 --- a/src/core/runtime/libp2p-nodejs.js +++ b/src/core/runtime/libp2p-nodejs.js @@ -63,8 +63,12 @@ class Node extends libp2p { dht: { kBucketSize: 20, enabled: true, + concurrency: 4, randomWalk: { - enabled: true + enabled: true, + interval: 600e3, + delay: 5e3, + timeout: 20e3 } }, EXPERIMENTAL: {