summaryrefslogtreecommitdiffstats
path: root/src/swarm/peer/keepalive.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-28 03:43:37 +0100
committertv <tv@krebsco.de>2026-10-28 03:43:37 +0100
commitff6d98bdd5f921942eb2b37d313d3b9d18acee40 (patch)
treeef98a1542aee821006ece373c1ece536cc0e9596 /src/swarm/peer/keepalive.rs
parent5184885fcec433d636060e5a4e889fa78827dadc (diff)
get swarm RTT from paths
Diffstat (limited to 'src/swarm/peer/keepalive.rs')
-rw-r--r--src/swarm/peer/keepalive.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/swarm/peer/keepalive.rs b/src/swarm/peer/keepalive.rs
index efb8a65..c8a93eb 100644
--- a/src/swarm/peer/keepalive.rs
+++ b/src/swarm/peer/keepalive.rs
@@ -2,7 +2,7 @@
//!
//! A quiet pair's keepalive (`PeerState::take_keepalive_due`) is a PING, answered with a
//! PONG by the peer's paths layer (`transport::paths`), over the same path: it tells both
-//! sides the other is alive, and gives the round trip (`swarm::rtt`). Every `Timing::status_refresh` it is a
+//! sides the other is alive, and measures the path (`swarm::rtt`). Every `Timing::status_refresh` it is a
//! STATUS instead, answered with a STATUS_REPLY: each side's state (heads, readiness,
//! epoch), which also go out as they change (relay announcements, the epoch after a
//! switch, readiness: `announce`). When a STATUS shows our documents differ while sync
@@ -33,18 +33,17 @@ pub(crate) async fn send_status(state: &AppState, peer: &str) -> Result<()> {
.await
}
-/// Sends `peer` a PING, noting it for its round trip.
+/// Sends `peer` a PING (the paths layer measures the path with it).
pub(crate) async fn send_ping(state: &AppState, peer: &str) -> Result<()> {
let nonce = crate::transport::paths::random_nonce();
- state.lock_rtt().ping_sent(peer, nonce, Instant::now());
state
.transport
.send_message(peer, &ParsedMessage::Ping(nonce))
.await
}
-/// A PING or PONG from `peer`: it is alive, and a PONG may answer our PING (its round
-/// trip). A transport without the paths layer (`Transport::answers_pings`: in tests)
+/// A PING or PONG from `peer`: it is alive, and after a PONG the paths layer has a
+/// new round-trip time to it (`swarm::rtt`). A transport without the paths layer (`Transport::answers_pings`: in tests)
/// leaves answering a PING to us. Only peers we know already: a PING makes none.
pub(super) async fn note_alive(state: &AppState, peer: &str, message: &ParsedMessage) {
let now = Instant::now();
@@ -55,7 +54,11 @@ pub(super) async fn note_alive(state: &AppState, peer: &str, message: &ParsedMes
debug!(peer = %peer, error = %format!("{error:#}"), "PONG failed");
}
}
- ParsedMessage::Pong(nonce) => state.lock_rtt().pong_received(peer, *nonce, now),
+ ParsedMessage::Pong(_) => {
+ if let Some(rtt) = state.transport.rtt(peer) {
+ state.lock_rtt().measured(peer, rtt, now);
+ }
+ }
_ => {}
}
let Some(peer_state) = state.get_peer_state(peer).await else {