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

[WIP] feat: read config from repo #1372

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 46 additions & 11 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 @@ -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
Expand All @@ -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)
})
}
}

Expand Down
25 changes: 25 additions & 0 deletions test/cli/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
})
})
})