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
impl PortMapping
sourcepub async fn new(
gateway: IpAddr,
client: IpAddr,
protocol: InternetProtocol,
internal_port: NonZeroU16,
mapping_options: PortMappingOptions
) -> Result<PortMapping, MappingFailure>
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.
sourcepub async fn try_renew(&mut self) -> Result<(), MappingFailure>
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.
sourcepub async fn try_drop(self) -> Result<(), (MappingFailure, Self)>
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.
sourcepub fn protocol(&self) -> InternetProtocol
pub fn protocol(&self) -> InternetProtocol
The protocol the mapping is for.
sourcepub fn internal_port(&self) -> NonZeroU16
pub fn internal_port(&self) -> NonZeroU16
The internal/local port of the port mapping.
sourcepub fn external_port(&self) -> NonZeroU16
pub fn external_port(&self) -> NonZeroU16
The external port of the port mapping.
sourcepub fn expiration(&self) -> Instant
pub fn expiration(&self) -> Instant
The datetime the port mapping is set to expire at, using this machine’s clock.
sourcepub fn gateway_epoch(&self) -> u32
pub fn gateway_epoch(&self) -> u32
The gateway epoch time when the port mapping was created.
sourcepub fn mapping_type(&self) -> PortMappingType
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
impl Clone for PortMapping
source§fn clone(&self) -> PortMapping
fn clone(&self) -> PortMapping
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more