From 2a6775e80b1a9ff1b5ccb5e65cb7e8f8d6e5adb9 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 26 Feb 2010 15:37:08 +0000 Subject: [PATCH] 2010-02-27 Tatsuhiro Tsujikawa Supported name attribute of metalink::metaurl element and multi-file torrent with Metalink4. Files with same metaurl are grouped and downloaded in one RequestGroup. * src/BtDependency.cc * src/FileEntry.h * src/Metalink2RequestGroup.cc * src/Metalink2RequestGroup.h * src/MetalinkEntry.cc * src/MetalinkEntry.h * src/MetalinkHelper.cc * src/MetalinkHelper.h * src/MetalinkMetaurl.cc * src/MetalinkMetaurl.h * src/MetalinkParserController.cc * src/RequestGroup.cc * src/RequestGroup.h * src/bittorrent_helper.cc * test/BittorrentHelperTest.cc * test/BtDependencyTest.cc * test/MetalinkHelperTest.cc --- ChangeLog | 23 ++++ src/BtDependency.cc | 62 +++++++--- src/FileEntry.h | 11 ++ src/Metalink2RequestGroup.cc | 207 +++++++++++++++++++------------- src/Metalink2RequestGroup.h | 2 +- src/MetalinkEntry.cc | 4 +- src/MetalinkEntry.h | 4 +- src/MetalinkHelper.cc | 38 ++++++ src/MetalinkHelper.h | 10 +- src/MetalinkMetaurl.cc | 5 + src/MetalinkMetaurl.h | 5 +- src/MetalinkParserController.cc | 1 + src/RequestGroup.cc | 129 +++++++++++++------- src/RequestGroup.h | 3 + src/bittorrent_helper.cc | 2 + test/BittorrentHelperTest.cc | 4 + test/BtDependencyTest.cc | 70 ++++++++++- test/MetalinkHelperTest.cc | 77 +++++++++++- 18 files changed, 500 insertions(+), 157 deletions(-) diff --git a/ChangeLog b/ChangeLog index 91f67b01..4511ac3b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2010-02-27 Tatsuhiro Tsujikawa + + Supported name attribute of metalink::metaurl element and + multi-file torrent with Metalink4. Files with same metaurl are + grouped and downloaded in one RequestGroup. + * src/BtDependency.cc + * src/FileEntry.h + * src/Metalink2RequestGroup.cc + * src/Metalink2RequestGroup.h + * src/MetalinkEntry.cc + * src/MetalinkEntry.h + * src/MetalinkHelper.cc + * src/MetalinkHelper.h + * src/MetalinkMetaurl.cc + * src/MetalinkMetaurl.h + * src/MetalinkParserController.cc + * src/RequestGroup.cc + * src/RequestGroup.h + * src/bittorrent_helper.cc + * test/BittorrentHelperTest.cc + * test/BtDependencyTest.cc + * test/MetalinkHelperTest.cc + 2010-02-26 Tatsuhiro Tsujikawa Store name attribute of metalink:metaurl element in MetalinkMetaurl. diff --git a/src/BtDependency.cc b/src/BtDependency.cc index a2009087..3c70804c 100644 --- a/src/BtDependency.cc +++ b/src/BtDependency.cc @@ -47,6 +47,7 @@ #include "File.h" #include "bittorrent_helper.h" #include "DlAbortEx.h" +#include "StringFormat.h" namespace aria2 { @@ -58,6 +59,18 @@ BtDependency::BtDependency(const RequestGroupWeakHandle& dependant, BtDependency::~BtDependency() {} +static void copyValues(const SharedHandle& d, + const SharedHandle& s) +{ + d->setRequested(true); + d->setPath(s->getPath()); + d->addUris(s->getRemainingUris().begin(), + s->getRemainingUris().end()); + if(!s->isSingleHostMultiConnectionEnabled()) { + d->disableSingleHostMultiConnection(); + } +} + bool BtDependency::resolve() { if(_dependee->getNumCommand() == 0 && _dependee->downloadFinished()) { @@ -80,23 +93,38 @@ bool BtDependency::resolve() bittorrent::loadFromMemory (content, context, File(dependee->getFirstFilePath()).getBasename()); } - if(context->getFileEntries().size() != - _dependant->getDownloadContext()->getFileEntries().size()) { - throw DL_ABORT_EX("The number of file in torrent doesn't match to" - " the dependent."); - } - // Copy file path in _dependant's FileEntries to newly created - // context's FileEntries to endorse the path structure of - // _dependant. URIs and singleHostMultiConnection are also copied. - for(std::vector >::const_iterator s = - _dependant->getDownloadContext()->getFileEntries().begin(), - d = context->getFileEntries().begin(); - d != context->getFileEntries().end(); ++s, ++d) { - (*d)->setPath((*s)->getPath()); - (*d)->addUris((*s)->getRemainingUris().begin(), - (*s)->getRemainingUris().end()); - if(!(*s)->isSingleHostMultiConnectionEnabled()) { - (*d)->disableSingleHostMultiConnection(); + const std::vector >& fileEntries = + context->getFileEntries(); + const std::vector >& dependantFileEntries = + _dependant->getDownloadContext()->getFileEntries(); + // If dependant's FileEntry::getOriginalName() is empty, we + // assume that torrent is single file. In Metalink3, this is + // always assumed. + if(fileEntries.size() == 1 && dependantFileEntries.size() == 1 && + dependantFileEntries[0]->getOriginalName().empty()) { + copyValues(fileEntries[0], dependantFileEntries[0]); + } else { + std::for_each(fileEntries.begin(), fileEntries.end(), + std::bind2nd(mem_fun_sh(&FileEntry::setRequested),false)); + // Copy file path in _dependant's FileEntries to newly created + // context's FileEntries to endorse the path structure of + // _dependant. URIs and singleHostMultiConnection are also copied. + for(std::vector >::const_iterator s = + dependantFileEntries.begin(); s != dependantFileEntries.end(); + ++s){ + std::vector >::const_iterator d = + context->getFileEntries().begin(); + for(; d != context->getFileEntries().end(); ++d) { + if((*d)->getOriginalName() == (*s)->getOriginalName()) { + break; + } + } + if(d == context->getFileEntries().end()) { + throw DL_ABORT_EX + (StringFormat("No entry %s in torrent file", + (*s)->getOriginalName().c_str()).str()); + } + copyValues(*d, *s); } } } catch(RecoverableException& e) { diff --git a/src/FileEntry.h b/src/FileEntry.h index 2dfe7eda..0199ba28 100644 --- a/src/FileEntry.h +++ b/src/FileEntry.h @@ -70,6 +70,7 @@ private: // available. std::deque _uriResults; bool _singleHostMultiConnection; + std::string _originalName; Logger* _logger; void storePool(const SharedHandle& request); @@ -227,6 +228,16 @@ public: void reuseUri(size_t num); void releaseRuntimeResource(); + + void setOriginalName(const std::string& originalName) + { + _originalName = originalName; + } + + const std::string& getOriginalName() const + { + return _originalName; + } }; typedef SharedHandle FileEntryHandle; diff --git a/src/Metalink2RequestGroup.cc b/src/Metalink2RequestGroup.cc index 74e1b2d5..4ccd924e 100644 --- a/src/Metalink2RequestGroup.cc +++ b/src/Metalink2RequestGroup.cc @@ -136,57 +136,66 @@ void removeMetalinkContentTypes(const SharedHandle& group) void Metalink2RequestGroup::createRequestGroup (std::deque >& groups, - std::deque > entries, + const std::deque >& entries, const SharedHandle