@@ -11,7 +11,9 @@ import (
11
11
"sort"
12
12
"sync"
13
13
14
- cmds "github.com/ipfs/go-ipfs/commands"
14
+ "github.com/ipfs/go-ipfs-cmds/cmdsutil"
15
+
16
+ cmds "github.com/ipfs/go-ipfs-cmds"
15
17
"github.com/ipfs/go-ipfs/core"
16
18
commands "github.com/ipfs/go-ipfs/core/commands"
17
19
corehttp "github.com/ipfs/go-ipfs/core/corehttp"
@@ -54,7 +56,7 @@ const (
54
56
)
55
57
56
58
var daemonCmd = & cmds.Command {
57
- Helptext : cmds .HelpText {
59
+ Helptext : cmdsutil .HelpText {
58
60
Tagline : "Run a network-connected IPFS node." ,
59
61
ShortDescription : `
60
62
'ipfs daemon' runs a persistent ipfs daemon that can serve commands
@@ -145,24 +147,25 @@ Headers.
145
147
` ,
146
148
},
147
149
148
- Options : []cmds.Option {
149
- cmds .BoolOption (initOptionKwd , "Initialize ipfs with default settings if not already initialized" ).Default (false ),
150
- cmds .StringOption (routingOptionKwd , "Overrides the routing option" ).Default ("dht" ),
151
- cmds .BoolOption (mountKwd , "Mounts IPFS to the filesystem" ).Default (false ),
152
- cmds .BoolOption (writableKwd , "Enable writing objects (with POST, PUT and DELETE)" ).Default (false ),
153
- cmds .StringOption (ipfsMountKwd , "Path to the mountpoint for IPFS (if using --mount). Defaults to config setting." ),
154
- cmds .StringOption (ipnsMountKwd , "Path to the mountpoint for IPNS (if using --mount). Defaults to config setting." ),
155
- cmds .BoolOption (unrestrictedApiAccessKwd , "Allow API access to unlisted hashes" ).Default (false ),
156
- cmds .BoolOption (unencryptTransportKwd , "Disable transport encryption (for debugging protocols)" ).Default (false ),
157
- cmds .BoolOption (enableGCKwd , "Enable automatic periodic repo garbage collection" ).Default (false ),
158
- cmds .BoolOption (adjustFDLimitKwd , "Check and raise file descriptor limits if needed" ).Default (true ),
159
- cmds .BoolOption (offlineKwd , "Run offline. Do not connect to the rest of the network but provide local API." ).Default (false ),
160
- cmds .BoolOption (migrateKwd , "If true, assume yes at the migrate prompt. If false, assume no." ),
161
- cmds .BoolOption (enableFloodSubKwd , "Instantiate the ipfs daemon with the experimental pubsub feature enabled." ),
162
- cmds .BoolOption (enableMultiplexKwd , "Add the experimental 'go-multiplex' stream muxer to libp2p on construction." ).Default (true ),
150
+ Options : []cmdsutil.Option {
151
+ cmdsutil .BoolOption (initOptionKwd , "Initialize ipfs with default settings if not already initialized" ).Default (false ),
152
+ cmdsutil .StringOption (routingOptionKwd , "Overrides the routing option" ).Default ("dht" ),
153
+ cmdsutil .BoolOption (mountKwd , "Mounts IPFS to the filesystem" ).Default (false ),
154
+ cmdsutil .BoolOption (writableKwd , "Enable writing objects (with POST, PUT and DELETE)" ).Default (false ),
155
+ cmdsutil .StringOption (ipfsMountKwd , "Path to the mountpoint for IPFS (if using --mount). Defaults to config setting." ),
156
+ cmdsutil .StringOption (ipnsMountKwd , "Path to the mountpoint for IPNS (if using --mount). Defaults to config setting." ),
157
+ cmdsutil .BoolOption (unrestrictedApiAccessKwd , "Allow API access to unlisted hashes" ).Default (false ),
158
+ cmdsutil .BoolOption (unencryptTransportKwd , "Disable transport encryption (for debugging protocols)" ).Default (false ),
159
+ cmdsutil .BoolOption (enableGCKwd , "Enable automatic periodic repo garbage collection" ).Default (false ),
160
+ cmdsutil .BoolOption (adjustFDLimitKwd , "Check and raise file descriptor limits if needed" ).Default (true ),
161
+ cmdsutil .BoolOption (offlineKwd , "Run offline. Do not connect to the rest of the network but provide local API." ).Default (false ),
162
+ cmdsutil .BoolOption (migrateKwd , "If true, assume yes at the migrate prompt. If false, assume no." ),
163
+ cmdsutil .BoolOption (enableFloodSubKwd , "Instantiate the ipfs daemon with the experimental pubsub feature enabled." ),
164
+ cmdsutil .BoolOption (enableMultiplexKwd , "Add the experimental 'go-multiplex' stream muxer to libp2p on construction." ),
165
+
163
166
// TODO: add way to override addresses. tricky part: updating the config if also --init.
164
- // cmds .StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
165
- // cmds .StringOption(swarmAddrKwd, "Address for the swarm socket (overrides config)"),
167
+ // cmdsutil .StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
168
+ // cmdsutil .StringOption(swarmAddrKwd, "Address for the swarm socket (overrides config)"),
166
169
},
167
170
Subcommands : map [string ]* cmds.Command {},
168
171
Run : daemonFunc ,
@@ -181,7 +184,7 @@ func defaultMux(path string) corehttp.ServeOption {
181
184
182
185
var fileDescriptorCheck = func () error { return nil }
183
186
184
- func daemonFunc (req cmds.Request , res cmds.Response ) {
187
+ func daemonFunc (req cmds.Request , re cmds.ResponseEmitter ) {
185
188
// Inject metrics before we do anything
186
189
187
190
err := mprome .Inject ()
@@ -221,7 +224,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
221
224
// running in an uninitialized state.
222
225
initialize , _ , err := req .Option (initOptionKwd ).Bool ()
223
226
if err != nil {
224
- res .SetError (err , cmds .ErrNormal )
227
+ re .SetError (err , cmdsutil .ErrNormal )
225
228
return
226
229
}
227
230
@@ -234,7 +237,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
234
237
if ! util .FileExists (req .InvocContext ().ConfigRoot ) {
235
238
err := initWithDefaults (os .Stdout , req .InvocContext ().ConfigRoot )
236
239
if err != nil {
237
- res .SetError (err , cmds .ErrNormal )
240
+ re .SetError (err , cmdsutil .ErrNormal )
238
241
return
239
242
}
240
243
}
@@ -245,7 +248,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
245
248
repo , err := fsrepo .Open (req .InvocContext ().ConfigRoot )
246
249
switch err {
247
250
default :
248
- res .SetError (err , cmds .ErrNormal )
251
+ re .SetError (err , cmdsutil .ErrNormal )
249
252
return
250
253
case fsrepo .ErrNeedMigration :
251
254
domigrate , found , _ := req .Option (migrateKwd ).Bool ()
@@ -258,7 +261,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
258
261
if ! domigrate {
259
262
fmt .Println ("Not running migrations of fs-repo now." )
260
263
fmt .Println ("Please get fs-repo-migrations from https://dist.ipfs.io" )
261
- res .SetError (fmt .Errorf ("fs-repo requires migration" ), cmds .ErrNormal )
264
+ re .SetError (fmt .Errorf ("fs-repo requires migration" ), cmdsutil .ErrNormal )
262
265
return
263
266
}
264
267
@@ -268,13 +271,13 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
268
271
fmt .Printf (" %s\n " , err )
269
272
fmt .Println ("If you think this is a bug, please file an issue and include this whole log output." )
270
273
fmt .Println (" https://github.com/ipfs/fs-repo-migrations" )
271
- res .SetError (err , cmds .ErrNormal )
274
+ re .SetError (err , cmdsutil .ErrNormal )
272
275
return
273
276
}
274
277
275
278
repo , err = fsrepo .Open (req .InvocContext ().ConfigRoot )
276
279
if err != nil {
277
- res .SetError (err , cmds .ErrNormal )
280
+ re .SetError (err , cmdsutil .ErrNormal )
278
281
return
279
282
}
280
283
case nil :
@@ -283,7 +286,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
283
286
284
287
cfg , err := ctx .GetConfig ()
285
288
if err != nil {
286
- res .SetError (err , cmds .ErrNormal )
289
+ re .SetError (err , cmdsutil .ErrNormal )
287
290
return
288
291
}
289
292
@@ -305,14 +308,14 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
305
308
306
309
routingOption , _ , err := req .Option (routingOptionKwd ).String ()
307
310
if err != nil {
308
- res .SetError (err , cmds .ErrNormal )
311
+ re .SetError (err , cmdsutil .ErrNormal )
309
312
return
310
313
}
311
314
switch routingOption {
312
315
case routingOptionSupernodeKwd :
313
316
servers , err := cfg .SupernodeRouting .ServerIPFSAddrs ()
314
317
if err != nil {
315
- res .SetError (err , cmds .ErrNormal )
318
+ re .SetError (err , cmdsutil .ErrNormal )
316
319
repo .Close () // because ownership hasn't been transferred to the node
317
320
return
318
321
}
@@ -332,14 +335,14 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
332
335
case routingOptionNoneKwd :
333
336
ncfg .Routing = core .NilRouterOption
334
337
default :
335
- res .SetError (fmt .Errorf ("unrecognized routing option: %s" , routingOption ), cmds .ErrNormal )
338
+ re .SetError (fmt .Errorf ("unrecognized routing option: %s" , routingOption ), cmdsutil .ErrNormal )
336
339
return
337
340
}
338
341
339
342
node , err := core .NewNode (req .Context (), ncfg )
340
343
if err != nil {
341
344
log .Error ("error from node construction: " , err )
342
- res .SetError (err , cmds .ErrNormal )
345
+ re .SetError (err , cmdsutil .ErrNormal )
343
346
return
344
347
}
345
348
node .SetLocal (false )
@@ -370,32 +373,43 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
370
373
// construct api endpoint - every time
371
374
err , apiErrc := serveHTTPApi (req )
372
375
if err != nil {
373
- res .SetError (err , cmds .ErrNormal )
376
+ re .SetError (err , cmdsutil .ErrNormal )
374
377
return
375
378
}
376
379
380
+ // construct http gateway - if it is set in the config
381
+ var gwErrc <- chan error
382
+ if len (cfg .Addresses .Gateway ) > 0 {
383
+ var err error
384
+ err , gwErrc = serveHTTPGateway (req )
385
+ if err != nil {
386
+ re .SetError (err , cmdsutil .ErrNormal )
387
+ return
388
+ }
389
+ }
390
+
377
391
// construct fuse mountpoints - if the user provided the --mount flag
378
392
mount , _ , err := req .Option (mountKwd ).Bool ()
379
393
if err != nil {
380
- res .SetError (err , cmds .ErrNormal )
394
+ re .SetError (err , cmdsutil .ErrNormal )
381
395
return
382
396
}
383
397
if mount && offline {
384
- res .SetError (errors .New ("mount is not currently supported in offline mode" ),
385
- cmds .ErrClient )
398
+ re .SetError (errors .New ("mount is not currently supported in offline mode" ),
399
+ cmdsutil .ErrClient )
386
400
return
387
401
}
388
402
if mount {
389
403
if err := mountFuse (req ); err != nil {
390
- res .SetError (err , cmds .ErrNormal )
404
+ re .SetError (err , cmdsutil .ErrNormal )
391
405
return
392
406
}
393
407
}
394
408
395
409
// repo blockstore GC - if --enable-gc flag is present
396
410
err , gcErrc := maybeRunGC (req , node )
397
411
if err != nil {
398
- res .SetError (err , cmds .ErrNormal )
412
+ re .SetError (err , cmdsutil .ErrNormal )
399
413
return
400
414
}
401
415
@@ -419,7 +433,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
419
433
for err := range merge (apiErrc , gwErrc , gcErrc ) {
420
434
if err != nil {
421
435
log .Error (err )
422
- res .SetError (err , cmds .ErrNormal )
436
+ re .SetError (err , cmdsutil .ErrNormal )
423
437
}
424
438
}
425
439
return
0 commit comments