Skip to content

Commit 4508460

Browse files
Handle ETA for stopped finished torrents
1 parent 518dbf0 commit 4508460

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

src/base/bittorrent/torrentimpl.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,32 @@ qlonglong TorrentImpl::totalUpload() const
13841384

13851385
qlonglong TorrentImpl::eta() const
13861386
{
1387-
if (isStopped()) return MAX_ETA;
1387+
if (isStopped())
1388+
{
1389+
if (!isFinished())
1390+
return MAX_ETA;
1391+
1392+
const ShareLimits shareLimits = effectiveShareLimits();
1393+
const bool hasRatioLimit = (shareLimits.ratioLimit >= 0);
1394+
const bool hasSeedingTimeLimit = (shareLimits.seedingTimeLimit >= 0);
1395+
const bool hasInactiveSeedingTimeLimit = (shareLimits.inactiveSeedingTimeLimit >= 0);
1396+
if (!hasRatioLimit && !hasSeedingTimeLimit && !hasInactiveSeedingTimeLimit)
1397+
return MAX_ETA;
1398+
1399+
const bool ratioLimitReached = !hasRatioLimit || (realRatio() >= shareLimits.ratioLimit);
1400+
const bool seedingTimeLimitReached = !hasSeedingTimeLimit
1401+
|| ((finishedTime() / 60) >= shareLimits.seedingTimeLimit);
1402+
const bool inactiveSeedingTimeLimitReached = !hasInactiveSeedingTimeLimit
1403+
|| ((timeSinceActivity() / 60) >= shareLimits.inactiveSeedingTimeLimit);
1404+
1405+
const bool shareLimitsReached = (shareLimits.mode == ShareLimitsMode::MatchAny)
1406+
? ((hasRatioLimit && ratioLimitReached)
1407+
|| (hasSeedingTimeLimit && seedingTimeLimitReached)
1408+
|| (hasInactiveSeedingTimeLimit && inactiveSeedingTimeLimitReached))
1409+
: (ratioLimitReached && seedingTimeLimitReached && inactiveSeedingTimeLimitReached);
1410+
1411+
return shareLimitsReached ? 0 : MAX_ETA;
1412+
}
13881413

13891414
const SpeedSampleAvg speedAverage = m_payloadRateMonitor.average();
13901415

0 commit comments

Comments
 (0)