From 26838e00937c5247f2788fb5ce1f307275dc15b0 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 30 May 2018 11:08:19 +0100 Subject: [PATCH 1/2] 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 --- src/core/index.js | 57 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/src/core/index.js b/src/core/index.js index 0f49423f78..5a709b5b11 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') @@ -124,16 +127,6 @@ class IPFS extends EventEmitter { this.stats = components.stats(this) this.resolve = components.resolve(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') - } - this.state = require('./state')(this) // ipfs.ls @@ -154,7 +147,49 @@ class IPFS extends EventEmitter { this.files[key] = mfs[key] }) - boot(this) + series([ + (cb) => { + waterfall([ + (done) => this._repo.config.get((error, config) => { + if (error) { + this.log(error) + } + + done(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) + }) } } From 287d7aec14308ac92099ba76ba70e2db44c05a21 Mon Sep 17 00:00:00 2001 From: victorbjelkholm Date: Wed, 29 Aug 2018 12:33:23 +0200 Subject: [PATCH 2/2] test: add test for reading config from repo when using cli License: MIT Signed-off-by: Victor Bjelkholm --- test/cli/daemon.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/cli/daemon.js b/test/cli/daemon.js index d60d591279..ee2859eff4 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -134,4 +134,29 @@ describe('daemon', () => { done() }) }) + + it('uses config from repo config', function () { + this.timeout(100 * 1000) + return ipfs('init').then(() => { + return ipfs('config EXPERIMENTAL.pubsub true --bool') + }).then(() => { + const config = JSON.parse(fs.readFileSync(path.join(repoPath, 'config'))) + expect(config.EXPERIMENTAL.pubsub).to.equal(true) + return ipfs('config EXPERIMENTAL.pubsub') + }).then((out) => { + expect(out.trim()).to.equal('true') + const proc = ipfs('daemon') + return new Promise((resolve, reject) => { + proc.stdout.on('data', (data) => { + if (data.toString().includes(`Daemon is ready`)) { + resolve() + } + }) + }) + }).then(() => { + return ipfs('pubsub ls') + }).then((out) => { + expect(out).to.equal('') + }) + }) })