mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-02 12:20:03 +08:00
add online method to node
This commit is contained in:

committed by
Juan Batiz-Benet

parent
e096060b90
commit
772f657fcd
@ -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) {
|
|||||||
// 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) {
|
|||||||
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?)")
|
||||||
|
Reference in New Issue
Block a user