use std::fmt;
use std::time::Duration;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NetworkHealthState {
Discovering,
Healthy,
Recovering,
Degraded,
}
impl NetworkHealthState {
pub fn as_str(self) -> &'static str {
match self {
Self::Discovering => "discovering",
Self::Healthy => "healthy",
Self::Recovering => "recovering",
Self::Degraded => "degraded",
}
}
}
impl fmt::Display for NetworkHealthState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NetworkHealthSnapshot {
pub state: NetworkHealthState,
pub connected_peers: usize,
pub rendezvous_enabled: bool,
pub consecutive_rendezvous_failures: u32,
pub consecutive_peer_dial_failures: u32,
pub rendezvous_restarts: u64,
pub last_rendezvous_success_ago: Option<Duration>,
pub last_rendezvous_error: Option<String>,
pub restart_recommended: bool,
}