bdns

package
v0.0.0-...-2fd2f9e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2017 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MockTimeoutError

func MockTimeoutError() *net.OpError

MockTimeoutError returns a a net.OpError for which Timeout() returns true.

func ReadHostList

func ReadHostList(filename string) (map[string]bool, error)

ReadHostList reads in a newline-separated file and returns a map containing each entry. If the filename is empty, returns a nil map and no error.

Types

type DNSClient

type DNSClient interface {
	LookupTXT(context.Context, string) (txts []string, authorities []string, err error)
	LookupHost(context.Context, string) ([]net.IP, error)
	LookupCAA(context.Context, string) ([]*dns.CAA, error)
	LookupMX(context.Context, string) ([]string, error)
}

DNSClient queries for DNS records

type DNSClientImpl

type DNSClientImpl struct {
	// contains filtered or unexported fields
}

DNSClientImpl represents a client that talks to an external resolver

func NewDNSClientImpl

func NewDNSClientImpl(
	readTimeout time.Duration,
	servers []string,
	caaSERVFAILExceptions map[string]bool,
	stats metrics.Scope,
	clk clock.Clock,
	maxTries int,
) *DNSClientImpl

NewDNSClientImpl constructs a new DNS resolver object that utilizes the provided list of DNS servers for resolution.

func NewTestDNSClientImpl

func NewTestDNSClientImpl(readTimeout time.Duration, servers []string, stats metrics.Scope, clk clock.Clock, maxTries int) *DNSClientImpl

NewTestDNSClientImpl constructs a new DNS resolver object that utilizes the provided list of DNS servers for resolution and will allow loopback addresses. This constructor should *only* be called from tests (unit or integration).

func (*DNSClientImpl) LookupCAA

func (dnsClient *DNSClientImpl) LookupCAA(ctx context.Context, hostname string) ([]*dns.CAA, error)

LookupCAA sends a DNS query to find all CAA records associated with the provided hostname.

func (*DNSClientImpl) LookupHost

func (dnsClient *DNSClientImpl) LookupHost(ctx context.Context, hostname string) ([]net.IP, error)

LookupHost sends a DNS query to find all A and AAAA records associated with the provided hostname. This method assumes that the external resolver will chase CNAME/DNAME aliases and return relevant records. It will retry requests in the case of temporary network errors. It can return net package, context.Canceled, and context.DeadlineExceeded errors, all wrapped in the DNSError type.

func (*DNSClientImpl) LookupMX

func (dnsClient *DNSClientImpl) LookupMX(ctx context.Context, hostname string) ([]string, error)

LookupMX sends a DNS query to find a MX record associated hostname and returns the record target.

func (*DNSClientImpl) LookupTXT

func (dnsClient *DNSClientImpl) LookupTXT(ctx context.Context, hostname string) ([]string, []string, error)

LookupTXT sends a DNS query to find all TXT records associated with the provided hostname which it returns along with the returned DNS authority section.

type DNSError

type DNSError struct {
	// contains filtered or unexported fields
}

DNSError wraps a DNS error with various relevant information

func (DNSError) Error

func (d DNSError) Error() string

func (DNSError) Timeout

func (d DNSError) Timeout() bool

Timeout returns true if the underlying error was a timeout

type MockDNSClient

type MockDNSClient struct {
}

MockDNSClient is a mock

func (*MockDNSClient) LookupCAA

func (mock *MockDNSClient) LookupCAA(_ context.Context, domain string) ([]*dns.CAA, error)

LookupCAA returns mock records for use in tests.

func (*MockDNSClient) LookupHost

func (mock *MockDNSClient) LookupHost(_ context.Context, hostname string) ([]net.IP, error)

LookupHost is a mock

Note: see comments on LookupMX regarding email.only

func (*MockDNSClient) LookupMX

func (mock *MockDNSClient) LookupMX(_ context.Context, domain string) ([]string, error)

LookupMX is a mock

Note: the email.only domain must have an MX but no A or AAAA records. The mock LookupHost returns an address of 127.0.0.1 for all domains except for special cases, so MX-only domains must be handled in both LookupHost and LookupMX.

func (*MockDNSClient) LookupTXT

func (mock *MockDNSClient) LookupTXT(_ context.Context, hostname string) ([]string, []string, error)

LookupTXT is a mock

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL