/* */ #ifndef D_BT_REGISTRY_H #define D_BT_REGISTRY_H #include "common.h" #include #include #include "RequestGroup.h" namespace aria2 { class PeerStorage; class PieceStorage; class BtAnnounce; class BtRuntime; class BtProgressInfoFile; class DownloadContext; class LpdMessageReceiver; class UDPTrackerClient; struct BtObject { std::shared_ptr downloadContext; std::shared_ptr pieceStorage; std::shared_ptr peerStorage; std::shared_ptr btAnnounce; std::shared_ptr btRuntime; std::shared_ptr btProgressInfoFile; BtObject(const std::shared_ptr& downloadContext, const std::shared_ptr& pieceStorage, const std::shared_ptr& peerStorage, const std::shared_ptr& btAnnounce, const std::shared_ptr& btRuntime, const std::shared_ptr& btProgressInfoFile); BtObject(); }; class BtRegistry { private: std::map> pool_; uint16_t tcpPort_; // This is UDP port for DHT and UDP tracker. But currently UDP // tracker is not supported in IPv6. uint16_t udpPort_; std::shared_ptr lpdMessageReceiver_; std::shared_ptr udpTrackerClient_; public: BtRegistry(); const std::shared_ptr& getDownloadContext(a2_gid_t gid) const; const std::shared_ptr& getDownloadContext(const std::string& infoHash) const; void put(a2_gid_t gid, std::unique_ptr obj); BtObject* get(a2_gid_t gid) const; template OutputIterator getAllDownloadContext(OutputIterator dest) { for (auto& kv : pool_) { *dest++ = kv.second->downloadContext; } return dest; } void removeAll(); bool remove(a2_gid_t gid); void setTcpPort(uint16_t port) { tcpPort_ = port; } uint16_t getTcpPort() const { return tcpPort_; } void setUdpPort(uint16_t port) { udpPort_ = port; } uint16_t getUdpPort() const { return udpPort_; } void setLpdMessageReceiver(const std::shared_ptr& receiver); const std::shared_ptr& getLpdMessageReceiver() const { return lpdMessageReceiver_; } void setUDPTrackerClient(const std::shared_ptr& tracker); const std::shared_ptr& getUDPTrackerClient() const { return udpTrackerClient_; } }; } // namespace aria2 #endif // D_BT_REGISTRY_H