From 3cfdb3c56c6cac6b32f7c1a3a9b5b2c1a54a7a8f Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 21 Apr 2021 19:42:03 +0200 Subject: [PATCH] feat: support non-ICANN DNSLink names https://github.com/ipfs/go-ipfs/issues/8060 This commit was moved from ipfs/go-namesys@1f2af4e5527ae625c797bad31f2528c4df44d092 --- namesys/dns.go | 4 ++-- namesys/namesys.go | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/namesys/dns.go b/namesys/dns.go index 96b9a6b25..43768804f 100644 --- a/namesys/dns.go +++ b/namesys/dns.go @@ -10,7 +10,7 @@ import ( path "github.com/ipfs/go-path" opts "github.com/ipfs/interface-go-ipfs-core/options/namesys" - isd "github.com/jbenet/go-is-domain" + dns "github.com/miekg/dns" ) // LookupTXTFunc is a generic type for a function that lookups TXT record values. @@ -52,7 +52,7 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options segments := strings.SplitN(name, "/", 2) domain := segments[0] - if !isd.IsDomain(domain) { + if _, ok := dns.IsDomainName(domain); !ok { out <- onceResult{err: fmt.Errorf("not a valid domain name: %s", domain)} close(out) return out diff --git a/namesys/namesys.go b/namesys/namesys.go index 85075d228..b28c13309 100644 --- a/namesys/namesys.go +++ b/namesys/namesys.go @@ -7,8 +7,8 @@ // DHT). // // Additionally, the /ipns/ namespace can also be used with domain names that -// use DNSLink (/ipns/my.domain.example, see https://dnslink.io) and proquint -// strings. +// use DNSLink (/ipns/, https://docs.ipfs.io/concepts/dnslink/) +// and proquint strings. // // The package provides implementations for all three resolvers. package namesys @@ -26,10 +26,10 @@ import ( dssync "github.com/ipfs/go-datastore/sync" path "github.com/ipfs/go-path" opts "github.com/ipfs/interface-go-ipfs-core/options/namesys" - isd "github.com/jbenet/go-is-domain" ci "github.com/libp2p/go-libp2p-core/crypto" peer "github.com/libp2p/go-libp2p-core/peer" routing "github.com/libp2p/go-libp2p-core/routing" + dns "github.com/miekg/dns" madns "github.com/multiformats/go-multiaddr-dns" ) @@ -225,9 +225,13 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts. if err == nil { res = ns.ipnsResolver - } else if isd.IsDomain(key) { + } else if _, ok := dns.IsDomainName(key); ok { res = ns.dnsResolver } else { + // TODO: remove proquint? + // dns.IsDomainName(key) will return true for proquint strings, + // so this block is a dead code. + // (alternative is to move this before DNS check) res = ns.proquintResolver }