Remove a redundant method
This commit is contained in:
parent
b42649a524
commit
2972b0c87b
3 changed files with 9 additions and 13 deletions
|
|
@ -196,8 +196,8 @@ impl ChunkTracker {
|
||||||
where
|
where
|
||||||
ByteBuf: AsRef<[u8]>,
|
ByteBuf: AsRef<[u8]>,
|
||||||
{
|
{
|
||||||
let chunk_info = self.lengths.chunk_info_from_received_piece(
|
let chunk_info = self.lengths.chunk_info_from_received_data(
|
||||||
piece.index,
|
self.lengths.validate_piece_index(piece.index)?,
|
||||||
piece.begin,
|
piece.begin,
|
||||||
piece.block.as_ref().len() as u32,
|
piece.block.as_ref().len() as u32,
|
||||||
)?;
|
)?;
|
||||||
|
|
|
||||||
|
|
@ -1225,8 +1225,13 @@ impl PeerHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_received_piece(&self, piece: Piece<ByteBuf>) -> anyhow::Result<()> {
|
fn on_received_piece(&self, piece: Piece<ByteBuf>) -> anyhow::Result<()> {
|
||||||
let chunk_info = match self.state.lengths.chunk_info_from_received_piece(
|
let piece_index = self
|
||||||
piece.index,
|
.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.begin,
|
||||||
piece.block.len() as u32,
|
piece.block.len() as u32,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -198,15 +198,6 @@ impl Lengths {
|
||||||
absolute_index,
|
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> {
|
pub const fn chunk_range(&self, index: ValidPieceIndex) -> std::ops::Range<usize> {
|
||||||
let start = index.0 * self.chunks_per_piece;
|
let start = index.0 * self.chunks_per_piece;
|
||||||
let end = start + self.chunks_per_piece(index);
|
let end = start + self.chunks_per_piece(index);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue