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 Jun 19, 2018
1 parent 2be4a0f commit c18f9be
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
61 changes: 46 additions & 15 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,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
Expand All @@ -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)
})
}
}

Expand Down

0 comments on commit c18f9be

Please sign in to comment.