提交 4b793f91 作者: Jeromy Johnson 提交者: GitHub

Merge pull request #3259 from ipfs/kevina/local-mode

Distinguish between Offline and Local Mode.
...@@ -332,6 +332,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) { ...@@ -332,6 +332,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
res.SetError(err, cmds.ErrNormal) res.SetError(err, cmds.ErrNormal)
return return
} }
node.SetLocal(false)
printSwarmAddrs(node) printSwarmAddrs(node)
......
...@@ -227,6 +227,7 @@ func (i *cmdInvocation) constructNodeFunc(ctx context.Context) func() (*core.Ipf ...@@ -227,6 +227,7 @@ func (i *cmdInvocation) constructNodeFunc(ctx context.Context) func() (*core.Ipf
if err != nil { if err != nil {
return nil, err return nil, err
} }
n.SetLocal(true)
i.node = n i.node = n
return i.node, nil return i.node, nil
} }
......
...@@ -76,6 +76,7 @@ type mode int ...@@ -76,6 +76,7 @@ type mode int
const ( const (
// zero value is not a valid mode, must be explicitly set // zero value is not a valid mode, must be explicitly set
invalidMode mode = iota invalidMode mode = iota
localMode
offlineMode offlineMode
onlineMode onlineMode
) )
...@@ -120,6 +121,7 @@ type IpfsNode struct { ...@@ -120,6 +121,7 @@ type IpfsNode struct {
ctx context.Context ctx context.Context
mode mode mode mode
localModeSet bool
} }
// Mounts defines what the node's mount state is. This should // Mounts defines what the node's mount state is. This should
...@@ -404,6 +406,26 @@ func (n *IpfsNode) OnlineMode() bool { ...@@ -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 { func (n *IpfsNode) Bootstrap(cfg BootstrapConfig) error {
// TODO what should return value be when in offlineMode? // TODO what should return value be when in offlineMode?
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论