From d1751ea22d7af4bed2694e0ed6e1de7839bd71c7 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 | 4 +-- src/core/index.js | 58 ++++++++++++++++++++++++++------- src/http/api/resources/files.js | 2 +- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 67d1819938..1c657514af 100644 --- a/package.json +++ b/package.json @@ -108,11 +108,11 @@ "ipfs-block": "~0.7.1", "ipfs-block-service": "~0.14.0", "ipfs-http-response": "~0.1.2", - "ipfs-mfs": "~0.1.0", + "ipfs-mfs": "~0.2.2", "ipfs-multipart": "~0.1.0", "ipfs-repo": "~0.22.1", "ipfs-unixfs": "~0.1.15", - "ipfs-unixfs-engine": "~0.30.0", + "ipfs-unixfs-engine": "~0.31.2", "ipld": "~0.17.3", "ipld-dag-cbor": "~0.12.1", "ipld-dag-pb": "~0.14.5", diff --git a/src/core/index.js b/src/core/index.js index 36f7c3a118..8d1bbdc8b6 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,17 +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') - } - this.state = require('./state')(this) // ipfs.ls @@ -140,7 +132,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) + }) } } diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index a3b7e8eaed..cd3c2f1e4c 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -153,7 +153,7 @@ exports.add = { validate: { query: Joi.object() .keys({ - 'cid-version': Joi.number().integer().min(0).max(1), + 'cid-version': Joi.number().integer().min(0).max(1).default(0), // Temporary restriction on raw-leaves: // When cid-version=1 then raw-leaves MUST be present and false. //