Skip to content

Commit

Permalink
feat(report): reworked stream to display ICMP extensions (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Nov 24, 2023
1 parent d434bfa commit 9a8b9b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn run_frontend(
) -> anyhow::Result<()> {
match args.mode {
Mode::Tui => frontend::run_frontend(traces, make_tui_config(args), resolver, geoip_lookup)?,
Mode::Stream => report::stream::report(&traces[0])?,
Mode::Stream => report::stream::report(&traces[0], &resolver)?,
Mode::Csv => report::csv::report(&traces[0], args.report_cycles, &resolver)?,
Mode::Json => report::json::report(&traces[0], args.report_cycles, &resolver)?,
Mode::Pretty => report::table::report_pretty(&traces[0], args.report_cycles, &resolver)?,
Expand Down
37 changes: 16 additions & 21 deletions src/report/stream.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
use crate::backend::trace::Trace;
use crate::report::types::Hop;
use crate::TraceInfo;
use anyhow::anyhow;
use std::thread::sleep;
use trippy::dns::Resolver;

/// Display a continuous stream of trace data.
pub fn report(info: &TraceInfo) -> anyhow::Result<()> {
pub fn report<R: Resolver>(info: &TraceInfo, resolver: &R) -> anyhow::Result<()> {
println!("Tracing to {} ({})", info.target_hostname, info.target_addr);
loop {
let trace_data = &info.data.read().clone();
if let Some(err) = trace_data.error() {
return Err(anyhow!("error: {}", err));
}
for hop in trace_data.hops(Trace::default_flow_id()) {
let ttl = hop.ttl();
let addrs = hop.addrs().collect::<Vec<_>>();
let sent = hop.total_sent();
let recv = hop.total_recv();
let last = hop
.last_ms()
.map(|last| format!("{last:.1}"))
.unwrap_or_default();
let best = hop
.best_ms()
.map(|best| format!("{best:.1}"))
.unwrap_or_default();
let worst = hop
.worst_ms()
.map(|worst| format!("{worst:.1}"))
.unwrap_or_default();
let stddev = hop.stddev_ms();
let avg = hop.avg_ms();
let loss_pct = hop.loss_pct();
let hop = Hop::from((hop, resolver));
let ttl = hop.ttl;
let addrs = hop.hosts.to_string();
let exts = hop.extensions.to_string();
let sent = hop.sent;
let recv = hop.recv;
let last = hop.last;
let best = hop.best;
let worst = hop.worst;
let stddev = hop.stddev;
let avg = hop.avg;
let loss_pct = hop.loss_pct;
println!(
"ttl={ttl} addrs={addrs:?} loss_pct={loss_pct:.1}, sent={sent} recv={recv} last={last} best={best} worst={worst} avg={avg:.1} stddev={stddev:.1}"
"ttl={ttl} addrs={addrs} exts={exts}, loss_pct={loss_pct:.1} sent={sent} recv={recv} last={last:.1} best={best:.1} worst={worst:.1} avg={avg:.1} stddev={stddev:.1}"
);
}
sleep(info.min_round_duration);
Expand Down

0 comments on commit 9a8b9b5

Please sign in to comment.