open_net/api/net_status/mod.rs
1//! Shared network monitoring with versioned snapshots and owned subscriptions.
2
3mod ip_stack;
4mod net_status_client;
5mod network_status;
6
7pub use crate::module::net_status::inner::shared::NetworkStatusContext;
8use crate::NetError;
9pub use ip_stack::IpStack;
10pub use net_status_client::NetStatusClient;
11pub use network_status::NetworkStatus;
12use std::time::SystemTime;
13
14/// One coherent observation, or an explicit state with no current observation.
15#[derive(Clone, Debug)]
16pub struct NetworkSnapshot {
17 /// Monotonically increasing snapshot revision.
18 pub revision: u64,
19 /// Counter identifying the current loss/recovery epoch.
20 pub loss_epoch: u64,
21 /// Lifecycle state at the time of observation.
22 pub state: MonitorState,
23 /// Reachability observation, when one has been obtained.
24 pub reachability: Option<NetworkStatus>,
25 /// Locally available IP protocol stack, when known.
26 pub ip_stack: Option<IpStack>,
27 /// Timestamp at which the observation was collected.
28 pub observed_at: Option<SystemTime>,
29 /// Human-readable network identifier supplied by the platform, when available.
30 pub network_name: Option<String>,
31}
32
33/// The lifecycle shared by every clone of a network status client.
34#[non_exhaustive]
35#[derive(Clone, Debug)]
36pub enum MonitorState {
37 /// Monitoring has not been started.
38 Stopped,
39 /// Monitoring startup is in progress.
40 Starting,
41 /// Monitoring is active and publishing observations.
42 Running,
43 /// Startup or monitoring failed; contains the classified cause.
44 Failed(NetError),
45 /// Monitoring was permanently shut down.
46 Closed,
47}