mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 18:42:15 +00:00
fix: dht config (#359)
This commit is contained in:
parent
51cc993876
commit
f3801f0e6c
@ -48,27 +48,16 @@ const configSchema = s({
|
|||||||
enabled: true
|
enabled: true
|
||||||
}),
|
}),
|
||||||
// DHT config
|
// DHT config
|
||||||
dht: s({
|
dht: s('object?', {
|
||||||
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 defaults
|
// DHT defaults
|
||||||
enabled: false,
|
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 config
|
||||||
EXPERIMENTAL: s({
|
EXPERIMENTAL: s({
|
||||||
@ -77,11 +66,7 @@ const configSchema = s({
|
|||||||
// Experimental defaults
|
// Experimental defaults
|
||||||
pubsub: false
|
pubsub: false
|
||||||
})
|
})
|
||||||
}, {
|
}, {})
|
||||||
relay: {},
|
|
||||||
dht: {},
|
|
||||||
EXPERIMENTAL: {}
|
|
||||||
})
|
|
||||||
|
|
||||||
const optionsSchema = s({
|
const optionsSchema = s({
|
||||||
switch: 'object?',
|
switch: 'object?',
|
||||||
|
@ -91,7 +91,7 @@ describe('configuration', () => {
|
|||||||
randomWalk: {
|
randomWalk: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
queriesPerPeriod: 1,
|
queriesPerPeriod: 1,
|
||||||
interval: 30000,
|
interval: 300000,
|
||||||
timeout: 10000
|
timeout: 10000
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -153,7 +153,7 @@ describe('configuration', () => {
|
|||||||
randomWalk: {
|
randomWalk: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
queriesPerPeriod: 1,
|
queriesPerPeriod: 1,
|
||||||
interval: 30000,
|
interval: 300000,
|
||||||
timeout: 10000
|
timeout: 10000
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -242,7 +242,7 @@ describe('configuration', () => {
|
|||||||
expect(() => validateConfig(options)).to.throw()
|
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 selectors = {}
|
||||||
const validators = {}
|
const validators = {}
|
||||||
|
|
||||||
@ -283,14 +283,6 @@ describe('configuration', () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
dht: {
|
dht: {
|
||||||
kBucketSize: 20,
|
|
||||||
enabled: false,
|
|
||||||
randomWalk: {
|
|
||||||
enabled: false,
|
|
||||||
queriesPerPeriod: 1,
|
|
||||||
interval: 30000,
|
|
||||||
timeout: 10000
|
|
||||||
},
|
|
||||||
selectors,
|
selectors,
|
||||||
validators
|
validators
|
||||||
}
|
}
|
||||||
@ -298,4 +290,43 @@ describe('configuration', () => {
|
|||||||
}
|
}
|
||||||
expect(validateConfig(options)).to.deep.equal(expected)
|
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: 300000,
|
||||||
|
timeout: 10000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user