Make session lifecycle state explicit #38

Merged
Lochnair merged 2 commits from refactor/session-machine-state into main 2026-08-03 16:41:59 +00:00
6 changed files with 44 additions and 41 deletions
Showing only changes of commit dc827908d9 - Show all commits

No files matched your search

+4 -4
View File
@@ -12,7 +12,7 @@ use crate::{
error::ClientError,
event::{ClientEvent, OpenOutcome},
receive::recv_datagram,
runtime::{recv_buffer_size, SendProbeResult, SessionRuntime, MAX_OPEN_PACKET_SIZE},
session::machine::{recv_buffer_size, SendProbeResult, SessionMachine, MAX_OPEN_PACKET_SIZE},
socket::{connect_udp_socket, resolve_remote, validate_open_timeouts},
socket_options::{apply_dscp_to_socket, clear_dscp_on_socket},
timing::ClientTimestamp,
@@ -20,7 +20,7 @@ use crate::{
#[cfg(test)]
use crate::{
runtime::{
session::machine::{
compute_one_way, compute_rtt, params_from_config, sequence_is_after, sequence_is_before,
unix_epoch_ns_i64, update_highest_received,
},
@@ -36,7 +36,7 @@ use crate::{
/// instead.
#[derive(Debug)]
pub struct Client {
runtime: SessionRuntime,
runtime: SessionMachine,
socket: UdpSocket,
remote: SocketAddr,
recv_buffer: Vec<u8>,
@@ -51,7 +51,7 @@ impl Client {
pub fn connect(config: ClientConfig) -> Result<Self, ClientError> {
validate_open_timeouts(&config.open_timeouts)?;
let remote = resolve_remote(&config)?;
let runtime = SessionRuntime::new(config.clone(), remote)?;
let runtime = SessionMachine::new(config.clone(), remote)?;
let socket = connect_udp_socket(&config.socket_config, remote)?;
Ok(Self {
-1
View File
@@ -59,7 +59,6 @@ mod managed;
mod metadata;
mod probe;
mod receive;
mod runtime;
mod session;
mod socket;
mod socket_options;
+3 -3
View File
@@ -17,7 +17,7 @@ use crate::{
event::{ClientEvent, OpenOutcome},
metadata::ReceiveMeta,
receive::recv_datagram_from,
runtime::{advance_cadence, params_from_config, SendProbeResult, SessionRuntime},
session::machine::{advance_cadence, params_from_config, SendProbeResult, SessionMachine},
socket::{bind_unconnected_udp_socket, validate_open_timeouts},
socket_options::apply_dscp_to_socket,
timing::ClientTimestamp,
@@ -625,7 +625,7 @@ struct TargetState {
id: TargetId,
remote: SocketAddr,
configured_auth: Option<ClientAuthConfig>,
runtime: SessionRuntime,
runtime: SessionMachine,
status: TargetStatus,
open_packet: Vec<u8>,
counters: TargetCounters,
@@ -709,7 +709,7 @@ impl TargetState {
if let Some(auth) = &target.auth {
config.hmac_key = auth.hmac_key.clone();
}
let runtime = SessionRuntime::new(config, target.remote)?;
let runtime = SessionMachine::new(config, target.remote)?;
let open_packet = runtime.open_packet()?;
Ok(Self {
id: target.id,
@@ -17,7 +17,7 @@ use crate::{
},
metadata::ReceiveMeta,
probe::{CompletedSet, PendingMap, PendingProbe, TimedOutMap},
session::{negotiate_params, ActiveSession, ClientPhase, CloseSource, NegotiatedParams},
session::{negotiate_params, NegotiatedParams},
timing::ClientTimestamp,
};
@@ -25,7 +25,7 @@ pub(crate) const MAX_OPEN_PACKET_SIZE: usize = 512;
const MIN_RECV_BUFFER_SIZE: usize = 2048;
#[derive(Debug)]
pub(crate) struct SessionRuntime {
pub(crate) struct SessionMachine {
config: ClientConfig,
remote: std::net::SocketAddr,
requested: Params,
@@ -35,6 +35,34 @@ pub(crate) struct SessionRuntime {
final_packets_sent: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum ClientPhase {
Connected,
Open { token: u64 },
NoTestCompleted,
Closed { source: CloseSource },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum CloseSource {
Local,
Peer,
}
#[derive(Debug)]
struct ActiveSession {
next_wire_seq: u32,
highest_received_seq: Option<u32>,
packets_sent: u64,
start_mono: Instant,
end_mono: Option<Instant>,
next_send_at: Instant,
pending: PendingMap,
timed_out: TimedOutMap,
completed: CompletedSet,
sending_done: bool,
}
#[derive(Debug, Clone, Copy)]
pub(crate) struct SendProbeResult {
pub(crate) sent_at: ClientTimestamp,
@@ -42,7 +70,7 @@ pub(crate) struct SendProbeResult {
pub(crate) send_call: Duration,
}
impl SessionRuntime {
impl SessionMachine {
pub(crate) fn new(
config: ClientConfig,
remote: std::net::SocketAddr,
+5
View File
@@ -0,0 +1,5 @@
pub(crate) mod machine;
mod negotiation;
pub(crate) use negotiation::negotiate_params;
pub use negotiation::{NegotiatedParams, NegotiationRestriction};
@@ -1,11 +1,10 @@
use std::{fmt, time::Instant};
use std::fmt;
use irtt_proto::{Clock, Params, ReceivedStats, StampAt, PROTOCOL_VERSION};
use crate::{
config::{NegotiationPolicy, MAX_DSCP_CODEPOINT},
error::ClientError,
probe::{CompletedSet, PendingMap, TimedOutMap},
};
/// Protocol parameters accepted for a session.
@@ -156,34 +155,6 @@ impl fmt::Display for NegotiationRestriction {
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum ClientPhase {
Connected,
Open { token: u64 },
NoTestCompleted,
Closed { source: CloseSource },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum CloseSource {
Local,
Peer,
}
#[derive(Debug)]
pub(crate) struct ActiveSession {
pub next_wire_seq: u32,
pub highest_received_seq: Option<u32>,
pub packets_sent: u64,
pub start_mono: Instant,
pub end_mono: Option<Instant>,
pub next_send_at: Instant,
pub pending: PendingMap,
pub timed_out: TimedOutMap,
pub completed: CompletedSet,
pub sending_done: bool,
}
pub(crate) fn negotiate_params(
requested: &Params,
returned: Params,