Struct crab_nat::PortMapping

source ·
pub struct PortMapping {
    pub timeout_config: TimeoutConfig,
    /* private fields */
}
Expand description

A port mapping on the gateway. Should be renewed with .try_renew() and deleted from the gateway with .try_drop().

Fields§

§timeout_config: TimeoutConfig

The configuration of the timing of UDP requests made to the gateway.

Implementations§

source§

impl PortMapping

source

pub async fn new( gateway: IpAddr, client: IpAddr, protocol: InternetProtocol, internal_port: NonZeroU16, mapping_options: PortMappingOptions ) -> Result<PortMapping, MappingFailure>

Attempts to map a port on the gateway using PCP first and falling back to NAT-PMP. Will request to use the given external port if specified, otherwise it will let the gateway choose. If no lifetime is specified, the NAT-PMP recommended lifetime of two hours will be used.

§Errors

Returns a MappingFailure enum which decomposes into NatPmp(natpmp::Failure) and Pcp(pcp::Failure) depending on which failed. Will never return Pcp(pcp::Failure::ResultCode(pcp::ResultCode::UnsupportedVersion)) because NAT-PMP will be used as a fallback in this case. If a different Pcp(_) error is returned, then NAT-PMP is likely not supported by the gateway and this call will not attempt it. If you want to still attempt NAT-PMP after PCP fails for unknown reasons, you can call natpmp::try_port_mapping(..) directly.

source

pub async fn try_renew(&mut self) -> Result<(), MappingFailure>

Attempts to renew this port mapping on the gateway, otherwise returns an error.

§Errors

Returns a MappingFailure enum which decomposes into NatPmp(natpmp::Failure) and Pcp(pcp::Failure) depending on which protocol was used to create the mapping.

source

pub async fn try_drop(self) -> Result<(), (MappingFailure, Self)>

Attempts to safely delete this port mapping on the gateway, otherwise returns an error and the PortMapping back.

§Errors

Returns a MappingFailure enum which decomposes into NatPmp(natpmp::Failure) and Pcp(pcp::Failure) depending on which protocol was used to create the mapping.

source

pub fn gateway(&self) -> IpAddr

The address of the gateway the mapping is registered with.

source

pub fn protocol(&self) -> InternetProtocol

The protocol the mapping is for.

source

pub fn internal_port(&self) -> NonZeroU16

The internal/local port of the port mapping.

source

pub fn external_port(&self) -> NonZeroU16

The external port of the port mapping.

source

pub fn lifetime(&self) -> u32

The lifetime of the port mapping in seconds.

source

pub fn expiration(&self) -> Instant

The datetime the port mapping is set to expire at, using this machine’s clock.

source

pub fn gateway_epoch(&self) -> u32

The gateway epoch time when the port mapping was created.

source

pub fn mapping_type(&self) -> PortMappingType

The type of mapping protocol used, as well as any protocol specific parameters.

Trait Implementations§

source§

impl Clone for PortMapping

source§

fn clone(&self) -> PortMapping

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 PortMapping

source§

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

Formats the value using the given formatter. 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.

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

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

source§

fn vzip(self) -> V