pub struct ProxyPool { /* private fields */ }Expand description
An advanced proxy pool that measures latency, removes dead proxies, and sorts proxies by response time in ascending order.
Implementations§
Source§impl ProxyPool
impl ProxyPool
Sourcepub fn new<T: IntoIterator<Item = impl AsRef<str>>>(url: T) -> Self
pub fn new<T: IntoIterator<Item = impl AsRef<str>>>(url: T) -> Self
Create a new LatencyProxyPool from a list of proxy URLs.
Sourcepub fn code_range(self, code_range: Range<u16>) -> Self
pub fn code_range(self, code_range: Range<u16>) -> Self
Set the range of HTTP status codes that are considered successful.
Sourcepub fn test_url(self, test_url: String) -> Self
pub fn test_url(self, test_url: String) -> Self
Set the URL used for testing proxy connectivity.
Sourcepub fn max_check_concurrency(self, max_check_concurrency: usize) -> Self
pub fn max_check_concurrency(self, max_check_concurrency: usize) -> Self
Set the maximum number of concurrent proxy checks during health validation.
Sourcepub async fn available_count(&self) -> usize
pub async fn available_count(&self) -> usize
Get the number of currently available (healthy) proxies.
Sourcepub async fn extend<T: IntoIterator<Item = impl AsRef<str>>>(&self, urls: T)
pub async fn extend<T: IntoIterator<Item = impl AsRef<str>>>(&self, urls: T)
Add new proxies to the pool without performing immediate validation.
New entries are appended, the cursor is reset, and the available count is updated.
Validation occurs on the next check() call.
Sourcepub async fn extend_check<T: IntoIterator<Item = impl AsRef<str>>>(
&self,
url: T,
retry_count: usize,
) -> Result<()>
pub async fn extend_check<T: IntoIterator<Item = impl AsRef<str>>>( &self, url: T, retry_count: usize, ) -> Result<()>
Add new proxies and immediately perform connectivity and latency checks.
Proxies are validated, failed ones are removed, and remaining entries are sorted by latency (ascending).
Sourcepub async fn check(&self, retry_count: usize) -> Result<()>
pub async fn check(&self, retry_count: usize) -> Result<()>
Validate all proxies, remove dead ones, and sort by latency.
Sourcepub async fn spawn_check(
&self,
check_interval: Duration,
retry_count: usize,
) -> Result<JoinHandle<()>>
pub async fn spawn_check( &self, check_interval: Duration, retry_count: usize, ) -> Result<JoinHandle<()>>
Spawn a background task to periodically validate proxies and update order by latency.
Returns a JoinHandle to allow cancellation or awaiting of the task.
Sourcepub async fn spawn_check_callback<F, R>(
&self,
check_interval: Duration,
retry_count: usize,
callback: F,
) -> Result<JoinHandle<Result<()>>>
pub async fn spawn_check_callback<F, R>( &self, check_interval: Duration, retry_count: usize, callback: F, ) -> Result<JoinHandle<Result<()>>>
Spawn a background task with a callback after each check.