fn query_peers_concurrently<'a>(
peers: &'a [LanInstance],
agent_id: &'a str,
http: &'a Client,
) -> FuturesUnordered<impl Future<Output = (String, String, Result<Response, Error>)> + 'a>Expand description
Query EVERY eligible LAN peer concurrently for agent_id, yielding results
as they arrive.
Replaces the sequential for peer in &peers { … .await } both lookups used
to run. That loop cost up to LAN_PEER_QUERY_TIMEOUT_SECS × peer_count
before a message could be delivered — 10s across five peers — and the
pathological ordering (a dead or slow peer ahead of the right one) is the
common case on a laptop network where stale peers linger until their mDNS
TTL expires. Fanning out makes the worst case ~one timeout regardless of
peer count.
Returns a stream so each caller keeps its OWN acceptance rule: find_agent
accepts any 2xx, while find_agent_lan_pubkey must keep trying after a 2xx
whose body carries no lan_public_key (that peer hosts the agent but hasn’t
minted a key). A shared “first success wins” helper could not express both.
Dropping the returned stream cancels every still-in-flight request —
so a caller that breaks on the first acceptable answer stops paying for
the rest, rather than merely ignoring them.