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

feat: allow daemon to init and start in a single cmd #2428

Merged
merged 19 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const preloadNode = MockPreloadNode.createNode()
const echoServer = EchoServer.createServer()

module.exports = {
bundlesize: { maxSize: '692kB' },
bundlesize: { maxSize: '696kB' },
webpack: {
resolve: {
mainFields: ['browser', 'main'],
Expand Down
33 changes: 25 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cache: false
stages:
- check
- test
- cov
- tag

node_js:
- '10'
Expand All @@ -18,8 +18,14 @@ os:
- osx
- windows

env:
# This stops Windows builds from hanging
# https://travis-ci.community/t/timeout-after-build-finished-and-succeeded/1336
- YARN_GPG=no

script: npx nyc -s npx aegir test -t node --timeout 10000 --bail
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov
after_success:
- npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov

jobs:
include:
Expand All @@ -34,26 +40,37 @@ jobs:
addons:
chrome: stable
script:
- npx aegir test -t browser
- npx aegir test -t webworker
- npx aegir test -t browser -t webworker

- stage: test
name: firefox
addons:
firefox: latest
script:
- npx aegir test -t browser -- --browsers FirefoxHeadless
- npx aegir test -t webworker -- --browsers FirefoxHeadless
- npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless

- stage: test
name: electron-main
os: osx
script:
- xvfb-run npx aegir test -t electron-main -- --bail --timeout 10000
- npx aegir test -t electron-main -- --bail --timeout 10000

- stage: test
name: electron-renderer
os: osx
script:
- npx aegir test -t electron-renderer -- --bail --timeout 10000

- stage: test
name: interop
script:
- npm run test:interop

- stage: tag
if: branch = master AND type = push AND fork = false
name: update-last-successful-build
script:
- xvfb-run npx aegir test -t electron-renderer -- --bail --timeout 10000
- npx aegir update-last-successful-build

notifications:
email: false
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"test:node:cli": "aegir test -t node -f test/cli/index.js",
"test:node:interface": "aegir test -t node -f test/core/interface.spec.js",
"test:bootstrapers": "IPFS_TEST=bootstrapers aegir test -t browser -f test/bootstrapers.js",
"test:interop": "IPFS_JS_EXEC=$PWD/src/cli/bin.js ipfs-interop",
"coverage": "nyc --reporter=text --reporter=lcov npm run test:node",
"benchmark": "echo \"Error: no benchmarks yet\" && exit 1",
"benchmark:node": "echo \"Error: no benchmarks yet\" && exit 1",
Expand Down Expand Up @@ -95,7 +96,7 @@
"ipfs-bitswap": "~0.25.1",
"ipfs-block": "~0.8.1",
"ipfs-block-service": "~0.15.2",
"ipfs-http-client": "^35.1.0",
"ipfs-http-client": "ipfs/js-ipfs-http-client#fix/fix-electron",
"ipfs-http-response": "~0.3.1",
"ipfs-mfs": "^0.12.2",
"ipfs-multipart": "^0.2.0",
Expand All @@ -122,7 +123,7 @@
"it-to-stream": "^0.1.1",
"just-safe-set": "^2.1.0",
"kind-of": "^6.0.2",
"ky": "~0.13.0",
"ky": "~0.14.0",
"ky-universal": "~0.3.0",
"libp2p": "~0.26.1",
"libp2p-bootstrap": "~0.9.3",
Expand All @@ -141,7 +142,7 @@
"libp2p-websocket-star-multi": "~0.4.3",
"libp2p-websockets": "~0.12.3",
"lodash": "^4.17.15",
"mafmt": "^6.0.2",
"mafmt": "^6.0.10",
"merge-options": "^1.0.1",
"mime-types": "^2.1.21",
"mkdirp": "~0.5.1",
Expand Down Expand Up @@ -186,7 +187,7 @@
"yargs-promise": "^1.1.0"
},
"devDependencies": {
"aegir": "^20.0.0",
"aegir": "^20.2.0",
"base64url": "^3.0.1",
"chai": "^4.2.0",
"clear-module": "^4.0.0",
Expand All @@ -197,15 +198,17 @@
"execa": "^2.0.4",
"form-data": "^2.5.1",
"hat": "0.0.3",
"interface-ipfs-core": "^0.113.0",
"ipfsd-ctl": "~0.46.0",
"interface-ipfs-core": "github:ipfs/interface-ipfs-core#fix/fix-electron",
"ipfs-interop": "~0.1.0",
"ipfsd-ctl": "ipfs/js-ipfsd-ctl#chore/new-http-client",
"libp2p-websocket-star": "~0.10.2",
"ncp": "^2.0.0",
"p-event": "^4.1.0",
"qs": "^6.5.2",
"rimraf": "^3.0.0",
"sinon": "^7.4.2",
"stream-to-promise": "^2.2.0"
"stream-to-promise": "^2.2.0",
"temp-write": "^4.0.0"
},
"optionalDependencies": {
"prom-client": "^11.5.3",
Expand Down
21 changes: 20 additions & 1 deletion src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict'

const os = require('os')
const fs = require('fs')
const toUri = require('multiaddr-to-uri')
const { ipfsPathHelp } = require('../utils')
const { isTest } = require('ipfs-utils/src/env')
const debug = require('debug')('ipfs:cli:daemon')

module.exports = {
command: 'daemon',
Expand All @@ -13,6 +15,10 @@ module.exports = {
builder (yargs) {
return yargs
.epilog(ipfsPathHelp)
.option('init-config', {
type: 'string',
desc: 'Path to existing configuration file to be loaded during --init.'
})
.option('enable-sharding-experiment', {
type: 'boolean',
default: false
Expand Down Expand Up @@ -42,9 +48,22 @@ module.exports = {

const repoPath = argv.getRepoPath()

let config = {}
// read and parse config file
if (argv.initConfig) {
try {
const raw = fs.readFileSync(argv.initConfig)
config = JSON.parse(raw)
} catch (error) {
debug(error)
throw new Error('Default config couldn\'t be found or content isn\'t valid JSON.')
}
}

// Required inline to reduce startup time
const Daemon = require('../../cli/daemon')
const daemon = new Daemon({
config,
silent: argv.silent,
repo: process.env.IPFS_PATH,
offline: argv.offline,
Expand Down Expand Up @@ -80,7 +99,7 @@ module.exports = {
print('Daemon is ready')

const cleanup = async () => {
print(`Received interrupt signal, shutting down...`)
print('Received interrupt signal, shutting down...')
await daemon.stop()
process.exit(0)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/file/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
argv.resolve((async () => {
const path = argv.key
// `ipfs file ls` is deprecated. See https://ipfs.io/docs/commands/#ipfs-file-ls
argv.print(`This functionality is deprecated, and will be removed in future versions. If possible, please use 'ipfs ls' instead.`)
argv.print('This functionality is deprecated, and will be removed in future versions. If possible, please use \'ipfs ls\' instead.')

const ipfs = await argv.getIpfs()
let links = await ipfs.ls(path)
Expand Down
24 changes: 19 additions & 5 deletions src/cli/commands/init.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
'use strict'

const fs = require('fs')
const debug = require('debug')('ipfs:cli:init')
const { ipfsPathHelp } = require('../utils')

module.exports = {
command: 'init [config] [options]',
command: 'init [default-config] [options]',
describe: 'Initialize a local IPFS node',
builder (yargs) {
return yargs
.epilog(ipfsPathHelp)
.positional('config', {
describe: 'Node config, this should JSON and will be merged with the default config. Check https://github.com/ipfs/js-ipfs#optionsconfig',
.positional('default-config', {
daviddias marked this conversation as resolved.
Show resolved Hide resolved
describe: 'Initialize with the given configuration. Path to the config file. Check https://github.com/ipfs/js-ipfs#optionsconfig',
type: 'string'
})
.option('bits', {
Expand All @@ -34,6 +36,18 @@ module.exports = {
argv.resolve((async () => {
const path = argv.getRepoPath()

let config = {}
// read and parse config file
if (argv.defaultConfig) {
try {
const raw = fs.readFileSync(argv.defaultConfig)
config = JSON.parse(raw)
} catch (error) {
debug(error)
throw new Error('Default config couldn\'t be found or content isn\'t valid JSON.')
}
}

argv.print(`initializing ipfs node at ${path}`)

// Required inline to reduce startup time
Expand All @@ -44,7 +58,7 @@ module.exports = {
repo: new Repo(path),
init: false,
start: false,
config: argv.config || {}
config
})

try {
Expand All @@ -57,7 +71,7 @@ module.exports = {
})
} catch (err) {
if (err.code === 'EACCES') {
err.message = `EACCES: permission denied, stat $IPFS_PATH/version`
err.message = 'EACCES: permission denied, stat $IPFS_PATH/version'
}
throw err
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ module.exports = {
commit: {
type: 'boolean',
default: false,
describe: `Include the version's commit hash`
describe: 'Include the version\'s commit hash'
},
repo: {
type: 'boolean',
default: false,
describe: `Print only the repo's version number`
describe: 'Print only the repo\'s version number'
},
all: {
type: 'boolean',
Expand Down
2 changes: 1 addition & 1 deletion src/cli/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Daemon {
}

// start the daemon
const ipfsOpts = Object.assign({ init: false }, this._options, { start: true, libp2p })
const ipfsOpts = Object.assign({ }, this._options, { init: true, start: true, libp2p })
const ipfs = new IPFS(ipfsOpts)

await new Promise((resolve, reject) => {
Expand Down
6 changes: 5 additions & 1 deletion src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) {
}

const getPubsubRouter = () => {
const router = get(config, 'Pubsub.Router', 'gossipsub')
let router = get(config, 'Pubsub.Router', 'gossipsub')

if (!router) {
router = 'gossipsub'
}

if (!PubsubRouters[router]) {
throw errCode(new Error(`Router unavailable. Configure libp2p.modules.pubsub to use the ${router} router.`), 'ERR_NOT_SUPPORTED')
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/pin/gc.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function createMarkedSet (ipfs, callback) {
(cb) => ipfs._repo.root.get(MFS_ROOT_KEY, (err, mh) => {
if (err) {
if (err.code === 'ERR_NOT_FOUND') {
log(`No blocks in MFS`)
log('No blocks in MFS')
return cb(null, [])
}
return cb(expErr(err, 'Could not get MFS root from datastore'))
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/pin/pin-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class PinManager {
this.repo.datastore.get(PIN_DS_KEY, (err, mh) => {
if (err) {
if (err.code === 'ERR_NOT_FOUND') {
this.log(`No pinned blocks`)
this.log('No pinned blocks')
return callback(null, [])
}
return callback(new Error(`Could not get pin sets root from datastore: ${err.message}`))
Expand Down
2 changes: 1 addition & 1 deletion src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const s = superstruct({

return true
},
'multiaddr-ipfs': v => mafmt.IPFS.matches(v) ? true : `multiaddr IPFS invalid`
'multiaddr-ipfs': v => mafmt.IPFS.matches(v) ? true : 'multiaddr IPFS invalid'
}
})

Expand Down
12 changes: 6 additions & 6 deletions src/core/ipns/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class IpnsPublisher {

_putRecordToRouting (record, peerId, callback) {
if (!(PeerId.isPeerId(peerId))) {
const errMsg = `peerId received is not valid`
const errMsg = 'peerId received is not valid'

log.error(errMsg)
return callback(errcode(new Error(errMsg), 'ERR_INVALID_PEER_ID'))
Expand Down Expand Up @@ -87,7 +87,7 @@ class IpnsPublisher {

_publishEntry (key, entry, peerId, callback) {
if (!(Key.isKey(key))) {
const errMsg = `datastore key does not have a valid format`
const errMsg = 'datastore key does not have a valid format'

log.error(errMsg)
return callback(errcode(new Error(errMsg), 'ERR_INVALID_DATASTORE_KEY'))
Expand Down Expand Up @@ -118,14 +118,14 @@ class IpnsPublisher {

_publishPublicKey (key, publicKey, peerId, callback) {
if ((!Key.isKey(key))) {
const errMsg = `datastore key does not have a valid format`
const errMsg = 'datastore key does not have a valid format'

log.error(errMsg)
return callback(errcode(new Error(errMsg), 'ERR_INVALID_DATASTORE_KEY'))
}

if (!publicKey || !publicKey.bytes) {
const errMsg = `one or more of the provided parameters are not defined`
const errMsg = 'one or more of the provided parameters are not defined'

log.error(errMsg)
return callback(errcode(new Error(errMsg), 'ERR_UNDEFINED_PARAMETER'))
Expand All @@ -149,7 +149,7 @@ class IpnsPublisher {
// If `checkRouting` is true and we have no existing record, this method will check the routing system for any existing records.
_getPublished (peerId, options, callback) {
if (!(PeerId.isPeerId(peerId))) {
const errMsg = `peerId received is not valid`
const errMsg = 'peerId received is not valid'

log.error(errMsg)
return callback(errcode(new Error(errMsg), 'ERR_INVALID_PEER_ID'))
Expand Down Expand Up @@ -209,7 +209,7 @@ class IpnsPublisher {

_updateOrCreateRecord (privKey, value, validity, peerId, callback) {
if (!(PeerId.isPeerId(peerId))) {
const errMsg = `peerId received is not valid`
const errMsg = 'peerId received is not valid'

log.error(errMsg)
return callback(errcode(new Error(errMsg), 'ERR_INVALID_PEER_ID'))
Expand Down
2 changes: 1 addition & 1 deletion src/core/ipns/republisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class IpnsRepublisher {
record = ipns.unmarshal(dsVal)
} catch (err) {
log.error(err)
return callback(errcode(new Error(`found ipns record that we couldn't convert to a value`), 'ERR_INVALID_IPNS_RECORD'))
return callback(errcode(new Error('found ipns record that we couldn\'t convert to a value'), 'ERR_INVALID_IPNS_RECORD'))
}

callback(null, record.value)
Expand Down
Loading