pub struct ConnectionInfo {Show 15 fields
pub connection_id: String,
pub user_id: Option<String>,
pub created_at: Instant,
pub last_active: Instant,
pub metadata: HashMap<String, String>,
pub device_info: Option<DeviceInfo>,
pub serialization_format: SerializationFormat,
pub compression: CompressionAlgorithm,
pub encryption: EncryptionAlgorithm,
pub authenticated: bool,
pub authenticated_at: Option<u64>,
pub negotiation_completed: bool,
pub negotiation_confirmed: bool,
pub cached_parser: Option<Arc<MessageParser>>,
pub cached_pipeline: Option<Arc<MessagePipeline>>,
}Expand description
连接信息
Fields§
§connection_id: String连接 ID(唯一标识符)
user_id: Option<String>用户 ID(如果已认证)
created_at: Instant创建时间
last_active: Instant最后活跃时间
metadata: HashMap<String, String>连接元数据
device_info: Option<DeviceInfo>设备信息(如果已提供)
serialization_format: SerializationFormat序列化格式(由客户端协商决定,默认 JSON)
compression: CompressionAlgorithm压缩算法(由客户端协商决定,默认不压缩)
encryption: EncryptionAlgorithm加密凡事(协商决定)
authenticated: bool是否已验证(如果启用认证,只有已验证的连接才能收发消息)
authenticated_at: Option<u64>认证时间戳(Unix 时间戳,秒,如果已验证)
negotiation_completed: bool协商是否已完成(CONNECT 和 CONNECT_ACK 完成)
negotiation_confirmed: bool协商是否已确认(客户端收到 CONNECT_ACK 后发送确认,服务端收到后标记) 确认后,消息必须严格按照协商好的方式处理,不再容错
cached_parser: Option<Arc<MessageParser>>缓存的 MessageParser(协商完成后创建,避免每次消息处理都创建新的 parser)
cached_pipeline: Option<Arc<MessagePipeline>>缓存的 MessagePipeline(协商完成后创建,如果配置了中间件或处理器)
Implementations§
Source§impl ConnectionInfo
impl ConnectionInfo
Sourcepub fn set_authenticated(&mut self, user_id: Option<String>)
pub fn set_authenticated(&mut self, user_id: Option<String>)
标记为已验证
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
检查连接是否已验证
Sourcepub fn with_device_info(self, device_info: DeviceInfo) -> Self
pub fn with_device_info(self, device_info: DeviceInfo) -> Self
设置设备信息
Sourcepub fn with_serialization_format(self, format: SerializationFormat) -> Self
pub fn with_serialization_format(self, format: SerializationFormat) -> Self
设置序列化格式
Sourcepub fn with_compression(self, compression: CompressionAlgorithm) -> Self
pub fn with_compression(self, compression: CompressionAlgorithm) -> Self
设置压缩算法
Sourcepub fn is_timeout(&self, timeout: Duration) -> bool
pub fn is_timeout(&self, timeout: Duration) -> bool
检查连接是否超时
Sourcepub fn update_active(&mut self)
pub fn update_active(&mut self)
更新最后活跃时间
Trait Implementations§
Source§impl Clone for ConnectionInfo
impl Clone for ConnectionInfo
Source§fn clone(&self) -> ConnectionInfo
fn clone(&self) -> ConnectionInfo
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 moreAuto Trait Implementations§
impl !RefUnwindSafe for ConnectionInfo
impl !UnwindSafe for ConnectionInfo
impl Freeze for ConnectionInfo
impl Send for ConnectionInfo
impl Sync for ConnectionInfo
impl Unpin for ConnectionInfo
impl UnsafeUnpin for ConnectionInfo
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