13
13
> Control an ipfs node daemon using either Node.js or the browser
14
14
15
15
```
16
-
17
-
18
16
+-----+
19
17
| H |
20
18
| T |
32
30
| +-----------------------+ | +-----------------------|---- | |
33
31
| | | +----------------------+ |
34
32
+-----------------------------+ +-----------------------------+
35
-
36
33
```
37
34
38
35
## Table of Contents
@@ -60,13 +57,10 @@ IPFS daemons are already easy to start and stop, but this module is here to do i
60
57
// Start a disposable node, and get access to the api
61
58
// print the node id, and stop the temporary daemon
62
59
63
- // IPFS_PATH will point to /tmp/ipfs_***** and will be
64
- // cleaned up when the process exits.
60
+ const controllerFactory = require ( ' ipfsd-ctl ' )
61
+ const daemonFactory = controllerFactory ()
65
62
66
- const daemonFactory = require (' ipfsd-ctl' )
67
- const local = daemonFactory .localController
68
-
69
- local .spawn (function (err , ipfsd ) {
63
+ daemonFactory .spawn (function (err , ipfsd ) {
70
64
const ipfsCtl = ipfsd .ctl
71
65
const ipfsCtrl = ipfsd .ctrl
72
66
ipfsCtl .id (function (err , id ) {
@@ -82,21 +76,18 @@ local.spawn(function (err, ipfsd) {
82
76
// Start a remote disposable node, and get access to the api
83
77
// print the node id, and stop the temporary daemon
84
78
85
- // IPFS_PATH will point to /tmp/ipfs_***** and will be
86
- // cleaned up when the process exits.
87
-
88
- const daemonFactory = require (' ipfsd-ctl' )
89
- const server = daemonFactory .server
79
+ const controllerFactory = require (' ipfsd-ctl' )
80
+ const daemonFactory = controllerFactory ()
90
81
91
- server .start ((err ) => {
82
+ const port = 9999
83
+ daemonFactory .start (port, (err ) => {
92
84
if (err) {
93
85
throw err
94
86
}
95
87
96
- const remote = daemonFactory .remoteController (port || 9999 )
97
- remote .spawn (function (err , controller ) {
98
- const ipfsCtl = controller .ctl
99
- const ipfsCtrl = controller .ctrl
88
+ daemonFactory .spawn (function (err , ipfsd ) {
89
+ const ipfsCtl = ipfsd .ctl
90
+ const ipfsCtrl = ipfsd .ctrl
100
91
ipfsCtl .id (function (err , id ) {
101
92
console .log (id)
102
93
ipfsCtrl .stopDaemon ()
@@ -138,16 +129,25 @@ module.exports = {
138
129
139
130
#### Create factory
140
131
141
- - ` daemonFactory.localController ` - create a local controller
142
- - ` daemonFactory.remoteController([port]) ` - create a remote controller, usable from browsers
143
- - These methods return a factory that exposes the ` spawn ` method, which allows spawning and controlling ipfs nodes
144
- - ` daemonFactory.server ` - exposes ` start ` and ` stop ` methods to start and stop the bundled http server that is required to run the remote controller.
132
+ ``` js
133
+ const controllerFactory = require (' ipfsd-ctl' )
134
+ const daemonFactory = controllerFactory ()
135
+ ```
136
+
137
+ > Create a factory that will expose the ` daemonFactory.spawn ` method
138
+
139
+ - These method return a factory that exposes the ` spawn ` method, which allows spawning and controlling ipfs nodes
140
+
141
+
142
+ > ` daemonFactory.server `
143
+
144
+ - exposes ` start ` and ` stop ` methods to start and stop the bundled http server that is required to run the remote controller.
145
145
146
146
#### Spawn nodes
147
147
148
148
> Spawn either a js-ipfs or go-ipfs node through ` localController ` or ` remoteController `
149
149
150
- ` spawn([options], cb ) `
150
+ ` spawn([options], callback ) `
151
151
152
152
- ` options ` - is an optional object with various options and ipfs config parameters
153
153
- ` js ` bool (default false) - spawn a js or go node (default go)
@@ -158,10 +158,11 @@ module.exports = {
158
158
- ` args ` - array of cmd line arguments to be passed to ipfs daemon
159
159
- ` config ` - ipfs configuration options
160
160
161
- - ` cb(err, {ctl: <ipfs-api instance>, ctrl: <Node (ctrl) instance>}) ` - a callback that receives an object with two members:
162
- - ` ctl ` - an [ ipfs-api] ( https://github.com/ipfs/js-ipfs-api ) instance attached to the newly created ipfs node
163
- - ` ctrl ` - an instance of a daemon controller object
164
-
161
+ - ` callback ` - is a function with the signature ` cb(err, ipfsd) ` where:
162
+ - ` err ` - is the error set if spawning the node is unsuccessful
163
+ - ` ipfsd ` - is an object with two properties:
164
+ - ` ctl ` - an [ ipfs-api] ( https://github.com/ipfs/js-ipfs-api ) instance attached to the newly created ipfs node
165
+ - ` ctrl ` - an instance of a daemon controller object
165
166
166
167
### IPFS Client (ctl)
167
168
@@ -170,14 +171,15 @@ module.exports = {
170
171
171
172
### IPFS Daemon Controller (ctrl)
172
173
174
+ > The IPFS daemon controller that allows interacting with the spawned IPFS process
173
175
174
176
#### ` apiAddr ` (getter)
175
177
176
178
> Get the address (multiaddr) of connected IPFS API.
177
179
178
180
- returns multiaddr
179
181
180
- #### ` gatewayAddr ` (getter)
182
+ #### ` gatewayAddr ` (getter)
181
183
182
184
> Get the address (multiaddr) of connected IPFS HTTP Gateway.
183
185
0 commit comments