upstream

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2022 License: GPL-3.0 Imports: 21 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 []byte) ([]byte, error)

type Opt

type Opt struct {
	// DialAddr specifies the address the upstream will
	// actually dial to.
	DialAddr 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.
	// Default: tcp & dot: 0 (disable connection reuse), doh: 30s.
	IdleTimeout time.Duration

	// MaxConns limits the total number of connections,
	// including connections in the dialing states.
	// Used by tcp, dot, doh. Default: 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  func(ctx context.Context) (net.Conn, error)
	WriteFunc func(c io.Writer, m []byte) (int, error)
	ReadFunc  func(c io.Reader) ([]byte, int, error)

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

	// MaxConns controls the maximum connections Transport can open.
	// It includes dialing connections.
	// Default is 1.
	MaxConns int

	// MaxQueryPerConn controls the maximum queries that one connection
	// handled. The connection will be closed if it reached the limit.
	// Default is 65535.
	MaxQueryPerConn uint16

	// IdleTimeout controls the maximum idle time for each connection.
	// If IdleTimeout <= 0, Transport will not reuse connections.
	IdleTimeout time.Duration
	// contains filtered or unexported fields
}

func (*Transport) CloseIdleConnections

func (t *Transport) CloseIdleConnections()

func (*Transport) ExchangeContext

func (t *Transport) ExchangeContext(ctx context.Context, q []byte) ([]byte, error)

type Upstream

type Upstream interface {
	// ExchangeContext exchanges query message q to the upstream, and returns
	// response.
	ExchangeContext(ctx context.Context, q []byte) ([]byte, 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