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
impl ProxyManager
Sourcepub fn new() -> ManagerResult<Self>
pub fn new() -> ManagerResult<Self>
Sourcepub fn init_judge(&mut self) -> ManagerResult<()>
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.
Sourcepub fn init_sleuth(&mut self) -> ManagerResult<()>
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.
Sourcepub fn add_proxy(&mut self, proxy: Proxy) -> ManagerResult<bool>
pub fn add_proxy(&mut self, proxy: Proxy) -> ManagerResult<bool>
Sourcepub fn add_proxies(&mut self, proxies: Vec<Proxy>) -> ManagerResult<usize>
pub fn add_proxies(&mut self, proxies: Vec<Proxy>) -> ManagerResult<usize>
Sourcepub fn get_proxy_mut(&mut self, id: &str) -> Option<&mut Proxy>
pub fn get_proxy_mut(&mut self, id: &str) -> Option<&mut Proxy>
Sourcepub fn remove_proxy(&mut self, id: &str) -> Option<Proxy>
pub fn remove_proxy(&mut self, id: &str) -> Option<Proxy>
Sourcepub fn proxy_count(&self) -> usize
pub fn proxy_count(&self) -> usize
Sourcepub fn get_all_proxies(&self) -> Vec<&Proxy>
pub fn get_all_proxies(&self) -> Vec<&Proxy>
Sourcepub fn get_all_proxies_owned(&self) -> Vec<Proxy>
pub fn get_all_proxies_owned(&self) -> Vec<Proxy>
Sourcepub fn filter_proxies<F>(&self, filter_fn: F) -> Vec<&Proxy>
pub fn filter_proxies<F>(&self, filter_fn: F) -> Vec<&Proxy>
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);Sourcepub fn add_source(&mut self, source: Source) -> ManagerResult<bool>
pub fn add_source(&mut self, source: Source) -> ManagerResult<bool>
Sourcepub fn add_sources(&mut self, sources: Vec<Source>) -> ManagerResult<usize>
pub fn add_sources(&mut self, sources: Vec<Source>) -> ManagerResult<usize>
Sourcepub fn get_source(&self, url: &str) -> Option<&Source>
pub fn get_source(&self, url: &str) -> Option<&Source>
Sourcepub fn get_source_mut(&mut self, url: &str) -> Option<&mut Source>
pub fn get_source_mut(&mut self, url: &str) -> Option<&mut Source>
Sourcepub fn remove_source(&mut self, url: &str) -> Option<Source>
pub fn remove_source(&mut self, url: &str) -> Option<Source>
Sourcepub fn source_count(&self) -> usize
pub fn source_count(&self) -> usize
Sourcepub fn get_all_sources(&self) -> Vec<&Source>
pub fn get_all_sources(&self) -> Vec<&Source>
Sourcepub fn get_all_sources_owned(&self) -> Vec<Source>
pub fn get_all_sources_owned(&self) -> Vec<Source>
Sourcepub fn get_proxy_stats(&self) -> ProxyStats
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.
Sourcepub fn get_source_stats(&self) -> SourceStats
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.
Sourcepub async fn check_proxy(&mut self, proxy_id: &str) -> ManagerResult<()>
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
Sourcepub async fn fetch_from_source(
&mut self,
source_url: &str,
) -> ManagerResult<Vec<Proxy>>
pub async fn fetch_from_source( &mut self, source_url: &str, ) -> ManagerResult<Vec<Proxy>>
Sourcepub async fn enrich_proxy(&mut self, proxy_id: &str) -> ManagerResult<()>
pub async fn enrich_proxy(&mut self, proxy_id: &str) -> ManagerResult<()>
Sourcepub fn get_last_update_time(&self) -> Option<DateTime<Utc>>
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.
Sourcepub fn clear_proxies(&mut self)
pub fn clear_proxies(&mut self)
Clear all proxies from the manager.
This removes all proxies from the manager but keeps the sources.
Sourcepub fn clear_sources(&mut self)
pub fn clear_sources(&mut self)
Clear all sources from the manager.
This removes all sources from the manager but keeps the proxies.
Sourcepub async fn check_all_proxies(
&mut self,
proxies: &mut [Proxy],
concurrency: usize,
) -> ManagerResult<()>
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 verifyconcurrency- 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.
Sourcepub async fn enrich_all_proxies(
&mut self,
proxies: &mut [Proxy],
concurrency: usize,
) -> ManagerResult<()>
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 enrichconcurrency- 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.
Sourcepub async fn fetch_from_all_sources(
&mut self,
concurrency: usize,
) -> ManagerResult<()>
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.
Sourcepub fn get_best_proxies(&self, count: usize) -> Vec<&Proxy>
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);