pub struct PortPolicy {
allowed: PortRanges,
}Expand description
A policy to match zero or more TCP/UDP ports.
These are used in Tor to summarize all policies in microdescriptors, and Ipv6 policies in router descriptors.
NOTE: If a port is listed as accepted, it doesn’t mean that the relay allows every address on that port. Instead, a port is listed if a relay will exit to most public addresses on that port. Therefore, unlike super::addrpolicy::AddrPolicy objects, these policies cannot tell you if a port is definitely allowed or rejected: only if it is probably allowed or rejected.
§Examples
use tor_netdoc::types::policy::PortPolicy;
let policy: PortPolicy = "accept 1-1023,8000-8999,60000-65535".parse().unwrap();
assert!(policy.allows_port(22));
assert!(policy.allows_port(8000));
assert!(! policy.allows_port(1024));
assert!(! policy.allows_port(9000));Fields§
§allowed: PortRangesA list of port ranges that this policy allows.
In case we see a reject, we simply invert the policy by the assumption that allows policies take less space than reject ones.
Implementations§
Source§impl PortPolicy
impl PortPolicy
Sourcepub fn new_reject_all() -> Self
pub fn new_reject_all() -> Self
Return a new PortPolicy that rejects all ports.
Sourcepub fn from_allowed_port_list(ports: Vec<u16>) -> Self
pub fn from_allowed_port_list(ports: Vec<u16>) -> Self
Create a PortPolicy from a list of allowed ports. All other ports will be rejected. The ports in the list may be in any order.
Sourcepub fn allows_port(&self, port: u16) -> bool
pub fn allows_port(&self, port: u16) -> bool
Return true iff port is allowed by this policy.
Sourcepub fn intern(self) -> Arc<Self> ⓘ
pub fn intern(self) -> Arc<Self> ⓘ
Replace this PortPolicy with an interned copy, to save memory.
Sourcepub fn allows_some_port(&self) -> bool
pub fn allows_some_port(&self) -> bool
Return true if this policy allows any ports at all.
§Example
use tor_netdoc::types::policy::PortPolicy;
let policy: PortPolicy = "accept 22".parse().unwrap();
assert!(policy.allows_some_port());
let policy2: PortPolicy = "reject 1-65535".parse().unwrap();
assert!(! policy2.allows_some_port());Trait Implementations§
Source§impl Clone for PortPolicy
impl Clone for PortPolicy
Source§fn clone(&self) -> PortPolicy
fn clone(&self) -> PortPolicy
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 PortPolicy
impl Debug for PortPolicy
Source§impl Default for PortPolicy
impl Default for PortPolicy
Source§fn default() -> PortPolicy
fn default() -> PortPolicy
Source§impl Display for PortPolicy
impl Display for PortPolicy
Source§impl FromStr for PortPolicy
impl FromStr for PortPolicy
Source§impl Hash for PortPolicy
impl Hash for PortPolicy
Source§impl ItemValueParseable for PortPolicy
impl ItemValueParseable for PortPolicy
Source§fn from_unparsed(item: UnparsedItem<'_>) -> Result<Self, EP>
fn from_unparsed(item: UnparsedItem<'_>) -> Result<Self, EP>
Source§impl PartialEq for PortPolicy
impl PartialEq for PortPolicy
Source§fn eq(&self, other: &PortPolicy) -> bool
fn eq(&self, other: &PortPolicy) -> bool
self and other values to be equal, and is used by ==.impl Eq for PortPolicy
impl StructuralPartialEq for PortPolicy
Auto Trait Implementations§
impl Freeze for PortPolicy
impl RefUnwindSafe for PortPolicy
impl Send for PortPolicy
impl Sync for PortPolicy
impl Unpin for PortPolicy
impl UnsafeUnpin for PortPolicy
impl UnwindSafe for PortPolicy
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