pub struct StreamingBlockTransfer {
pub transfers: HashMap<u64, BlockTransfer>,
pub next_id: u64,
pub current_tick: u64,
}Expand description
Manager for chunked, resumable block transfers between peers.
Each transfer is identified by a unique u64 transfer ID returned by
StreamingBlockTransfer::start_transfer.
Fields§
§transfers: HashMap<u64, BlockTransfer>All tracked transfers indexed by their transfer ID.
next_id: u64Counter used to assign the next unique transfer ID.
current_tick: u64Monotonically increasing logical clock.
Implementations§
Source§impl StreamingBlockTransfer
impl StreamingBlockTransfer
Sourcepub fn start_transfer(
&mut self,
cid: String,
peer_id: String,
direction: TransferDirection,
total_bytes: u64,
chunk_size: u64,
) -> u64
pub fn start_transfer( &mut self, cid: String, peer_id: String, direction: TransferDirection, total_bytes: u64, chunk_size: u64, ) -> u64
Register a new transfer and return its assigned transfer ID.
The transfer begins in the TransferState::Pending state.
If chunk_size is 0, it defaults to 65536.
Sourcepub fn receive_chunk(
&mut self,
transfer_id: u64,
chunk: TransferChunk,
) -> Result<(), String>
pub fn receive_chunk( &mut self, transfer_id: u64, chunk: TransferChunk, ) -> Result<(), String>
Process an incoming chunk for the given transfer.
§Errors
Returns an error string when:
- The transfer ID is unknown.
- The transfer is not in an
InProgressorPendingstate. - The chunk checksum does not match its data.
- The chunk index has already been received.
Sourcepub fn pause(&mut self, transfer_id: u64) -> bool
pub fn pause(&mut self, transfer_id: u64) -> bool
Pause an active or pending transfer.
Returns true if the transfer was successfully paused, false otherwise
(e.g., the transfer ID is unknown, or the transfer is already paused/done).
Sourcepub fn resume(&mut self, transfer_id: u64) -> bool
pub fn resume(&mut self, transfer_id: u64) -> bool
Resume a paused transfer.
Returns true if the transfer was successfully resumed, false otherwise.
Sourcepub fn fail(&mut self, transfer_id: u64, reason: String) -> bool
pub fn fail(&mut self, transfer_id: u64, reason: String) -> bool
Mark a transfer as failed with a descriptive reason.
Returns true if the transfer was found and transitioned to
TransferState::Failed, false if the ID is unknown or the
transfer has already completed/failed.
Sourcepub fn stats(&self) -> TransferManagerStats
pub fn stats(&self) -> TransferManagerStats
Compute aggregated statistics across all managed transfers.
Sourcepub fn advance_tick(&mut self)
pub fn advance_tick(&mut self)
Advance the logical clock by one tick.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StreamingBlockTransfer
impl RefUnwindSafe for StreamingBlockTransfer
impl Send for StreamingBlockTransfer
impl Sync for StreamingBlockTransfer
impl Unpin for StreamingBlockTransfer
impl UnsafeUnpin for StreamingBlockTransfer
impl UnwindSafe for StreamingBlockTransfer
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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