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: NodeIdUnique identifier for this connection.
room_code: StringRoom code the client joined.
client_name: Option<String>Client-provided name (optional).
connected_at: InstantWhen the connection was established.
last_ping: InstantWhen the last ping/pong was received.
latency_us: u64Measured round-trip latency in microseconds.
reconnect_count: u32Number of reconnections for this node.
clock_offset: i64Clock offset in microseconds (positive = client ahead).
Implementations§
Source§impl ConnectionState
impl ConnectionState
Sourcepub fn new(
node_id: NodeId,
room_code: String,
client_name: Option<String>,
) -> Self
pub fn new( node_id: NodeId, room_code: String, client_name: Option<String>, ) -> Self
Create a new connection state.
Sourcepub fn update_latency(&mut self, rtt_us: u64)
pub fn update_latency(&mut self, rtt_us: u64)
Sourcepub fn update_clock_offset(
&mut self,
client_send: u64,
server_receive: u64,
server_send: u64,
client_receive: u64,
)
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.
Sourcepub fn is_stale(&self, timeout: Duration) -> bool
pub fn is_stale(&self, timeout: Duration) -> bool
Check if the connection should be considered stale.
Sourcepub fn mark_reconnected(&mut self)
pub fn mark_reconnected(&mut self)
Mark as reconnected, incrementing the counter.
Sourcepub fn client_to_server_time(&self, client_time: u64) -> u64
pub fn client_to_server_time(&self, client_time: u64) -> u64
Convert a client timestamp to server time using the clock offset.
Sourcepub fn server_to_client_time(&self, server_time: u64) -> u64
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
impl Clone for ConnectionState
Source§fn clone(&self) -> ConnectionState
fn clone(&self) -> ConnectionState
Returns a duplicate of the value. Read more
1.0.0 · 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 Freeze for ConnectionState
impl RefUnwindSafe for ConnectionState
impl Send for ConnectionState
impl Sync for ConnectionState
impl Unpin for ConnectionState
impl UnwindSafe for ConnectionState
Blanket Implementations§
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