Skip to main content

arc_malachitebft_sync/
config.rs

1use std::time::Duration;
2
3use crate::scoring::Strategy;
4
5const DEFAULT_PARALLEL_REQUESTS: usize = 5;
6const DEFAULT_BATCH_SIZE: usize = 5;
7
8#[derive(Copy, Clone, Debug)]
9pub struct Config {
10    pub enabled: bool,
11    pub request_timeout: Duration,
12    pub max_request_size: usize,
13    pub max_response_size: usize,
14    pub parallel_requests: usize,
15    pub scoring_strategy: Strategy,
16    pub inactive_threshold: Option<Duration>,
17    pub batch_size: usize,
18}
19
20impl Config {
21    pub fn new(enabled: bool) -> Self {
22        Self {
23            enabled,
24            ..Default::default()
25        }
26    }
27
28    pub fn with_request_timeout(mut self, request_timeout: Duration) -> Self {
29        self.request_timeout = request_timeout;
30        self
31    }
32
33    pub fn with_max_request_size(mut self, max_request_size: usize) -> Self {
34        self.max_request_size = max_request_size;
35        self
36    }
37
38    pub fn with_max_response_size(mut self, max_response_size: usize) -> Self {
39        self.max_response_size = max_response_size;
40        self
41    }
42
43    pub fn with_parallel_requests(mut self, parallel_requests: usize) -> Self {
44        self.parallel_requests = parallel_requests;
45        self
46    }
47
48    pub fn with_scoring_strategy(mut self, scoring_strategy: Strategy) -> Self {
49        self.scoring_strategy = scoring_strategy;
50        self
51    }
52
53    pub fn with_inactive_threshold(mut self, inactive_threshold: Option<Duration>) -> Self {
54        self.inactive_threshold = inactive_threshold;
55        self
56    }
57
58    pub fn with_batch_size(mut self, batch_size: usize) -> Self {
59        self.batch_size = batch_size;
60        self
61    }
62}
63
64impl Default for Config {
65    fn default() -> Self {
66        Self {
67            enabled: true,
68            request_timeout: Duration::from_secs(10),
69            max_request_size: 1024 * 1024,       // 1 MiB
70            max_response_size: 10 * 1024 * 1024, // 10 MiB
71            parallel_requests: DEFAULT_PARALLEL_REQUESTS,
72            scoring_strategy: Strategy::default(),
73            inactive_threshold: None,
74            batch_size: DEFAULT_BATCH_SIZE,
75        }
76    }
77}