Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

refactor: enable DHT by default #1994

Closed
wants to merge 6 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"execa": "^1.0.0",
"form-data": "^2.3.3",
"hat": "0.0.3",
"interface-ipfs-core": "~0.104.0",
"interface-ipfs-core": "~0.104.2",
"ipfsd-ctl": "~0.42.0",
"libp2p-websocket-star": "~0.10.2",
"ncp": "^2.0.0",
Expand Down
5 changes: 2 additions & 3 deletions src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) {
},
dht: {
kBucketSize: get(options, 'dht.kBucketSize', 20),
// enabled: !get(options, 'offline', false), // disable if offline, on by default
enabled: false,
enabled: !get(options, 'offline', false), // disable if offline, on by default
randomWalk: {
enabled: false // disabled waiting for https://github.com/libp2p/js-libp2p-kad-dht/issues/86
enabled: true
},
validators: {
ipns: ipnsUtils.validator
Expand Down
2 changes: 1 addition & 1 deletion src/core/ipns/routing/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = (ipfs) => {
}

// DHT should not be added as routing if we are offline or it is disabled
if (get(ipfs._options, 'offline') || !get(ipfs._options, 'libp2p.dht.enabled', false)) {
if (get(ipfs._options, 'offline') || !get(ipfs._options, 'libp2p.dht.enabled', true)) {
const offlineDatastore = new OfflineDatastore(ipfs._repo)
ipnsStores.push(offlineDatastore)
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/core/runtime/config-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ module.exports = () => ({
],
Swarm: {
ConnMgr: {
LowWater: 200,
HighWater: 500
LowWater: 20,
HighWater: 50
}
}
})
10 changes: 9 additions & 1 deletion src/core/runtime/libp2p-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ class Node extends libp2p {
}
},
dht: {
enabled: false
enabled: true,
concurrency: 3,
kBucketSize: 20,
randomWalk: {
enabled: false,
interval: 600e3, // 10minutes
delay: 10e3,
timeout: 30e3
}
},
EXPERIMENTAL: {
pubsub: false
Expand Down
8 changes: 6 additions & 2 deletions src/core/runtime/libp2p-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ class Node extends libp2p {
},
dht: {
kBucketSize: 20,
enabled: false,
enabled: true,
concurrency: 4,
randomWalk: {
enabled: false
enabled: true,
interval: 600e3,
delay: 5e3,
timeout: 20e3
}
},
EXPERIMENTAL: {
Expand Down
3 changes: 1 addition & 2 deletions test/cli/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ const daemonOpts = {
initOptions: { bits: 512 }
}

// TODO: unskip when DHT is enabled in 0.36
describe.skip('dht', () => {
describe('dht', () => {
let nodes = []
let ipfsA
let ipfsB
Expand Down
3 changes: 1 addition & 2 deletions test/core/dht.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const isNode = require('detect-node')
const IPFSFactory = require('ipfsd-ctl')
const IPFS = require('../../src/core')

// TODO: unskip when DHT is enabled in 0.36
describe.skip('dht', () => {
describe('dht', () => {
describe('enabled', () => {
let ipfsd, ipfs

Expand Down
4 changes: 1 addition & 3 deletions test/core/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ describe('interface-ipfs-core tests', function () {
initOptions: { bits: 512 }
}
}), {
skip: {
reason: 'TODO: unskip when DHT is enabled in 0.36'
}
skip: !isNode
})

tests.filesRegular(defaultCommonFactory, {
Expand Down
33 changes: 27 additions & 6 deletions test/core/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ describe('name', function () {
})
})

// TODO: unskip when DHT is enabled in 0.36
describe.skip('work with dht', () => {
describe('work with dht', () => {
let nodes
let nodeA
let nodeB
Expand Down Expand Up @@ -538,8 +537,16 @@ describe('name', function () {
})

describe('ipns.routing', function () {
it('should use only the offline datastore by default', function (done) {
const ipfs = {}
it('should use offline datastore if DHT is disabled', function (done) {
const ipfs = {
_options: {
libp2p: {
dht: {
enabled: false
}
}
}
}
const config = ipnsRouting(ipfs)

expect(config.stores).to.have.lengthOf(1)
Expand All @@ -563,8 +570,11 @@ describe('name', function () {
})

it('should use the pubsub datastore if enabled', function (done) {
const dht = {}

const ipfs = {
libp2p: {
dht,
pubsub: {}
},
_peerInfo: {
Expand All @@ -582,8 +592,8 @@ describe('name', function () {
const config = ipnsRouting(ipfs)

expect(config.stores).to.have.lengthOf(2)
expect(config.stores[0] instanceof PubsubDatastore).to.eql(true)
expect(config.stores[1] instanceof OfflineDatastore).to.eql(true)
expect(config.stores.some(s => s instanceof PubsubDatastore)).to.eql(true)
expect(config.stores).to.include(dht)

done()
})
Expand Down Expand Up @@ -617,5 +627,16 @@ describe('name', function () {

done()
})

it('should use the dht by default', function (done) {
const dht = {}
const ipfs = { libp2p: { dht } }
const config = ipnsRouting(ipfs)

expect(config.stores).to.have.lengthOf(1)
expect(config.stores[0]).to.eql(dht)

done()
})
})
})
3 changes: 1 addition & 2 deletions test/core/ping.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ describe('ping', function () {
})
})

// TODO: unskip when DHT enabled in 0.36
describe.skip('DHT enabled', function () {
describe('DHT enabled', function () {
// Our bootstrap process will run 3 IPFS daemons where
// A ----> B ----> C
// Allowing us to test the ping command using the DHT peer routing
Expand Down
3 changes: 1 addition & 2 deletions test/http-api/inject/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const expect = chai.expect
chai.use(dirtyChai)

module.exports = (http) => {
// TODO: unskip when DHT is enabled in 0.36
describe.skip('/dht', () => {
describe('/dht', () => {
let api

before(() => {
Expand Down
6 changes: 1 addition & 5 deletions test/http-api/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {
}
}
}
}), {
skip: {
reason: 'TODO: unskip when DHT is enabled in 0.36'
}
})
}))

tests.filesRegular(defaultCommonFactory)

Expand Down