Skip to main content

CoherenceContext

Struct CoherenceContext 

Source
pub struct CoherenceContext {
    pub proxy_geo_country: Option<IsoCountry>,
    pub dns_resolver_country: Option<IsoCountry>,
    pub browser_locale: Locale,
    pub browser_timezone: Tz,
    pub accept_language: AcceptLanguage,
    pub webrtc_local_ip: Option<IpAddr>,
    pub webrtc_public_ip: Option<IpAddr>,
    pub proxy_ip: Option<IpAddr>,
}
Expand description

Snapshot of the network-identity vectors that the CoherencePort validates.

The browser (or test harness) builds a CoherenceContext from the live page + the proxy that is about to be used; the port then decides whether the request is safe to send.

proxy_ip is optional because the manager can build the context from the crate::types::Proxy record (which carries url but not the resolved IP) before the proxy is actually contacted; the validator treats a missing proxy_ip as a soft Unknown rather than a hard mismatch so the integration does not require an extra DNS lookup on the hot path.

§Example

use std::net::IpAddr;
use std::str::FromStr;
use stygian_proxy::ports::coherence::{AcceptLanguage, CoherenceContext, IsoCountry, Locale, Tz};

let ctx = CoherenceContext {
    proxy_geo_country: Some(IsoCountry::new("US").unwrap()),
    dns_resolver_country: Some(IsoCountry::new("US").unwrap()),
    browser_locale: Locale::new("en-US").unwrap(),
    browser_timezone: Tz::new("America/New_York").unwrap(),
    accept_language: AcceptLanguage::new("en-US,en;q=0.9").unwrap(),
    webrtc_local_ip: None,
    webrtc_public_ip: Some(IpAddr::from_str("192.0.2.42").unwrap()),
    proxy_ip: Some(IpAddr::from_str("192.0.2.7").unwrap()),
};
assert_eq!(ctx.proxy_geo_country.as_ref().map(IsoCountry::as_str), Some("US"));

Fields§

§proxy_geo_country: Option<IsoCountry>

ISO-3166-1 alpha-2 country of the proxy exit (provider-supplied).

§dns_resolver_country: Option<IsoCountry>

ISO-3166-1 alpha-2 country of the recursive DNS resolver.

§browser_locale: Locale

Browser locale reported by navigator.language.

§browser_timezone: Tz

Browser timezone reported by Intl.DateTimeFormat().resolvedOptions().timeZone.

§accept_language: AcceptLanguage

Accept-Language header value.

§webrtc_local_ip: Option<IpAddr>

WebRTC local (LAN) candidate IP, if the browser exposed one.

§webrtc_public_ip: Option<IpAddr>

WebRTC public (server-reflexive) candidate IP, if the browser exposed one.

§proxy_ip: Option<IpAddr>

Resolved IP of the proxy exit. None skips the WebRTC /16 check.

Implementations§

Source§

impl CoherenceContext

Source

pub fn same_slash_16(a: IpAddr, b: IpAddr) -> Option<bool>

Compute the canonical /16 prefix of an IpAddr.

Returns None for IPv6 addresses (the heuristic is IPv4-only) and for addresses that fall outside the routable unicast space. Used by [crate::adapters::coherence::DefaultCoherenceValidator] for the WebRTC public-IP agreement check.

§Example
use std::net::IpAddr;
use std::str::FromStr;
use stygian_proxy::ports::coherence::CoherenceContext;
let ip = IpAddr::from_str("192.0.2.42").unwrap();
assert_eq!(CoherenceContext::same_slash_16(ip, IpAddr::from_str("192.0.2.7").unwrap()), Some(true));
assert_eq!(CoherenceContext::same_slash_16(ip, IpAddr::from_str("203.0.113.5").unwrap()), Some(false));
Source

pub fn evaluate(&self) -> CoherenceVerdict

Convenience: evaluate this context with no validator wired in.

Without the coherence-validation cargo feature enabled, the ProxyManager has no validator installed and every call returns CoherenceVerdict::Unknown("no_coherence_validator"). External callers that want a no-op verdict should call this method rather than reaching into a private field on the manager.

Trait Implementations§

Source§

impl Clone for CoherenceContext

Source§

fn clone(&self) -> CoherenceContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CoherenceContext

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for CoherenceContext

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for CoherenceContext

Source§

impl PartialEq for CoherenceContext

Source§

fn eq(&self, other: &CoherenceContext) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for CoherenceContext

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for CoherenceContext

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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: Sized + 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: Sized + 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<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