From 74b7fd28ba284ce59e0f2045e8dcc0292fe865e6 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Sun, 15 May 2016 14:12:57 +0200 Subject: [PATCH] Add offline daemon mode Resolves #2393 License: MIT Signed-off-by: Jakub Sztandera --- cmd/ipfs/daemon.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index 825d3fa49..a42e6cf24 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -42,6 +42,7 @@ const ( unencryptTransportKwd = "disable-transport-encryption" enableGCKwd = "enable-gc" adjustFDLimitKwd = "manage-fdlimit" + offlineKwd = "offline" // apiAddrKwd = "address-api" // swarmAddrKwd = "address-swarm" ) @@ -136,6 +137,7 @@ future version, along with this notice. Please move to setting the HTTP Headers. cmds.BoolOption(unencryptTransportKwd, "Disable transport encryption (for debugging protocols)").Default(false), cmds.BoolOption(enableGCKwd, "Enable automatic periodic repo garbage collection").Default(false), cmds.BoolOption(adjustFDLimitKwd, "Check and raise file descriptor limits if needed").Default(false), + cmds.BoolOption(offlineKwd, "Run in offline. Do not connect with rest of the network but provide local API.").Default(false), // TODO: add way to override addresses. tricky part: updating the config if also --init. // cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"), @@ -226,9 +228,10 @@ func daemonFunc(req cmds.Request, res cmds.Response) { // Start assembling node config ncfg := &core.BuildCfg{ - Online: true, - Repo: repo, + Repo: repo, } + offline, _, _ := req.Option(offlineKwd).Bool() + ncfg.Online = !offline routingOption, _, err := req.Option(routingOptionKwd).String() if err != nil { @@ -416,6 +419,10 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) { // printSwarmAddrs prints the addresses of the host func printSwarmAddrs(node *core.IpfsNode) { + if !node.OnlineMode() { + fmt.Println("Swarm not listening, running in offline mode.") + return + } var addrs []string for _, addr := range node.PeerHost.Addrs() { addrs = append(addrs, addr.String())