/* */ #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" class ShareRatioSeedCriteria : public SeedCriteria { private: double ratio; BtContextHandle btContext; PeerStorageHandle peerStorage; PieceStorageHandle pieceStorage; BtRuntimeHandle btRuntime; public: ShareRatioSeedCriteria(double ratio, const BtContextHandle& 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(); long long int allTimeUploadLength = btRuntime->getUploadLengthAtStartup()+stat.getSessionUploadLength(); return ratio <= ((double)allTimeUploadLength)/pieceStorage->getCompletedLength(); } void setRatio(double ratio) { this->ratio = ratio; } double getRatio() const { return ratio; } }; #endif // _D_SHARE_RATIO_SEED_CRITERIA_H_