update for the new namesys api
vyzo committed
Apr 16, 2021 at 01:05 UTC
eb7456d38fb6455d31a239c2558bfc73af094e57
3 files changed
+25
-4
core/coreapi/coreapi.go
+9
-1
@@ -215,7 +215,15 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
215
}
216
217
subApi.routing = offlineroute.NewOfflineRouter(subApi.repo.Datastore(), subApi.recordValidator)
218
- subApi.namesys = namesys.NewNameSystem(subApi.routing, subApi.repo.Datastore(), subApi.dnsResolver, cs)
218
+
219
+ subApi.namesys, err = namesys.NewNameSystem(subApi.routing,
220
+ namesys.WithDatastore(subApi.repo.Datastore()),
221
+ namesys.WithDNSResolver(subApi.dnsResolver),
222
+ namesys.WithCache(cs))
223
+ if err != nil {
224
+ return nil, fmt.Errorf("error constructing namesys: %w", err)
225
+ }
226
+
227
subApi.provider = provider.NewOfflineProvider()
228
229
subApi.peerstore = nil
core/coreapi/name.go
+6
-2
@@ -93,9 +93,13 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name
93
}
94
95
var resolver namesys.Resolver = api.namesys
96
-
96
if !options.Cache {
98
- resolver = namesys.NewNameSystem(api.routing, api.repo.Datastore(), api.dnsResolver, 0)
97
+ resolver, err = namesys.NewNameSystem(api.routing,
98
+ namesys.WithDatastore(api.repo.Datastore()),
99
+ namesys.WithDNSResolver(api.dnsResolver))
100
+ if err != nil {
101
+ return nil, err
102
+ }
103
}
104
105
if !strings.HasPrefix(name, "/ipns/") {
core/node/ipns.go
+10
-1
@@ -30,7 +30,16 @@ func RecordValidator(ps peerstore.Peerstore) record.Validator {
30
// Namesys creates new name system
31
func Namesys(cacheSize int) func(rt routing.Routing, rslv *madns.Resolver, repo repo.Repo) (namesys.NameSystem, error) {
32
return func(rt routing.Routing, rslv *madns.Resolver, repo repo.Repo) (namesys.NameSystem, error) {
33
- return namesys.NewNameSystem(rt, repo.Datastore(), rslv, cacheSize), nil
33
+ opts := []namesys.Option{
34
+ namesys.WithDatastore(repo.Datastore()),
35
+ namesys.WithDNSResolver(rslv),
36
+ }
37
+
38
+ if cacheSize > 0 {
39
+ opts = append(opts, namesys.WithCache(cacheSize))
40
+ }
41
+
42
+ return namesys.NewNameSystem(rt, opts...)
43
}
44
}
45