Documentation
¶
Overview ¶
Package server provides the core DNS server implementation.
Index ¶
- Constants
- type DNSCache
- func (c *DNSCache) Cleanup()
- func (c *DNSCache) Flush()
- func (c *DNSCache) Get(key string) ([]byte, bool)
- func (c *DNSCache) GetInto(key string, txID uint16) ([]byte, bool)
- func (c *DNSCache) Invalidate(key string)
- func (c *DNSCache) Ping(ctx context.Context) error
- func (c *DNSCache) Set(key string, data []byte, ttl time.Duration)
- func (c *DNSCache) SetNoCopy(key string, data []byte, ttl time.Duration)
- type RedisCache
- func (r *RedisCache) Close() error
- func (r *RedisCache) DLQLen(ctx context.Context) (int64, error)
- func (r *RedisCache) Get(ctx context.Context, key string) ([]byte, bool)
- func (r *RedisCache) GetWithTTL(ctx context.Context, key string) ([]byte, time.Duration, bool)
- func (r *RedisCache) Invalidate(ctx context.Context, name string, qType domain.RecordType) error
- func (r *RedisCache) Ping(ctx context.Context) error
- func (r *RedisCache) PoolConfig() RedisPoolConfig
- func (r *RedisCache) PopFromDLQ(ctx context.Context, timeout time.Duration) (string, error)
- func (r *RedisCache) PushToDLQ(ctx context.Context, msg string) error
- func (r *RedisCache) Set(ctx context.Context, key string, data []byte, ttl time.Duration)
- func (r *RedisCache) Subscribe(ctx context.Context) *redis.PubSub
- type RedisPoolConfig
- type Server
Constants ¶
const ClassCHAOS = 3
ClassCHAOS is the DNS class for server identity and metadata.
const DLQChannel = "dns:invalidation:dlq"
DLQChannel is the Redis list key for dead letter queue of failed invalidation messages.
const InvalidationChannel = "dns:invalidation"
InvalidationChannel is the Redis pub/sub channel for cache invalidation events.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DNSCache ¶
type DNSCache struct {
// contains filtered or unexported fields
}
DNSCache implements a sharded, thread-safe, in-memory cache for DNS responses. Sharding is used to minimize lock contention during high-concurrency access.
func NewDNSCache ¶
NewDNSCache initializes a new DNSCache with pre-allocated shards and starts the background expiration cleanup loop. The done channel controls when the cleanup goroutine exits. If wg is provided, wg.Add(1) is called and wg.Done() is called when the cleanup goroutine exits.
func (*DNSCache) Cleanup ¶
func (c *DNSCache) Cleanup()
Cleanup scans all shards and deletes items that have passed their expiration time.
func (*DNSCache) Get ¶
Get retrieves a response from the cache. It returns (nil, false) if the key is missing or has already expired. Note: callers must not retain or mutate the returned slice.
func (*DNSCache) GetInto ¶
GetInto returns data from the cache with the transaction ID injected. For data >= 2 bytes: TXID is written at offset 0 (overwriting first 2 bytes of data). For data < 2 bytes: no TXID injection (would corrupt too-short responses). The returned slice is from a pooled buffer — callers must not retain or mutate it.
func (*DNSCache) Invalidate ¶
Invalidate removes a specific key from the cache.
func (*DNSCache) Set ¶
Set stores a response in the cache with a specific TTL. The input data is copied so the cache owns its own backing array.
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache implements a DNS cache backed by Redis.
func NewRedisCache ¶
func NewRedisCache(addr string, password string, db int, cfg RedisPoolConfig) *RedisCache
NewRedisCache creates a new Redis cache client.
func (*RedisCache) Close ¶
func (r *RedisCache) Close() error
Close shuts down the Redis client connection.
func (*RedisCache) DLQLen ¶
func (r *RedisCache) DLQLen(ctx context.Context) (int64, error)
DLQLen returns the current length of the dead letter queue.
func (*RedisCache) GetWithTTL ¶
GetWithTTL retrieves cached data and remaining TTL in a single pipeline call.
func (*RedisCache) Invalidate ¶
func (r *RedisCache) Invalidate(ctx context.Context, name string, qType domain.RecordType) error
Invalidate deletes the key from Redis and publishes an invalidation event to all nodes. When qType is empty, publishes a zone-level invalidation (zone name only, no type suffix).
func (*RedisCache) Ping ¶
func (r *RedisCache) Ping(ctx context.Context) error
Ping checks Redis connectivity.
func (*RedisCache) PoolConfig ¶
func (r *RedisCache) PoolConfig() RedisPoolConfig
PoolConfig returns the pool configuration currently applied to the client.
func (*RedisCache) PopFromDLQ ¶
PopFromDLQ pops a message from the dead letter queue with blocking. Returns ("", nil) if timeout is reached before a message is available.
func (*RedisCache) PushToDLQ ¶
func (r *RedisCache) PushToDLQ(ctx context.Context, msg string) error
PushToDLQ pushes a failed invalidation message to the dead letter queue. The message is stored with a timestamp prefix for ordering.
type RedisPoolConfig ¶
type RedisPoolConfig struct {
PoolSize int
MinIdleConns int
PoolTimeout time.Duration
ConnMaxLifetime time.Duration
}
RedisPoolConfig holds connection pool settings for the Redis client.
type Server ¶
type Server struct {
Addr string
Repo ports.DNSRepository
Cache *DNSCache
Redis *RedisCache
DNSSEC *services.DNSSECService
DNSSECValidator *services.DNSSECValidator
DNSSECMode string // "disabled", "ad-bit-only", "strict"
DNSSECConfig *config.DNSSECConfig
WorkerCount int
Logger *slog.Logger
TsigKeys map[string][]byte
NodeID string
RecursionEnabled bool
CookieSecret []byte
// Testing/Chaos flags
SimulateDBLatency time.Duration
NotifyPortOverride int
DisableAsync bool // If true, NOTIFY and UPDATE handlers won't spawn goroutines
// TLS Config for DoT, DoH, and DoQ
TLSConfig *tls.Config
DoQAddr string // DNS-over-QUIC listen address (default ":853")
// contains filtered or unexported fields
}
Server is the core DNS server that handles incoming queries, zone transfers (AXFR/IXFR), updates (RFC 2136), and NOTIFY (RFC 1996).