dnscache

package
v1.18.2 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: BSD-3-Clause Imports: 13 Imported by: 25

Documentation

Overview

Package dnscache contains a minimal DNS cache that makes a bunch of assumptions that are only valid for us. Not recommended for general use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DialContextFunc added in v1.4.0

type DialContextFunc func(ctx context.Context, network, address string) (net.Conn, error)

func Dialer added in v1.4.0

func Dialer(fwd DialContextFunc, dnsCache *Resolver) DialContextFunc

Dialer returns a wrapped DialContext func that uses the provided dnsCache.

func TLSDialer added in v1.6.0

func TLSDialer(fwd DialContextFunc, dnsCache *Resolver, tlsConfigBase *tls.Config) DialContextFunc

TLSDialer is like Dialer but returns a func suitable for using with net/http.Transport.DialTLSContext. It returns a *tls.Conn type on success. On TLS cert validation failure, it can invoke a backup DNS resolution strategy.

type Resolver

type Resolver struct {
	// Forward is the resolver to use to populate the cache.
	// If nil, net.DefaultResolver is used.
	Forward *net.Resolver

	// LookupIPFallback optionally provides a backup DNS mechanism
	// to use if Forward returns an error or no results.
	LookupIPFallback func(ctx context.Context, host string) ([]netaddr.IP, error)

	// TTL is how long to keep entries cached
	//
	// If zero, a default (currently 10 minutes) is used.
	TTL time.Duration

	// UseLastGood controls whether a cached entry older than TTL is used
	// if a refresh fails.
	UseLastGood bool
	// contains filtered or unexported fields
}

Resolver is a minimal DNS caching resolver.

The TTL is always fixed for now. It's not intended for general use. Cache entries are never cleaned up so it's intended that this is only used with a fixed set of hostnames.

func Get

func Get() *Resolver

Get returns a caching Resolver singleton.

func (*Resolver) LookupIP

func (r *Resolver) LookupIP(ctx context.Context, host string) (ip, v6 net.IP, allIPs []net.IPAddr, err error)

LookupIP returns the host's primary IP address (either IPv4 or IPv6, but preferring IPv4) and optionally its IPv6 address, if there is both IPv4 and IPv6.

If err is nil, ip will be non-nil. The v6 address may be nil even with a nil error.

Jump to

Keyboard shortcuts

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