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: LocaleBrowser locale reported by navigator.language.
browser_timezone: TzBrowser timezone reported by Intl.DateTimeFormat().resolvedOptions().timeZone.
accept_language: AcceptLanguageAccept-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
impl CoherenceContext
Sourcepub fn same_slash_16(a: IpAddr, b: IpAddr) -> Option<bool>
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));Sourcepub fn evaluate(&self) -> CoherenceVerdict
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
impl Clone for CoherenceContext
Source§fn clone(&self) -> CoherenceContext
fn clone(&self) -> CoherenceContext
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 CoherenceContext
impl Debug for CoherenceContext
Source§impl<'de> Deserialize<'de> for CoherenceContext
impl<'de> Deserialize<'de> for CoherenceContext
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 CoherenceContext
Source§impl PartialEq for CoherenceContext
impl PartialEq for CoherenceContext
Source§impl Serialize for CoherenceContext
impl Serialize for CoherenceContext
impl StructuralPartialEq for CoherenceContext
Auto Trait Implementations§
impl Freeze for CoherenceContext
impl RefUnwindSafe for CoherenceContext
impl Send for CoherenceContext
impl Sync for CoherenceContext
impl Unpin for CoherenceContext
impl UnsafeUnpin for CoherenceContext
impl UnwindSafe for CoherenceContext
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.