-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add keysize through an option to spawn #203
Changes from 8 commits
2595fc4
718e0ce
c9c25da
c3fca62
55142c5
17d578e
f5f400e
ee74427
b167a3c
ac70cda
6c7a028
2ca9aa1
1351dde
fb30e0e
174e9dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,13 @@ | |
"lint": "aegir lint", | ||
"docs": "aegir docs", | ||
"build": "aegir build", | ||
"test": "aegir test -t node -t browser --no-cors", | ||
"test:node": "aegir test -t node", | ||
"test:browser": "aegir test -t browser --no-cors", | ||
"test": "cross-env IPFS_KEYSIZE=1024 aegir test -t node -t browser --no-cors", | ||
"test:node": "cross-env IPFS_KEYSIZE=1024 aegir test -t node", | ||
"test:browser": "cross-env IPFS_KEYSIZE=1024 aegir test -t browser --no-cors", | ||
"release": "aegir release", | ||
"release-minor": "aegir release --type minor", | ||
"release-major": "aegir release --type major", | ||
"coverage": "COVERAGE=true aegir coverage --timeout 50000", | ||
"coverage": "IPFS_KEYSIZE=1024 COVERAGE=true aegir coverage --timeout 50000", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dryajov please set these values on tests themselves. |
||
"coverage-publish": "aegir coverage -u" | ||
}, | ||
"browser": { | ||
|
@@ -78,17 +78,19 @@ | |
"detect-node": "^2.0.3", | ||
"hapi": "^16.6.2", | ||
"hat": "0.0.3", | ||
"ipfs-api": "^17.3.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"ipfs-repo": "^0.18.5", | ||
"joi": "^13.0.2", | ||
"lodash.clone": "^4.5.0", | ||
"lodash.defaults": "^4.2.0", | ||
"lodash.defaultsdeep": "^4.6.0", | ||
"multiaddr": "^3.0.2", | ||
"once": "^1.4.0", | ||
"readable-stream": "^2.3.3", | ||
"rimraf": "^2.6.2", | ||
"safe-json-parse": "^4.0.0", | ||
"safe-json-stringify": "^1.0.4", | ||
"shutdown": "^0.3.0", | ||
"ipfs-api": "^17.3.0", | ||
"stream-http": "^2.7.2", | ||
"subcomandante": "^1.0.5", | ||
"superagent": "^3.8.2", | ||
|
@@ -97,6 +99,7 @@ | |
"devDependencies": { | ||
"aegir": "^12.4.0", | ||
"chai": "^4.1.2", | ||
"cross-env": "^5.1.3", | ||
"detect-port": "^1.2.2", | ||
"dirty-chai": "^2.0.1", | ||
"go-ipfs-dep": "0.4.13", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ class FactoryDaemon { | |
* | ||
* Options are: | ||
* - `init` bool - should the node be initialized | ||
* - `initOpts` Object, it is expected to be of the form `{bits: <size>}`, which sets the desired key size | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the README as well |
||
* - `start` bool - should the node be started | ||
* - `repoPath` string - the repository path to use for this node, ignored if node is disposable | ||
* - `disposable` bool - a new repo is created and initialized for each invocation | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,23 +2,26 @@ | |
|
||
const fs = require('fs') | ||
const waterfall = require('async/waterfall') | ||
const series = require('async/series') | ||
const ipfs = require('ipfs-api') | ||
const multiaddr = require('multiaddr') | ||
const rimraf = require('rimraf') | ||
const path = require('path') | ||
const once = require('once') | ||
const truthy = require('truthy') | ||
const flatten = require('./utils/flatten') | ||
const defaults = require('lodash.defaults') | ||
const debug = require('debug') | ||
const os = require('os') | ||
const hat = require('hat') | ||
const log = debug('ipfsd-ctl:daemon') | ||
|
||
const safeParse = require('safe-json-parse/callback') | ||
const safeStringify = require('safe-json-stringify') | ||
|
||
const parseConfig = require('./utils/parse-config') | ||
const tmpDir = require('./utils/tmp-dir') | ||
const findIpfsExecutable = require('./utils/find-ipfs-executable') | ||
const setConfigValue = require('./utils/set-config-value') | ||
const configureNode = require('./utils/configure-node') | ||
const run = require('./utils/run') | ||
|
||
const GRACE_PERIOD = 10500 // amount of ms to wait before sigkill | ||
|
@@ -42,8 +45,6 @@ class Daemon { | |
const type = truthy(process.env.IPFS_TYPE) | ||
|
||
this.opts = opts || { type: type || 'go' } | ||
this.opts.config = flatten(this.opts.config) | ||
|
||
const td = tmpDir(opts.type === 'js') | ||
this.path = this.opts.disposable | ||
? td | ||
|
@@ -57,6 +58,7 @@ class Daemon { | |
this._gatewayAddr = null | ||
this._started = false | ||
this.api = null | ||
this.bits = this.opts.initOpts ? this.opts.initOpts.bits : process.env.IPFS_KEYSIZE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. L60 is redundant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
if (this.opts.env) { | ||
Object.assign(this.env, this.opts.env) | ||
|
@@ -112,7 +114,7 @@ class Daemon { | |
* Initialize a repo. | ||
* | ||
* @param {Object} [initOpts={}] | ||
* @param {number} [initOpts.keysize=2048] - The bit size of the identiy key. | ||
* @param {number} [initOpts.bits=2048] - The bit size of the identiy key. | ||
* @param {string} [initOpts.directory=IPFS_PATH] - The location of the repo. | ||
* @param {string} [initOpts.pass] - The passphrase of the keychain. | ||
* @param {function (Error, Node)} callback | ||
|
@@ -128,24 +130,32 @@ class Daemon { | |
this.path = initOpts.directory | ||
} | ||
|
||
const args = ['init', '-b', initOpts.keysize || 2048] | ||
const bits = initOpts.bits ? initOpts.bits : this.bits | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this repeating part of line 61? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const args = ['init'] | ||
// do not just set a default keysize, | ||
// in case we decide to change it at | ||
// the daemon level in the future | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sentence doesn't read right. Do you mean "Skip if default daemon keysize"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, ipfs daemons have a default keysize when using |
||
if (bits) { | ||
args.concat(['-b', bits]) | ||
} | ||
if (initOpts.pass) { | ||
args.push('--pass') | ||
args.push('"' + initOpts.pass + '"') | ||
} | ||
log(`initializing with keysize: ${bits}`) | ||
run(this, args, { env: this.env }, (err, result) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
|
||
configureNode(this, this.opts.config, (err) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
|
||
waterfall([ | ||
(cb) => this.getConfig(cb), | ||
(conf, cb) => this.replaceConfig(defaults({}, this.opts.config, conf), cb) | ||
], (err) => { | ||
if (err) { return callback } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the callback needs to be called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch |
||
this.clean = false | ||
this.initialized = true | ||
callback(null, this) | ||
return callback(null, this) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Init should not need to return a reference to the instance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is done for backwards compatibility, that is how we used to do it previous versions, plus it helps with chaining in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove. |
||
}) | ||
}) | ||
} | ||
|
@@ -328,7 +338,7 @@ class Daemon { | |
cb | ||
), | ||
(config, cb) => { | ||
if (!key) { | ||
if (key === 'show') { | ||
return safeParse(config, cb) | ||
} | ||
cb(null, config.trim()) | ||
|
@@ -348,6 +358,33 @@ class Daemon { | |
setConfigValue(this, key, value, callback) | ||
} | ||
|
||
/** | ||
* Replace the current config with the provided one | ||
* | ||
* @param {object} config | ||
* @param {function(Error)} callback | ||
* @return {undefined} | ||
*/ | ||
replaceConfig (config, callback) { | ||
const tmpFile = path.join(os.tmpdir(), hat()) | ||
// I wanted to use streams here, but js-ipfs doesn't | ||
// read from stdin when providing '-' (or piping) like | ||
// go-ipfs, and adding it right now seems like a fair | ||
// bit of work, so we're using tmp file for now - not ideal... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR with a WIP here ipfs/js-ipfs#785 really close to finish. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you update this comment to refer the WIP PR ipfs/js-ipfs#785 and add a proper TODO to come back here once that is done. |
||
series([ | ||
(cb) => fs.writeFile(tmpFile, safeStringify(config), cb), | ||
(cb) => run( | ||
this, | ||
['config', 'replace', `${tmpFile}`], | ||
{ env: this.env }, | ||
cb | ||
) | ||
], (err) => { | ||
if (err) { return callback(err) } | ||
fs.unlink(tmpFile, callback) | ||
}) | ||
} | ||
|
||
/** | ||
* Get the version of ipfs | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ const isNode = require('detect-node') | |
const hat = require('hat') | ||
const IPFSFactory = require('../src') | ||
const JSIPFS = require('ipfs') | ||
const os = require('os') | ||
|
||
const isWindows = os.platform() === 'win32' | ||
|
||
const tests = [ | ||
{ type: 'go' }, | ||
|
@@ -112,6 +115,9 @@ describe('Spawn options', () => { | |
}) | ||
|
||
describe('spawn from a initialized repo', () => { | ||
// TODO: wont work on windows until we get `/shutdown` implemented in js-ipfs | ||
if (isWindows) { return } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skip doesn't work inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// TODO: figure out why `proc` IPFS refuses | ||
// to start with a provided repo | ||
// `Error: Not able to start from state: uninitalized` | ||
|
@@ -183,7 +189,7 @@ describe('Spawn options', () => { | |
}) | ||
}) | ||
|
||
describe('custom init options', () => { | ||
describe('custom config options', () => { | ||
it('custom config', function (done) { | ||
this.timeout(40 * 1000) | ||
|
||
|
@@ -215,6 +221,7 @@ describe('Spawn options', () => { | |
config = JSON.parse(config) | ||
} | ||
expect(config).to.eql([swarmAddr1]) | ||
// expect(config).to.include(swarmAddr1) | ||
cb(null, ipfsd) | ||
}) | ||
], (err, ipfsd) => { | ||
|
@@ -344,7 +351,8 @@ describe('Spawn options', () => { | |
}) | ||
}) | ||
|
||
after((done) => { | ||
after(function (done) { | ||
this.timeout(50 * 1000) | ||
ipfsd.stop(done) | ||
}) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of conditional types in a parameter. Either it's a
Boolean
or it's aObject
. Rather, we should add a new option. If we're only addingkeySize
, why not makekeySize
a key of theoptions
object?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think we call the option
bits
here, OR, change the option in go-ipfs as well. It'sbits
there currently, butkeySize
is probably a more descriptive name.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @victorbjelkholm, I thought about that too and you're right, I'll add another options
initOpts
and leaveinit
as a bool.For the second comment,
keysize
is used because historically that is whatipfsd-ctl
used and it's the same name we use when passing that flag toinit
, and yes I thinkkeysize
is more descriptive.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
read: #188 (comment)
I'm fine with init being boolean or object, but I'm fine with
initOptions
(not initOpts) too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README needs to be updated to include
initOptions