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: use default daemon addrs #220

Merged
merged 8 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Spawn the daemon
- `start` bool (default true) - should the node be started
- `repoPath` string - the repository path to use for this node, ignored if node is disposable
- `disposable` bool (default true) - a new repo is created and initialized for each invocation, as well as cleaned up automatically once the process exits
- `defaultAddrs` bool (default false) - use the daemon default `Swarm` addrs
- `args` - array of cmd line arguments to be passed to ipfs daemon
- `config` - ipfs configuration options

Expand Down
8 changes: 5 additions & 3 deletions src/factory-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class FactoryDaemon {
* - `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
* - `defaultAddrs` bool (default false) - use the daemon default `Swarm` addrs
* - `config` - ipfs configuration options
* - `args` - array of cmd line arguments to be passed to ipfs daemon
* - `exec` string (optional) - path to the desired IPFS executable to spawn,
Expand All @@ -104,9 +105,6 @@ class FactoryDaemon {

if (!options.disposable) {
const nonDisposableConfig = clone(defaultConfig)
// TODO Why delete these?
// delete nonDisposableConfig.Addresses

options.init = false
options.start = false

Expand All @@ -124,6 +122,10 @@ class FactoryDaemon {
options.config = defaultsDeep({}, options.config, defaultConfig)
}

if (options.defaultAddrs) {
delete options.config.Addresses
}

options.type = this.type
options.exec = options.exec || this.exec

Expand Down
10 changes: 6 additions & 4 deletions src/factory-in-proc.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ class FactoryInProc {
* Spawn JSIPFS instances
*
* Options are:
* - `init` {bool|Object} - should the node be initialized
* - `init` bool - should the node be initialized
* - `initOptions` 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
* - `defaultAddrs` bool (default false) - use the daemon default `Swarm` addrs
* - `config` - ipfs configuration options
* - `args` - array of cmd line arguments to be passed to ipfs daemon
* - `exec` string (optional) - path to the desired IPFS executable to spawn,
Expand All @@ -105,9 +106,6 @@ class FactoryInProc {
options.config = defaults({}, options.config, defaultConfig)
} else {
const nonDisposableConfig = clone(defaultConfig)
// TODO why delete the addrs here???
// delete nonDisposableConfig.Addresses

options.init = false
options.start = false

Expand All @@ -120,6 +118,10 @@ class FactoryInProc {
options.config = defaults({}, options.config, nonDisposableConfig)
}

if (options.defaultAddrs) {
delete options.config.Addresses
}

options.type = this.type
options.exec = options.exec || this.exec

Expand Down
46 changes: 46 additions & 0 deletions test/spawn-options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const versions = {
proc: jsVersion
}

const dscskip = describe.skip

describe('Spawn options', function () {
this.timeout(20 * 1000)

Expand Down Expand Up @@ -186,6 +188,50 @@ describe('Spawn options', function () {
})
})

// TODO re-enable when jenkins runs tests in isolation
dscskip('spawn with default swarm addrs', () => {
Copy link
Member

Choose a reason for hiding this comment

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

just replace for describe.skip, it is just being used once

const addrs = {
go: [
'/ip4/0.0.0.0/tcp/4001',
'/ip6/::/tcp/4001'
],
js: [
'/ip4/0.0.0.0/tcp/4002',
'/ip4/127.0.0.1/tcp/4003/ws'
],
proc: [
'/ip4/0.0.0.0/tcp/4002',
'/ip4/127.0.0.1/tcp/4003/ws'
]
}

it('swarm contains default addrs', function (done) {
this.timeout(20 * 1000)

if (!isNode && fOpts.type === 'proc') {
this.skip()
}

f.spawn({
defaultAddrs: true,
initOptions: {
bits: fOpts.bits
}
}, (err, ipfsd) => {
expect(err).to.not.exist()
ipfsd.getConfig('Addresses.Swarm', (err, config) => {
expect(err).to.not.exist()
if (fOpts.type !== 'proc') {
config = JSON.parse(config)
}

expect(config).to.deep.equal(addrs[fOpts.type])
ipfsd.stop(done)
})
})
})
})

describe('custom config options', () => {
it('custom config', function (done) {
this.timeout(50 * 1000)
Expand Down