upstream

package
v3.8.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DoHUpstream added in v3.7.0

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

	AddOnCloser io.Closer
}

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

func (*DoHUpstream) Close added in v3.8.0

func (u *DoHUpstream) Close() error

func (*DoHUpstream) CloseIdleConnections added in v3.7.0

func (u *DoHUpstream) CloseIdleConnections()

func (*DoHUpstream) ExchangeContext added in v3.7.0

func (u *DoHUpstream) 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.
	// Not implemented for doh upstreams with http/3.
	DialAddr string

	// Socks5 specifies the socks5 proxy server that the upstream
	// will connect though.
	// Not implemented for udp upstreams and doh upstreams with http/3.
	Socks5 string

	// SoMark specifies the mark for each packet sent through this upstream.
	// Not implemented for doh upstreams with http/3
	SoMark int

	// IdleTimeout specifies the idle timeout for long-connections.
	// Available for TCP, DoT, DoH.
	// If negative, TCP, DoT will not reuse connections.
	// Default: TCP, DoT: 10s , DoH: 30s.
	IdleTimeout time.Duration

	// EnablePipeline enables query pipelining support as RFC 7766 6.2.1.1 suggested.
	// Available for TCP, DoT upstream with IdleTimeout >= 0.
	EnablePipeline bool

	// EnableHTTP3 enables HTTP/3 protocol for DoH upstream.
	EnableHTTP3 bool

	// MaxConns limits the total number of connections, including connections
	// in the dialing states.
	// Implemented for TCP/DoT pipeline enabled upstreams and DoH upstreams.
	// Default is 1.
	MaxConns int

	// TLSConfig specifies the tls.Config that the TLS client will use.
	// Available for DoT, DoH upstreams.
	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 defaultMaxConns.
	// 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 defaultMaxQueryPerConn.
	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) Close added in v3.8.0

func (t *Transport) Close() error

Close closes the Transport and all its active connections. All going queries will fail instantly. It always returns nil error.

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()

	io.Closer
}

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