keri_core/processor/escrow/
mod.rs1pub mod delegation_escrow;
2pub mod duplicitous_events;
3pub mod maybe_out_of_order_escrow;
4pub mod partially_signed_escrow;
5pub mod partially_witnessed_escrow;
6#[cfg(feature = "query")]
7pub mod reply_escrow;
8
9use std::{fmt::Debug, sync::Arc, time::Duration};
10
11use delegation_escrow::DelegationEscrow;
12use duplicitous_events::DuplicitousEvents;
13use maybe_out_of_order_escrow::MaybeOutOfOrderEscrow;
14use partially_signed_escrow::PartiallySignedEscrow;
15use partially_witnessed_escrow::PartiallyWitnessedEscrow;
16
17use super::notification::{JustNotification, NotificationBus};
18use crate::database::{EscrowCreator, EventDatabase};
19
20#[derive(Debug, Clone)]
21pub struct EscrowConfig {
22 pub out_of_order_timeout: Duration,
23 pub partially_signed_timeout: Duration,
24 pub partially_witnessed_timeout: Duration,
25 pub trans_receipt_timeout: Duration,
26 pub delegation_timeout: Duration,
27}
28
29impl Default for EscrowConfig {
30 fn default() -> Self {
31 Self {
32 out_of_order_timeout: Duration::from_secs(60),
33 partially_signed_timeout: Duration::from_secs(60),
34 partially_witnessed_timeout: Duration::from_secs(60),
35 trans_receipt_timeout: Duration::from_secs(60),
36 delegation_timeout: Duration::from_secs(60),
37 }
38 }
39}
40
41pub fn default_escrow_bus<D>(
42 event_db: Arc<D>,
43 escrow_config: EscrowConfig,
44) -> (
45 NotificationBus,
46 (
47 Arc<MaybeOutOfOrderEscrow<D>>,
48 Arc<PartiallySignedEscrow<D>>,
49 Arc<PartiallyWitnessedEscrow<D>>,
50 Arc<DelegationEscrow<D>>,
51 Arc<DuplicitousEvents<D>>,
52 ),
53)
54where
55 D: EventDatabase + EscrowCreator + Sync + Send + 'static,
56{
57 let mut bus = NotificationBus::new();
58
59 let ooo_escrow = Arc::new(MaybeOutOfOrderEscrow::new(
61 event_db.clone(),
62 escrow_config.out_of_order_timeout,
63 ));
64 bus.register_observer(
65 ooo_escrow.clone(),
66 vec![
67 JustNotification::OutOfOrder,
68 JustNotification::KeyEventAdded,
69 ],
70 );
71
72 let ps_escrow = Arc::new(PartiallySignedEscrow::new(
73 event_db.clone(),
74 escrow_config.partially_signed_timeout,
75 ));
76 bus.register_observer(ps_escrow.clone(), vec![JustNotification::PartiallySigned]);
77
78 let pw_escrow = Arc::new(PartiallyWitnessedEscrow::new(
79 event_db.clone(),
80 event_db.get_log_db(),
81 escrow_config.partially_witnessed_timeout,
82 ));
83 bus.register_observer(
84 pw_escrow.clone(),
85 vec![
86 JustNotification::PartiallyWitnessed,
87 JustNotification::ReceiptOutOfOrder,
88 ],
89 );
90
91 let delegation_escrow = Arc::new(DelegationEscrow::new(
92 event_db.clone(),
93 escrow_config.delegation_timeout,
94 ));
95 bus.register_observer(
96 delegation_escrow.clone(),
97 vec![
98 JustNotification::MissingDelegatingEvent,
99 JustNotification::KeyEventAdded,
100 ],
101 );
102
103 let dup = Arc::new(DuplicitousEvents::new(event_db));
104 bus.register_observer(dup.clone(), vec![JustNotification::DuplicitousEvent]);
105
106 (
107 bus,
108 (ooo_escrow, ps_escrow, pw_escrow, delegation_escrow, dup),
109 )
110}