/* */ #ifndef D_PEER_STAT_H #define D_PEER_STAT_H #include "common.h" #include #include "SpeedCalc.h" #include "SharedHandle.h" #include "Command.h" namespace aria2 { class PeerStat { public: enum STATUS { IDLE, ACTIVE, }; private: cuid_t cuid_; std::string hostname_; std::string protocol_; SpeedCalc downloadSpeed_; SpeedCalc uploadSpeed_; Timer downloadStartTime_; PeerStat::STATUS status_; unsigned int avgDownloadSpeed_; unsigned int avgUploadSpeed_; uint64_t sessionDownloadLength_; uint64_t sessionUploadLength_; public: PeerStat (cuid_t cuid, const std::string& hostname, const::std::string& protocol); PeerStat(cuid_t cuid = 0); ~PeerStat(); // Don't allow copying PeerStat(const PeerStat&); PeerStat& operator=(const PeerStat&); /** * Returns current download speed in byte per sec. */ unsigned int calculateDownloadSpeed(); unsigned int calculateAvgDownloadSpeed(); unsigned int calculateUploadSpeed(); unsigned int calculateAvgUploadSpeed(); void updateDownloadLength(size_t bytes); void updateUploadLength(size_t bytes); unsigned int getMaxDownloadSpeed() const; unsigned int getMaxUploadSpeed() const; unsigned int getAvgDownloadSpeed() const { return avgDownloadSpeed_; } unsigned int getAvgUploadSpeed() const { return avgUploadSpeed_; } void reset(); void downloadStart(); void downloadStop(); const Timer& getDownloadStartTime() const { return downloadStartTime_; } PeerStat::STATUS getStatus() const { return status_; } cuid_t getCuid() const { return cuid_; } const std::string& getHostname() const { return hostname_; } const std::string& getProtocol() const { return protocol_; } uint64_t getSessionDownloadLength() const { return sessionDownloadLength_; } uint64_t getSessionUploadLength() const { return sessionUploadLength_; } void addSessionDownloadLength(uint64_t length) { sessionDownloadLength_ += length; } }; typedef SharedHandle PeerStatHandle; } // namespace aria2 #endif // D_PEER_STAT_H