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

Commit 2470be8

Browse files
author
Alan Shaw
authored
fix: really disable DHT (#1991)
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 4376121 commit 2470be8

File tree

10 files changed

+140
-49
lines changed

10 files changed

+140
-49
lines changed

src/core/components/libp2p.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) {
6666
},
6767
dht: {
6868
kBucketSize: get(options, 'dht.kBucketSize', 20),
69-
enabled: !get(options, 'offline', false), // disable if offline, on by default
69+
// enabled: !get(options, 'offline', false), // disable if offline, on by default
70+
enabled: false,
7071
randomWalk: {
7172
enabled: false // disabled waiting for https://github.com./libp2p/js-libp2p-kad-dht/issues/86
7273
},

src/core/components/start.js

+3-29
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
const series = require('async/series')
44
const Bitswap = require('ipfs-bitswap')
5-
const get = require('dlv')
65
const setImmediate = require('async/setImmediate')
76
const promisify = require('promisify-es6')
8-
const { TieredDatastore } = require('datastore-core')
97

108
const IPNS = require('../ipns')
11-
const PubsubDatastore = require('../ipns/routing/pubsub-datastore')
12-
const OfflineDatastore = require('../ipns/routing/offline-datastore')
9+
const routingConfig = require('../ipns/routing/config')
1310
const createLibp2pBundle = require('./libp2p')
1411

1512
module.exports = (self) => {
@@ -53,31 +50,8 @@ module.exports = (self) => {
5350
})
5451
},
5552
(cb) => {
56-
// Setup online routing for IPNS with a tiered routing composed by a DHT and a Pubsub router (if properly enabled)
57-
const ipnsStores = []
58-
59-
// Add IPNS pubsub if enabled
60-
let pubsubDs
61-
if (get(self._options, 'EXPERIMENTAL.ipnsPubsub', false)) {
62-
const pubsub = self.libp2p.pubsub
63-
const localDatastore = self._repo.datastore
64-
const peerId = self._peerInfo.id
65-
66-
pubsubDs = new PubsubDatastore(pubsub, localDatastore, peerId)
67-
ipnsStores.push(pubsubDs)
68-
}
69-
70-
// DHT should be added as routing if we are not running with local flag
71-
if (!self._options.offline) {
72-
ipnsStores.push(self.libp2p.dht)
73-
} else {
74-
const offlineDatastore = new OfflineDatastore(self._repo)
75-
ipnsStores.push(offlineDatastore)
76-
}
77-
78-
// Create ipns routing with a set of datastores
79-
const routing = new TieredDatastore(ipnsStores)
80-
self._ipns = new IPNS(routing, self._repo.datastore, self._peerInfo, self._keychain, self._options)
53+
const ipnsRouting = routingConfig(self)
54+
self._ipns = new IPNS(ipnsRouting, self._repo.datastore, self._peerInfo, self._keychain, self._options)
8155

8256
self._bitswap = new Bitswap(
8357
self.libp2p,

src/core/ipns/routing/config.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict'
2+
3+
const { TieredDatastore } = require('datastore-core')
4+
const get = require('dlv')
5+
6+
const PubsubDatastore = require('./pubsub-datastore')
7+
const OfflineDatastore = require('./offline-datastore')
8+
9+
module.exports = (ipfs) => {
10+
// Setup online routing for IPNS with a tiered routing composed by a DHT and a Pubsub router (if properly enabled)
11+
const ipnsStores = []
12+
13+
// Add IPNS pubsub if enabled
14+
let pubsubDs
15+
if (get(ipfs._options, 'EXPERIMENTAL.ipnsPubsub', false)) {
16+
const pubsub = ipfs.libp2p.pubsub
17+
const localDatastore = ipfs._repo.datastore
18+
const peerId = ipfs._peerInfo.id
19+
20+
pubsubDs = new PubsubDatastore(pubsub, localDatastore, peerId)
21+
ipnsStores.push(pubsubDs)
22+
}
23+
24+
// DHT should not be added as routing if we are offline or it is disabled
25+
if (get(ipfs._options, 'offline') || !get(ipfs._options, 'libp2p.dht.enabled', false)) {
26+
const offlineDatastore = new OfflineDatastore(ipfs._repo)
27+
ipnsStores.push(offlineDatastore)
28+
} else {
29+
ipnsStores.push(ipfs.libp2p.dht)
30+
}
31+
32+
// Create ipns routing with a set of datastores
33+
return new TieredDatastore(ipnsStores)
34+
}

test/cli/dht.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const daemonOpts = {
3131
initOptions: { bits: 512 }
3232
}
3333

34-
describe('dht', () => {
34+
// TODO: unskip when DHT is enabled in 0.36
35+
describe.skip('dht', () => {
3536
let nodes = []
3637
let ipfsA
3738
let ipfsB

test/core/dht.spec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const isNode = require('detect-node')
1212
const IPFSFactory = require('ipfsd-ctl')
1313
const IPFS = require('../../src/core')
1414

15-
describe('dht', () => {
15+
// TODO: unskip when DHT is enabled in 0.36
16+
describe.skip('dht', () => {
1617
describe('enabled', () => {
1718
let ipfsd, ipfs
1819

test/core/interface.spec.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,9 @@ describe('interface-ipfs-core tests', function () {
5252
initOptions: { bits: 512 }
5353
}
5454
}), {
55-
skip: isNode ? [
56-
// dht.get
57-
{
58-
name: 'should get a value after it was put on another node',
59-
reason: 'Needs https://github.com./ipfs/interface-ipfs-core/pull/383'
60-
}
61-
] : true
55+
skip: {
56+
reason: 'TODO: unskip when DHT is enabled in 0.36'
57+
}
6258
})
6359

6460
tests.filesRegular(defaultCommonFactory, {

test/core/name.js

+87-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const series = require('async/series')
1616
const isNode = require('detect-node')
1717
const IPFS = require('../../src')
1818
const ipnsPath = require('../../src/core/ipns/path')
19+
const ipnsRouting = require('../../src/core/ipns/routing/config')
20+
const OfflineDatastore = require('../../src/core/ipns/routing/offline-datastore')
21+
const PubsubDatastore = require('../../src/core/ipns/routing/pubsub-datastore')
1922
const { Key } = require('interface-datastore')
2023

2124
const DaemonFactory = require('ipfsd-ctl')
@@ -193,7 +196,8 @@ describe('name', function () {
193196
})
194197
})
195198

196-
describe('work with dht', () => {
199+
// TODO: unskip when DHT is enabled in 0.36
200+
describe.skip('work with dht', () => {
197201
let nodes
198202
let nodeA
199203
let nodeB
@@ -532,4 +536,86 @@ describe('name', function () {
532536
})
533537
})
534538
})
539+
540+
describe('ipns.routing', function () {
541+
it('should use only the offline datastore by default', function (done) {
542+
const ipfs = {}
543+
const config = ipnsRouting(ipfs)
544+
545+
expect(config.stores).to.have.lengthOf(1)
546+
expect(config.stores[0] instanceof OfflineDatastore).to.eql(true)
547+
548+
done()
549+
})
550+
551+
it('should use only the offline datastore if offline', function (done) {
552+
const ipfs = {
553+
_options: {
554+
offline: true
555+
}
556+
}
557+
const config = ipnsRouting(ipfs)
558+
559+
expect(config.stores).to.have.lengthOf(1)
560+
expect(config.stores[0] instanceof OfflineDatastore).to.eql(true)
561+
562+
done()
563+
})
564+
565+
it('should use the pubsub datastore if enabled', function (done) {
566+
const ipfs = {
567+
libp2p: {
568+
pubsub: {}
569+
},
570+
_peerInfo: {
571+
id: {}
572+
},
573+
_repo: {
574+
datastore: {}
575+
},
576+
_options: {
577+
EXPERIMENTAL: {
578+
ipnsPubsub: true
579+
}
580+
}
581+
}
582+
const config = ipnsRouting(ipfs)
583+
584+
expect(config.stores).to.have.lengthOf(2)
585+
expect(config.stores[0] instanceof PubsubDatastore).to.eql(true)
586+
expect(config.stores[1] instanceof OfflineDatastore).to.eql(true)
587+
588+
done()
589+
})
590+
591+
it('should use the dht if enabled', function (done) {
592+
const dht = {}
593+
594+
const ipfs = {
595+
libp2p: {
596+
dht
597+
},
598+
_peerInfo: {
599+
id: {}
600+
},
601+
_repo: {
602+
datastore: {}
603+
},
604+
_options: {
605+
libp2p: {
606+
dht: {
607+
enabled: true
608+
}
609+
}
610+
}
611+
}
612+
613+
const config = ipnsRouting(ipfs)
614+
615+
expect(config.stores).to.have.lengthOf(1)
616+
expect(config.stores[0]).to.eql(dht)
617+
618+
done()
619+
})
620+
})
535621
})

test/core/ping.spec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ describe('ping', function () {
194194
})
195195
})
196196

197-
describe('DHT enabled', function () {
197+
// TODO: unskip when DHT enabled in 0.36
198+
describe.skip('DHT enabled', function () {
198199
// Our bootstrap process will run 3 IPFS daemons where
199200
// A ----> B ----> C
200201
// Allowing us to test the ping command using the DHT peer routing

test/http-api/inject/dht.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const expect = chai.expect
88
chai.use(dirtyChai)
99

1010
module.exports = (http) => {
11-
describe('/dht', () => {
11+
// TODO: unskip when DHT is enabled in 0.36
12+
describe.skip('/dht', () => {
1213
let api
1314

1415
before(() => {

test/http-api/interface.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,9 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {
4343
}
4444
}
4545
}), {
46-
skip: [
47-
// dht.get
48-
{
49-
name: 'should get a value after it was put on another node',
50-
reason: 'Needs https://github.com./ipfs/interface-ipfs-core/pull/383'
51-
}
52-
]
46+
skip: {
47+
reason: 'TODO: unskip when DHT is enabled in 0.36'
48+
}
5349
})
5450

5551
tests.filesRegular(defaultCommonFactory)

0 commit comments

Comments
 (0)