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

Commit 1e82102

Browse files
committed
refactor: rename StandaloneDaemon to Daemon
License: MIT Signed-off-by: Marcin Rataj <[email protected]>
1 parent 7c32da8 commit 1e82102

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

src/cli/commands/daemon.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

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

67
module.exports = {
@@ -44,8 +45,8 @@ module.exports = {
4445
const repoPath = getRepoPath()
4546

4647
// Required inline to reduce startup time
47-
const StandaloneDaemon = require('../../cli/standalone-daemon')
48-
const daemon = new StandaloneDaemon({
48+
const Daemon = require('../../cli/daemon')
49+
const daemon = new Daemon({
4950
silent: argv.silent,
5051
repo: process.env.IPFS_PATH,
5152
offline: argv.offline,
@@ -61,6 +62,15 @@ module.exports = {
6162

6263
try {
6364
await daemon.start()
65+
daemon._httpApi._apiServers.forEach(apiServer => {
66+
print(`API listening on ${apiServer.info.ma.toString()}`)
67+
})
68+
daemon._httpApi._gatewayServers.forEach(gatewayServer => {
69+
print(`Gateway (read only) listening on ${gatewayServer.info.ma.toString()}`)
70+
})
71+
daemon._httpApi._apiServers.forEach(apiServer => {
72+
print(`Web UI available at ${toUri(apiServer.info.ma)}/webui`)
73+
})
6474
} catch (err) {
6575
if (err.code === 'ENOENT' && err.message.match(/uninitialized/i)) {
6676
print('Error: no initialized ipfs repo found in ' + repoPath)

src/cli/standalone-daemon.js renamed to src/cli/daemon.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ const TCP = require('libp2p-tcp')
99
const MulticastDNS = require('libp2p-mdns')
1010
const WS = require('libp2p-websockets')
1111
const Bootstrap = require('libp2p-bootstrap')
12+
const promisify = require('promisify-es6')
1213

13-
class StandaloneDaemon {
14+
class Daemon {
1415
constructor (options) {
1516
this._options = options || {}
1617
this._log = debug('ipfs:daemon')
@@ -69,9 +70,14 @@ class StandaloneDaemon {
6970
this._ipfs = ipfs
7071

7172
// start HTTP servers (if API or Gateway is enabled in options)
72-
const httpApi = new HttpApi(ipfs, Object.assign({ announceListeners: true }, ipfsOpts))
73+
const httpApi = new HttpApi(ipfs, ipfsOpts)
7374
this._httpApi = await httpApi.start()
7475

76+
// for the CLI to know the where abouts of the API
77+
if (this._httpApi._apiServers.length) {
78+
await promisify(ipfs._repo.apiAddr.set)(this._httpApi._apiServers[0].info.ma)
79+
}
80+
7581
this._log('started')
7682
return this
7783
}
@@ -87,4 +93,4 @@ class StandaloneDaemon {
8793
}
8894
}
8995

90-
module.exports = StandaloneDaemon
96+
module.exports = Daemon

src/http/index.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const Hapi = require('hapi')
44
const Pino = require('hapi-pino')
55
const debug = require('debug')
66
const multiaddr = require('multiaddr')
7-
const promisify = require('promisify-es6')
8-
const toUri = require('multiaddr-to-uri')
97
const toMultiaddr = require('uri-to-multiaddr')
108

119
const errorHandler = require('./error-handler')
@@ -69,24 +67,9 @@ class HttpApi {
6967
const apiAddrs = config.Addresses.API
7068
this._apiServers = await serverCreator(apiAddrs, this._createApiServer, ipfs)
7169

72-
// for the CLI to know the where abouts of the API
73-
if (this._apiServers.length) {
74-
await promisify(ipfs._repo.apiAddr.set)(this._apiServers[0].info.ma)
75-
}
76-
7770
const gatewayAddrs = config.Addresses.Gateway
7871
this._gatewayServers = await serverCreator(gatewayAddrs, this._createGatewayServer, ipfs)
7972

80-
const announce = this._options.announceListeners ? ipfs._print : this._log
81-
this._apiServers.forEach(apiServer => {
82-
announce('API listening on %s', apiServer.info.ma.toString())
83-
})
84-
this._gatewayServers.forEach(gatewayServer => {
85-
announce('Gateway (read only) listening on %s', gatewayServer.info.ma.toString())
86-
})
87-
this._apiServers.forEach(apiServer => {
88-
announce('Web UI available at %s', toUri(apiServer.info.ma) + '/webui')
89-
})
9073
this._log('started')
9174
return this
9275
}

test/gateway/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const chai = require('chai')
55
const dirtyChai = require('dirty-chai')
66
const expect = chai.expect
77
chai.use(dirtyChai)
8-
const StandaloneDaemon = require('../../src/cli/standalone-daemon')
8+
const Daemon = require('../../src/cli/daemon')
99
const loadFixture = require('aegir/fixtures')
1010
const os = require('os')
1111
const path = require('path')
@@ -33,7 +33,7 @@ describe('HTTP Gateway', function () {
3333
this.timeout(60 * 1000)
3434
const repoPath = path.join(os.tmpdir(), '/ipfs-' + hat())
3535

36-
http.api = new StandaloneDaemon({
36+
http.api = new Daemon({
3737
repo: repoPath,
3838
init: true,
3939
config: {

test/http-api/routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const chai = require('chai')
66
const dirtyChai = require('dirty-chai')
77
chai.use(dirtyChai)
88
const hat = require('hat')
9-
const StandaloneDaemon = require('../../src/cli/standalone-daemon')
9+
const Daemon = require('../../src/cli/daemon')
1010
const promisify = require('promisify-es6')
1111
const ncp = promisify(require('ncp').ncp)
1212
const path = require('path')
@@ -22,7 +22,7 @@ describe('HTTP API', () => {
2222
let http = {}
2323

2424
const startHttpAPI = async (config) => {
25-
http.api = new StandaloneDaemon({
25+
http.api = new Daemon({
2626
repo: repoTests,
2727
pass: hat(),
2828
config,

0 commit comments

Comments
 (0)