pub struct PeerSession {
pub peer_node_id: NodeId,
pub state: SessionState,
pub created_at_ms: u64,
pub last_activity_ms: u64,
pub outbound_counter: u64,
pub inbound_counter: u64,
/* private fields */
}Expand description
A per-peer E2EE session
Fields§
§peer_node_id: NodeIdPeer’s node ID
state: SessionStateSession state
created_at_ms: u64Timestamp when session was created
last_activity_ms: u64Timestamp of last activity
outbound_counter: u64Outbound message counter (for replay protection)
inbound_counter: u64Highest inbound message counter seen (for replay protection)
Implementations§
Source§impl PeerSession
impl PeerSession
Sourcepub fn new_initiator(peer_node_id: NodeId, now_ms: u64) -> Self
pub fn new_initiator(peer_node_id: NodeId, now_ms: u64) -> Self
Create a new session in awaiting state (we initiated)
Sourcepub fn new_responder(
peer_node_id: NodeId,
session_key: PeerSessionKey,
peer_public_key: [u8; 32],
now_ms: u64,
) -> Self
pub fn new_responder( peer_node_id: NodeId, session_key: PeerSessionKey, peer_public_key: [u8; 32], now_ms: u64, ) -> Self
Create a new established session (peer initiated, we’re responding)
Sourcepub fn complete_handshake(
&mut self,
session_key: PeerSessionKey,
peer_public_key: [u8; 32],
now_ms: u64,
)
pub fn complete_handshake( &mut self, session_key: PeerSessionKey, peer_public_key: [u8; 32], now_ms: u64, )
Complete the handshake (transition from AwaitingPeerKey to Established)
Sourcepub fn is_established(&self) -> bool
pub fn is_established(&self) -> bool
Check if session is established
Sourcepub fn is_expired(&self, now_ms: u64, timeout_ms: u64) -> bool
pub fn is_expired(&self, now_ms: u64, timeout_ms: u64) -> bool
Check if session is expired
Sourcepub fn next_outbound_counter(&mut self) -> u64
pub fn next_outbound_counter(&mut self) -> u64
Get next outbound message counter and increment
Sourcepub fn validate_inbound_counter(&mut self, counter: u64) -> bool
pub fn validate_inbound_counter(&mut self, counter: u64) -> bool
Validate and update inbound message counter (replay protection)
Returns true if the counter is valid (not previously seen). Uses >= check with next-counter storage to accept counter 0 initially.
Sourcepub fn session_key(&self) -> Option<&PeerSessionKey>
pub fn session_key(&self) -> Option<&PeerSessionKey>
Get the session key (if established)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PeerSession
impl RefUnwindSafe for PeerSession
impl Send for PeerSession
impl Sync for PeerSession
impl Unpin for PeerSession
impl UnwindSafe for PeerSession
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