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 all 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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<a name="0.31.0"></a>
# [0.31.0](https://github.com/ipfs/js-ipfsd-ctl/compare/v0.30.4...v0.31.0) (2018-03-27)


### Features

* upgrade to go-ipfs-0.4.14 ([77b4cd9](https://github.com/ipfs/js-ipfsd-ctl/commit/77b4cd9))



<a name="0.30.4"></a>
## [0.30.4](https://github.com/ipfs/js-ipfsd-ctl/compare/v0.30.3...v0.30.4) (2018-03-21)

Expand Down
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ipfsd-ctl",
"version": "0.30.4",
"version": "0.31.0",
"description": "Spawn IPFS Daemons, JS or Go",
"main": "src/index.js",
"scripts": {
Expand Down Expand Up @@ -104,7 +104,7 @@
"cross-env": "^5.1.4",
"detect-port": "^1.2.2",
"dirty-chai": "^2.0.1",
"go-ipfs-dep": "0.4.13",
"go-ipfs-dep": "0.4.14",
"ipfs": "~0.28.2",
"is-running": "1.0.5",
"mkdirp": "^0.5.1",
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
44 changes: 44 additions & 0 deletions test/spawn-options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,50 @@ describe('Spawn options', function () {
})
})

// TODO re-enable when jenkins runs tests in isolation
describe.skip('spawn with default swarm addrs', () => {
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
2 changes: 1 addition & 1 deletion test/start-stop.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ tests.forEach((fOpts) => {
ipfsd.start(['--should-not-exist'], (err) => {
expect(err).to.exist()
expect(err.message)
.to.match(/Unrecognized option 'should-not-exist'/)
.to.match(/unknown option "should-not-exist"\n/)

done()
})
Expand Down