Skip to main content

ProxyManager

Struct ProxyManager 

Source
pub struct ProxyManager { /* private fields */ }
Expand description

Manager for proxy and source collections with testing and enrichment capabilities.

ProxyManager is the central component for managing proxies and sources. It provides:

  • Storage and retrieval of proxies and sources
  • Testing proxies for anonymity and performance
  • Enriching proxies with metadata (country, organization, ASN)
  • Fetching new proxies from sources
  • Filtering and selection of proxies based on various criteria

§Examples

use gooty_proxy::orchestration::manager::ProxyManager;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a new manager
    let mut manager = ProxyManager::new()?;

    // Initialize services
    manager.init_judge().await?;
    manager.init_sleuth()?;

    // Get stats about managed proxies
    let stats = manager.get_proxy_stats();
    println!("Managing {} proxies, {} working", stats.total, stats.working);

    Ok(())
}

Implementations§

Source§

impl ProxyManager

Source

pub fn new() -> ManagerResult<Self>

Create a new proxy manager with default configuration.

This initializes the manager with empty collections and a default requestor. The judge and sleuth services must be initialized separately.

§Returns

A new ProxyManager instance.

§Errors

Returns an error if the requestor cannot be initialized.

Source

pub fn init_judge(&mut self) -> ManagerResult<()>

Initialize the judge for proxy testing.

The judge service is used to test proxies and determine their anonymity level. This must be called before using methods that test proxies.

§Returns

Ok(()) if the judge was successfully initialized.

§Errors

Returns an error if the judge service cannot be initialized.

Source

pub fn init_sleuth(&mut self) -> ManagerResult<()>

Initialize the sleuth for IP lookups.

The sleuth service is used to lookup IP metadata such as country, organization, and ASN. This must be called before using methods that enrich proxy information.

§Returns

Ok(()) if the sleuth was successfully initialized.

§Errors

Returns an error if the sleuth service cannot be initialized.

Source

pub fn add_proxy(&mut self, proxy: Proxy) -> ManagerResult<bool>

Add a proxy to the manager.

§Arguments
  • proxy - The proxy to add
§Returns

Returns true if the proxy was added, false if it already existed.

§Errors

Returns an error if the proxy is invalid.

Source

pub fn add_proxies(&mut self, proxies: Vec<Proxy>) -> ManagerResult<usize>

Add multiple proxies to the manager.

§Arguments
  • proxies - Vector of proxies to add
§Returns

Returns the number of new proxies that were added.

§Errors

Returns an error if any proxy is invalid.

Source

pub fn get_proxy(&self, id: &str) -> Option<&Proxy>

Get a proxy by its connection string.

§Arguments
  • id - Connection string identifier of the proxy
§Returns

An Option containing a reference to the proxy if found, or None if not found.

Source

pub fn get_proxy_mut(&mut self, id: &str) -> Option<&mut Proxy>

Get a mutable reference to a proxy by its connection string.

§Arguments
  • id - Connection string identifier of the proxy
§Returns

An Option containing a mutable reference to the proxy if found, or None if not found.

Source

pub fn remove_proxy(&mut self, id: &str) -> Option<Proxy>

Remove a proxy by its connection string.

§Arguments
  • id - Connection string identifier of the proxy to remove
§Returns

An Option containing the removed proxy if found, or None if not found.

Source

pub fn proxy_count(&self) -> usize

Get the total number of proxies managed.

§Returns

The number of proxies in the manager.

Source

pub fn get_all_proxies(&self) -> Vec<&Proxy>

Get all proxies as a vector of references.

§Returns

A vector containing references to all proxies.

Source

pub fn get_all_proxies_owned(&self) -> Vec<Proxy>

Get all proxies as owned values.

§Returns

A vector containing clones of all proxies.

Source

pub fn filter_proxies<F>(&self, filter_fn: F) -> Vec<&Proxy>
where F: Fn(&Proxy) -> bool,

Get all proxies that match certain criteria.

§Arguments
  • filter_fn - A function that returns true for proxies that should be included
§Returns

A vector of references to proxies that match the filter criteria.

§Examples
// Get all elite proxies
let elite_proxies = manager.filter_proxies(|p| p.anonymity == AnonymityLevel::Elite);

// Get all proxies with latency under 500ms
let fast_proxies = manager.filter_proxies(|p| p.latency_ms.unwrap_or(u32::MAX) < 500);
Source

pub fn add_source(&mut self, source: Source) -> ManagerResult<bool>

Add a source to the manager.

§Arguments
  • source - The source to add
§Returns

Returns true if the source was added, false if it already existed.

§Errors

Returns an error if the source is invalid.

Source

pub fn add_sources(&mut self, sources: Vec<Source>) -> ManagerResult<usize>

Add multiple sources to the manager.

§Arguments
  • sources - Vector of sources to add
§Returns

Returns the number of new sources that were added.

§Errors

Returns an error if any source is invalid.

Source

pub fn get_source(&self, url: &str) -> Option<&Source>

Get a source by its URL.

§Arguments
  • url - URL identifier of the source
§Returns

An Option containing a reference to the source if found, or None if not found.

Source

pub fn get_source_mut(&mut self, url: &str) -> Option<&mut Source>

