Skip to content

Commit a0c876d

Browse files
refactor(iroh): simplify probeplan
1 parent b79b26e commit a0c876d

1 file changed

Lines changed: 15 additions & 34 deletions

File tree

iroh/src/net_report/probes.rs

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,6 @@ impl ProbeSet {
119119
}
120120
}
121121

122-
impl fmt::Display for ProbeSet {
123-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
124-
writeln!(f, r#"ProbeSet("{}") {{"#, self.proto)?;
125-
for (delay, node) in self.probes.iter() {
126-
writeln!(f, " {delay:?} to {node},")?;
127-
}
128-
writeln!(f, "}}")
129-
}
130-
}
131-
132122
/// A probe plan.
133123
///
134124
/// A probe plan contains a number of [`ProbeSet`]s containing probes to be executed.
@@ -142,7 +132,6 @@ impl fmt::Display for ProbeSet {
142132
#[derive(Debug, PartialEq, Eq)]
143133
pub(super) struct ProbePlan {
144134
set: BTreeSet<ProbeSet>,
145-
protocols: BTreeSet<Probe>,
146135
}
147136

148137
impl ProbePlan {
@@ -154,8 +143,7 @@ impl ProbePlan {
154143
if_state: &super::IfStateDetails,
155144
) -> Self {
156145
let mut plan = Self {
157-
set: BTreeSet::new(),
158-
protocols: protocols.clone(),
146+
set: Default::default(),
159147
};
160148

161149
// The first time we need add probes after the STUN we record this delay, so that
@@ -176,8 +164,8 @@ impl ProbePlan {
176164
quic_ipv6_probes.push(delay, relay_node.clone());
177165
}
178166
}
179-
plan.add_if_enabled(quic_ipv4_probes);
180-
plan.add_if_enabled(quic_ipv6_probes);
167+
plan.add_if_enabled(protocols, quic_ipv4_probes);
168+
plan.add_if_enabled(protocols, quic_ipv6_probes);
181169

182170
// The HTTP probes only start after the QUAD probes have had a chance.
183171
let mut https_probes = ProbeSet::new(Probe::Https);
@@ -194,7 +182,7 @@ impl ProbePlan {
194182
https_probes.push(delay, relay_node.clone());
195183
}
196184

197-
plan.add_if_enabled(https_probes);
185+
plan.add_if_enabled(protocols, https_probes);
198186
}
199187
plan
200188
}
@@ -205,8 +193,7 @@ impl ProbePlan {
205193
#[cfg(wasm_browser)]
206194
pub(super) fn initial(relay_map: &RelayMap, protocols: &BTreeSet<Probe>) -> Self {
207195
let mut plan = Self {
208-
set: BTreeSet::new(),
209-
protocols: protocols.clone(),
196+
set: Default::default(),
210197
};
211198

212199
for relay_node in relay_map.nodes() {
@@ -217,7 +204,7 @@ impl ProbePlan {
217204
https_probes.push(delay, relay_node.clone());
218205
}
219206

220-
plan.add_if_enabled(https_probes);
207+
plan.add_if_enabled(protocols, https_probes);
221208
}
222209
plan
223210
}
@@ -237,7 +224,6 @@ impl ProbePlan {
237224
}
238225
let mut plan = Self {
239226
set: Default::default(),
240-
protocols: protocols.clone(),
241227
};
242228

243229
// The first time we need to add probes after the STUN we record this delay, so that
@@ -298,8 +284,8 @@ impl ProbePlan {
298284
quic_ipv6_probes.push(delay, relay_node.clone());
299285
}
300286
}
301-
plan.add_if_enabled(quic_ipv4_probes);
302-
plan.add_if_enabled(quic_ipv6_probes);
287+
plan.add_if_enabled(protocols, quic_ipv4_probes);
288+
plan.add_if_enabled(protocols, quic_ipv6_probes);
303289

