Downloading chunks now does not copy the chunks, but writes them straight to disk. (Still reads into a buffer first though, but does not allocate on every chunk)

This commit is contained in:
Igor Katson 2021-06-28 16:37:15 +01:00
parent fab43a8d23
commit 14b62b45c5
7 changed files with 96 additions and 109 deletions

View file

@ -1,7 +1,6 @@
use log::{debug, info};
use crate::{
buffers::ByteString,
lengths::{ChunkInfo, Lengths, ValidPieceIndex},
peer_binary_protocol::Piece,
type_aliases::BF,
@ -118,10 +117,13 @@ impl ChunkTracker {
}
// return true if the whole piece is marked downloaded
pub fn mark_chunk_downloaded(
pub fn mark_chunk_downloaded<ByteBuf>(
&mut self,
piece: &Piece<ByteString>,
) -> Option<ChunkMarkingResult> {
piece: &Piece<ByteBuf>,
) -> Option<ChunkMarkingResult>
where
ByteBuf: AsRef<[u8]>,
{
let chunk_info = self.lengths.chunk_info_from_received_piece(piece)?;
let chunk_range = self.lengths.chunk_range(chunk_info.piece_index);
let chunk_range = self.chunk_status.get_mut(chunk_range).unwrap();