pub struct BtMessageHandler;Expand description
BT Message Handler for block-level operations
Manages the process of requesting and receiving individual blocks from peers during piece download.
Implementations§
Source§impl BtMessageHandler
impl BtMessageHandler
Sourcepub async fn request_block(
connections: &mut [BtPeerConn],
piece_index: u32,
block_offset: u32,
block_length: u32,
) -> Result<BlockDownloadResult>
pub async fn request_block( connections: &mut [BtPeerConn], piece_index: u32, block_offset: u32, block_length: u32, ) -> Result<BlockDownloadResult>
Request and receive a single block from available peers
This method implements the core block request/receive loop:
- Send the block request to a peer
- Wait for the response with timeout
- Handle various message types while waiting
- Return the block data on success
§Arguments
connections- Mutable slice of active peer connectionspiece_index- The index of the piece this block belongs toblock_offset- The byte offset within the pieceblock_length- The length of this block in bytes
§Returns
Ok(BlockDownloadResult)- Result containing success status and dataErr(Aria2Error)- If all peers fail to respond
Sourcepub async fn download_piece_blocks(
connections: &mut [BtPeerConn],
piece_index: u32,
piece_length: u32,
num_blocks: u32,
) -> Result<Vec<u8>>
pub async fn download_piece_blocks( connections: &mut [BtPeerConn], piece_index: u32, piece_length: u32, num_blocks: u32, ) -> Result<Vec<u8>>
Download all blocks for a piece with retry logic
Coordinates the download of all blocks that make up a piece, implementing retry logic for failed pieces.
§Arguments
connections- Mutable slice of active peer connectionspiece_index- Index of the piece to downloadpiece_length- Total length of this piece in bytesnum_blocks- Number of blocks in this piece
§Returns
Ok(Vec<u8>)- Complete piece data if all blocks downloaded successfullyErr(Aria2Error)- If piece download fails after all retries
Sourcepub async fn download_piece_blocks_endgame(
connections: &mut [BtPeerConn],
piece_index: u32,
piece_length: u32,
num_blocks: u32,
endgame_state: &mut EndgameState,
) -> Result<Vec<u8>>
pub async fn download_piece_blocks_endgame( connections: &mut [BtPeerConn], piece_index: u32, piece_length: u32, num_blocks: u32, endgame_state: &mut EndgameState, ) -> Result<Vec<u8>>
Download all blocks for a piece using endgame mode (duplicate request strategy).
In endgame mode, when few pieces remain, we request each block from ALL available peers simultaneously. When any peer responds first, we immediately send Cancel messages to the other peers to stop them from sending redundant data.
§Phase 14 - B1/B2: Endgame Duplicate Request Strategy + Cancel on Block Arrival
§Arguments
connections- Mutable slice of active peer connectionspiece_index- Index of the piece to downloadpiece_length- Total length of this piece in bytesnum_blocks- Number of blocks in this pieceendgame_state- Mutable reference to EndgameState for tracking duplicate requests
§Returns
Ok(Vec<u8>)- Complete piece data if all blocks downloaded successfullyErr(Aria2Error)- If piece download fails after all retries
Auto Trait Implementations§
impl Freeze for BtMessageHandler
impl RefUnwindSafe for BtMessageHandler
impl Send for BtMessageHandler
impl Sync for BtMessageHandler
impl Unpin for BtMessageHandler
impl UnsafeUnpin for BtMessageHandler
impl UnwindSafe for BtMessageHandler
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