pub struct CooperationState {
pub sessions: Vec<SessionView>,
pub claims: Vec<ClaimView>,
pub overlaps: Vec<ClaimOverlap>,
pub handovers: Vec<HandoverView>,
pub reviews: Vec<ReviewView>,
pub opaque_events: usize,
pub digest: String,
}Expand description
The whole folded state, every collection in key order, and its digest: two runtimes that agree print the same digest.
The digest is the point. Convergence is otherwise a claim nobody can check from one
machine; with it, two operators compare one short string and know whether their
runtimes are looking at the same world. opaque_events is the other half of that
honesty: events of kinds this executable does not interpret are counted and relayed
rather than dropped, so a newer peer’s traffic is visible instead of silently missing.
use std::sync::Arc;
use majordomus_cli::mesh::identity::NodeIdentity;
use majordomus_cli::mesh::journal::{EventBody, Journal, SessionInfo, StreamLiveness};
use majordomus_cli::mesh::state::{fold, CooperationState};
let j = Journal::open(Arc::new(NodeIdentity::ephemeral().unwrap()), "0000000000000001",
"repo".into(), None).unwrap();
j.append_own(EventBody::SessionOpened { info: SessionInfo::named("s1", "cli") }).unwrap();
let events = j.events();
let state: CooperationState = fold(&events, &|_| StreamLiveness::Own);
assert_eq!(state.digest.len(), 32);
// the same events in another order, and twice over, are the same state
let mut shuffled = events.clone();
shuffled.reverse();
shuffled.extend(events);
assert_eq!(fold(&shuffled, &|_| StreamLiveness::Own).digest, state.digest);Fields§
§sessions: Vec<SessionView>Every session.
claims: Vec<ClaimView>Every claim.
overlaps: Vec<ClaimOverlap>Advisory overlaps between live claims.
handovers: Vec<HandoverView>Every handover.
reviews: Vec<ReviewView>Every review request.
opaque_events: usizeEvents of kinds this executable does not interpret.
digest: String32 hex of the SHA-256 of the canonical JSON of everything above.
Trait Implementations§
Source§impl Clone for CooperationState
impl Clone for CooperationState
Source§fn clone(&self) -> CooperationState
fn clone(&self) -> CooperationState
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CooperationState
impl Debug for CooperationState
Source§impl Default for CooperationState
impl Default for CooperationState
Source§fn default() -> CooperationState
fn default() -> CooperationState
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for CooperationState
impl<'de> Deserialize<'de> for CooperationState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for CooperationState
Source§impl JsonSchema for CooperationState
impl JsonSchema for CooperationState
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
Whether JSON Schemas generated for this type should be included directly in parent schemas,
rather than being re-used where possible using the
$ref keyword. Read moreSource§impl PartialEq for CooperationState
impl PartialEq for CooperationState
Source§fn eq(&self, other: &CooperationState) -> bool
fn eq(&self, other: &CooperationState) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for CooperationState
impl Serialize for CooperationState
impl StructuralPartialEq for CooperationState
Auto Trait Implementations§
impl Freeze for CooperationState
impl RefUnwindSafe for CooperationState
impl Send for CooperationState
impl Sync for CooperationState
impl Unpin for CooperationState
impl UnsafeUnpin for CooperationState
impl UnwindSafe for CooperationState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.