Skip to content

Commit

Permalink
fix: various fixes from @vmx review
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov committed Jan 12, 2018
1 parent aa8d72b commit 6b4ec15
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ server.start((err) => {
- **`js`** - calling `DaemonFactory.create({type: 'js'})` will spawn a `js-ipfs` daemon.
- **`proc`** - calling `DaemonFactory.create({type: 'proc', exec: require('ipfs') })` will spawn an `in process js-ipfs node` using the provided code reference that implements the core IPFS API. Note that, `exec` option to `df.spawn()` is required if `type: 'proc'` is used.

#### DaemonFactory endpoint for remote spawning - `const server = DaemonFactory.createServer([options]) `
#### DaemonFactory endpoint for remote spawning - `const server = `DaemonFactory.createServer([options]) `

`DaemonFactory.createServer` create an instance of the bundled REST API used by the remote controller.

Expand Down Expand Up @@ -162,15 +162,15 @@ The IPFS daemon controller (`ipfsd`) allows you to interact with the spawned IPF

#### `ipfsd.apiAddr` (getter)

Get the address (multiaddr) of connected IPFS API. Returns a multiaddr,
Get the address (multiaddr) of connected IPFS API. Returns a multiaddr

#### `ipfsd.gatewayAddr` (getter)

Get the address (multiaddr) of connected IPFS HTTP Gateway. Returns a multiaddr.

#### `ipfsd.repoPath` (getter)

Get the current repo path. Returns string
Get the current repo path. Returns string.

#### `ipfsd.started` (getter)

Expand All @@ -181,7 +181,7 @@ Is the node started. Returns a boolean.
Initialize a repo.

`initOpts` (optional) is an object with the following properties:
- `keysize` (default 2048) - The bit size of the identiy key.
- `keysize` (default 2048) - The bit size of the identity key.
- `directory` (default IPFS_PATH if defined, or ~/.ipfs for go-ipfs and ~/.jsipfs for js-ipfs) - The location of the repo.

`callback` is a function with the signature `function (Error, ipfsd)` where `err` is an Error in case something goes wrong and `ipfsd` is the daemon controller instance.
Expand All @@ -198,36 +198,36 @@ Start the daemon.

`flags` - Flags array to be passed to the `ipfs daemon` command.

`callback` is a function with the signature `function(err, ipfsApi)}` that receives an instance of `ipfs-api` on success or an instance of `Error` on failure
`callback` is a function with the signature `function(err, ipfsApi)` that receives an instance of `ipfs-api` on success or an instance of `Error` on failure


#### `ipfsd.stop(callback)`
#### `ipfsd.stop([callback])`

Stop the daemon.

`callback` is a function with the signature `function(err)` callback - function that receives an instance of `Error` on failure

#### `ipfsd.killProcess (callback)`
#### `ipfsd.killProcess([callback])`

Kill the `ipfs daemon` process.

First a `SIGTERM` is sent, after 10.5 seconds `SIGKILL` is sent if the process hasn't exited yet.

`callback` is a function with the signature `function()` called once the process is killed

#### `ipfsd.pid ()`
#### `ipfsd.pid()`

Get the pid of the `ipfs daemon` process. Returns the pid number

#### `ipfsd.getConfig(key, callback)`
#### `ipfsd.getConfig([key], callback)`

Returns the output of an `ipfs config` command. If no `key` is passed, the whole config is returned as an object.

`key` (optional) - A specific config to retrieve.

`callback` is a function with the signature `function(err, (Object|string)` that receives an object or string on success or an `Error` instance on failure
`callback` is a function with the signature `function(err, (Object|string))` that receives an object or string on success or an `Error` instance on failure

#### `ipfsd.setConfig (key, value, callback)`
#### `ipfsd.setConfig(key, value, callback)`

Set a config value.

Expand All @@ -251,7 +251,7 @@ This instance is returned for each successfully started IPFS daemon, when either

### Packaging

`ipfsd-ctl` can be packaged in Electron applications, but the ipfs binary has to be excluded from asar (Electron Archives),
`ipfsd-ctl` can be packaged in Electron applications, but the ipfs binary has to be excluded from asar (Electron Archives).
[read more about unpack files from asar](https://electron.atom.io/docs/tutorial/application-packaging/#adding-unpacked-files-in-asar-archive).

`ipfsd-ctl` will try to detect if used from within an `app.asar` archive and tries to resolve ipfs from `app.asar.unpacked`. The ipfs binary is part of the `go-ipfs-dep` module.
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DaemonFactory {
static create (opts) {
const options = defaults({}, opts, { remote: !isNode })

if (options.remote && options.type === 'proc') {
if (options.type === 'proc') {
options.remote = false
}

Expand Down
6 changes: 4 additions & 2 deletions src/remote-node/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class Node {
* @returns {undefined}
*/
stop (cb) {
cb = cb || (() => {})
request
.post(`${this.baseUrl}/stop`)
.query({ id: this._id })
Expand All @@ -175,6 +176,7 @@ class Node {
* @returns {undefined}
*/
killProcess (cb) {
cb = cb || (() => {})
request
.post(`${this.baseUrl}/kill`)
.query({ id: this._id })
Expand Down Expand Up @@ -219,11 +221,11 @@ class Node {
getConfig (key, cb) {
if (typeof key === 'function') {
cb = key
key = null
key = undefined
}

const qr = { id: this._id }
qr.key = key || undefined
qr.key = key
request
.get(`${this.baseUrl}/config`)
.query(qr)
Expand Down
9 changes: 0 additions & 9 deletions test/add-retrive.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,5 @@ module.exports = () => {
expect(this.ipfsd.api).to.have.property('apiHost')
expect(this.ipfsd.api).to.have.property('apiPort')
})

it('should be able to store objects', () => {
expect(store)
.to.equal('QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ')
})

it('should be able to retrieve objects', () => {
expect(retrieve.toString()).to.equal('blorb')
})
})
}
4 changes: 2 additions & 2 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ module.exports = (df, type) => {
// Check for props in daemon
expect(ipfsd).to.have.property('apiAddr')
expect(ipfsd).to.have.property('gatewayAddr')
expect(ipfsd.apiAddr).to.not.equal(null)
expect(ipfsd.apiAddr).to.not.be.null()
expect(multiaddr.isMultiaddr(ipfsd.apiAddr)).to.equal(true)
expect(ipfsd.gatewayAddr).to.not.equal(null)
expect(ipfsd.gatewayAddr).to.not.be.null()
expect(multiaddr.isMultiaddr(ipfsd.gatewayAddr)).to.equal(true)

// Check for props in ipfs-api instance
Expand Down
1 change: 1 addition & 0 deletions test/remote/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const routes = proxyquire('../../src/remote-node/routes', {
node.stop = (cb) => {
node.killProcess(cb)
}

node.killProcess = (cb) => {
node.started = false
cb()
Expand Down

0 comments on commit 6b4ec15

Please sign in to comment.