aboutsummaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/events.rs31
-rw-r--r--src/api/peers.rs14
2 files changed, 18 insertions, 27 deletions
diff --git a/src/api/events.rs b/src/api/events.rs
index f49c540..45c9a32 100644
--- a/src/api/events.rs
+++ b/src/api/events.rs
@@ -106,39 +106,16 @@ 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.
+/// What `node` says it speaks and knows (SPEAKS, `swarm::speaking::shown`), this node's
+/// own as it is; 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,
- })
+ speaks.map_or(JsonValue::Null, crate::swarm::speaking::shown)
}
/// The revisions this continuum knows, the base revision first: each its number, its ID,
diff --git a/src/api/peers.rs b/src/api/peers.rs
index 2bdde96..1f7af21 100644
--- a/src/api/peers.rs
+++ b/src/api/peers.rs
@@ -17,6 +17,7 @@ use crate::document::store;
use crate::locks::MutexExt;
use crate::state::{AppState, HelloState, Incidents, Liveness};
use crate::swarm::peer::forgotten_path;
+use crate::swarm::speaking;
use crate::transport::Destination;
use crate::transport::paths::ClockOffset;
use crate::transport::traffic::PeerTraffic;
@@ -67,6 +68,11 @@ pub(crate) struct PeerStatus {
/// absent before it said so in this session. Keys of members not in our member
/// list are left out.
pub(crate) reaches: Option<Vec<String>>,
+ /// What it said it speaks and knows with its handshakes (SPEAKS,
+ /// `swarm::speaking::shown`): the wire versions, the newest revision of the
+ /// federation. Null where it said nothing: a build from before SPEAKS, or no
+ /// handshake from it since we started.
+ pub(crate) knows: serde_json::Value,
/// Messages and payload bytes exchanged with it, by kind, since we started (or
/// since it was last listed).
pub(crate) traffic: PeerTraffic,
@@ -139,6 +145,8 @@ pub(crate) struct PeerListResponse {
pub(crate) local_addresses: Vec<String>,
/// The members we reach (`swarm::reach`), as we last told our neighbours.
pub(crate) local_reaches: Vec<String>,
+ /// What we tell peers we speak and know, as `PeerStatus::knows`.
+ pub(crate) local_knows: serde_json::Value,
/// By node ID.
pub(crate) peers: BTreeMap<String, PeerStatus>,
}
@@ -228,6 +236,10 @@ pub(crate) async fn peer_list(state: &AppState) -> PeerListResponse {
.effective(&peer, now, state.timing.rtt_fresh_for())
.map(|rtt| rtt.as_millis() as u64 / 2),
});
+ let knows = state
+ .speaking
+ .of(&peer)
+ .map_or(serde_json::Value::Null, speaking::shown);
peers.insert(
peer,
PeerStatus {
@@ -254,6 +266,7 @@ pub(crate) async fn peer_list(state: &AppState) -> PeerListResponse {
heads: ps.reported_heads,
neighbour,
reaches: crate::swarm::reach::of(ps.reaches.as_ref()).map(&named),
+ knows,
traffic,
incidents: ps.incidents,
sync_throughput,
@@ -269,6 +282,7 @@ pub(crate) async fn peer_list(state: &AppState) -> PeerListResponse {
local_addresses: state.transport.local_addresses(),
local_epoch: local_epoch.into(),
local_reaches: named(crate::swarm::reach::published(&state)),
+ local_knows: speaking::shown(speaking::own()),
local_heads,
peers,
}