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

Commit 60525ef

Browse files
committed
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
1 parent 48aceb1 commit 60525ef

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@
108108
"ipfs-block": "~0.7.1",
109109
"ipfs-block-service": "~0.14.0",
110110
"ipfs-http-response": "~0.1.2",
111-
"ipfs-mfs": "~0.1.0",
111+
"ipfs-mfs": "~0.2.2",
112112
"ipfs-multipart": "~0.1.0",
113113
"ipfs-repo": "~0.22.1",
114114
"ipfs-unixfs": "~0.1.15",
115-
"ipfs-unixfs-engine": "~0.30.0",
115+
"ipfs-unixfs-engine": "~0.31.2",
116116
"ipld": "~0.17.3",
117117
"ipld-dag-cbor": "~0.12.1",
118118
"ipld-dag-pb": "~0.14.5",

src/core/index.js

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const CID = require('cids')
1616
const debug = require('debug')
1717
const extend = require('deep-extend')
1818
const EventEmitter = require('events')
19+
const waterfall = require('async/waterfall')
20+
const series = require('async/series')
21+
const defaults = require('lodash/defaultsDeep')
1922

2023
const config = require('./config')
2124
const boot = require('./boot')
@@ -109,17 +112,6 @@ class IPFS extends EventEmitter {
109112
this.dns = components.dns(this)
110113
this.key = components.key(this)
111114
this.stats = components.stats(this)
112-
113-
if (this._options.EXPERIMENTAL.pubsub) {
114-
this.log('EXPERIMENTAL pubsub is enabled')
115-
}
116-
if (this._options.EXPERIMENTAL.sharding) {
117-
this.log('EXPERIMENTAL sharding is enabled')
118-
}
119-
if (this._options.EXPERIMENTAL.dht) {
120-
this.log('EXPERIMENTAL Kademlia DHT is enabled')
121-
}
122-
123115
this.state = require('./state')(this)
124116

125117
// ipfs.ls
@@ -140,7 +132,49 @@ class IPFS extends EventEmitter {
140132
this.files[key] = mfs[key]
141133
})
142134

143-
boot(this)
135+
series([
136+
(cb) => {
137+
waterfall([
138+
(done) => this._repo.config.get((error, config) => {
139+
if (error) {
140+
this.log(error)
141+
}
142+
143+
done(null, config || {})
144+
}),
145+
(config, done) => {
146+
this._options = defaults({}, config, this._options)
147+
148+
done()
149+
}
150+
], cb)
151+
},
152+
(cb) => {
153+
if (this._options.EXPERIMENTAL.pubsub) {
154+
this.log('EXPERIMENTAL pubsub is enabled')
155+
}
156+
157+
if (this._options.EXPERIMENTAL.sharding) {
158+
this.log('EXPERIMENTAL sharding is enabled')
159+
}
160+
161+
if (this._options.EXPERIMENTAL.dht) {
162+
this.log('EXPERIMENTAL Kademlia DHT is enabled')
163+
}
164+
165+
if (this._options.EXPERIMENTAL.relay) {
166+
this.log('EXPERIMENTAL Relay is enabled')
167+
}
168+
169+
cb()
170+
}
171+
], (error) => {
172+
if (error) {
173+
return this.emit('error', error)
174+
}
175+
176+
boot(this)
177+
})
144178
}
145179
}
146180

src/http/api/resources/files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ exports.add = {
153153
validate: {
154154
query: Joi.object()
155155
.keys({
156-
'cid-version': Joi.number().integer().min(0).max(1),
156+
'cid-version': Joi.number().integer().min(0).max(1).default(0),
157157
// Temporary restriction on raw-leaves:
158158
// When cid-version=1 then raw-leaves MUST be present and false.
159159
//

0 commit comments

Comments
 (0)