Documentation
¶
Overview ¶
Package resolver implements a lightweight DNS resolver
It'd be really cool if this all worked. It's a work in progress.
Worky?
Index ¶
Constants ¶
const ( // TIMEOUT is the default query and connect timeout TIMEOUT = 10 * time.Second // RETRYINTERVAL is the default interval between retries RETRYINTERVAL = 3 * time.Second )
Variables ¶
var ( ErrRCFormErr = errors.New("formerr") /* Format Error */ ErrRCServFail = errors.New("servfail") /* Server Failure */ ErrRCNXDomain = errors.New("nxdomain") /* Nonexistent domain */ ErrRCNotImp = errors.New("notimp") /* Not implemented */ ErrRCRefused = errors.New("refused") /* Query refused */ )
The following errors correspond to non-success (i.e. not NOERROR) Response Codes returned from DNS servers.
var ErrAnswerTimeout = errors.New("timeout waiting for answer")
ErrAnswerTimeout is returned if the answer did not return before the timeout elapsed.
var ErrNotImplemented = errors.New("not implemented")
ErrNotImplemented is returned by StdlibResolver's LookupAC and LookupAAAAAC methods. This should not be confused with ErrRCNotImp.
var ErrTooManyQueries = errors.New("too many outstanding queries")
ErrTooManyQueries is returned when there are too many outstanding queries. Approximate 65k queries can be in flight at once.
var StdlibResolver = stdlibResolver()
StdlibResolver is a Resolver which wraps the net.Lookup* functions. The Resolver's LookupAC and LookupAAAAC methods will always return errors and its LookupA and LookupAAAA methods will both make queries for both A and AAAA records. StblibResolver.QueryTimeout and StdlibResolver.RetryInterval are no-ops. The default net.Lookup* timeouts are used instead.
Functions ¶
This section is empty.
Types ¶
type QueryMethod ¶
type QueryMethod int
QueryMethod is used to configure which server(s) are queried by resolver returned by NewResolver.
const ( // RoundRobin causes a different server to be used for every query. RoundRobin QueryMethod = iota // NextOnFail causes the servers to be tried in order until one // returns an answer or the list of servers is exhausted. NextOnFail // QueryAll causes all servers to be tried for every query. Duplicate // replies are possible if multiple servers return identical replies. QueryAll )
type Resolver ¶
type Resolver interface { // LookupA returns the A records (IPv4 addresses) for the given name. LookupA(name string) ([][4]byte, error) //// LookupAC performs a query for A records for the given name, but //// expects and returns only CNAME records sent in the reply. LookupAC(name string) ([]string, error) //// LookupNS returns the NS records for the given name. LookupNS(name string) ([]string, error) // LookupCNAME returns the CNAME records for the given name. LookupCNAME(name string) ([]string, error) // LookupPTR looks up the PTR records for the given IP address. LookupPTR(addr net.IP) ([]string, error) // LookupMX looks up the MX records for the given name. LookupMX(name string) ([]MX, error) // LookupTXT looks up the TXT records for the given name. LookupTXT(name string) ([]string, error) // LookupAAAA looks up the AAAA records (IPv6 addresses) for the given // name. LookupAAAA(name string) ([][16]byte, error) // LookupAAAAC performs a query for AAAA records for the given name, // but expects and returns only CNAME records sent in the reply. LookupAAAAC(name string) ([]string, error) // LookupSRV looks up the SRV records for the given name. LookupSRV(name string) ([]SRV, error) // Timeout sets the timeout for connecting to servers and receiving // responses to queries. Timeout(to time.Duration) // RetryInterval sets the interval between resending queries if no // response has been received on a datagram-oriented (i.e. // net.PacketConn) connection. If this is set to a duration larger // than QueryTimeout, queries will not be resent. RetryInterval(rint time.Duration) }
Resolver implements a lightweight DNS resolver.
func NewResolver ¶
func NewResolver(method QueryMethod, servers ...string) (Resolver, error)
NewResolver returns a resolver which makes queries to the given servers. How the servers are queried is determined by method. The servers should be given as URLs of the form network://address[:port]. Any network accepted by net.Dial is accepted, as is "tls", which will cause the DNS queries to be made over a TLS connection. If a port is omitted on addresses which would normally require it (e.g. tcp), port 53 will be used.
func NewResolverFromConn ¶
NewResolverFromConn returns a Resolver which sends its queries on the provided net.Conn. If the net.Conn implements the net.PacketConn interface, it will be treated as a UDPish connection (though it need not be), otherwise it will be treated as TCPish. Errors encountered during reading and parsing responses will be sent to the returned channel which will be closed when no more responses are able to be read (usually due to c being closed). The channel must be serviced or resolution will hang.