use crate::common::compression::CompressionAlgorithm;
use crate::common::config_types::{HeartbeatConfig, TlsConfig, TransportProtocol};
use crate::common::device::DeviceConflictStrategy;
use crate::common::encryption::EncryptionAlgorithm;
use crate::common::protocol::SerializationFormat;
use crate::server::config::ServerConfig;
use std::sync::Arc;
use std::time::Duration;
pub struct BaseServerBuilderConfig {
pub config: ServerConfig,
pub authenticator: Option<Arc<dyn crate::server::auth::Authenticator>>,
}
impl BaseServerBuilderConfig {
pub fn new(bind_address: impl Into<String>) -> Self {
Self {
config: ServerConfig::new(bind_address.into()),
authenticator: None,
}
}
#[must_use]
pub fn with_authenticator(
mut self,
authenticator: Arc<dyn crate::server::auth::Authenticator>,
) -> Self {
self.authenticator = Some(authenticator);
self
}
#[must_use]
pub fn enable_auth(mut self) -> Self {
self.config = self.config.enable_auth();
self
}
#[must_use]
pub fn with_auth_timeout(mut self, timeout: Duration) -> Self {
self.config = self.config.with_auth_timeout(timeout);
self
}
#[must_use]
pub fn with_protocol(mut self, protocol: TransportProtocol) -> Self {
self.config.transport = protocol;
self
}
#[must_use]
pub fn with_protocols(mut self, protocols: Vec<TransportProtocol>) -> Self {
self.config = self.config.with_protocols(protocols);
self
}
#[must_use]
pub fn with_protocol_address(mut self, protocol: TransportProtocol, address: String) -> Self {
self.config = self.config.with_protocol_address(protocol, address);
self
}
#[must_use]
pub fn with_max_connections(mut self, max: usize) -> Self {
self.config = self.config.with_max_connections(max);
self
}
#[must_use]
pub fn with_handshake_timeout(mut self, timeout: Duration) -> Self {
self.config = self.config.with_handshake_timeout(timeout);
self
}
#[must_use]
pub fn with_max_handshake_concurrency(mut self, max: usize) -> Self {
self.config = self.config.with_max_handshake_concurrency(max);
self
}
#[must_use]
pub fn with_write_timeout(mut self, timeout: Duration) -> Self {
self.config = self.config.with_write_timeout(timeout);
self
}
#[must_use]
pub fn with_fanout_concurrency(mut self, max: usize) -> Self {
self.config = self.config.with_fanout_concurrency(max);
self
}
#[must_use]
pub fn with_connection_timeout(mut self, timeout: Duration) -> Self {
self.config = self.config.with_connection_timeout(timeout);
self
}
#[must_use]
pub fn with_heartbeat(mut self, heartbeat: HeartbeatConfig) -> Self {
self.config = self.config.with_heartbeat(heartbeat);
self
}
#[must_use]
pub fn with_tls(mut self, tls: TlsConfig) -> Self {
self.config = self.config.with_tls(tls);
self
}
#[must_use]
pub fn with_default_format(mut self, format: SerializationFormat) -> Self {
self.config = self.config.with_format(format);
self
}
#[must_use]
pub fn with_default_compression(mut self, compression: CompressionAlgorithm) -> Self {
self.config = self.config.with_compression(compression);
self
}
#[must_use]
pub fn with_default_encryption(mut self, encryption: EncryptionAlgorithm) -> Self {
self.config = self.config.with_encryption(encryption);
self
}
#[must_use]
pub fn with_device_conflict_strategy(mut self, strategy: DeviceConflictStrategy) -> Self {
self.config = self.config.with_device_conflict_strategy(strategy);
self
}
}