aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/hop.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/hop.rs')
-rw-r--r--src/swarm/hop.rs25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/swarm/hop.rs b/src/swarm/hop.rs
index 4cd413f..1084ddd 100644
--- a/src/swarm/hop.rs
+++ b/src/swarm/hop.rs
@@ -1,5 +1,6 @@
-//! How long sync messages take from a peer to us, per hop: from the peer's clock when it
-//! generated one (`SyncEnvelope::sent`) to ours when we start handling it, the peer's
+//! How long sync messages (and BLOB messages) take from a peer to us, per hop: from the
+//! peer's clock when it generated one (`SyncEnvelope::sent`, `BlobMessage::sent`) to
+//! ours when we start handling it, the peer's
//! clock offset taken off (`Transport::clock_offset`, from PING and PONG). So the
//! transport, the network and the queues at both ends, which a PING's round trip leaves
//! out (PINGs don't wait behind sync messages).
@@ -61,6 +62,26 @@ impl HopDelays {
}
}
+/// A message from `peer` that it `sent` (its clock) is here: how long it took, recorded
+/// with the peer's hop delays (`PeerState::hop_delays`); None while its clock isn't
+/// known.
+pub(crate) async fn note(
+ state: &crate::state::AppState,
+ peer: &str,
+ sent: crate::clock::UnixMillis,
+) -> Option<i64> {
+ let offset = state.transport.clock_offset(peer)?;
+ let delay = delay_ms(sent, state.clock.now_millis(), offset.offset_ms);
+ if let Some(peer_state) = state.get_peer_state(peer).await {
+ peer_state
+ .lock()
+ .await
+ .hop_delays
+ .record(delay, Instant::now());
+ }
+ Some(delay)
+}
+
/// How long a sync message `sent` by a peer (its clock) took to come, as `arrived` (ours),
/// with the peer's clock `offset_ms` ahead of ours.
pub(crate) fn delay_ms(