Skip to main content

Host

Struct Host 

Source
pub struct Host {
    pub key: HostKey,
    rate_limiter: Option<RateLimiter<NotKeyed, InMemoryState, DefaultClock>>,
    semaphore: Semaphore,
    client: Client,
    stats: Mutex<HostStats>,
    backoff_duration: Mutex<Duration>,
    cache: DashMap<Uri, CacheableResponse>,
}
Expand description

Represents a single host with its own rate limiting, concurrency control, HTTP client configuration, and request cache.

Each host maintains:

  • A token bucket rate limiter using governor
  • A semaphore for concurrency control
  • A dedicated HTTP client with host-specific headers and cookies
  • Statistics tracking for adaptive behavior
  • A per-host cache to prevent duplicate requests

Fields§

§key: HostKey

The hostname this instance manages

§rate_limiter: Option<RateLimiter<NotKeyed, InMemoryState, DefaultClock>>

Rate limiter using token bucket algorithm

§semaphore: Semaphore

Controls maximum concurrent requests to this host

§client: Client

HTTP client configured for this specific host

§stats: Mutex<HostStats>

Request statistics and adaptive behavior tracking

§backoff_duration: Mutex<Duration>

Current backoff duration for adaptive rate limiting

§cache: DashMap<Uri, CacheableResponse>

Per-host cache to prevent duplicate requests during a single link check invocation. Note that this cache has no direct relation to the inter-process persistable crate::CacheStatus.

Implementations§

Source§

impl Host

Source

pub fn new( key: HostKey, host_config: &HostConfig, global_config: &RateLimitConfig, client: ReqwestClient, ) -> Self

Create a new Host instance for the given hostname

Source

fn get_cached_status( &self, uri: &Uri, needs_body: bool, ) -> Option<CacheableResponse>

Check if a URI is cached and returns the cached response if it is valid and satisfies the needs_body requirement.

Source

fn record_cache_hit(&self)

Source

fn record_cache_miss(&self)

Source

fn cache_result(&self, uri: &Uri, response: CacheableResponse)

Cache a request result

Source

pub(crate) async fn execute_request( &self, request: Request, needs_body: bool, ) -> Result<CacheableResponse>

Execute a request with rate limiting, concurrency control, and caching

§Errors

Returns an error if the request fails or rate limiting is exceeded

§Panics

Panics if the statistics mutex is poisoned

Source

pub(crate) const fn get_client(&self) -> &ReqwestClient

Source

async fn perform_request( &self, request: Request, uri: Uri, needs_body: bool, ) -> Result<CacheableResponse>

Source

async fn await_backoff(&self)

Await adaptive backoff if needed

Source

async fn acquire_semaphore(&self) -> SemaphorePermit<'_>

Source

fn update_backoff(&self, status: StatusCode)

Source

fn update_stats(&self, status: StatusCode, request_time: Duration)

Source

fn handle_rate_limit_headers(&self, response: &ReqwestResponse)

Parse rate limit headers from response and adjust behavior

Source

fn handle_common_rate_limit_header_fields(&self, headers: &HeaderMap)

Handle the common “X-RateLimit” header fields.

Source

fn handle_retry_after_header(&self, headers: &HeaderMap)

Handle the “Retry-After” header

Source

fn increase_backoff(&self, increased_backoff: Duration)

Source

pub fn stats(&self) -> HostStats

Get host statistics

§Panics

Panics if the statistics mutex is poisoned

Source

pub(crate) fn record_persistent_cache_hit(&self)

Record a cache hit from the persistent disk cache. Cache misses are tracked internally, so we don’t expose such a method.

Source

pub fn cache_size(&self) -> usize

Get the current cache size (number of cached entries)

Trait Implementations§

Source§

impl Debug for Host

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Host

§

impl !RefUnwindSafe for Host

§

impl Send for Host

§

impl Sync for Host

§

impl Unpin for Host

§

impl UnsafeUnpin for Host

§

impl !UnwindSafe for Host

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

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
§

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> Same for T

Source§

type Output = T

Should always be Self
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.
§

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

§

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