pub struct AddrPolicy {
rules: Vec<AddrPolicyRule>,
}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 *:*Fields§
§rules: Vec<AddrPolicyRule>A list of rules to apply to find out whether an address is contained by this policy.
The rules apply in order; the first one to match determines whether the address is accepted or rejected.
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 (const: unstable) · 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
Source§impl NetdocParseableFields for AddrPolicy
impl NetdocParseableFields for AddrPolicy
Source§type Accumulator = AddrPolicy
type Accumulator = AddrPolicy
Source§fn is_item_keyword(kw: KeywordRef<'_>) -> bool
fn is_item_keyword(kw: KeywordRef<'_>) -> bool
Source§fn accumulate_item(
acc: &mut Self::Accumulator,
item: UnparsedItem<'_>,
) -> Result<(), EP>
fn accumulate_item( acc: &mut Self::Accumulator, item: UnparsedItem<'_>, ) -> Result<(), EP>
Source§impl PartialEq for AddrPolicy
impl PartialEq for AddrPolicy
Source§fn eq(&self, other: &AddrPolicy) -> bool
fn eq(&self, other: &AddrPolicy) -> bool
self and other values to be equal, and is used by ==.impl Eq for AddrPolicy
impl StructuralPartialEq for 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 UnsafeUnpin for AddrPolicy
impl UnwindSafe for AddrPolicy
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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