From cf947913380fd1f01893c06c15903de50aaacf08 Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 13 Apr 2021 17:22:44 +0300 Subject: [PATCH 1/3] gomod: get miekg/dns --- go.mod | 5 ++++- go.sum | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 2a004bf..821b248 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,8 @@ module github.com/multiformats/go-multiaddr-dns -require github.com/multiformats/go-multiaddr v0.2.0 +require ( + github.com/miekg/dns v1.1.41 + github.com/multiformats/go-multiaddr v0.2.0 +) go 1.12 diff --git a/go.sum b/go.sum index 68d1c69..f3237b8 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,11 @@ +github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY= +github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771 h1:MHkK1uRtFbVqvAgvWxafZe54+5uBxLluGylDiKgdhwo= github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiformats/go-multiaddr v0.1.1 h1:rVAztJYMhCQ7vEFr8FvxW3mS+HF2eY/oPbOMeS0ZDnE= -github.com/multiformats/go-multiaddr v0.1.1/go.mod h1:aMKBKNEYmzmDmxfX88/vz+J5IU55txyt0p4aiWVohjo= github.com/multiformats/go-multiaddr v0.2.0 h1:lR52sFwcTCuQb6bTfnXF6zA2XfyYvyd+5a9qECv/J90= github.com/multiformats/go-multiaddr v0.2.0/go.mod h1:0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4= github.com/multiformats/go-multihash v0.0.8 h1:wrYcW5yxSi3dU07n5jnuS5PrNwyHy0zRHGVoUugWvXg= @@ -18,7 +18,16 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 h1:1wopBVtVdWnn03fZelqdXTqk7U7zPQCb+T4rbU9ZEoU= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04 h1:cEhElsAv9LUt9ZUUocxzWe05oFLVd+AA2nstydTeI8g= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From af99b2d42e136475ec982d2476ea375d55804de8 Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 13 Apr 2021 17:24:12 +0300 Subject: [PATCH 2/3] normalize domains to fqdn for resolver selection --- resolve.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/resolve.go b/resolve.go index 705fed7..95ac5bb 100644 --- a/resolve.go +++ b/resolve.go @@ -5,6 +5,7 @@ import ( "net" "strings" + "github.com/miekg/dns" ma "github.com/multiformats/go-multiaddr" ) @@ -63,23 +64,31 @@ func WithDomainResolver(domain string, rslv BasicResolver) Option { if r.custom == nil { r.custom = make(map[string]BasicResolver) } - r.custom[domain] = rslv + fqdn := dns.Fqdn(domain) + r.custom[fqdn] = rslv return nil } } func (r *Resolver) getResolver(domain string) BasicResolver { + fqdn := dns.Fqdn(domain) + // we match left-to-right, with more specific resolvers superseding generic ones. // So for a domain a.b.c, we will try a.b,c, b.c, c, and fallback to the default if // there is no match - rslv, ok := r.custom[domain] + rslv, ok := r.custom[fqdn] if ok { return rslv } - for i := strings.Index(domain, "."); i != -1; i = strings.Index(domain, ".") { - domain = domain[i+1:] - rslv, ok = r.custom[domain] + for i := strings.Index(fqdn, "."); i != -1; i = strings.Index(fqdn, ".") { + fqdn = fqdn[i+1:] + if fqdn == "" { + // the . is the default resolver + break + } + + rslv, ok = r.custom[fqdn] if ok { return rslv } From 1fac232e44953db6c41868865a6fe7c50990058a Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 13 Apr 2021 17:27:47 +0300 Subject: [PATCH 3/3] bump go to 1.15 --- .travis.yml | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 336deb4..02f3c37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ os: language: go go: - - 1.12.x + - 1.15.x env: global: diff --git a/go.mod b/go.mod index 821b248..70c5f49 100644 --- a/go.mod +++ b/go.mod @@ -5,4 +5,4 @@ require ( github.com/multiformats/go-multiaddr v0.2.0 ) -go 1.12 +go 1.15