refactor(client): separate accepted negotiation state from peer evidence

This commit is contained in:
Nils Andreas Svee committed 2026-10-04 18:19:28 +07:00
1 parent f62e6a9953
commit d467211f41
32 files changed
+507 -447

No files matched your search

+14 -11
View File
@@ -5,7 +5,7 @@ use std::{
};
use irtt_client::{
ClientEvent, NegotiatedParams, OneWayDelaySample, PacketMeta, ReceivedStatsSample, RttSample,
ClientEvent, NegotiationResult, OneWayDelaySample, PacketMeta, ReceivedStatsSample, RttSample,
ServerTiming, SignedDuration, WarningKind,
};
@@ -234,22 +234,22 @@ enum OutputRow {
impl OutputRow {
fn from_event(event: &ClientEvent) -> Self {
match event {
ClientEvent::SessionStarted {
ClientEvent::SessionStarted(irtt_client::SessionStarted {
remote,
token,
negotiated,
negotiation: negotiated,
at,
} => Self::SessionStarted(LifecycleRow::new(
}) => Self::SessionStarted(LifecycleRow::new(
*remote,
Some(*token),
negotiated,
at.wall,
)),
ClientEvent::NoTestCompleted {
ClientEvent::NoTestCompleted(irtt_client::NoTestCompleted {
remote,
negotiated,
negotiation: negotiated,
at,
} => Self::NoTestCompleted(LifecycleRow::new(*remote, None, negotiated, at.wall)),
}) => Self::NoTestCompleted(LifecycleRow::new(*remote, None, negotiated, at.wall)),
ClientEvent::SessionClosed { remote, token, at } => Self::SessionClosed {
remote: *remote,
token: *token,
@@ -384,16 +384,19 @@ impl LifecycleRow {
fn new(
remote: SocketAddr,
token: Option<u64>,
negotiated: &NegotiatedParams,
negotiated: &NegotiationResult,
event_wall: SystemTime,
) -> Self {
Self {
remote,
token,
event_wall,
duration_ns: i128::from(negotiated.params.duration_ns),
interval_ns: i128::from(negotiated.params.interval_ns),
payload_length: i128::from(negotiated.params.length),
duration_ns: negotiated
.accepted
.duration
.map_or(0, |duration| duration.as_nanos() as i128),
interval_ns: negotiated.accepted.interval.as_nanos() as i128,
payload_length: i128::from(negotiated.accepted.length),
}
}
}
+21 -20
View File
@@ -10,7 +10,7 @@ use crossterm::{
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
use irtt_client::managed::{ManagedTargetEndReason, ManagedTargetOutcome, TargetInstance};
use irtt_client::{ClientEvent, NegotiatedParams, SignedDuration};
use irtt_client::{ClientEvent, NegotiationResult, SignedDuration};
use irtt_stats::{Snapshot, StatsCollector, TimeStats};
use ratatui::{
backend::CrosstermBackend,
@@ -266,12 +266,12 @@ impl TuiState {
};
target.stats.process(event);
match event {
ClientEvent::SessionStarted {
ClientEvent::SessionStarted(irtt_client::SessionStarted {
remote,
token,
negotiated,
negotiation: negotiated,
..
} => {
}) => {
target.remote = Some(remote.to_string());
target.session = Some(format!("{token:#x}"));
target.negotiated = Some(negotiated.clone());
@@ -279,9 +279,11 @@ impl TuiState {
global_status = Some(TuiStatus::Running);
recent = Some(format!("session started token={token:#x}"));
}
ClientEvent::NoTestCompleted {
remote, negotiated, ..
} => {
ClientEvent::NoTestCompleted(irtt_client::NoTestCompleted {
remote,
negotiation: negotiated,
..
}) => {
target.remote = Some(remote.to_string());
target.negotiated = Some(negotiated.clone());
target.status = TargetStatus::NoTest;
@@ -541,7 +543,7 @@ pub(super) struct TuiTargetState {
remote: Option<String>,
session: Option<String>,
status: TargetStatus,
negotiated: Option<NegotiatedParams>,
negotiated: Option<NegotiationResult>,
graph_history: VecDeque<GraphSample>,
last_sample: Option<LastSample>,
last_warning: Option<String>,
@@ -1897,27 +1899,26 @@ fn push_time_line(lines: &mut Vec<Line<'_>>, label: &str, stats: &TimeStats) {
)));
}
fn format_negotiated(negotiated: &NegotiatedParams) -> String {
let params = &negotiated.params;
let duration = if params.duration_ns == 0 {
"-".to_owned()
} else {
format_optional_ns_i128(Some(i128::from(params.duration_ns)))
};
let restrictions = if negotiated.restrictions.is_empty() {
fn format_negotiated(negotiated: &NegotiationResult) -> String {
let params = &negotiated.accepted;
let duration = params.duration.map_or_else(
|| "-".to_owned(),
|duration| format_optional_ns_i128(Some(duration.as_nanos() as i128)),
);
let changes = if negotiated.changes.is_empty() {
"none".to_owned()
} else {
negotiated.restrictions.len().to_string()
negotiated.changes.len().to_string()
};
format!(
"duration={} interval={} length={} clock={:?} timestamps={:?} stats={:?} restrictions={}",
"duration={} interval={} length={} clock={:?} timestamps={:?} stats={:?} changes={}",
duration,
format_optional_ns_i128(Some(i128::from(params.interval_ns))),
format_optional_ns_i128(Some(params.interval.as_nanos() as i128)),
params.length,
params.clock,
params.stamp_at,
params.received_stats,
restrictions
changes
)
}