Skip to main content

open_net/api/net_status/
mod.rs

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