Skip to content

Commit

Permalink
fix: add extend, fixes ipfs#2579
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Nov 1, 2019
1 parent b4d11e8 commit d83fd68
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
"qs": "^6.5.2",
"rimraf": "^3.0.0",
"sinon": "^7.4.2",
"stardust4ipfs": "^0.1.2",
"stardust4ipfs": "^0.1.3",
"stream-to-promise": "^2.2.0",
"temp-write": "^4.0.0"
},
Expand Down
11 changes: 9 additions & 2 deletions src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,23 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) {
}

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

let libp2pOptions = libp2pDefaults

// allow user to specify overrideFunction, while at the same time allowing static arguments
if (libp2pUserOptions.overrideFunction && typeof libp2pUserOptions.overrideFunction === 'function') {
libp2pOptions = mergeOptions(libp2pOptions, libp2pUserOptions.overrideFunction({ datastore, peerInfo, peerBook, options, config }))
const override = libp2pUserOptions.overrideFunction({ datastore, peerInfo, peerBook, options, config })

if (override.extend != null) {
libp2pExtend = override.extend
}

libp2pOptions = mergeOptions.call({ concatArrays: libp2pExtend }, libp2pOptions, override)
delete libp2pUserOptions.overrideFunction
}

libp2pOptions = mergeOptions(libp2pOptions, libp2pUserOptions)
libp2pOptions = mergeOptions.call({ concatArrays: libp2pExtend }, libp2pOptions, libp2pUserOptions)

// Required inline to reduce startup time
// Note: libp2p-nodejs gets replaced by libp2p-browser when webpacked/browserified
Expand Down
5 changes: 4 additions & 1 deletion src/core/runtime/libp2p-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class Node extends libp2p {
constructor (_options) {
const wrtcstar = new WebRTCStar({ id: _options.peerInfo.id })

const { extend } = _options
delete _options.extend

const defaults = {
switch: {
denyTTL: 2 * 60 * 1e3, // 2 minute base
Expand Down Expand Up @@ -63,7 +66,7 @@ class Node extends libp2p {
}
}

super(mergeOptions(defaults, _options))
super(mergeOptions.call({ concatArrays: extend }, defaults, _options))
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/core/runtime/libp2p-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const mergeOptions = require('merge-options')

class Node extends libp2p {
constructor (_options) {
const { extend } = _options
delete _options.extend

const defaults = {
switch: {
denyTTL: 2 * 60 * 1e3, // 2 minute base
Expand Down Expand Up @@ -66,7 +69,7 @@ class Node extends libp2p {
}
}

super(mergeOptions(defaults, _options))
super(mergeOptions.call({ concatArrays: extend }, defaults, _options))
}
}

Expand Down

0 comments on commit d83fd68

Please sign in to comment.