pub struct PeerSessionManager { /* private fields */ }Expand description
Manager for all per-peer E2EE sessions
Implementations§
Source§impl PeerSessionManager
impl PeerSessionManager
Sourcepub fn new(our_node_id: NodeId) -> Self
pub fn new(our_node_id: NodeId) -> Self
Create a new session manager with a generated identity key
Sourcepub fn with_identity_key(
our_node_id: NodeId,
identity_key: PeerIdentityKey,
) -> Self
pub fn with_identity_key( our_node_id: NodeId, identity_key: PeerIdentityKey, ) -> Self
Create with a specific identity key
Sourcepub fn with_max_sessions(self, max: usize) -> Self
pub fn with_max_sessions(self, max: usize) -> Self
Configure maximum sessions
Sourcepub fn with_session_timeout(self, timeout_ms: u64) -> Self
pub fn with_session_timeout(self, timeout_ms: u64) -> Self
Configure session timeout
Sourcepub fn our_public_key(&self) -> [u8; 32]
pub fn our_public_key(&self) -> [u8; 32]
Get our public key bytes (for sharing with peers)
Sourcepub fn our_node_id(&self) -> NodeId
pub fn our_node_id(&self) -> NodeId
Get our node ID
Sourcepub fn initiate_session(
&mut self,
peer_node_id: NodeId,
now_ms: u64,
) -> KeyExchangeMessage
pub fn initiate_session( &mut self, peer_node_id: NodeId, now_ms: u64, ) -> KeyExchangeMessage
Initiate an E2EE session with a peer
Returns a key exchange message to send to the peer.
Sourcepub fn handle_key_exchange(
&mut self,
msg: &KeyExchangeMessage,
now_ms: u64,
) -> Option<(KeyExchangeMessage, bool)>
pub fn handle_key_exchange( &mut self, msg: &KeyExchangeMessage, now_ms: u64, ) -> Option<(KeyExchangeMessage, bool)>
Handle incoming key exchange message from peer
Returns:
Some((response, established))if we should respond (response is our key exchange message)Noneif the message is invalid or session limit reached
Sourcepub fn has_session(&self, peer_node_id: NodeId) -> bool
pub fn has_session(&self, peer_node_id: NodeId) -> bool
Check if we have an established session with a peer
Sourcepub fn session_state(&self, peer_node_id: NodeId) -> Option<SessionState>
pub fn session_state(&self, peer_node_id: NodeId) -> Option<SessionState>
Get session state for a peer
Sourcepub fn encrypt_for_peer(
&mut self,
peer_node_id: NodeId,
plaintext: &[u8],
now_ms: u64,
) -> Result<PeerEncryptedMessage, EncryptionError>
pub fn encrypt_for_peer( &mut self, peer_node_id: NodeId, plaintext: &[u8], now_ms: u64, ) -> Result<PeerEncryptedMessage, EncryptionError>
Encrypt a message for a specific peer
Returns the encrypted message, or an error if no established session exists.
Sourcepub fn decrypt_from_peer(
&mut self,
msg: &PeerEncryptedMessage,
now_ms: u64,
) -> Result<Vec<u8>, EncryptionError>
pub fn decrypt_from_peer( &mut self, msg: &PeerEncryptedMessage, now_ms: u64, ) -> Result<Vec<u8>, EncryptionError>
Decrypt a message from a peer
Returns the plaintext, or an error if decryption fails.
Sourcepub fn close_session(&mut self, peer_node_id: NodeId)
pub fn close_session(&mut self, peer_node_id: NodeId)
Close a session with a peer
Sourcepub fn remove_session(&mut self, peer_node_id: NodeId) -> Option<PeerSession>
pub fn remove_session(&mut self, peer_node_id: NodeId) -> Option<PeerSession>
Remove a session entirely
Sourcepub fn cleanup_expired(&mut self, now_ms: u64) -> Vec<NodeId>
pub fn cleanup_expired(&mut self, now_ms: u64) -> Vec<NodeId>
Cleanup expired sessions
Sourcepub fn session_count(&self) -> usize
pub fn session_count(&self) -> usize
Get number of active sessions
Sourcepub fn established_count(&self) -> usize
pub fn established_count(&self) -> usize
Get number of established sessions