Remove a redundant method

This commit is contained in:
Igor Katson 2024-03-30 14:12:54 +00:00
parent b42649a524
commit 2972b0c87b
3 changed files with 9 additions and 13 deletions

View file

@ -196,8 +196,8 @@ impl ChunkTracker {
where
ByteBuf: AsRef<[u8]>,
{
let chunk_info = self.lengths.chunk_info_from_received_piece(
piece.index,
let chunk_info = self.lengths.chunk_info_from_received_data(
self.lengths.validate_piece_index(piece.index)?,
piece.begin,
piece.block.as_ref().len() as u32,
)?;

View file

@ -1225,8 +1225,13 @@ impl PeerHandler {
}
fn on_received_piece(&self, piece: Piece<ByteBuf>) -> anyhow::Result<()> {
let chunk_info = match self.state.lengths.chunk_info_from_received_piece(
piece.index,
let piece_index = self
.state
.lengths
.validate_piece_index(piece.index)
.with_context(|| format!("peer sent an invalid piece {}", piece.index))?;
let chunk_info = match self.state.lengths.chunk_info_from_received_data(
piece_index,
piece.begin,
piece.block.len() as u32,
) {

View file

@ -198,15 +198,6 @@ impl Lengths {
absolute_index,
})
}
pub fn chunk_info_from_received_piece(
&self,
index: u32,
begin: u32,
block_len: u32,
) -> Option<ChunkInfo> {
self.chunk_info_from_received_data(self.validate_piece_index(index)?, begin, block_len)
}
pub const fn chunk_range(&self, index: ValidPieceIndex) -> std::ops::Range<usize> {
let start = index.0 * self.chunks_per_piece;
let end = start + self.chunks_per_piece(index);