Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function buildConfig (opts) {
const defaultOpts = JSON.parse(optionDefaults.ipfsNodeConfig)
defaultOpts.libp2p = {
config: {
dht: {
// TODO: check if below is needed after js-ipfs is released with DHT disabled
enabled: false
}
}
}
const userOpts = JSON.parse(opts.ipfsNodeConfig)
const ipfsNodeConfig = mergeOptions.call({ concatArrays: true }, defaultOpts, userOpts, { start: false })
// Detect when API or Gateway port is not available (taken by something else)
// We find the next free port and update configuration to use it instead
const multiaddr2port = (ma) => parseInt(new URL(multiaddr2httpUrl(ma)).port, 10)
const gatewayPort = multiaddr2port(ipfsNodeConfig.config.Addresses.Gateway)
const apiPort = multiaddr2port(ipfsNodeConfig.config.Addresses.API)
log(`checking if ports are available: api: ${apiPort}, gateway: ${gatewayPort}`)
const freeGatewayPort = await getPort({ port: getPort.makeRange(gatewayPort, gatewayPort + 100) })
const freeApiPort = await getPort({ port: getPort.makeRange(apiPort, apiPort + 100) })
if (gatewayPort !== freeGatewayPort || apiPort !== freeApiPort) {
log(`updating config to available ports: api: ${freeApiPort}, gateway: ${freeGatewayPort}`)
const addrs = ipfsNodeConfig.config.Addresses
addrs.Gateway = addrs.Gateway.replace(gatewayPort.toString(), freeGatewayPort.toString())
addrs.API = addrs.API.replace(apiPort.toString(), freeApiPort.toString())
}
module.exports = (blockService, options) => {
options = options || {}
return mergeOptions.call(
// ensure we have the defaults formats even if the user overrides `formats: []`
{ concatArrays: true },
{
blockService: blockService,
formats: [ipldDagCbor, ipldDagPb, ipldRaw]
}, options)
}
module.exports = (blockService, options) => {
options = options || {}
return mergeOptions.call(
// ensure we have the defaults formats even if the user overrides `formats: []`
{ concatArrays: true },
{
blockService: blockService,
formats: [
require('ipld-dag-cbor'),
require('ipld-dag-pb'),
require('ipld-raw'),
require('ipld-bitcoin'),
require('ipld-ethereum').ethAccountSnapshot,
require('ipld-ethereum').ethBlock,
require('ipld-ethereum').ethBlockList,
require('ipld-ethereum').ethStateTrie,
require('ipld-ethereum').ethStorageTrie,
require('ipld-ethereum').ethTx,
require('ipld-ethereum').ethTxTrie,
module.exports = (blockService, options, log) => {
options = options || {}
return mergeOptions.call(
// ensure we have the defaults formats even if the user overrides `formats: []`
{ concatArrays: true },
{
blockService: blockService,
loadFormat: (codec) => {
log('Loading IPLD format', codec)
if (IpldFormats[codec]) {
return IpldFormats[codec]
} else {
throw new Error(`Missing IPLD format "${codec}"`)
}
}
}, options)
}
function getBatchOptions(config: DuckConfig): AwsOptions | LocalOptions {
const { batchOptions = {} } = config;
return mergeOptions.call({ concatArrays: true }, defaultBatchOptions(config), batchOptions);
}
constructor (libp2p, options) {
this._libp2p = libp2p
this._registrar = libp2p.registrar
this._peerId = libp2p.peerInfo.id.toString()
this._options = mergeOptions.call({ ignoreUndefined: true }, defaultOptions, options)
assert(
this._options.maxConnections > this._options.minConnections,
'Connection Manager maxConnections must be greater than minConnections'
)
debug('options: %j', this._options)
this._metrics = libp2p.metrics
this._peerValues = new Map()
this._connections = new Map()
this._timer = null
this._checkMetrics = this._checkMetrics.bind(this)
}