Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(iroh): Replace timer module with AbortOnDropHandle and sleep #3141

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions iroh/src/magicsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ use crate::{
mod metrics;
mod node_map;
mod relay_actor;
mod timer;
mod udp_conn;

pub use node_map::Source;

pub(super) use self::timer::Timer;
pub use self::{
metrics::Metrics,
node_map::{ConnectionType, ControlMsg, DirectAddrInfo, RemoteInfo},
Expand Down
14 changes: 7 additions & 7 deletions iroh/src/magicsock/node_map/node_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use iroh_relay::protos::stun;
use netwatch::ip::is_unicast_link_local;
use serde::{Deserialize, Serialize};
use tokio::sync::mpsc;
use tokio_util::task::AbortOnDropHandle;
use tracing::{debug, event, info, instrument, trace, warn, Level};

use super::{
Expand All @@ -24,7 +25,7 @@ use super::{
use crate::endpoint::PathSelection;
use crate::{
disco::{self, SendAddr},
magicsock::{ActorMessage, MagicsockMetrics, QuicMappedAddr, Timer, HEARTBEAT_INTERVAL},
magicsock::{ActorMessage, MagicsockMetrics, QuicMappedAddr, HEARTBEAT_INTERVAL},
watchable::{Watchable, Watcher},
};

Expand Down Expand Up @@ -526,19 +527,20 @@ impl NodeState {
}

let id = self.id;
let timer = Timer::after(PING_TIMEOUT_DURATION, async move {
let _expiry_task = AbortOnDropHandle::new(tokio::spawn(async move {
tokio::time::sleep(PING_TIMEOUT_DURATION).await;
sender
.send(ActorMessage::EndpointPingExpired(id, tx_id))
.await
.ok();
});
}));
self.sent_pings.insert(
tx_id,
SentPing {
to,
at: now,
purpose,
timer,
_expiry_task,
},
);
}
Expand Down Expand Up @@ -887,8 +889,6 @@ impl NodeState {
None
}
Some(sp) => {
sp.timer.abort();

let mut node_map_insert = None;

let now = Instant::now();
Expand Down Expand Up @@ -1230,7 +1230,7 @@ pub(super) struct SentPing {
pub(super) at: Instant,
#[allow(dead_code)]
pub(super) purpose: DiscoPingPurpose,
pub(super) timer: Timer,
pub(super) _expiry_task: AbortOnDropHandle<()>,
}

/// The reason why a discovery ping message was sent.
Expand Down
101 changes: 0 additions & 101 deletions iroh/src/magicsock/timer.rs

This file was deleted.

Loading