提交 772f657f 作者: Brian Tiger Chow 提交者: Juan Batiz-Benet

add online method to node

上级 e096060b
...@@ -74,6 +74,8 @@ type IpfsNode struct { ...@@ -74,6 +74,8 @@ type IpfsNode struct {
Pinning pin.Pinner Pinning pin.Pinner
ctxc.ContextCloser ctxc.ContextCloser
online bool // alternatively, offline
} }
// NewIpfsNode constructs a new IpfsNode based on the given config. // NewIpfsNode constructs a new IpfsNode based on the given config.
...@@ -92,6 +94,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) { ...@@ -92,6 +94,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) {
// derive this from a higher context. // derive this from a higher context.
ctx := context.TODO() ctx := context.TODO()
n = &IpfsNode{ n = &IpfsNode{
online: online,
Config: cfg, Config: cfg,
ContextCloser: ctxc.NewContextCloser(ctx, nil), ContextCloser: ctxc.NewContextCloser(ctx, nil),
} }
...@@ -172,6 +175,10 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) { ...@@ -172,6 +175,10 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) {
return n, nil return n, nil
} }
func (n *IpfsNode) Online() bool {
return n.online
}
func initIdentity(cfg *config.Config, peers peer.Peerstore, online bool) (peer.Peer, error) { func initIdentity(cfg *config.Config, peers peer.Peerstore, online bool) (peer.Peer, error) {
if cfg.Identity.PeerID == "" { if cfg.Identity.PeerID == "" {
return nil, errors.New("Identity was not set in config (was ipfs init run?)") return nil, errors.New("Identity was not set in config (was ipfs init run?)")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论