refactor: minor naming change in block_info (#2233)
* refactor: rename method as block_info.pieceSize() * refactor: rename method as block_info.blockSize()
This commit is contained in:
parent
6cc9afe1c2
commit
742ae6fb00
|
@ -42,13 +42,13 @@ struct tr_block_info
|
|||
return n_blocks_in_piece ? block / n_blocks_in_piece : 0;
|
||||
}
|
||||
|
||||
constexpr uint32_t countBytesInPiece(tr_piece_index_t piece) const
|
||||
constexpr uint32_t pieceSize(tr_piece_index_t piece) const
|
||||
{
|
||||
// how many bytes are in this piece?
|
||||
return piece + 1 == n_pieces ? final_piece_size : piece_size;
|
||||
}
|
||||
|
||||
constexpr uint32_t countBytesInBlock(tr_block_index_t block) const
|
||||
constexpr uint32_t blockSize(tr_block_index_t block) const
|
||||
{
|
||||
// how many bytes are in this block?
|
||||
return block + 1 == n_blocks ? final_block_size : block_size;
|
||||
|
@ -88,7 +88,7 @@ struct tr_block_info
|
|||
}
|
||||
|
||||
auto const begin = blockOf(offset(piece, 0));
|
||||
auto const end = 1 + blockOf(offset(piece, countBytesInPiece(piece) - 1));
|
||||
auto const end = 1 + blockOf(offset(piece, pieceSize(piece) - 1));
|
||||
return { begin, end };
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ uint64_t tr_completion::computeHasValid() const
|
|||
{
|
||||
if (hasPiece(piece))
|
||||
{
|
||||
size += block_info_->countBytesInPiece(piece);
|
||||
size += block_info_->pieceSize(piece);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ uint64_t tr_completion::computeSizeWhenDone() const
|
|||
{
|
||||
if (!tor_->pieceIsDnd(piece))
|
||||
{
|
||||
size += block_info_->countBytesInPiece(piece);
|
||||
size += block_info_->pieceSize(piece);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -106,7 +106,7 @@ size_t tr_completion::countMissingBlocksInPiece(tr_piece_index_t piece) const
|
|||
|
||||
size_t tr_completion::countMissingBytesInPiece(tr_piece_index_t piece) const
|
||||
{
|
||||
return block_info_->countBytesInPiece(piece) - countHasBytesInSpan(block_info_->blockSpanForPiece(piece));
|
||||
return block_info_->pieceSize(piece) - countHasBytesInSpan(block_info_->blockSpanForPiece(piece));
|
||||
}
|
||||
|
||||
tr_completeness tr_completion::status() const
|
||||
|
@ -155,7 +155,7 @@ void tr_completion::addBlock(tr_block_index_t block)
|
|||
}
|
||||
|
||||
blocks_.set(block);
|
||||
size_now_ += block_info_->countBytesInBlock(block);
|
||||
size_now_ += block_info_->blockSize(block);
|
||||
|
||||
has_valid_.reset();
|
||||
}
|
||||
|
|
|
@ -260,7 +260,7 @@ static std::optional<tr_sha1_digest_t> recalculateHash(tr_torrent* tor, tr_piece
|
|||
TR_ASSERT(tor != nullptr);
|
||||
TR_ASSERT(piece < tor->info.pieceCount);
|
||||
|
||||
auto bytes_left = size_t{ tor->countBytesInPiece(piece) };
|
||||
auto bytes_left = size_t{ tor->pieceSize(piece) };
|
||||
auto offset = uint32_t{};
|
||||
tr_ioPrefetch(tor, piece, offset, bytes_left);
|
||||
|
||||
|
|
|
@ -732,7 +732,7 @@ static void peerSuggestedPiece(tr_swarm* /*s*/, tr_peer* /*peer*/, tr_piece_inde
|
|||
if (tor->hasBlock(b))
|
||||
{
|
||||
uint32_t const offset = getBlockOffsetInPiece(tor, b);
|
||||
uint32_t const length = tor->countBytesInBlock(b);
|
||||
uint32_t const length = tor->blockSize(b);
|
||||
tr_peerMsgsAddRequest(peer->msgs, pieceIndex, offset, length);
|
||||
incrementPieceRequests(t, pieceIndex);
|
||||
}
|
||||
|
@ -762,7 +762,7 @@ void tr_peerMgrPieceCompleted(tr_torrent* tor, tr_piece_index_t p)
|
|||
|
||||
if (pieceCameFromPeers) /* webseed downloads don't belong in announce totals */
|
||||
{
|
||||
tr_announcerAddBytes(tor, TR_ANN_DOWN, tor->countBytesInPiece(p));
|
||||
tr_announcerAddBytes(tor, TR_ANN_DOWN, tor->pieceSize(p));
|
||||
}
|
||||
|
||||
/* bookkeeping */
|
||||
|
@ -1243,7 +1243,7 @@ tr_pex* tr_peerMgrCompact6ToPex(
|
|||
void tr_peerMgrGotBadPiece(tr_torrent* tor, tr_piece_index_t pieceIndex)
|
||||
{
|
||||
tr_swarm* s = tor->swarm;
|
||||
uint32_t const byteCount = tor->countBytesInPiece(pieceIndex);
|
||||
uint32_t const byteCount = tor->pieceSize(pieceIndex);
|
||||
|
||||
for (int i = 0, n = tr_ptrArraySize(&s->peers); i != n; ++i)
|
||||
{
|
||||
|
|
|
@ -1893,9 +1893,9 @@ static int clientGotBlock(tr_peerMsgsImpl* msgs, struct evbuffer* data, struct p
|
|||
return EBADMSG;
|
||||
}
|
||||
|
||||
if (req->length != msgs->torrent->countBytesInBlock(block))
|
||||
if (req->length != msgs->torrent->blockSize(block))
|
||||
{
|
||||
dbgmsg(msgs, "wrong block size -- expected %u, got %d", msgs->torrent->countBytesInBlock(block), req->length);
|
||||
dbgmsg(msgs, "wrong block size -- expected %u, got %d", msgs->torrent->blockSize(block), req->length);
|
||||
return EMSGSIZE;
|
||||
}
|
||||
|
||||
|
|
|
@ -2270,7 +2270,7 @@ void tr_torrentGetBlockLocation(
|
|||
uint64_t piece_begin = tor->info.pieceSize;
|
||||
piece_begin *= *piece;
|
||||
*offset = pos - piece_begin;
|
||||
*length = tor->countBytesInBlock(block);
|
||||
*length = tor->blockSize(block);
|
||||
}
|
||||
|
||||
bool tr_torrentReqIsValid(tr_torrent const* tor, tr_piece_index_t index, uint32_t offset, uint32_t length)
|
||||
|
@ -2287,7 +2287,7 @@ bool tr_torrentReqIsValid(tr_torrent const* tor, tr_piece_index_t index, uint32_
|
|||
{
|
||||
err = 2;
|
||||
}
|
||||
else if (offset + length > tor->countBytesInPiece(index))
|
||||
else if (offset + length > tor->pieceSize(index))
|
||||
{
|
||||
err = 3;
|
||||
}
|
||||
|
@ -3031,7 +3031,7 @@ void tr_torrentGotBlock(tr_torrent* tor, tr_block_index_t block)
|
|||
}
|
||||
else
|
||||
{
|
||||
uint32_t const n = tor->countBytesInPiece(p);
|
||||
uint32_t const n = tor->pieceSize(p);
|
||||
tr_logAddTorErr(tor, _("Piece %" PRIu32 ", which was just downloaded, failed its checksum test"), p);
|
||||
tor->corruptCur += n;
|
||||
tor->downloadedCur -= std::min(tor->downloadedCur, uint64_t{ n });
|
||||
|
@ -3041,7 +3041,7 @@ void tr_torrentGotBlock(tr_torrent* tor, tr_block_index_t block)
|
|||
}
|
||||
else
|
||||
{
|
||||
uint32_t const n = tor->countBytesInBlock(block);
|
||||
uint32_t const n = tor->blockSize(block);
|
||||
tor->downloadedCur -= std::min(tor->downloadedCur, uint64_t{ n });
|
||||
tr_logAddTorDbg(tor, "we have this block already...");
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ static bool verifyTorrent(tr_torrent* tor, bool* stopFlag)
|
|||
}
|
||||
|
||||
/* figure out how much we can read this pass */
|
||||
uint64_t leftInPiece = tor->countBytesInPiece(piece) - piecePos;
|
||||
uint64_t leftInPiece = tor->pieceSize(piece) - piecePos;
|
||||
uint64_t leftInFile = file->length - filePos;
|
||||
uint64_t bytesThisPass = std::min(leftInFile, leftInPiece);
|
||||
bytesThisPass = std::min(bytesThisPass, uint64_t{ buflen });
|
||||
|
|
|
@ -147,7 +147,7 @@ static void fire_client_got_rejs(tr_torrent* tor, tr_webseed* w, tr_block_index_
|
|||
{
|
||||
if (i == count)
|
||||
{
|
||||
e.length = tor->countBytesInBlock(block + count - 1);
|
||||
e.length = tor->blockSize(block + count - 1);
|
||||
}
|
||||
|
||||
publish(w, &e);
|
||||
|
@ -165,7 +165,7 @@ static void fire_client_got_blocks(tr_torrent* tor, tr_webseed* w, tr_block_inde
|
|||
{
|
||||
if (i == count)
|
||||
{
|
||||
e.length = tor->countBytesInBlock(block + count - 1);
|
||||
e.length = tor->blockSize(block + count - 1);
|
||||
}
|
||||
|
||||
publish(w, &e);
|
||||
|
@ -373,7 +373,7 @@ static void on_idle(tr_webseed* w)
|
|||
task->block = begin;
|
||||
task->piece_index = tor->pieceForBlock(begin);
|
||||
task->piece_offset = tor->block_size * begin - tor->info.pieceSize * task->piece_index;
|
||||
task->length = (end - 1 - begin) * tor->block_size + tor->countBytesInBlock(end - 1);
|
||||
task->length = (end - 1 - begin) * tor->block_size + tor->blockSize(end - 1);
|
||||
task->blocks_done = 0;
|
||||
task->response_code = 0;
|
||||
task->block_size = tor->block_size;
|
||||
|
|
|
@ -85,7 +85,7 @@ TEST_F(BlockInfoTest, pieceForBlock)
|
|||
}
|
||||
}
|
||||
|
||||
TEST_F(BlockInfoTest, countBytesInPiece)
|
||||
TEST_F(BlockInfoTest, pieceSize)
|
||||
{
|
||||
auto info = tr_block_info{};
|
||||
|
||||
|
@ -96,11 +96,11 @@ TEST_F(BlockInfoTest, countBytesInPiece)
|
|||
uint64_t constexpr TotalSize = PieceSize * (PieceCount - 1) + 1;
|
||||
info.initSizes(TotalSize, PieceSize);
|
||||
|
||||
EXPECT_EQ(PieceSize, info.countBytesInPiece(info.n_pieces - 2));
|
||||
EXPECT_EQ(1, info.countBytesInPiece(info.n_pieces - 1));
|
||||
EXPECT_EQ(PieceSize, info.pieceSize(info.n_pieces - 2));
|
||||
EXPECT_EQ(1, info.pieceSize(info.n_pieces - 1));
|
||||
}
|
||||
|
||||
TEST_F(BlockInfoTest, countBytesInBlock)
|
||||
TEST_F(BlockInfoTest, blockSize)
|
||||
{
|
||||
auto info = tr_block_info{};
|
||||
|
||||
|
@ -111,8 +111,8 @@ TEST_F(BlockInfoTest, countBytesInBlock)
|
|||
uint64_t constexpr TotalSize = PieceSize * (PieceCount - 1) + 1;
|
||||
info.initSizes(TotalSize, PieceSize);
|
||||
|
||||
EXPECT_EQ(ExpectedBlockSize, info.countBytesInBlock(info.n_blocks - 2));
|
||||
EXPECT_EQ(1, info.countBytesInBlock(info.n_blocks - 1));
|
||||
EXPECT_EQ(ExpectedBlockSize, info.blockSize(info.n_blocks - 2));
|
||||
EXPECT_EQ(1, info.blockSize(info.n_blocks - 1));
|
||||
}
|
||||
|
||||
TEST_F(BlockInfoTest, offset)
|
||||
|
|
|
@ -414,15 +414,15 @@ TEST_F(CompletionTest, countMissingBytesInPiece)
|
|||
auto const block_info = tr_block_info{ TotalSize, PieceSize };
|
||||
auto completion = tr_completion(&torrent, &block_info);
|
||||
|
||||
EXPECT_EQ(block_info.countBytesInPiece(0), completion.countMissingBytesInPiece(0));
|
||||
EXPECT_EQ(block_info.pieceSize(0), completion.countMissingBytesInPiece(0));
|
||||
completion.addBlock(0);
|
||||
EXPECT_EQ(block_info.countBytesInPiece(0) - block_info.block_size, completion.countMissingBytesInPiece(0));
|
||||
EXPECT_EQ(block_info.pieceSize(0) - block_info.block_size, completion.countMissingBytesInPiece(0));
|
||||
completion.addPiece(0);
|
||||
EXPECT_EQ(0, completion.countMissingBytesInPiece(0));
|
||||
|
||||
auto const final_piece = block_info.n_pieces - 1;
|
||||
auto const final_block = block_info.n_blocks - 1;
|
||||
EXPECT_EQ(block_info.countBytesInPiece(final_piece), completion.countMissingBytesInPiece(final_piece));
|
||||
EXPECT_EQ(block_info.pieceSize(final_piece), completion.countMissingBytesInPiece(final_piece));
|
||||
completion.addBlock(final_block);
|
||||
EXPECT_EQ(1, block_info.final_piece_size);
|
||||
EXPECT_EQ(1, block_info.final_block_size);
|
||||
|
|
Loading…
Reference in New Issue