transport

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: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTDCTooManyQueries = errors.New("too many queries") // Connection has too many ongoing queries.
	ErrTDCClosed         = errors.New("dns connection closed")
)
View Source
var (
	ErrClosedTransport                     = errors.New("transport has been closed")
	ErrPayloadOverFlow                     = errors.New("payload is too large")
	ErrNewConnCannotReserveQueryExchanger  = errors.New("new connection failed to reserve query exchanger")
	ErrLazyConnCannotReserveQueryExchanger = errors.New("lazy connection failed to reserve query exchanger")
)

Functions

This section is empty.

Types

type DnsConn added in v5.3.0

type DnsConn interface {
	// ReserveNewQuery reserves a query. It MUST be fast and non-block. If DnsConn
	// cannot serve more query due to its capacity, ReserveNewQuery returns nil.
	// If DnsConn is closed and can no longer serve more query, returns closed = true.
	ReserveNewQuery() (_ ReservedExchanger, closed bool)
	io.Closer
}

type NetConn added in v5.3.0

type NetConn interface {
	io.ReadWriteCloser
	SetDeadline(t time.Time) error
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error
}

type PipelineOpts

type PipelineOpts struct {
	// DialContext specifies the method to dial a connection to the server.
	// DialContext MUST NOT be nil.
	DialContext func(ctx context.Context) (DnsConn, error)

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

	// When connection is dialing, how many queries can be queued up in that
	// connection. Default is defaultLazyConnMaxConcurrentQuery.
	// Note: If the connection turns out having a smaller limit, part of queued up
	// queries will fail.
	MaxConcurrentQueryWhileDialing int

	Logger *zap.Logger
}

type PipelineTransport

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

PipelineTransport will pipeline queries as RFC 7766 6.2.1.1 suggested. It also can reuse udp socket. Since dns over udp is some kind of "pipeline".

func NewPipelineTransport

func NewPipelineTransport(opt PipelineOpts) *PipelineTransport

func (*PipelineTransport) Close

func (t *PipelineTransport) Close() error

Close closes PipelineTransport and all its connections. It always returns a nil error.

func (*PipelineTransport) ExchangeContext

func (t *PipelineTransport) ExchangeContext(ctx context.Context, m []byte) (*[]byte, error)

type QuicDnsConn added in v5.3.0

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

func NewQuicDnsConn added in v5.3.0

func NewQuicDnsConn(c quic.Connection) *QuicDnsConn

func (*QuicDnsConn) Close added in v5.3.0

func (c *QuicDnsConn) Close() error

func (*QuicDnsConn) ReserveNewQuery added in v5.3.0

func (c *QuicDnsConn) ReserveNewQuery() (_ ReservedExchanger, closed bool)

type ReservedExchanger added in v5.3.0

type ReservedExchanger interface {
	// ExchangeReserved sends q to the server and returns it's response.
	// ExchangeReserved MUST not modify nor keep the q.
	// q MUST be a valid dns message.
	// resp (if no err) should be released by ReleaseResp().
	ExchangeReserved(ctx context.Context, q []byte) (resp *[]byte, err error)

	// WithdrawReserved aborts the query.
	WithdrawReserved()
}

One method MUST be called in ReservedExchanger.

type ReuseConnOpts

type ReuseConnOpts struct {
	// DialContext specifies the method to dial a connection to the server.
	// DialContext MUST NOT be nil.
	DialContext func(ctx context.Context) (NetConn, error)

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

	// Default is defaultIdleTimeout
	IdleTimeout time.Duration

	Logger *zap.Logger
}

type ReuseConnTransport

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

ReuseConnTransport is for old tcp protocol. (no pipelining)

func NewReuseConnTransport

func NewReuseConnTransport(opt ReuseConnOpts) *ReuseConnTransport

func (*ReuseConnTransport) Close

func (t *ReuseConnTransport) Close() error

Close closes ReuseConnTransport and all its connections. It always returns a nil error.

func (*ReuseConnTransport) ExchangeContext

func (t *ReuseConnTransport) ExchangeContext(ctx context.Context, m []byte) (*[]byte, error)

type TraditionalDnsConn added in v5.3.0

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

TraditionalDnsConn is a low-level connection for traditional dns protocol, where dns frames transport in a single and simple connection. (e.g. udp, tcp, tls)

func NewDnsConn added in v5.3.0

func NewDnsConn(opt TraditionalDnsConnOpts, conn NetConn) *TraditionalDnsConn

func (*TraditionalDnsConn) Close added in v5.3.0

func (dc *TraditionalDnsConn) Close() error

func (*TraditionalDnsConn) CloseWithErr added in v5.3.0

func (dc *TraditionalDnsConn) CloseWithErr(err error)

CloseWithErr closes DnsConn with an error. The error will be sent to the waiting Exchange calls. Subsequent calls are noop. Default err is ErrTDCClosed.

func (*TraditionalDnsConn) IsClosed added in v5.3.0

func (dc *TraditionalDnsConn) IsClosed() bool

func (*TraditionalDnsConn) ReserveNewQuery added in v5.3.0

func (dc *TraditionalDnsConn) ReserveNewQuery() (_ ReservedExchanger, closed bool)

type TraditionalDnsConnOpts added in v5.3.0

type TraditionalDnsConnOpts struct {
	// Set to true if underlayer connection require a length header.
	// e.g. TCP and DoT.
	WithLengthHeader bool

	// IdleTimeout controls the maximum idle time for each connection.
	// Default is defaultIdleTimeout.
	IdleTimeout time.Duration

	// MaxConcurrentQuery limits the number of maximum concurrent queries
	// in the connection. Default is defaultTdcMaxConcurrentQuery.
	MaxConcurrentQuery int
}

Jump to

Keyboard shortcuts

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