pub struct SessionManager { /* private fields */ }Expand description
Manager maintaining session slots, concurrency bounds, and token authentication.
Implementations§
Source§impl SessionManager
impl SessionManager
pub fn new() -> Self
Sourcepub fn pin_tracker(&self) -> &PinTracker
pub fn pin_tracker(&self) -> &PinTracker
Returns a reference to the PIN attempt tracker.
Sourcepub async fn has_active_session(&self) -> bool
pub async fn has_active_session(&self) -> bool
Checks if a session is currently pending or active.
Sourcepub async fn claim_pending(
&self,
session_id: String,
sender_ip: IpAddr,
cert_fingerprint: Option<String>,
cancel: CancellationToken,
) -> Result<(), StatusCode>
pub async fn claim_pending( &self, session_id: String, sender_ip: IpAddr, cert_fingerprint: Option<String>, cancel: CancellationToken, ) -> Result<(), StatusCode>
Claims the session slot for a pending prepare-upload request. Returns hyper::StatusCode::CONFLICT (409) if a session is already active or pending.
Sourcepub async fn clear_pending(&self, session_id: &str)
pub async fn clear_pending(&self, session_id: &str)
Releases the pending session if it still matches session_id.
Sourcepub async fn activate_session(
&self,
session_id: &str,
sender_ip: IpAddr,
cert_fingerprint: Option<String>,
files: HashMap<String, SessionFile>,
) -> Result<(), StatusCode>
pub async fn activate_session( &self, session_id: &str, sender_ip: IpAddr, cert_fingerprint: Option<String>, files: HashMap<String, SessionFile>, ) -> Result<(), StatusCode>
Promotes a pending session into an active upload session with accepted files.
Sourcepub async fn validate_and_start_upload(
&self,
session_id: &str,
file_id: &str,
token: &str,
sender_ip: IpAddr,
) -> Result<SessionFile, StatusCode>
pub async fn validate_and_start_upload( &self, session_id: &str, file_id: &str, token: &str, sender_ip: IpAddr, ) -> Result<SessionFile, StatusCode>
Validates upload authorization parameters for /api/localsend/v2/upload.
Verifies:
- An active session exists matching
session_id. - Sender IP matches the session’s recorded IP.
- The requested
file_idwas accepted and has not completed. - The upload
tokenmatches the token issued during prepare-upload.
Returns the corresponding SessionFile and sets its status to InProgress.
Sourcepub async fn mark_file_status(
&self,
session_id: &str,
file_id: &str,
status: FileTransferStatus,
) -> bool
pub async fn mark_file_status( &self, session_id: &str, file_id: &str, status: FileTransferStatus, ) -> bool
Updates the status of a file in the active session. If all files reach terminal status, the session is completed and the slot is freed. Returns whether the entire session finished.
Sourcepub async fn cancel_session(
&self,
session_id: Option<&str>,
remote_ip: IpAddr,
) -> Option<SessionEndReason>
pub async fn cancel_session( &self, session_id: Option<&str>, remote_ip: IpAddr, ) -> Option<SessionEndReason>
Cancels the session if the request matches the current pending or active session.
Returns Some(SessionEndReason) if an active or pending session was cancelled.
Sourcepub async fn abort_locally(&self) -> Option<SessionEndReason>
pub async fn abort_locally(&self) -> Option<SessionEndReason>
Forcibly aborts and clears the current session locally.