/* */ #ifndef _D_PEER_STORAGE_H_ #define _D_PEER_STORAGE_H_ #include "common.h" #include "Peer.h" class TransferStat { public: uint32_t downloadSpeed; uint32_t uploadSpeed; uint64_t sessionDownloadLength; uint64_t sessionUploadLength; public: TransferStat():downloadSpeed(0), uploadSpeed(0), sessionDownloadLength(0), sessionUploadLength(0) {} uint32_t getDownloadSpeed() const { return downloadSpeed; } void setDownloadSpeed(uint32_t s) { downloadSpeed = s; } uint32_t getUploadSpeed() const { return uploadSpeed; } void setUploadSpeed(uint32_t s) { uploadSpeed = s; } /** * Returns the number of bytes downloaded since the program started. * This is not the total number of bytes downloaded. */ uint64_t getSessionDownloadLength() const { return sessionDownloadLength; } void setSessionDownloadLength(uint64_t s) { sessionDownloadLength = s; } /** * Returns the number of bytes uploaded since the program started. * This is not the total number of bytes uploaded. */ uint64_t getSessionUploadLength() const { return sessionUploadLength; } void setSessionUploadLength(uint64_t s) { sessionUploadLength = s; } }; class PeerStorage { public: virtual ~PeerStorage() {} /** * Adds new peer to internal peer list. * If the peer is added successfully, returns true. Otherwise returns false. */ virtual bool addPeer(const PeerHandle& peer) = 0; /** * Adds all peers in peers to internal peer list. */ virtual void addPeer(const Peers& peers) = 0; /** * Returns internal peer list. */ virtual const Peers& getPeers() = 0; /** * Returns one of the unused peers. */ virtual PeerHandle getUnusedPeer() = 0; /** * Returns true if at least one unused peer exists. * Otherwise returns false. */ virtual bool isPeerAvailable() = 0; /** * Returns the list of peers which are currently connected from localhost. */ virtual Peers getActivePeers() = 0; /** * Calculates current download/upload statistics. */ virtual TransferStat calculateStat() = 0; }; typedef SharedHandle PeerStorageHandle; #endif // _D_PEER_STORAGE_H_