Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a9eb7dc

Browse files
committedMar 3, 2020
test(namesys): proper peerid resolution in /ipns/
This switches to peer.Decode as suggested in #6096 (comment) and adds tests for missing PeerID types. License: MIT Signed-off-by: Marcin Rataj <lidel@lidel.org>
1 parent defb1fd commit a9eb7dc

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed
 

‎namesys/namesys.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"time"
77

88
lru "github.com/hashicorp/golang-lru"
9-
cid "github.com/ipfs/go-cid"
109
ds "github.com/ipfs/go-datastore"
1110
path "github.com/ipfs/go-path"
1211
opts "github.com/ipfs/interface-go-ipfs-core/options/namesys"
@@ -112,12 +111,12 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.
112111
}
113112

114113
// Resolver selection:
115-
// 1. if it is a CID/multihash resolve through "ipns".
114+
// 1. if it is a PeerID/CID/multihash resolve through "ipns".
116115
// 2. if it is a domain name, resolve through "dns"
117116
// 3. otherwise resolve through the "proquint" resolver
118117

119118
var res resolver
120-
if _, err := cid.Decode(key); err == nil {
119+
if _, err := peer.Decode(key); err == nil {
121120
res = ns.ipnsResolver
122121
} else if isd.IsDomain(key) {
123122
res = ns.dnsResolver

‎namesys/namesys_test.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
offroute "github.com/ipfs/go-ipfs-routing/offline"
1212
ipns "github.com/ipfs/go-ipns"
1313
path "github.com/ipfs/go-path"
14-
"github.com/ipfs/go-unixfs"
14+
unixfs "github.com/ipfs/go-unixfs"
1515
opts "github.com/ipfs/interface-go-ipfs-core/options/namesys"
1616
ci "github.com/libp2p/go-libp2p-core/crypto"
1717
peer "github.com/libp2p/go-libp2p-core/peer"
@@ -49,10 +49,12 @@ func (r *mockResolver) resolveOnceAsync(ctx context.Context, name string, option
4949
func mockResolverOne() *mockResolver {
5050
return &mockResolver{
5151
entries: map[string]string{
52-
"QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy": "/ipfs/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj",
53-
"QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n": "/ipns/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy",
54-
"QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD": "/ipns/ipfs.io",
55-
"QmQ4QZh8nrsczdUEwTyfBope4THUhqxqc1fx6qYhhzZQei": "/ipfs/QmP3ouCnU8NNLsW6261pAx2pNLV2E4dQoisB1sgda12Act",
52+
"QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy": "/ipfs/Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj",
53+
"QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n": "/ipns/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy",
54+
"QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD": "/ipns/ipfs.io",
55+
"QmQ4QZh8nrsczdUEwTyfBope4THUhqxqc1fx6qYhhzZQei": "/ipfs/QmP3ouCnU8NNLsW6261pAx2pNLV2E4dQoisB1sgda12Act",
56+
"12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5": "/ipns/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", // ed25519+identity multihash
57+
"bafzbeickencdqw37dpz3ha36ewrh4undfjt2do52chtcky4rxkj447qhdm": "/ipns/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", // cidv1 in base32 with libp2p-key multicodec
5658
},
5759
}
5860
}
@@ -82,6 +84,8 @@ func TestNamesysResolution(t *testing.T) {
8284
testResolution(t, r, "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", 1, "/ipns/ipfs.io", ErrResolveRecursion)
8385
testResolution(t, r, "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", 2, "/ipns/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", ErrResolveRecursion)
8486
testResolution(t, r, "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", 3, "/ipns/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy", ErrResolveRecursion)
87+
testResolution(t, r, "/ipns/12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5", 1, "/ipns/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", ErrResolveRecursion)
88+
testResolution(t, r, "/ipns/bafzbeickencdqw37dpz3ha36ewrh4undfjt2do52chtcky4rxkj447qhdm", 1, "/ipns/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", ErrResolveRecursion)
8589
}
8690

8791
func TestPublishWithCache0(t *testing.T) {

‎test/sharness/lib/test-lib.sh

-1
Original file line numberDiff line numberDiff line change
@@ -438,4 +438,3 @@ findprovs_expect() {
438438
test_cmp findprovsOut expected
439439
'
440440
}
441-

0 commit comments

Comments
 (0)
Please sign in to comment.