diff --git a/src/BtDependency.cc b/src/BtDependency.cc index 9c9976bf..4e8a9565 100644 --- a/src/BtDependency.cc +++ b/src/BtDependency.cc @@ -101,7 +101,7 @@ bool BtDependency::resolve() diskAdaptor->openExistingFile(); std::string content = util::toString(diskAdaptor); if(dependee->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) { - std::shared_ptr attrs = + auto attrs = bittorrent::getTorrentAttrs(dependee->getDownloadContext()); bittorrent::loadFromMemory (bittorrent::metadata2Torrent(content, attrs), context, diff --git a/src/BtSetup.cc b/src/BtSetup.cc index 43457d86..b3f446bd 100644 --- a/src/BtSetup.cc +++ b/src/BtSetup.cc @@ -98,7 +98,7 @@ void BtSetup::setup(std::vector& commands, if(!requestGroup->getDownloadContext()->hasAttribute(CTX_ATTR_BT)){ return; } - std::shared_ptr torrentAttrs = + auto torrentAttrs = bittorrent::getTorrentAttrs(requestGroup->getDownloadContext()); bool metadataGetMode = torrentAttrs->metadata.empty(); const std::shared_ptr& btReg = e->getBtRegistry(); diff --git a/src/DefaultBtInteractive.cc b/src/DefaultBtInteractive.cc index 61b8343d..c6c088e9 100644 --- a/src/DefaultBtInteractive.cc +++ b/src/DefaultBtInteractive.cc @@ -195,8 +195,7 @@ void DefaultBtInteractive::addHandshakeExtendedMessageToQueue() m->setClientVersion("aria2/" PACKAGE_VERSION); m->setTCPPort(tcpPort_); m->setExtensions(extensionMessageRegistry_->getExtensions()); - std::shared_ptr attrs = - bittorrent::getTorrentAttrs(downloadContext_); + auto attrs = bittorrent::getTorrentAttrs(downloadContext_); if(!attrs->metadata.empty()) { m->setMetadataSize(attrs->metadataSize); } diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc index 1c400b33..811c68b7 100644 --- a/src/DefaultPieceStorage.cc +++ b/src/DefaultPieceStorage.cc @@ -478,8 +478,7 @@ void DefaultPieceStorage::completePiece(const std::shared_ptr& piece) } #ifdef ENABLE_BITTORRENT if(downloadContext_->hasAttribute(CTX_ATTR_BT)) { - std::shared_ptr torrentAttrs = - bittorrent::getTorrentAttrs(downloadContext_); + auto torrentAttrs = bittorrent::getTorrentAttrs(downloadContext_); if(!torrentAttrs->metadata.empty()) { #ifdef __MINGW32__ // On Windows, if aria2 opens files with GENERIC_WRITE access diff --git a/src/DownloadContext.cc b/src/DownloadContext.cc index 7fba6d55..5620cc5f 100644 --- a/src/DownloadContext.cc +++ b/src/DownloadContext.cc @@ -150,19 +150,18 @@ void DownloadContext::setFileFilter(SegList& sgl) } void DownloadContext::setAttribute -(ContextAttributeType key, const std::shared_ptr& value) +(ContextAttributeType key, std::unique_ptr&& value) { assert(key < MAX_CTX_ATTR); - attrs_[key] = value; + attrs_[key] = std::move(value); } -const std::shared_ptr& DownloadContext::getAttribute -(ContextAttributeType key) +ContextAttribute* DownloadContext::getAttribute(ContextAttributeType key) { assert(key < MAX_CTX_ATTR); - const std::shared_ptr& attr = attrs_[key]; + const std::unique_ptr& attr = attrs_[key]; if(attr) { - return attr; + return attr.get(); } else { throw DL_ABORT_EX(fmt("No attribute named %s", strContextAttributeType(key))); diff --git a/src/DownloadContext.h b/src/DownloadContext.h index ee5df7be..ddac615d 100644 --- a/src/DownloadContext.h +++ b/src/DownloadContext.h @@ -78,7 +78,7 @@ private: RequestGroup* ownerRequestGroup_; - std::vector > attrs_; + std::vector > attrs_; NetStat netStat_; @@ -204,9 +204,9 @@ public: } void setAttribute - (ContextAttributeType key, const std::shared_ptr& value); + (ContextAttributeType key, std::unique_ptr&& value); - const std::shared_ptr& getAttribute(ContextAttributeType key); + ContextAttribute* getAttribute(ContextAttributeType key); bool hasAttribute(ContextAttributeType key) const; diff --git a/src/HandshakeExtensionMessage.cc b/src/HandshakeExtensionMessage.cc index 1a39e782..f37526f1 100644 --- a/src/HandshakeExtensionMessage.cc +++ b/src/HandshakeExtensionMessage.cc @@ -109,7 +109,7 @@ void HandshakeExtensionMessage::doReceivedAction() peer_->setExtension(i, id); } } - std::shared_ptr attrs = bittorrent::getTorrentAttrs(dctx_); + auto attrs = bittorrent::getTorrentAttrs(dctx_); if(attrs->metadata.empty()) { if(!peer_->getExtensionMessageID(ExtensionMessageRegistry::UT_METADATA)) { // TODO In metadataGetMode, if peer don't support metadata diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc index c9e118c3..35b18328 100644 --- a/src/PeerInteractionCommand.cc +++ b/src/PeerInteractionCommand.cc @@ -114,7 +114,7 @@ PeerInteractionCommand::PeerInteractionCommand family = AF_INET; } - std::shared_ptr torrentAttrs = + auto torrentAttrs = bittorrent::getTorrentAttrs(requestGroup_->getDownloadContext()); bool metadataGetMode = torrentAttrs->metadata.empty(); diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index 66bc2898..74e028fc 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -287,8 +287,7 @@ void RequestGroup::createInitialCommand #ifdef ENABLE_BITTORRENT { if(downloadContext_->hasAttribute(CTX_ATTR_BT)) { - std::shared_ptr torrentAttrs = - bittorrent::getTorrentAttrs(downloadContext_); + auto torrentAttrs = bittorrent::getTorrentAttrs(downloadContext_); bool metadataGetMode = torrentAttrs->metadata.empty(); if(option_->getAsBool(PREF_DRY_RUN)) { throw DOWNLOAD_FAILURE_EXCEPTION @@ -1207,8 +1206,7 @@ void RequestGroup::reportDownloadFinished() int64_t completedLength = getCompletedLength(); double shareRatio = completedLength == 0 ? 0.0 : 1.0*stat.allTimeUploadLength/completedLength; - std::shared_ptr attrs = - bittorrent::getTorrentAttrs(downloadContext_); + auto attrs = bittorrent::getTorrentAttrs(downloadContext_); if(!attrs->metadata.empty()) { A2_LOG_NOTICE(fmt(MSG_SHARE_RATIO_REPORT, shareRatio, diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc index 4118104e..ddbb8435 100644 --- a/src/RpcMethodImpl.cc +++ b/src/RpcMethodImpl.cc @@ -697,8 +697,7 @@ void gatherProgressCommon #ifdef ENABLE_BITTORRENT void gatherBitTorrentMetadata -(const std::shared_ptr& btDict, - const std::shared_ptr& torrentAttrs) +(const std::shared_ptr& btDict, TorrentAttribute* torrentAttrs) { if(!torrentAttrs->comment.empty()) { btDict->put(KEY_COMMENT, torrentAttrs->comment); @@ -731,7 +730,7 @@ void gatherBitTorrentMetadata namespace { void gatherProgressBitTorrent (const std::shared_ptr& entryDict, - const std::shared_ptr& torrentAttrs, + TorrentAttribute* torrentAttrs, const std::shared_ptr& btObject, const std::vector& keys) { @@ -801,7 +800,7 @@ void gatherProgress gatherProgressCommon(entryDict, group, keys); #ifdef ENABLE_BITTORRENT if(group->getDownloadContext()->hasAttribute(CTX_ATTR_BT)) { - std::shared_ptr torrentAttrs = + auto torrentAttrs = bittorrent::getTorrentAttrs(group->getDownloadContext()); const std::shared_ptr& btObject = e->getBtRegistry()->get(group->getGID()); diff --git a/src/RpcMethodImpl.h b/src/RpcMethodImpl.h index 04265229..0a5a9b4a 100644 --- a/src/RpcMethodImpl.h +++ b/src/RpcMethodImpl.h @@ -599,8 +599,7 @@ void gatherProgressCommon #ifdef ENABLE_BITTORRENT // Helper function to store BitTorrent metadata from torrentAttrs. void gatherBitTorrentMetadata -(const std::shared_ptr& btDict, - const std::shared_ptr& torrentAttrs); +(const std::shared_ptr& btDict, TorrentAttribute* torrentAttrs); #endif // ENABLE_BITTORRENT } // namespace rpc diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc index 4c95236e..5b1d63da 100644 --- a/src/TrackerWatcherCommand.cc +++ b/src/TrackerWatcherCommand.cc @@ -328,8 +328,7 @@ namespace { bool backupTrackerIsAvailable (const std::shared_ptr& context) { - std::shared_ptr torrentAttrs = - bittorrent::getTorrentAttrs(context); + auto torrentAttrs = bittorrent::getTorrentAttrs(context); if(torrentAttrs->announceList.size() >= 2) { return true; } diff --git a/src/UTMetadataPostDownloadHandler.cc b/src/UTMetadataPostDownloadHandler.cc index da9f1a4a..82084243 100644 --- a/src/UTMetadataPostDownloadHandler.cc +++ b/src/UTMetadataPostDownloadHandler.cc @@ -59,7 +59,7 @@ bool UTMetadataPostDownloadHandler::Criteria::match const std::shared_ptr& dctx = requestGroup->getDownloadContext(); if(dctx->hasAttribute(CTX_ATTR_BT)) { - std::shared_ptr attrs = bittorrent::getTorrentAttrs(dctx); + auto attrs = bittorrent::getTorrentAttrs(dctx); if(attrs->metadata.empty()) { return true; } @@ -77,7 +77,7 @@ void UTMetadataPostDownloadHandler::getNextRequestGroups (std::vector >& groups, RequestGroup* requestGroup) { const std::shared_ptr& dctx =requestGroup->getDownloadContext(); - std::shared_ptr attrs = bittorrent::getTorrentAttrs(dctx); + auto attrs = bittorrent::getTorrentAttrs(dctx); std::string metadata = util::toString(requestGroup->getPieceStorage()->getDiskAdaptor()); std::string torrent = bittorrent::metadata2Torrent(metadata, attrs); diff --git a/src/UTMetadataRequestExtensionMessage.cc b/src/UTMetadataRequestExtensionMessage.cc index f4444123..695be23e 100644 --- a/src/UTMetadataRequestExtensionMessage.cc +++ b/src/UTMetadataRequestExtensionMessage.cc @@ -76,7 +76,7 @@ std::string UTMetadataRequestExtensionMessage::toString() const void UTMetadataRequestExtensionMessage::doReceivedAction() { - std::shared_ptr attrs = bittorrent::getTorrentAttrs(dctx_); + auto attrs = bittorrent::getTorrentAttrs(dctx_); uint8_t id = peer_->getExtensionMessageID (ExtensionMessageRegistry::UT_METADATA); if(attrs->metadata.empty()) { diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc index 07e9259f..e907ab0f 100644 --- a/src/bittorrent_helper.cc +++ b/src/bittorrent_helper.cc @@ -129,17 +129,16 @@ void extractPieceHash(const std::shared_ptr& ctx, namespace { void extractUrlList -(const std::shared_ptr& torrent, std::vector& uris, +(TorrentAttribute* torrent, std::vector& uris, const ValueBase* v) { class UrlListVisitor:public ValueBaseVisitor { private: std::vector& uris_; - const std::shared_ptr& torrent_; + TorrentAttribute* torrent_; public: UrlListVisitor - (std::vector& uris, - const std::shared_ptr& torrent): + (std::vector& uris, TorrentAttribute* torrent): uris_(uris), torrent_(torrent) {} virtual void visit(const String& v) @@ -195,7 +194,7 @@ OutputIterator createUri namespace { void extractFileEntries (const std::shared_ptr& ctx, - const std::shared_ptr& torrent, + TorrentAttribute* torrent, const Dict* infoDict, const std::shared_ptr