Skip to main content

ConnectionInfo

Struct ConnectionInfo 

Source
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

Source

pub fn new(connection_id: String, requires_auth: bool) -> Self

创建新的连接信息

§参数
  • connection_id: 连接 ID
  • requires_auth: 是否需要认证(如果为 false,连接直接标记为已验证)
Source

pub fn set_authenticated(&mut self, user_id: Option<String>)

标记为已验证

Source

pub fn is_authenticated(&self) -> bool

检查连接是否已验证

Source

pub fn with_device_info(self, device_info: DeviceInfo) -> Self

设置设备信息

Source

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

设置序列化格式

Source

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

设置压缩算法

Source

pub fn is_timeout(&self, timeout: Duration) -> bool

检查连接是否超时

Source

pub fn update_active(&mut self)

更新最后活跃时间

Trait Implementations§

Source§

impl Clone for ConnectionInfo

Source§

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)

Performs copy-assignment from source. 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> 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