Skip to content

Commit

Permalink
feat: use default daemon addrs (#220)
Browse files Browse the repository at this point in the history
* feat: use default daemon addrs

* fix: uncomment go and js test

* chore: lint

* wip: skip dafault addr tests

* wip: skip dafault addr tests

* feat: upgrade to go-ipfs-0.4.14

* chore: release version v0.31.0

* fix: review
  • Loading branch information
dryajov authored and daviddias committed Apr 2, 2018
1 parent 1371f0f commit 510b320
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
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
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

0 comments on commit 510b320

Please sign in to comment.