update for the new namesys api

This commit is contained in:
vyzo 2021-04-16 01:05:35 +03:00 committed by Steven Allen
parent 0b4037c7cd
commit eb7456d38f
3 changed files with 25 additions and 4 deletions

View File

@ -215,7 +215,15 @@ func (api *CoreAPI) WithOptions(opts ...options.ApiOption) (coreiface.CoreAPI, e
}
subApi.routing = offlineroute.NewOfflineRouter(subApi.repo.Datastore(), subApi.recordValidator)
subApi.namesys = namesys.NewNameSystem(subApi.routing, subApi.repo.Datastore(), subApi.dnsResolver, cs)
subApi.namesys, err = namesys.NewNameSystem(subApi.routing,
namesys.WithDatastore(subApi.repo.Datastore()),
namesys.WithDNSResolver(subApi.dnsResolver),
namesys.WithCache(cs))
if err != nil {
return nil, fmt.Errorf("error constructing namesys: %w", err)
}
subApi.provider = provider.NewOfflineProvider()
subApi.peerstore = nil

View File

@ -93,9 +93,13 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name
}
var resolver namesys.Resolver = api.namesys
if !options.Cache {
resolver = namesys.NewNameSystem(api.routing, api.repo.Datastore(), api.dnsResolver, 0)
resolver, err = namesys.NewNameSystem(api.routing,
namesys.WithDatastore(api.repo.Datastore()),
namesys.WithDNSResolver(api.dnsResolver))
if err != nil {
return nil, err
}
}
if !strings.HasPrefix(name, "/ipns/") {

View File

@ -30,7 +30,16 @@ func RecordValidator(ps peerstore.Peerstore) record.Validator {
// Namesys creates new name system
func Namesys(cacheSize int) func(rt routing.Routing, rslv *madns.Resolver, repo repo.Repo) (namesys.NameSystem, error) {
return func(rt routing.Routing, rslv *madns.Resolver, repo repo.Repo) (namesys.NameSystem, error) {
return namesys.NewNameSystem(rt, repo.Datastore(), rslv, cacheSize), nil
opts := []namesys.Option{
namesys.WithDatastore(repo.Datastore()),
namesys.WithDNSResolver(rslv),
}
if cacheSize > 0 {
opts = append(opts, namesys.WithCache(cacheSize))
}
return namesys.NewNameSystem(rt, opts...)
}
}