bottin

package module
v0.0.0-...-70d2c58 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: MIT Imports: 11 Imported by: 0

README

bottin

.github/workflows/tests.yml codecov

Recursive DNS Resolver for Go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Timeout             = 2000 * time.Millisecond
	TypicalResponseTime = 100 * time.Millisecond
	MaxRecursion        = 10
	MaxNameservers      = 2
	MaxIPs              = 2
)
View Source
var (
	NXDOMAIN = fmt.Errorf("NXDOMAIN")

	ErrMaxRecursion = fmt.Errorf("maximum recursion depth reached: %d", MaxRecursion)
	ErrMaxIPs       = fmt.Errorf("maximum name server IPs queried: %d", MaxIPs)
	ErrNoARecords   = fmt.Errorf("no A records found for name server")
	ErrNoResponse   = fmt.Errorf("no responses received")
	ErrTimeout      = fmt.Errorf("timeout expired") // TODO: Timeouter interface? e.g. func (e) Timeout() bool { return true }
)

Resolver errors.

View Source
var DebugLogger io.Writer

DebugLogger will receive writes of DNS resolution traces if not nil.

Functions

This section is empty.

Types

type BottinResolver

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

func New

func New(cap int) *BottinResolver

func NewExpiring

func NewExpiring(cap int) *BottinResolver

func NewExpiringWithTimeout

func NewExpiringWithTimeout(cap int, timeout time.Duration) *BottinResolver

func NewResolver

func NewResolver(options ...Option) *BottinResolver

func NewWithTimeout

func NewWithTimeout(cap int, timeout time.Duration) *BottinResolver

func (*BottinResolver) Resolve

func (br *BottinResolver) Resolve(qname, qtype string) RRs

func (*BottinResolver) ResolveContext

func (br *BottinResolver) ResolveContext(ctx context.Context, qname, qtype string) (RRs, error)

func (*BottinResolver) ResolveCtx

func (br *BottinResolver) ResolveCtx(ctx context.Context, qname, qtype string) (RRs, error)

func (*BottinResolver) ResolveErr

func (br *BottinResolver) ResolveErr(qname, qtype string) (RRs, error)

type Cache

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

Cache stores slices of RR structs, with each key mapping to an RR slice.

func NewCache

func NewCache() *Cache

NewCache initializes a new cache for storing slices of RR structs.

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes an item from the cache by key.

func (*Cache) DumpJSON

func (c *Cache) DumpJSON() (string, error)

DumpJSON returns a JSON representation of the current cache state.

func (*Cache) Get

func (c *Cache) Get(key string) ([]RR, bool)

Get retrieves a slice of RR items by key if they exist and are unexpired.

func (*Cache) LoadJSON

func (c *Cache) LoadJSON(data string) error

LoadJSON loads the cache state from a JSON string.

func (*Cache) Set

func (c *Cache) Set(key string, rrs []RR)

Set adds a slice of RR items to the cache for a specific key. Each RR's Expiry is set based on its TTL.

type Option

type Option func(*Resolver)

Option specifies a configuration option for a Resolver.

func WithCache

func WithCache(cap int) Option

WithCache specifies a cache with capacity cap.

func WithDialer

func WithDialer(dialer *net.Dialer) Option

WithDialer sets a custom dialer for the Resolver.

func WithExpiry

func WithExpiry() Option

WithExpiry sets an expiry duration for cached responses.

func WithTCPRetry

func WithTCPRetry() Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets a timeout for the Resolver's operations.

type RR

type RR struct {
	Name   string        `json:"name"`
	Type   string        `json:"type"`
	Value  string        `json:"value"`
	TTL    time.Duration `json:"ttl"`
	Expiry time.Time     `json:"expiry"`
}

RR represents a DNS-like record.

func (*RR) Key

func (rr *RR) Key() string

type RRs

type RRs struct {
	AnswerRRs     []RR
	AuthorityRRs  []RR
	AdditionalRRs []RR
}

type Resolver

type Resolver interface {
	Resolve(qname, qtype string) RRs
	ResolveContext(ctx context.Context, qname, qtype string) (RRs, error)
	ResolveCtx(ctx context.Context, qname, qtype string) (RRs, error)
	ResolveErr(qname, qtype string) (RRs, error)
}

Jump to

Keyboard shortcuts

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