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: start kad dht random walk #251

Merged
merged 4 commits into from
Oct 4, 2018
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ class Node extends libp2p {
}
},
dht: {
kBucketSize: 20
kBucketSize: 20,
enabledDiscovery: true // Allows to disable discovery (enabled by default)
},
// Enable/Disable Experimental features
EXPERIMENTAL: { // Experimental features ("behind a flag")
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"dirty-chai": "^2.0.1",
"electron-webrtc": "~0.3.0",
"libp2p-circuit": "~0.2.1",
"libp2p-kad-dht": "~0.10.3",
"libp2p-kad-dht": "~0.10.5",
"libp2p-mdns": "~0.12.0",
"libp2p-mplex": "~0.8.2",
"libp2p-railing": "~0.9.2",
Expand Down
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const OptionsSchema = Joi.object({
})
}).default(),
dht: Joi.object().keys({
kBucketSize: Joi.number().allow(null)
kBucketSize: Joi.number().allow(null),
enabledDiscovery: Joi.boolean().default(true)
}),
EXPERIMENTAL: Joi.object().keys({
dht: Joi.boolean().default(false),
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ class Node extends EventEmitter {
// dht provided components (peerRouting, contentRouting, dht)
if (this._config.EXPERIMENTAL.dht) {
const DHT = this._modules.dht
const enabledDiscovery = this._config.dht.enabledDiscovery !== false

this._dht = new DHT(this._switch, {
kBucketSize: this._config.dht.kBucketSize || 20,
enabledDiscovery,
// TODO make datastore an option of libp2p itself so
// that other things can use it as well
datastore: dht.datastore
Expand Down
4 changes: 4 additions & 0 deletions test/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ describe('libp2p creation', () => {
sinon.spy(sw, 'start')
sinon.spy(cm, 'start')
sinon.spy(dht, 'start')
sinon.spy(dht.randomWalk, 'start')
sinon.spy(pub, 'start')
sinon.spy(sw, 'stop')
sinon.spy(cm, 'stop')
sinon.spy(dht, 'stop')
sinon.spy(dht.randomWalk, 'stop')
sinon.spy(pub, 'stop')
sinon.spy(node, 'emit')

Expand All @@ -41,6 +43,7 @@ describe('libp2p creation', () => {
expect(sw.start.calledOnce).to.equal(true)
expect(cm.start.calledOnce).to.equal(true)
expect(dht.start.calledOnce).to.equal(true)
expect(dht.randomWalk.start.calledOnce).to.equal(true)
expect(pub.start.calledOnce).to.equal(true)
expect(node.emit.calledWith('start')).to.equal(true)

Expand All @@ -53,6 +56,7 @@ describe('libp2p creation', () => {
expect(sw.stop.calledOnce).to.equal(true)
expect(cm.stop.calledOnce).to.equal(true)
expect(dht.stop.calledOnce).to.equal(true)
expect(dht.randomWalk.stop.called).to.equal(true)
expect(pub.stop.calledOnce).to.equal(true)
expect(node.emit.calledWith('stop')).to.equal(true)

Expand Down
3 changes: 2 additions & 1 deletion test/utils/bundle-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class Node extends libp2p {
}
},
dht: {
kBucketSize: 20
kBucketSize: 20,
enabledDiscovery: true
},
EXPERIMENTAL: {
dht: false,
Expand Down
3 changes: 2 additions & 1 deletion test/utils/bundle-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class Node extends libp2p {
}
},
dht: {
kBucketSize: 20
kBucketSize: 20,
enabledDiscovery: true
},
EXPERIMENTAL: {
dht: false,
Expand Down