diff options
| author | tv <tv@krebsco.de> | 2026-10-31 05:01:17 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-31 05:01:17 +0100 |
| commit | 69bc5ae4ce1c0e8ff2fe03091b1ba022edc13ad1 (patch) | |
| tree | 73650e158f1872cb04a42d92da4ff41a2f4edd9e /src | |
| parent | 6c7809103f62c89fc10cc82228a28a0f39db5277 (diff) | |
replace EpochInfo by EpochRecord
Diffstat (limited to 'src')
| -rw-r--r-- | src/api/peers.rs | 25 | ||||
| -rw-r--r-- | src/api/stats.rs | 5 | ||||
| -rw-r--r-- | src/document/replica.rs | 18 | ||||
| -rw-r--r-- | src/remake/records.rs | 17 |
4 files changed, 26 insertions, 39 deletions
diff --git a/src/api/peers.rs b/src/api/peers.rs index 8ebffc5..020221b 100644 --- a/src/api/peers.rs +++ b/src/api/peers.rs @@ -12,7 +12,7 @@ use tokio::time::Instant; use tracing::warn; use super::store_status; -use crate::document::replica::Epoch; +use crate::document::replica::EpochRecord; use crate::document::store; use crate::locks::MutexExt; use crate::state::{AppState, HelloState, Incidents, Liveness}; @@ -31,23 +31,6 @@ pub(crate) enum PeerLivenessStatus { #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] -pub(crate) struct EpochInfo { - pub(crate) generation: u64, - /// Hex-encoded snapshot hash; all zeros for the genesis epoch. - pub(crate) id: String, -} - -impl From<Epoch> for EpochInfo { - fn from(epoch: Epoch) -> Self { - Self { - generation: epoch.generation, - id: epoch.id_hex(), - } - } -} - -#[derive(Debug, Serialize)] -#[serde(rename_all = "camelCase")] pub(crate) struct PeerStatus { /// The name the peer gave itself in the member list, if any (not unique). pub(crate) alias: Option<String>, @@ -68,7 +51,7 @@ pub(crate) struct PeerStatus { pub(crate) diverged_for_secs: Option<u64>, pub(crate) has_pending_delivery: bool, /// Epoch the peer last advertised; absent until it has sent a message. - pub(crate) epoch: Option<EpochInfo>, + pub(crate) epoch: Option<EpochRecord>, /// Whether that epoch equals ours, i.e. whether we sync with this peer. pub(crate) same_epoch: Option<bool>, /// Number of heads in its last keepalive; absent before one, or when it had more @@ -99,7 +82,7 @@ pub(crate) struct ThroughputInfo { pub(crate) struct PeerListResponse { /// Our own alias (`--alias`). pub(crate) local_alias: Option<String>, - pub(crate) local_epoch: EpochInfo, + pub(crate) local_epoch: EpochRecord, /// Number of heads of our document. Several heads are concurrent changes no later /// change has merged yet. pub(crate) local_heads: usize, @@ -178,7 +161,7 @@ pub(crate) async fn peer_list(state: &AppState) -> PeerListResponse { .diverged_since .map(|t| now.saturating_duration_since(t).as_secs()), has_pending_delivery: ps.sync.sending.is_some() || ps.sync.retry_at.is_some(), - epoch: ps.epoch.map(EpochInfo::from), + epoch: ps.epoch.map(EpochRecord::from), same_epoch: ps.epoch.map(|epoch| epoch == local_epoch), heads: ps.reported_heads, neighbour, diff --git a/src/api/stats.rs b/src/api/stats.rs index 9e1b278..13610dd 100644 --- a/src/api/stats.rs +++ b/src/api/stats.rs @@ -13,7 +13,8 @@ use std::collections::BTreeMap; use serde::Serialize; -use super::peers::{EpochInfo, PeerListResponse, peer_list}; +use super::peers::{PeerListResponse, peer_list}; +use crate::document::replica::EpochRecord; use crate::state::{AppState, Incidents}; use crate::swarm::{members, stability, topology}; use crate::transport::stats::TransportStats; @@ -28,7 +29,7 @@ pub(crate) struct StatsResponse { alias: Option<String>, uptime_secs: u64, ready: bool, - epoch: EpochInfo, + epoch: EpochRecord, document: DocumentStats, catch_up: CatchUpStats, remakes: RemakeStats, diff --git a/src/document/replica.rs b/src/document/replica.rs index fe76c12..c8f648b 100644 --- a/src/document/replica.rs +++ b/src/document/replica.rs @@ -59,6 +59,24 @@ impl Epoch { } } +/// An epoch as records and the API show it: its generation and its snapshot hash in +/// hex (all zeros for the genesis epoch). +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] +pub(crate) struct EpochRecord { + pub(crate) generation: u64, + pub(crate) id: String, +} + +impl From<Epoch> for EpochRecord { + fn from(epoch: Epoch) -> Self { + Self { + generation: epoch.generation, + id: epoch.id_hex(), + } + } +} + impl fmt::Display for Epoch { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if *self == Epoch::GENESIS { diff --git a/src/remake/records.rs b/src/remake/records.rs index 720aea1..463d085 100644 --- a/src/remake/records.rs +++ b/src/remake/records.rs @@ -45,22 +45,7 @@ const DAY_MS: u64 = 24 * 60 * 60 * 1000; // --- record types ------------------------------------------------------------ -/// An epoch in a record: generation plus hex-encoded snapshot hash. -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub(crate) struct EpochRecord { - pub(crate) generation: u64, - pub(crate) id: String, -} - -impl From<Epoch> for EpochRecord { - fn from(epoch: Epoch) -> Self { - Self { - generation: epoch.generation, - id: epoch.id_hex(), - } - } -} +pub(crate) use crate::document::replica::EpochRecord; impl EpochRecord { pub(crate) fn to_epoch(&self) -> Option<Epoch> { |
