Documentation
¶
Overview ¶
Package proxypool provides the outbound proxy pool: dialing through a proxy of any supported scheme, active health probing, and fetching free proxy sources. It is deliberately independent of the traffic (MITM) layer so the pool works whether or not traffic recording is on.
Index ¶
Constants ¶
const DefaultProbeURL = "http://www.gstatic.com/generate_204"
DefaultProbeURL is the liveness target hit through each proxy. generate_204 is tiny, plain HTTP, and returns 204 with no body — cheap and unambiguous.
Variables ¶
var BuiltinSources = []Source{
{Name: "TheSpeedX-http", URL: "https://raw.githubusercontent.com/TheSpeedX/PROXY-List/master/http.txt", Protocol: "http"},
{Name: "TheSpeedX-socks5", URL: "https://raw.githubusercontent.com/TheSpeedX/PROXY-List/master/socks5.txt", Protocol: "socks5"},
{Name: "monosans-http", URL: "https://raw.githubusercontent.com/monosans/proxy-list/main/proxies/http.txt", Protocol: "http"},
{Name: "monosans-socks5", URL: "https://raw.githubusercontent.com/monosans/proxy-list/main/proxies/socks5.txt", Protocol: "socks5"},
}
BuiltinSources is the catalog of free proxy sources. These are widely-mirrored, daily-updated raw text lists with a stable "ip:port\n" format. If a source dies (raw lists do rot), the user disables it; adding/removing entries here is the only maintenance touch-point. 仅收录可拨号的协议(http/https/socks5)——socks4 go-mitmproxy/x/net 均不支持,故不纳入。
Functions ¶
func DialThrough ¶
DialThrough opens a TCP connection to address (host:port) through the given proxy URL. Supports http/https (CONNECT tunnel) and socks5. The returned conn is a raw byte stream to the target; TLS to the target (if any) is the caller's job — the proxy only tunnels, it never terminates TLS to the target.
func SourceNames ¶
func SourceNames() []string
SourceNames returns every built-in source name (for seeding the source list UI).
Types ¶
type Config ¶
type Config struct {
Enabled func() bool // master switch (proxy_pool_enabled)
FetchInterval func() time.Duration // how often to pull enabled free sources
CheckInterval func() time.Duration // how often to re-probe every enabled proxy
ProbeURL func() string // liveness target (empty = DefaultProbeURL)
Concurrency int // parallel probes (default 50)
ProbeTimeout time.Duration // per-probe timeout (default 10s)
}
Config wires the pool's background loops to live settings via callbacks, so a settings change takes effect on the next tick without restarting the loops.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway is a local forward proxy (入口C): agents point HTTP_PROXY at it and it tunnels each connection out through a pool proxy chosen per target host. It is a plain CONNECT tunnel / HTTP forwarder — it does NOT decrypt TLS or record, so it works with cert-pinned targets and protocols the MITM can't parse. Independent of the traffic layer; used when traffic capture is off but the pool is on.
func NewGateway ¶
NewGateway builds a gateway listening on addr (e.g. 127.0.0.1:8789).
func (*Gateway) SetUpstream ¶
SetUpstream installs (or clears with nil) the per-host upstream resolver. A nil return for a host means dial that host directly (gateway adds nothing).
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool runs the proxy pool's two background loops (fetch + probe) and serves one-off manual probes. It owns nothing the DB doesn't; all state lives in PG.
func (*Pool) FetchSourceNow ¶
FetchSourceNow pulls one source on demand (manual "fetch now" button), then probes so freshly-added nodes become usable without waiting for the loop.
func (*Pool) ProbeNow ¶
ProbeNow probes a single proxy on demand (manual "check" button) and writes back the result, returning it for immediate UI feedback.
type ProbeResult ¶
ProbeResult is one liveness check outcome.
func Probe ¶
func Probe(ctx context.Context, proxyURL *url.URL, probeURL string, timeout time.Duration) ProbeResult
Probe checks whether a proxy can reach probeURL within timeout, returning success + round-trip latency, or the failure reason. A 2xx/3xx response counts as alive (some probe targets redirect).
type Source ¶
type Source struct {
Name string
URL string
Protocol string // protocol assigned to every entry from this source
}
Source is one free proxy source. Only format-stable GitHub raw "host:port" lists are used (no HTML scraping) — each line is a bare host:port, protocol is fixed per source. Sources are DISABLED by default; users opt in per source.