refactor: make tr_torrent::verify_state_ private (#2982)

This commit is contained in:
Charles Kerr 2022-04-24 22:43:26 -05:00 committed by GitHub
parent aa2bb367ab
commit ca13842c84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 17 deletions

View File

@ -288,7 +288,7 @@ static char const* torrentStop(
{
for (auto* tor : getTorrents(session, args_in))
{
if (tor->isRunning || tor->isQueued() || tor->verifyState != TR_VERIFY_NONE)
if (tor->isRunning || tor->isQueued() || tor->verifyState() != TR_VERIFY_NONE)
{
tor->isStopping = true;
notify(session, TR_RPC_TORRENT_STOPPED, tor);

View File

@ -970,7 +970,8 @@ void tr_torrent::setVerifyState(tr_verify_state state)
{
TR_ASSERT(state == TR_VERIFY_NONE || state == TR_VERIFY_WAIT || state == TR_VERIFY_NOW);
this->verifyState = state;
this->verify_state_ = state;
this->verify_progress_ = {};
this->markChanged();
}
@ -980,11 +981,11 @@ tr_torrent_activity tr_torrentGetActivity(tr_torrent const* tor)
bool const is_seed = tor->isDone();
if (tor->verifyState == TR_VERIFY_NOW)
if (tor->verifyState() == TR_VERIFY_NOW)
{
ret = TR_STATUS_CHECK;
}
else if (tor->verifyState == TR_VERIFY_WAIT)
else if (tor->verifyState() == TR_VERIFY_WAIT)
{
ret = TR_STATUS_CHECK_WAIT;
}
@ -1019,11 +1020,6 @@ static inline bool tr_torrentIsStalled(tr_torrent const* tor, int idle_secs)
return tr_sessionGetQueueStalledEnabled(tor->session) && idle_secs > tr_sessionGetQueueStalledMinutes(tor->session) * 60;
}
static double getVerifyProgress(tr_torrent const* tor)
{
return tor->verify_progress ? *tor->verify_progress : 0.0;
}
tr_stat const* tr_torrentStat(tr_torrent* tor)
{
TR_ASSERT(tr_isTorrent(tor));
@ -1072,7 +1068,9 @@ tr_stat const* tr_torrentStat(tr_torrent* tor)
s->percentDone = tor->completion.percentDone();
s->leftUntilDone = tor->completion.leftUntilDone();
s->sizeWhenDone = tor->completion.sizeWhenDone();
s->recheckProgress = s->activity == TR_STATUS_CHECK ? getVerifyProgress(tor) : 0;
auto const verify_progress = tor->verifyProgress();
s->recheckProgress = verify_progress ? *verify_progress : 0.0F;
s->activityDate = tor->activityDate;
s->addedDate = tor->addedDate;
s->doneDate = tor->doneDate;

View File

@ -559,6 +559,26 @@ public:
void setVerifyState(tr_verify_state state);
[[nodiscard]] constexpr auto verifyState() const noexcept
{
return verify_state_;
}
constexpr void setVerifyProgress(float f) noexcept
{
verify_progress_ = f;
}
[[nodiscard]] constexpr std::optional<float> verifyProgress() const noexcept
{
if (verify_state_ == TR_VERIFY_NOW)
{
return verify_progress_;
}
return {};
}
void setDateActive(time_t t);
void setLabels(tr_quark const* labels, size_t n_labels);
@ -580,8 +600,6 @@ public:
tr_swarm* swarm = nullptr;
std::optional<double> verify_progress;
tr_stat_errtype error = TR_STAT_OK;
tr_interned_string error_announce_url;
std::string error_string;
@ -683,8 +701,6 @@ public:
uint16_t maxConnectedPeers = TR_DEFAULT_PEER_LIMIT_TORRENT;
tr_verify_state verifyState = TR_VERIFY_NONE;
time_t lastStatTime = 0;
tr_stat stats = {};
@ -717,6 +733,9 @@ public:
tr_bitfield checked_pieces_ = tr_bitfield{ 0 };
private:
tr_verify_state verify_state_ = TR_VERIFY_NONE;
float verify_progress_ = -1;
void setFilesWanted(tr_file_index_t const* files, size_t n_files, bool wanted, bool is_bootstrapping)
{
auto const lock = unique_lock();

View File

@ -46,7 +46,6 @@ static bool verifyTorrent(tr_torrent* tor, bool const* stopFlag)
auto sha = tr_sha1_init();
tr_logAddDebugTor(tor, "verifying torrent...");
tor->verify_progress = 0;
while (!*stopFlag && piece < tor->pieceCount())
{
@ -115,7 +114,7 @@ static bool verifyTorrent(tr_torrent* tor, bool const* stopFlag)
sha = tr_sha1_init();
++piece;
tor->verify_progress = piece / double(tor->pieceCount());
tor->setVerifyProgress(piece / float(tor->pieceCount()));
piece_pos = 0;
}
@ -139,7 +138,6 @@ static bool verifyTorrent(tr_torrent* tor, bool const* stopFlag)
tr_sys_file_close(fd);
}
tor->verify_progress.reset();
tr_sha1_final(sha);
/* stopwatch */