/* */ #include "ShareRatioSeedCriteria.h" #include "DownloadContext.h" #include "BtRuntime.h" #include "PieceStorage.h" namespace aria2 { ShareRatioSeedCriteria::ShareRatioSeedCriteria( double ratio, const std::shared_ptr& downloadContext) : ratio_(ratio), downloadContext_(downloadContext) { } ShareRatioSeedCriteria::~ShareRatioSeedCriteria() {} void ShareRatioSeedCriteria::reset() {} bool ShareRatioSeedCriteria::evaluate() { int64_t completedLength = pieceStorage_->getCompletedLength(); if (completedLength == 0) { return true; } int64_t uploadLength = btRuntime_->getUploadLengthAtStartup() + downloadContext_->getNetStat().getSessionUploadLength(); return ratio_ <= 1.0 * uploadLength / completedLength; } void ShareRatioSeedCriteria::setBtRuntime( const std::shared_ptr& btRuntime) { btRuntime_ = btRuntime; } void ShareRatioSeedCriteria::setPieceStorage( const std::shared_ptr& pieceStorage) { pieceStorage_ = pieceStorage; } } // namespace aria2