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