1use crate::fetch::DynFetch;
4use crate::peer_store::DynPeerStore;
5use crate::transport::DynTransport;
6use crate::{
7 builder, config, BoxFut, DhtArc, DynLocalAgentStore, DynOpStore,
8 DynPeerMetaStore, K2Result, SpaceId, StoredOp, Timestamp, Url,
9};
10use serde::{Deserialize, Serialize};
11use std::collections::HashMap;
12use std::sync::Arc;
13
14#[derive(Debug, Clone)]
16pub struct GossipStateSummaryRequest {
17 pub include_dht_summary: bool,
19}
20
21pub trait Gossip: 'static + Send + Sync + std::fmt::Debug {
23 fn inform_ops_stored(&self, ops: Vec<StoredOp>)
28 -> BoxFut<'_, K2Result<()>>;
29
30 fn get_state_summary(
32 &self,
33 request: GossipStateSummaryRequest,
34 ) -> BoxFut<'_, K2Result<GossipStateSummary>>;
35}
36
37pub type DynGossip = Arc<dyn Gossip>;
39
40pub trait GossipFactory: 'static + Send + Sync + std::fmt::Debug {
42 fn default_config(&self, config: &mut config::Config) -> K2Result<()>;
45
46 fn validate_config(&self, config: &config::Config) -> K2Result<()>;
48
49 #[allow(clippy::too_many_arguments)]
51 fn create(
52 &self,
53 builder: Arc<builder::Builder>,
54 space_id: SpaceId,
55 peer_store: DynPeerStore,
56 local_agent_store: DynLocalAgentStore,
57 peer_meta_store: DynPeerMetaStore,
58 op_store: DynOpStore,
59 transport: DynTransport,
60 fetch: DynFetch,
61 ) -> BoxFut<'static, K2Result<DynGossip>>;
62}
63
64pub type DynGossipFactory = Arc<dyn GossipFactory>;
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct DhtSegmentState {
70 pub disc_top_hash: bytes::Bytes,
72 pub disc_boundary: Timestamp,
74 pub ring_top_hashes: Vec<bytes::Bytes>,
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct PeerMeta {
81 pub last_gossip_timestamp: Option<Timestamp>,
83 pub new_ops_bookmark: Option<Timestamp>,
85 pub peer_behavior_errors: Option<u32>,
87 pub local_errors: Option<u32>,
89 pub peer_busy: Option<u32>,
91 pub peer_terminated: Option<u32>,
95 pub completed_rounds: Option<u32>,
97 pub peer_timeouts: Option<u32>,
99 pub is_tombstone: bool,
101 pub storage_arc: DhtArc,
103}
104
105#[derive(Debug, Clone, Serialize, Deserialize)]
107pub struct GossipRoundStateSummary {
108 pub session_with_peer: Url,
110}
111
112#[derive(Debug, Clone, Serialize, Deserialize)]
114pub struct GossipStateSummary {
115 pub initiated_round: Option<GossipRoundStateSummary>,
117 pub accepted_rounds: Vec<GossipRoundStateSummary>,
119 pub dht_summary: HashMap<String, DhtSegmentState>,
121 pub peer_meta: HashMap<Url, PeerMeta>,
123}