Merge pull request #17363 from Chocobo1/pause

Add workaround for payload upload/download rate
This commit is contained in:
Chocobo1 2022-07-16 11:52:28 +08:00 committed by GitHub
commit ce0e92e12a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 35 deletions

View file

@ -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
@ -1038,7 +1071,7 @@ qlonglong TorrentImpl::eta() const
{
if (isPaused()) return MAX_ETA;
const SpeedSampleAvg speedAverage = m_speedMonitor.average();
const SpeedSampleAvg speedAverage = m_payloadRateMonitor.average();
if (isSeed())
{
@ -1296,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
@ -1611,7 +1646,7 @@ void TorrentImpl::pause()
setAutoManaged(false);
m_nativeHandle.pause();
m_speedMonitor.reset();
m_payloadRateMonitor.reset();
}
}
@ -2114,7 +2149,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())

View file

@ -298,7 +298,7 @@ namespace BitTorrent
QHash<lt::file_index_t, int> m_indexMap;
QVector<DownloadPriority> m_filePriorities;
QBitArray m_completedFiles;
SpeedMonitor m_speedMonitor;
SpeedMonitor m_payloadRateMonitor;
InfoHash m_infoHash;