Add offline daemon mode Resolves #2393
Add offline daemon mode Resolves #2393 License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
May 15, 2016 at 14:12 UTC
74b7fd28ba284ce59e0f2045e8dcc0292fe865e6
1 file changed
+9
-2
cmd/ipfs/daemon.go
+9
-2
@@ -42,6 +42,7 @@ const (
42
unencryptTransportKwd = "disable-transport-encryption"
43
enableGCKwd = "enable-gc"
44
adjustFDLimitKwd = "manage-fdlimit"
45
+ offlineKwd = "offline"
46
// apiAddrKwd = "address-api"
47
// swarmAddrKwd = "address-swarm"
48
)
@@ -136,6 +137,7 @@ future version, along with this notice. Please move to setting the HTTP Headers.
137
cmds.BoolOption(unencryptTransportKwd, "Disable transport encryption (for debugging protocols)").Default(false),
138
cmds.BoolOption(enableGCKwd, "Enable automatic periodic repo garbage collection").Default(false),
139
cmds.BoolOption(adjustFDLimitKwd, "Check and raise file descriptor limits if needed").Default(false),
140
+ cmds.BoolOption(offlineKwd, "Run in offline. Do not connect with rest of the network but provide local API.").Default(false),
141
142
// TODO: add way to override addresses. tricky part: updating the config if also --init.
143
// cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
@@ -226,9 +228,10 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
228
229
// Start assembling node config
230
ncfg := &core.BuildCfg{
229
- Online: true,
230
- Repo: repo,
231
+ Repo: repo,
232
}
233
+ offline, _, _ := req.Option(offlineKwd).Bool()
234
+ ncfg.Online = !offline
235
236
routingOption, _, err := req.Option(routingOptionKwd).String()
237
if err != nil {
@@ -416,6 +419,10 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
419
420
// printSwarmAddrs prints the addresses of the host
421
func printSwarmAddrs(node *core.IpfsNode) {
422
+ if !node.OnlineMode() {
423
+ fmt.Println("Swarm not listening, running in offline mode.")
424
+ return
425
+ }
426
var addrs []string
427
for _, addr := range node.PeerHost.Addrs() {
428
addrs = append(addrs, addr.String())