cls_eedi/wire/
trust_report.rs1use super::{State, TrustEntry};
3use serde::Serialize;
4
5#[derive(Debug, PartialEq, Eq, Serialize)]
10pub struct TrustReport {
11 pub timestamp: i64,
12 pub trust: Option<TrustSummary>,
13}
14
15#[derive(Debug, Default, PartialEq, Eq, Serialize)]
17#[serde(rename_all = "camelCase")]
18pub struct TrustSummary {
19 pub direct_ski: usize,
20 pub pairing_pending: usize,
21 pub pairing_established: usize,
22}
23
24impl TrustSummary {
25 pub fn from_entries(entries: &[TrustEntry]) -> Self {
27 let mut counts = Self::default();
28 for entry in entries {
29 if let Some(pairing) = &entry.ship_pairing_service {
30 if pairing.ski.is_some() {
31 counts.pairing_established += 1;
32 } else {
33 counts.pairing_pending += 1;
34 }
35 } else if entry.ski.is_some() {
36 counts.direct_ski += 1;
37 }
38 }
39 counts
40 }
41}
42
43impl TrustReport {
44 pub fn from_state(state: &State) -> Self {
46 Self {
47 timestamp: state.timestamp,
48 trust: state.trust.as_deref().map(TrustSummary::from_entries),
49 }
50 }
51}