pub struct FreshnessPolicy {
pub kind: FreshnessPolicyKind,
pub domain_class_overrides: HashMap<String, DomainClass>,
pub default_max_age_ms: u64,
pub hostile_max_age_ms: u64,
pub authenticated_max_age_ms: u64,
pub sensitive_max_age_ms: u64,
pub signature_required: bool,
}Expand description
Configurable TTL and signature policy for freshness contracts.
The default TTLs are tuned for typical scraping workflows; callers
can override them per-policy via FreshnessPolicy::with_overrides
or per-domain via FreshnessPolicy::with_domain_override.
§Example
use stygian_browser::freshness::{DomainClass, FreshnessPolicy};
use std::time::Duration;
let mut policy = FreshnessPolicy::default();
policy = policy.with_domain_override("accounts.example.com", Some(DomainClass::Sensitive));
assert_eq!(policy.class_for("accounts.example.com"), DomainClass::Sensitive);
assert_eq!(
policy.max_age_for("accounts.example.com"),
Duration::from_millis(policy.max_age_ms_for(DomainClass::Sensitive))
);Fields§
§kind: FreshnessPolicyKindPolicy band for short-circuit classification (logging, telemetry).
domain_class_overrides: HashMap<String, DomainClass>Per-domain class overrides keyed by lowercased host.
default_max_age_ms: u64Default max-age in milliseconds.
hostile_max_age_ms: u64Max-age for DomainClass::Hostile in milliseconds.
authenticated_max_age_ms: u64Max-age for DomainClass::Authenticated in milliseconds.
sensitive_max_age_ms: u64Max-age for DomainClass::Sensitive in milliseconds.
signature_required: boolWhen true, contracts without a signature are rejected
regardless of TTL.
Implementations§
Source§impl FreshnessPolicy
impl FreshnessPolicy
Sourcepub fn with_kind(kind: FreshnessPolicyKind) -> Self
pub fn with_kind(kind: FreshnessPolicyKind) -> Self
Build a policy with explicit kind and default TTLs.
Sourcepub const fn tightened(self, factor: f64) -> Self
pub const fn tightened(self, factor: f64) -> Self
Tighten all TTLs by factor (e.g. 0.5 for half-life).
Sourcepub fn with_domain_override(
self,
host: &str,
class: Option<DomainClass>,
) -> Self
pub fn with_domain_override( self, host: &str, class: Option<DomainClass>, ) -> Self
Override the DomainClass for host.
host is normalised to lower-case ASCII before being inserted.
Pass None to clear an existing override.
Sourcepub fn with_overrides(self, overrides: HashMap<String, DomainClass>) -> Self
pub fn with_overrides(self, overrides: HashMap<String, DomainClass>) -> Self
Replace the full override map at once.
Sourcepub const fn with_signature_required(self, required: bool) -> Self
pub const fn with_signature_required(self, required: bool) -> Self
Set whether contracts without a signature are rejected.
Sourcepub fn class_for(&self, host: &str) -> DomainClass
pub fn class_for(&self, host: &str) -> DomainClass
Resolve the DomainClass for a host.
Lookup walks the override map first, then falls back to
heuristics that recognise well-known challenge issuers
(captcha, challenge, auth, login, accounts,
payment, checkout) as DomainClass::Sensitive.
Sourcepub fn for_domain(&self, host: &str) -> DomainClass
pub fn for_domain(&self, host: &str) -> DomainClass
Convenience wrapper that returns the DomainClass for host
via Self::class_for.
Sourcepub const fn max_age_ms_for(&self, class: DomainClass) -> u64
pub const fn max_age_ms_for(&self, class: DomainClass) -> u64
Max-age in milliseconds for a given class.
Sourcepub fn max_age_for(&self, host: &str) -> Duration
pub fn max_age_for(&self, host: &str) -> Duration
Max-age as a Duration for host.
Sourcepub fn build_contract(
&self,
host: &str,
signature: Option<&str>,
) -> Result<FreshnessContract, FreshnessError>
pub fn build_contract( &self, host: &str, signature: Option<&str>, ) -> Result<FreshnessContract, FreshnessError>
Build a contract for host capturing the current wall-clock
and signature (when known). The max-age is resolved via
Self::max_age_for.
§Errors
Returns FreshnessError::InvalidContract when host is empty
or signature is empty.
Trait Implementations§
Source§impl Clone for FreshnessPolicy
impl Clone for FreshnessPolicy
Source§fn clone(&self) -> FreshnessPolicy
fn clone(&self) -> FreshnessPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more