Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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())
}
return ipfsNodeConfig
}
const getPlugins = async ({
input,
output,
isDevelopmentMode,
}) => {
const inputFolder = path.dirname(input);
const port = await getPort({
port: getPort.makeRange(3000, 3100),
});
return isDevelopmentMode
// Dev plugins
? [
sourcemaps(),
serve({
// Launch in browser
open: true,
contentBase: output,
port,
verbose: true,
}),
livereload({
watch: [
output,
inputFolder,
const specFileExists = await fs.pathExists(specStorePath)
if (specFileExists) {
try {
const specFileContents = await fs.readJson(specStorePath)
if (!Array.isArray(specFileContents)) {
throw new Error('not array')
}
} catch (e) {
return this.error(fromOptic('It looks like there is something wrong with your API spec file. Please make sure it is a valid JSON array.'))
}
}
await emitGitState()
const port = await getPort({port: getPort.makeRange(3201, 3299)})
const sessionUtilities = new SessionUtilities(sessionsPath)
const sessionValidatorAndLoader = new FileSystemSessionValidatorAndLoader(sessionUtilities)
const paths = await getPaths()
await startServer(paths, sessionValidatorAndLoader, port, config)
const url = `http://localhost:${port}/`
this.log(fromOptic('Displaying your API Spec at ' + url))
await open(url)
await cli.wait(1000)
await cli.anykey('Press any key to exit')
return process.exit()
}
}
async start() {
this.options.devToolsPort = await getPort({
port: getPort.makeRange(9222, 9350),
host: '127.0.0.1'
});
if (get(this.options, 'connectivity.tsproxy.port') === undefined) {
set(
this.options,
'connectivity.tsproxy.port',
await getPort({
port: getPort.makeRange(1080, 1099),
host: '127.0.0.1'
})
);
}
if (!this.options.connectivity.variance) {
await addConnectivity(this.options);
}
return Promise.all([this.myXVFB.start(), this.myExtensionServer.start()]);
}
const configApiMa = parseCfgMultiaddr(config.Addresses.API)
const configGatewayMa = parseCfgMultiaddr(config.Addresses.Gateway)
const isApiMaDaemon = await checkIfAddrIsDaemon(configApiMa.nodeAddress())
const isGatewayMaDaemon = await checkIfAddrIsDaemon(configGatewayMa.nodeAddress())
if (isApiMaDaemon && isGatewayMaDaemon) {
logger.info('[daemon] ports busy by a daemon')
return
}
const apiPort = parseInt(configApiMa.nodeAddress().port, 10)
const gatewayPort = parseInt(configGatewayMa.nodeAddress().port, 10)
const freeGatewayPort = await getPort({ port: getPort.makeRange(gatewayPort, gatewayPort + 100) })
const freeApiPort = await getPort({ port: getPort.makeRange(apiPort, apiPort + 100) })
const busyApiPort = apiPort !== freeApiPort
const busyGatewayPort = gatewayPort !== freeGatewayPort
if (!busyApiPort && !busyGatewayPort) {
return
}
let message = null
let options = null
if (busyApiPort && busyGatewayPort) {
logger.info('[daemon] api and gateway ports busy')
message = 'busyPortsDialog'
options = {
port1: apiPort,
const configApiMa = parseCfgMultiaddr(config.Addresses.API)
const configGatewayMa = parseCfgMultiaddr(config.Addresses.Gateway)
const isApiMaDaemon = await checkIfAddrIsDaemon(configApiMa.nodeAddress())
const isGatewayMaDaemon = await checkIfAddrIsDaemon(configGatewayMa.nodeAddress())
if (isApiMaDaemon && isGatewayMaDaemon) {
logger.info('[daemon] ports busy by a daemon')
return
}
const apiPort = parseInt(configApiMa.nodeAddress().port, 10)
const gatewayPort = parseInt(configGatewayMa.nodeAddress().port, 10)
const freeGatewayPort = await getPort({ port: getPort.makeRange(gatewayPort, gatewayPort + 100) })
const freeApiPort = await getPort({ port: getPort.makeRange(apiPort, apiPort + 100) })
const busyApiPort = apiPort !== freeApiPort
const busyGatewayPort = gatewayPort !== freeGatewayPort
if (!busyApiPort && !busyGatewayPort) {
return
}
let message = null
let options = null
if (busyApiPort && busyGatewayPort) {
logger.info('[daemon] api and gateway ports busy')
message = 'busyPortsDialog'
options = {
(async () => {
let enginePort = await getPort({
host: "127.0.0.1",
port: getPort.makeRange(3050, 3150)
});
if (global.server === undefined) {
global.server = new WeatherServer(enginePort);
global.client = new WeatherClient("localhost", enginePort);
global.server.startEngine();
}
})();
});
for (const addr of addrs) {
const ma = parseCfgMultiaddr(addr)
const port = parseInt(ma.nodeAddress().port, 10)
if (port === 0) {
continue
}
const isDaemon = await checkIfAddrIsDaemon(ma.nodeAddress())
if (isDaemon) {
continue
}
const freePort = await getPort({ port: getPort.makeRange(port, port + 100) })
if (port !== freePort) {
const opt = showDialog({
title: i18n.t('multipleBusyPortsDialog.title'),
message: i18n.t('multipleBusyPortsDialog.message'),
type: 'error',
buttons: [
i18n.t('multipleBusyPortsDialog.action'),
i18n.t('close')
]
})
if (opt === 0) {
shell.openItem(join(ipfsd.repoPath, 'config'))
}
(async () => {
const port = await getPort({port: getPort.makeRange(5000, 5100)});
this.setPort(port);
this.createTCPServer();
})();
}