1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-19 09:52:03 +08:00

namesys: drop prefix args

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
Łukasz Magiera
2018-10-16 16:35:31 +02:00
parent 7dbeb27e5b
commit e335fd32f2
7 changed files with 25 additions and 22 deletions

View File

@ -40,7 +40,7 @@ type NameAPI interface {
// Search is a version of Resolve which outputs paths as they are discovered,
// reducing the time to first entry
//
// Note that by default only the last path returned before the channel closes
// can be considered 'safe'.
// Note: by default, all paths read from the channel are considered unsafe,
// except the latest (last path in channel read buffer).
Search(ctx context.Context, name string, opts ...options.NameResolveOption) (<-chan IpnsResult, error)
}

View File

@ -21,14 +21,14 @@ type resolver interface {
}
// resolve is a helper for implementing Resolver.ResolveN using resolveOnce.
func resolve(ctx context.Context, r resolver, name string, options opts.ResolveOpts, prefix string) (path.Path, error) {
func resolve(ctx context.Context, r resolver, name string, options opts.ResolveOpts) (path.Path, error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
err := ErrResolveFailed
var p path.Path
resCh := resolveAsync(ctx, r, name, options, prefix)
resCh := resolveAsync(ctx, r, name, options)
for res := range resCh {
p, err = res.Path, res.Err
@ -40,7 +40,7 @@ func resolve(ctx context.Context, r resolver, name string, options opts.ResolveO
return p, err
}
func resolveAsync(ctx context.Context, r resolver, name string, options opts.ResolveOpts, prefix string) <-chan Result {
func resolveAsync(ctx context.Context, r resolver, name string, options opts.ResolveOpts) <-chan Result {
resCh := r.resolveOnceAsync(ctx, name, options)
depth := options.Depth
outCh := make(chan Result, 1)
@ -86,8 +86,8 @@ func resolveAsync(ctx context.Context, r resolver, name string, options opts.Res
subCtx, cancelSub = context.WithCancel(ctx)
defer cancelSub()
p := strings.TrimPrefix(res.value.String(), prefix)
subCh = resolveAsync(subCtx, r, p, subopts, prefix)
p := strings.TrimPrefix(res.value.String(), ipnsPrefix)
subCh = resolveAsync(subCtx, r, p, subopts)
case res, ok := <-subCh:
if !ok {
subCh = nil

View File

@ -28,12 +28,12 @@ func NewDNSResolver() *DNSResolver {
// Resolve implements Resolver.
func (r *DNSResolver) Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (path.Path, error) {
return resolve(ctx, r, name, opts.ProcessOpts(options), "/ipns/")
return resolve(ctx, r, name, opts.ProcessOpts(options))
}
// ResolveAsync implements Resolver.
func (r *DNSResolver) ResolveAsync(ctx context.Context, name string, options ...opts.ResolveOpt) <-chan Result {
return resolveAsync(ctx, r, name, opts.ProcessOpts(options), "/ipns/")
return resolveAsync(ctx, r, name, opts.ProcessOpts(options))
}
type lookupRes struct {

View File

@ -5,9 +5,10 @@ import (
"testing"
"time"
opts "github.com/ipfs/go-ipfs/namesys/opts"
path "gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
opts "github.com/ipfs/go-ipfs/namesys/opts"
testutil "gx/ipfs/QmNfQbgBfARAtrYsBguChX6VJ5nbjeoYy1KdC36aaYWqG8/go-testutil"
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
routing "gx/ipfs/QmPmFeQ5oY5G6M7aBWggi5phxEPXwsQntE1DFcUzETULdp/go-libp2p-routing"
@ -57,7 +58,7 @@ func TestResolverValidation(t *testing.T) {
}
// Resolve entry
resp, err := resolve(ctx, resolver, id.Pretty(), opts.DefaultResolveOpts(), "/ipns/")
resp, err := resolve(ctx, resolver, id.Pretty(), opts.DefaultResolveOpts())
if err != nil {
t.Fatal(err)
}
@ -77,7 +78,7 @@ func TestResolverValidation(t *testing.T) {
}
// Record should fail validation because entry is expired
_, err = resolve(ctx, resolver, id.Pretty(), opts.DefaultResolveOpts(), "/ipns/")
_, err = resolve(ctx, resolver, id.Pretty(), opts.DefaultResolveOpts())
if err == nil {
t.Fatal("ValidateIpnsRecord should have returned error")
}
@ -99,7 +100,7 @@ func TestResolverValidation(t *testing.T) {
// Record should fail validation because public key defined by
// ipns path doesn't match record signature
_, err = resolve(ctx, resolver, id2.Pretty(), opts.DefaultResolveOpts(), "/ipns/")
_, err = resolve(ctx, resolver, id2.Pretty(), opts.DefaultResolveOpts())
if err == nil {
t.Fatal("ValidateIpnsRecord should have failed signature verification")
}
@ -117,7 +118,7 @@ func TestResolverValidation(t *testing.T) {
// Record should fail validation because public key is not available
// in peer store or on network
_, err = resolve(ctx, resolver, id3.Pretty(), opts.DefaultResolveOpts(), "/ipns/")
_, err = resolve(ctx, resolver, id3.Pretty(), opts.DefaultResolveOpts())
if err == nil {
t.Fatal("ValidateIpnsRecord should have failed because public key was not found")
}
@ -132,7 +133,7 @@ func TestResolverValidation(t *testing.T) {
// public key is available in the peer store by looking it up in
// the DHT, which causes the DHT to fetch it and cache it in the
// peer store
_, err = resolve(ctx, resolver, id3.Pretty(), opts.DefaultResolveOpts(), "/ipns/")
_, err = resolve(ctx, resolver, id3.Pretty(), opts.DefaultResolveOpts())
if err != nil {
t.Fatal(err)
}

View File

@ -62,7 +62,7 @@ func (ns *mpns) Resolve(ctx context.Context, name string, options ...opts.Resolv
return path.ParsePath("/ipfs/" + name)
}
return resolve(ctx, ns, name, opts.ProcessOpts(options), "/ipns/")
return resolve(ctx, ns, name, opts.ProcessOpts(options))
}
func (ns *mpns) ResolveAsync(ctx context.Context, name string, options ...opts.ResolveOpt) <-chan Result {
@ -79,7 +79,7 @@ func (ns *mpns) ResolveAsync(ctx context.Context, name string, options ...opts.R
return res
}
return resolveAsync(ctx, ns, name, opts.ProcessOpts(options), "/ipns/")
return resolveAsync(ctx, ns, name, opts.ProcessOpts(options))
}
// resolveOnce implements resolver.

View File

@ -4,16 +4,17 @@ import (
"context"
"errors"
opts "github.com/ipfs/go-ipfs/namesys/opts"
proquint "gx/ipfs/QmYnf27kzqR2cxt6LFZdrAFJuQd6785fTkBvMuEj9EeRxM/proquint"
path "gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
opts "github.com/ipfs/go-ipfs/namesys/opts"
)
type ProquintResolver struct{}
// Resolve implements Resolver.
func (r *ProquintResolver) Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (path.Path, error) {
return resolve(ctx, r, name, opts.ProcessOpts(options), "/ipns/")
return resolve(ctx, r, name, opts.ProcessOpts(options))
}
// resolveOnce implements resolver. Decodes the proquint string.

View File

@ -5,9 +5,10 @@ import (
"strings"
"time"
opts "github.com/ipfs/go-ipfs/namesys/opts"
path "gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
opts "github.com/ipfs/go-ipfs/namesys/opts"
cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
routing "gx/ipfs/QmPmFeQ5oY5G6M7aBWggi5phxEPXwsQntE1DFcUzETULdp/go-libp2p-routing"
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
@ -39,12 +40,12 @@ func NewIpnsResolver(route routing.ValueStore) *IpnsResolver {
// Resolve implements Resolver.
func (r *IpnsResolver) Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (path.Path, error) {
return resolve(ctx, r, name, opts.ProcessOpts(options), "/ipns/")
return resolve(ctx, r, name, opts.ProcessOpts(options))
}
// ResolveAsync implements Resolver.
func (r *IpnsResolver) ResolveAsync(ctx context.Context, name string, options ...opts.ResolveOpt) <-chan Result {
return resolveAsync(ctx, r, name, opts.ProcessOpts(options), "/ipns/")
return resolveAsync(ctx, r, name, opts.ProcessOpts(options))
}
// resolveOnce implements resolver. Uses the IPFS routing system to