/* */ #ifndef _D_DHT_PEER_ANNOUNCE_STORAGE_H_ #define _D_DHT_PEER_ANNOUNCE_STORAGE_H_ #include "common.h" #include "DHTPeerAnnounceStorageDecl.h" #include "DHTPeerAnnounceEntryDecl.h" #include "PeerDecl.h" #include "BtContextDecl.h" #include "DHTTaskQueueDecl.h" #include "DHTTaskFactoryDecl.h" class Logger; class DHTPeerAnnounceStorage { private: DHTPeerAnnounceEntries _entries; DHTPeerAnnounceEntryHandle getPeerAnnounceEntry(const unsigned char* infoHash); DHTTaskQueueHandle _taskQueue; DHTTaskFactoryHandle _taskFactory; const Logger* _logger; public: DHTPeerAnnounceStorage(); ~DHTPeerAnnounceStorage(); void addPeerAnnounce(const unsigned char* infoHash, const string& ipaddr, uint16_t port); // add peer announce as localhost downloading the content void addPeerAnnounce(const BtContextHandle& ctx); // give 0 to DHTPeerAnnounceEntry::setBtContext(). // If DHTPeerAnnounceEntry is empty, it is erased. void removePeerAnnounce(const BtContextHandle& ctx); bool contains(const unsigned char* infoHash) const; Peers getPeers(const unsigned char* infoHash); // drop peer announce entry which is not updated in the past // DHT_PEER_ANNOUNCE_PURGE_INTERVAL seconds. void handleTimeout(); // announce peer in every DHT_PEER_ANNOUNCE_PURGE_INTERVAL. // The torrents which are announced in the past DHT_PEER_ANNOUNCE_PURGE_INTERVAL // are excluded from announce. void announcePeer(); void setTaskQueue(const DHTTaskQueueHandle& taskQueue); void setTaskFactory(const DHTTaskFactoryHandle& taskFactory); }; #endif // _D_DHT_PEER_ANNOUNCE_STORAGE_H_