Documentation
¶
Overview ¶
Package proxy implements a forwarding proxy with connection caching. It manages a pool of upstream connections (UDP and TCP) to reuse them for subsequent requests, reducing latency and handshake overhead. It supports in-band health checking.
Index ¶
- Constants
- Variables
- type HealthChecker
- type Options
- type Proxy
- func (p *Proxy) Addr() string
- func (p *Proxy) Connect(ctx context.Context, state request.Request, opts Options) (*dns.Msg, error)
- func (p *Proxy) Down(maxfails uint32) bool
- func (p *Proxy) Fails() uint32
- func (p *Proxy) GetHealthchecker() HealthChecker
- func (p *Proxy) GetTransport() *Transport
- func (p *Proxy) Healthcheck()
- func (p *Proxy) SetExpire(expire time.Duration)
- func (p *Proxy) SetMaxIdleConns(n int)
- func (p *Proxy) SetReadTimeout(duration time.Duration)
- func (p *Proxy) SetTLSConfig(cfg *tls.Config)
- func (p *Proxy) Start(duration time.Duration)
- func (p *Proxy) Stop()
- type Transport
- func (t *Transport) Dial(proto string) (*persistConn, bool, error)
- func (t *Transport) GetTLSConfig() *tls.Config
- func (t *Transport) SetExpire(expire time.Duration)
- func (t *Transport) SetMaxIdleConns(n int)
- func (t *Transport) SetTLSConfig(cfg *tls.Config)
- func (t *Transport) Start()
- func (t *Transport) Stop()
- func (t *Transport) Yield(pc *persistConn)
Constants ¶
const (
ErrTransportStopped = "proxy: transport stopped"
)
Variables ¶
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") )
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)
}
HealthChecker checks the upstream health.
func NewHealthChecker ¶
func NewHealthChecker(proxyName, trans 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
}
Options holds various Options that can be set.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy defines an upstream host.
func (*Proxy) GetHealthchecker ¶
func (p *Proxy) GetHealthchecker() HealthChecker
func (*Proxy) GetTransport ¶ added in v1.13.2
func (*Proxy) Healthcheck ¶
func (p *Proxy) Healthcheck()
Healthcheck kicks of a round of health checks for this proxy.
func (*Proxy) SetMaxIdleConns ¶ added in v1.14.1
SetMaxIdleConns sets the maximum idle connections per transport type. A value of 0 means unlimited (default).
func (*Proxy) SetReadTimeout ¶
func (*Proxy) SetTLSConfig ¶
SetTLSConfig sets the TLS config in the lower p.transport and in the healthchecking client.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport hold the persistent cache.
func (*Transport) Dial ¶
Dial dials the address configured in transport, potentially reusing a connection or creating a new one.
func (*Transport) GetTLSConfig ¶ added in v1.13.2
GetTLSConfig returns the TLS config in transport.
func (*Transport) SetMaxIdleConns ¶ added in v1.14.1
SetMaxIdleConns sets the maximum idle connections per transport type. A value of 0 means unlimited (default).
func (*Transport) SetTLSConfig ¶
SetTLSConfig sets the TLS config in transport.