Struct ConnectionState

Source
pub struct ConnectionState {
    pub node_id: NodeId,
    pub room_code: String,
    pub client_name: Option<String>,
    pub connected_at: Instant,
    pub last_ping: Instant,
    pub latency_us: u64,
    pub reconnect_count: u32,
    pub clock_offset: i64,
}
Expand description

Connection state for a single WebSocket client.

Fields§

§node_id: NodeId

Unique identifier for this connection.

§room_code: String

Room code the client joined.

§client_name: Option<String>

Client-provided name (optional).

§connected_at: Instant

When the connection was established.

§last_ping: Instant

When the last ping/pong was received.

§latency_us: u64

Measured round-trip latency in microseconds.

§reconnect_count: u32

Number of reconnections for this node.

§clock_offset: i64

Clock offset in microseconds (positive = client ahead).

Implementations§

Source§

impl ConnectionState

Source

pub fn new( node_id: NodeId, room_code: String, client_name: Option<String>, ) -> Self

Create a new connection state.

Source

pub fn update_latency(&mut self, rtt_us: u64)

Update latency from ping/pong exchange.

§Arguments
  • rtt_us - Round-trip time in microseconds
Source

pub fn update_clock_offset( &mut self, client_send: u64, server_receive: u64, server_send: u64, client_receive: u64, )

Update clock offset from ping/pong exchange.

Uses NTP-style calculation to determine the difference between client and server clocks.

Source

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

Check if the connection should be considered stale.

Source

pub fn mark_reconnected(&mut self)

Mark as reconnected, incrementing the counter.

Source

pub fn client_to_server_time(&self, client_time: u64) -> u64

Convert a client timestamp to server time using the clock offset.

Source

pub fn server_to_client_time(&self, server_time: u64) -> u64

Convert a server timestamp to client time using the clock offset.

Trait Implementations§

Source§

impl Clone for ConnectionState

Source§

fn clone(&self) -> ConnectionState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ConnectionState

Source§

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

Formats the value using the given formatter. 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<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, 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.
§

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

§

fn vzip(self) -> V