mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-26 04:47:45 +08:00
update for the new namesys api
This commit is contained in:
parent
0b4037c7cd
commit
eb7456d38f
@ -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
|
||||
|
||||
@ -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/") {
|
||||
|
||||
@ -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...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user