Skip to content

Commit 40e840d

Browse files
vasco-santosjacobheun
authored andcommitted
feat: add datastore to config
1 parent 9518eb4 commit 40e840d

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"cids": "~0.5.3",
6464
"dirty-chai": "^2.0.1",
6565
"electron-webrtc": "~0.3.0",
66+
"interface-datastore": "~0.6.0",
6667
"libp2p-bootstrap": "~0.9.3",
6768
"libp2p-circuit": "~0.2.1",
6869
"libp2p-delegated-content-routing": "~0.2.2",

src/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const ModuleSchema = Joi.alternatives().try(Joi.func(), Joi.object())
77
const OptionsSchema = Joi.object({
88
// TODO: create proper validators for the generics
99
connectionManager: Joi.object(),
10+
datastore: Joi.object(),
1011
peerInfo: Joi.object().required(),
1112
peerBook: Joi.object(),
1213
modules: Joi.object().keys({

src/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Node extends EventEmitter {
4141
// and add default values where appropriate
4242
_options = validateConfig(_options)
4343

44+
this.datastore = _options.datastore
4445
this.peerInfo = _options.peerInfo
4546
this.peerBook = _options.peerBook || new PeerBook()
4647

@@ -100,9 +101,7 @@ class Node extends EventEmitter {
100101
this._dht = new DHT(this._switch, {
101102
kBucketSize: this._config.dht.kBucketSize || 20,
102103
enabledDiscovery,
103-
// TODO make datastore an option of libp2p itself so
104-
// that other things can use it as well
105-
datastore: dht.datastore
104+
datastore: this.datastore
106105
})
107106
}
108107

test/dht.node.js

+4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ const chai = require('chai')
66
chai.use(require('dirty-chai'))
77
const expect = chai.expect
88

9+
const MemoryStore = require('interface-datastore').MemoryDatastore
10+
911
const createNode = require('./utils/create-node')
1012

1113
describe('.dht', () => {
1214
describe('enabled', () => {
1315
let nodeA
16+
const datastore = new MemoryStore()
1417

1518
before(function (done) {
1619
createNode('/ip4/0.0.0.0/tcp/0', {
20+
datastore,
1721
config: {
1822
EXPERIMENTAL: {
1923
dht: true

0 commit comments

Comments
 (0)