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

Commit

Permalink
refactor: rename StandaloneDaemon to Daemon
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
lidel committed Apr 12, 2019
1 parent 7c32da8 commit 1e82102
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
14 changes: 12 additions & 2 deletions src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const os = require('os')
const toUri = require('multiaddr-to-uri')
const { getRepoPath, print, ipfsPathHelp } = require('../utils')

module.exports = {
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions src/cli/standalone-daemon.js → src/cli/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
}
Expand All @@ -87,4 +93,4 @@ class StandaloneDaemon {
}
}

module.exports = StandaloneDaemon
module.exports = Daemon
17 changes: 0 additions & 17 deletions src/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions test/gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions test/http-api/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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,
Expand Down

0 comments on commit 1e82102

Please sign in to comment.