aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-19 21:19:38 +0000
committertv <tv@krebsco.de>2026-11-19 22:30:20 +0100
commit5e93c28c963224ce89901b813c06598bcc84f8c7 (patch)
treeef082939fbbb37f6e5c7910c36851ffe564a5735
parentedb4443510d7c8e4957e953093a25f9e7876493e (diff)
events/counts: when this node last heard from each listed node
Each party in GET /events/counts gives `heard` now: by node ID, how many seconds ago this node last heard from each node the party lists (its peer state's last_seen), 0 for itself, left out where it never heard from it since it started. A party's client reads from it whether nodes are cut off, where a vote may be held back, and a party's session, which reads no /peers, has it.
-rw-r--r--docs/openapi.yaml10
-rw-r--r--src/api/events.rs45
2 files changed, 51 insertions, 4 deletions
diff --git a/docs/openapi.yaml b/docs/openapi.yaml
index af17d69..8dfbc88 100644
--- a/docs/openapi.yaml
+++ b/docs/openapi.yaml
@@ -1587,7 +1587,9 @@ paths:
What counts, as the store reads now (docs/federation.md): the current version
(its number, its hash, its revision, by number and ID and as people read it, and
the version itself), each party's keys and nodes, the names those nodes gave
- themselves (`names`, by node ID, `--alias`, of those that did), what each said
+ themselves (`names`, by node ID, `--alias`, of those that did), how many seconds
+ ago this node last heard from each (`heard`, by node ID; 0 for itself; left out
+ for one it never heard from since it started), what each said
it speaks and knows (`knows`, by node ID: the wire versions it speaks, the oldest
and the newest, and the newest revision of the federation it knows, by number
and ID and as people read it, its number null where this node doesn't know it;
@@ -1623,7 +1625,7 @@ paths:
type: object
additionalProperties:
type: object
- required: [keys, nodes, names, knows]
+ required: [keys, nodes, names, heard, knows]
properties:
keys:
type: array
@@ -1637,6 +1639,10 @@ paths:
type: object
additionalProperties:
type: string
+ heard:
+ type: object
+ additionalProperties:
+ type: integer
knows:
type: object
additionalProperties:
diff --git a/src/api/events.rs b/src/api/events.rs
index 81f1481..d6c06c4 100644
--- a/src/api/events.rs
+++ b/src/api/events.rs
@@ -154,9 +154,44 @@ async fn event(State(state): State<AppState>, Path(id): Path<String>) -> Respons
}
}
+/// Of the nodes the parties list, how many seconds ago this node last heard from each: 0
+/// for itself; none it never heard from since it started.
+async fn heard(state: &AppState) -> std::collections::HashMap<String, u64> {
+ let nodes: Vec<String> = state
+ .holding
+ .with(|store| {
+ let read = store.state();
+ let current = read.current();
+ current
+ .parties
+ .keys()
+ .flat_map(|party| read.nodes_of(party, current))
+ .collect()
+ })
+ .unwrap_or_default();
+ let now = tokio::time::Instant::now();
+ let mut heard = std::collections::HashMap::new();
+ for node in nodes {
+ if node == state.local_id() {
+ heard.insert(node, 0);
+ continue;
+ }
+ let Some(peer) = state.get_peer_state(&node).await else {
+ continue;
+ };
+ let last_seen = peer.lock().await.last_seen;
+ if let Some(at) = last_seen {
+ heard.insert(node, now.saturating_duration_since(at).as_secs());
+ }
+ }
+ heard
+}
+
/// `GET /events/counts`: what counts, as the store reads now: the current version, each
-/// party's keys and nodes, the names those nodes gave themselves (`names`, `--alias`), what
-/// each of them says it speaks and knows (`knows`),
+/// party's keys and nodes, the names those nodes gave themselves (`names`, `--alias`), how
+/// long ago this node last heard from each (`heard`, in seconds; 0 for itself; left out
+/// where it never did since it started), what each of them says it speaks and knows
+/// (`knows`),
/// the values at places, the members, and the proposals on the
/// current version, each with the events proposing it a vote may build on (`proposals`:
/// for a checkpoint, those above its heads), the votes on it, the parties
@@ -166,6 +201,7 @@ async fn event(State(state): State<AppState>, Path(id): Path<String>) -> Respons
/// refuses (`beside`, `signed_beside`).
async fn counts(State(state): State<AppState>) -> Response {
let aliases = crate::swarm::members::aliases(&state.doc.read().await.doc);
+ let heard = heard(&state).await;
with_store(&state, |store| {
let read = store.state();
let current = read.current();
@@ -182,12 +218,17 @@ async fn counts(State(state): State<AppState>) -> Response {
.iter()
.filter_map(|node| Some((node.clone(), aliases.get(node)?.clone().into())))
.collect();
+ let heard: serde_json::Map<String, JsonValue> = nodes
+ .iter()
+ .filter_map(|node| Some((node.clone(), (*heard.get(node)?).into())))
+ .collect();
(
party.clone(),
json!({
"keys": read.keys_of(party, current),
"nodes": nodes,
"names": names,
+ "heard": heard,
"knows": knows,
}),
)