/* */ #ifndef _D_SHARE_RATIO_SEED_CRITERIA_H_ #define _D_SHARE_RATIO_SEED_CRITERIA_H_ #include "SeedCriteria.h" #include "BtContext.h" #include "PeerStorage.h" #include "PieceStorage.h" #include "BtRuntime.h" #include "BtRegistry.h" namespace aria2 { class ShareRatioSeedCriteria : public SeedCriteria { private: double ratio; SharedHandle btContext; SharedHandle peerStorage; SharedHandle pieceStorage; SharedHandle btRuntime; public: ShareRatioSeedCriteria(double ratio, const SharedHandle& btContext) :ratio(ratio), btContext(btContext), peerStorage(PEER_STORAGE(btContext)), pieceStorage(PIECE_STORAGE(btContext)), btRuntime(BT_RUNTIME(btContext)) {} virtual ~ShareRatioSeedCriteria() {} virtual void reset() {} virtual bool evaluate() { if(btContext->getTotalLength() == 0) { return false; } TransferStat stat = peerStorage->calculateStat(); uint64_t allTimeUploadLength = btRuntime->getUploadLengthAtStartup()+stat.getSessionUploadLength(); return ratio <= ((double)allTimeUploadLength)/pieceStorage->getCompletedLength(); } void setRatio(double ratio) { this->ratio = ratio; } double getRatio() const { return ratio; } }; } // namespace aria2 #endif // _D_SHARE_RATIO_SEED_CRITERIA_H_