pub struct Session {Show 31 fields
pub session_id: [u8; 16],
pub client_addr: SocketAddr,
pub state: SessionState,
pub keys: SessionKeys,
pub eph_pub: [u8; 32],
pub counter: u64,
pub last_seen: Instant,
pub created_at: Instant,
pub last_server_send: Instant,
pub mask: Option<MaskProfile>,
pub pending_mask: Option<(MaskProfile, Instant)>,
pub fsm_state: u16,
pub fsm_packets: u32,
pub fsm_state_start: Instant,
pub send_seq: u32,
pub recv_seq: u32,
pub send_counter: u64,
pub expected_tags: HashMap<u64, [u8; 8]>,
pub tag_window_base: u64,
pub received_bitmap: u256,
pub pending_bytes_in: u64,
pub pending_bytes_out: u64,
pub server_eph_pub: Option<[u8; 32]>,
pub server_hello_signature: Option<[u8; 64]>,
pub ratcheted_keys: Option<SessionKeys>,
pub ratcheted_expected_tags: HashMap<u64, [u8; 8]>,
pub is_ratcheted: bool,
pub vpn_ip: Option<Ipv4Addr>,
pub client_id: Option<String>,
pub pre_ratchet_tags: HashMap<u64, [u8; 8]>,
pub pre_ratchet_expire: Option<Instant>,
}Expand description
Session information
Fields§
§session_id: [u8; 16]§client_addr: SocketAddr§state: SessionState§keys: SessionKeys§eph_pub: [u8; 32]§counter: u64Packet counter for tag generation
last_seen: InstantLast seen timestamp
created_at: InstantCreated timestamp
last_server_send: InstantLast server-to-client packet timestamp (for downlink recording IAT)
mask: Option<MaskProfile>Current mask profile
pending_mask: Option<(MaskProfile, Instant)>Pending mask awaiting grace period before activation. Stored as (new_mask, timestamp_when_MaskUpdate_was_sent).
fsm_state: u16Current FSM state
fsm_packets: u32Packets in current FSM state
fsm_state_start: InstantDuration in current FSM state
send_seq: u32Sequence number for outgoing packets
recv_seq: u32Last received sequence (for ACK)
send_counter: u64Send counter for nonce generation (u64, same space as tags)
Expected tags (counter -> tag)
tag_window_base: u64Counter value used as the base for the currently precomputed tag window.
received_bitmap: u256Received tag bitmap (for anti-replay)
pending_bytes_in: u64Accumulated inbound bytes to flush into client_db in batches.
pending_bytes_out: u64Accumulated outbound (downlink) bytes to flush into client_db in batches.
server_eph_pub: Option<[u8; 32]>Server’s ephemeral public key for this session
server_hello_signature: Option<[u8; 64]>Ed25519 signature for ServerHello
ratcheted_keys: Option<SessionKeys>Ratcheted session keys (PFS)
Ratcheted tags for validation (counter -> tag)
is_ratcheted: boolWhether session has completed PFS ratchet
vpn_ip: Option<Ipv4Addr>Assigned VPN IP (e.g. 10.0.0.2)
client_id: Option<String>Registered client ID (from client_db) for traffic accounting
Pre-ratchet expected tags preserved for a 2-second grace window after complete_ratchet() so client packets that were already in-flight with the old keys are not silently dropped as unrecognised.
pre_ratchet_expire: Option<Instant>Deadline until which pre_ratchet_tags are still accepted.
Implementations§
Source§impl Session
impl Session
pub fn new( session_id: [u8; 16], client_addr: SocketAddr, keys: SessionKeys, eph_pub: [u8; 32], ) -> Self
Sourcepub fn next_send_nonce(&mut self) -> ([u8; 12], u64)
pub fn next_send_nonce(&mut self) -> ([u8; 12], u64)
Compute next nonce for encryption from send_counter (u64) Uses the same counter space as tag generation for consistency
Sourcepub fn update_tag_window(&mut self)
pub fn update_tag_window(&mut self)
Update expected tags for validation window
Sourcepub fn validate_tag(&self, tag: &[u8; 8]) -> Option<(u64, bool)>
pub fn validate_tag(&self, tag: &[u8; 8]) -> Option<(u64, bool)>
Validate received tag (constant-time) Returns (counter, is_ratcheted_tag) if valid. Checks the current time window first, then adjacent windows (±1) for clock skew tolerance.
Sourcepub fn mark_tag_received(&mut self, counter: u64)
pub fn mark_tag_received(&mut self, counter: u64)
Mark tag as received
Sourcepub fn update_fsm(&mut self)
pub fn update_fsm(&mut self)
Update FSM state
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if session is expired
Sourcepub fn update_ratcheted_tag_window(&mut self)
pub fn update_ratcheted_tag_window(&mut self)
Pre-compute tags for ratcheted keys
Sourcepub fn complete_ratchet(&mut self)
pub fn complete_ratchet(&mut self)
Complete PFS ratchet: switch to ratcheted keys, zeroize old ones
Sourcepub fn commit_pending_mask(&mut self) -> bool
pub fn commit_pending_mask(&mut self) -> bool
Check and commit a pending mask if the grace period has elapsed. Returns true if a mask was committed. Grace period = 500ms — enough for the MaskUpdate packet to reach the client.