Documentation
¶
Index ¶
- func FetchECHConfigs(ctx context.Context, hostname string) ([]byte, error)
- func FetchECHConfigsBase64(ctx context.Context, hostname string) (string, error)
- func GetECHDNSServers() []string
- func InvalidateECHConfig(hostname string)
- func IsECHIncompatible(host string) bool
- func MarkECHIncompatible(host string)
- func SetECHDNSServers(servers []string)
- type Cache
- func (c *Cache) Cleanup()
- func (c *Cache) Clear()
- func (c *Cache) Invalidate(host string)
- func (c *Cache) PreferIPv4() bool
- func (c *Cache) Resolve(ctx context.Context, host string) ([]net.IP, error)
- func (c *Cache) ResolveAllSorted(ctx context.Context, host string) ([]net.IP, error)
- func (c *Cache) ResolveIPv6First(ctx context.Context, host string) (ipv6 []net.IP, ipv4 []net.IP, err error)
- func (c *Cache) ResolveOne(ctx context.Context, host string) (net.IP, error)
- func (c *Cache) SetPreferIPv4(prefer bool)
- func (c *Cache) SetTTL(ttl time.Duration)
- func (c *Cache) StartCleanup(ctx context.Context, interval time.Duration)
- func (c *Cache) Stats() (total int, expired int)
- type ECHEntry
- type Entry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchECHConfigs ¶ added in v1.0.1
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
FetchECHConfigsBase64 returns ECH configs as base64 string (for debugging)
func GetECHDNSServers ¶ added in v1.5.8
func GetECHDNSServers() []string
GetECHDNSServers returns the current DNS servers used for ECH config queries.
func InvalidateECHConfig ¶ added in v1.6.7
func InvalidateECHConfig(hostname string)
InvalidateECHConfig drops the cached ECH config for a host so the next FetchECHConfigs re-queries DNS for a fresh one. Call this when a handshake is rejected in a way that suggests the cached config went stale (for example the CDN rotated its ECH keys).
func IsECHIncompatible ¶ added in v1.6.8
IsECHIncompatible reports whether ECH should currently be skipped for host (it recently stalled or rejected an ECH handshake).
func MarkECHIncompatible ¶ added in v1.6.8
func MarkECHIncompatible(host string)
MarkECHIncompatible records that a target host could not complete a TLS handshake with an ECH config applied, so callers skip ECH for it until the TTL expires. Sweeps expired entries inline once the map grows large so it stays bounded.
func SetECHDNSServers ¶ added in v1.5.8
func SetECHDNSServers(servers []string)
SetECHDNSServers sets the DNS servers to use for ECH config queries. Pass nil or empty slice to reset to defaults.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache provides DNS caching with bounded entry lifetime, single-flight deduplication of concurrent lookups, and short negative caching.
func (*Cache) Invalidate ¶
Invalidate removes a hostname from the cache
func (*Cache) PreferIPv4 ¶ added in v1.0.1
PreferIPv4 returns whether IPv4 is preferred over IPv6
func (*Cache) Resolve ¶
Resolve looks up the IP addresses for a hostname Returns cached result if available and not expired
func (*Cache) ResolveAllSorted ¶
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 ¶
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
SetPreferIPv4 sets whether to prefer IPv4 addresses over IPv6
func (*Cache) StartCleanup ¶
StartCleanup starts a background goroutine that periodically cleans up expired entries
type ECHEntry ¶ added in v1.0.1
ECHEntry represents a cached ECH config entry. A negative entry has ConfigList == nil and records "this host advertises no ECH" for its TTL, so we don't re-fire public-DNS HTTPS queries on every H3 dial to a non-ECH host.
type Entry ¶
type Entry struct {
IPs []net.IP
ExpiresAt time.Time
LookupAt time.Time
// contains filtered or unexported fields
}
Entry represents a cached DNS entry. A negative entry (negative == true) caches a lookup failure for a short window so a genuinely missing/erroring name isn't re-resolved on every request.