Get a mutable reference to a source by its URL.

§Arguments
  • url - URL identifier of the source
§Returns

An Option containing a mutable reference to the source if found, or None if not found.

Source

pub fn remove_source(&mut self, url: &str) -> Option<Source>

Remove a source by its URL.

§Arguments
  • url - URL identifier of the source to remove
§Returns

An Option containing the removed source if found, or None if not found.

Source

pub fn source_count(&self) -> usize

Get the total number of sources.

§Returns

The number of sources in the manager.

Source

pub fn get_all_sources(&self) -> Vec<&Source>

Get all sources as a vector of references.

§Returns

A vector containing references to all sources.

Source

pub fn get_all_sources_owned(&self) -> Vec<Source>

Get all sources as owned values.

§Returns

A vector containing clones of all sources.

Source

pub fn get_proxy_stats(&self) -> ProxyStats

Get statistics about the managed proxies.

This method calculates counts, distributions, and performance metrics for the proxies currently in the manager.

§Returns

A ProxyStats struct containing the calculated statistics.

Source

pub fn get_source_stats(&self) -> SourceStats

Get statistics about the managed sources.

This method calculates counts and performance metrics for the sources currently in the manager.

§Returns

A SourceStats struct containing the calculated statistics.

Source

pub async fn check_proxy(&mut self, proxy_id: &str) -> ManagerResult<()>

Check a proxy by testing its connectivity and anonymity.

§Arguments
  • proxy_id - The connection string identifier of the proxy to check
§Returns

Ok(()) if the check was performed (regardless of the proxy’s status).

§Errors

Returns an error if:

  • The proxy ID is invalid
  • The judge service is not initialized
  • There’s a critical failure in the checking process
Source

pub async fn fetch_from_source( &mut self, source_url: &str, ) -> ManagerResult<Vec<Proxy>>

Fetch proxies from a source.

§Arguments
  • source_url - The URL identifier of the source to fetch from
§Returns

A vector of proxies fetched from the source.

§Errors

Returns an error if:

  • The source URL is invalid
  • The source fails to fetch proxies
Source

pub async fn enrich_proxy(&mut self, proxy_id: &str) -> ManagerResult<()>

Enrich a proxy with IP metadata.

§Arguments
  • proxy_id - The connection string identifier of the proxy to enrich
§Returns

Ok(()) if the enrichment was performed.

§Errors

Returns an error if:

  • The proxy ID is invalid
  • The sleuth service is not initialized
  • There’s a failure in the enrichment process
Source

pub fn get_last_update_time(&self) -> Option<DateTime<Utc>>

Get the last update time of the manager state.

§Returns

An Option containing the DateTime of the last update, or None if never updated.

Source

pub fn clear_proxies(&mut self)

Clear all proxies from the manager.

This removes all proxies from the manager but keeps the sources.

Source

pub fn clear_sources(&mut self)

Clear all sources from the manager.

This removes all sources from the manager but keeps the proxies.

Source

pub async fn check_all_proxies( &mut self, proxies: &mut [Proxy], concurrency: usize, ) -> ManagerResult<()>

Check all proxies in parallel.

This method is useful for bulk verification of proxies, using concurrent processing for efficiency.

§Arguments
  • proxies - A mutable slice of proxies to verify
  • concurrency - The maximum number of concurrent verification operations
§Returns

Ok(()) if the verification process completes.

§Errors

Returns an error if there’s a critical failure in the verification process.

§Panics

Panics if init_judge() has been called successfully but the internal judge is still None, which should never happen in practice.

Source

pub async fn enrich_all_proxies( &mut self, proxies: &mut [Proxy], concurrency: usize, ) -> ManagerResult<()>

Enrich all proxies with IP metadata in parallel.

This method is useful for bulk enrichment of proxies, using concurrent processing for efficiency.

§Arguments
  • proxies - A mutable slice of proxies to enrich
  • concurrency - The maximum number of concurrent enrichment operations
§Returns

Ok(()) if the enrichment process completes.

§Errors

Returns an error if there’s a critical failure in the enrichment process.

§Panics

Panics if init_sleuth() has been called successfully but the internal sleuth is still None, which should never happen in practice.

Source

pub async fn fetch_from_all_sources( &mut self, concurrency: usize, ) -> ManagerResult<()>

Fetch proxies from all active sources in parallel.

This method scrapes proxies from all active sources concurrently, handles errors gracefully, and filters out inactive or blacklisted sources.

§Arguments
  • concurrency - The maximum number of concurrent fetch operations
§Returns

Ok(()) if the fetch process completes.

§Errors

Returns an error if there’s a critical failure in the fetch process.

Source

pub fn get_best_proxies(&self, count: usize) -> Vec<&Proxy>

Get the best proxies based on latency and success rate.

This method selects the most reliable proxies based on their success rate and latency. It’s useful for getting a set of high-quality proxies for critical tasks.

§Arguments
  • count - The maximum number of proxies to return
§Returns

A vector containing references to the best proxies, ordered by quality.

§Examples
// Get the 5 best proxies for an important task
let best_proxies = manager.get_best_proxies(5);

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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: Sized + 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: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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