From ef00a67244dd5e459e8834db297efe419355d1b9 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 6 Feb 2020 01:14:09 +0100 Subject: [PATCH] feat: resolve peer IDs as CIDs This adds support for resolving /ipns/ cc #5287 License: MIT Signed-off-by: Marcin Rataj --- namesys/namesys.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/namesys/namesys.go b/namesys/namesys.go index 079eecccc03..b2a0c5bd294 100644 --- a/namesys/namesys.go +++ b/namesys/namesys.go @@ -6,6 +6,7 @@ import ( "time" lru "github.com/hashicorp/golang-lru" + cid "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" path "github.com/ipfs/go-path" opts "github.com/ipfs/interface-go-ipfs-core/options/namesys" @@ -13,7 +14,6 @@ import ( ci "github.com/libp2p/go-libp2p-core/crypto" peer "github.com/libp2p/go-libp2p-core/peer" routing "github.com/libp2p/go-libp2p-core/routing" - mh "github.com/multiformats/go-multihash" ) // mpns (a multi-protocol NameSystem) implements generic IPFS naming. @@ -112,12 +112,12 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts. } // Resolver selection: - // 1. if it is a multihash resolve through "ipns". + // 1. if it is a CID/multihash resolve through "ipns". // 2. if it is a domain name, resolve through "dns" // 3. otherwise resolve through the "proquint" resolver var res resolver - if _, err := mh.FromB58String(key); err == nil { + if _, err := cid.Decode(key); err == nil { res = ns.ipnsResolver } else if isd.IsDomain(key) { res = ns.dnsResolver