@cryptotaxi247 / kubo / commits / e335fd32f

namesys: drop prefix args

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Oct 16, 2018 at 16:35 UTC e335fd32f26951d84df57813b7a91bc23b09062e
7 files changed +25 -22
core/coreapi/interface/name.go
+2 -2
@@ -40,7 +40,7 @@ type NameAPI interface {
40 // Search is a version of Resolve which outputs paths as they are discovered,
41 // reducing the time to first entry
42 //
43 - // Note that by default only the last path returned before the channel closes
44 - // can be considered 'safe'.
43 + // Note: by default, all paths read from the channel are considered unsafe,
44 + // except the latest (last path in channel read buffer).
45 Search(ctx context.Context, name string, opts ...options.NameResolveOption) (<-chan IpnsResult, error)
46 }
namesys/base.go
+5 -5
@@ -21,14 +21,14 @@ type resolver interface {
21 }
22
23 // resolve is a helper for implementing Resolver.ResolveN using resolveOnce.
24 -func resolve(ctx context.Context, r resolver, name string, options opts.ResolveOpts, prefix string) (path.Path, error) {
24 +func resolve(ctx context.Context, r resolver, name string, options opts.ResolveOpts) (path.Path, error) {
25 ctx, cancel := context.WithCancel(ctx)
26 defer cancel()
27
28 err := ErrResolveFailed
29 var p path.Path
30
31 - resCh := resolveAsync(ctx, r, name, options, prefix)
31 + resCh := resolveAsync(ctx, r, name, options)
32
33 for res := range resCh {
34 p, err = res.Path, res.Err
@@ -40,7 +40,7 @@ func resolve(ctx context.Context, r resolver, name string, options opts.ResolveO
40 return p, err
41 }
42
43 -func resolveAsync(ctx context.Context, r resolver, name string, options opts.ResolveOpts, prefix string) <-chan Result {
43 +func resolveAsync(ctx context.Context, r resolver, name string, options opts.ResolveOpts) <-chan Result {
44 resCh := r.resolveOnceAsync(ctx, name, options)
45 depth := options.Depth
46 outCh := make(chan Result, 1)
@@ -86,8 +86,8 @@ func resolveAsync(ctx context.Context, r resolver, name string, options opts.Res
86 subCtx, cancelSub = context.WithCancel(ctx)
87 defer cancelSub()
88
89 - p := strings.TrimPrefix(res.value.String(), prefix)
90 - subCh = resolveAsync(subCtx, r, p, subopts, prefix)
89 + p := strings.TrimPrefix(res.value.String(), ipnsPrefix)
90 + subCh = resolveAsync(subCtx, r, p, subopts)
91 case res, ok := <-subCh:
92 if !ok {
93 subCh = nil
namesys/dns.go
+2 -2
@@ -28,12 +28,12 @@ func NewDNSResolver() *DNSResolver {
28
29 // Resolve implements Resolver.
30 func (r *DNSResolver) Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (path.Path, error) {
31 - return resolve(ctx, r, name, opts.ProcessOpts(options), "/ipns/")
31 + return resolve(ctx, r, name, opts.ProcessOpts(options))
32 }
33
34 // ResolveAsync implements Resolver.
35 func (r *DNSResolver) ResolveAsync(ctx context.Context, name string, options ...opts.ResolveOpt) <-chan Result {
36 - return resolveAsync(ctx, r, name, opts.ProcessOpts(options), "/ipns/")
36 + return resolveAsync(ctx, r, name, opts.ProcessOpts(options))
37 }
38
39 type lookupRes struct {
namesys/ipns_resolver_validation_test.go
+7 -6
@@ -5,9 +5,10 @@ import (
5 "testing"
6 "time"
7
8 - opts "github.com/ipfs/go-ipfs/namesys/opts"
8 path "gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
9
10 + opts "github.com/ipfs/go-ipfs/namesys/opts"
11 +
12 testutil "gx/ipfs/QmNfQbgBfARAtrYsBguChX6VJ5nbjeoYy1KdC36aaYWqG8/go-testutil"
13 u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
14 routing "gx/ipfs/QmPmFeQ5oY5G6M7aBWggi5phxEPXwsQntE1DFcUzETULdp/go-libp2p-routing"
@@ -57,7 +58,7 @@ func TestResolverValidation(t *testing.T) {
58 }
59
60 // Resolve entry
60 - resp, err := resolve(ctx, resolver, id.Pretty(), opts.DefaultResolveOpts(), "/ipns/")
61 + resp, err := resolve(ctx, resolver, id.Pretty(), opts.DefaultResolveOpts())
62 if err != nil {
63 t.Fatal(err)
64 }
@@ -77,7 +78,7 @@ func TestResolverValidation(t *testing.T) {
78 }
79
80 // Record should fail validation because entry is expired
80 - _, err = resolve(ctx, resolver, id.Pretty(), opts.DefaultResolveOpts(), "/ipns/")
81 + _, err = resolve(ctx, resolver, id.Pretty(), opts.DefaultResolveOpts())
82 if err == nil {
83 t.Fatal("ValidateIpnsRecord should have returned error")
84 }
@@ -99,7 +100,7 @@ func TestResolverValidation(t *testing.T) {
100
101 // Record should fail validation because public key defined by
102 // ipns path doesn't match record signature
102 - _, err = resolve(ctx, resolver, id2.Pretty(), opts.DefaultResolveOpts(), "/ipns/")
103 + _, err = resolve(ctx, resolver, id2.Pretty(), opts.DefaultResolveOpts())
104 if err == nil {
105 t.Fatal("ValidateIpnsRecord should have failed signature verification")
106 }
@@ -117,7 +118,7 @@ func TestResolverValidation(t *testing.T) {
118
119 // Record should fail validation because public key is not available
120 // in peer store or on network
120 - _, err = resolve(ctx, resolver, id3.Pretty(), opts.DefaultResolveOpts(), "/ipns/")
121 + _, err = resolve(ctx, resolver, id3.Pretty(), opts.DefaultResolveOpts())
122 if err == nil {
123 t.Fatal("ValidateIpnsRecord should have failed because public key was not found")
124 }
@@ -132,7 +133,7 @@ func TestResolverValidation(t *testing.T) {
133 // public key is available in the peer store by looking it up in
134 // the DHT, which causes the DHT to fetch it and cache it in the
135 // peer store
135 - _, err = resolve(ctx, resolver, id3.Pretty(), opts.DefaultResolveOpts(), "/ipns/")
136 + _, err = resolve(ctx, resolver, id3.Pretty(), opts.DefaultResolveOpts())
137 if err != nil {
138 t.Fatal(err)
139 }
namesys/namesys.go
+2 -2
@@ -62,7 +62,7 @@ func (ns *mpns) Resolve(ctx context.Context, name string, options ...opts.Resolv
62 return path.ParsePath("/ipfs/" + name)
63 }
64
65 - return resolve(ctx, ns, name, opts.ProcessOpts(options), "/ipns/")
65 + return resolve(ctx, ns, name, opts.ProcessOpts(options))
66 }
67
68 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
79 return res
80 }
81
82 - return resolveAsync(ctx, ns, name, opts.ProcessOpts(options), "/ipns/")
82 + return resolveAsync(ctx, ns, name, opts.ProcessOpts(options))
83 }
84
85 // resolveOnce implements resolver.
namesys/proquint.go
+3 -2
@@ -4,16 +4,17 @@ import (
4 "context"
5 "errors"
6
7 - opts "github.com/ipfs/go-ipfs/namesys/opts"
7 proquint "gx/ipfs/QmYnf27kzqR2cxt6LFZdrAFJuQd6785fTkBvMuEj9EeRxM/proquint"
8 path "gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
9 +
10 + opts "github.com/ipfs/go-ipfs/namesys/opts"
11 )
12
13 type ProquintResolver struct{}
14
15 // Resolve implements Resolver.
16 func (r *ProquintResolver) Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (path.Path, error) {
16 - return resolve(ctx, r, name, opts.ProcessOpts(options), "/ipns/")
17 + return resolve(ctx, r, name, opts.ProcessOpts(options))
18 }
19
20 // resolveOnce implements resolver. Decodes the proquint string.
namesys/routing.go
+4 -3
@@ -5,9 +5,10 @@ import (
5 "strings"
6 "time"
7
8 - opts "github.com/ipfs/go-ipfs/namesys/opts"
8 path "gx/ipfs/QmdrpbDgeYH3VxkCciQCJY5LkDYdXtig6unDzQmMxFtWEw/go-path"
9
10 + opts "github.com/ipfs/go-ipfs/namesys/opts"
11 +
12 cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
13 routing "gx/ipfs/QmPmFeQ5oY5G6M7aBWggi5phxEPXwsQntE1DFcUzETULdp/go-libp2p-routing"
14 mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
@@ -39,12 +40,12 @@ func NewIpnsResolver(route routing.ValueStore) *IpnsResolver {
40
41 // Resolve implements Resolver.
42 func (r *IpnsResolver) Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (path.Path, error) {
42 - return resolve(ctx, r, name, opts.ProcessOpts(options), "/ipns/")
43 + return resolve(ctx, r, name, opts.ProcessOpts(options))
44 }
45
46 // ResolveAsync implements Resolver.
47 func (r *IpnsResolver) ResolveAsync(ctx context.Context, name string, options ...opts.ResolveOpt) <-chan Result {
47 - return resolveAsync(ctx, r, name, opts.ProcessOpts(options), "/ipns/")
48 + return resolveAsync(ctx, r, name, opts.ProcessOpts(options))
49 }
50
51 // resolveOnce implements resolver. Uses the IPFS routing system to