flare_core/server/builder/
base.rs1use crate::common::compression::CompressionAlgorithm;
12use crate::common::config_types::{HeartbeatConfig, TlsConfig, TransportProtocol};
13use crate::common::device::DeviceConflictStrategy;
14use crate::common::encryption::EncryptionAlgorithm;
15use crate::common::protocol::SerializationFormat;
16use crate::server::config::ServerConfig;
17use std::sync::Arc;
18use std::time::Duration;
19
20pub struct BaseServerBuilderConfig {
25 pub config: ServerConfig,
26 pub authenticator: Option<Arc<dyn crate::server::auth::Authenticator>>,
27}
28
29impl BaseServerBuilderConfig {
30 pub fn new(bind_address: impl Into<String>) -> Self {
32 Self {
33 config: ServerConfig::new(bind_address.into()),
34 authenticator: None,
35 }
36 }
37
38 #[must_use]
40 pub fn with_authenticator(
41 mut self,
42 authenticator: Arc<dyn crate::server::auth::Authenticator>,
43 ) -> Self {
44 self.authenticator = Some(authenticator);
45 self
46 }
47
48 #[must_use]
50 pub fn enable_auth(mut self) -> Self {
51 self.config = self.config.enable_auth();
52 self
53 }
54
55 #[must_use]
57 pub fn with_auth_timeout(mut self, timeout: Duration) -> Self {
58 self.config = self.config.with_auth_timeout(timeout);
59 self
60 }
61
62 #[must_use]
64 pub fn with_protocol(mut self, protocol: TransportProtocol) -> Self {
65 self.config.transport = protocol;
66 self
67 }
68
69 #[must_use]
71 pub fn with_protocols(mut self, protocols: Vec<TransportProtocol>) -> Self {
72 self.config = self.config.with_protocols(protocols);
73 self
74 }
75
76 #[must_use]
78 pub fn with_protocol_address(mut self, protocol: TransportProtocol, address: String) -> Self {
79 self.config = self.config.with_protocol_address(protocol, address);
80 self
81 }
82
83 #[must_use]
85 pub fn with_max_connections(mut self, max: usize) -> Self {
86 self.config = self.config.with_max_connections(max);
87 self
88 }
89
90 #[must_use]
92 pub fn with_handshake_timeout(mut self, timeout: Duration) -> Self {
93 self.config = self.config.with_handshake_timeout(timeout);
94 self
95 }
96
97 #[must_use]
99 pub fn with_max_handshake_concurrency(mut self, max: usize) -> Self {
100 self.config = self.config.with_max_handshake_concurrency(max);
101 self
102 }
103
104 #[must_use]
106 pub fn with_write_timeout(mut self, timeout: Duration) -> Self {
107 self.config = self.config.with_write_timeout(timeout);
108 self
109 }
110
111 #[must_use]
113 pub fn with_fanout_concurrency(mut self, max: usize) -> Self {
114 self.config = self.config.with_fanout_concurrency(max);
115 self
116 }
117
118 #[must_use]
120 pub fn with_connection_timeout(mut self, timeout: Duration) -> Self {
121 self.config = self.config.with_connection_timeout(timeout);
122 self
123 }
124
125 #[must_use]
127 pub fn with_heartbeat(mut self, heartbeat: HeartbeatConfig) -> Self {
128 self.config = self.config.with_heartbeat(heartbeat);
129 self
130 }
131
132 #[must_use]
134 pub fn with_tls(mut self, tls: TlsConfig) -> Self {
135 self.config = self.config.with_tls(tls);
136 self
137 }
138
139 #[must_use]
141 pub fn with_default_format(mut self, format: SerializationFormat) -> Self {
142 self.config = self.config.with_format(format);
143 self
144 }
145
146 #[must_use]
148 pub fn with_default_compression(mut self, compression: CompressionAlgorithm) -> Self {
149 self.config = self.config.with_compression(compression);
150 self
151 }
152
153 #[must_use]
155 pub fn with_default_encryption(mut self, encryption: EncryptionAlgorithm) -> Self {
156 self.config = self.config.with_encryption(encryption);
157 self
158 }
159
160 #[must_use]
162 pub fn with_device_conflict_strategy(mut self, strategy: DeviceConflictStrategy) -> Self {
163 self.config = self.config.with_device_conflict_strategy(strategy);
164 self
165 }
166}