refactor(session): separate negotiation from session state
This commit is contained in:
6 files changed
+44
-41
No files matched your search
@@ -12,7 +12,7 @@ use crate::{
|
|||||||
error::ClientError,
|
error::ClientError,
|
||||||
event::{ClientEvent, OpenOutcome},
|
event::{ClientEvent, OpenOutcome},
|
||||||
receive::recv_datagram,
|
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::{connect_udp_socket, resolve_remote, validate_open_timeouts},
|
||||||
socket_options::{apply_dscp_to_socket, clear_dscp_on_socket},
|
socket_options::{apply_dscp_to_socket, clear_dscp_on_socket},
|
||||||
timing::ClientTimestamp,
|
timing::ClientTimestamp,
|
||||||
@@ -20,7 +20,7 @@ use crate::{
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use crate::{
|
use crate::{
|
||||||
runtime::{
|
session::machine::{
|
||||||
compute_one_way, compute_rtt, params_from_config, sequence_is_after, sequence_is_before,
|
compute_one_way, compute_rtt, params_from_config, sequence_is_after, sequence_is_before,
|
||||||
unix_epoch_ns_i64, update_highest_received,
|
unix_epoch_ns_i64, update_highest_received,
|
||||||
},
|
},
|
||||||
@@ -36,7 +36,7 @@ use crate::{
|
|||||||
/// instead.
|
/// instead.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
runtime: SessionRuntime,
|
runtime: SessionMachine,
|
||||||
socket: UdpSocket,
|
socket: UdpSocket,
|
||||||
remote: SocketAddr,
|
remote: SocketAddr,
|
||||||
recv_buffer: Vec<u8>,
|
recv_buffer: Vec<u8>,
|
||||||
@@ -51,7 +51,7 @@ impl Client {
|
|||||||
pub fn connect(config: ClientConfig) -> Result<Self, ClientError> {
|
pub fn connect(config: ClientConfig) -> Result<Self, ClientError> {
|
||||||
validate_open_timeouts(&config.open_timeouts)?;
|
validate_open_timeouts(&config.open_timeouts)?;
|
||||||
let remote = resolve_remote(&config)?;
|
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)?;
|
let socket = connect_udp_socket(&config.socket_config, remote)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ mod managed;
|
|||||||
mod metadata;
|
mod metadata;
|
||||||
mod probe;
|
mod probe;
|
||||||
mod receive;
|
mod receive;
|
||||||
mod runtime;
|
|
||||||
mod session;
|
mod session;
|
||||||
mod socket;
|
mod socket;
|
||||||
mod socket_options;
|
mod socket_options;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use crate::{
|
|||||||
event::{ClientEvent, OpenOutcome},
|
event::{ClientEvent, OpenOutcome},
|
||||||
metadata::ReceiveMeta,
|
metadata::ReceiveMeta,
|
||||||
receive::recv_datagram_from,
|
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::{bind_unconnected_udp_socket, validate_open_timeouts},
|
||||||
socket_options::apply_dscp_to_socket,
|
socket_options::apply_dscp_to_socket,
|
||||||
timing::ClientTimestamp,
|
timing::ClientTimestamp,
|
||||||
@@ -625,7 +625,7 @@ struct TargetState {
|
|||||||
id: TargetId,
|
id: TargetId,
|
||||||
remote: SocketAddr,
|
remote: SocketAddr,
|
||||||
configured_auth: Option<ClientAuthConfig>,
|
configured_auth: Option<ClientAuthConfig>,
|
||||||
runtime: SessionRuntime,
|
runtime: SessionMachine,
|
||||||
status: TargetStatus,
|
status: TargetStatus,
|
||||||
open_packet: Vec<u8>,
|
open_packet: Vec<u8>,
|
||||||
counters: TargetCounters,
|
counters: TargetCounters,
|
||||||
@@ -709,7 +709,7 @@ impl TargetState {
|
|||||||
if let Some(auth) = &target.auth {
|
if let Some(auth) = &target.auth {
|
||||||
config.hmac_key = auth.hmac_key.clone();
|
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()?;
|
let open_packet = runtime.open_packet()?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
id: target.id,
|
id: target.id,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
metadata::ReceiveMeta,
|
metadata::ReceiveMeta,
|
||||||
probe::{CompletedSet, PendingMap, PendingProbe, TimedOutMap},
|
probe::{CompletedSet, PendingMap, PendingProbe, TimedOutMap},
|
||||||
session::{negotiate_params, ActiveSession, ClientPhase, CloseSource, NegotiatedParams},
|
session::{negotiate_params, NegotiatedParams},
|
||||||
timing::ClientTimestamp,
|
timing::ClientTimestamp,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ pub(crate) const MAX_OPEN_PACKET_SIZE: usize = 512;
|
|||||||
const MIN_RECV_BUFFER_SIZE: usize = 2048;
|
const MIN_RECV_BUFFER_SIZE: usize = 2048;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct SessionRuntime {
|
pub(crate) struct SessionMachine {
|
||||||
config: ClientConfig,
|
config: ClientConfig,
|
||||||
remote: std::net::SocketAddr,
|
remote: std::net::SocketAddr,
|
||||||
requested: Params,
|
requested: Params,
|
||||||
@@ -35,6 +35,34 @@ pub(crate) struct SessionRuntime {
|
|||||||
final_packets_sent: u64,
|
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)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub(crate) struct SendProbeResult {
|
pub(crate) struct SendProbeResult {
|
||||||
pub(crate) sent_at: ClientTimestamp,
|
pub(crate) sent_at: ClientTimestamp,
|
||||||
@@ -42,7 +70,7 @@ pub(crate) struct SendProbeResult {
|
|||||||
pub(crate) send_call: Duration,
|
pub(crate) send_call: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SessionRuntime {
|
impl SessionMachine {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
config: ClientConfig,
|
config: ClientConfig,
|
||||||
remote: std::net::SocketAddr,
|
remote: std::net::SocketAddr,
|
||||||
@@ -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 irtt_proto::{Clock, Params, ReceivedStats, StampAt, PROTOCOL_VERSION};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{NegotiationPolicy, MAX_DSCP_CODEPOINT},
|
config::{NegotiationPolicy, MAX_DSCP_CODEPOINT},
|
||||||
error::ClientError,
|
error::ClientError,
|
||||||
probe::{CompletedSet, PendingMap, TimedOutMap},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Protocol parameters accepted for a session.
|
/// 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(
|
pub(crate) fn negotiate_params(
|
||||||
requested: &Params,
|
requested: &Params,
|
||||||
returned: Params,
|
returned: Params,
|
||||||
Reference in new issue
Block a user