304290
// The HTTP and ICMP probes only start after the STUN probes have had a chance.
305291
let mut https_probes = ProbeSet::new(Probe::Https);
@@ -311,7 +297,7 @@ impl ProbePlan {
311297
https_probes.push(delay, relay_node.clone());
312298
}
313299

314-
plan.add_if_enabled(https_probes);
300+
plan.add_if_enabled(protocols, https_probes);
315301
}
316302
plan
317303
}
@@ -327,7 +313,6 @@ impl ProbePlan {
327313
}
328314
let mut plan = Self {
329315
set: Default::default(),
330-
protocols: protocols.clone(),
331316
};
332317

333318
let sorted_relays = sort_relays(relay_map, last_report);
@@ -360,7 +345,7 @@ impl ProbePlan {
360345
https_probes.push(delay, relay_node.clone());
361346
}
362347

363-
plan.add_if_enabled(https_probes);
348+
plan.add_if_enabled(protocols, https_probes);
364349
}
365350
plan
366351
}
@@ -372,8 +357,8 @@ impl ProbePlan {
372357

373358
/// Adds a [`ProbeSet`] if it contains probes and the protocol indicated in
374359
/// the [`ProbeSet] matches a protocol in our set of [`Probe`]s.
375-
fn add_if_enabled(&mut self, set: ProbeSet) {
376-
if !set.is_empty() && self.protocols.contains(&set.proto) {
360+
fn add_if_enabled(&mut self, protocols: &BTreeSet<Probe>, set: ProbeSet) {
361+
if !set.is_empty() && protocols.contains(&set.proto) {
377362
self.set.insert(set);
378363
}
379364
}
@@ -412,7 +397,6 @@ impl FromIterator<ProbeSet> for ProbePlan {
412397
fn from_iter<T: IntoIterator<Item = ProbeSet>>(iter: T) -> Self {
413398
Self {
414399
set: iter.into_iter().collect(),
415-
protocols: BTreeSet::new(),
416400
}
417401
}
418402
}
@@ -486,7 +470,7 @@ mod tests {
486470
let if_state = IfStateDetails::fake();
487471
let plan = ProbePlan::initial(&relay_map, &default_protocols(), &if_state);
488472

489-
let mut expected_plan: ProbePlan = [
473+
let expected_plan: ProbePlan = [
490474
probeset! {
491475
proto: Probe::QadIpv4,
492476
relay: relay_node_1.clone(),
@@ -532,7 +516,6 @@ mod tests {
532516
]
533517
.into_iter()
534518
.collect();
535-
expected_plan.protocols = default_protocols();
536519

537520
println!("expected:");
538521
println!("{expected_plan}");
@@ -552,7 +535,7 @@ mod tests {
552535
let if_state = IfStateDetails::fake();
553536
let plan = ProbePlan::initial(&relay_map, &BTreeSet::from([Probe::Https]), &if_state);
554537

555-
let mut expected_plan: ProbePlan = [
538+
let expected_plan: ProbePlan = [
556539
probeset! {
557540
proto: Probe::Https,
558541
relay: relay_node_1.clone(),
@@ -570,7 +553,6 @@ mod tests {
570553
]
571554
.into_iter()
572555
.collect();
573-
expected_plan.protocols = BTreeSet::from([Probe::Https]);
574556

575557
println!("expected:");
576558
println!("{expected_plan}");
@@ -625,7 +607,7 @@ mod tests {
625607
&default_protocols(),
626608
&if_state,
627609
);
628-
let mut expected_plan: ProbePlan = [
610+
let expected_plan: ProbePlan = [
629611
probeset! {
630612
proto: Probe::QadIpv4,
631613
relay: relay_node_1.clone(),
@@ -671,7 +653,6 @@ mod tests {
671653
]
672654
.into_iter()
673655
.collect();
674-
expected_plan.protocols = default_protocols();
675656

676657
println!("{} round", i);
677658
println!("expected:");

0 commit comments

Comments
 (0)