1use crate::network::TcpNetworkConfig;
2use std::time::Duration;
3
4#[derive(Debug, Clone)]
5pub struct RabiaConfig {
6 pub phase_timeout: Duration,
7 pub sync_timeout: Duration,
8 pub max_batch_size: usize,
9 pub max_pending_batches: usize,
10 pub cleanup_interval: Duration,
11 pub max_phase_history: usize,
12 pub heartbeat_interval: Duration,
13 pub randomization_seed: Option<u64>,
14 pub max_retries: usize,
15 pub backoff_base: Duration,
16 pub backoff_max: Duration,
17 pub network_config: TcpNetworkConfig,
18}
19
20impl Default for RabiaConfig {
21 fn default() -> Self {
22 Self {
23 phase_timeout: Duration::from_millis(5000),
24 sync_timeout: Duration::from_millis(10000),
25 max_batch_size: 1000,
26 max_pending_batches: 100,
27 cleanup_interval: Duration::from_secs(30),
28 max_phase_history: 1000,
29 heartbeat_interval: Duration::from_millis(1000),
30 randomization_seed: None,
31 max_retries: 3,
32 backoff_base: Duration::from_millis(100),
33 backoff_max: Duration::from_secs(10),
34 network_config: TcpNetworkConfig::default(),
35 }
36 }
37}
38
39impl RabiaConfig {
40 pub fn new() -> Self {
41 Self::default()
42 }
43
44 pub fn with_phase_timeout(mut self, timeout: Duration) -> Self {
45 self.phase_timeout = timeout;
46 self
47 }
48
49 pub fn with_sync_timeout(mut self, timeout: Duration) -> Self {
50 self.sync_timeout = timeout;
51 self
52 }
53
54 pub fn with_max_batch_size(mut self, size: usize) -> Self {
55 self.max_batch_size = size;
56 self
57 }
58
59 pub fn with_cleanup_interval(mut self, interval: Duration) -> Self {
60 self.cleanup_interval = interval;
61 self
62 }
63
64 pub fn with_randomization_seed(mut self, seed: u64) -> Self {
65 self.randomization_seed = Some(seed);
66 self
67 }
68
69 pub fn with_network_config(mut self, config: TcpNetworkConfig) -> Self {
70 self.network_config = config;
71 self
72 }
73}