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

fix: really disable DHT #1991

Merged
merged 9 commits into from
Apr 12, 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
3 changes: 2 additions & 1 deletion src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ 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: !get(options, 'offline', false), // disable if offline, on by default
enabled: false,
randomWalk: {
enabled: false // disabled waiting for https://github.com/libp2p/js-libp2p-kad-dht/issues/86
},
Expand Down
32 changes: 3 additions & 29 deletions src/core/components/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

const series = require('async/series')
const Bitswap = require('ipfs-bitswap')
const get = require('dlv')
const setImmediate = require('async/setImmediate')
const promisify = require('promisify-es6')
const { TieredDatastore } = require('datastore-core')

const IPNS = require('../ipns')
const PubsubDatastore = require('../ipns/routing/pubsub-datastore')
const OfflineDatastore = require('../ipns/routing/offline-datastore')
const routingConfig = require('../ipns/routing/config')
const createLibp2pBundle = require('./libp2p')

module.exports = (self) => {
Expand Down Expand Up @@ -53,31 +50,8 @@ module.exports = (self) => {
})
},
(cb) => {
// Setup online routing for IPNS with a tiered routing composed by a DHT and a Pubsub router (if properly enabled)
const ipnsStores = []

// Add IPNS pubsub if enabled
let pubsubDs
if (get(self._options, 'EXPERIMENTAL.ipnsPubsub', false)) {
const pubsub = self.libp2p.pubsub
const localDatastore = self._repo.datastore
const peerId = self._peerInfo.id

pubsubDs = new PubsubDatastore(pubsub, localDatastore, peerId)
ipnsStores.push(pubsubDs)
}

// DHT should be added as routing if we are not running with local flag
if (!self._options.offline) {
ipnsStores.push(self.libp2p.dht)
} else {
const offlineDatastore = new OfflineDatastore(self._repo)
ipnsStores.push(offlineDatastore)
}

// Create ipns routing with a set of datastores
const routing = new TieredDatastore(ipnsStores)
self._ipns = new IPNS(routing, self._repo.datastore, self._peerInfo, self._keychain, self._options)
const ipnsRouting = routingConfig(self)
self._ipns = new IPNS(ipnsRouting, self._repo.datastore, self._peerInfo, self._keychain, self._options)

self._bitswap = new Bitswap(
self.libp2p,
Expand Down
34 changes: 34 additions & 0 deletions src/core/ipns/routing/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict'

const { TieredDatastore } = require('datastore-core')
const get = require('dlv')

const PubsubDatastore = require('./pubsub-datastore')
const OfflineDatastore = require('./offline-datastore')

module.exports = (ipfs) => {
// Setup online routing for IPNS with a tiered routing composed by a DHT and a Pubsub router (if properly enabled)
const ipnsStores = []

// Add IPNS pubsub if enabled
let pubsubDs
if (get(ipfs._options, 'EXPERIMENTAL.ipnsPubsub', false)) {
const pubsub = ipfs.libp2p.pubsub
const localDatastore = ipfs._repo.datastore
const peerId = ipfs._peerInfo.id

pubsubDs = new PubsubDatastore(pubsub, localDatastore, peerId)
ipnsStores.push(pubsubDs)
}

// 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)) {
const offlineDatastore = new OfflineDatastore(ipfs._repo)
ipnsStores.push(offlineDatastore)
} else {
ipnsStores.push(ipfs.libp2p.dht)
}

// Create ipns routing with a set of datastores
return new TieredDatastore(ipnsStores)
}
3 changes: 2 additions & 1 deletion test/cli/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const daemonOpts = {
initOptions: { bits: 512 }
}

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

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

Expand Down
10 changes: 3 additions & 7 deletions test/core/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,9 @@ describe('interface-ipfs-core tests', function () {
initOptions: { bits: 512 }
}
}), {
skip: isNode ? [
// dht.get
{
name: 'should get a value after it was put on another node',
reason: 'Needs https://github.com/ipfs/interface-ipfs-core/pull/383'
}
] : true
skip: {
reason: 'TODO: unskip when DHT is enabled in 0.36'
}
})

tests.filesRegular(defaultCommonFactory, {
Expand Down
88 changes: 87 additions & 1 deletion test/core/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const series = require('async/series')
const isNode = require('detect-node')
const IPFS = require('../../src')
const ipnsPath = require('../../src/core/ipns/path')
const ipnsRouting = require('../../src/core/ipns/routing/config')
const OfflineDatastore = require('../../src/core/ipns/routing/offline-datastore')
const PubsubDatastore = require('../../src/core/ipns/routing/pubsub-datastore')
const { Key } = require('interface-datastore')

const DaemonFactory = require('ipfsd-ctl')
Expand Down Expand Up @@ -193,7 +196,8 @@ describe('name', function () {
})
})

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

describe('ipns.routing', function () {
it('should use only the offline datastore by default', function (done) {
const ipfs = {}
const config = ipnsRouting(ipfs)

expect(config.stores).to.have.lengthOf(1)
expect(config.stores[0] instanceof OfflineDatastore).to.eql(true)

done()
})

it('should use only the offline datastore if offline', function (done) {
const ipfs = {
_options: {
offline: true
}
}
const config = ipnsRouting(ipfs)

expect(config.stores).to.have.lengthOf(1)
expect(config.stores[0] instanceof OfflineDatastore).to.eql(true)

done()
})

it('should use the pubsub datastore if enabled', function (done) {
const ipfs = {
libp2p: {
pubsub: {}
},
_peerInfo: {
id: {}
},
_repo: {
datastore: {}
},
_options: {
EXPERIMENTAL: {
ipnsPubsub: true
}
}
}
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)

done()
})

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

const ipfs = {
libp2p: {
dht
},
_peerInfo: {
id: {}
},
_repo: {
datastore: {}
},
_options: {
libp2p: {
dht: {
enabled: true
}
}
}
}

const config = ipnsRouting(ipfs)

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

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

describe('DHT enabled', function () {
// TODO: unskip when DHT enabled in 0.36
describe.skip('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: 2 additions & 1 deletion test/http-api/inject/dht.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const expect = chai.expect
chai.use(dirtyChai)

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

before(() => {
Expand Down
10 changes: 3 additions & 7 deletions test/http-api/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,9 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {
}
}
}), {
skip: [
// dht.get
{
name: 'should get a value after it was put on another node',
reason: 'Needs https://github.com/ipfs/interface-ipfs-core/pull/383'
}
]
skip: {
reason: 'TODO: unskip when DHT is enabled in 0.36'
}
})

tests.filesRegular(defaultCommonFactory)
Expand Down