@cryptotaxi247 / kubo / commits / 6044d2ae8

coreapi offline: Address review

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Dec 19, 2018 at 02:08 UTC 6044d2ae8976b126d9e62dccc5dbfe4d554f129b
4 files changed +11 -13
core/coreapi/coreapi.go
+4 -6
@@ -67,10 +67,8 @@ type CoreAPI struct {
67
68 pubSub *pubsub.PubSub
69
70 - // TODO: this can be generalized to all functions when we implement some
71 - // api based security mechanism
72 - isPublishAllowed func() error
73 - isOnline func(allowOffline bool) error
70 + checkPublishAllowed func() error
71 + checkOnline func(allowOffline bool) error
72
73 // ONLY for re-applying options in WithOptions, DO NOT USE ANYWHERE ELSE
74 nd *core.IpfsNode
@@ -178,14 +176,14 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
176 parentOpts: settings,
177 }
178
181 - subApi.isOnline = func(allowOffline bool) error {
179 + subApi.checkOnline = func(allowOffline bool) error {
180 if !n.OnlineMode() && !allowOffline {
181 return coreiface.ErrOffline
182 }
183 return nil
184 }
185
188 - subApi.isPublishAllowed = func() error {
186 + subApi.checkPublishAllowed = func() error {
187 if n.Mounts.Ipns != nil && n.Mounts.Ipns.IsActive() {
188 return errors.New("cannot manually publish while IPNS is mounted")
189 }
core/coreapi/dht.go
+3 -3
@@ -21,7 +21,7 @@ import (
21 type DhtAPI CoreAPI
22
23 func (api *DhtAPI) FindPeer(ctx context.Context, p peer.ID) (pstore.PeerInfo, error) {
24 - err := api.isOnline(false)
24 + err := api.checkOnline(false)
25 if err != nil {
26 return pstore.PeerInfo{}, err
27 }
@@ -40,7 +40,7 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p coreiface.Path, opts ...
40 return nil, err
41 }
42
43 - err = api.isOnline(false)
43 + err = api.checkOnline(false)
44 if err != nil {
45 return nil, err
46 }
@@ -65,7 +65,7 @@ func (api *DhtAPI) Provide(ctx context.Context, path coreiface.Path, opts ...cao
65 return err
66 }
67
68 - err = api.isOnline(false)
68 + err = api.checkOnline(false)
69 if err != nil {
70 return err
71 }
core/coreapi/name.go
+3 -3
@@ -36,7 +36,7 @@ func (e *ipnsEntry) Value() coreiface.Path {
36
37 // Publish announces new IPNS name and returns the new IPNS entry.
38 func (api *NameAPI) Publish(ctx context.Context, p coreiface.Path, opts ...caopts.NamePublishOption) (coreiface.IpnsEntry, error) {
39 - if err := api.isPublishAllowed(); err != nil {
39 + if err := api.checkPublishAllowed(); err != nil {
40 return nil, err
41 }
42
@@ -45,7 +45,7 @@ func (api *NameAPI) Publish(ctx context.Context, p coreiface.Path, opts ...caopt
45 return nil, err
46 }
47
48 - err = api.isOnline(options.AllowOffline)
48 + err = api.checkOnline(options.AllowOffline)
49 if err != nil {
50 return nil, err
51 }
@@ -87,7 +87,7 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name
87 return nil, err
88 }
89
90 - err = api.isOnline(true)
90 + err = api.checkOnline(true)
91 if err != nil {
92 return nil, err
93 }
core/coreapi/pubsub.go
+1 -1
@@ -127,7 +127,7 @@ func (api *PubSubAPI) checkNode() (routing.IpfsRouting, error) {
127 return nil, errors.New("experimental pubsub feature not enabled. Run daemon with --enable-pubsub-experiment to use.")
128 }
129
130 - err := api.isOnline(false)
130 + err := api.checkOnline(false)
131 if err != nil {
132 return nil, err
133 }