proxy

package
v0.0.4-openssl Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 26 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package proxy implements a forwarding proxy with connection caching. It reuses upstream DNS, DoT, DoH, and DoQ connections to reduce latency and handshake overhead. It supports in-band health checking.

Index

Constants

View Source
const (
	ErrTransportStopped = "proxy: transport stopped"
)

Variables

View Source
var (
	// ErrNoHealthy means no healthy proxies left.
	ErrNoHealthy = errors.New("no healthy proxies")
	// ErrNoForward means no forwarder defined.
	ErrNoForward = errors.New("no forwarder defined")
	// ErrCachedClosed means cached connection was closed by peer.
	ErrCachedClosed = errors.New("cached connection was closed by peer")
	// ErrUnsupportedRequest means the proxy transport cannot represent the request.
	ErrUnsupportedRequest = errors.New("proxy: unsupported request")
)
View Source
var ErrInvalidRequest = errors.New("proxy: invalid request")

Functions

This section is empty.

Types

type HealthChecker

type HealthChecker interface {
	Check(*Proxy) error
	SetTLSConfig(*tls.Config)
	GetTLSConfig() *tls.Config
	SetRecursionDesired(bool)
	GetRecursionDesired() bool
	SetDomain(domain string)
	GetDomain() string
	SetTCPTransport()
	GetReadTimeout() time.Duration
	SetReadTimeout(time.Duration)
	GetWriteTimeout() time.Duration
	SetWriteTimeout(time.Duration)
	SetLocalAddress(net.IP)
	GetLocalAddress() net.IP
}

HealthChecker checks the upstream health.

func NewHealthChecker

func NewHealthChecker(proxyName, protocol string, recursionDesired bool, domain string) HealthChecker

NewHealthChecker returns a new HealthChecker based on transport.

type Options

type Options struct {
	// ForceTCP use TCP protocol for upstream DNS request. Has precedence over PreferUDP flag
	ForceTCP bool
	// PreferUDP use UDP protocol for upstream DNS request.
	PreferUDP bool
	// HCRecursionDesired sets recursion desired flag for Proxy healthcheck requests
	HCRecursionDesired bool
	// HCDomain sets domain for Proxy healthcheck requests
	HCDomain string
	// TLSConnectDeadline bounds the TCP dial and TLS handshake for DoT, not the DNS exchange.
	// A zero value leaves the adaptive dial timeout and caller context as the only limits.
	TLSConnectDeadline time.Time
}

Options holds various Options that can be set.

type Proxy

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

Proxy defines an upstream host.

func NewProxy

func NewProxy(proxyName, addr, protocol string) *Proxy

NewProxy returns a new proxy.

func (*Proxy) Addr

func (p *Proxy) Addr() string

func (*Proxy) Connect

func (p *Proxy) Connect(ctx context.Context, state request.Request, opts Options) (*dns.Msg, net.Addr, string, error)

Connect selects an upstream, sends the request and waits for a response. It also returns CoreDNS's own outbound address on the upstream socket (localAddr) and the transport proto ("udp" or "tcp") actually used to reach the upstream.

func (*Proxy) DoHHost

func (p *Proxy) DoHHost() string

func (*Proxy) Down

func (p *Proxy) Down(maxfails uint32) bool

Down returns true if this proxy is down, i.e. has *more* fails than maxfails.

func (*Proxy) Fails

func (p *Proxy) Fails() uint32

func (*Proxy) GetHealthchecker

func (p *Proxy) GetHealthchecker() HealthChecker

func (*Proxy) GetTransport

func (p *Proxy) GetTransport() *Transport

func (*Proxy) Healthcheck

func (p *Proxy) Healthcheck()

Healthcheck kicks of a round of health checks for this proxy.

func (*Proxy) SetDOHHost

func (p *Proxy) SetDOHHost(host string)

func (*Proxy) SetDOHRequestOptions

func (p *Proxy) SetDOHRequestOptions(method string)

func (*Proxy) SetExpire

func (p *Proxy) SetExpire(expire time.Duration)

SetExpire sets the expire duration in the lower p.transport.

func (*Proxy) SetHTTPClient

func (p *Proxy) SetHTTPClient(client *http.Client)

func (*Proxy) SetLocalAddress

func (p *Proxy) SetLocalAddress(addr net.IP)

SetLocalAddress sets the local address for the proxy, used as the source address for outbound connections.

func (*Proxy) SetMaxAge

func (p *Proxy) SetMaxAge(maxAge time.Duration)

SetMaxAge sets the maximum connection lifetime in the lower p.transport. A value of 0 (default) disables max-age.

func (*Proxy) SetMaxIdleConns

func (p *Proxy) SetMaxIdleConns(n int)

SetMaxIdleConns sets the maximum idle connections per transport type. A value of 0 means unlimited (default).

func (*Proxy) SetReadTimeout

func (p *Proxy) SetReadTimeout(duration time.Duration)

func (*Proxy) SetTLSConfig

func (p *Proxy) SetTLSConfig(cfg *tls.Config)

SetTLSConfig sets the TLS config in the lower p.transport and in the healthchecking client.

func (*Proxy) Start

func (p *Proxy) Start(duration time.Duration)

Start starts the proxy's healthchecking.

func (*Proxy) Stop

func (p *Proxy) Stop()

Stop stops health checking and closes the DoQ transport, when configured.

type Transport

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

Transport hold the persistent cache.

func (*Transport) Dial

func (t *Transport) Dial(proto string) (*persistConn, bool, error)

Dial dials the address configured in transport, potentially reusing a connection or creating a new one.

func (*Transport) DialContext

func (t *Transport) DialContext(ctx context.Context, proto string) (*persistConn, bool, error)

DialContext is like Dial but honors ctx while establishing a new connection, including the TLS handshake. The context does not affect the connection after dialing.

func (*Transport) GetTLSConfig

func (t *Transport) GetTLSConfig() *tls.Config

GetTLSConfig returns the TLS config in transport.

func (*Transport) SetExpire

func (t *Transport) SetExpire(expire time.Duration)

SetExpire sets the connection expire time in transport.

func (*Transport) SetLocalAddress

func (t *Transport) SetLocalAddress(addr net.IP)

SetLocalAddress sets the local address in transport.

func (*Transport) SetMaxAge

func (t *Transport) SetMaxAge(maxAge time.Duration)

SetMaxAge sets the maximum lifetime of a connection regardless of activity. A value of 0 (default) disables max-age and connections are only closed by expire (idle-timeout).

func (*Transport) SetMaxIdleConns

func (t *Transport) SetMaxIdleConns(n int)

SetMaxIdleConns sets the maximum idle connections per transport type. A value of 0 means unlimited (default).

func (*Transport) SetTLSConfig

func (t *Transport) SetTLSConfig(cfg *tls.Config)

SetTLSConfig sets the TLS config in transport.

func (*Transport) Start

func (t *Transport) Start()

Start starts the transport's connection manager.

func (*Transport) Stop

func (t *Transport) Stop()

Stop stops the transport's connection manager.

func (*Transport) Yield

func (t *Transport) Yield(pc *persistConn)

Yield returns the connection to transport for reuse.

Jump to

Keyboard shortcuts

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