Skip to main content

FileTransferManager

Struct FileTransferManager 

Source
pub struct FileTransferManager { /* private fields */ }
Expand description

File transfer manager for chunking and reassembly.

Implementations§

Source§

impl FileTransferManager

Source

pub const MANUAL_SENDER: &'static str = "manual:ffi"

Pseudo-sender bound to assemblies fed through the manual process_file_chunk FFI path, which carries no wire sender. All manual chunks share this identity for sender binding and quota. The : is rejected by wire UserId validation, so no remote peer can ever claim this identity.

Source

pub fn new() -> Self

Creates a new file transfer manager.

Source

pub fn with_config(config: FileTransferConfig) -> Self

Creates a new file transfer manager with custom configuration.

max_total_buffered_bytes is clamped up to what a single max_file_size transfer charges (payload plus per-chunk overhead) — any lower value would make max_file_size unachievable.

Source

pub fn chunk_file( &self, file_id: String, file_name: String, file_data: Vec<u8>, chunk_size_override: Option<usize>, ) -> Result<Vec<FileChunk>>

Chunks a file for sending.

§Arguments
  • file_id - Unique identifier for this file transfer
  • file_name - Name of the file
  • file_data - Complete file data
  • chunk_size_override - If Some, uses this chunk size instead of the configured default. Allows callers to select a transport-appropriate chunk size.
§Returns

Returns a vector of FileChunk ready to send. Fails if the file is empty or exceeds max_file_size, if the chunk size is zero, or if the chunking is so fine that the chunk count would exceed the receive-side total_chunks cap — Self::process_chunk on a receiver with the same max_file_size would silently drop every chunk of such a transfer.

Source

pub fn process_chunk( &mut self, sender: &str, chunk: FileChunk, ) -> Result<FileProgress, ChunkRejection>

Processes a received file chunk from sender.

All wire-supplied fields (file_size, total_chunks, chunk_data, file_id) are bounded here before any assembly state is created, so a remote peer cannot force oversized allocations or unbounded bookkeeping. Assemblies are bound to the sender that started them, counted against global and per-sender caps, and the bytes buffered across all assemblies never exceed max_total_buffered_bytes.

§Arguments
  • sender - The authenticated (or wire-claimed) sender of the chunk
  • chunk - The received file chunk
§Returns

Returns Ok(FileProgress) with current progress, or the ChunkRejection explaining why the chunk was dropped.

Source

pub fn is_complete(&self, file_id: &str) -> bool

Checks if a file transfer is complete.

Source

pub fn finalize_file(&mut self, file_id: &str) -> Option<Vec<u8>>

Finalizes a file transfer and returns the complete file data.

Verifies the SHA256 checksum of the reassembled file before returning.

§Arguments
  • file_id - File identifier
§Returns

Returns Some(Vec<u8>) if file is complete, its size matches the claimed file_size, and the checksum matches, None otherwise.

Source

pub fn cleanup_stale_transfers( &mut self, max_age: Duration, ) -> Vec<StaleTransfer>

Removes stale/incomplete transfers that have not received any chunk updates within max_age, returning what was dropped so callers can surface the loss. Swept ids are tombstoned so straggler chunks cannot resurrect them; tombstones themselves expire by the same rule — no chunks for max_age — freeing the id for reuse.

Source

pub fn get_progress(&self, file_id: &str) -> Option<FileProgress>

Gets the progress of an active file transfer.

Source

pub fn cancel_transfer(&mut self, file_id: &str) -> bool

Cancels an active file transfer.

Source

pub fn active_transfer_count(&self) -> usize

Gets the number of active file transfers.

Trait Implementations§

Source§

impl Default for FileTransferManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Classify for T

Source§

type Classified = T

Source§

fn classify(self) -> T

Source§

impl<T> Declassify for T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more