Skip to content

Commit

Permalink
feat: enable dht by default (#313)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: dht experimental flag was removed and a dht.enabled property was added to the config
  • Loading branch information
vasco-santos authored and jacobheun committed Jan 29, 2019
1 parent ebaab3e commit c4cab00
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 59 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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())
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 10 additions & 10 deletions test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ describe('configuration', () => {
peerInfo,
modules: {
transport: [ WS ],
peerDiscovery: [ Bootstrap ]
peerDiscovery: [ Bootstrap ],
dht: DHT
},
config: {
peerDiscovery: {
Expand All @@ -79,7 +80,8 @@ describe('configuration', () => {
peerInfo,
modules: {
transport: [ WS ],
peerDiscovery: [ Bootstrap ]
peerDiscovery: [ Bootstrap ],
dht: DHT
},
config: {
peerDiscovery: {
Expand All @@ -89,11 +91,11 @@ describe('configuration', () => {
}
},
EXPERIMENTAL: {
pubsub: false,
dht: false
pubsub: false
},
dht: {
kBucketSize: 20,
enabled: true,
enabledDiscovery: true
},
relay: {
Expand All @@ -115,7 +117,8 @@ describe('configuration', () => {
transport: [ WS ],
peerDiscovery: [ Bootstrap ],
peerRouting: [ peerRouter ],
contentRouting: [ contentRouter ]
contentRouting: [ contentRouter ],
dht: DHT
},
config: {
peerDiscovery: {
Expand Down Expand Up @@ -160,9 +163,6 @@ describe('configuration', () => {
dht: DHT
},
config: {
EXPERIMENTAL: {
dht: true
},
dht: {
selectors,
validators
Expand All @@ -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
Expand Down
22 changes: 11 additions & 11 deletions test/content-routing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down Expand Up @@ -159,6 +153,9 @@ describe('.contentRouting', () => {
contentRouting: [ delegate ]
},
config: {
dht: {
enabled: false
},
relay: {
enabled: true,
hop: {
Expand Down Expand Up @@ -320,9 +317,6 @@ describe('.contentRouting', () => {
enabled: true,
active: false
}
},
EXPERIMENTAL: {
dht: true
}
}
})
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions test/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ describe('libp2p creation', () => {
createNode([], {
config: {
EXPERIMENTAL: {
dht: true,
pubsub: true
},
dht: {
enabled: true
}
}
}, (err, node) => {
Expand Down Expand Up @@ -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()
})
Expand Down
11 changes: 3 additions & 8 deletions test/dht.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down
8 changes: 7 additions & 1 deletion test/fsm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
26 changes: 13 additions & 13 deletions test/peer-routing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion test/pnet.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -23,7 +24,8 @@ describe('private network', () => {
config = {
peerInfo,
modules: {
transport: [ WS ]
transport: [ WS ],
dht: DHT
}
}
cb()
Expand Down
3 changes: 0 additions & 3 deletions test/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ describe('libp2p', () => {
mdns: {
enabled: false
}
},
EXPERIMENTAL: {
dht: true
}
}
}, (err, node) => {
Expand Down
4 changes: 2 additions & 2 deletions test/utils/bundle-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ class Node extends libp2p {
},
dht: {
kBucketSize: 20,
enabledDiscovery: true
enabledDiscovery: true,
enabled: false
},
EXPERIMENTAL: {
dht: false,
pubsub: false
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/utils/bundle-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class Node extends libp2p {
},
dht: {
kBucketSize: 20,
enabledDiscovery: true
enabledDiscovery: true,
enabled: true
},
EXPERIMENTAL: {
dht: false,
pubsub: false
}
}
Expand Down

0 comments on commit c4cab00

Please sign in to comment.