Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 7783805

Browse files
committed
fix: add extend, fixes #2579
1 parent 4f39db8 commit 7783805

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
"qs": "^6.5.2",
214214
"rimraf": "^3.0.0",
215215
"sinon": "^7.4.2",
216-
"stardust4ipfs": "^0.1.2",
216+
"stardust4ipfs": "^0.1.3",
217217
"stream-to-promise": "^2.2.0",
218218
"temp-write": "^4.0.0"
219219
},

src/core/components/libp2p.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,23 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) {
134134
}
135135

136136
const libp2pUserOptions = get(options, 'libp2p', {})
137+
let libp2pExtend = get(options, 'libp2p.extend', false)
137138

138139
let libp2pOptions = libp2pDefaults
139140

140141
// allow user to specify overrideFunction, while at the same time allowing static arguments
141142
if (libp2pUserOptions.overrideFunction && typeof libp2pUserOptions.overrideFunction === 'function') {
142-
libp2pOptions = mergeOptions(libp2pOptions, libp2pUserOptions.overrideFunction({ datastore, peerInfo, peerBook, options, config }))
143+
const override = libp2pUserOptions.overrideFunction({ datastore, peerInfo, peerBook, options, config })
144+
145+
if (override.extend != null) {
146+
libp2pExtend = override.extend
147+
}
148+
149+
libp2pOptions = mergeOptions.call({ concatArrays: libp2pExtend }, libp2pOptions, override)
143150
delete libp2pUserOptions.overrideFunction
144151
}
145152

146-
libp2pOptions = mergeOptions(libp2pOptions, libp2pUserOptions)
153+
libp2pOptions = mergeOptions.call({ concatArrays: libp2pExtend }, libp2pOptions, libp2pUserOptions)
147154

148155
// Required inline to reduce startup time
149156
// Note: libp2p-nodejs gets replaced by libp2p-browser when webpacked/browserified

src/core/runtime/libp2p-browser.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class Node extends libp2p {
1414
constructor (_options) {
1515
const wrtcstar = new WebRTCStar({ id: _options.peerInfo.id })
1616

17+
const { extend } = _options
18+
delete _options.extend
19+
1720
const defaults = {
1821
switch: {
1922
denyTTL: 2 * 60 * 1e3, // 2 minute base
@@ -63,7 +66,7 @@ class Node extends libp2p {
6366
}
6467
}
6568

66-
super(mergeOptions(defaults, _options))
69+
super(mergeOptions.call({ concatArrays: extend }, defaults, _options))
6770
}
6871
}
6972

src/core/runtime/libp2p-nodejs.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const mergeOptions = require('merge-options')
1313

1414
class Node extends libp2p {
1515
constructor (_options) {
16+
const { extend } = _options
17+
delete _options.extend
18+
1619
const defaults = {
1720
switch: {
1821
denyTTL: 2 * 60 * 1e3, // 2 minute base
@@ -66,7 +69,7 @@ class Node extends libp2p {
6669
}
6770
}
6871

69-
super(mergeOptions(defaults, _options))
72+
super(mergeOptions.call({ concatArrays: extend }, defaults, _options))
7073
}
7174
}
7275

0 commit comments

Comments
 (0)