proxypool

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

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

View Source
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

View Source
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

func DialThrough(ctx context.Context, proxyURL *url.URL, address string) (net.Conn, error)

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

func NewGateway(addr string) *Gateway

NewGateway builds a gateway listening on addr (e.g. 127.0.0.1:8789).

func (*Gateway) Addr

func (g *Gateway) Addr() string

Addr returns the listen address.

func (*Gateway) SetUpstream

func (g *Gateway) SetUpstream(fn func(host string) *url.URL)

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).

func (*Gateway) Start

func (g *Gateway) Start() error

Start begins serving in the background. Safe to call once.

func (*Gateway) Stop

func (g *Gateway) Stop()

Stop gracefully shuts the gateway down.

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 NewPool

func NewPool(database *db.DB, cfg Config) *Pool

NewPool builds a pool bound to db with the given config, applying defaults.

func (*Pool) FetchSourceNow

func (p *Pool) FetchSourceNow(ctx context.Context, name string) (total, added int, err error)

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

func (p *Pool) ProbeNow(ctx context.Context, id int64) (ProbeResult, error)

ProbeNow probes a single proxy on demand (manual "check" button) and writes back the result, returning it for immediate UI feedback.

func (*Pool) Start

func (p *Pool) Start(parent context.Context)

Start launches the fetch and probe loops. Idempotent guards are the caller's job; call once. Stop() (or a cancelled parent ctx) ends both loops.

func (*Pool) Stop

func (p *Pool) Stop()

Stop ends the background loops and waits for them to exit.

type ProbeResult

type ProbeResult struct {
	OK      bool
	Latency time.Duration
	Err     string
}

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.

Jump to

Keyboard shortcuts

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