Documentation
¶
Overview ¶
Package proxyhive manages proxy pools with health checking, rotation strategies, latency scoring, geo-filtering, and sticky sessions.
Index ¶
- type Dialer
- type Filter
- type HealthChecker
- type Option
- type Pool
- func (p *Pool) Add(rawURL string, opts ...ProxyOption) error
- func (p *Pool) AddMany(rawURLs []string, opts ...ProxyOption) error
- func (p *Pool) Alive() []*Proxy
- func (p *Pool) Close()
- func (p *Pool) DialContext(ctx context.Context, network, addr string) (net.Conn, error)
- func (p *Pool) Get(filters ...Filter) (*Proxy, error)
- func (p *Pool) NewDialer(filters ...Filter) *Dialer
- func (p *Pool) Remove(rawURL string)
- func (p *Pool) RoundTripper(filters ...Filter) http.RoundTripper
- func (p *Pool) Stats() PoolStats
- type PoolStats
- type Protocol
- type Proxy
- type ProxyOption
- type Strategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
Dialer wraps a Pool to provide a DialContext compatible with net.Dialer.
type Filter ¶
Filter narrows proxy selection by returning true for matching proxies.
func Sticky ¶
Sticky returns a special filter that enables sticky sessions. The given key maps to a specific proxy for the duration of ttl.
func WithAlive ¶
func WithAlive() Filter
WithAlive returns a filter that matches only alive proxies. Applied by default.
func WithCity ¶
WithCity returns a filter that matches proxies in any of the given cities (case-insensitive).
func WithCountry ¶
WithCountry returns a filter that matches proxies in any of the given countries (ISO 3166-1 alpha-2).
func WithMaxLatency ¶
WithMaxLatency returns a filter that excludes proxies with EWMA latency above d.
func WithProtocol ¶
WithProtocol returns a filter that matches proxies with the given protocol.
type HealthChecker ¶
type HealthChecker struct {
// contains filtered or unexported fields
}
HealthChecker runs background health checks against proxies in a pool.
type Option ¶
type Option func(*poolConfig)
Option configures a Pool.
func WithEWMADecay ¶
WithEWMADecay sets the alpha factor for EWMA latency calculation.
func WithHealthCheck ¶
WithHealthCheck sets the interval and timeout for background health checks.
func WithHealthCheckURL ¶
WithHealthCheckURL sets the URL used for health check validation.
func WithMaxBackoff ¶
WithMaxBackoff sets the maximum backoff duration for failed proxies.
func WithStrategy ¶
WithStrategy sets the proxy rotation strategy.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manages a set of proxies with health checking and rotation.
func (*Pool) Add ¶
func (p *Pool) Add(rawURL string, opts ...ProxyOption) error
Add parses and adds a single proxy to the pool.
func (*Pool) AddMany ¶
func (p *Pool) AddMany(rawURLs []string, opts ...ProxyOption) error
AddMany parses and adds multiple proxies to the pool.
func (*Pool) Close ¶
func (p *Pool) Close()
Close stops the background health checker and releases resources.
func (*Pool) DialContext ¶
DialContext connects to the target address through a pool proxy.
func (*Pool) Get ¶
Get selects a proxy from the pool using the configured strategy. WithAlive is always applied. Additional filters narrow the candidates.
func (*Pool) RoundTripper ¶
func (p *Pool) RoundTripper(filters ...Filter) http.RoundTripper
RoundTripper returns an http.RoundTripper that routes requests through the pool.
type PoolStats ¶
type PoolStats struct {
Total int
Alive int
Dead int
AvgLatency time.Duration
Protocols map[Protocol]int
Countries map[string]int
}
PoolStats contains aggregate statistics about the pool.
type Proxy ¶
type Proxy struct {
URL *url.URL
Protocol Protocol
Country string
City string
ASN string
// contains filtered or unexported fields
}
Proxy represents a single proxy with metadata and health stats.
func ParseProxy ¶
ParseProxy parses a raw proxy string into a Proxy. Supported formats: http://host:port, socks5://user:pass@host:port, socks4://host:port, or bare host:port (defaults to HTTP).
func ParseProxyList ¶
ParseProxyList reads proxies from a reader, one per line. Empty lines and lines starting with # are skipped.
func (*Proxy) SuccessCount ¶
SuccessCount returns the total successful checks.
type ProxyOption ¶
type ProxyOption func(*Proxy)
ProxyOption configures per-proxy metadata when adding.
func WithASNTag ¶
func WithASNTag(asn string) ProxyOption
WithASNTag sets the proxy's ASN identifier.
type Strategy ¶
Strategy selects a proxy from a list of candidates.
func LeastLatency ¶
func LeastLatency() Strategy
LeastLatency returns a strategy that always picks the lowest latency proxy. Warning: may cause thundering herd if many clients use the same pool.
func P2C ¶
func P2C() Strategy
P2C returns a Power of Two Choices strategy. Picks 2 random proxies and returns the one with lower latency.
func Random ¶
func Random() Strategy
Random returns a strategy that selects a proxy uniformly at random.
func RoundRobin ¶
func RoundRobin() Strategy
RoundRobin returns a strategy that cycles through proxies sequentially.