/* */ #ifndef D_DEFAULT_PEER_STORAGE_H #define D_DEFAULT_PEER_STORAGE_H #include "PeerStorage.h" #include #include #include "TimerA2.h" namespace aria2 { class BtRuntime; class BtSeederStateChoke; class BtLeecherStateChoke; class PieceStorage; class DefaultPeerStorage : public PeerStorage { private: SharedHandle btRuntime_; SharedHandle pieceStorage_; size_t maxPeerListSize_; std::deque > peers_; std::deque > droppedPeers_; 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); virtual 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); void setMaxPeerListSize(size_t maxPeerListSize) { maxPeerListSize_ = maxPeerListSize; } }; } // namespace aria2 #endif // D_DEFAULT_PEER_STORAGE_H