upstream

package
v3.5.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2022 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DoH

type DoH struct {
	// EndPoint is the DoH server URL.
	EndPoint string
	// Client is a http.Client that sends http requests.
	Client *http.Client
}

DoH is a DNS-over-HTTPS (RFC 8484) upstream.

func (*DoH) CloseIdleConnections

func (u *DoH) CloseIdleConnections()

func (*DoH) ExchangeContext

func (u *DoH) ExchangeContext(ctx context.Context, q *dns.Msg) (*dns.Msg, error)

type Opt

type Opt struct {
	// DialAddr specifies the address the upstream will
	// actually dial to.
	DialAddr string

	Bootstrap string

	// Socks5 specifies the socks5 proxy server that the upstream
	// will connect though. Currently, only tcp, dot, doh upstream support Socks5 proxy.
	Socks5 string

	// IdleTimeout used by tcp, dot, doh to control connection idle timeout.
	// If negative, tcp, dot will not reuse connections.
	// Default: tcp & dot: 10s , doh: 30s.
	IdleTimeout time.Duration

	// EnablePipeline enables the query pipelining as RFC 7766 6.2.1.1 suggested.
	// Available for tcp/dot upstream with IdleTimeout >= 0.
	EnablePipeline bool

	// EnableHTTP3 enables the HTTP/3 for DoH. Note that there is no HTTP/2 fallback.
	EnableHTTP3 bool

	// MaxConns limits the total number of connections, including connections
	// in the dialing states.
	// MaxConns takes effect on tcp/dot upstream with IdleTimeout >= 0 and EnablePipeline.
	// And doh upstream.
	// Default is 1.
	MaxConns int

	// TLSConfig specifies the tls.Config that the TLS client will use.
	// Used by dot, doh.
	TLSConfig *tls.Config

	// Logger specifies the logger that the upstream will use.
	Logger *zap.Logger
}

type Transport

type Transport struct {
	// Nil logger disables logging.
	Logger *zap.Logger

	// The following funcs cannot be nil.
	// DialFunc specifies the method to dial a connection to the server.
	DialFunc func(ctx context.Context) (net.Conn, error)
	// WriteFunc specifies the method to write a wire dns msg to the connection
	// opened by the DialFunc.
	WriteFunc func(c io.Writer, m *dns.Msg) (int, error)
	// ReadFunc specifies the method to read a wire dns msg from the connection
	// opened by the DialFunc.
	ReadFunc func(c io.Reader) (*dns.Msg, int, error)

	// DialTimeout specifies the timeout for DialFunc.
	// Default is defaultDialTimeout.
	DialTimeout time.Duration

	// IdleTimeout controls the maximum idle time for each connection.
	// If IdleTimeout < 0, Transport will not reuse connections.
	// Default is defaultIdleTimeout.
	IdleTimeout time.Duration

	// If EnablePipeline is set and IdleTimeout > 0, the Transport will pipeline
	// queries as RFC 7766 6.2.1.1 suggested.
	EnablePipeline bool

	// MaxConns controls the maximum pipeline connections Transport can open.
	// It includes dialing connections.
	// Default is 1.
	// Each connection can handle no more than 65535 queries concurrently.
	// Typically, it is very rare reaching that limit.
	MaxConns int

	// MaxQueryPerConn controls the maximum queries that one pipeline connection
	// can handle. The connection will be closed if it reached the limit.
	// Default is 65535.
	MaxQueryPerConn uint16
	// contains filtered or unexported fields
}

Transport is a DNS msg transport that supposes DNS over UDP,TCP,TLS. For UDP, it can reuse UDP sockets. For TCP and DoT, it implements RFC 7766 and supports pipeline mode and can handle out-of-order responses.

func (*Transport) CloseIdleConnections

func (t *Transport) CloseIdleConnections()

func (*Transport) ExchangeContext

func (t *Transport) ExchangeContext(ctx context.Context, q *dns.Msg) (*dns.Msg, error)

type Upstream

type Upstream interface {
	// ExchangeContext exchanges query message m to the upstream, and returns
	// response. It MUST NOT keep or modify m.
	ExchangeContext(ctx context.Context, m *dns.Msg) (*dns.Msg, error)

	// CloseIdleConnections closes any connections in the Upstream which
	// now sitting idle. It does not interrupt any connections currently in use.
	CloseIdleConnections()
}

Upstream represents a DNS upstream.

func NewUpstream

func NewUpstream(addr string, opt *Opt) (Upstream, error)

Jump to

Keyboard shortcuts

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