aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/events.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/events.rs')
-rw-r--r--src/api/events.rs45
1 files changed, 43 insertions, 2 deletions
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,
}),
)