server

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server answers DNS over UDP and TCP: parse, decide, then either answer from the sinkhole or forward the raw query upstream.

The core (respond, forward) does not care about the transport. udp.go and tcp.go only move bytes in and out.

Index

Constants

View Source
const IdleTimeout = 10 * time.Second

IdleTimeout closes TCP connections that send nothing for this long. RFC 7766 section 6.2.3 suggests a few seconds for a busy server.

Variables

This section is empty.

Functions

This section is empty.

Types

type QueryLog

type QueryLog int

QueryLog chooses which queries get a log line.

const (
	LogAll     QueryLog = iota
	LogBlocked          // blocked and suspicious queries only
	LogNone
)

func ParseQueryLog

func ParseQueryLog(s string) (QueryLog, error)

type Server

type Server struct {
	Cache    *cache.Cache                     // nil disables caching
	Detect   *detect.Detector                 // nil disables threat detection
	Events   *events.Hub                      // nil: no live viewers
	Stats    *stats.Stats                     // nil: no dashboard statistics
	Upstream *upstream.Pool                   // resolvers with failover, UDP and TCP
	Local    func(name string) *upstream.Pool // your own zones (-forward); nil or a nil result means Upstream
	ACL      *guard.ACL                       // nil: every client may ask
	Limit    *guard.Limiter                   // nil: no rate limit
	Log      *slog.Logger
	QueryLog QueryLog
	// contains filtered or unexported fields
}

func (*Server) BlocklistSize

func (s *Server) BlocklistSize() int

BlocklistSize reports how many domains the active policy blocks.

func (*Server) ServeTCP

func (s *Server) ServeTCP(ln net.Listener) error

ServeTCP accepts connections until ln is closed.

func (*Server) ServeUDP

func (s *Server) ServeUDP(conn net.PacketConn) error

ServeUDP handles packets until conn is closed. Each query gets its own goroutine, so one slow upstream answer never blocks the others.

func (*Server) SetPolicy

func (s *Server) SetPolicy(p *policy.Policy)

SetPolicy installs p for all queries from now on.

Jump to

Keyboard shortcuts

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