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