Skip to main content

ProxyManager

Struct ProxyManager 

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

Unified proxy pool orchestrator.

Manage proxies via add_proxy and remove_proxy, acquire one via acquire_proxy, and start background health checking with start.

§Quick start

use std::sync::Arc;
use stygian_proxy::{ProxyManager, ProxyConfig, Proxy, ProxyType};
use stygian_proxy::storage::MemoryProxyStore;

let storage = Arc::new(MemoryProxyStore::default());
let mgr = ProxyManager::with_round_robin(storage, ProxyConfig::default())?;
let (token, _handle) = mgr.start();
let proxy = mgr.add_proxy(Proxy {
    url: "http://proxy.example.com:8080".into(),
    proxy_type: ProxyType::Http,
    username: None,
    password: None,
    weight: 1,
    tags: vec![],
}).await?;
let handle = mgr.acquire_proxy().await?;
handle.mark_success();
token.cancel();

Implementations§

Source§

impl ProxyManager

Source

pub fn builder() -> ProxyManagerBuilder

Source

pub fn with_round_robin( storage: Arc<dyn ProxyStoragePort>, config: ProxyConfig, ) -> ProxyResult<Self>

Convenience: round-robin rotation (default).

Source

pub fn with_random( storage: Arc<dyn ProxyStoragePort>, config: ProxyConfig, ) -> ProxyResult<Self>

Convenience: random rotation.

Source

pub fn with_weighted( storage: Arc<dyn ProxyStoragePort>, config: ProxyConfig, ) -> ProxyResult<Self>

Convenience: weighted rotation.

Source

pub fn with_least_used( storage: Arc<dyn ProxyStoragePort>, config: ProxyConfig, ) -> ProxyResult<Self>

Convenience: least-used rotation.

Source

pub async fn add_proxy(&self, proxy: Proxy) -> ProxyResult<Uuid>

Add a proxy and register a circuit breaker for it. Returns the new ID.

The circuit_breakers write lock is held for the duration of the storage write. This is intentional: acquire_proxy holds a read lock on the same map while it inspects candidates, so it cannot proceed past that point until both the storage record and its CB entry exist. Without this ordering a concurrent acquire_proxy could select the new proxy before its CB was registered, breaking failure accounting.

Source

pub async fn remove_proxy(&self, id: Uuid) -> ProxyResult<()>

Remove a proxy from the pool and drop its circuit breaker.

Source

pub fn start(&self) -> (CancellationToken, JoinHandle<()>)

Spawn the background health-check task.

Returns a (CancellationToken, JoinHandle) pair. Cancel the token to trigger a graceful shutdown; await the handle to ensure it finishes.

Source

pub async fn acquire_proxy(&self) -> ProxyResult<ProxyHandle>

Acquire a proxy from the pool.

Builds ProxyCandidate entries from current storage, consulting the health map and each proxy’s circuit breaker to set the healthy flag. Delegates selection to the configured [RotationStrategy].

Source

pub async fn pool_stats(&self) -> ProxyResult<PoolStats>

Return a health snapshot of the pool.

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