dns

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchECHConfigs added in v1.0.1

func FetchECHConfigs(ctx context.Context, hostname string) ([]byte, error)

FetchECHConfigs fetches ECH configs from DNS HTTPS records for the given hostname. Returns nil if no ECH configs are available (this is not an error).

func FetchECHConfigsBase64 added in v1.0.1

func FetchECHConfigsBase64(ctx context.Context, hostname string) (string, error)

FetchECHConfigsBase64 returns ECH configs as base64 string (for debugging)

Types

type Cache

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

Cache provides TTL-aware DNS caching

func NewCache

func NewCache() *Cache

NewCache creates a new DNS cache

func (*Cache) Cleanup

func (c *Cache) Cleanup()

Cleanup removes expired entries from the cache

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all entries from the cache

func (*Cache) Invalidate

func (c *Cache) Invalidate(host string)

Invalidate removes a hostname from the cache

func (*Cache) PreferIPv4 added in v1.0.1

func (c *Cache) PreferIPv4() bool

PreferIPv4 returns whether IPv4 is preferred over IPv6

func (*Cache) Resolve

func (c *Cache) Resolve(ctx context.Context, host string) ([]net.IP, error)

Resolve looks up the IP addresses for a hostname Returns cached result if available and not expired

func (*Cache) ResolveAllSorted

func (c *Cache) ResolveAllSorted(ctx context.Context, host string) ([]net.IP, error)

ResolveAllSorted returns all IPs sorted for Happy Eyeballs (RFC 8305) By default IPv6 addresses first, interleaved with IPv4 If PreferIPv4 is set, IPv4 addresses come first

func (*Cache) ResolveIPv6First

func (c *Cache) ResolveIPv6First(ctx context.Context, host string) (ipv6 []net.IP, ipv4 []net.IP, err error)

ResolveIPv6First returns IPv6 addresses first, then IPv4 addresses This is for strict IPv6 preference - try all IPv6 before falling back to IPv4

func (*Cache) ResolveOne

func (c *Cache) ResolveOne(ctx context.Context, host string) (net.IP, error)

ResolveOne returns a single IP address for the hostname By default prefers IPv6 over IPv4 (modern browser behavior) If PreferIPv4 is set, prefers IPv4 instead

func (*Cache) SetPreferIPv4 added in v1.0.1

func (c *Cache) SetPreferIPv4(prefer bool)

SetPreferIPv4 sets whether to prefer IPv4 addresses over IPv6

func (*Cache) SetTTL

func (c *Cache) SetTTL(ttl time.Duration)

SetTTL sets the default TTL for cached entries

func (*Cache) StartCleanup

func (c *Cache) StartCleanup(ctx context.Context, interval time.Duration)

StartCleanup starts a background goroutine that periodically cleans up expired entries

func (*Cache) Stats

func (c *Cache) Stats() (total int, expired int)

Stats returns cache statistics

type ECHEntry added in v1.0.1

type ECHEntry struct {
	ConfigList []byte
	ExpiresAt  time.Time
}

ECHEntry represents a cached ECH config entry

type Entry

type Entry struct {
	IPs       []net.IP
	ExpiresAt time.Time
	LookupAt  time.Time
}

Entry represents a cached DNS entry

func (*Entry) IsExpired

func (e *Entry) IsExpired() bool

IsExpired checks if the entry has expired

Jump to

Keyboard shortcuts

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