Skip to content

Distinguish between Offline and Local Mode. #3259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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