diff --git a/core/coreapi/coreapi.go b/core/coreapi/coreapi.go index 44068a16e..407d29cdc 100644 --- a/core/coreapi/coreapi.go +++ b/core/coreapi/coreapi.go @@ -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") } diff --git a/core/coreapi/dht.go b/core/coreapi/dht.go index 4e91169de..4b0616566 100644 --- a/core/coreapi/dht.go +++ b/core/coreapi/dht.go @@ -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 } diff --git a/core/coreapi/name.go b/core/coreapi/name.go index d9e95925e..e986567b5 100644 --- a/core/coreapi/name.go +++ b/core/coreapi/name.go @@ -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 } diff --git a/core/coreapi/pubsub.go b/core/coreapi/pubsub.go index d02638300..6ec123a98 100644 --- a/core/coreapi/pubsub.go +++ b/core/coreapi/pubsub.go @@ -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 }