Skip to content

Commit

Permalink
fix(backend): only update lowest_ttl and round for Awaited and …
Browse files Browse the repository at this point in the history
…`Complete` probes
  • Loading branch information
fujiapple852 committed May 13, 2022
1 parent bc6515e commit 688a8d0
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,11 @@ impl Trace {
}

fn update_from_probe(&mut self, probe: &Probe) {
let index = usize::from(probe.ttl.0) - 1;
if self.lowest_ttl == 0 {
self.lowest_ttl = probe.ttl.0;
} else {
self.lowest_ttl = self.lowest_ttl.min(probe.ttl.0);
}
self.round = self.round.max(probe.round.0);
self.update_lowest_ttl(probe);
self.update_round(probe);
match probe.status {
ProbeStatus::Complete => {
let index = usize::from(probe.ttl.0) - 1;
let hop = &mut self.hops[index];
hop.ttl = probe.ttl.0;
hop.total_sent += 1;
Expand All @@ -102,6 +98,7 @@ impl Trace {
*hop.addrs.entry(host).or_default() += 1;
}
ProbeStatus::Awaited => {
let index = usize::from(probe.ttl.0) - 1;
self.hops[index].total_sent += 1;
self.hops[index].ttl = probe.ttl.0;
self.hops[index].samples.insert(0, Duration::default());
Expand All @@ -112,6 +109,24 @@ impl Trace {
ProbeStatus::NotSent => {}
}
}

/// Update `lowest_ttl` for valid probes.
fn update_lowest_ttl(&mut self, probe: &Probe) {
if matches!(probe.status, ProbeStatus::Awaited | ProbeStatus::Complete) {
if self.lowest_ttl == 0 {
self.lowest_ttl = probe.ttl.0;
} else {
self.lowest_ttl = self.lowest_ttl.min(probe.ttl.0);
}
}
}

/// Update `round` for valid probes.
fn update_round(&mut self, probe: &Probe) {
if matches!(probe.status, ProbeStatus::Awaited | ProbeStatus::Complete) {
self.round = self.round.max(probe.round.0);
}
}
}

/// Information about a single `Hop` within a `Trace`.
Expand Down

0 comments on commit 688a8d0

Please sign in to comment.