Skip to content

Commit

Permalink
remove yet one more unnecesary clone
Browse files Browse the repository at this point in the history
  • Loading branch information
divagant-martian committed Jul 2, 2023
1 parent eaf5ede commit f558246
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
30 changes: 16 additions & 14 deletions iroh-net/src/hp/netcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,17 +536,15 @@ impl ReportState {
mut self,
actor_addr: ActorAddr,
dm: DerpMap,
port_mapper: Option<portmapper::Client>,
skip_external_network: bool,
portmap_probe: Option<oneshot::Receiver<Result<portmapper::ProbeOutput, String>>>,
) -> Result<(Report, DerpMap)> {
debug!(port_mapper = %port_mapper.is_some(), %skip_external_network, "running report");
debug!(portmap_probe = %portmap_probe.is_some(), "running report");
self.report.write().await.os_has_ipv6 = os_has_ipv6().await;

let mut portmap_probe = MaybeFuture::default();
if !skip_external_network {
if let Some(port_mapper) = port_mapper {
portmap_probe.inner = Some(Box::pin(async move {
match port_mapper.probe().await {
let mut portmap_probe = {
let inner = portmap_probe.map(|portmap_probe| {
Box::pin(async move {
match portmap_probe.await {
Ok(Ok(res)) => Some(res),
Ok(Err(err)) => {
warn!("skipping port mapping: {err:?}");
Expand All @@ -557,9 +555,10 @@ impl ReportState {
None
}
}
}));
}
}
})
});
MaybeFuture { inner }
};

self.prepare_hairpin().await;

Expand Down Expand Up @@ -1333,15 +1332,18 @@ impl Actor {
.create_report_state(&derp_map, stun_sock_v4, stun_sock_v6)
.await
.context("failed to create ReportState")?;
let port_mapper = self.port_mapper.clone();
let skip_external = self.skip_external_network;
let portmap_probe = self
.port_mapper
.as_ref()
.filter(|_| !self.skip_external_network)
.map(|port_mapper| port_mapper.probe());
let addr = self.addr();

tokio::spawn(async move {
let _guard = cancel_token.drop_guard();
match time::timeout(
OVERALL_PROBE_TIMEOUT,
report_state.run(addr.clone(), derp_map, port_mapper, skip_external),
report_state.run(addr.clone(), derp_map, portmap_probe),
)
.await
{
Expand Down
4 changes: 1 addition & 3 deletions iroh-net/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ impl CancelOnDrop {
pub fn new(task_name: &'static str, handle: tokio::task::AbortHandle) -> Self {
CancelOnDrop { task_name, handle }
}

pub fn cancel(self) {}
}

impl Drop for CancelOnDrop {
Expand All @@ -61,7 +59,7 @@ pub struct MaybeFuture<T> {
pub inner: Option<T>,
}

// NOTE: explicit implementation to bypass derive unnecessary bounds
// NOTE: explicit implementation to bypass derive's unnecessary bounds
impl<T> Default for MaybeFuture<T> {
fn default() -> Self {
MaybeFuture { inner: None }
Expand Down

0 comments on commit f558246

Please sign in to comment.