Skip to content

Commit 510b320

Browse files
dryajovdaviddias
authored andcommitted
feat: use default daemon addrs (#220)
* 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
1 parent 1371f0f commit 510b320

File tree

4 files changed

+56
-7
lines changed

4 files changed

+56
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Spawn the daemon
120120
- `start` bool (default true) - should the node be started
121121
- `repoPath` string - the repository path to use for this node, ignored if node is disposable
122122
- `disposable` bool (default true) - a new repo is created and initialized for each invocation, as well as cleaned up automatically once the process exits
123+
- `defaultAddrs` bool (default false) - use the daemon default `Swarm` addrs
123124
- `args` - array of cmd line arguments to be passed to ipfs daemon
124125
- `config` - ipfs configuration options
125126

src/factory-daemon.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class FactoryDaemon {
7979
* - `start` bool - should the node be started
8080
* - `repoPath` string - the repository path to use for this node, ignored if node is disposable
8181
* - `disposable` bool - a new repo is created and initialized for each invocation
82+
* - `defaultAddrs` bool (default false) - use the daemon default `Swarm` addrs
8283
* - `config` - ipfs configuration options
8384
* - `args` - array of cmd line arguments to be passed to ipfs daemon
8485
* - `exec` string (optional) - path to the desired IPFS executable to spawn,
@@ -104,9 +105,6 @@ class FactoryDaemon {
104105

105106
if (!options.disposable) {
106107
const nonDisposableConfig = clone(defaultConfig)
107-
// TODO Why delete these?
108-
// delete nonDisposableConfig.Addresses
109-
110108
options.init = false
111109
options.start = false
112110

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

125+
if (options.defaultAddrs) {
126+
delete options.config.Addresses
127+
}
128+
127129
options.type = this.type
128130
options.exec = options.exec || this.exec
129131

src/factory-in-proc.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ class FactoryInProc {
7676
* Spawn JSIPFS instances
7777
*
7878
* Options are:
79-
* - `init` {bool|Object} - should the node be initialized
79+
* - `init` bool - should the node be initialized
8080
* - `initOptions` Object, it is expected to be of the form `{bits: <size>}`, which sets the desired key size
8181
* - `start` bool - should the node be started
8282
* - `repoPath` string - the repository path to use for this node, ignored if node is disposable
8383
* - `disposable` bool - a new repo is created and initialized for each invocation
84+
* - `defaultAddrs` bool (default false) - use the daemon default `Swarm` addrs
8485
* - `config` - ipfs configuration options
8586
* - `args` - array of cmd line arguments to be passed to ipfs daemon
8687
* - `exec` string (optional) - path to the desired IPFS executable to spawn,
@@ -105,9 +106,6 @@ class FactoryInProc {
105106
options.config = defaults({}, options.config, defaultConfig)
106107
} else {
107108
const nonDisposableConfig = clone(defaultConfig)
108-
// TODO why delete the addrs here???
109-
// delete nonDisposableConfig.Addresses
110-
111109
options.init = false
112110
options.start = false
113111

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

121+
if (options.defaultAddrs) {
122+
delete options.config.Addresses
123+
}
124+
123125
options.type = this.type
124126
options.exec = options.exec || this.exec
125127

test/spawn-options.spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,50 @@ describe('Spawn options', function () {
186186
})
187187
})
188188

189+
// TODO re-enable when jenkins runs tests in isolation
190+
describe.skip('spawn with default swarm addrs', () => {
191+
const addrs = {
192+
go: [
193+
'/ip4/0.0.0.0/tcp/4001',
194+
'/ip6/::/tcp/4001'
195+
],
196+
js: [
197+
'/ip4/0.0.0.0/tcp/4002',
198+
'/ip4/127.0.0.1/tcp/4003/ws'
199+
],
200+
proc: [
201+
'/ip4/0.0.0.0/tcp/4002',
202+
'/ip4/127.0.0.1/tcp/4003/ws'
203+
]
204+
}
205+
206+
it('swarm contains default addrs', function (done) {
207+
this.timeout(20 * 1000)
208+
209+
if (!isNode && fOpts.type === 'proc') {
210+
this.skip()
211+
}
212+
213+
f.spawn({
214+
defaultAddrs: true,
215+
initOptions: {
216+
bits: fOpts.bits
217+
}
218+
}, (err, ipfsd) => {
219+
expect(err).to.not.exist()
220+
ipfsd.getConfig('Addresses.Swarm', (err, config) => {
221+
expect(err).to.not.exist()
222+
if (fOpts.type !== 'proc') {
223+
config = JSON.parse(config)
224+
}
225+
226+
expect(config).to.deep.equal(addrs[fOpts.type])
227+
ipfsd.stop(done)
228+
})
229+
})
230+
})
231+
})
232+
189233
describe('custom config options', () => {
190234
it('custom config', function (done) {
191235
this.timeout(50 * 1000)

0 commit comments

Comments
 (0)