Skip to content

Commit

Permalink
Add offline daemon mode
Browse files Browse the repository at this point in the history
Resolves #2393

License: MIT
Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Kubuxu committed May 15, 2016
1 parent 7f61b31 commit b11e337
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
unencryptTransportKwd = "disable-transport-encryption"
enableGCKwd = "enable-gc"
adjustFDLimitKwd = "manage-fdlimit"
offlineKwd = "offline"
// apiAddrKwd = "address-api"
// swarmAddrKwd = "address-swarm"
)
Expand Down Expand Up @@ -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)"),
cmds.BoolOption(enableGCKwd, "Enable automatic periodic repo garbage collection"),
cmds.BoolOption(adjustFDLimitKwd, "Check and raise file descriptor limits if needed"),
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)"),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit b11e337

Please sign in to comment.