/* */ #ifndef _D_DEFAULT_PEER_STORAGE_H_ #define _D_DEFAULT_PEER_STORAGE_H_ #include "PeerStorage.h" #include #include "TimerA2.h" namespace aria2 { class Logger; class BtRuntime; class BtSeederStateChoke; class BtLeecherStateChoke; class PieceStorage; class DefaultPeerStorage : public PeerStorage { private: SharedHandle btRuntime_; SharedHandle pieceStorage_; std::deque > peers_; std::deque > droppedPeers_; Logger* logger_; uint64_t removedPeerSessionDownloadLength_; uint64_t removedPeerSessionUploadLength_; BtSeederStateChoke* seederStateChoke_; BtLeecherStateChoke* leecherStateChoke_; std::map peerTransferStatMap_; Timer lastTransferStatMapUpdated_; TransferStat cachedTransferStat_; bool isPeerAlreadyAdded(const SharedHandle& peer); void addDroppedPeer(const SharedHandle& peer); public: DefaultPeerStorage(); virtual ~DefaultPeerStorage(); virtual bool addPeer(const SharedHandle& peer); size_t countPeer() const; virtual SharedHandle getUnusedPeer(); SharedHandle getPeer(const std::string& ipaddr, uint16_t port) const; virtual void addPeer(const std::vector >& peers); virtual const std::deque >& getPeers(); virtual const std::deque >& getDroppedPeers(); virtual bool isPeerAvailable(); virtual void getActivePeers(std::vector >& peers); virtual TransferStat calculateStat(); virtual void updateTransferStatFor(const SharedHandle& peer); virtual TransferStat getTransferStatFor(const SharedHandle& peer); virtual void returnPeer(const SharedHandle& peer); virtual bool chokeRoundIntervalElapsed(); virtual void executeChoke(); void deleteUnusedPeer(size_t delSize); void onErasingPeer(const SharedHandle& peer); void onReturningPeer(const SharedHandle& peer); void setPieceStorage(const SharedHandle& pieceStorage); void setBtRuntime(const SharedHandle& btRuntime); }; } // namespace aria2 #endif // _D_DEFAULT_PEER_STORAGE_H_