From f306ca202bb19dad1ca33a4cf451fc577decdc20 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 31 Oct 2018 11:48:02 +0000 Subject: [PATCH] feat: add datastore to config --- package.json | 1 + src/config.js | 1 + src/index.js | 5 ++--- test/dht.node.js | 4 ++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index c8d71050dc..8e750e5971 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/config.js b/src/config.js index 989afcd1d1..1d01fe88da 100644 --- a/src/config.js +++ b/src/config.js @@ -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({ diff --git a/src/index.js b/src/index.js index 9d54b85395..40ec5f4563 100644 --- a/src/index.js +++ b/src/index.js @@ -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() @@ -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 }) } diff --git a/test/dht.node.js b/test/dht.node.js index d2c392331d..3dfb4036b7 100644 --- a/test/dht.node.js +++ b/test/dht.node.js @@ -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