Skip to main content

ProxyManager

Struct ProxyManager 

Source
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

Source

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.

Source

pub fn increment_request_count(&self, proxy_url: &str) -> u32

Atomically increment the request count for a proxy and return the new value.

Source

pub fn request_count(&self, proxy_url: &str) -> u32

Return the current request count for a proxy node.

Source

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.

Source

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.

Source

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.

Source

pub fn all_proxy_urls(&self) -> Vec<String>

Get all proxy URLs currently in the manager.

Source

pub fn get_active_proxies(&self) -> Vec<String>

Get proxy URLs that are eligible for scheduling (not Dead or Retired).

Source

pub fn set_state(&self, proxy: &str, state: ProxyState)

Set the state of a proxy.

Source

pub fn get_state(&self, proxy: &str) -> ProxyState

Get the state of a proxy. Returns Unknown if the proxy is not tracked.

Source

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.

Source

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.

Source

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://" when prefer_remote_dns is true, otherwise kept as-is.
  • Bare "ip:port" → prepended with "socks5h://" when prefer_remote_dns is true, otherwise "socks5://".
Source

pub fn total_count(&self) -> usize

Total number of proxies being tracked.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more