diff options
| -rw-r--r-- | docs/openapi.yaml | 53 | ||||
| -rw-r--r-- | docs/operations.md | 3 | ||||
| -rw-r--r-- | docs/peers.md | 9 | ||||
| -rw-r--r-- | src/api/events.rs | 31 | ||||
| -rw-r--r-- | src/api/peers.rs | 14 | ||||
| -rw-r--r-- | src/swarm/speaking.rs | 51 |
6 files changed, 111 insertions, 50 deletions
diff --git a/docs/openapi.yaml b/docs/openapi.yaml index b1e1e28..4982cac 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -1596,23 +1596,9 @@ paths: knows: type: object additionalProperties: - type: [object, 'null'] - required: [wire, revision] - properties: - wire: - type: array - items: - type: integer - revision: - type: [object, 'null'] - required: [number, id, named] - properties: - number: - type: [integer, 'null'] - id: - type: string - named: - type: string + oneOf: + - $ref: '#/components/schemas/Knows' + - type: 'null' values: type: object members: @@ -2700,7 +2686,7 @@ components: PeerList: type: object - required: [localAddresses, localEpoch, localHeads, localReaches, peers] + required: [localAddresses, localEpoch, localHeads, localReaches, localKnows, peers] properties: localAlias: type: [string, 'null'] @@ -2719,12 +2705,38 @@ components: items: type: string description: The members this node reaches (an active session with each, answering), by node ID, as it last told its neighbours. + localKnows: + $ref: '#/components/schemas/Knows' peers: type: object description: By node ID. additionalProperties: $ref: '#/components/schemas/Peer' + Knows: + type: object + description: What a node says it speaks and knows (SPEAKS, docs/peers.md), what decides which builds work together. + required: [wire, revision] + properties: + wire: + type: array + items: + type: integer + description: The wire versions it speaks, the oldest and the newest. + revision: + type: [object, 'null'] + description: The newest revision of the federation it knows; null where it knows none (built without the federation). + required: [number, id, named] + properties: + number: + type: [integer, 'null'] + description: Null where this node doesn't know the revision. + id: + type: string + named: + type: string + description: As people read it. + Peer: type: object required: [addresses, status, handshakeComplete, hasPendingDelivery, neighbour, traffic, incidents] @@ -2828,6 +2840,11 @@ components: items: type: string description: The members it said it reaches, by node ID (those in our member list); null before it said so since its session began (handshake, or back from dormant). + knows: + oneOf: + - $ref: '#/components/schemas/Knows' + - type: 'null' + description: What it said it speaks and knows with its handshakes (SPEAKS); null where it said nothing, a build from before SPEAKS, or no handshake from it since this node started. traffic: $ref: '#/components/schemas/Traffic' incidents: diff --git a/docs/operations.md b/docs/operations.md index 97fee26..f64bc13 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -112,7 +112,8 @@ Before 1.0.0, any release may be a flag day; its tag's message says whether it i What decides which builds work together, a build says (`-V` the release alone): the wire versions it speaks, the federation and the revisions of it it knows (with the `federation` feature), and the Automerge it makes documents with. `continuum-party ---version` says the same. +--version` says the same. Of the wire versions and the revision, a node tells its peers +too: each peer's, as far as the node heard, is its `knows` in `GET /peers`. ```sh continuum --version diff --git a/docs/peers.md b/docs/peers.md index d2f822f..34023db 100644 --- a/docs/peers.md +++ b/docs/peers.md @@ -99,10 +99,11 @@ Before each HELLO and each HELLO_REPLY, a node sends SPEAKS: the wire versions i and the newest revision of the federation it knows, as its build has them. It stands outside the wire versions, laid out as no build changes, so that a peer on another build reads it too, once that peer reads the node's WHO and ME -([Node IDs and addresses](#node-ids-and-addresses)): what each peer said shows in `knows` -of `GET /events/counts`, for the nodes a federated store's parties list. A build from -before SPEAKS takes it for a message of another wire version, and logs that once of the -peer ([`operations.md`](operations.md), [Upgrading](operations.md#upgrading)). +([Node IDs and addresses](#node-ids-and-addresses)): what each peer said shows as its +`knows` in `GET /peers`, the node's own as `localKnows`, and in `GET /events/counts` for +the nodes a federated store's parties list. A build from before SPEAKS takes it for a +message of another wire version, and logs that once of the peer +([`operations.md`](operations.md), [Upgrading](operations.md#upgrading)). Every HELLO carries a random id of the sender's current run, and the HELLO_REPLY echoes it. A reply with another id answers a HELLO from an earlier run (delivered late, or 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, } diff --git a/src/swarm/speaking.rs b/src/swarm/speaking.rs index e1a8d2c..4626fb1 100644 --- a/src/swarm/speaking.rs +++ b/src/swarm/speaking.rs @@ -30,6 +30,44 @@ fn newest_revision() -> Option<[u8; 32]> { None } +/// `speaks` as the API shows it (`knows` in `GET /peers` and `GET /events/counts`): the +/// wire versions, the oldest and the newest, and the newest revision of the federation, +/// by number and ID and as people read it, its number null where this continuum doesn't +/// know it; null where there is none. +pub(crate) fn shown(speaks: Speaks) -> serde_json::Value { + serde_json::json!({ + "wire": [speaks.oldest, speaks.newest], + "revision": speaks.revision.map(revision_shown), + }) +} + +#[cfg(feature = "federation")] +fn revision_shown(id: [u8; 32]) -> serde_json::Value { + use crate::federation::revision::Revision; + let id = crate::federation::store::Id(id); + match Revision::of(&id) { + Some(revision) => serde_json::json!({ + "number": revision.0, + "id": id.to_string(), + "named": revision.to_string(), + }), + None => unknown(&id.to_string()), + } +} + +#[cfg(not(feature = "federation"))] +fn revision_shown(id: [u8; 32]) -> serde_json::Value { + unknown(&crate::transport::Hex(&id).to_string()) +} + +fn unknown(id: &str) -> serde_json::Value { + serde_json::json!({ + "number": null, + "id": id, + "named": format!("{id}, a revision this continuum doesn't know"), + }) +} + /// The SPEAKS each peer sent last, by node ID. #[derive(Default)] pub(crate) struct Speaking(std::sync::Mutex<BTreeMap<String, Speaks>>); @@ -68,5 +106,18 @@ mod tests { speaking.heard("a", older); assert_eq!(speaking.of("a"), Some(older)); assert_eq!(own().newest, wire::VERSION); + let unknown = shown(Speaks { + revision: Some([7; 32]), + ..older + }); + assert_eq!(unknown["wire"], serde_json::json!([1, 1])); + assert_eq!(unknown["revision"]["number"], serde_json::Value::Null); + assert_eq!(unknown["revision"]["id"], "07".repeat(32)); + assert_eq!(shown(older)["revision"], serde_json::Value::Null); + #[cfg(feature = "federation")] + assert_eq!( + shown(own())["revision"]["number"], + crate::federation::revision::FEATURES.len() + ); } } |
