From e82f870fdc3c1a7fc2c0b66a9f623a5386ece3d6 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 29 Jun 2009 08:42:58 +0000 Subject: [PATCH] 2009-06-29 Tatsuhiro Tsujikawa Removed _uris from RequestGroup. All functions that refer to _uris were moved to FileEntry. Exit status code are now defined in DownloadResultCode.h. * src/AbstractCommand.cc * src/AdaptiveURISelector.cc * src/AdaptiveURISelector.h * src/AutoSaveCommand.cc * src/BtPostDownloadHandler.cc * src/CheckIntegrityDispatcherCommand.cc * src/CookieStorage.cc * src/DHTAutoSaveCommand.cc * src/DHTBucketRefreshCommand.cc * src/DHTEntryPointNameResolveCommand.cc * src/DHTInteractionCommand.cc * src/DHTPeerAnnounceCommand.cc * src/DHTTokenUpdateCommand.cc * src/DlAbortEx.h * src/DlRetryEx.h * src/DownloadCommand.cc * src/DownloadContext.h * src/DownloadFailureException.h * src/DownloadResult.h * src/DownloadResultCode.h * src/FeedbackURISelector.cc * src/FeedbackURISelector.h * src/FileEntry.cc * src/FileEntry.h * src/FtpNegotiationCommand.cc * src/HttpListenCommand.cc * src/HttpResponseCommand.cc * src/HttpServerResponseCommand.cc * src/HttpSkipResponseCommand.cc * src/InOrderURISelector.cc * src/InOrderURISelector.h * src/Makefile.am * src/Makefile.in * src/Metalink2RequestGroup.cc * src/MultiUrlRequestInfo.cc * src/MultiUrlRequestInfo.h * src/OptionHandlerFactory.cc * src/PeerListenCommand.cc * src/RecoverableException.h * src/RequestGroup.cc * src/RequestGroup.h * src/RequestGroupMan.cc * src/RequestGroupMan.h * src/TimedHaltCommand.cc * src/TrackerWatcherCommand.cc * src/URIResult.cc * src/URIResult.h * src/URISelector.h * src/XmlRpcMethodImpl.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/download_helper.cc * src/main.cc * src/option_processing.cc * test/BtDependencyTest.cc * test/BtPostDownloadHandlerTest.cc * test/CookieStorageTest.cc * test/DefaultBtMessageDispatcherTest.cc * test/DownloadHandlerFactoryTest.cc * test/DownloadHelperTest.cc * test/FeedbackURISelectorTest.cc * test/FileEntryTest.cc * test/InOrderURISelectorTest.cc * test/Metalink2RequestGroupTest.cc * test/MetalinkPostDownloadHandlerTest.cc * test/RequestGroupManTest.cc * test/RequestGroupTest.cc * test/XmlRpcMethodTest.cc --- ChangeLog | 74 ++++++++++ src/AbstractCommand.cc | 15 +- src/AdaptiveURISelector.cc | 12 +- src/AdaptiveURISelector.h | 4 +- src/AutoSaveCommand.cc | 1 + src/BtPostDownloadHandler.cc | 2 +- src/CheckIntegrityDispatcherCommand.cc | 1 + src/CookieStorage.cc | 1 + src/DHTAutoSaveCommand.cc | 1 + src/DHTBucketRefreshCommand.cc | 1 + src/DHTEntryPointNameResolveCommand.cc | 1 + src/DHTInteractionCommand.cc | 1 + src/DHTPeerAnnounceCommand.cc | 1 + src/DHTTokenUpdateCommand.cc | 1 + src/DlAbortEx.h | 2 +- src/DlRetryEx.h | 2 +- src/DownloadCommand.cc | 2 +- src/DownloadContext.h | 2 +- src/DownloadFailureException.h | 3 +- src/DownloadResult.h | 32 +---- src/DownloadResultCode.h | 59 ++++++++ src/FeedbackURISelector.cc | 4 +- src/FeedbackURISelector.h | 4 +- src/FileEntry.cc | 60 +++++++- src/FileEntry.h | 32 ++++- src/FtpNegotiationCommand.cc | 12 +- src/HttpListenCommand.cc | 1 + src/HttpResponseCommand.cc | 6 +- src/HttpServerResponseCommand.cc | 1 + src/HttpSkipResponseCommand.cc | 2 +- src/InOrderURISelector.cc | 4 +- src/InOrderURISelector.h | 2 +- src/Makefile.am | 3 +- src/Makefile.in | 21 +-- src/Metalink2RequestGroup.cc | 6 +- src/MultiUrlRequestInfo.cc | 8 +- src/MultiUrlRequestInfo.h | 2 +- src/OptionHandlerFactory.cc | 1 + src/PeerListenCommand.cc | 1 + src/RecoverableException.h | 14 +- src/RequestGroup.cc | 180 +++++++++--------------- src/RequestGroup.h | 66 ++------- src/RequestGroupMan.cc | 28 ++-- src/RequestGroupMan.h | 8 +- src/TimedHaltCommand.cc | 1 + src/TrackerWatcherCommand.cc | 2 +- src/URIResult.cc | 2 +- src/URIResult.h | 8 +- src/URISelector.h | 5 +- src/XmlRpcMethodImpl.cc | 8 +- src/bittorrent_helper.cc | 54 ++++++- src/bittorrent_helper.h | 18 +++ src/download_helper.cc | 13 +- src/main.cc | 8 +- src/option_processing.cc | 20 +-- test/BtDependencyTest.cc | 6 +- test/BtPostDownloadHandlerTest.cc | 6 +- test/CookieStorageTest.cc | 1 + test/DefaultBtMessageDispatcherTest.cc | 2 +- test/DownloadHandlerFactoryTest.cc | 8 +- test/DownloadHelperTest.cc | 32 ++--- test/FeedbackURISelectorTest.cc | 28 ++-- test/FileEntryTest.cc | 45 ++++++ test/InOrderURISelectorTest.cc | 23 +-- test/Metalink2RequestGroupTest.cc | 8 +- test/MetalinkPostDownloadHandlerTest.cc | 6 +- test/RequestGroupManTest.cc | 6 +- test/RequestGroupTest.cc | 74 ++-------- test/XmlRpcMethodTest.cc | 14 +- 69 files changed, 640 insertions(+), 442 deletions(-) create mode 100644 src/DownloadResultCode.h diff --git a/ChangeLog b/ChangeLog index 927c4062..88744514 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,77 @@ +2009-06-29 Tatsuhiro Tsujikawa + + Removed _uris from RequestGroup. All functions that refer to _uris + were moved to FileEntry. Exit status code are now defined in + DownloadResultCode.h. + * src/AbstractCommand.cc + * src/AdaptiveURISelector.cc + * src/AdaptiveURISelector.h + * src/AutoSaveCommand.cc + * src/BtPostDownloadHandler.cc + * src/CheckIntegrityDispatcherCommand.cc + * src/CookieStorage.cc + * src/DHTAutoSaveCommand.cc + * src/DHTBucketRefreshCommand.cc + * src/DHTEntryPointNameResolveCommand.cc + * src/DHTInteractionCommand.cc + * src/DHTPeerAnnounceCommand.cc + * src/DHTTokenUpdateCommand.cc + * src/DlAbortEx.h + * src/DlRetryEx.h + * src/DownloadCommand.cc + * src/DownloadContext.h + * src/DownloadFailureException.h + * src/DownloadResult.h + * src/DownloadResultCode.h + * src/FeedbackURISelector.cc + * src/FeedbackURISelector.h + * src/FileEntry.cc + * src/FileEntry.h + * src/FtpNegotiationCommand.cc + * src/HttpListenCommand.cc + * src/HttpResponseCommand.cc + * src/HttpServerResponseCommand.cc + * src/HttpSkipResponseCommand.cc + * src/InOrderURISelector.cc + * src/InOrderURISelector.h + * src/Makefile.am + * src/Makefile.in + * src/Metalink2RequestGroup.cc + * src/MultiUrlRequestInfo.cc + * src/MultiUrlRequestInfo.h + * src/OptionHandlerFactory.cc + * src/PeerListenCommand.cc + * src/RecoverableException.h + * src/RequestGroup.cc + * src/RequestGroup.h + * src/RequestGroupMan.cc + * src/RequestGroupMan.h + * src/TimedHaltCommand.cc + * src/TrackerWatcherCommand.cc + * src/URIResult.cc + * src/URIResult.h + * src/URISelector.h + * src/XmlRpcMethodImpl.cc + * src/bittorrent_helper.cc + * src/bittorrent_helper.h + * src/download_helper.cc + * src/main.cc + * src/option_processing.cc + * test/BtDependencyTest.cc + * test/BtPostDownloadHandlerTest.cc + * test/CookieStorageTest.cc + * test/DefaultBtMessageDispatcherTest.cc + * test/DownloadHandlerFactoryTest.cc + * test/DownloadHelperTest.cc + * test/FeedbackURISelectorTest.cc + * test/FileEntryTest.cc + * test/InOrderURISelectorTest.cc + * test/Metalink2RequestGroupTest.cc + * test/MetalinkPostDownloadHandlerTest.cc + * test/RequestGroupManTest.cc + * test/RequestGroupTest.cc + * test/XmlRpcMethodTest.cc + 2009-06-28 Tatsuhiro Tsujikawa Removed MockBtContext.h * test/Makefile.am diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index 2c05a555..7e1a43cc 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -174,7 +174,7 @@ bool AbstractCommand::execute() { req->getProtocol()); ss->setError(); - throw DL_RETRY_EX2(EX_TIME_OUT, DownloadResult::TIME_OUT); + throw DL_RETRY_EX2(EX_TIME_OUT, downloadresultcode::TIME_OUT); } e->commands.push_back(this); return false; @@ -187,7 +187,8 @@ bool AbstractCommand::execute() { DL_ABORT_EX2(StringFormat ("URI=%s", req->getCurrentUrl().c_str()).str(),err), cuid, req->getUrl().c_str()); - _requestGroup->addURIResult(req->getUrl(), err.getCode()); + _fileEntry->addURIResult(req->getUrl(), err.getCode()); + _requestGroup->setLastUriResult(req->getUrl(), err.getCode()); } onAbort(); // TODO Do we need this? @@ -195,6 +196,7 @@ bool AbstractCommand::execute() { tryReserved(); return true; } catch(DlRetryEx& err) { + // TODO1.5 Consider the case when req is null logger->info(MSG_RESTARTING_DOWNLOAD, DL_RETRY_EX2(StringFormat ("URI=%s", req->getCurrentUrl().c_str()).str(),err), @@ -214,15 +216,18 @@ bool AbstractCommand::execute() { if(isAbort) { logger->info(MSG_MAX_TRY, cuid, req->getTryCount()); logger->error(MSG_DOWNLOAD_ABORTED, err, cuid, req->getUrl().c_str()); - _requestGroup->addURIResult(req->getUrl(), err.getCode()); + _fileEntry->addURIResult(req->getUrl(), err.getCode()); + _requestGroup->setLastUriResult(req->getUrl(), err.getCode()); tryReserved(); return true; } else { return prepareForRetry(getOption()->getAsInt(PREF_RETRY_WAIT)); } } catch(DownloadFailureException& err) { + // TODO1.5 Consider the case when req is null logger->error(EX_EXCEPTION_CAUGHT, err); - _requestGroup->addURIResult(req->getUrl(), err.getCode()); + _fileEntry->addURIResult(req->getUrl(), err.getCode()); + _requestGroup->setLastUriResult(req->getUrl(), err.getCode()); _requestGroup->setHaltRequested(true); return true; } @@ -279,7 +284,7 @@ void AbstractCommand::onAbort() { // TODO This might be a problem if the failure is caused by proxy. e->_requestGroupMan->getOrCreateServerStat(req->getHost(), req->getProtocol())->setError(); - _requestGroup->removeIdenticalURI(req->getUrl()); + _fileEntry->removeIdenticalURI(req->getUrl()); _fileEntry->removeRequest(req); } diff --git a/src/AdaptiveURISelector.cc b/src/AdaptiveURISelector.cc index ef355b15..7ceb09fa 100644 --- a/src/AdaptiveURISelector.cc +++ b/src/AdaptiveURISelector.cc @@ -50,6 +50,7 @@ #include "Option.h" #include "SimpleRandomizer.h" #include "SocketCore.h" +#include "FileEntry.h" namespace aria2 { @@ -71,14 +72,15 @@ AdaptiveURISelector::AdaptiveURISelector AdaptiveURISelector::~AdaptiveURISelector() {} -std::string AdaptiveURISelector::select(std::deque& uris) +std::string AdaptiveURISelector::select(FileEntry* fileEntry) { _logger->debug("AdaptiveURISelector: called %d", _requestGroup->getNumConnection()); + std::deque& uris = fileEntry->getRemainingUris(); if (uris.empty() && _requestGroup->getNumConnection() <= 1) { // here we know the download will fail, trying to find previously // failed uris that may succeed with more permissive values - mayRetryWithIncreasedTimeout(uris); + mayRetryWithIncreasedTimeout(fileEntry); } std::string selected = selectOne(uris); @@ -89,15 +91,15 @@ std::string AdaptiveURISelector::select(std::deque& uris) return selected; } -void AdaptiveURISelector::mayRetryWithIncreasedTimeout -(std::deque& uris) +void AdaptiveURISelector::mayRetryWithIncreasedTimeout(FileEntry* fileEntry) { if (_requestGroup->getTimeout()*2 >= MAX_TIMEOUT) return; _requestGroup->setTimeout(_requestGroup->getTimeout()*2); + std::deque& uris = fileEntry->getRemainingUris(); // looking for retries std::deque timeouts; - _requestGroup->extractURIResult(timeouts, DownloadResult::TIME_OUT); + fileEntry->extractURIResult(timeouts, downloadresultcode::TIME_OUT); std::transform(timeouts.begin(), timeouts.end(), std::back_inserter(uris), std::mem_fun_ref(&URIResult::getURI)); diff --git a/src/AdaptiveURISelector.h b/src/AdaptiveURISelector.h index 6804b9cc..1e3c0869 100644 --- a/src/AdaptiveURISelector.h +++ b/src/AdaptiveURISelector.h @@ -57,7 +57,7 @@ private: Logger* _logger; - void mayRetryWithIncreasedTimeout(std::deque& uris); + void mayRetryWithIncreasedTimeout(FileEntry* fileEntry); std::string selectOne(const std::deque& uris); void adjustLowestSpeedLimit(const std::deque& uris, @@ -78,7 +78,7 @@ public: virtual ~AdaptiveURISelector(); - virtual std::string select(std::deque& uris); + virtual std::string select(FileEntry* fileEntry); virtual void tuneDownloadCommand(const std::deque& uris, DownloadCommand* command); diff --git a/src/AutoSaveCommand.cc b/src/AutoSaveCommand.cc index ad5001bc..4202c68c 100644 --- a/src/AutoSaveCommand.cc +++ b/src/AutoSaveCommand.cc @@ -35,6 +35,7 @@ #include "AutoSaveCommand.h" #include "DownloadEngine.h" #include "RequestGroupMan.h" +#include "FileEntry.h" namespace aria2 { diff --git a/src/BtPostDownloadHandler.cc b/src/BtPostDownloadHandler.cc index 5e733d75..14d3c4ae 100644 --- a/src/BtPostDownloadHandler.cc +++ b/src/BtPostDownloadHandler.cc @@ -66,7 +66,7 @@ void BtPostDownloadHandler::getNextRequestGroups const SharedHandle