Skip to main content

gent_protocol/
stats.rs

1//! Read models for the owner-facing Gent statistics command and Desktop tab.
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
5pub struct Traffic {
6    pub messages: u64,
7    pub bytes: u64,
8    pub text_bytes: u64,
9    pub attachment_bytes: u64,
10}
11
12#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
13pub struct Sender {
14    pub chat_id: String,
15    pub name: String,
16    #[serde(flatten)]
17    pub traffic: Traffic,
18}
19
20#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
21pub struct Babysitter {
22    pub ordinary_submitted: u64,
23    pub goal_submitted: u64,
24}
25
26#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
27pub struct Node {
28    pub id: String,
29    pub name: String,
30}
31
32#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
33pub struct Tracking {
34    pub tracking_started_at: i64,
35    pub backfill: String,
36    pub older_daemon_activity: String,
37}
38
39/// A physical node's contribution before ranking or merging chat IDs.
40#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
41pub struct NodeContribution {
42    pub node: Node,
43    pub outbound: Traffic,
44    pub senders: Vec<Sender>,
45    pub babysitter: Babysitter,
46    pub coverage: Tracking,
47}
48
49#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
50pub struct NodeStats {
51    pub node: Node,
52    pub status: String,
53    pub as_of: Option<i64>,
54    pub outbound: Option<Traffic>,
55    pub babysitter: Option<Babysitter>,
56    pub coverage: Option<Tracking>,
57}
58
59#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
60pub struct Coverage {
61    pub expected_nodes: usize,
62    pub reporting_nodes: usize,
63    pub fresh_nodes: usize,
64    pub complete: bool,
65}
66
67/// Counts from a bounded refresh, including the local node.
68#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
69pub struct Refresh {
70    pub confirmed_nodes: usize,
71    pub expected_nodes: usize,
72}
73
74#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
75pub struct Stats {
76    pub scope: String,
77    pub outbound: Traffic,
78    pub babysitter: Babysitter,
79    pub top_senders: Vec<Sender>,
80    pub nodes: Vec<NodeStats>,
81    pub coverage: Coverage,
82    #[serde(default, skip_serializing_if = "Option::is_none")]
83    pub refresh: Option<Refresh>,
84}