mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-21 02:33:23 +00:00
Tweak timer I/O representation
This commit is contained in:
@@ -9,7 +9,9 @@ use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use failure::Error;
|
||||
use quinn_proto::{self as quinn, Config, Directionality, Endpoint, Event, Io, ReadError, Timer};
|
||||
use quinn_proto::{
|
||||
self as quinn, Config, Directionality, Endpoint, Event, Io, ReadError, Timer, TimerUpdate,
|
||||
};
|
||||
use rustls::ProtocolVersion;
|
||||
use slog::{Drain, Logger};
|
||||
|
||||
@@ -159,41 +161,45 @@ impl Context {
|
||||
sent += 1;
|
||||
self.socket.send_to(&packet, destination)?;
|
||||
}
|
||||
Io::TimerStart {
|
||||
Io::TimerUpdate {
|
||||
timer: Timer::LossDetection,
|
||||
time,
|
||||
update: TimerUpdate::Start(time),
|
||||
..
|
||||
} => {
|
||||
self.loss_timer = Some(time);
|
||||
}
|
||||
Io::TimerStart {
|
||||
Io::TimerUpdate {
|
||||
timer: Timer::Close,
|
||||
time,
|
||||
update: TimerUpdate::Start(time),
|
||||
..
|
||||
} => {
|
||||
self.close_timer = Some(time);
|
||||
}
|
||||
Io::TimerStart {
|
||||
Io::TimerUpdate {
|
||||
timer: Timer::Idle,
|
||||
time,
|
||||
update: TimerUpdate::Start(time),
|
||||
..
|
||||
} => {
|
||||
self.idle_timer = Some(time);
|
||||
}
|
||||
Io::TimerStop {
|
||||
Io::TimerUpdate {
|
||||
timer: Timer::LossDetection,
|
||||
update: TimerUpdate::Stop,
|
||||
..
|
||||
} => {
|
||||
self.loss_timer = None;
|
||||
}
|
||||
Io::TimerStop {
|
||||
Io::TimerUpdate {
|
||||
timer: Timer::Close,
|
||||
update: TimerUpdate::Stop,
|
||||
..
|
||||
} => {
|
||||
self.close_timer = None;
|
||||
}
|
||||
Io::TimerStop {
|
||||
timer: Timer::Idle, ..
|
||||
Io::TimerUpdate {
|
||||
timer: Timer::Idle,
|
||||
update: TimerUpdate::Stop,
|
||||
..
|
||||
} => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2792,8 +2792,11 @@ impl IoQueue {
|
||||
}
|
||||
}
|
||||
|
||||
/// Changes to a connection's timers
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum TimerUpdate {
|
||||
/// Set the timer to expire at an a certain point in time, in absolute microseconds
|
||||
Start(u64),
|
||||
/// Cancel time timer if it's currently running
|
||||
Stop,
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ use slog::{self, Logger};
|
||||
use crate::coding::BufMutExt;
|
||||
use crate::connection::{
|
||||
self, handshake_close, ClientConfig, Connection, ConnectionError, ConnectionHandle, State,
|
||||
TimerUpdate,
|
||||
};
|
||||
use crate::crypto::{self, reset_token_for, ConnectError, Crypto, TlsSession, TokenKey};
|
||||
use crate::packet::{
|
||||
@@ -288,20 +289,10 @@ impl Endpoint {
|
||||
ecn,
|
||||
packet,
|
||||
},
|
||||
connection::Io::TimerUpdate {
|
||||
timer,
|
||||
update: connection::TimerUpdate::Stop,
|
||||
} => Io::TimerStop {
|
||||
connection::Io::TimerUpdate { timer, update } => Io::TimerUpdate {
|
||||
connection: conn,
|
||||
timer,
|
||||
},
|
||||
connection::Io::TimerUpdate {
|
||||
timer,
|
||||
update: connection::TimerUpdate::Start(time),
|
||||
} => Io::TimerStart {
|
||||
connection: conn,
|
||||
timer,
|
||||
time,
|
||||
update,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
@@ -733,9 +724,10 @@ impl Endpoint {
|
||||
pub fn timeout(&mut self, now: u64, conn: ConnectionHandle, timer: Timer) {
|
||||
match timer {
|
||||
Timer::Close => {
|
||||
self.ctx.io.push_back(Io::TimerStop {
|
||||
self.ctx.io.push_back(Io::TimerUpdate {
|
||||
connection: conn,
|
||||
timer: Timer::Idle,
|
||||
update: TimerUpdate::Stop,
|
||||
});
|
||||
self.ctx.events.push_back((conn, Event::ConnectionDrained));
|
||||
if self.connections[conn.0].app_closed {
|
||||
@@ -947,16 +939,11 @@ pub enum Io {
|
||||
ecn: Option<EcnCodepoint>,
|
||||
packet: Box<[u8]>,
|
||||
},
|
||||
/// Start or reset a timer
|
||||
TimerStart {
|
||||
connection: ConnectionHandle,
|
||||
timer: Timer,
|
||||
/// Absolute μs
|
||||
time: u64,
|
||||
},
|
||||
TimerStop {
|
||||
/// Start, stop, or reset a timer
|
||||
TimerUpdate {
|
||||
connection: ConnectionHandle,
|
||||
timer: Timer,
|
||||
update: TimerUpdate,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ mod transport_parameters;
|
||||
mod varint;
|
||||
|
||||
mod connection;
|
||||
pub use crate::connection::{ConnectionError, ConnectionHandle};
|
||||
pub use crate::connection::{ConnectionError, ConnectionHandle, TimerUpdate};
|
||||
|
||||
mod crypto;
|
||||
pub use crate::crypto::{ClientConfig, ConnectError, TokenKey};
|
||||
|
||||
+23
-28
@@ -313,19 +313,33 @@ impl TestEndpoint {
|
||||
Io::Transmit { packet, ecn, .. } => {
|
||||
self.outbound.push_back((ecn, packet));
|
||||
}
|
||||
Io::TimerStart {
|
||||
Io::TimerUpdate {
|
||||
timer,
|
||||
time,
|
||||
update,
|
||||
connection,
|
||||
} => {
|
||||
self.conn = Some(connection);
|
||||
trace!(
|
||||
log,
|
||||
"{side:?} {timer:?} start: {dt}",
|
||||
side = self.side,
|
||||
timer = timer,
|
||||
dt = (time - now)
|
||||
);
|
||||
let time = match update {
|
||||
TimerUpdate::Stop => {
|
||||
trace!(
|
||||
log,
|
||||
"{side:?} {timer:?} stop",
|
||||
side = self.side,
|
||||
timer = timer
|
||||
);
|
||||
u64::max_value()
|
||||
}
|
||||
TimerUpdate::Start(time) => {
|
||||
trace!(
|
||||
log,
|
||||
"{side:?} {timer:?} start: {dt}",
|
||||
side = self.side,
|
||||
timer = timer,
|
||||
dt = (time - now)
|
||||
);
|
||||
time
|
||||
}
|
||||
};
|
||||
match timer {
|
||||
Timer::LossDetection => {
|
||||
self.loss = time;
|
||||
@@ -338,25 +352,6 @@ impl TestEndpoint {
|
||||
}
|
||||
}
|
||||
}
|
||||
Io::TimerStop { timer, .. } => {
|
||||
trace!(
|
||||
log,
|
||||
"{side:?} {timer:?} stop",
|
||||
side = self.side,
|
||||
timer = timer
|
||||
);
|
||||
match timer {
|
||||
Timer::LossDetection => {
|
||||
self.loss = u64::max_value();
|
||||
}
|
||||
Timer::Idle => {
|
||||
self.idle = u64::max_value();
|
||||
}
|
||||
Timer::Close => {
|
||||
self.close = u64::max_value();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-5
@@ -802,10 +802,10 @@ impl Future for Driver {
|
||||
endpoint.outgoing.push_front((destination, packet));
|
||||
}
|
||||
}
|
||||
TimerStart {
|
||||
TimerUpdate {
|
||||
connection,
|
||||
timer: timer @ quinn::Timer::Close,
|
||||
time,
|
||||
update: quinn::TimerUpdate::Start(time),
|
||||
} => {
|
||||
let instant = endpoint.epoch + duration_micros(time);
|
||||
endpoint.timers.push(Timer {
|
||||
@@ -815,10 +815,10 @@ impl Future for Driver {
|
||||
cancel: None,
|
||||
});
|
||||
}
|
||||
TimerStart {
|
||||
TimerUpdate {
|
||||
connection,
|
||||
timer,
|
||||
time,
|
||||
update: quinn::TimerUpdate::Start(time),
|
||||
} => {
|
||||
// Loss detection and idle timers start before the connection is established
|
||||
let pending = endpoint
|
||||
@@ -845,7 +845,11 @@ impl Future for Driver {
|
||||
cancel: Some(recv),
|
||||
});
|
||||
}
|
||||
TimerStop { connection, timer } => {
|
||||
TimerUpdate {
|
||||
connection,
|
||||
timer,
|
||||
update: quinn::TimerUpdate::Stop,
|
||||
} => {
|
||||
trace!(endpoint.log, "timer stop"; "timer" => ?timer);
|
||||
// If a connection was lost, we already canceled its loss/idle timers.
|
||||
if let Some(pending) = endpoint.pending.get_mut(&connection) {
|
||||
|
||||
Reference in New Issue
Block a user