summaryrefslogtreecommitdiffstats
path: root/src/swarm/rtt.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/rtt.rs')
-rw-r--r--src/swarm/rtt.rs42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/swarm/rtt.rs b/src/swarm/rtt.rs
index ed6cc73..01d10ee 100644
--- a/src/swarm/rtt.rs
+++ b/src/swarm/rtt.rs
@@ -1,4 +1,4 @@
-//! Round-trip times to peers, measured from traffic we send anyway: PING → PONG and
+//! Round-trip times to peers, measured from traffic we send anyway: STATUS → STATUS_REPLY and
//! HELLO → HELLO_REPLY. No probes of our own.
//!
//! A sample only counts when exactly one request was outstanding: with two, we can't tell
@@ -18,7 +18,7 @@ use tokio::time::Instant;
#[derive(Debug, Default)]
pub(crate) struct RttTable {
- pings: HashMap<String, Outstanding>,
+ statuses: HashMap<String, Outstanding>,
hellos: HashMap<String, Outstanding>,
smoothed: HashMap<String, Sample>,
}
@@ -36,12 +36,12 @@ struct Outstanding {
}
impl RttTable {
- pub(crate) fn ping_sent(&mut self, peer: &str, now: Instant) {
- Self::sent(&mut self.pings, peer, now);
+ pub(crate) fn status_sent(&mut self, peer: &str, now: Instant) {
+ Self::sent(&mut self.statuses, peer, now);
}
- pub(crate) fn pong_received(&mut self, peer: &str, now: Instant) {
- if let Some(sample) = Self::answered(&mut self.pings, peer, now) {
+ pub(crate) fn status_reply_received(&mut self, peer: &str, now: Instant) {
+ if let Some(sample) = Self::answered(&mut self.statuses, peer, now) {
self.record(peer, sample, now);
}
}
@@ -68,7 +68,7 @@ impl RttTable {
.smoothed
.get(peer)
.filter(|sample| now.saturating_duration_since(sample.at) < fresh_for)?;
- let waiting = [self.pings.get(peer), self.hellos.get(peer)]
+ let waiting = [self.statuses.get(peer), self.hellos.get(peer)]
.into_iter()
.flatten()
.map(|outstanding| now.saturating_duration_since(outstanding.sent))
@@ -128,31 +128,31 @@ mod tests {
let mut table = RttTable::default();
let start = Instant::now();
let at = |ms| start + Duration::from_millis(ms);
- table.ping_sent("a", start);
- table.pong_received("a", at(100));
+ table.status_sent("a", start);
+ table.status_reply_received("a", at(100));
assert_eq!(
table.effective("a", at(100), FRESH),
Some(Duration::from_millis(100))
);
- table.ping_sent("a", at(100));
- table.pong_received("a", at(300));
+ table.status_sent("a", at(100));
+ table.status_reply_received("a", at(300));
assert_eq!(
table.effective("a", at(300), FRESH),
Some(Duration::from_millis(125))
);
- // Two PINGs out: the PONG can't be attributed.
- table.ping_sent("a", at(300));
- table.ping_sent("a", at(400));
- table.pong_received("a", at(450));
+ // Two STATUSes out: the STATUS_REPLY can't be attributed.
+ table.status_sent("a", at(300));
+ table.status_sent("a", at(400));
+ table.status_reply_received("a", at(450));
assert_eq!(
table.effective("a", at(450), FRESH),
Some(Duration::from_millis(125))
);
- // An unsolicited PONG changes nothing.
- table.pong_received("b", start);
+ // An unsolicited STATUS_REPLY changes nothing.
+ table.status_reply_received("b", start);
assert_eq!(table.effective("b", start, FRESH), None);
}
@@ -160,12 +160,12 @@ mod tests {
fn unanswered_requests_raise_it_and_old_samples_expire() {
let mut table = RttTable::default();
let start = Instant::now();
- table.ping_sent("a", start);
- table.pong_received("a", start + Duration::from_millis(50));
+ table.status_sent("a", start);
+ table.status_reply_received("a", start + Duration::from_millis(50));
- // A PING unanswered for 40 s: at least 40 s.
+ // A STATUS unanswered for 40 s: at least 40 s.
let sent = start + Duration::from_secs(60);
- table.ping_sent("a", sent);
+ table.status_sent("a", sent);
let later = sent + Duration::from_secs(40);
assert_eq!(
table.effective("a", later, FRESH),