pub struct ProxyManager { /* private fields */ }Expand description
Manages a set of SOCKS5 proxies: fetching from sources, normalizing URLs,
tracking state, and caching reqwest::Client instances.
Implementations§
Source§impl ProxyManager
impl ProxyManager
Sourcepub fn new(proxy_timeout: Duration) -> Self
pub fn new(proxy_timeout: Duration) -> Self
Create a new ProxyManager with the given per-proxy connection timeout.
Retrieve the stored cookie value for a proxy node, if any.
Store a cookie value for a proxy node, replacing any existing value.
Sourcepub fn increment_request_count(&self, proxy_url: &str) -> u32
pub fn increment_request_count(&self, proxy_url: &str) -> u32
Atomically increment the request count for a proxy and return the new value.
Sourcepub fn request_count(&self, proxy_url: &str) -> u32
pub fn request_count(&self, proxy_url: &str) -> u32
Return the current request count for a proxy node.
Sourcepub fn reset_request_count(&self, proxy_url: &str)
pub fn reset_request_count(&self, proxy_url: &str)
Reset the request count for a proxy node and, if the node was Retired,
restore it to Active. Dead nodes are not restored.
Sourcepub fn challenge_lock(&self, proxy_url: &str) -> Arc<Semaphore>
pub fn challenge_lock(&self, proxy_url: &str) -> Arc<Semaphore>
Acquire the per-proxy challenge lock (semaphore with 1 permit).
Ensures at most one concurrent challenge solve per proxy node.
Sourcepub async fn fetch_and_add(
&self,
sources: &[String],
prefer_remote_dns: bool,
) -> Result<usize, ScatterProxyError>
pub async fn fetch_and_add( &self, sources: &[String], prefer_remote_dns: bool, ) -> Result<usize, ScatterProxyError>
Fetch proxy lists from the given source URLs, normalize each line, and add any new proxies to the manager.
Returns the count of newly added proxies across all sources. Errors fetching individual sources are logged but do not cause the overall call to fail.
Sourcepub fn all_proxy_urls(&self) -> Vec<String>
pub fn all_proxy_urls(&self) -> Vec<String>
Get all proxy URLs currently in the manager.
Sourcepub fn get_active_proxies(&self) -> Vec<String>
pub fn get_active_proxies(&self) -> Vec<String>
Get proxy URLs that are eligible for scheduling (not Dead or Retired).
Sourcepub fn set_state(&self, proxy: &str, state: ProxyState)
pub fn set_state(&self, proxy: &str, state: ProxyState)
Set the state of a proxy.
Sourcepub fn get_state(&self, proxy: &str) -> ProxyState
pub fn get_state(&self, proxy: &str) -> ProxyState
Get the state of a proxy. Returns Unknown if the proxy is not tracked.
Sourcepub fn proxy_counts(&self) -> (usize, usize, usize, usize, usize)
pub fn proxy_counts(&self) -> (usize, usize, usize, usize, usize)
Count proxies by state.
Returns (total, active_or_unknown, cooldown_placeholder, dead, retired).
The cooldown placeholder is always 0 — cooldown tracking lives in a separate module.
Sourcepub fn get_client(&self, proxy_url: &str) -> Result<Client, ScatterProxyError>
pub fn get_client(&self, proxy_url: &str) -> Result<Client, ScatterProxyError>
Get or create a reqwest::Client configured to route through the given
proxy URL. Clients are cached for reuse.
Sourcepub fn normalize_proxy_url(raw: &str, prefer_remote_dns: bool) -> String
pub fn normalize_proxy_url(raw: &str, prefer_remote_dns: bool) -> String
Normalize a raw proxy string to a full URL.
Rules:
- Empty lines and lines starting with
#are returned as empty string. "socks5h://ip:port"→ returned as-is."socks5://ip:port"→ replaced with"socks5h://"whenprefer_remote_dnsis true, otherwise kept as-is.- Bare
"ip:port"→ prepended with"socks5h://"whenprefer_remote_dnsis true, otherwise"socks5://".
Sourcepub fn total_count(&self) -> usize
pub fn total_count(&self) -> usize
Total number of proxies being tracked.