From c4cab007af5e7ec170615941230c18c893eece8a Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 29 Jan 2019 17:57:09 +0000 Subject: [PATCH] feat: enable dht by default (#313) BREAKING CHANGE: dht experimental flag was removed and a dht.enabled property was added to the config --- README.md | 4 ++-- src/config.js | 4 ++-- src/index.js | 2 +- test/config.spec.js | 20 ++++++++++---------- test/content-routing.node.js | 22 +++++++++++----------- test/create.spec.js | 6 +++--- test/dht.node.js | 11 +++-------- test/fsm.spec.js | 8 +++++++- test/peer-routing.node.js | 26 +++++++++++++------------- test/pnet.node.js | 4 +++- test/stats.js | 3 --- test/utils/bundle-browser.js | 4 ++-- test/utils/bundle-nodejs.js | 4 ++-- 13 files changed, 59 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 30b5f8192b..2d07558882 100644 --- a/README.md +++ b/README.md @@ -175,12 +175,12 @@ class Node extends libp2p { }, dht: { kBucketSize: 20, + enabled: true, enabledDiscovery: true // Allows to disable discovery (enabled by default) }, // Enable/Disable Experimental features EXPERIMENTAL: { // Experimental features ("behind a flag") - pubsub: false, - dht: false + pubsub: false } } } diff --git a/src/config.js b/src/config.js index c295dbb6a2..9d44e14b1a 100644 --- a/src/config.js +++ b/src/config.js @@ -33,12 +33,12 @@ const OptionsSchema = Joi.object({ }).default(), dht: Joi.object().keys({ kBucketSize: Joi.number().default(20), + enabled: Joi.boolean().default(true), enabledDiscovery: Joi.boolean().default(true), validators: Joi.object().allow(null), selectors: Joi.object().allow(null) }).default(), EXPERIMENTAL: Joi.object().keys({ - dht: Joi.boolean().default(false), pubsub: Joi.boolean().default(false) }).default() }).default() @@ -48,7 +48,7 @@ module.exports.validate = (options) => { options = Joi.attempt(options, OptionsSchema) // Ensure dht is correct - if (options.config.EXPERIMENTAL.dht) { + if (options.config.dht.enabled) { Joi.assert(options.modules.dht, ModuleSchema.required()) } diff --git a/src/index.js b/src/index.js index 047a190302..47bfdbcd38 100644 --- a/src/index.js +++ b/src/index.js @@ -102,7 +102,7 @@ class Node extends EventEmitter { } // dht provided components (peerRouting, contentRouting, dht) - if (this._config.EXPERIMENTAL.dht) { + if (this._config.dht.enabled) { const DHT = this._modules.dht const enabledDiscovery = this._config.dht.enabledDiscovery !== false diff --git a/test/config.spec.js b/test/config.spec.js index 67f164928a..3864673b6a 100644 --- a/test/config.spec.js +++ b/test/config.spec.js @@ -63,7 +63,8 @@ describe('configuration', () => { peerInfo, modules: { transport: [ WS ], - peerDiscovery: [ Bootstrap ] + peerDiscovery: [ Bootstrap ], + dht: DHT }, config: { peerDiscovery: { @@ -79,7 +80,8 @@ describe('configuration', () => { peerInfo, modules: { transport: [ WS ], - peerDiscovery: [ Bootstrap ] + peerDiscovery: [ Bootstrap ], + dht: DHT }, config: { peerDiscovery: { @@ -89,11 +91,11 @@ describe('configuration', () => { } }, EXPERIMENTAL: { - pubsub: false, - dht: false + pubsub: false }, dht: { kBucketSize: 20, + enabled: true, enabledDiscovery: true }, relay: { @@ -115,7 +117,8 @@ describe('configuration', () => { transport: [ WS ], peerDiscovery: [ Bootstrap ], peerRouting: [ peerRouter ], - contentRouting: [ contentRouter ] + contentRouting: [ contentRouter ], + dht: DHT }, config: { peerDiscovery: { @@ -160,9 +163,6 @@ describe('configuration', () => { dht: DHT }, config: { - EXPERIMENTAL: { - dht: true - }, dht: { selectors, validators @@ -177,14 +177,14 @@ describe('configuration', () => { }, config: { EXPERIMENTAL: { - pubsub: false, - dht: true + pubsub: false }, relay: { enabled: true }, dht: { kBucketSize: 20, + enabled: true, enabledDiscovery: true, selectors, validators diff --git a/test/content-routing.node.js b/test/content-routing.node.js index 4bfa58e19f..d015690c31 100644 --- a/test/content-routing.node.js +++ b/test/content-routing.node.js @@ -30,13 +30,7 @@ describe('.contentRouting', () => { before(function (done) { this.timeout(5 * 1000) const tasks = _times(5, () => (cb) => { - createNode('/ip4/0.0.0.0/tcp/0', { - config: { - EXPERIMENTAL: { - dht: true - } - } - }, (err, node) => { + createNode('/ip4/0.0.0.0/tcp/0', (err, node) => { expect(err).to.not.exist() node.start((err) => cb(err, node)) }) @@ -159,6 +153,9 @@ describe('.contentRouting', () => { contentRouting: [ delegate ] }, config: { + dht: { + enabled: false + }, relay: { enabled: true, hop: { @@ -320,9 +317,6 @@ describe('.contentRouting', () => { enabled: true, active: false } - }, - EXPERIMENTAL: { - dht: true } } }) @@ -387,7 +381,13 @@ describe('.contentRouting', () => { describe('no routers', () => { let nodeA before((done) => { - createNode('/ip4/0.0.0.0/tcp/0', (err, node) => { + createNode('/ip4/0.0.0.0/tcp/0', { + config: { + dht: { + enabled: false + } + } + }, (err, node) => { expect(err).to.not.exist() nodeA = node done() diff --git a/test/create.spec.js b/test/create.spec.js index e832771fe5..51fcaf1394 100644 --- a/test/create.spec.js +++ b/test/create.spec.js @@ -13,8 +13,10 @@ describe('libp2p creation', () => { createNode([], { config: { EXPERIMENTAL: { - dht: true, pubsub: true + }, + dht: { + enabled: true } } }, (err, node) => { @@ -69,13 +71,11 @@ describe('libp2p creation', () => { createNode([], { config: { EXPERIMENTAL: { - dht: false, pubsub: false } } }, (err, node) => { expect(err).to.not.exist() - expect(node._dht).to.not.exist() expect(node._floodSub).to.not.exist() done() }) diff --git a/test/dht.node.js b/test/dht.node.js index 3dfb4036b7..41e370a926 100644 --- a/test/dht.node.js +++ b/test/dht.node.js @@ -17,12 +17,7 @@ describe('.dht', () => { before(function (done) { createNode('/ip4/0.0.0.0/tcp/0', { - datastore, - config: { - EXPERIMENTAL: { - dht: true - } - } + datastore }, (err, node) => { expect(err).to.not.exist() nodeA = node @@ -124,8 +119,8 @@ describe('.dht', () => { before(function (done) { createNode('/ip4/0.0.0.0/tcp/0', { config: { - EXPERIMENTAL: { - dht: false + dht: { + enabled: false } } }, (err, node) => { diff --git a/test/fsm.spec.js b/test/fsm.spec.js index 9279c1313d..131dafad46 100644 --- a/test/fsm.spec.js +++ b/test/fsm.spec.js @@ -13,7 +13,13 @@ describe('libp2p state machine (fsm)', () => { describe('starting and stopping', () => { let node beforeEach((done) => { - createNode([], (err, _node) => { + createNode([], { + config: { + dht: { + enabled: false + } + } + }, (err, _node) => { node = _node done(err) }) diff --git a/test/peer-routing.node.js b/test/peer-routing.node.js index 37319d86d0..25075d5fff 100644 --- a/test/peer-routing.node.js +++ b/test/peer-routing.node.js @@ -24,13 +24,7 @@ describe('.peerRouting', () => { before('create the outer ring of connections', (done) => { const tasks = _times(5, () => (cb) => { - createNode('/ip4/0.0.0.0/tcp/0', { - config: { - EXPERIMENTAL: { - dht: true - } - } - }, (err, node) => { + createNode('/ip4/0.0.0.0/tcp/0', (err, node) => { expect(err).to.not.exist() node.start((err) => cb(err, node)) }) @@ -112,6 +106,11 @@ describe('.peerRouting', () => { createNode('/ip4/0.0.0.0/tcp/0', { modules: { peerRouting: [ delegate ] + }, + config: { + dht: { + enabled: false + } } }, (err, node) => { expect(err).to.not.exist() @@ -213,11 +212,6 @@ describe('.peerRouting', () => { createNode('/ip4/0.0.0.0/tcp/0', { modules: { peerRouting: [ delegate ] - }, - config: { - EXPERIMENTAL: { - dht: true - } } }, (err, node) => { expect(err).to.not.exist() @@ -270,7 +264,13 @@ describe('.peerRouting', () => { describe('no routers', () => { let nodeA before((done) => { - createNode('/ip4/0.0.0.0/tcp/0', (err, node) => { + createNode('/ip4/0.0.0.0/tcp/0', { + config: { + dht: { + enabled: false + } + } + }, (err, node) => { expect(err).to.not.exist() nodeA = node done() diff --git a/test/pnet.node.js b/test/pnet.node.js index 641dde96f9..0d4b3c122a 100644 --- a/test/pnet.node.js +++ b/test/pnet.node.js @@ -9,6 +9,7 @@ const PeerId = require('peer-id') const waterfall = require('async/waterfall') const WS = require('libp2p-websockets') const defaultsDeep = require('@nodeutils/defaults-deep') +const DHT = require('libp2p-kad-dht') const Libp2p = require('../src') @@ -23,7 +24,8 @@ describe('private network', () => { config = { peerInfo, modules: { - transport: [ WS ] + transport: [ WS ], + dht: DHT } } cb() diff --git a/test/stats.js b/test/stats.js index ac3628ce14..08e05b4fdc 100644 --- a/test/stats.js +++ b/test/stats.js @@ -15,9 +15,6 @@ describe('libp2p', () => { mdns: { enabled: false } - }, - EXPERIMENTAL: { - dht: true } } }, (err, node) => { diff --git a/test/utils/bundle-browser.js b/test/utils/bundle-browser.js index 159b6f80dd..2ca716a083 100644 --- a/test/utils/bundle-browser.js +++ b/test/utils/bundle-browser.js @@ -80,10 +80,10 @@ class Node extends libp2p { }, dht: { kBucketSize: 20, - enabledDiscovery: true + enabledDiscovery: true, + enabled: false }, EXPERIMENTAL: { - dht: false, pubsub: false } } diff --git a/test/utils/bundle-nodejs.js b/test/utils/bundle-nodejs.js index b018007bfd..d59987cec6 100644 --- a/test/utils/bundle-nodejs.js +++ b/test/utils/bundle-nodejs.js @@ -73,10 +73,10 @@ class Node extends libp2p { }, dht: { kBucketSize: 20, - enabledDiscovery: true + enabledDiscovery: true, + enabled: true }, EXPERIMENTAL: { - dht: false, pubsub: false } }