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 #359

Merged
merged 2 commits into from
Apr 17, 2019
Merged
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
33 changes: 9 additions & 24 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,16 @@ const configSchema = s({
enabled: true
}),
// DHT config
dht: s({
kBucketSize: 'number',
enabled: 'boolean?',
validators: 'object?',
selectors: 'object?',
randomWalk: optional(s({
enabled: 'boolean?',
queriesPerPeriod: 'number?',
interval: 'number?',
timeout: 'number?'
}, {
// random walk defaults
enabled: false, // disabled waiting for https://github.com/libp2p/js-libp2p-kad-dht/issues/86
queriesPerPeriod: 1,
interval: 30000,
timeout: 10000
}))
}, {
dht: s('object?', {
// DHT defaults
enabled: false,
kBucketSize: 20
kBucketSize: 20,
randomWalk: {
enabled: false, // disabled waiting for https://github.com/libp2p/js-libp2p-kad-dht/issues/86
queriesPerPeriod: 1,
interval: 300e3,
timeout: 10e3
}
}),
// Experimental config
EXPERIMENTAL: s({
Expand All @@ -77,11 +66,7 @@ const configSchema = s({
// Experimental defaults
pubsub: false
})
}, {
relay: {},
dht: {},
EXPERIMENTAL: {}
})
}, {})

const optionsSchema = s({
switch: 'object?',
Expand Down
47 changes: 39 additions & 8 deletions test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('configuration', () => {
randomWalk: {
enabled: false,
queriesPerPeriod: 1,
interval: 30000,
interval: 300000,
timeout: 10000
}
},
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('configuration', () => {
randomWalk: {
enabled: false,
queriesPerPeriod: 1,
interval: 30000,
interval: 300000,
timeout: 10000
}
},
Expand Down Expand Up @@ -242,7 +242,7 @@ describe('configuration', () => {
expect(() => validateConfig(options)).to.throw()
})

it('should add defaults, validators and selectors for dht', () => {
it('should be able to add validators and selectors for dht', () => {
const selectors = {}
const validators = {}

Expand Down Expand Up @@ -282,20 +282,51 @@ describe('configuration', () => {
enabled: false
}
},
dht: {
selectors,
validators
}
}
}
expect(validateConfig(options)).to.deep.equal(expected)
})

it('should support new properties for the dht config', () => {
const options = {
peerInfo,
modules: {
transport: [WS],
dht: DHT
},
config: {
dht: {
kBucketSize: 20,
enabled: false,
myNewDHTConfigProperty: true,
randomWalk: {
enabled: false,
queriesPerPeriod: 1,
interval: 30000,
interval: 300000,
timeout: 10000
},
selectors,
validators
}
}
}
}
expect(validateConfig(options)).to.deep.equal(expected)

const expected = {
kBucketSize: 20,
enabled: false,
myNewDHTConfigProperty: true,
randomWalk: {
enabled: false,
queriesPerPeriod: 1,
interval: 300000,
timeout: 10000
}
}

const actual = validateConfig(options).config.dht

expect(actual).to.deep.equal(expected)
})
})