mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 00:39:31 +08:00
DNSResolver: use isd.IsDomain
this commit dedicated to @whyrusleeping
This commit is contained in:
@ -2,25 +2,29 @@ package namesys
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
b58 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
|
||||
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
isd "github.com/jbenet/go-is-domain"
|
||||
)
|
||||
|
||||
// DNSResolver implements a Resolver on DNS domains
|
||||
type DNSResolver struct {
|
||||
// TODO: maybe some sort of caching?
|
||||
// cache would need a timeout
|
||||
}
|
||||
|
||||
// Matches implements Resolver
|
||||
func (r *DNSResolver) Matches(name string) bool {
|
||||
return strings.Contains(name, ".") && !strings.HasPrefix(name, ".")
|
||||
return isd.IsDomain(name)
|
||||
}
|
||||
|
||||
// Resolve implements Resolver
|
||||
// TXT records for a given domain name should contain a b58
|
||||
// encoded multihash.
|
||||
func (r *DNSResolver) Resolve(name string) (string, error) {
|
||||
log.Info("DNSResolver resolving %v", name)
|
||||
txt, err := net.LookupTXT(name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
Reference in New Issue
Block a user