diff options
Diffstat (limited to 'src/api/events.rs')
| -rw-r--r-- | src/api/events.rs | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/src/api/events.rs b/src/api/events.rs index 7bb322e..f49c540 100644 --- a/src/api/events.rs +++ b/src/api/events.rs @@ -106,6 +106,41 @@ async fn summary(State(state): State<AppState>) -> Response { }) } +/// What `node` says it speaks and knows (SPEAKS, `swarm::speaking`), this node's own as +/// it is: 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 continuum doesn't know it. Null where the node said nothing: a build from +/// before SPEAKS, or one not heard from. +fn knows(state: &AppState, node: &str) -> JsonValue { + let speaks = if node == state.local_id() { + Some(crate::swarm::speaking::own()) + } else { + state.speaking.of(node) + }; + let Some(speaks) = speaks else { + return JsonValue::Null; + }; + let revision = speaks.revision.map(|id| { + let id = Id(id); + match Revision::of(&id) { + Some(revision) => json!({ + "number": revision.0, + "id": id.to_string(), + "named": revision.to_string(), + }), + None => json!({ + "number": null, + "id": id.to_string(), + "named": format!("{id}, a revision this continuum doesn't know"), + }), + } + }); + json!({ + "wire": [speaks.oldest, speaks.newest], + "revision": revision, + }) +} + /// The revisions this continuum knows, the base revision first: each its number, its ID, /// the feature it adds and what that adds, and as people read it. fn revisions() -> Vec<JsonValue> { @@ -143,7 +178,8 @@ async fn event(State(state): State<AppState>, Path(id): Path<String>) -> Respons } /// `GET /events/counts`: what counts, as the store reads now: the current version, each -/// party's keys and nodes, the values at places, the members, and the proposals on the +/// party's keys and nodes, what each of those nodes 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 (`proposing`: /// for a checkpoint, those above its heads), the votes on it, the parties /// voting `true` and `false`, whether it passed and whether it is dead, and why a party's @@ -157,11 +193,17 @@ async fn counts(State(state): State<AppState>) -> Response { .parties .keys() .map(|party| { + let nodes = read.nodes_of(party, current); + let knows: serde_json::Map<String, JsonValue> = nodes + .iter() + .map(|node| (node.clone(), knows(&state, node))) + .collect(); ( party.clone(), json!({ "keys": read.keys_of(party, current), - "nodes": read.nodes_of(party, current), + "nodes": nodes, + "knows": knows, }), ) }) |
