PeerSession

Struct PeerSession 

Source
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: NodeId

Peer’s node ID

§state: SessionState

Session state

§created_at_ms: u64

Timestamp when session was created

§last_activity_ms: u64

Timestamp of last activity

§outbound_counter: u64

Outbound message counter (for replay protection)

§inbound_counter: u64

Highest inbound message counter seen (for replay protection)

Implementations§

Source§

impl PeerSession

Source

pub fn new_initiator(peer_node_id: NodeId, now_ms: u64) -> Self

Create a new session in awaiting state (we initiated)

Source

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)

Source

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)

Source

pub fn is_established(&self) -> bool

Check if session is established

Source

pub fn is_expired(&self, now_ms: u64, timeout_ms: u64) -> bool

Check if session is expired

Source

pub fn next_outbound_counter(&mut self) -> u64

Get next outbound message counter and increment

Source

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.

Source

pub fn session_key(&self) -> Option<&PeerSessionKey>

Get the session key (if established)

Source

pub fn touch(&mut self, now_ms: u64)

Update last activity timestamp

Source

pub fn close(&mut self)

Close the session

Trait Implementations§

Source§

impl Debug for PeerSession

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> 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, 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.