/* */ #ifndef _D_DEFAULT_PEER_STORAGE_H_ #define _D_DEFAULT_PEER_STORAGE_H_ #include "PeerStorage.h" #include "BtContext.h" #include "Option.h" #include "Logger.h" #include "BtRuntime.h" #define MAX_PEER_LIST_SIZE 60 #define MAX_PEER_ERROR 5 class DefaultPeerStorage : public PeerStorage { private: BtContextHandle btContext; const Option* option; Peers peers; int32_t maxPeerListSize; Logger* logger; BtRuntimeHandle btRuntime; int64_t removedPeerSessionDownloadLength; int64_t removedPeerSessionUploadLength; bool isPeerAlreadyAdded(const PeerHandle& peer); public: DefaultPeerStorage(BtContextHandle btContext, const Option* option); virtual ~DefaultPeerStorage(); void setBtRuntime(const BtRuntimeHandle& btRuntime) { this->btRuntime = btRuntime; } BtRuntimeHandle getBtRuntime() const { return btRuntime; } virtual bool addPeer(const PeerHandle& peer); int32_t countPeer() const; virtual PeerHandle getUnusedPeer(); PeerHandle getPeer(const string& ipaddr, int32_t port) const; virtual void addPeer(const Peers& peers); virtual const Peers& getPeers(); virtual bool isPeerAvailable(); virtual Peers getActivePeers(); virtual TransferStat calculateStat(); virtual void returnPeer(const PeerHandle& peer); void setMaxPeerListSize(int32_t size) { this->maxPeerListSize = size; } int32_t getMaxPeerListSize() const { return maxPeerListSize; } void deleteUnusedPeer(int32_t delSize); void onErasingPeer(const PeerHandle& peer); }; #endif // _D_DEFAULT_PEER_STORAGE_H_