chore: checkpoint

This commit is contained in:
Yat Ho 2024-01-30 11:55:34 +08:00 committed by Charles Kerr
parent a7bbc09786
commit 46b2dbf630
4 changed files with 23 additions and 23 deletions

View File

@ -183,22 +183,22 @@ class tr_peer
public:
using Speed = libtransmission::Values::Speed;
tr_peer(tr_torrent const* tor);
explicit tr_peer(tr_torrent const* tor);
virtual ~tr_peer();
[[nodiscard]] virtual Speed get_piece_speed(uint64_t now, tr_direction direction) const = 0;
[[nodiscard]] bool hasPiece(tr_piece_index_t piece) const noexcept
[[nodiscard]] bool has_piece(tr_piece_index_t piece) const noexcept
{
return has().test(piece);
}
[[nodiscard]] float percentDone() const noexcept
[[nodiscard]] float percent_done() const noexcept
{
return has().percent();
}
[[nodiscard]] bool isSeed() const noexcept
[[nodiscard]] bool is_seed() const noexcept
{
return has().has_all();
}

View File

@ -782,7 +782,7 @@ private:
{
peer->on_torrent_got_metainfo();
if (peer->isSeed())
if (peer->is_seed())
{
mark_peer_as_seed(*peer->peer_info);
}
@ -1006,7 +1006,7 @@ size_t tr_swarm::WishlistMediator::count_piece_replication(tr_piece_index_t piec
std::begin(swarm_.peers),
std::end(swarm_.peers),
size_t{},
[piece](size_t acc, tr_peer* peer) { return acc + (peer->hasPiece(piece) ? 1U : 0U); });
[piece](size_t acc, tr_peer* peer) { return acc + (peer->has_piece(piece) ? 1U : 0U); });
}
tr_block_span_t tr_swarm::WishlistMediator::block_span(tr_piece_index_t piece) const
@ -1262,7 +1262,7 @@ std::vector<tr_block_span_t> tr_peerMgrGetNextRequests(tr_torrent* torrent, tr_p
}
return swarm.wishlist->next(
numwant,
[peer](tr_piece_index_t p) { return peer->hasPiece(p); },
[peer](tr_piece_index_t p) { return peer->has_piece(p); },
[peer, &swarm](tr_block_index_t b) { return swarm.active_requests.has(b, peer); });
}
@ -1634,7 +1634,7 @@ int8_t tr_peerMgrPieceAvailability(tr_torrent const* tor, tr_piece_index_t piece
}
auto const& peers = tor->swarm->peers;
return std::count_if(std::begin(peers), std::end(peers), [piece](auto const* peer) { return peer->hasPiece(piece); });
return std::count_if(std::begin(peers), std::end(peers), [piece](auto const* peer) { return peer->has_piece(piece); });
}
void tr_peerMgrTorrentAvailability(tr_torrent const* tor, int8_t* tab, unsigned int n_tabs)
@ -1740,7 +1740,7 @@ namespace peer_stat_helpers
stats.client = peer->user_agent().c_str();
stats.port = port.host();
stats.from = peer->peer_info->from_first();
stats.progress = peer->percentDone();
stats.progress = peer->percent_done();
stats.isUTP = peer->is_utp_connection();
stats.isEncrypted = peer->is_encrypted();
stats.rateToPeer_KBps = peer->get_piece_speed(now_msec, TR_CLIENT_TO_PEER).count(Speed::Units::KByps);
@ -1752,7 +1752,7 @@ namespace peer_stat_helpers
stats.isIncoming = peer->is_incoming_connection();
stats.isDownloadingFrom = peer->is_active(TR_PEER_TO_CLIENT);
stats.isUploadingTo = peer->is_active(TR_CLIENT_TO_PEER);
stats.isSeed = peer->isSeed();
stats.isSeed = peer->is_seed();
stats.blocksToPeer = peer->blocks_sent_to_peer.count(now, CancelHistorySec);
stats.blocksToClient = peer->blocks_sent_to_client.count(now, CancelHistorySec);
@ -1866,14 +1866,14 @@ namespace update_interest_helpers
TR_ASSERT(!tor->is_done());
TR_ASSERT(tor->client_can_download());
if (peer->isSeed())
if (peer->is_seed())
{
return true;
}
for (tr_piece_index_t i = 0; i < tor->piece_count(); ++i)
{
if (piece_is_interesting[i] && peer->hasPiece(i))
if (piece_is_interesting[i] && peer->has_piece(i))
{
return true;
}
@ -2009,7 +2009,7 @@ void rechokeUploads(tr_swarm* s, uint64_t const now)
auto salter = tr_salt_shaker{};
for (auto* const peer : peers)
{
if (peer->isSeed())
if (peer->is_seed())
{
/* choke seeds and partial seeds */
peer->set_choke(true);
@ -2150,7 +2150,7 @@ auto constexpr MaxUploadIdleSecs = time_t{ 60 * 5 };
auto const* const info = peer->peer_info;
/* disconnect if we're both seeds and enough time has passed for PEX */
if (tor->is_done() && peer->isSeed())
if (tor->is_done() && peer->is_seed())
{
return !tor->allows_pex() || info->idle_secs(now).value_or(0U) >= 30U;
}

View File

@ -436,7 +436,7 @@ public:
if (chokeChangedAt > fibrillation_time)
{
// TODO logtrace(msgs, "Not changing choke to %d to avoid fibrillation", peer_is_choked);
logtrace(this, fmt::format("Not changing choke to {} to avoid fibrillation", peer_is_choked));
}
else if (this->peer_is_choked() != peer_is_choked)
{
@ -562,7 +562,7 @@ public:
// ---
[[nodiscard]] std::optional<int> pop_next_metadata_request();
[[nodiscard]] std::optional<int64_t> pop_next_metadata_request();
[[nodiscard]] size_t add_next_metadata_piece();
[[nodiscard]] size_t add_next_piece(uint64_t now);
[[nodiscard]] size_t fill_output_buffer(time_t now_sec, uint64_t now_msec);
@ -623,7 +623,7 @@ public:
std::array<std::vector<tr_pex>, NUM_TR_AF_INET_TYPES> pex_;
std::queue<int> peerAskedForMetadata;
std::queue<int64_t> peerAskedForMetadata;
time_t clientSentAnythingAt = 0;
@ -652,7 +652,7 @@ private:
// ---
[[nodiscard]] constexpr bool messageLengthIsCorrect(tr_torrent const* const tor, uint8_t id, uint32_t len)
[[nodiscard]] constexpr bool is_message_length_correct(tr_torrent const* const tor, uint8_t id, uint32_t len)
{
switch (id)
{
@ -784,7 +784,7 @@ void build_peer_message(tr_peerMsgsImpl const* const msgs, MessageWriter& out, u
out.add_uint8(type);
(add_param(out, args), ...);
TR_ASSERT(messageLengthIsCorrect(msgs->torrent, type, msg_len));
TR_ASSERT(is_message_length_correct(msgs->torrent, type, msg_len));
}
} // namespace protocol_send_message_helpers
@ -849,7 +849,7 @@ void tr_peerMsgsImpl::protocol_send_interest(bool b) const
protocol_send_message(b ? BtPeerMsgs::Interested : BtPeerMsgs::NotInterested);
}
[[nodiscard]] std::optional<int> tr_peerMsgsImpl::pop_next_metadata_request()
[[nodiscard]] std::optional<int64_t> tr_peerMsgsImpl::pop_next_metadata_request()
{
auto& reqs = peerAskedForMetadata;
@ -1320,7 +1320,7 @@ ReadResult tr_peerMsgsImpl::process_peer_message(uint8_t id, MessageReader& payl
static_cast<int>(id),
std::size(payload)));
if (!messageLengthIsCorrect(torrent, id, sizeof(id) + std::size(payload)))
if (!is_message_length_correct(torrent, id, sizeof(id) + std::size(payload)))
{
logdbg(
this,

View File

@ -187,7 +187,7 @@ TEST_F(CompletionTest, percentCompleteAndDone)
EXPECT_DOUBLE_EQ(0.5, completion.percent_done());
// but marking some of the pieces we have as unwanted
// should not change percentDone
// should not change percent_done
for (size_t i = 0; i < 16; ++i)
{
torrent.dnd_pieces.insert(i);
@ -197,7 +197,7 @@ TEST_F(CompletionTest, percentCompleteAndDone)
EXPECT_DOUBLE_EQ(0.5, completion.percent_done());
// but marking some of the pieces we DON'T have as unwanted
// SHOULD change percentDone
// SHOULD change percent_done
for (size_t i = 32; i < 48; ++i)
{
torrent.dnd_pieces.insert(i);