Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/dht config default #289

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const OptionsSchema = Joi.object({
})
}).default(),
dht: Joi.object().keys({
kBucketSize: Joi.number().allow(null),
kBucketSize: Joi.number().default(20),
enabledDiscovery: Joi.boolean().default(true)
}),
}).default(),
EXPERIMENTAL: Joi.object().keys({
dht: Joi.boolean().default(false),
pubsub: Joi.boolean().default(false)
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 {
const enabledDiscovery = this._config.dht.enabledDiscovery !== false

this._dht = new DHT(this._switch, {
kBucketSize: this._config.dht.kBucketSize || 20,
kBucketSize: this._config.dht.kBucketSize,
enabledDiscovery,
datastore: this.datastore
})
Expand Down
43 changes: 43 additions & 0 deletions test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const WS = require('libp2p-websockets')
const Bootstrap = require('libp2p-bootstrap')
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
const DHT = require('libp2p-kad-dht')

const validateConfig = require('../src/config').validate

Expand Down Expand Up @@ -93,6 +94,10 @@ describe('configuration', () => {
},
relay: {
enabled: true
},
dht: {
enabledDiscovery: true,
kBucketSize: 20
}
}
}
Expand Down Expand Up @@ -143,4 +148,42 @@ describe('configuration', () => {

expect(() => validateConfig(options)).to.throw()
})

it('should add defaults for dht', () => {
const options = {
peerInfo,
modules: {
transport: [ WS ],
dht: DHT
},
config: {
EXPERIMENTAL: {
dht: true
}
}
}

const expected = {
peerInfo,
modules: {
transport: [ WS ],
dht: DHT
},
config: {
EXPERIMENTAL: {
pubsub: false,
dht: true
},
relay: {
enabled: true
},
dht: {
kBucketSize: 20,
enabledDiscovery: true
}
}
}

expect(validateConfig(options)).to.deep.equal(expected)
})
})
4 changes: 2 additions & 2 deletions test/transports.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ describe('transports', () => {
cb()
}),
(cb) => {
const wstar = new WRTCStar({wrtc: wrtc})
const wstar = new WRTCStar({ wrtc: wrtc })

createNode([
'/ip4/0.0.0.0/tcp/0',
Expand Down Expand Up @@ -474,7 +474,7 @@ describe('transports', () => {
}),

(cb) => {
const wstar = new WRTCStar({wrtc: wrtc})
const wstar = new WRTCStar({ wrtc: wrtc })

createNode([
'/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'
Expand Down