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

feat: add datastore to config #270

Merged
merged 1 commit into from
Oct 31, 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"cids": "~0.5.3",
"dirty-chai": "^2.0.1",
"electron-webrtc": "~0.3.0",
"interface-datastore": "~0.6.0",
"libp2p-bootstrap": "~0.9.3",
"libp2p-circuit": "~0.2.1",
"libp2p-delegated-content-routing": "~0.2.2",
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const ModuleSchema = Joi.alternatives().try(Joi.func(), Joi.object())
const OptionsSchema = Joi.object({
// TODO: create proper validators for the generics
connectionManager: Joi.object(),
datastore: Joi.object(),
peerInfo: Joi.object().required(),
peerBook: Joi.object(),
modules: Joi.object().keys({
Expand Down
5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Node extends EventEmitter {
// and add default values where appropriate
_options = validateConfig(_options)

this.datastore = _options.datastore
this.peerInfo = _options.peerInfo
this.peerBook = _options.peerBook || new PeerBook()

Expand Down Expand Up @@ -100,9 +101,7 @@ class Node extends EventEmitter {
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
datastore: this.datastore
})
}

Expand Down
4 changes: 4 additions & 0 deletions test/dht.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect

const MemoryStore = require('interface-datastore').MemoryDatastore

const createNode = require('./utils/create-node')

describe('.dht', () => {
describe('enabled', () => {
let nodeA
const datastore = new MemoryStore()

before(function (done) {
createNode('/ip4/0.0.0.0/tcp/0', {
datastore,
config: {
EXPERIMENTAL: {
dht: true
Expand Down