pub struct ChainEngine { /* private fields */ }Expand description
Routes outbound TCP connections through a configurable chain of proxies.
Implementations§
Source§impl ChainEngine
impl ChainEngine
Sourcepub fn new(config: ChainConfig) -> Self
pub fn new(config: ChainConfig) -> Self
Create a new engine from config.
Sourcepub fn rr_peek_offset(&self) -> usize
pub fn rr_peek_offset(&self) -> usize
Return the current round-robin offset without advancing it.
Useful for inspection and benchmarking; the value may change concurrently and is only a snapshot.
Sourcepub async fn connect(&self, target: Target) -> Result<BoxStream>
pub async fn connect(&self, target: Target) -> Result<BoxStream>
Open a connection to target through the proxy chain.
If the target matches a localnet rule, a direct connection is made.
DNAT rewrites are applied before localnet and proxy selection.
For Random and RoundRobin chains, the selection is retried up to
chain_retries additional times (with a fresh random/rotating slice
each attempt) before giving up.
Returns a BoxStream so that TLS-wrapped hops (HTTPS proxies) and
plain TCP hops share the same return type.
Sourcepub fn apply_dnat(&self, target: Target) -> Target
pub fn apply_dnat(&self, target: Target) -> Target
Apply DNAT rewrite rules to target.
Returns the rewritten target, or target unchanged if no rule matches.
Sourcepub fn is_localnet(&self, target: &Target) -> bool
pub fn is_localnet(&self, target: &Target) -> bool
Check whether target matches any localnet exclusion rule.
Returns true when the connection should bypass the proxy chain and
connect directly.
Sourcepub fn live_proxy_refs(&self) -> Vec<&ProxyEntry>
pub fn live_proxy_refs(&self) -> Vec<&ProxyEntry>
Return references to all proxies that have not been marked dead.
Falls back to the full proxy list if every proxy is dead, so that callers always have at least one candidate to try.
Sourcepub fn record_failure(&self, proxy: &ProxyEntry)
pub fn record_failure(&self, proxy: &ProxyEntry)
Increment the failure counter for proxy. No-op when proxy_dead_threshold == 0.
Callers may use this to pre-populate the dead-proxy state (e.g. from persistent storage between process restarts) or to manually evict a known-bad proxy.