mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-03-28 05:11:04 +00:00
feat: add datastore to config
This commit is contained in:
parent
9518eb44b3
commit
40e840d5fd
@ -63,6 +63,7 @@
|
|||||||
"cids": "~0.5.3",
|
"cids": "~0.5.3",
|
||||||
"dirty-chai": "^2.0.1",
|
"dirty-chai": "^2.0.1",
|
||||||
"electron-webrtc": "~0.3.0",
|
"electron-webrtc": "~0.3.0",
|
||||||
|
"interface-datastore": "~0.6.0",
|
||||||
"libp2p-bootstrap": "~0.9.3",
|
"libp2p-bootstrap": "~0.9.3",
|
||||||
"libp2p-circuit": "~0.2.1",
|
"libp2p-circuit": "~0.2.1",
|
||||||
"libp2p-delegated-content-routing": "~0.2.2",
|
"libp2p-delegated-content-routing": "~0.2.2",
|
||||||
|
@ -7,6 +7,7 @@ const ModuleSchema = Joi.alternatives().try(Joi.func(), Joi.object())
|
|||||||
const OptionsSchema = Joi.object({
|
const OptionsSchema = Joi.object({
|
||||||
// TODO: create proper validators for the generics
|
// TODO: create proper validators for the generics
|
||||||
connectionManager: Joi.object(),
|
connectionManager: Joi.object(),
|
||||||
|
datastore: Joi.object(),
|
||||||
peerInfo: Joi.object().required(),
|
peerInfo: Joi.object().required(),
|
||||||
peerBook: Joi.object(),
|
peerBook: Joi.object(),
|
||||||
modules: Joi.object().keys({
|
modules: Joi.object().keys({
|
||||||
|
@ -41,6 +41,7 @@ class Node extends EventEmitter {
|
|||||||
// and add default values where appropriate
|
// and add default values where appropriate
|
||||||
_options = validateConfig(_options)
|
_options = validateConfig(_options)
|
||||||
|
|
||||||
|
this.datastore = _options.datastore
|
||||||
this.peerInfo = _options.peerInfo
|
this.peerInfo = _options.peerInfo
|
||||||
this.peerBook = _options.peerBook || new PeerBook()
|
this.peerBook = _options.peerBook || new PeerBook()
|
||||||
|
|
||||||
@ -100,9 +101,7 @@ class Node extends EventEmitter {
|
|||||||
this._dht = new DHT(this._switch, {
|
this._dht = new DHT(this._switch, {
|
||||||
kBucketSize: this._config.dht.kBucketSize || 20,
|
kBucketSize: this._config.dht.kBucketSize || 20,
|
||||||
enabledDiscovery,
|
enabledDiscovery,
|
||||||
// TODO make datastore an option of libp2p itself so
|
datastore: this.datastore
|
||||||
// that other things can use it as well
|
|
||||||
datastore: dht.datastore
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,14 +6,18 @@ const chai = require('chai')
|
|||||||
chai.use(require('dirty-chai'))
|
chai.use(require('dirty-chai'))
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
|
||||||
|
const MemoryStore = require('interface-datastore').MemoryDatastore
|
||||||
|
|
||||||
const createNode = require('./utils/create-node')
|
const createNode = require('./utils/create-node')
|
||||||
|
|
||||||
describe('.dht', () => {
|
describe('.dht', () => {
|
||||||
describe('enabled', () => {
|
describe('enabled', () => {
|
||||||
let nodeA
|
let nodeA
|
||||||
|
const datastore = new MemoryStore()
|
||||||
|
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
createNode('/ip4/0.0.0.0/tcp/0', {
|
createNode('/ip4/0.0.0.0/tcp/0', {
|
||||||
|
datastore,
|
||||||
config: {
|
config: {
|
||||||
EXPERIMENTAL: {
|
EXPERIMENTAL: {
|
||||||
dht: true
|
dht: true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user