pub struct ServerConfig {Show 19 fields
pub bind_address: String,
pub transport: TransportProtocol,
pub transports: Option<Vec<TransportProtocol>>,
pub protocol_addresses: Option<HashMap<TransportProtocol, String>>,
pub default_serialization_format: SerializationFormat,
pub default_compression: CompressionAlgorithm,
pub default_encryption: EncryptionAlgorithm,
pub max_connections: usize,
pub handshake_timeout: Duration,
pub max_handshake_concurrency: usize,
pub write_timeout: Duration,
pub fanout_concurrency: usize,
pub connection_timeout: Duration,
pub default_heartbeat: HeartbeatConfig,
pub tls: TlsConfig,
pub max_message_size: usize,
pub device_conflict_strategy: DeviceConflictStrategy,
pub auth_enabled: bool,
pub auth_timeout: Duration,
}Expand description
服务端配置
Fields§
§bind_address: String监听地址(单个协议时使用,多协议时用作默认地址)
transport: TransportProtocol传输协议(单个)
transports: Option<Vec<TransportProtocol>>传输协议列表(用于同时监听多个协议)
protocol_addresses: Option<HashMap<TransportProtocol, String>>每个协议的独立地址配置(协议 -> 地址映射) 如果设置了此映射,每个协议将使用对应的地址
default_serialization_format: SerializationFormat序列化格式(默认格式)
default_compression: CompressionAlgorithm压缩算法(默认)
default_encryption: EncryptionAlgorithm加密算法(默认)
max_connections: usize最大连接数
handshake_timeout: Duration握手超时时间
max_handshake_concurrency: usize最大并发握手数
write_timeout: Duration单次连接写入超时时间
fanout_concurrency: usizefanout 发送最大并发度
connection_timeout: Duration连接超时时间
default_heartbeat: HeartbeatConfig默认心跳配置(可以为每个连接配置不同的心跳)
tls: TlsConfigTLS 配置(用于 HTTPS/WSS/QUIC)
max_message_size: usize消息大小限制(字节)
device_conflict_strategy: DeviceConflictStrategy设备冲突策略(用于多端设备管理)
auth_enabled: bool是否启用认证(如果启用,连接必须通过 token 验证才能收发消息)
auth_timeout: Duration认证超时时间(连接建立后,如果在此时间内未完成认证,连接将被关闭)
Implementations§
Source§impl ServerConfig
impl ServerConfig
Sourcepub fn with_format(self, format: SerializationFormat) -> Self
pub fn with_format(self, format: SerializationFormat) -> Self
设置默认序列化格式
Sourcepub fn with_compression(self, compression: CompressionAlgorithm) -> Self
pub fn with_compression(self, compression: CompressionAlgorithm) -> Self
设置默认压缩算法
Sourcepub fn with_encryption(self, encryption: EncryptionAlgorithm) -> Self
pub fn with_encryption(self, encryption: EncryptionAlgorithm) -> Self
设置默认加密算法
Sourcepub fn with_max_connections(self, max: usize) -> Self
pub fn with_max_connections(self, max: usize) -> Self
设置最大连接数
Sourcepub fn with_handshake_timeout(self, timeout: Duration) -> Self
pub fn with_handshake_timeout(self, timeout: Duration) -> Self
设置握手超时时间
Sourcepub fn with_max_handshake_concurrency(self, max: usize) -> Self
pub fn with_max_handshake_concurrency(self, max: usize) -> Self
设置最大并发握手数
Sourcepub fn with_write_timeout(self, timeout: Duration) -> Self
pub fn with_write_timeout(self, timeout: Duration) -> Self
设置单次连接写入超时时间
Sourcepub fn with_fanout_concurrency(self, max: usize) -> Self
pub fn with_fanout_concurrency(self, max: usize) -> Self
设置 fanout 发送最大并发度
Sourcepub fn with_protocols(self, protocols: Vec<TransportProtocol>) -> Self
pub fn with_protocols(self, protocols: Vec<TransportProtocol>) -> Self
启用多协议监听
Sourcepub fn with_protocol_address(
self,
protocol: TransportProtocol,
address: String,
) -> Self
pub fn with_protocol_address( self, protocol: TransportProtocol, address: String, ) -> Self
为特定协议设置监听地址
Sourcepub fn with_protocol_addresses(
self,
addresses: HashMap<TransportProtocol, String>,
) -> Self
pub fn with_protocol_addresses( self, addresses: HashMap<TransportProtocol, String>, ) -> Self
批量设置协议地址映射
Sourcepub fn get_protocol_address(&self, protocol: &TransportProtocol) -> String
pub fn get_protocol_address(&self, protocol: &TransportProtocol) -> String
获取指定协议的地址
Sourcepub fn with_heartbeat(self, heartbeat: HeartbeatConfig) -> Self
pub fn with_heartbeat(self, heartbeat: HeartbeatConfig) -> Self
设置默认心跳配置
Sourcepub fn with_connection_timeout(self, timeout: Duration) -> Self
pub fn with_connection_timeout(self, timeout: Duration) -> Self
设置连接超时
Sourcepub fn get_protocols(&self) -> Vec<TransportProtocol>
pub fn get_protocols(&self) -> Vec<TransportProtocol>
获取要使用的协议列表
Sourcepub fn with_device_conflict_strategy(
self,
strategy: DeviceConflictStrategy,
) -> Self
pub fn with_device_conflict_strategy( self, strategy: DeviceConflictStrategy, ) -> Self
设置设备冲突策略
Sourcepub fn enable_auth(self) -> Self
pub fn enable_auth(self) -> Self
启用认证
启用后,所有连接必须通过 token 验证才能收发消息
Sourcepub fn disable_auth(self) -> Self
pub fn disable_auth(self) -> Self
禁用认证(默认)
Sourcepub fn with_auth_timeout(self, timeout: Duration) -> Self
pub fn with_auth_timeout(self, timeout: Duration) -> Self
设置认证超时时间
连接建立后,如果在此时间内未完成认证,连接将被关闭 默认值为 30 秒
Trait Implementations§
Source§impl Clone for ServerConfig
impl Clone for ServerConfig
Source§fn clone(&self) -> ServerConfig
fn clone(&self) -> ServerConfig
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ServerConfig
impl Debug for ServerConfig
Source§impl Default for ServerConfig
impl Default for ServerConfig
Source§impl<'de> Deserialize<'de> for ServerConfig
impl<'de> Deserialize<'de> for ServerConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ServerConfig
impl RefUnwindSafe for ServerConfig
impl Send for ServerConfig
impl Sync for ServerConfig
impl Unpin for ServerConfig
impl UnsafeUnpin for ServerConfig
impl UnwindSafe for ServerConfig
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more