feat: track uploads with progress and cancellation
serve_file streams in chunks, updating a shared byte counter and aborting with Interrupted when a cancel flag is set. Each served upload is registered (peer, virtual path, size, live progress, status) and exposed via Client::uploads(); Client::cancel_upload flags a matching in-progress transfer. e2e: the download test now also asserts the uploader recorded a completed upload with the right peer and byte count.
This commit is contained in:
@@ -251,3 +251,24 @@ mod tests {
|
||||
assert_eq!(transfer.size, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// Lifecycle of a file we are serving to a peer.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum UploadStatus {
|
||||
InProgress,
|
||||
Completed,
|
||||
Cancelled,
|
||||
Failed(String),
|
||||
}
|
||||
|
||||
/// A snapshot of one upload for display purposes.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UploadInfo {
|
||||
/// The peer receiving the file.
|
||||
pub username: String,
|
||||
/// The peer-facing virtual path being served.
|
||||
pub filename: String,
|
||||
pub size: u64,
|
||||
pub bytes_sent: u64,
|
||||
pub status: UploadStatus,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user