Skip to content

Commit

Permalink
Distinguish between Offline and Local Mode.
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
  • Loading branch information
kevina committed Sep 25, 2016
1 parent 300187a commit bf80213
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
res.SetError(err, cmds.ErrNormal)
return
}
node.SetLocal(false)

printSwarmAddrs(node)

Expand Down
1 change: 1 addition & 0 deletions cmd/ipfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func (i *cmdInvocation) constructNodeFunc(ctx context.Context) func() (*core.Ipf
if err != nil {
return nil, err
}
n.SetLocal(true)
i.node = n
return i.node, nil
}
Expand Down
22 changes: 22 additions & 0 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type mode int
const (
// zero value is not a valid mode, must be explicitly set
invalidMode mode = iota
localMode
offlineMode
onlineMode
)
Expand Down Expand Up @@ -116,6 +117,7 @@ type IpfsNode struct {
ctx context.Context

mode mode
localModeSet bool
}

// Mounts defines what the node's mount state is. This should
Expand Down Expand Up @@ -396,6 +398,26 @@ func (n *IpfsNode) OnlineMode() bool {
}
}

func (n *IpfsNode) SetLocal(isLocal bool) {
if isLocal {
n.mode = localMode
}
n.localModeSet = true
}

func (n *IpfsNode) LocalMode() bool {
if !n.localModeSet {
// programmer error should not happen
panic("local mode not set")
}
switch n.mode {
case localMode:
return true
default:
return false
}
}

func (n *IpfsNode) Bootstrap(cfg BootstrapConfig) error {

// TODO what should return value be when in offlineMode?
Expand Down

0 comments on commit bf80213

Please sign in to comment.