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

source

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.

source

pub fn allows_sockaddr(&self, addr: &SocketAddr) -> Option<RuleKind>

As allows, but accept a SocketAddr.

source

pub fn new() -> Self

Create a new AddrPolicy that matches nothing.

source

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

source§

fn clone(&self) -> AddrPolicy

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for AddrPolicy

source§

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

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

impl Default for AddrPolicy

source§

fn default() -> AddrPolicy

Returns the “default value” for a type. Read more

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more