Struct tor_netdoc::types::policy::AddrPolicy
source · pub struct AddrPolicy { /* private fields */ }
Expand description
A sequence of rules that are applied to an address:port until one matches.
Each rule is of the form “accept PATTERN” or “reject PATTERN”, where every pattern describes a set of addresses and ports. Address sets are given as a prefix of 0-128 bits that the address must have; port sets are given as a low-bound and high-bound that the target port might lie between.
Relays use this type for defining their own policies, and for publishing their IPv4 policies. Clients instead use super::portpolicy::PortPolicy objects to view a summary of the relays’ declared policies.
An example IPv4 policy might be:
reject *:25
reject 127.0.0.0/8:*
reject 192.168.0.0/16:*
accept *:80
accept *:443
accept *:9000-65535
reject *:*
Implementations§
source§impl AddrPolicy
impl AddrPolicy
sourcepub fn allows(&self, addr: &IpAddr, port: u16) -> Option<RuleKind>
pub fn allows(&self, addr: &IpAddr, port: u16) -> Option<RuleKind>
Apply this policy to an address:port combination
We do this by applying each rule in sequence, until one matches.
Returns None if no rule matches.
sourcepub fn allows_sockaddr(&self, addr: &SocketAddr) -> Option<RuleKind>
pub fn allows_sockaddr(&self, addr: &SocketAddr) -> Option<RuleKind>
As allows, but accept a SocketAddr.
sourcepub fn push(&mut self, kind: RuleKind, pattern: AddrPortPattern)
pub fn push(&mut self, kind: RuleKind, pattern: AddrPortPattern)
Add a new rule to this policy.
The newly added rule is applied after all previous rules. It matches all addresses and ports covered by AddrPortPattern.
If accept is true, the rule is to accept addresses that match; if accept is false, the rule rejects such addresses.
Trait Implementations§
source§impl Clone for AddrPolicy
impl Clone for AddrPolicy
source§fn clone(&self) -> AddrPolicy
fn clone(&self) -> AddrPolicy
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for AddrPolicy
impl Debug for AddrPolicy
source§impl Default for AddrPolicy
impl Default for AddrPolicy
source§fn default() -> AddrPolicy
fn default() -> AddrPolicy
Auto Trait Implementations§
impl Freeze for AddrPolicy
impl RefUnwindSafe for AddrPolicy
impl Send for AddrPolicy
impl Sync for AddrPolicy
impl Unpin for AddrPolicy
impl UnwindSafe for AddrPolicy
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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