Skip to content
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

Merged
merged 15 commits into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "IPFS_KEYSIZE=1024 aegir test -t node -t browser --no-cors",
"test:node": "IPFS_KEYSIZE=1024 aegir test -t node",
"test:browser": "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",
Copy link
Member

Choose a reason for hiding this comment

The 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": {
Expand Down
4 changes: 2 additions & 2 deletions src/factory-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class FactoryDaemon {
* Spawn an IPFS node, either js-ipfs or go-ipfs
*
* Options are:
* - `init` {bool|Object} - should the node be initialized
* - if `init` is an Object, it is expected to be of the form `{keySize: <bits>}`
* - `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
Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down
2 changes: 1 addition & 1 deletion src/factory-in-proc.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class FactoryInProc {
*
* Options are:
* - `init` {bool|Object} - should the node be initialized
* - if `init` is an Object, it is expected to be of the form `{keySize: <bits>}`
* - `initOpts` Object, it is expected to be of the form `{bits: <size>}`, which sets the desired key size
* - `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
Expand Down
19 changes: 7 additions & 12 deletions src/ipfsd-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,9 @@ class Daemon {
this._gatewayAddr = null
this._started = false
this.api = null
this.keySize = null
this.bits = null

this.keySize = process.env.IPFS_KEYSIZE

// option takes precedence over env variable
if (typeof this.opts.init === 'object') {
this.keySize = this.opts.init.keySize
}
this.bits = this.opts.initOpts ? this.opts.initOpts.bits : process.env.IPFS_KEYSIZE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L60 is redundant

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/initOpts/initOptions/g


if (this.opts.env) {
Object.assign(this.env, this.opts.env)
Expand Down Expand Up @@ -120,7 +115,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
Expand All @@ -136,19 +131,19 @@ class Daemon {
this.path = initOpts.directory
}

const keySize = initOpts.keysize ? initOpts.keysize : this.keySize
const bits = initOpts.bits ? initOpts.bits : this.bits
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this repeating part of line 61?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init also accepts a keysize

const args = ['init']
// do not just set a default keysize,
// in case we decide to change it at
// the daemon level in the future
Copy link
Member

Choose a reason for hiding this comment

The 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"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, ipfs daemons have a default keysize when using ipfs init - if we pass a value with ipfs init -b <keysize>, we're overriding that default (we're currently doing that in latest master). I don't think that is correct and we should rely on the default used by the daemon internally.

if (keySize) {
args.concat(['-b', keySize])
if (bits) {
args.concat(['-b', bits])
}
if (initOpts.pass) {
args.push('--pass')
args.push('"' + initOpts.pass + '"')
}
log(`initializing with keysize: ${keySize}`)
log(`initializing with keysize: ${bits}`)
run(this, args, { env: this.env }, (err, result) => {
if (err) {
return callback(err)
Expand Down
17 changes: 6 additions & 11 deletions src/ipfsd-in-proc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Node {
this._started = false
this.initialized = false
this.api = null
this.keySize = null
this.bits = null

this.opts.EXPERIMENTAL = defaults({}, opts.EXPERIMENTAL, {
pubsub: false,
Expand All @@ -57,12 +57,7 @@ class Node {
}
})

// option takes precedence over env variable
if (typeof this.opts.init === 'object') {
this.keySize = this.opts.init.keySize
} else if (process.env.IPFS_KEYSIZE) {
this.keySize = process.env.IPFS_KEYSIZE
}
this.bits = this.opts.initOpts ? this.opts.initOpts.bits : process.env.IPFS_KEYSIZE

this.exec = new IPFS({
repo: this.repo,
Expand Down Expand Up @@ -123,7 +118,7 @@ class Node {
* 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
Expand All @@ -135,12 +130,12 @@ class Node {
initOpts = {}
}

const keySize = initOpts.keysize ? initOpts.keysize : this.keySize
const bits = initOpts.keysize ? initOpts.bits : this.bits
// do not just set a default keysize,
// in case we decide to change it at
// the daemon level in the future
if (keySize) {
initOpts.bits = keySize
if (bits) {
initOpts.bits = bits
}
this.exec.init(initOpts, (err) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion test/spawn-options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe('Spawn options', () => {
})
})

describe('custom init options', () => {
describe('custom config options', () => {
it('custom config', function (done) {
this.timeout(40 * 1000)

Expand Down