Documentation ¶
Overview ¶
Package forward implements a forwarding proxy. It caches an upstream net.Conn for some time, so if the same client returns the upstream's Conn will be precached. Depending on how you benchmark this looks to be 50% faster than just opening a new connection for every client. It works with UDP and TCP and uses inband healthchecking.
Package forward implements a forwarding proxy. It caches an upstream net.Conn for some time, so if the same client returns the upstream's Conn will be precached. Depending on how you benchmark this looks to be 50% faster than just opening a new connection for every client. It works with UDP and TCP and uses inband healthchecking.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoHealthy means no healthy proxies left. ErrNoHealthy = errors.New("no healthy proxies") // ErrCachedClosed means cached connection was closed by peer. ErrCachedClosed = errors.New("cached connection was closed by peer") )
var ( RequestCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "pridns", Name: "requests_total", Help: "Counter of requests made per upstream.", }, []string{"to"}) RcodeCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "pridns", Name: "responses_total", Help: "Counter of responses received per upstream.", }, []string{"rcode", "to"}) RequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{ Namespace: plugin.Namespace, Subsystem: "pridns", Name: "request_duration_seconds", Buckets: plugin.TimeBuckets, Help: "Histogram of the time each request took.", }, []string{"to", "rcode"}) HealthcheckFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "pridns", Name: "healthcheck_failures_total", Help: "Counter of the number of failed healthchecks.", }, []string{"to"}) HealthcheckBrokenCount = promauto.NewCounter(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "pridns", Name: "healthcheck_broken_total", Help: "Counter of the number of complete failures of the healthchecks.", }) MaxConcurrentRejectCount = promauto.NewCounter(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "pridns", Name: "max_concurrent_rejects_total", Help: "Counter of the number of queries rejected because the concurrent queries were at maximum.", }) ConnCacheHitsCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "pridns", Name: "conn_cache_hits_total", Help: "Counter of connection cache hits per upstream and protocol.", }, []string{"to", "proto"}) ConnCacheMissesCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "pridns", Name: "conn_cache_misses_total", Help: "Counter of connection cache misses per upstream and protocol.", }, []string{"to", "proto"}) )
Variables declared for monitoring.
var ClientSessionCache = tls.NewLRUClientSessionCache(0)
ClientSessionCache 默认情况下,ClientSessionCache 为 nil,即不会从历史会话中恢复,所以如果有 ClientSessionCache,则二次连接同一 TLS 服务器时握手可能会加快。
Functions ¶
Types ¶
type HealthChecker ¶
type HealthChecker interface { Check(*Proxy) error SetTLSConfig(*tls.Config) SetRecursionDesired(bool) GetRecursionDesired() bool SetDomain(domain string) GetDomain() string SetTCPTransport() }
HealthChecker checks the upstream health.
func NewHealthChecker ¶
func NewHealthChecker(trans string, recursionDesired bool, domain string) HealthChecker
NewHealthChecker returns a new HealthChecker based on transport.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy defines an upstream host.
func GetProxy ¶
func GetProxy(config *types.Config, dnsSvrArray []string, RegisterCloseHook func(func()) func()) ([]*Proxy, error)
GetProxy 根据 forwards 数据从缓存查询对应的 Proxy 实例,如果缓存不存在则创建新实例加入缓存
func (*Proxy) Connect ¶
func (p *Proxy) Connect(ctx context.Context, state request.Request, forceTCP bool, preferUDP bool) (*dns.Msg, error)
Connect selects an upstream, sends the request and waits for a response.
func (*Proxy) Healthcheck ¶
func (p *Proxy) Healthcheck()
Healthcheck kicks of a round of health checks for this proxy.
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) SetTLSConfig ¶
SetTLSConfig sets the TLS config in transport.