Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
feat: read config from repo
Browse files Browse the repository at this point in the history
Lets us do things like `jsipfs config --bool EXPERIMENTAL.pubsub true` and have IPFS
respect the flags in daemon and non-daemon mode
  • Loading branch information
achingbrain committed Jul 20, 2018
1 parent f4344b0 commit d1751ea
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
58 changes: 46 additions & 12 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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)
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/http/api/resources/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down

0 comments on commit d1751ea

Please sign in to comment.