ts_runtime/status.rs
1//! Netmap status aggregation, WhoIs lookups, and a netmap-change watcher.
2//!
3//! These surface the internal netmap state ([`ts_control::StateUpdate`], consumed by the
4//! [`PeerTracker`](crate::peer_tracker::PeerTracker)) to embedders, mirroring tsnet's
5//! `LocalClient::Status`, `WhoIs`, and `WatchIPNBus`.
6//!
7//! ## Capability / user / online surfacing (do not fabricate)
8//!
9//! tsnet's `Status`/`WhoIs` also carry per-node *online* state, the owning *user* (login/profile),
10//! and a *capability map*. Status of each in this fork:
11//! - **Capabilities** — surfaced: [`WhoIs::capabilities`] is populated from the domain
12//! [`Node`](ts_control::Node)'s `cap_map` (the control-pushed `CapMap`), which the domain model
13//! retains.
14//! - **User (login/profile)** — surfaced when the netmap provided it: [`WhoIs::user`] is the owning
15//! user's login/display name, resolved by joining the node's owning user id against the netmap's
16//! `UserProfiles` table (accumulated by the [`PeerTracker`](crate::peer_tracker::PeerTracker)
17//! across delta updates). `None` when control sent no profile for that user.
18//! - **Online state** — surfaced: [`StatusNode::online`] / [`StatusNode::last_seen`] reflect the
19//! domain [`Node`](ts_control::Node)'s retained `online`/`last_seen`, populated from the netmap
20//! node and its online deltas (`PeerChange`, `MapResponse.online_change`/`peer_seen_change`).
21//! `online` stays tri-state (`None` = unknown), never fabricated to `false`.
22
23use std::net::{IpAddr, SocketAddr};
24
25use ts_control::{Node, StableNodeId, UserId};
26
27/// A snapshot of the local netmap: this node plus every known peer.
28///
29/// Analogous to tsnet's `ipnstate.Status`. Built by [`Runtime::status`](crate::Runtime::status)
30/// from the self node held by the control runner and the peers held by the peer tracker.
31#[derive(Debug, Clone, PartialEq, Eq)]
32pub struct Status {
33 /// This node, if a netmap has been received from control yet.
34 pub self_node: Option<StatusNode>,
35 /// Every peer currently known in the netmap.
36 pub peers: Vec<StatusNode>,
37 /// The stable id of the exit node traffic is **currently** egressing through, if any (Go's
38 /// `Status.ExitNodeStatus.ID`). This is the *resolved + fail-closed* answer from the route
39 /// updater — `None` when no exit node is configured, the configured selector matches no peer, or
40 /// the matched peer no longer advertises a default route — so it reflects what is actually
41 /// engaged, not merely what [`Config::exit_node`](ts_control::Config) requested. Find the peer's
42 /// details by matching this id against [`peers`](Status::peers).
43 pub active_exit_node: Option<StableNodeId>,
44 /// The tailnet's MagicDNS suffix (e.g. `"tail0123.ts.net"`) — Go `ipnstate.Status.MagicDNSSuffix`.
45 /// Derived (like Go's `NetworkMap.MagicDNSSuffix`) from the self node's FQDN minus its host label,
46 /// **not** from the DNS config and **not** from the tailnet `Domain` name. `None` before the first
47 /// netmap, or when the self FQDN has no tailnet component (a bare hostname).
48 pub magic_dns_suffix: Option<String>,
49}
50
51/// A single node entry in a [`Status`] snapshot.
52///
53/// Analogous to tsnet's `ipnstate.PeerStatus`.
54#[derive(Debug, Clone, PartialEq, Eq)]
55pub struct StatusNode {
56 /// The node's stable id (stable across re-registration).
57 pub stable_id: StableNodeId,
58 /// A display name for the node: its fqdn if a tailnet component is known, else its bare
59 /// hostname.
60 pub display_name: String,
61 /// The node's tailnet IPv4 address.
62 pub ipv4: IpAddr,
63 /// The node's tailnet IPv6 address.
64 pub ipv6: IpAddr,
65 /// Whether the node is online, if known (`ipnstate.PeerStatus.Online`). Tri-state: `Some(true)`
66 /// connected to control, `Some(false)` offline, `None` unknown (control sent no online status or
67 /// the local node lacks permission to know). Reflects control's liveness state, retained from the
68 /// netmap node + its online deltas — `None` is *unknown*, never fabricated to `false`.
69 pub online: Option<bool>,
70 /// When control last saw this node online (`ipnstate.PeerStatus.LastSeen`). Per Go, only
71 /// meaningful while the node is not currently online. `None` when unknown or never seen.
72 pub last_seen: Option<chrono::DateTime<chrono::Utc>>,
73 /// The routes this node accepts traffic for (its own `/32` and `/128`, plus any advertised
74 /// subnet routes and possibly the exit-node default route).
75 pub allowed_routes: Vec<ipnet::IpNet>,
76 /// Whether this node advertises a default route (`0.0.0.0/0` or `::/0`), making it eligible to
77 /// be selected as an exit node.
78 pub is_exit_node: bool,
79 /// The current trusted direct UDP endpoint for this peer, if a direct path is confirmed right now
80 /// (Go `ipnstate.PeerStatus.CurAddr`). `Some` ⇒ traffic to this peer flows directly to this
81 /// address; `None` ⇒ it relays via DERP (see [`relay`](Self::relay)). Mutually exclusive with a
82 /// `relay` for a routed peer, mirroring Go's empty-vs-set `CurAddr`/`Relay` strings. A live
83 /// snapshot — the direct path can expire/re-confirm between calls. Always `None` for the self node
84 /// and a whois lookup (no path to oneself; whois is an ownership query).
85 pub cur_addr: Option<SocketAddr>,
86 /// The DERP region code this peer relays through when there is **no** direct path (Go
87 /// `ipnstate.PeerStatus.Relay`, e.g. `"nyc"`). `Some` ⇔ [`cur_addr`](Self::cur_addr) is `None`
88 /// and the peer's home DERP region is known; `None` when a direct path is confirmed, or the
89 /// region code is unknown. Carries the region **code**, not its numeric id.
90 pub relay: Option<String>,
91}
92
93impl StatusNode {
94 /// Build a [`StatusNode`] from a domain [`Node`].
95 pub fn from_node(node: &Node) -> Self {
96 let is_exit_node = node
97 .accepted_routes
98 .iter()
99 .any(|route| route.prefix_len() == 0);
100
101 Self {
102 stable_id: node.stable_id.clone(),
103 display_name: node
104 .fqdn_opt(false)
105 .unwrap_or_else(|| node.hostname.clone()),
106 ipv4: node.tailnet_address.ipv4.addr().into(),
107 ipv6: node.tailnet_address.ipv6.addr().into(),
108 online: node.online,
109 last_seen: node.last_seen,
110 allowed_routes: node.accepted_routes.clone(),
111 is_exit_node,
112 // A bare `Node` carries no live path state, so connectivity is unknown here. The peer
113 // tracker overwrites these in `status_peers` by joining against the direct manager; the
114 // self node and whois lookups (which also use `from_node`) correctly keep `None`.
115 cur_addr: None,
116 relay: None,
117 }
118 }
119}
120
121/// The result of a [`Runtime::whois`](crate::Runtime::whois) lookup: the node that owns a tailnet
122/// source address, plus its user and capabilities.
123///
124/// Analogous to tsnet's `apitype.WhoIsResponse`.
125#[derive(Debug, Clone, PartialEq, Eq)]
126pub struct WhoIs {
127 /// The node that owns the queried source IP.
128 pub node: Node,
129 /// The login/email of the user that owns the node, if known.
130 ///
131 /// Always `None` in this fork: the domain [`Node`](ts_control::Node) does not retain the
132 /// wire-level user/login mapping (see the module-level capability/user gap note).
133 pub user: Option<String>,
134 /// The node's capability map, as `(capability, args)` pairs.
135 ///
136 /// Populated from the domain [`Node`](ts_control::Node)'s `cap_map` (the control-pushed
137 /// `CapMap`), sorted by capability name (the underlying map is a `BTreeMap`). Empty when control
138 /// granted the node no capabilities. Mirrors tsnet's `WhoIsResponse.CapMap`.
139 pub capabilities: Vec<(String, Vec<String>)>,
140}
141
142impl WhoIs {
143 /// Build a [`WhoIs`] from the owning node and its resolved owner login/display name (if the
144 /// netmap's `UserProfiles` table mapped the node's owning user id to a profile; `None` when
145 /// control sent no profile — e.g. a tagged node with no human owner).
146 ///
147 /// `capabilities` is always populated from the node's `cap_map`.
148 pub(crate) fn from_node_with_user(node: Node, user: Option<String>) -> Self {
149 let capabilities = node
150 .cap_map
151 .iter()
152 .map(|(cap, args)| (cap.clone(), args.clone()))
153 .collect();
154 Self {
155 node,
156 user,
157 capabilities,
158 }
159 }
160}
161
162/// Resolve which node owns a tailnet source address, used by WhoIs.
163pub(crate) fn whois_addr(addr: SocketAddr) -> IpAddr {
164 addr.ip()
165}
166
167/// A measured-latency entry for one DERP region in a [`NetcheckReport`].
168#[derive(Debug, Clone, PartialEq, Eq)]
169pub struct RegionLatency {
170 /// The DERP region id (Go `tailcfg.DERPRegionID`).
171 pub region_id: u32,
172 /// The measured round-trip latency to the region's closest DERP node.
173 pub latency: std::time::Duration,
174}
175
176/// A snapshot of this node's latest network conditions report — the Rust analog of Go's
177/// `netcheck.Report` as `tailscale netcheck` surfaces it.
178///
179/// ## Surfaced subset (do not fabricate)
180/// Go's `netcheck.Report` also carries UDP/IPv4/IPv6 reachability, port-mapping support
181/// (UPnP/PMP/PCP), `MappingVariesByDestIP`, global-address discovery, etc. This fork's net-report
182/// path measures only **DERP-region latency** (the data that drives home-region selection), so the
183/// report carries exactly that — the preferred (lowest-latency) region and the per-region latency
184/// map — rather than inventing fields we never probe. Empty before the first measurement.
185#[derive(Debug, Clone, PartialEq, Eq, Default, kameo::Reply)]
186pub struct NetcheckReport {
187 /// The id of the preferred DERP region — the lowest-latency region this node measured, the one it
188 /// homes to (Go `Report.PreferredDERP`). `None` before the first measurement / when no region
189 /// was reachable.
190 pub preferred_derp: Option<u32>,
191 /// Per-region measured latencies, sorted by latency ascending (Go `Report.RegionLatency`, here as
192 /// an ordered list). The first entry, when present, is the [`preferred_derp`](Self::preferred_derp)
193 /// region.
194 pub region_latencies: Vec<RegionLatency>,
195}
196
197impl NetcheckReport {
198 /// Build a report from the latest DERP-region measurements (the `RegionResult` set the latency
199 /// measurer produces). `results` is expected sorted by latency ascending (the measurer's
200 /// `RegionResult` `Ord` sorts on latency first), so the first entry is the preferred region; we
201 /// do not re-sort beyond trusting that contract for `preferred_derp`, but the list is emitted in
202 /// the order given. An empty `results` yields the default (no preferred region, empty list).
203 pub(crate) fn from_region_results(results: &[ts_netcheck::RegionResult]) -> NetcheckReport {
204 let region_latencies: Vec<RegionLatency> = results
205 .iter()
206 .map(|r| RegionLatency {
207 // `ts_derp::RegionId` is a `NonZeroU32` newtype (its `.0` is the public inner).
208 region_id: r.id.0.get(),
209 latency: r.latency,
210 })
211 .collect();
212 NetcheckReport {
213 preferred_derp: region_latencies.first().map(|r| r.region_id),
214 region_latencies,
215 }
216 }
217}
218
219/// A tailnet peer this node can send a Taildrop file *to*, plus the peerAPI base URL to reach it.
220///
221/// Analogous to tsnet's `apitype.FileTarget`. The set is produced by
222/// [`Runtime::file_targets`](crate::Runtime::file_targets) (exposed as `Device::file_targets`).
223#[derive(Debug, Clone, PartialEq, Eq)]
224pub struct FileTarget {
225 /// The target peer's node record — pass straight to the Taildrop send path
226 /// (`Device::send_file`), which re-derives the same peerAPI address.
227 pub node: Node,
228 /// The `http://ip:port` base URL of the peer's peerAPI, with no trailing path — the exact shape
229 /// of Go's `apitype.FileTarget.PeerAPIURL`. Derived from
230 /// [`Node::peerapi_addr`](ts_control::Node::peerapi_addr).
231 pub peerapi_url: String,
232}
233
234/// Compute the sorted Taildrop send-target list from the peer set, given the local node's owning
235/// user id. The pure core of [`Runtime::file_targets`](crate::Runtime::file_targets) — separated out
236/// so the eligibility + ordering rules are unit-testable without spinning up the actor graph (the
237/// node-level file-sharing gate is applied by the caller before this runs).
238///
239/// A peer is a target when it advertises a reachable peerAPI (Go `PeerAPIBase(p) != ""`) **and** is
240/// either owned by `self_user_id` **or** carries the file-sharing-target capability — Go's two-way
241/// OR. Sorted by MagicDNS name (Go sorts by `Node.Name`), falling back to the bare hostname.
242pub(crate) fn build_file_targets(peers: Vec<Node>, self_user_id: UserId) -> Vec<FileTarget> {
243 let mut targets: Vec<FileTarget> = peers
244 .into_iter()
245 .filter_map(|peer| {
246 // Must advertise a reachable peerAPI (Go `PeerAPIBase(p) != ""`).
247 let addr = peer.peerapi_addr()?;
248 // Same owner OR explicitly an ACL file-sharing target (Go's two-way OR).
249 let eligible = peer.user_id == self_user_id || peer.is_file_sharing_target();
250 if !eligible {
251 return None;
252 }
253 Some(FileTarget {
254 peerapi_url: format!("http://{addr}"),
255 node: peer,
256 })
257 })
258 .collect();
259 // Sort by MagicDNS name (Go sorts by `Node.Name`), bare hostname as the fallback key.
260 targets.sort_by(|a, b| {
261 let name = |t: &FileTarget| {
262 t.node
263 .fqdn_opt(false)
264 .unwrap_or_else(|| t.node.hostname.clone())
265 };
266 name(a).cmp(&name(b))
267 });
268 targets
269}
270
271#[cfg(test)]
272mod tests {
273 use ts_control::{Node, StableNodeId, TailnetAddress};
274
275 use super::*;
276
277 fn node(stable: &str, hostname: &str, tailnet: Option<&str>, ipv4: &str) -> Node {
278 Node {
279 id: 1,
280 stable_id: StableNodeId(stable.to_string()),
281 hostname: hostname.to_string(),
282 user_id: 0,
283 tailnet: tailnet.map(str::to_string),
284 tags: vec![],
285 tailnet_address: TailnetAddress {
286 ipv4: format!("{ipv4}/32").parse().unwrap(),
287 ipv6: "fd7a::1/128".parse().unwrap(),
288 },
289 node_key: [0u8; 32].into(),
290 node_key_expiry: None,
291 online: None,
292 last_seen: None,
293 key_signature: vec![],
294 machine_key: None,
295 disco_key: None,
296 accepted_routes: vec![],
297 underlay_addresses: vec![],
298 derp_region: None,
299 cap: Default::default(),
300 cap_map: Default::default(),
301 peerapi_port: None,
302 peerapi_dns_proxy: false,
303 is_wireguard_only: false,
304 exit_node_dns_resolvers: vec![],
305 peer_relay: false,
306 service_vips: Default::default(),
307 }
308 }
309
310 #[test]
311 fn status_node_display_name_prefers_fqdn() {
312 let with_tailnet = node("n1", "host", Some("ts.net"), "100.64.0.1");
313 assert_eq!(
314 StatusNode::from_node(&with_tailnet).display_name,
315 "host.ts.net"
316 );
317
318 let bare = node("n2", "solo", None, "100.64.0.2");
319 assert_eq!(StatusNode::from_node(&bare).display_name, "solo");
320 }
321
322 #[test]
323 fn status_node_addresses_and_online_surfaced() {
324 let n = node("n1", "host", Some("ts.net"), "100.64.0.7");
325 let s = StatusNode::from_node(&n);
326
327 assert_eq!(s.ipv4, "100.64.0.7".parse::<IpAddr>().unwrap());
328 assert_eq!(s.ipv6, "fd7a::1".parse::<IpAddr>().unwrap());
329 // A node with no online data surfaces `None` (unknown) — never a fabricated `false`.
330 assert_eq!(s.online, None);
331 assert_eq!(s.last_seen, None);
332
333 // A node whose domain online state is known surfaces it through StatusNode (no longer
334 // hardwired to None).
335 let mut online = node("n2", "up", Some("ts.net"), "100.64.0.8");
336 online.online = Some(true);
337 assert_eq!(StatusNode::from_node(&online).online, Some(true));
338
339 let mut offline = node("n3", "down", Some("ts.net"), "100.64.0.9");
340 offline.online = Some(false);
341 assert_eq!(StatusNode::from_node(&offline).online, Some(false));
342 }
343
344 #[test]
345 fn status_node_detects_exit_node() {
346 let mut not_exit = node("n1", "a", Some("ts.net"), "100.64.0.1");
347 not_exit.accepted_routes = vec!["100.64.0.1/32".parse().unwrap()];
348 assert!(!StatusNode::from_node(¬_exit).is_exit_node);
349
350 let mut exit = node("n2", "b", Some("ts.net"), "100.64.0.2");
351 exit.accepted_routes = vec![
352 "100.64.0.2/32".parse().unwrap(),
353 "0.0.0.0/0".parse().unwrap(),
354 ];
355 assert!(StatusNode::from_node(&exit).is_exit_node);
356
357 let mut exit6 = node("n3", "c", Some("ts.net"), "100.64.0.3");
358 exit6.accepted_routes = vec!["::/0".parse().unwrap()];
359 assert!(StatusNode::from_node(&exit6).is_exit_node);
360 }
361
362 /// `from_node` carries NO live connectivity: a bare domain `Node` has no path state, so
363 /// `cur_addr`/`relay` default to `None`. `Runtime::status` overwrites `cur_addr` by joining the
364 /// direct manager's `best_addrs`; the self node and whois (which also use `from_node`) keep
365 /// `None`. This pins the default so the enrichment seam stays the single source of connectivity.
366 #[test]
367 fn status_node_from_node_has_no_connectivity_by_default() {
368 let n = node("n1", "host", Some("ts.net"), "100.64.0.7");
369 let s = StatusNode::from_node(&n);
370 assert_eq!(s.cur_addr, None, "a bare Node has no direct endpoint");
371 assert_eq!(s.relay, None, "a bare Node has no resolved relay");
372 }
373
374 #[test]
375 fn whois_caps_empty_when_node_has_none() {
376 // A node with no cap_map surfaces empty capabilities (not fabricated), and no user unless a
377 // profile was joined in.
378 let n = node("n1", "host", Some("ts.net"), "100.64.0.9");
379 let whois = WhoIs::from_node_with_user(n.clone(), None);
380
381 assert_eq!(whois.node, n);
382 assert_eq!(whois.user, None);
383 assert!(whois.capabilities.is_empty());
384 }
385
386 #[test]
387 fn whois_populates_capabilities_from_cap_map() {
388 // WhoIs surfaces the domain Node's cap_map verbatim, sorted by capability name (BTreeMap).
389 let mut n = node("n1", "host", Some("ts.net"), "100.64.0.9");
390 n.cap_map
391 .insert("https://tailscale.com/cap/is-admin".to_string(), vec![]);
392 n.cap_map.insert(
393 "cap/ssh".to_string(),
394 vec!["root".to_string(), "ubuntu".to_string()],
395 );
396 let whois = WhoIs::from_node_with_user(n, None);
397
398 // BTreeMap iteration is sorted: "cap/ssh" < "https://…".
399 assert_eq!(
400 whois.capabilities,
401 vec![
402 (
403 "cap/ssh".to_string(),
404 vec!["root".to_string(), "ubuntu".to_string()]
405 ),
406 ("https://tailscale.com/cap/is-admin".to_string(), vec![]),
407 ]
408 );
409 }
410
411 #[test]
412 fn whois_from_node_with_user_sets_user_and_caps() {
413 let mut n = node("n1", "host", Some("ts.net"), "100.64.0.9");
414 n.cap_map.insert("cap/x".to_string(), vec!["y".to_string()]);
415 let whois = WhoIs::from_node_with_user(n, Some("alice@example.com".to_string()));
416
417 assert_eq!(whois.user, Some("alice@example.com".to_string()));
418 assert_eq!(
419 whois.capabilities,
420 vec![("cap/x".to_string(), vec!["y".to_string()])]
421 );
422 }
423
424 /// Build a peer with a reachable peerAPI on `ipv4`, owned by `user`.
425 fn peer_with_peerapi(stable: &str, hostname: &str, ipv4: &str, user: UserId) -> Node {
426 let mut n = node(stable, hostname, Some("ts.net"), ipv4);
427 n.user_id = user;
428 n.peerapi_port = Some(8089);
429 n
430 }
431
432 #[test]
433 fn file_targets_includes_same_owner_peer_with_peerapi() {
434 let peer = peer_with_peerapi("p1", "host", "100.64.0.5", 42);
435 let targets = build_file_targets(vec![peer], 42);
436
437 assert_eq!(targets.len(), 1);
438 assert_eq!(targets[0].peerapi_url, "http://100.64.0.5:8089");
439 assert_eq!(targets[0].node.hostname, "host");
440 }
441
442 #[test]
443 fn file_targets_includes_cross_owner_peer_with_target_cap() {
444 // Different owner, but carries the file-sharing-target cap → still a target (Go's OR).
445 let mut peer = peer_with_peerapi("p1", "host", "100.64.0.5", 99);
446 peer.cap_map
447 .insert("tailscale.com/cap/file-sharing-target".to_string(), vec![]);
448 let targets = build_file_targets(vec![peer], 42);
449
450 assert_eq!(
451 targets.len(),
452 1,
453 "cross-owner peer with the target cap qualifies"
454 );
455 }
456
457 #[test]
458 fn file_targets_excludes_cross_owner_peer_without_cap() {
459 // Different owner and no target cap → excluded.
460 let peer = peer_with_peerapi("p1", "host", "100.64.0.5", 99);
461 let targets = build_file_targets(vec![peer], 42);
462
463 assert!(
464 targets.is_empty(),
465 "a different owner without the cap is not a target"
466 );
467 }
468
469 #[test]
470 fn file_targets_excludes_peer_without_peerapi() {
471 // Same owner, but advertises no peerAPI (no port) → excluded (Go `PeerAPIBase(p) == ""`).
472 let mut peer = peer_with_peerapi("p1", "host", "100.64.0.5", 42);
473 peer.peerapi_port = None;
474 let targets = build_file_targets(vec![peer], 42);
475
476 assert!(
477 targets.is_empty(),
478 "a peer with no peerAPI cannot be a Taildrop target"
479 );
480 }
481
482 #[test]
483 fn file_targets_sorted_by_magic_dns_name() {
484 // Insert out of order; expect sorted by fqdn ("alpha.ts.net" < "zeta.ts.net").
485 let zeta = peer_with_peerapi("p2", "zeta", "100.64.0.6", 42);
486 let alpha = peer_with_peerapi("p1", "alpha", "100.64.0.5", 42);
487 let targets = build_file_targets(vec![zeta, alpha], 42);
488
489 let names: Vec<_> = targets.iter().map(|t| t.node.hostname.clone()).collect();
490 assert_eq!(names, vec!["alpha", "zeta"]);
491 }
492
493 fn region_result(id: u32, latency_ms: u64) -> ts_netcheck::RegionResult {
494 ts_netcheck::RegionResult {
495 latency: std::time::Duration::from_millis(latency_ms),
496 id: ts_derp::RegionId(std::num::NonZeroU32::new(id).unwrap()),
497 latency_map_key: format!("{id}-v4"),
498 connected_remote: "1.2.3.4:443".parse().unwrap(),
499 }
500 }
501
502 #[test]
503 fn netcheck_report_preferred_is_first_region() {
504 // The measurer hands results sorted by latency ascending, so the first is the preferred
505 // (home) region and every region is surfaced.
506 let results = [
507 region_result(5, 12),
508 region_result(9, 40),
509 region_result(2, 88),
510 ];
511 let report = NetcheckReport::from_region_results(&results);
512 assert_eq!(
513 report.preferred_derp,
514 Some(5),
515 "lowest-latency region is preferred"
516 );
517 assert_eq!(report.region_latencies.len(), 3);
518 assert_eq!(report.region_latencies[0].region_id, 5);
519 assert_eq!(
520 report.region_latencies[0].latency,
521 std::time::Duration::from_millis(12)
522 );
523 // Order is preserved as given (latency-ascending from the measurer).
524 let ids: Vec<u32> = report
525 .region_latencies
526 .iter()
527 .map(|r| r.region_id)
528 .collect();
529 assert_eq!(ids, vec![5, 9, 2]);
530 }
531
532 #[test]
533 fn netcheck_report_empty_when_no_measurements() {
534 // Before any measurement (or when none was reachable): no preferred region, empty list — not
535 // a fabricated value.
536 let report = NetcheckReport::from_region_results(&[]);
537 assert_eq!(report, NetcheckReport::default());
538 assert_eq!(report.preferred_derp, None);
539 assert!(report.region_latencies.is_empty());
540 }
541}