Skip to main content

hyperstack_sdk/
config.rs

1use crate::auth::AuthConfig;
2use crate::store::DEFAULT_MAX_ENTRIES_PER_VIEW;
3use std::time::Duration;
4
5#[derive(Debug, Clone)]
6pub struct HyperStackConfig {
7    pub auto_reconnect: bool,
8    pub reconnect_intervals: Vec<Duration>,
9    pub max_reconnect_attempts: u32,
10    pub ping_interval: Duration,
11    pub initial_data_timeout: Duration,
12    pub max_entries_per_view: Option<usize>,
13    pub auth: Option<AuthConfig>,
14}
15
16impl Default for HyperStackConfig {
17    fn default() -> Self {
18        Self {
19            auto_reconnect: true,
20            reconnect_intervals: vec![
21                Duration::from_secs(1),
22                Duration::from_secs(2),
23                Duration::from_secs(4),
24                Duration::from_secs(8),
25                Duration::from_secs(16),
26            ],
27            max_reconnect_attempts: 5,
28            ping_interval: Duration::from_secs(15),
29            initial_data_timeout: Duration::from_secs(5),
30            max_entries_per_view: Some(DEFAULT_MAX_ENTRIES_PER_VIEW),
31            auth: None,
32        }
33    }
34}
35
36#[derive(Debug, Clone)]
37pub struct ConnectionConfig {
38    pub auto_reconnect: bool,
39    pub reconnect_intervals: Vec<Duration>,
40    pub max_reconnect_attempts: u32,
41    pub ping_interval: Duration,
42    pub auth: Option<AuthConfig>,
43}
44
45impl From<HyperStackConfig> for ConnectionConfig {
46    fn from(config: HyperStackConfig) -> Self {
47        Self {
48            auto_reconnect: config.auto_reconnect,
49            reconnect_intervals: config.reconnect_intervals,
50            max_reconnect_attempts: config.max_reconnect_attempts,
51            ping_interval: config.ping_interval,
52            auth: config.auth,
53        }
54    }
55}
56
57impl Default for ConnectionConfig {
58    fn default() -> Self {
59        HyperStackConfig::default().into()
60    }
61}