Crate portmapper
source ·Expand description
Port mapping client and service.
+Crate portmapper
source ·Expand description
Port mapping client and service.
Structs§
- Port mapping client.
- Configures which port mapping protocols are enabled in the
Service. - Enum of metrics for the module
- Output of a port mapping probe.
- A port mapping client.
Struct portmapper::Service
source · pub struct Service { /* private fields */ }Expand description
A port mapping client.
-Trait Implementations§
Auto Trait Implementations§
impl Freeze for Service
impl !RefUnwindSafe for Service
impl Send for Service
impl Sync for Service
impl Unpin for Service
impl !UnwindSafe for Service
Blanket Implementations§
source§impl<T> Any for Twhere
+Service in portmapper - Rust Struct portmapper::Service
source · pub struct Service { /* private fields */ }
Expand description
A port mapping client.
+Trait Implementations§
Auto Trait Implementations§
§impl Freeze for Service
§impl !RefUnwindSafe for Service
§impl Send for Service
§impl Sync for Service
§impl Unpin for Service
§impl !UnwindSafe for Service
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read moresource§impl<T> From<T> for T
source§fn from(t: T) -> T
Returns the argument unchanged.
diff --git a/pr/2877/docs/src/portmapper/lib.rs.html b/pr/2877/docs/src/portmapper/lib.rs.html
index a2aadfed9b..9c18f2a6dc 100644
--- a/pr/2877/docs/src/portmapper/lib.rs.html
+++ b/pr/2877/docs/src/portmapper/lib.rs.html
@@ -713,17 +713,6 @@
713
714
715
-716
-717
-718
-719
-720
-721
-722
-723
-724
-725
-726
//! Port mapping client and service.
use std::{
@@ -978,13 +967,10 @@
inner: (enable_upnp && !upnp).then(|| {
Box::pin(async {
tracing::info!("upnp probe, sleeping");
- tokio::time::timeout(Duration::from_secs(3), async move {
- upnp::probe_available()
- .await
- .map(|addr| (addr, Instant::now()))
- })
- .await
- })
+ upnp::probe_available()
+ .await
+ .map(|addr| (addr, Instant::now()))
+ })
}),
};
@@ -1023,15 +1009,7 @@
tokio::select! {
last_upnp_gateway_addr = &mut upnp_probing_task, if !upnp_done => {
trace!("tick: upnp probe ready");
- match last_upnp_gateway_addr {
- Ok(addr) => {
- probe.last_upnp_gateway_addr = addr;
- }
- Err(_err) => {
- probe.last_upnp_gateway_addr = None;
- tracing::debug!("upnp probe timed out");
- }
- }
+ probe.last_upnp_gateway_addr = last_upnp_gateway_addr;
upnp_done = true;
},
last_nat_pmp = &mut nat_pmp_probing_task, if !nat_pmp_done => {
diff --git a/pr/2877/docs/src/portmapper/upnp.rs.html b/pr/2877/docs/src/portmapper/upnp.rs.html
index 8922ad5dc5..d8679779cc 100644
--- a/pr/2877/docs/src/portmapper/upnp.rs.html
+++ b/pr/2877/docs/src/portmapper/upnp.rs.html
@@ -140,6 +140,21 @@
140
141
142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
use std::{
net::{Ipv4Addr, SocketAddrV4},
num::NonZeroU16,
@@ -191,11 +206,15 @@
let gateway = if let Some(known_gateway) = gateway {
known_gateway
} else {
- aigd::tokio::search_gateway(igd_next::SearchOptions {
- timeout: Some(SEARCH_TIMEOUT),
- ..Default::default()
- })
- .await?
+ // Wrap in manual timeout, because igd_next doesn't respect the set timeout
+ tokio::time::timeout(
+ SEARCH_TIMEOUT,
+ aigd::tokio::search_gateway(igd_next::SearchOptions {
+ timeout: Some(SEARCH_TIMEOUT),
+ ..Default::default()
+ }),
+ )
+ .await??
};
let std::net::IpAddr::V4(external_ip) = gateway.get_external_ip().await? else {
@@ -268,14 +287,25 @@
/// Searches for UPnP gateways.
pub async fn probe_available() -> Option<Gateway> {
inc!(Metrics, upnp_probes);
- match aigd::tokio::search_gateway(igd_next::SearchOptions {
- timeout: Some(SEARCH_TIMEOUT),
- ..Default::default()
- })
- .await
- {
- Ok(gateway) => Some(gateway),
+
+ // Wrap in manual timeout, because igd_next doesn't respect the set timeout
+ let res = tokio::time::timeout(
+ SEARCH_TIMEOUT,
+ aigd::tokio::search_gateway(igd_next::SearchOptions {
+ timeout: Some(SEARCH_TIMEOUT),
+ ..Default::default()
+ }),
+ )
+ .await;
+
+ match res {
+ Ok(Ok(gateway)) => Some(gateway),
Err(e) => {
+ inc!(Metrics, upnp_probes_failed);
+ debug!("upnp probe timed out: {e}");
+ None
+ }
+ Ok(Err(e)) => {
inc!(Metrics, upnp_probes_failed);
debug!("upnp probe failed: {e}");
None
impl<T> Any for Twhere
+Service in portmapper - Rust Struct portmapper::Service
source · pub struct Service { /* private fields */ }
Expand description
A port mapping client.
+Trait Implementations§
Auto Trait Implementations§
§impl Freeze for Service
§impl !RefUnwindSafe for Service
§impl Send for Service
§impl Sync for Service
§impl Unpin for Service
§impl !UnwindSafe for Service
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read moresource§impl<T> From<T> for T
source§fn from(t: T) -> T
Returns the argument unchanged.
diff --git a/pr/2877/docs/src/portmapper/lib.rs.html b/pr/2877/docs/src/portmapper/lib.rs.html
index a2aadfed9b..9c18f2a6dc 100644
--- a/pr/2877/docs/src/portmapper/lib.rs.html
+++ b/pr/2877/docs/src/portmapper/lib.rs.html
@@ -713,17 +713,6 @@
713
714
715
-716
-717
-718
-719
-720
-721
-722
-723
-724
-725
-726
//! Port mapping client and service.
use std::{
@@ -978,13 +967,10 @@
inner: (enable_upnp && !upnp).then(|| {
Box::pin(async {
tracing::info!("upnp probe, sleeping");
- tokio::time::timeout(Duration::from_secs(3), async move {
- upnp::probe_available()
- .await
- .map(|addr| (addr, Instant::now()))
- })
- .await
- })
+ upnp::probe_available()
+ .await
+ .map(|addr| (addr, Instant::now()))
+ })
}),
};
@@ -1023,15 +1009,7 @@
tokio::select! {
last_upnp_gateway_addr = &mut upnp_probing_task, if !upnp_done => {
trace!("tick: upnp probe ready");
- match last_upnp_gateway_addr {
- Ok(addr) => {
- probe.last_upnp_gateway_addr = addr;
- }
- Err(_err) => {
- probe.last_upnp_gateway_addr = None;
- tracing::debug!("upnp probe timed out");
- }
- }
+ probe.last_upnp_gateway_addr = last_upnp_gateway_addr;
upnp_done = true;
},
last_nat_pmp = &mut nat_pmp_probing_task, if !nat_pmp_done => {
diff --git a/pr/2877/docs/src/portmapper/upnp.rs.html b/pr/2877/docs/src/portmapper/upnp.rs.html
index 8922ad5dc5..d8679779cc 100644
--- a/pr/2877/docs/src/portmapper/upnp.rs.html
+++ b/pr/2877/docs/src/portmapper/upnp.rs.html
@@ -140,6 +140,21 @@
140
141
142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
use std::{
net::{Ipv4Addr, SocketAddrV4},
num::NonZeroU16,
@@ -191,11 +206,15 @@
let gateway = if let Some(known_gateway) = gateway {
known_gateway
} else {
- aigd::tokio::search_gateway(igd_next::SearchOptions {
- timeout: Some(SEARCH_TIMEOUT),
- ..Default::default()
- })
- .await?
+ // Wrap in manual timeout, because igd_next doesn't respect the set timeout
+ tokio::time::timeout(
+ SEARCH_TIMEOUT,
+ aigd::tokio::search_gateway(igd_next::SearchOptions {
+ timeout: Some(SEARCH_TIMEOUT),
+ ..Default::default()
+ }),
+ )
+ .await??
};
let std::net::IpAddr::V4(external_ip) = gateway.get_external_ip().await? else {
@@ -268,14 +287,25 @@
/// Searches for UPnP gateways.
pub async fn probe_available() -> Option<Gateway> {
inc!(Metrics, upnp_probes);
- match aigd::tokio::search_gateway(igd_next::SearchOptions {
- timeout: Some(SEARCH_TIMEOUT),
- ..Default::default()
- })
- .await
- {
- Ok(gateway) => Some(gateway),
+
+ // Wrap in manual timeout, because igd_next doesn't respect the set timeout
+ let res = tokio::time::timeout(
+ SEARCH_TIMEOUT,
+ aigd::tokio::search_gateway(igd_next::SearchOptions {
+ timeout: Some(SEARCH_TIMEOUT),
+ ..Default::default()
+ }),
+ )
+ .await;
+
+ match res {
+ Ok(Ok(gateway)) => Some(gateway),
Err(e) => {
+ inc!(Metrics, upnp_probes_failed);
+ debug!("upnp probe timed out: {e}");
+ None
+ }
+ Ok(Err(e)) => {
inc!(Metrics, upnp_probes_failed);
debug!("upnp probe failed: {e}");
None
Struct portmapper::Service
source · pub struct Service { /* private fields */ }Expand description
A port mapping client.
+Trait Implementations§
Auto Trait Implementations§
impl Freeze for Service
impl !RefUnwindSafe for Service
impl Send for Service
impl Sync for Service
impl Unpin for Service
impl !UnwindSafe for Service
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
Mutably borrows from an owned value. Read more
source§impl<T> From<T> for T
impl<T> From<T> for T
source§fn from(t: T) -> T
fn from(t: T) -> T
Returns the argument unchanged.
diff --git a/pr/2877/docs/src/portmapper/lib.rs.html b/pr/2877/docs/src/portmapper/lib.rs.html index a2aadfed9b..9c18f2a6dc 100644 --- a/pr/2877/docs/src/portmapper/lib.rs.html +++ b/pr/2877/docs/src/portmapper/lib.rs.html @@ -713,17 +713,6 @@ 713 714 715 -716 -717 -718 -719 -720 -721 -722 -723 -724 -725 -726//! Port mapping client and service.
use std::{
@@ -978,13 +967,10 @@
inner: (enable_upnp && !upnp).then(|| {
Box::pin(async {
tracing::info!("upnp probe, sleeping");
- tokio::time::timeout(Duration::from_secs(3), async move {
- upnp::probe_available()
- .await
- .map(|addr| (addr, Instant::now()))
- })
- .await
- })
+ upnp::probe_available()
+ .await
+ .map(|addr| (addr, Instant::now()))
+ })
}),
};
@@ -1023,15 +1009,7 @@
tokio::select! {
last_upnp_gateway_addr = &mut upnp_probing_task, if !upnp_done => {
trace!("tick: upnp probe ready");
- match last_upnp_gateway_addr {
- Ok(addr) => {
- probe.last_upnp_gateway_addr = addr;
- }
- Err(_err) => {
- probe.last_upnp_gateway_addr = None;
- tracing::debug!("upnp probe timed out");
- }
- }
+ probe.last_upnp_gateway_addr = last_upnp_gateway_addr;
upnp_done = true;
},
last_nat_pmp = &mut nat_pmp_probing_task, if !nat_pmp_done => {
diff --git a/pr/2877/docs/src/portmapper/upnp.rs.html b/pr/2877/docs/src/portmapper/upnp.rs.html
index 8922ad5dc5..d8679779cc 100644
--- a/pr/2877/docs/src/portmapper/upnp.rs.html
+++ b/pr/2877/docs/src/portmapper/upnp.rs.html
@@ -140,6 +140,21 @@
140
141
142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
use std::{
net::{Ipv4Addr, SocketAddrV4},
num::NonZeroU16,
@@ -191,11 +206,15 @@
let gateway = if let Some(known_gateway) = gateway {
known_gateway
} else {
- aigd::tokio::search_gateway(igd_next::SearchOptions {
- timeout: Some(SEARCH_TIMEOUT),
- ..Default::default()
- })
- .await?
+ // Wrap in manual timeout, because igd_next doesn't respect the set timeout
+ tokio::time::timeout(
+ SEARCH_TIMEOUT,
+ aigd::tokio::search_gateway(igd_next::SearchOptions {
+ timeout: Some(SEARCH_TIMEOUT),
+ ..Default::default()
+ }),
+ )
+ .await??
};
let std::net::IpAddr::V4(external_ip) = gateway.get_external_ip().await? else {
@@ -268,14 +287,25 @@
/// Searches for UPnP gateways.
pub async fn probe_available() -> Option<Gateway> {
inc!(Metrics, upnp_probes);
- match aigd::tokio::search_gateway(igd_next::SearchOptions {
- timeout: Some(SEARCH_TIMEOUT),
- ..Default::default()
- })
- .await
- {
- Ok(gateway) => Some(gateway),
+
+ // Wrap in manual timeout, because igd_next doesn't respect the set timeout
+ let res = tokio::time::timeout(
+ SEARCH_TIMEOUT,
+ aigd::tokio::search_gateway(igd_next::SearchOptions {
+ timeout: Some(SEARCH_TIMEOUT),
+ ..Default::default()
+ }),
+ )
+ .await;
+
+ match res {
+ Ok(Ok(gateway)) => Some(gateway),
Err(e) => {
+ inc!(Metrics, upnp_probes_failed);
+ debug!("upnp probe timed out: {e}");
+ None
+ }
+ Ok(Err(e)) => {
inc!(Metrics, upnp_probes_failed);
debug!("upnp probe failed: {e}");
None