From b6b0b54cdb8e8891893bd7cc5c17a7b6839a84c2 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 13 Jul 2022 14:35:04 +0800 Subject: [PATCH 1/3] Rename variable --- src/base/bittorrent/torrentimpl.cpp | 6 +++--- src/base/bittorrent/torrentimpl.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index fd08c5bdc..f605db04f 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1038,7 +1038,7 @@ qlonglong TorrentImpl::eta() const { if (isPaused()) return MAX_ETA; - const SpeedSampleAvg speedAverage = m_speedMonitor.average(); + const SpeedSampleAvg speedAverage = m_payloadRateMonitor.average(); if (isSeed()) { @@ -1611,7 +1611,7 @@ void TorrentImpl::pause() setAutoManaged(false); m_nativeHandle.pause(); - m_speedMonitor.reset(); + m_payloadRateMonitor.reset(); } } @@ -2114,7 +2114,7 @@ void TorrentImpl::updateStatus(const lt::torrent_status &nativeStatus) m_nativeStatus = nativeStatus; updateState(); - m_speedMonitor.addSample({nativeStatus.download_payload_rate + m_payloadRateMonitor.addSample({nativeStatus.download_payload_rate , nativeStatus.upload_payload_rate}); if (hasMetadata()) diff --git a/src/base/bittorrent/torrentimpl.h b/src/base/bittorrent/torrentimpl.h index 1f975072d..f4b33143d 100644 --- a/src/base/bittorrent/torrentimpl.h +++ b/src/base/bittorrent/torrentimpl.h @@ -298,7 +298,7 @@ namespace BitTorrent QHash m_indexMap; QVector m_filePriorities; QBitArray m_completedFiles; - SpeedMonitor m_speedMonitor; + SpeedMonitor m_payloadRateMonitor; InfoHash m_infoHash; From bafe4e909c1b917098e167baa856640a528c0be2 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 14 Jul 2022 16:50:15 +0800 Subject: [PATCH 2/3] Use `switch()` statement --- src/base/bittorrent/torrentimpl.cpp | 91 ++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 29 deletions(-) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index f605db04f..ffcc12efd 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -838,47 +838,80 @@ bool TorrentImpl::isChecking() const bool TorrentImpl::isDownloading() const { - return m_state == TorrentState::Downloading - || m_state == TorrentState::DownloadingMetadata - || m_state == TorrentState::ForcedDownloadingMetadata - || m_state == TorrentState::StalledDownloading - || m_state == TorrentState::CheckingDownloading - || m_state == TorrentState::PausedDownloading - || m_state == TorrentState::QueuedDownloading - || m_state == TorrentState::ForcedDownloading; + switch (m_state) + { + case TorrentState::Downloading: + case TorrentState::DownloadingMetadata: + case TorrentState::ForcedDownloadingMetadata: + case TorrentState::StalledDownloading: + case TorrentState::CheckingDownloading: + case TorrentState::PausedDownloading: + case TorrentState::QueuedDownloading: + case TorrentState::ForcedDownloading: + return true; + default: + break; + }; + + return false; } bool TorrentImpl::isUploading() const { - return m_state == TorrentState::Uploading - || m_state == TorrentState::StalledUploading - || m_state == TorrentState::CheckingUploading - || m_state == TorrentState::QueuedUploading - || m_state == TorrentState::ForcedUploading; + switch (m_state) + { + case TorrentState::Uploading: + case TorrentState::StalledUploading: + case TorrentState::CheckingUploading: + case TorrentState::QueuedUploading: + case TorrentState::ForcedUploading: + return true; + default: + break; + }; + + return false; } bool TorrentImpl::isCompleted() const { - return m_state == TorrentState::Uploading - || m_state == TorrentState::StalledUploading - || m_state == TorrentState::CheckingUploading - || m_state == TorrentState::PausedUploading - || m_state == TorrentState::QueuedUploading - || m_state == TorrentState::ForcedUploading; + switch (m_state) + { + case TorrentState::Uploading: + case TorrentState::StalledUploading: + case TorrentState::CheckingUploading: + case TorrentState::PausedUploading: + case TorrentState::QueuedUploading: + case TorrentState::ForcedUploading: + return true; + default: + break; + }; + + return false; } bool TorrentImpl::isActive() const { - if (m_state == TorrentState::StalledDownloading) + switch (m_state) + { + case TorrentState::StalledDownloading: return (uploadPayloadRate() > 0); - return m_state == TorrentState::DownloadingMetadata - || m_state == TorrentState::ForcedDownloadingMetadata - || m_state == TorrentState::Downloading - || m_state == TorrentState::ForcedDownloading - || m_state == TorrentState::Uploading - || m_state == TorrentState::ForcedUploading - || m_state == TorrentState::Moving; + case TorrentState::DownloadingMetadata: + case TorrentState::ForcedDownloadingMetadata: + case TorrentState::Downloading: + case TorrentState::ForcedDownloading: + case TorrentState::Uploading: + case TorrentState::ForcedUploading: + case TorrentState::Moving: + return true; + + default: + break; + }; + + return false; } bool TorrentImpl::isInactive() const @@ -888,8 +921,8 @@ bool TorrentImpl::isInactive() const bool TorrentImpl::isErrored() const { - return m_state == TorrentState::MissingFiles - || m_state == TorrentState::Error; + return ((m_state == TorrentState::MissingFiles) + || (m_state == TorrentState::Error)); } bool TorrentImpl::isSeed() const From 56bb379024f2b530b1c51705f59cb711907e4a3d Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 14 Jul 2022 16:54:28 +0800 Subject: [PATCH 3/3] Add workaround for payload upload/download rate The graphs are showing 0 for both payload upload & download rate but torrent statistics aren't, so suppress it manually. The workaround only applies to paused state for now. Closes #17294. --- src/base/bittorrent/torrentimpl.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index ffcc12efd..fe7dfeab8 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1329,12 +1329,14 @@ qreal TorrentImpl::realRatio() const int TorrentImpl::uploadPayloadRate() const { - return m_nativeStatus.upload_payload_rate; + // workaround: suppress the speed for paused state + return isPaused() ? 0 : m_nativeStatus.upload_payload_rate; } int TorrentImpl::downloadPayloadRate() const { - return m_nativeStatus.download_payload_rate; + // workaround: suppress the speed for paused state + return isPaused() ? 0 : m_nativeStatus.download_payload_rate; } qlonglong TorrentImpl::totalPayloadUpload() const