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
2 changes: 1 addition & 1 deletion src/endpoint/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.exports = (server) => {
return reply(boom.badRequest(err))
}

reply({ initialized: true })
reply({ initialized: nodes[id].initialized })
})
},
config: routeConfig
Expand Down
11 changes: 5 additions & 6 deletions src/ipfsd-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Daemon {
this._gatewayAddr = null
this._started = false
this.api = null
this.bits = process.env.IPFS_KEYSIZE || (this.opts.initOptions ? this.opts.initOptions.bits : null)
this.bits = this.opts.initOptions ? this.opts.initOptions.bits : null

if (this.opts.env) {
Object.assign(this.env, this.opts.env)
Expand Down Expand Up @@ -121,7 +121,7 @@ class Daemon {
* @returns {undefined}
*/
init (initOptions, callback) {
if (!callback) {
if (typeof initOptions === 'function') {
callback = initOptions
initOptions = {}
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean that is mandatory to always pass a initOptions object? There should be a check to see if initOptions is a func.

Copy link
Member Author

Choose a reason for hiding this comment

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

we're checking for !callback which is not consistent with how do it elsewhere (leftover from prev codebase), I'll change it. Good catch.

}
Expand Down Expand Up @@ -368,10 +368,9 @@ class Daemon {
*/
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...
// TODO: we're using tmp file here until
// https://github.com/ipfs/js-ipfs/pull/785
// is ready
series([
(cb) => fs.writeFile(tmpFile, safeStringify(config), cb),
(cb) => run(
Expand Down
4 changes: 2 additions & 2 deletions src/ipfsd-in-proc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Node {
this._started = false
this.initialized = false
this.api = null
this.bits = process.env.IPFS_KEYSIZE || (this.opts.initOptions ? this.opts.initOptions.bits : null)
this.bits = this.opts.initOptions ? this.opts.initOptions.bits : null

this.opts.EXPERIMENTAL = defaultsDeep({}, opts.EXPERIMENTAL, {
pubsub: false,
Expand Down Expand Up @@ -126,7 +126,7 @@ class Node {
* @returns {undefined}
*/
init (initOptions, callback) {
if (!callback) {
if (typeof initOptions === 'function') {
callback = initOptions
initOptions = {}
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

}
Expand Down
14 changes: 6 additions & 8 deletions test/add-retrieve.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const IPFSFactory = require('../src')
const JSIPFS = require('ipfs')

const tests = [
{ type: 'go' },
{ type: 'js' },
{ type: 'go', bits: 1024 },
{ type: 'js', bits: 512 },
{ type: 'proc', exec: JSIPFS }
Copy link
Member

Choose a reason for hiding this comment

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

Don't forget about his one.

]
Copy link
Member

Choose a reason for hiding this comment

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

The proc node also should receive the bits.


Expand All @@ -21,13 +21,11 @@ describe('data can be put and fetched', () => {
let ipfsd

before(function (done) {
this.timeout(30 * 1000)
this.timeout(20 * 1000)

const f = IPFSFactory.create(dfOpts)

f.spawn({
initOptions: { bits: 1024 }
}, (err, _ipfsd) => {
f.spawn({ initOptions: { bits: dfOpts.bits } }, (err, _ipfsd) => {
expect(err).to.not.exist()
expect(_ipfsd).to.exist()
expect(_ipfsd.api).to.exist()
Expand All @@ -39,12 +37,12 @@ describe('data can be put and fetched', () => {
})

after(function (done) {
this.timeout(30 * 1000)
this.timeout(20 * 1000)
ipfsd.stop(done)
})

it('put and fetch a block', function (done) {
this.timeout(30 * 1000)
this.timeout(20 * 1000)

const data = Buffer.from('blorb')

Expand Down
4 changes: 2 additions & 2 deletions test/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('ipfsd.api for Daemons', () => {
})

it('test the ipfsd.api', function (done) {
this.timeout(40 * 1000)
this.timeout(20 * 1000)

// TODO skip in browser - can we avoid using file system operations here?
if (!isNode) { this.skip() }
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('ipfsd.api for Daemons', () => {
})

it('check if API and Gateway addrs are correct', function (done) {
this.timeout(30 * 1000)
this.timeout(20 * 1000)

df.spawn({
config: config,
Expand Down
83 changes: 44 additions & 39 deletions test/spawn-options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const os = require('os')
const isWindows = os.platform() === 'win32'

const tests = [
{ type: 'go' },
{ type: 'js' },
{ type: 'go', bits: 1024 },
{ type: 'js', bits: 512 },
{ type: 'proc', exec: JSIPFS }
]

Expand Down Expand Up @@ -72,7 +72,8 @@ describe('Spawn options', () => {
repoPath: repoPath,
init: false,
start: false,
disposable: false
disposable: false,
initOptions: { bits: fOpts.bits }
}

f.spawn(options, (err, _ipfsd) => {
Expand All @@ -89,12 +90,11 @@ describe('Spawn options', () => {
it('ipfsd.init', function (done) {
this.timeout(20 * 1000)

ipfsd.init({ bits: 1024 },
(err) => {
expect(err).to.not.exist()
expect(ipfsd.initialized).to.be.ok()
done()
})
ipfsd.init((err) => {
expect(err).to.not.exist()
expect(ipfsd.initialized).to.be.ok()
done()
})
})

it('ipfsd.start', function (done) {
Expand All @@ -116,9 +116,6 @@ 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 }

// TODO: figure out why `proc` IPFS refuses
// to start with a provided repo
// `Error: Not able to start from state: uninitalized`
Expand All @@ -127,6 +124,9 @@ describe('Spawn options', () => {
let ipfsd

it('f.spawn', function (done) {
// TODO: wont work on windows until we get `/shutdown` implemented in js-ipfs
if (isWindows) { return }

this.timeout(20 * 1000)

const options = {
Expand All @@ -147,6 +147,9 @@ describe('Spawn options', () => {
})

it('ipfsd.start', function (done) {
// TODO: wont work on windows until we get `/shutdown` implemented in js-ipfs
if (isWindows) { return }

this.timeout(20 * 1000)

ipfsd.start((err, api) => {
Expand All @@ -158,6 +161,9 @@ describe('Spawn options', () => {
})

it('ipfsd.stop', function (done) {
// TODO: wont work on windows until we get `/shutdown` implemented in js-ipfs
if (isWindows) { return }

this.timeout(20 * 1000)

ipfsd.stop(done)
Expand All @@ -170,31 +176,30 @@ describe('Spawn options', () => {
let ipfsd

it('create init and start node', function (done) {
this.timeout(30 * 1000)
this.timeout(20 * 1000)

f.spawn({
initOptions: { bits: 1024 }
}, (err, _ipfsd) => {
expect(err).to.not.exist()
expect(_ipfsd).to.exist()
expect(_ipfsd.api).to.exist()
expect(_ipfsd.api.id).to.exist()
f.spawn({ initOptions: { bits: fOpts.bits } },
(err, _ipfsd) => {
expect(err).to.not.exist()
expect(_ipfsd).to.exist()
expect(_ipfsd.api).to.exist()
expect(_ipfsd.api.id).to.exist()

ipfsd = _ipfsd
done()
})
ipfsd = _ipfsd
done()
})
})

it('ipfsd.stop', function (done) {
this.timeout(30 * 1000)
this.timeout(20 * 1000)

ipfsd.stop(done)
})
})

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

const addr = '/ip4/127.0.0.1/tcp/5678'
const swarmAddr1 = '/ip4/127.0.0.1/tcp/35666'
Expand All @@ -207,7 +212,7 @@ describe('Spawn options', () => {
}
}

const options = { config: config, initOptions: { bits: 1024 } }
const options = { config: config, initOptions: { bits: fOpts.bits } }

waterfall([
(cb) => f.spawn(options, cb),
Expand Down Expand Up @@ -251,7 +256,7 @@ describe('Spawn options', () => {
})

it('allows passing custom repo path to spawn', function (done) {
this.timeout(50 * 1000)
this.timeout(20 * 1000)

const config = {
Addresses: {
Expand All @@ -269,7 +274,8 @@ describe('Spawn options', () => {
init: false,
start: false,
repoPath: repoPath,
config: config
config: config,
initOptions: { bits: fOpts.bits }
}

series([
Expand All @@ -279,7 +285,7 @@ describe('Spawn options', () => {
cb()
}),
(cb) => {
ipfsd.init({ bits: 1024 }, cb)
ipfsd.init(cb)
},
(cb) => {
ipfsd.start(cb)
Expand Down Expand Up @@ -309,7 +315,7 @@ describe('Spawn options', () => {

const options = {
args: ['--enable-pubsub-experiment'],
initOptions: { bits: 1024 }
initOptions: { bits: fOpts.bits }
}

f.spawn(options, (err, _ipfsd) => {
Expand Down Expand Up @@ -347,18 +353,17 @@ describe('Spawn options', () => {
let ipfsd

before(function (done) {
this.timeout(50 * 1000)
f.spawn({
initOptions: { bits: 1024 }
}, (err, _ipfsd) => {
expect(err).to.not.exist()
ipfsd = _ipfsd
done()
})
this.timeout(20 * 1000)
f.spawn({ initOptions: { bits: fOpts.bits } },
(err, _ipfsd) => {
expect(err).to.not.exist()
ipfsd = _ipfsd
done()
})
})

after(function (done) {
this.timeout(50 * 1000)
this.timeout(20 * 1000)
ipfsd.stop(done)
})

Expand Down
Loading