coreapi: FetchBlocks option
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Jan 4, 2019 at 15:40 UTC
2c28ef19ae9850dc4ed903f0210245b07426baa6
2 files changed
+15
-2
core/coreapi/coreapi.go
+2
@@ -210,7 +210,9 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
210
subApi.peerstore = nil
211
subApi.peerHost = nil
212
subApi.recordValidator = nil
213
+ }
214
215
+ if settings.Offline || !settings.FetchBlocks {
216
subApi.exchange = offlinexch.Exchange(subApi.blockstore)
217
subApi.blocks = bserv.New(subApi.blockstore, subApi.exchange)
218
subApi.dag = dag.NewDAGService(subApi.blocks)
core/coreapi/interface/options/global.go
+13
-2
@@ -1,14 +1,16 @@
1
package options
2
3
type ApiSettings struct {
4
- Offline bool
4
+ Offline bool
5
+ FetchBlocks bool
6
}
7
8
type ApiOption func(*ApiSettings) error
9
10
func ApiOptions(opts ...ApiOption) (*ApiSettings, error) {
11
options := &ApiSettings{
11
- Offline: false,
12
+ Offline: false,
13
+ FetchBlocks: true,
14
}
15
16
return ApiOptionsTo(options, opts...)
@@ -34,3 +36,12 @@ func (apiOpts) Offline(offline bool) ApiOption {
36
return nil
37
}
38
}
39
+
40
+// FetchBlocks when set to false prevents api from fetching blocks from the
41
+// network while allowing other services such as IPNS to still be online
42
+func (apiOpts) FetchBlocks(fetch bool) ApiOption {
43
+ return func(settings *ApiSettings) error {
44
+ settings.FetchBlocks = fetch
45
+ return nil
46
+ }
47
+}