From c18f9be4e18268522b86050803bef98ee21e13ba Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 30 May 2018 11:08:19 +0100 Subject: [PATCH] feat: read config from repo Lets us do things like `jsipfs config --bool EXPERIMENTAL.pubsub true` and have IPFS respect the flags in daemon and non-daemon mode --- package.json | 1 + src/core/index.js | 61 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index dba09a090d..1af5208b11 100644 --- a/package.json +++ b/package.json @@ -136,6 +136,7 @@ "libp2p-webrtc-star": "~0.15.0", "libp2p-websocket-star": "~0.8.0", "libp2p-websockets": "~0.12.0", + "lodash.defaultsdeep": "^4.6.0", "lodash.flatmap": "^4.5.0", "lodash.get": "^4.4.2", "lodash.set": "^4.3.2", diff --git a/src/core/index.js b/src/core/index.js index 0b19160429..77b08c7e94 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -16,6 +16,9 @@ const CID = require('cids') const debug = require('debug') const extend = require('deep-extend') const EventEmitter = require('events') +const waterfall = require('async/waterfall') +const series = require('async/series') +const defaults = require('lodash.defaultsdeep') const config = require('./config') const boot = require('./boot') @@ -109,20 +112,6 @@ class IPFS extends EventEmitter { this.dns = components.dns(this) this.key = components.key(this) this.stats = components.stats(this) - - if (this._options.EXPERIMENTAL.pubsub) { - this.log('EXPERIMENTAL pubsub is enabled') - } - if (this._options.EXPERIMENTAL.sharding) { - this.log('EXPERIMENTAL sharding is enabled') - } - if (this._options.EXPERIMENTAL.dht) { - this.log('EXPERIMENTAL Kademlia DHT is enabled') - } - if (this._options.EXPERIMENTAL.relay) { - this.log('EXPERIMENTAL Relay is enabled') - } - this.state = require('./state')(this) // ipfs.ls @@ -136,7 +125,49 @@ class IPFS extends EventEmitter { isIPFS: isIPFS } - boot(this) + series([ + (cb) => { + waterfall([ + (done) => this._repo.config.get((error, config) => { + if (error) { + console.info('Error', error) + } + + cb(null, config || {}) + }), + (config, done) => { + this._options = defaults({}, config, this._options) + + done() + } + ], cb) + }, + (cb) => { + if (this._options.EXPERIMENTAL.pubsub) { + this.log('EXPERIMENTAL pubsub is enabled') + } + + if (this._options.EXPERIMENTAL.sharding) { + this.log('EXPERIMENTAL sharding is enabled') + } + + if (this._options.EXPERIMENTAL.dht) { + this.log('EXPERIMENTAL Kademlia DHT is enabled') + } + + if (this._options.EXPERIMENTAL.relay) { + this.log('EXPERIMENTAL Relay is enabled') + } + + cb() + } + ], (error) => { + if (error) { + return this.emit('error', error) + } + + boot(this) + }) } }