/* */ #include "BtRegistry.h" #include "DlAbortEx.h" #include "DownloadContext.h" #include "PeerStorage.h" #include "PieceStorage.h" #include "BtAnnounce.h" #include "BtRuntime.h" #include "BtProgressInfoFile.h" #include "bittorrent_helper.h" #include "LpdMessageReceiver.h" #include "UDPTrackerClient.h" #include "NullHandle.h" namespace aria2 { BtRegistry::BtRegistry() : tcpPort_{0}, udpPort_{0} {} const std::shared_ptr& BtRegistry::getDownloadContext(a2_gid_t gid) const { auto res = get(gid); if (res) { return res->downloadContext; } else { return getNull(); } } const std::shared_ptr& BtRegistry::getDownloadContext(const std::string& infoHash) const { for (auto& kv : pool_) { if (bittorrent::getTorrentAttrs(kv.second->downloadContext)->infoHash == infoHash) { return kv.second->downloadContext; } } return getNull(); } void BtRegistry::put(a2_gid_t gid, std::unique_ptr obj) { pool_[gid] = std::move(obj); } BtObject* BtRegistry::get(a2_gid_t gid) const { auto i = pool_.find(gid); if (i == std::end(pool_)) { return nullptr; } else { return (*i).second.get(); } } bool BtRegistry::remove(a2_gid_t gid) { return pool_.erase(gid); } void BtRegistry::removeAll() { pool_.clear(); } void BtRegistry::setLpdMessageReceiver( const std::shared_ptr& receiver) { lpdMessageReceiver_ = receiver; } void BtRegistry::setUDPTrackerClient( const std::shared_ptr& tracker) { udpTrackerClient_ = tracker; } BtObject::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) : downloadContext{downloadContext}, pieceStorage{pieceStorage}, peerStorage{peerStorage}, btAnnounce{btAnnounce}, btRuntime{btRuntime}, btProgressInfoFile{btProgressInfoFile} { } BtObject::BtObject() {} } // namespace aria2