pub struct ClientDatabase { /* private fields */ }Expand description
Thread-safe client database with file persistence
Implementations§
Source§impl ClientDatabase
impl ClientDatabase
Sourcepub fn load(file_path: &Path, network_config: VpnNetworkConfig) -> Result<Self>
pub fn load(file_path: &Path, network_config: VpnNetworkConfig) -> Result<Self>
Load or create client database from file
Sourcepub fn add_client(&self, name: &str) -> Result<ClientConfig>
pub fn add_client(&self, name: &str) -> Result<ClientConfig>
Add a new client, returns the generated config
pub fn network_config(&self) -> VpnNetworkConfig
Sourcepub fn remove_client(&self, client_id: &str) -> Result<()>
pub fn remove_client(&self, client_id: &str) -> Result<()>
Remove a client by ID
Sourcepub fn list_clients(&self) -> Vec<ClientConfig>
pub fn list_clients(&self) -> Vec<ClientConfig>
Get all clients
Sourcepub fn find_by_psk(&self, psk: &[u8; 32]) -> Option<ClientConfig>
pub fn find_by_psk(&self, psk: &[u8; 32]) -> Option<ClientConfig>
Find client by PSK (used during handshake to identify the connecting client)
Sourcepub fn find_by_vpn_ip(&self, ip: &Ipv4Addr) -> Option<ClientConfig>
pub fn find_by_vpn_ip(&self, ip: &Ipv4Addr) -> Option<ClientConfig>
Find client by VPN IP
Sourcepub fn find_by_id(&self, id: &str) -> Option<ClientConfig>
pub fn find_by_id(&self, id: &str) -> Option<ClientConfig>
Find client by ID
Sourcepub fn record_handshake(&self, client_id: &str)
pub fn record_handshake(&self, client_id: &str)
Update client stats (called from gateway on traffic)
Sourcepub fn record_traffic(&self, client_id: &str, bytes_in: u64, bytes_out: u64)
pub fn record_traffic(&self, client_id: &str, bytes_in: u64, bytes_out: u64)
Update traffic counters
Sourcepub fn flush_stats(&self)
pub fn flush_stats(&self)
Persist stats periodically (called from a background task)
Sourcepub fn reload_if_changed(&self) -> bool
pub fn reload_if_changed(&self) -> bool
Reload client database from disk if the file has changed. Preserves in-memory traffic stats for existing clients. Returns true if the client configuration changed.
Auto Trait Implementations§
impl !Freeze for ClientDatabase
impl !RefUnwindSafe for ClientDatabase
impl Send for ClientDatabase
impl Sync for ClientDatabase
impl Unpin for ClientDatabase
impl UnsafeUnpin for ClientDatabase
impl UnwindSafe for ClientDatabase
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