pub struct CoherencePolicy { /* private fields */ }Expand description
Policy configuring how [crate::manager::ProxyManager::acquire_proxy_with_coherence]
reacts to a CoherenceVerdict::Mismatch.
The default CoherencePolicy::advisory policy never blocks; every
mismatch is logged and the proxy is returned. Operators opt into
blocking via CoherencePolicy::hard_fail_on or the
CoherencePolicy::with_hard_fail builder step.
Implementations§
Source§impl CoherencePolicy
impl CoherencePolicy
Sourcepub const fn advisory() -> Self
pub const fn advisory() -> Self
Advisory-only policy: every mismatch is logged, none block.
§Example
use stygian_proxy::ports::coherence::{CoherencePolicy, MismatchField};
let policy = CoherencePolicy::advisory();
assert!(!policy.is_hard_fail(MismatchField::ProxyGeoVsDns));
assert!(policy.is_advisory_only());Sourcepub fn hard_fail_on(field: MismatchField) -> Self
pub fn hard_fail_on(field: MismatchField) -> Self
Build a policy that fails on a single hard-mismatch field.
§Example
use stygian_proxy::ports::coherence::{CoherencePolicy, MismatchField, MismatchSeverity};
let policy = CoherencePolicy::hard_fail_on(MismatchField::WebRtcPublicIp);
assert!(policy.is_hard_fail(MismatchField::WebRtcPublicIp));
assert_eq!(policy.severity(MismatchField::WebRtcPublicIp), MismatchSeverity::Hard);
assert!(!policy.is_hard_fail(MismatchField::Timezone));Sourcepub fn with_hard_fail(self, field: MismatchField) -> Self
pub fn with_hard_fail(self, field: MismatchField) -> Self
Builder step: register an additional hard-fail field.
§Example
use stygian_proxy::ports::coherence::{CoherencePolicy, MismatchField};
let policy = CoherencePolicy::advisory()
.with_hard_fail(MismatchField::ProxyGeoVsDns)
.with_hard_fail(MismatchField::WebRtcPublicIp);
assert!(policy.is_hard_fail(MismatchField::ProxyGeoVsDns));
assert!(policy.is_hard_fail(MismatchField::WebRtcPublicIp));
assert!(!policy.is_hard_fail(MismatchField::Timezone));Sourcepub fn contains(&self, field: MismatchField) -> bool
pub fn contains(&self, field: MismatchField) -> bool
Returns true when field is registered as a hard-fail vector.
§Example
use stygian_proxy::ports::coherence::{CoherencePolicy, MismatchField};
let policy = CoherencePolicy::hard_fail_on(MismatchField::Timezone);
assert!(policy.is_hard_fail(MismatchField::Timezone));
assert!(!policy.is_hard_fail(MismatchField::Locale));Sourcepub fn is_hard_fail(&self, field: MismatchField) -> bool
pub fn is_hard_fail(&self, field: MismatchField) -> bool
Alias for CoherencePolicy::contains matching the
policy.is_hard_fail(field) shape used in the rustdoc examples
above.
Sourcepub fn is_advisory_only(&self) -> bool
pub fn is_advisory_only(&self) -> bool
Returns true when no field is registered for hard-fail.
Sourcepub fn severity(&self, field: MismatchField) -> MismatchSeverity
pub fn severity(&self, field: MismatchField) -> MismatchSeverity
Severity under which the policy blocks a request on field.
Always MismatchSeverity::Hard for registered fields and
MismatchSeverity::Advisory otherwise. Used by the manager
to decide whether a given CoherenceVerdict::Mismatch should
fail the acquisition or just be logged.
Sourcepub fn hard_fail_count(&self) -> usize
pub fn hard_fail_count(&self) -> usize
Number of registered hard-fail fields.
Trait Implementations§
Source§impl Clone for CoherencePolicy
impl Clone for CoherencePolicy
Source§fn clone(&self) -> CoherencePolicy
fn clone(&self) -> CoherencePolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CoherencePolicy
impl Debug for CoherencePolicy
Source§impl Default for CoherencePolicy
impl Default for CoherencePolicy
Source§fn default() -> CoherencePolicy
fn default() -> CoherencePolicy
Source§impl<'de> Deserialize<'de> for CoherencePolicy
impl<'de> Deserialize<'de> for CoherencePolicy
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for CoherencePolicy
Source§impl PartialEq for CoherencePolicy
impl PartialEq for CoherencePolicy
Source§impl Serialize for CoherencePolicy
impl Serialize for CoherencePolicy
impl StructuralPartialEq for CoherencePolicy
Auto Trait Implementations§
impl Freeze for CoherencePolicy
impl RefUnwindSafe for CoherencePolicy
impl Send for CoherencePolicy
impl Sync for CoherencePolicy
impl Unpin for CoherencePolicy
impl UnsafeUnpin for CoherencePolicy
impl UnwindSafe for CoherencePolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.