server

package
v5.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadCert

func LoadCert(tlsCfg *tls.Config, cert, key string) error

func ReadMsgFromReq added in v5.2.0

func ReadMsgFromReq(req *http.Request) (*dns.Msg, error)

func ServeDoQ added in v5.2.0

func ServeDoQ(l *quic.Listener, h Handler, opts DoQServerOpts) error

ServeDoQ starts a server at l. It returns if l had an Accept() error. It always returns a non-nil error.

func ServeTCP added in v5.2.0

func ServeTCP(l net.Listener, h Handler, opts TCPServerOpts) error

ServeTCP starts a server at l. It returns if l had an Accept() error. It always returns a non-nil error.

func ServeUDP added in v5.2.0

func ServeUDP(c *net.UDPConn, h Handler, opts UDPServerOpts) error

ServeUDP starts a server at c. It returns if c had a read error. It always returns a non-nil error. h is required. logger is optional.

Types

type DoQServerOpts added in v5.2.0

type DoQServerOpts struct {
	Logger      *zap.Logger
	IdleTimeout time.Duration
}

type Handler added in v5.2.0

type Handler interface {
	Handle(ctx context.Context, q *dns.Msg, meta QueryMeta, packMsgPayload func(m *dns.Msg) (*[]byte, error)) (respPayload *[]byte)
}

Handler handles incoming request q and MUST ALWAYS return a response. Handler MUST handle dns errors by itself and return a proper error responses. e.g. Return a SERVFAIL if something goes wrong. If Handle() returns a nil resp, caller will udp: do nothing. tcp/dot: close the connection immediately. doh: send a 500 response. doq: close the stream immediately.

type HttpHandler added in v5.2.0

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

func NewHttpHandler added in v5.2.0

func NewHttpHandler(h Handler, opts HttpHandlerOpts) *HttpHandler

func (*HttpHandler) ServeHTTP added in v5.2.0

func (h *HttpHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type HttpHandlerOpts added in v5.2.0

type HttpHandlerOpts struct {
	// GetSrcIPFromHeader specifies the header that contain client source address.
	// e.g. "X-Forwarded-For".
	GetSrcIPFromHeader string

	// Logger specifies the logger which Handler writes its log to.
	// Default is a nop logger.
	Logger *zap.Logger
}

type QueryMeta added in v5.2.0

type QueryMeta struct {
	FromUDP bool

	// Optional
	ClientAddr netip.Addr
	ServerName string
	UrlPath    string
}

type TCPServerOpts

type TCPServerOpts struct {
	// Nil logger == nop
	Logger *zap.Logger

	// Default is defaultTCPIdleTimeout.
	IdleTimeout time.Duration
}

type UDPServerOpts

type UDPServerOpts struct {
	Logger *zap.Logger
}

Jump to

Keyboard shortcuts

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