server

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2021 License: GPL-3.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrServerClosed  = errors.New("server closed")
	ErrServerStarted = errors.New("server has been started")
)

Server errors

Functions

func GetClientIPFromReq

func GetClientIPFromReq(req *http.Request, checkHeader string) *utils.NetAddr

func GetMsgFromReq

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

Types

type DNSServerHandler

type DNSServerHandler interface {
	// ServeDNS uses ctx to control deadline, exchanges qCtx, and writes response to w.
	ServeDNS(ctx context.Context, qCtx *handler.Context, w ResponseWriter)
}

type DefaultServerHandler

type DefaultServerHandler struct {
	// Logger is used for logging. A nil value will disable logging.
	Logger *zap.Logger

	// Entry is the entry ExecutablePlugin's tag. This cannot be nil.
	Entry executable_seq.ExecutableCmd

	// ConcurrentLimit controls the max concurrent queries for the DefaultServerHandler.
	// If ConcurrentLimit <= 0, means no limit.
	// When calling DefaultServerHandler.ServeDNS(), if a query exceeds the limit, it will wait on a FIFO queue until
	// - its ctx is done -> The query will be dropped silently.
	// - it can be proceeded -> Normal procedure.
	ConcurrentLimit int
	// contains filtered or unexported fields
}

func (*DefaultServerHandler) ServeDNS

ServeDNS If entry returns an err, a SERVFAIL response will be sent back to client. If concurrentLimit is reached, the query will block and wait available token until ctx is done.

type DoHHandler

type DoHHandler struct {
	DNSHandler          DNSServerHandler // DNS handler for incoming requests. This cannot be nil.
	URLPath             string           // If empty, DoHHandler will not check request's path.
	GetUserIPFromHeader string           // Get client ip from http header, e.g. for nginx, X-Forwarded-For.
	QueryTimeout        time.Duration    // Default is defaultQueryTimeout.
	Logger              *zap.Logger      // Nil logger disables logging.
	// contains filtered or unexported fields
}

func (*DoHHandler) ServeHTTP

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

type DummyServerHandler

type DummyServerHandler struct {
	T       *testing.T
	WantMsg *dns.Msg
	WantErr error
}

func (*DummyServerHandler) ServeDNS

type Protocol

type Protocol uint8
const (
	ProtocolUDP Protocol = iota
	ProtocolTCP
	ProtocolDoT
	ProtocolDoH
	ProtocolHttp
)

DNS protocols

func ParseProtocol

func ParseProtocol(s string) (p Protocol, err error)

type ResponseWriter

type ResponseWriter interface {
	Write(m *dns.Msg) (n int, err error)
}

ResponseWriter can write msg to the client.

type Server

type Server struct {
	Handler  DNSServerHandler
	Protocol Protocol

	Listener   net.Listener
	PacketConn net.PacketConn

	TLSConfig *tls.Config // Used by dot, doh in tls.NewListener.

	URLPath             string // Used by doh, http. If it's emtpy, any path will be handled.
	GetUserIPFromHeader string // Used by doh, http. Get user ip address from http header.

	QueryTimeout time.Duration // Used by all protocol as query timeout, default is defaultQueryTimeout.
	IdleTimeout  time.Duration // Used by tcp, dot, doh as connection idle timeout, default is defaultIdleTimeout.

	Logger *zap.Logger // Nil logger disables logging.
	// contains filtered or unexported fields
}

func (*Server) Close

func (s *Server) Close() error

func (*Server) Start

func (s *Server) Start() error

Start starts the udp server. Start always returns an non-nil err. If server was closed, an ErrServerClosed will be returned.

Jump to

Keyboard shortcuts

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