Skip to content

Commit

Permalink
quinn-rs#2008: Store negotiated idle_timeout as Duration.
Browse files Browse the repository at this point in the history
  • Loading branch information
mstyura committed Oct 9, 2024
1 parent b02b846 commit ae20c67
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub struct Connection {
/// Whether the idle timer should be reset the next time an ack-eliciting packet is transmitted.
permit_idle_reset: bool,
/// Negotiated idle timeout
idle_timeout: Option<VarInt>,
idle_timeout: Option<Duration>,
timers: TimerTable,
/// Number of packets received which could not be authenticated
authentication_failures: u64,
Expand Down Expand Up @@ -317,7 +317,10 @@ impl Connection {
next_crypto: None,
accepted_0rtt: false,
permit_idle_reset: true,
idle_timeout: config.max_idle_timeout,
idle_timeout: config
.max_idle_timeout
.filter(|dur| dur.0 != 0)
.map(|dur| Duration::from_millis(dur.0)),
timers: TimerTable::default(),
authentication_failures: 0,
error: None,
Expand Down Expand Up @@ -1845,7 +1848,7 @@ impl Connection {
fn reset_idle_timeout(&mut self, now: Instant, space: SpaceId) {
let timeout = match self.idle_timeout {
None => return,
Some(x) => Duration::from_millis(x.0),
Some(dur) => dur,
};
if self.state.is_closed() {
self.timers.stop(Timer::Idle);
Expand Down Expand Up @@ -3774,12 +3777,12 @@ impl SentFrames {
}
}

fn negotiate_max_idle_timeout(x: VarInt, y: VarInt) -> Option<VarInt> {
fn negotiate_max_idle_timeout(x: VarInt, y: VarInt) -> Option<Duration> {
match (x, y) {
(VarInt(0), VarInt(0)) => None,
(VarInt(0), y) => Some(y),
(x, VarInt(0)) => Some(x),
(x, y) => Some(cmp::min(x, y)),
(VarInt(0), y) => Some(Duration::from_millis(y.0)),
(x, VarInt(0)) => Some(Duration::from_millis(x.0)),
(x, y) => Some(Duration::from_millis(cmp::min(x, y).0)),
}
}

Expand All @@ -3791,9 +3794,9 @@ mod tests {
fn negotiate_max_idle_timeout_commutative() {
let test_params = [
(VarInt(0), VarInt(0), None),
(VarInt(2), VarInt(0), Some(VarInt(2))),
(VarInt(0), VarInt(3), Some(VarInt(3))),
(VarInt(1), VarInt(4), Some(VarInt(1))),
(VarInt(2), VarInt(0), Some(Duration::from_millis(2))),
(VarInt(0), VarInt(3), Some(Duration::from_millis(3))),
(VarInt(1), VarInt(4), Some(Duration::from_millis(1))),
];

for (left, right, result) in test_params {
Expand Down

0 comments on commit ae20c67

Please sign in to comment.