mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-25 04:17:44 +08:00
coreapi offline: Address review
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
parent
190728f04a
commit
6044d2ae89
@ -67,10 +67,8 @@ type CoreAPI struct {
|
||||
|
||||
pubSub *pubsub.PubSub
|
||||
|
||||
// TODO: this can be generalized to all functions when we implement some
|
||||
// api based security mechanism
|
||||
isPublishAllowed func() error
|
||||
isOnline func(allowOffline bool) error
|
||||
checkPublishAllowed func() error
|
||||
checkOnline func(allowOffline bool) error
|
||||
|
||||
// ONLY for re-applying options in WithOptions, DO NOT USE ANYWHERE ELSE
|
||||
nd *core.IpfsNode
|
||||
@ -178,14 +176,14 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
|
||||
parentOpts: settings,
|
||||
}
|
||||
|
||||
subApi.isOnline = func(allowOffline bool) error {
|
||||
subApi.checkOnline = func(allowOffline bool) error {
|
||||
if !n.OnlineMode() && !allowOffline {
|
||||
return coreiface.ErrOffline
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
subApi.isPublishAllowed = func() error {
|
||||
subApi.checkPublishAllowed = func() error {
|
||||
if n.Mounts.Ipns != nil && n.Mounts.Ipns.IsActive() {
|
||||
return errors.New("cannot manually publish while IPNS is mounted")
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ import (
|
||||
type DhtAPI CoreAPI
|
||||
|
||||
func (api *DhtAPI) FindPeer(ctx context.Context, p peer.ID) (pstore.PeerInfo, error) {
|
||||
err := api.isOnline(false)
|
||||
err := api.checkOnline(false)
|
||||
if err != nil {
|
||||
return pstore.PeerInfo{}, err
|
||||
}
|
||||
@ -40,7 +40,7 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p coreiface.Path, opts ...
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = api.isOnline(false)
|
||||
err = api.checkOnline(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -65,7 +65,7 @@ func (api *DhtAPI) Provide(ctx context.Context, path coreiface.Path, opts ...cao
|
||||
return err
|
||||
}
|
||||
|
||||
err = api.isOnline(false)
|
||||
err = api.checkOnline(false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ func (e *ipnsEntry) Value() coreiface.Path {
|
||||
|
||||
// Publish announces new IPNS name and returns the new IPNS entry.
|
||||
func (api *NameAPI) Publish(ctx context.Context, p coreiface.Path, opts ...caopts.NamePublishOption) (coreiface.IpnsEntry, error) {
|
||||
if err := api.isPublishAllowed(); err != nil {
|
||||
if err := api.checkPublishAllowed(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ func (api *NameAPI) Publish(ctx context.Context, p coreiface.Path, opts ...caopt
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = api.isOnline(options.AllowOffline)
|
||||
err = api.checkOnline(options.AllowOffline)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -87,7 +87,7 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = api.isOnline(true)
|
||||
err = api.checkOnline(true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ func (api *PubSubAPI) checkNode() (routing.IpfsRouting, error) {
|
||||
return nil, errors.New("experimental pubsub feature not enabled. Run daemon with --enable-pubsub-experiment to use.")
|
||||
}
|
||||
|
||||
err := api.isOnline(false)
|
||||
err := api.checkOnline(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user