Skip to main content

Module server

Module server 

Source
Expand description

A local rotating proxy server: accepts client connections and relays each through a pool of checked proxies, retrying on a different proxy when one fails. server.py.

Behind the server feature — pure library users mostly do not want a listening socket.

A forward proxy is mostly byte-splicing (copy_bidirectional) plus a CONNECT/negotiate handshake, so this is built on raw tokio rather than hyper: hyper is structured around parsed HTTP messages and is awkward for the CONNECT tunnel upgrade this needs.

The pool avoids server.py’s heapq.heappush((avg_resp_time, proxy)), which raises TypeError on tied f64 (Python compares the Proxy objects, which define no __lt__). Selection here uses f64::total_cmp, so ties are ordered deterministically, never fatal. Imports are served by one dedicated task feeding a Notify, not a per-waiter mutex over the receiver (design critique #22).

Structs§

Pool
A pool of checked proxies, refilled from a [ProxyStream] by a background importer.
PoolConfig
Tuning for proxy eviction and selection (server.py:ProxyPool).
PoolSnapshot
A cheap, allocation-light snapshot of the pool’s live state (F1). One producer, shared with the (deferred) F4 dashboard.
ServerHandle
A running server. Dropping the handle (or calling ServerHandle::shutdown) stops it.

Enums§

ClientKey
The identity a Strategy::Sticky session is keyed on.
Strategy
How the pool picks an upstream for each client request.

Functions§

serve
Start the local proxy server on addr, relaying through pool. Binds immediately and returns the handle (so local_addr works at once); the accept loop runs in a background task and, when min_queue > 0, does not start serving until the pool holds that many proxies (B13). backlog is the TCP listen backlog. auth (user:pass) gates clients: when Some, a client without a matching Proxy-Authorization: Basic <b64> gets 407 (B9).