make accounting of sent and lost packets more accurate
diff --git a/src/lib.rs b/src/lib.rs
index a7eb18e..4611b65 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -427,6 +427,9 @@
application_protos: Vec<Vec<u8>>,
+ sent_count: usize,
+ lost_count: usize,
+
rx_data: usize,
max_rx_data: usize,
new_max_rx_data: usize,
@@ -564,6 +567,9 @@
application_protos: config.application_protos.clone(),
+ sent_count: 0,
+ lost_count: 0,
+
rx_data: 0,
max_rx_data: max_rx_data as usize,
new_max_rx_data: max_rx_data as usize,
@@ -1180,6 +1186,11 @@
}
}
+ // Update global lost packets counter. This prevents us from losing
+ // information when the Initial state is dropped.
+ self.lost_count += space.flight.lost_count;
+ space.flight.lost_count = 0;
+
// Calculate available space in the packet based on congestion window.
let mut left = cmp::min(self.recovery.cwnd(), b.cap());
@@ -1466,6 +1477,8 @@
space.next_pkt_num += 1;
+ self.sent_count += 1;
+
// On the client, drop initial state after sending an Handshake packet.
if !self.is_server && hdr.ty == packet::Type::Handshake {
self.drop_initial_state();
@@ -1690,14 +1703,8 @@
/// Collects and returns statistics about the connection.
pub fn stats(&self) -> Stats {
Stats {
- sent: self.initial.flight.total_sent_pkts +
- self.handshake.flight.total_sent_pkts +
- self.application.flight.total_sent_pkts,
-
- lost: self.initial.flight.total_lost_pkts +
- self.handshake.flight.total_lost_pkts +
- self.application.flight.total_lost_pkts,
-
+ sent: self.sent_count,
+ lost: self.lost_count,
rtt: self.recovery.rtt(),
}
}
diff --git a/src/recovery.rs b/src/recovery.rs
index 8f0fe0d..e1cd5bb 100644
--- a/src/recovery.rs
+++ b/src/recovery.rs
@@ -86,8 +86,7 @@
pub lost: Vec<frame::Frame>,
pub acked: Vec<frame::Frame>,
- pub total_sent_pkts: usize,
- pub total_lost_pkts: usize,
+ pub lost_count: usize,
}
impl Default for InFlight {
@@ -97,8 +96,7 @@
lost: Vec::new(),
acked: Vec::new(),
- total_sent_pkts: 0,
- total_lost_pkts: 0,
+ lost_count: 0,
}
}
}
@@ -122,7 +120,7 @@
self.lost.append(&mut p.frames);
}
- self.total_lost_pkts += self.sent.len();
+ self.lost_count += self.sent.len();
self.sent.clear();
@@ -141,7 +139,7 @@
}
}
- self.total_lost_pkts += self.sent.len();
+ self.lost_count += self.sent.len();
self.sent.clear();
@@ -247,8 +245,6 @@
flight.sent.insert(pkt_num, pkt);
- flight.total_sent_pkts += 1;
-
if ack_eliciting {
if is_crypto {
self.time_of_last_sent_crypto_pkt = now;
@@ -526,7 +522,7 @@
for lost in lost_pkt {
let mut p = flight.sent.remove(&lost).unwrap();
- flight.total_lost_pkts += 1;
+ flight.lost_count += 1;
if !p.ack_eliciting {
continue;