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
sourceimpl 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
sourceimpl Clone for AddrPolicy
impl Clone for AddrPolicy
sourcefn clone(&self) -> AddrPolicy
fn clone(&self) -> AddrPolicy
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for AddrPolicy
impl Debug for AddrPolicy
sourceimpl Default for AddrPolicy
impl Default for AddrPolicy
sourcefn default() -> AddrPolicy
fn default() -> AddrPolicy
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl RefUnwindSafe for AddrPolicy
impl Send for AddrPolicy
impl Sync for AddrPolicy
impl Unpin for AddrPolicy
impl UnwindSafe for AddrPolicy
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more