From 582ee409955cb43e5f1bf903716d27f555e514b0 Mon Sep 17 00:00:00 2001 From: Tim Anglade Date: Sat, 20 Jun 2026 16:17:05 -0700 Subject: [PATCH] connect: document and idiomatize deterministic peer/IP selection Replace .iter().next() with .first() for idiomatic deterministic selection from BTreeSet, and document the selection contract in doc comments on connect_name and connect_imid. The prior code was already deterministic (BTreeSet::iter().next() returns the Ord-minimum), so this is a documentation and idiom cleanup rather than a runtime fix. Refs IM-58. Co-authored-by: openhands --- src/connect.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/connect.rs b/src/connect.rs index e944469..5d8220d 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -97,6 +97,9 @@ impl IntermeshClient { } /// Connect to a mesh name. + /// + /// If the name resolves to multiple IMIDs, an arbitrary but deterministic + /// choice is made (the `Ord`-minimum IMID). pub(crate) async fn connect_name( &mut self, name: &Name, @@ -107,22 +110,23 @@ impl IntermeshClient { .derivation() .name_to_imid .get(name) - .and_then(|s| s.iter().next()) + .and_then(|s| s.first()) .cloned() .ok_or_else(|| anyhow!("failed to resolve name to IMID: {name}"))?; - self.connect_imid(&imid, port).await } /// Connect to an IMID. + /// + /// If the IMID resolves to multiple IPs, an arbitrary but deterministic + /// choice is made (the `Ord`-minimum IP). async fn connect_imid(&mut self, imid: &Imid, port: u16) -> Result> { - // Trust engine is authoritative; bootstrap hint is fallback for bootstrap. let te_ip = self .te .derivation() .imid_to_ip .get(imid) - .and_then(|s| s.iter().next()) + .and_then(|s| s.first()) .copied(); let hint_ip = self .bootstrap_hint