pub struct AddressPolicy { /* 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(6) PATTERN” or “reject(6) 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.
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 AddressPolicy
impl AddressPolicy
Sourcepub const fn new() -> AddressPolicy
pub const fn new() -> AddressPolicy
Create a new AddressPolicy that matches nothing.
Sourcepub fn new_open() -> AddressPolicy
pub fn new_open() -> AddressPolicy
Create a new AddressPolicy that matches everything.
Sourcepub fn parse_from_torrc<S>(raw: S) -> Result<AddressPolicy, PolicyError>
pub fn parse_from_torrc<S>(raw: S) -> Result<AddressPolicy, PolicyError>
Attempts to parse the AddressPolicy out of raw torrc representation.
Sourcepub fn format_as_torrc(&self) -> String
pub fn format_as_torrc(&self) -> String
Formats the AddressPolicy with torrc representation
Sourcepub fn allows(&self, addr: &IpAddr, port: u16) -> Option<bool>
pub fn allows(&self, addr: &IpAddr, port: u16) -> Option<bool>
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<bool>
pub fn allows_sockaddr(&self, addr: &SocketAddr) -> Option<bool>
As allows, but accept a SocketAddr.
Sourcepub fn push(&mut self, action: AddressPolicyAction, pattern: AddressPortPattern)
pub fn push(&mut self, action: AddressPolicyAction, pattern: AddressPortPattern)
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 AddressPortPattern.
If accept is true, the rule is to accept addresses that match; if accept is false, the rule rejects such addresses.
Sourcepub fn push_rule(&mut self, rule: AddressPolicyRule)
pub fn push_rule(&mut self, rule: AddressPolicyRule)
As push, but accepts a AddressPolicyRule.
Trait Implementations§
Source§impl Clone for AddressPolicy
impl Clone for AddressPolicy
Source§fn clone(&self) -> AddressPolicy
fn clone(&self) -> AddressPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AddressPolicy
impl Debug for AddressPolicy
Source§impl Default for AddressPolicy
impl Default for AddressPolicy
Source§fn default() -> AddressPolicy
fn default() -> AddressPolicy
Source§impl<'de> Deserialize<'de> for AddressPolicy
impl<'de> Deserialize<'de> for AddressPolicy
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<AddressPolicy, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<AddressPolicy, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for AddressPolicy
impl PartialEq for AddressPolicy
Source§impl Serialize for AddressPolicy
impl Serialize for AddressPolicy
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for AddressPolicy
impl StructuralPartialEq for AddressPolicy
Auto Trait Implementations§
impl Freeze for AddressPolicy
impl RefUnwindSafe for AddressPolicy
impl Send for AddressPolicy
impl Sync for AddressPolicy
impl Unpin for AddressPolicy
impl UnwindSafe for AddressPolicy
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,
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<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