From 1e821029b75d5e5847cdd26007631e0bc6861477 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Fri, 12 Apr 2019 12:10:53 +0200 Subject: [PATCH] refactor: rename StandaloneDaemon to Daemon License: MIT Signed-off-by: Marcin Rataj --- src/cli/commands/daemon.js | 14 ++++++++++++-- src/cli/{standalone-daemon.js => daemon.js} | 12 +++++++++--- src/http/index.js | 17 ----------------- test/gateway/index.js | 4 ++-- test/http-api/routes.js | 4 ++-- 5 files changed, 25 insertions(+), 26 deletions(-) rename src/cli/{standalone-daemon.js => daemon.js} (88%) diff --git a/src/cli/commands/daemon.js b/src/cli/commands/daemon.js index a274a30bb6..570cd56a86 100644 --- a/src/cli/commands/daemon.js +++ b/src/cli/commands/daemon.js @@ -1,6 +1,7 @@ 'use strict' const os = require('os') +const toUri = require('multiaddr-to-uri') const { getRepoPath, print, ipfsPathHelp } = require('../utils') module.exports = { @@ -44,8 +45,8 @@ module.exports = { const repoPath = getRepoPath() // Required inline to reduce startup time - const StandaloneDaemon = require('../../cli/standalone-daemon') - const daemon = new StandaloneDaemon({ + const Daemon = require('../../cli/daemon') + const daemon = new Daemon({ silent: argv.silent, repo: process.env.IPFS_PATH, offline: argv.offline, @@ -61,6 +62,15 @@ module.exports = { try { await daemon.start() + daemon._httpApi._apiServers.forEach(apiServer => { + print(`API listening on ${apiServer.info.ma.toString()}`) + }) + daemon._httpApi._gatewayServers.forEach(gatewayServer => { + print(`Gateway (read only) listening on ${gatewayServer.info.ma.toString()}`) + }) + daemon._httpApi._apiServers.forEach(apiServer => { + print(`Web UI available at ${toUri(apiServer.info.ma)}/webui`) + }) } catch (err) { if (err.code === 'ENOENT' && err.message.match(/uninitialized/i)) { print('Error: no initialized ipfs repo found in ' + repoPath) diff --git a/src/cli/standalone-daemon.js b/src/cli/daemon.js similarity index 88% rename from src/cli/standalone-daemon.js rename to src/cli/daemon.js index e4d9c5c541..879432018b 100644 --- a/src/cli/standalone-daemon.js +++ b/src/cli/daemon.js @@ -9,8 +9,9 @@ const TCP = require('libp2p-tcp') const MulticastDNS = require('libp2p-mdns') const WS = require('libp2p-websockets') const Bootstrap = require('libp2p-bootstrap') +const promisify = require('promisify-es6') -class StandaloneDaemon { +class Daemon { constructor (options) { this._options = options || {} this._log = debug('ipfs:daemon') @@ -69,9 +70,14 @@ class StandaloneDaemon { this._ipfs = ipfs // start HTTP servers (if API or Gateway is enabled in options) - const httpApi = new HttpApi(ipfs, Object.assign({ announceListeners: true }, ipfsOpts)) + const httpApi = new HttpApi(ipfs, ipfsOpts) this._httpApi = await httpApi.start() + // for the CLI to know the where abouts of the API + if (this._httpApi._apiServers.length) { + await promisify(ipfs._repo.apiAddr.set)(this._httpApi._apiServers[0].info.ma) + } + this._log('started') return this } @@ -87,4 +93,4 @@ class StandaloneDaemon { } } -module.exports = StandaloneDaemon +module.exports = Daemon diff --git a/src/http/index.js b/src/http/index.js index 330ed923bd..b46448ef8a 100644 --- a/src/http/index.js +++ b/src/http/index.js @@ -4,8 +4,6 @@ const Hapi = require('hapi') const Pino = require('hapi-pino') const debug = require('debug') const multiaddr = require('multiaddr') -const promisify = require('promisify-es6') -const toUri = require('multiaddr-to-uri') const toMultiaddr = require('uri-to-multiaddr') const errorHandler = require('./error-handler') @@ -69,24 +67,9 @@ class HttpApi { const apiAddrs = config.Addresses.API this._apiServers = await serverCreator(apiAddrs, this._createApiServer, ipfs) - // for the CLI to know the where abouts of the API - if (this._apiServers.length) { - await promisify(ipfs._repo.apiAddr.set)(this._apiServers[0].info.ma) - } - const gatewayAddrs = config.Addresses.Gateway this._gatewayServers = await serverCreator(gatewayAddrs, this._createGatewayServer, ipfs) - const announce = this._options.announceListeners ? ipfs._print : this._log - this._apiServers.forEach(apiServer => { - announce('API listening on %s', apiServer.info.ma.toString()) - }) - this._gatewayServers.forEach(gatewayServer => { - announce('Gateway (read only) listening on %s', gatewayServer.info.ma.toString()) - }) - this._apiServers.forEach(apiServer => { - announce('Web UI available at %s', toUri(apiServer.info.ma) + '/webui') - }) this._log('started') return this } diff --git a/test/gateway/index.js b/test/gateway/index.js index 8ad692288d..f8836700fb 100644 --- a/test/gateway/index.js +++ b/test/gateway/index.js @@ -5,7 +5,7 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) -const StandaloneDaemon = require('../../src/cli/standalone-daemon') +const Daemon = require('../../src/cli/daemon') const loadFixture = require('aegir/fixtures') const os = require('os') const path = require('path') @@ -33,7 +33,7 @@ describe('HTTP Gateway', function () { this.timeout(60 * 1000) const repoPath = path.join(os.tmpdir(), '/ipfs-' + hat()) - http.api = new StandaloneDaemon({ + http.api = new Daemon({ repo: repoPath, init: true, config: { diff --git a/test/http-api/routes.js b/test/http-api/routes.js index ed971d2928..d79572dc18 100644 --- a/test/http-api/routes.js +++ b/test/http-api/routes.js @@ -6,7 +6,7 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') chai.use(dirtyChai) const hat = require('hat') -const StandaloneDaemon = require('../../src/cli/standalone-daemon') +const Daemon = require('../../src/cli/daemon') const promisify = require('promisify-es6') const ncp = promisify(require('ncp').ncp) const path = require('path') @@ -22,7 +22,7 @@ describe('HTTP API', () => { let http = {} const startHttpAPI = async (config) => { - http.api = new StandaloneDaemon({ + http.api = new Daemon({ repo: repoTests, pass: hat(), config,