fix(resolve): correctly handle .eth domains
This should have been handled down inside the DNSLink resolver. Otherwise, we'll break any name happens to end in `.eth`. also fixes #6699
Steven Allen committed
Oct 7, 2019 at 17:07 UTC
d5f22c2ca40c612a0c34642fa54f8c3025609f6c
4 files changed
+12
-11
go.mod
+1
-1
@@ -52,7 +52,7 @@ require (
52
github.com/ipfs/go-unixfs v0.2.1
53
github.com/ipfs/go-verifcid v0.0.1
54
github.com/ipfs/interface-go-ipfs-core v0.2.3
55
- github.com/jbenet/go-is-domain v1.0.2
55
+ github.com/jbenet/go-is-domain v1.0.3
56
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
57
github.com/jbenet/go-temp-err-catcher v0.0.0-20150120210811-aac704a3f4f2
58
github.com/jbenet/goprocess v0.1.3
go.sum
+2
-2
@@ -261,8 +261,8 @@ github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+
261
github.com/jbenet/go-cienv v0.0.0-20150120210510-1bb1476777ec/go.mod h1:rGaEvXB4uRSZMmzKNLoXvTu1sfx+1kv/DojUlPrSZGs=
262
github.com/jbenet/go-cienv v0.1.0 h1:Vc/s0QbQtoxX8MwwSLWWh+xNNZvM3Lw7NsTcHrvvhMc=
263
github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA=
264
-github.com/jbenet/go-is-domain v1.0.2 h1:11r5MSptcNFZyBoqubBQnVMUKRWLuRjL1banaIk+iYo=
265
-github.com/jbenet/go-is-domain v1.0.2/go.mod h1:xbRLRb0S7FgzDBTJlguhDVwLYM/5yNtvktxj2Ttfy7Q=
264
+github.com/jbenet/go-is-domain v1.0.3 h1:FuRBJ0h79p00eseyaLckJT5KnE8RyqI+HLopvNSyNE0=
265
+github.com/jbenet/go-is-domain v1.0.3/go.mod h1:xbRLRb0S7FgzDBTJlguhDVwLYM/5yNtvktxj2Ttfy7Q=
266
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c h1:uUx61FiAa1GI6ZmVd2wf2vULeQZIKG66eybjNXKYCz4=
267
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c/go.mod h1:sdx1xVM9UuLw1tXnhJWN3piypTUO3vCIHYmG15KE/dU=
268
github.com/jbenet/go-temp-err-catcher v0.0.0-20150120210811-aac704a3f4f2 h1:vhC1OXXiT9R2pczegwz6moDvuRpggaroAXhPIseh57A=
namesys/dns.go
+9
@@ -11,6 +11,9 @@ import (
11
isd "github.com/jbenet/go-is-domain"
12
)
13
14
+const ethTLD = "eth"
15
+const linkTLD = "link"
16
+
17
type LookupTXTFunc func(name string) (txt []string, err error)
18
19
// DNSResolver implements a Resolver on DNS domains
@@ -62,6 +65,12 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options
65
fqdn = domain + "."
66
}
67
68
+ if strings.HasSuffix(fqdn, "."+ethTLD+".") {
69
+ // This is an ENS name. As we're resolving via an arbitrary DNS server
70
+ // that may not know about .eth we need to add our link domain suffix.
71
+ fqdn += linkTLD + "."
72
+ }
73
+
74
rootChan := make(chan lookupRes, 1)
75
go workDomain(r, fqdn, rootChan)
76
namesys/namesys.go
-8
@@ -80,9 +80,6 @@ func (ns *mpns) ResolveAsync(ctx context.Context, name string, options ...opts.R
80
return resolveAsync(ctx, ns, name, opts.ProcessOpts(options))
81
}
82
83
-const ethTLD = ".eth"
84
-const linkTLD = ".link"
85
-
83
// resolveOnce implements resolver.
84
func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.ResolveOpts) <-chan onceResult {
85
out := make(chan onceResult, 1)
@@ -90,11 +87,6 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.
87
if !strings.HasPrefix(name, ipnsPrefix) {
88
name = ipnsPrefix + name
89
}
93
- if strings.HasSuffix(name, ethTLD) {
94
- // This is an ENS name. As we're resolving via an arbitrary DNS server
95
- // that may not know about .eth we need to add our link domain suffix.
96
- name = name + linkTLD
97
- }
90
segments := strings.SplitN(name, "/", 4)
91
if len(segments) < 3 || segments[0] != "" {
92
log.Debugf("invalid name syntax for %s", name)