Skip to content

Commit

Permalink
Merge pull request #3259 from ipfs/kevina/local-mode
Browse files Browse the repository at this point in the history
Distinguish between Offline and Local Mode.
  • Loading branch information
whyrusleeping authored Nov 2, 2016
2 parents 437cc7f + bf80213 commit 4b793f9
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 @@ -332,6 +332,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 @@ -76,6 +76,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 @@ -120,6 +121,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 @@ -404,6 +406,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 4b793f9

Please sign in to comment.