Skip to main content

ServerConfig

Struct ServerConfig 

Source
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: usize

fanout 发送最大并发度

§connection_timeout: Duration

连接超时时间

§default_heartbeat: HeartbeatConfig

默认心跳配置(可以为每个连接配置不同的心跳)

§tls: TlsConfig

TLS 配置(用于 HTTPS/WSS/QUIC)

§max_message_size: usize

消息大小限制(字节)

§device_conflict_strategy: DeviceConflictStrategy

设备冲突策略(用于多端设备管理)

§auth_enabled: bool

是否启用认证(如果启用,连接必须通过 token 验证才能收发消息)

§auth_timeout: Duration

认证超时时间(连接建立后,如果在此时间内未完成认证,连接将被关闭)

Implementations§

Source§

impl ServerConfig

Source

pub fn new(bind_address: String) -> Self

创建新的服务端配置

Source

pub fn websocket(self) -> Self

使用 WebSocket 协议

Source

pub fn quic(self) -> Self

使用 QUIC 协议

Source

pub fn tcp(self) -> Self

使用 TCP 协议

Source

pub fn with_format(self, format: SerializationFormat) -> Self

设置默认序列化格式

Source

pub fn with_compression(self, compression: CompressionAlgorithm) -> Self

设置默认压缩算法

Source

pub fn with_encryption(self, encryption: EncryptionAlgorithm) -> Self

设置默认加密算法

Source

pub fn with_max_connections(self, max: usize) -> Self

设置最大连接数

Source

pub fn with_handshake_timeout(self, timeout: Duration) -> Self

设置握手超时时间

Source

pub fn with_max_handshake_concurrency(self, max: usize) -> Self

设置最大并发握手数

Source

pub fn with_write_timeout(self, timeout: Duration) -> Self

设置单次连接写入超时时间

Source

pub fn with_fanout_concurrency(self, max: usize) -> Self

设置 fanout 发送最大并发度

Source

pub fn with_protocols(self, protocols: Vec<TransportProtocol>) -> Self

启用多协议监听

Source

pub fn with_protocol_address( self, protocol: TransportProtocol, address: String, ) -> Self

为特定协议设置监听地址

Source

pub fn with_protocol_addresses( self, addresses: HashMap<TransportProtocol, String>, ) -> Self

批量设置协议地址映射

Source

pub fn get_protocol_address(&self, protocol: &TransportProtocol) -> String

获取指定协议的地址

Source

pub fn with_heartbeat(self, heartbeat: HeartbeatConfig) -> Self

设置默认心跳配置

Source

pub fn with_tls(self, tls: TlsConfig) -> Self

设置 TLS 配置

Source

pub fn with_connection_timeout(self, timeout: Duration) -> Self

设置连接超时

Source

pub fn get_protocols(&self) -> Vec<TransportProtocol>

获取要使用的协议列表

Source

pub fn with_device_conflict_strategy( self, strategy: DeviceConflictStrategy, ) -> Self

设置设备冲突策略

Source

pub fn enable_auth(self) -> Self

启用认证

启用后,所有连接必须通过 token 验证才能收发消息

Source

pub fn disable_auth(self) -> Self

禁用认证(默认)

Source

pub fn with_auth_timeout(self, timeout: Duration) -> Self

设置认证超时时间

连接建立后,如果在此时间内未完成认证,连接将被关闭 默认值为 30 秒

Trait Implementations§

Source§

impl Clone for ServerConfig

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for ServerConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ServerConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ServerConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ServerConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more