2009-06-29 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

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
pull/1/head
Tatsuhiro Tsujikawa 2009-06-29 08:42:58 +00:00
parent 8122399ca7
commit e82f870fdc
69 changed files with 640 additions and 442 deletions

View File

@ -1,3 +1,77 @@
2009-06-29 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
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 <t-tujikawa@users.sourceforge.net> 2009-06-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed MockBtContext.h Removed MockBtContext.h
* test/Makefile.am * test/Makefile.am

View File

@ -174,7 +174,7 @@ bool AbstractCommand::execute() {
req->getProtocol()); req->getProtocol());
ss->setError(); 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); e->commands.push_back(this);
return false; return false;
@ -187,7 +187,8 @@ bool AbstractCommand::execute() {
DL_ABORT_EX2(StringFormat DL_ABORT_EX2(StringFormat
("URI=%s", req->getCurrentUrl().c_str()).str(),err), ("URI=%s", req->getCurrentUrl().c_str()).str(),err),
cuid, req->getUrl().c_str()); cuid, req->getUrl().c_str());
_requestGroup->addURIResult(req->getUrl(), err.getCode()); _fileEntry->addURIResult(req->getUrl(), err.getCode());
_requestGroup->setLastUriResult(req->getUrl(), err.getCode());
} }
onAbort(); onAbort();
// TODO Do we need this? // TODO Do we need this?
@ -195,6 +196,7 @@ bool AbstractCommand::execute() {
tryReserved(); tryReserved();
return true; return true;
} catch(DlRetryEx& err) { } catch(DlRetryEx& err) {
// TODO1.5 Consider the case when req is null
logger->info(MSG_RESTARTING_DOWNLOAD, logger->info(MSG_RESTARTING_DOWNLOAD,
DL_RETRY_EX2(StringFormat DL_RETRY_EX2(StringFormat
("URI=%s", req->getCurrentUrl().c_str()).str(),err), ("URI=%s", req->getCurrentUrl().c_str()).str(),err),
@ -214,15 +216,18 @@ bool AbstractCommand::execute() {
if(isAbort) { if(isAbort) {
logger->info(MSG_MAX_TRY, cuid, req->getTryCount()); logger->info(MSG_MAX_TRY, cuid, req->getTryCount());
logger->error(MSG_DOWNLOAD_ABORTED, err, cuid, req->getUrl().c_str()); 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(); tryReserved();
return true; return true;
} else { } else {
return prepareForRetry(getOption()->getAsInt(PREF_RETRY_WAIT)); return prepareForRetry(getOption()->getAsInt(PREF_RETRY_WAIT));
} }
} catch(DownloadFailureException& err) { } catch(DownloadFailureException& err) {
// TODO1.5 Consider the case when req is null
logger->error(EX_EXCEPTION_CAUGHT, err); 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); _requestGroup->setHaltRequested(true);
return true; return true;
} }
@ -279,7 +284,7 @@ void AbstractCommand::onAbort() {
// TODO This might be a problem if the failure is caused by proxy. // TODO This might be a problem if the failure is caused by proxy.
e->_requestGroupMan->getOrCreateServerStat(req->getHost(), e->_requestGroupMan->getOrCreateServerStat(req->getHost(),
req->getProtocol())->setError(); req->getProtocol())->setError();
_requestGroup->removeIdenticalURI(req->getUrl()); _fileEntry->removeIdenticalURI(req->getUrl());
_fileEntry->removeRequest(req); _fileEntry->removeRequest(req);
} }

View File

@ -50,6 +50,7 @@
#include "Option.h" #include "Option.h"
#include "SimpleRandomizer.h" #include "SimpleRandomizer.h"
#include "SocketCore.h" #include "SocketCore.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {
@ -71,14 +72,15 @@ AdaptiveURISelector::AdaptiveURISelector
AdaptiveURISelector::~AdaptiveURISelector() {} AdaptiveURISelector::~AdaptiveURISelector() {}
std::string AdaptiveURISelector::select(std::deque<std::string>& uris) std::string AdaptiveURISelector::select(FileEntry* fileEntry)
{ {
_logger->debug("AdaptiveURISelector: called %d", _logger->debug("AdaptiveURISelector: called %d",
_requestGroup->getNumConnection()); _requestGroup->getNumConnection());
std::deque<std::string>& uris = fileEntry->getRemainingUris();
if (uris.empty() && _requestGroup->getNumConnection() <= 1) { if (uris.empty() && _requestGroup->getNumConnection() <= 1) {
// here we know the download will fail, trying to find previously // here we know the download will fail, trying to find previously
// failed uris that may succeed with more permissive values // failed uris that may succeed with more permissive values
mayRetryWithIncreasedTimeout(uris); mayRetryWithIncreasedTimeout(fileEntry);
} }
std::string selected = selectOne(uris); std::string selected = selectOne(uris);
@ -89,15 +91,15 @@ std::string AdaptiveURISelector::select(std::deque<std::string>& uris)
return selected; return selected;
} }
void AdaptiveURISelector::mayRetryWithIncreasedTimeout void AdaptiveURISelector::mayRetryWithIncreasedTimeout(FileEntry* fileEntry)
(std::deque<std::string>& uris)
{ {
if (_requestGroup->getTimeout()*2 >= MAX_TIMEOUT) return; if (_requestGroup->getTimeout()*2 >= MAX_TIMEOUT) return;
_requestGroup->setTimeout(_requestGroup->getTimeout()*2); _requestGroup->setTimeout(_requestGroup->getTimeout()*2);
std::deque<std::string>& uris = fileEntry->getRemainingUris();
// looking for retries // looking for retries
std::deque<URIResult> timeouts; std::deque<URIResult> timeouts;
_requestGroup->extractURIResult(timeouts, DownloadResult::TIME_OUT); fileEntry->extractURIResult(timeouts, downloadresultcode::TIME_OUT);
std::transform(timeouts.begin(), timeouts.end(), std::back_inserter(uris), std::transform(timeouts.begin(), timeouts.end(), std::back_inserter(uris),
std::mem_fun_ref(&URIResult::getURI)); std::mem_fun_ref(&URIResult::getURI));

View File

@ -57,7 +57,7 @@ private:
Logger* _logger; Logger* _logger;
void mayRetryWithIncreasedTimeout(std::deque<std::string>& uris); void mayRetryWithIncreasedTimeout(FileEntry* fileEntry);
std::string selectOne(const std::deque<std::string>& uris); std::string selectOne(const std::deque<std::string>& uris);
void adjustLowestSpeedLimit(const std::deque<std::string>& uris, void adjustLowestSpeedLimit(const std::deque<std::string>& uris,
@ -78,7 +78,7 @@ public:
virtual ~AdaptiveURISelector(); virtual ~AdaptiveURISelector();
virtual std::string select(std::deque<std::string>& uris); virtual std::string select(FileEntry* fileEntry);
virtual void tuneDownloadCommand(const std::deque<std::string>& uris, virtual void tuneDownloadCommand(const std::deque<std::string>& uris,
DownloadCommand* command); DownloadCommand* command);

View File

@ -35,6 +35,7 @@
#include "AutoSaveCommand.h" #include "AutoSaveCommand.h"
#include "DownloadEngine.h" #include "DownloadEngine.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -66,7 +66,7 @@ void BtPostDownloadHandler::getNextRequestGroups
const SharedHandle<Option>& op = requestGroup->getOption(); const SharedHandle<Option>& op = requestGroup->getOption();
_logger->debug("Generating RequestGroups for Torrent file %s", _logger->debug("Generating RequestGroups for Torrent file %s",
requestGroup->getFirstFilePath().c_str()); requestGroup->getFirstFilePath().c_str());
RequestGroupHandle rg(new RequestGroup(op, std::deque<std::string>())); RequestGroupHandle rg(new RequestGroup(op));
std::string content; std::string content;
try { try {

View File

@ -37,6 +37,7 @@
#include "CheckIntegrityCommand.h" #include "CheckIntegrityCommand.h"
#include "message.h" #include "message.h"
#include "Logger.h" #include "Logger.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -44,6 +44,7 @@
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "NsCookieParser.h" #include "NsCookieParser.h"
#include "File.h"
#ifdef HAVE_SQLITE3 #ifdef HAVE_SQLITE3
# include "Sqlite3MozCookieParser.h" # include "Sqlite3MozCookieParser.h"
#endif // HAVE_SQLITE3 #endif // HAVE_SQLITE3

View File

@ -52,6 +52,7 @@
#include "message.h" #include "message.h"
#include "Logger.h" #include "Logger.h"
#include "a2functional.h" #include "a2functional.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -39,6 +39,7 @@
#include "DHTTask.h" #include "DHTTask.h"
#include "DownloadEngine.h" #include "DownloadEngine.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -51,6 +51,7 @@
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "Logger.h" #include "Logger.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -45,6 +45,7 @@
#include "Logger.h" #include "Logger.h"
#include "DHTMessageCallback.h" #include "DHTMessageCallback.h"
#include "DHTNode.h" #include "DHTNode.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -39,6 +39,7 @@
#include "RecoverableException.h" #include "RecoverableException.h"
#include "message.h" #include "message.h"
#include "Logger.h" #include "Logger.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -39,6 +39,7 @@
#include "RecoverableException.h" #include "RecoverableException.h"
#include "message.h" #include "message.h"
#include "Logger.h" #include "Logger.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -54,7 +54,7 @@ public:
DlAbortEx(const char* file, int line, const RecoverableException& e): DlAbortEx(const char* file, int line, const RecoverableException& e):
RecoverableException(file, line, e) {} RecoverableException(file, line, e) {}
DlAbortEx(const char* file, int line, const std::string& msg, DlAbortEx(const char* file, int line, const std::string& msg,
DownloadResult::RESULT code): downloadresultcode::RESULT code):
RecoverableException(file, line, msg, code) {} RecoverableException(file, line, msg, code) {}
}; };

View File

@ -54,7 +54,7 @@ public:
DlRetryEx(const char* file, int line, const DlRetryEx& e): DlRetryEx(const char* file, int line, const DlRetryEx& e):
RecoverableException(file, line, e) {} RecoverableException(file, line, e) {}
DlRetryEx(const char* file, int line, const std::string& msg, DlRetryEx(const char* file, int line, const std::string& msg,
DownloadResult::RESULT code): downloadresultcode::RESULT code):
RecoverableException(file, line, msg, code) {} RecoverableException(file, line, msg, code) {}
}; };

View File

@ -252,7 +252,7 @@ void DownloadCommand::checkLowestDownloadSpeed() const
nowSpeed, nowSpeed,
lowestDownloadSpeedLimit, lowestDownloadSpeedLimit,
req->getHost().c_str()).str(), req->getHost().c_str()).str(),
DownloadResult::TOO_SLOW_DOWNLOAD_SPEED); downloadresultcode::TOO_SLOW_DOWNLOAD_SPEED);
} }
} }
} }

View File

@ -47,10 +47,10 @@
#include "A2STR.h" #include "A2STR.h"
#include "BDE.h" #include "BDE.h"
#include "IntSequence.h" #include "IntSequence.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {
class FileEntry;
class RequestGroup; class RequestGroup;
class DownloadContext class DownloadContext

View File

@ -59,7 +59,8 @@ public:
const DownloadFailureException& e): const DownloadFailureException& e):
RecoverableException(file, line, e) {} RecoverableException(file, line, e) {}
DownloadFailureException(const char* file, int line, DownloadFailureException(const char* file, int line,
const std::string& msg, DownloadResult::RESULT code): const std::string& msg,
downloadresultcode::RESULT code):
RecoverableException(file, line, msg, code) {} RecoverableException(file, line, msg, code) {}
}; };

View File

@ -43,59 +43,37 @@
#include <vector> #include <vector>
#include "SharedHandle.h" #include "SharedHandle.h"
#include "FileEntry.h" #include "DownloadResultCode.h"
namespace aria2 { namespace aria2 {
class FileEntry;
class DownloadResult class DownloadResult
{ {
public: public:
// RESULT is used as an exit status code.
enum RESULT {
FINISHED = 0,
UNKNOWN_ERROR = 1,
TIME_OUT = 2,
RESOURCE_NOT_FOUND = 3,
MAX_FILE_NOT_FOUND = 4,
TOO_SLOW_DOWNLOAD_SPEED = 5,
NETWORK_PROBLEM = 6,
IN_PROGRESS = 7,
};
int32_t gid; int32_t gid;
std::vector<SharedHandle<FileEntry> > fileEntries; std::vector<SharedHandle<FileEntry> > fileEntries;
bool inMemoryDownload; bool inMemoryDownload;
uint64_t totalLength;
std::string uri;
size_t numUri;
uint64_t sessionDownloadLength; uint64_t sessionDownloadLength;
// milliseconds // milliseconds
int64_t sessionTime; int64_t sessionTime;
RESULT result; downloadresultcode::RESULT result;
DownloadResult(int32_t gid, DownloadResult(int32_t gid,
const std::vector<SharedHandle<FileEntry> >& fileEntries, const std::vector<SharedHandle<FileEntry> >& fileEntries,
bool inMemoryDownload, bool inMemoryDownload,
uint64_t totalLength,
const std::string& uri,
size_t numUri,
uint64_t sessionDownloadLength, uint64_t sessionDownloadLength,
int64_t sessionTime, int64_t sessionTime,
RESULT result): downloadresultcode::RESULT result):
gid(gid), gid(gid),
fileEntries(fileEntries), fileEntries(fileEntries),
inMemoryDownload(inMemoryDownload), inMemoryDownload(inMemoryDownload),
totalLength(totalLength),
uri(uri),
numUri(numUri),
sessionDownloadLength(sessionDownloadLength), sessionDownloadLength(sessionDownloadLength),
sessionTime(sessionTime), sessionTime(sessionTime),
result(result) {} result(result) {}

59
src/DownloadResultCode.h Normal file
View File

@ -0,0 +1,59 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2009 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef _D_DOWNLOAD_RESULT_CODE_H_
#define _D_DOWNLOAD_RESULT_CODE_H_
#include "common.h"
namespace aria2 {
namespace downloadresultcode {
enum RESULT {
FINISHED = 0,
UNKNOWN_ERROR = 1,
TIME_OUT = 2,
RESOURCE_NOT_FOUND = 3,
MAX_FILE_NOT_FOUND = 4,
TOO_SLOW_DOWNLOAD_SPEED = 5,
NETWORK_PROBLEM = 6,
IN_PROGRESS = 7,
};
} // namespace downloadresultcode
} // namespace aria2
#endif // _D_DOWNLOAD_RESULT_CODE_H_

View File

@ -40,6 +40,7 @@
#include "ServerStat.h" #include "ServerStat.h"
#include "Request.h" #include "Request.h"
#include "A2STR.h" #include "A2STR.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {
@ -59,8 +60,9 @@ public:
} }
}; };
std::string FeedbackURISelector::select(std::deque<std::string>& uris) std::string FeedbackURISelector::select(FileEntry* fileEntry)
{ {
std::deque<std::string>& uris = fileEntry->getRemainingUris();
if(uris.empty()) { if(uris.empty()) {
return A2STR::NIL; return A2STR::NIL;
} }

View File

@ -4,7 +4,7 @@
* *
* Copyright (C) 2006 Tatsuhiro Tsujikawa * Copyright (C) 2006 Tatsuhiro Tsujikawa
* *
* This program is free software; you can redistribute it and/or modify nn * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
@ -50,7 +50,7 @@ public:
virtual ~FeedbackURISelector(); virtual ~FeedbackURISelector();
virtual std::string select(std::deque<std::string>& uris); virtual std::string select(FileEntry* fileEntry);
}; };
} // namespace aria2 } // namespace aria2

View File

@ -35,9 +35,11 @@
#include "FileEntry.h" #include "FileEntry.h"
#include <cassert> #include <cassert>
#include <algorithm>
#include "Util.h" #include "Util.h"
#include "URISelector.h" #include "URISelector.h"
#include "LogFactory.h"
namespace aria2 { namespace aria2 {
@ -46,7 +48,12 @@ FileEntry::FileEntry(const std::string& path,
off_t offset, off_t offset,
const std::deque<std::string>& uris): const std::deque<std::string>& uris):
path(path), _uris(uris), length(length), offset(offset), path(path), _uris(uris), length(length), offset(offset),
extracted(false), requested(true) {} extracted(false), requested(true),
_logger(LogFactory::getInstance()) {}
FileEntry::FileEntry():
length(0), offset(0), extracted(false), requested(false),
_logger(LogFactory::getInstance()) {}
FileEntry::~FileEntry() {} FileEntry::~FileEntry() {}
@ -91,7 +98,7 @@ void FileEntry::getUris(std::deque<std::string>& uris) const
std::string FileEntry::selectUri(const SharedHandle<URISelector>& uriSelector) std::string FileEntry::selectUri(const SharedHandle<URISelector>& uriSelector)
{ {
return uriSelector->select(_uris); return uriSelector->select(this);
} }
SharedHandle<Request> SharedHandle<Request>
@ -100,7 +107,7 @@ FileEntry::getRequest(const SharedHandle<URISelector>& selector)
SharedHandle<Request> req; SharedHandle<Request> req;
if(_requestPool.empty()) { if(_requestPool.empty()) {
while(1) { while(1) {
std::string uri = selector->select(_uris); std::string uri = selector->select(this);
if(uri.empty()) { if(uri.empty()) {
return req; return req;
} }
@ -139,4 +146,51 @@ bool FileEntry::removeRequest(const SharedHandle<Request>& request)
return false; return false;
} }
void FileEntry::removeURIWhoseHostnameIs(const std::string& hostname)
{
std::deque<std::string> newURIs;
Request req;
for(std::deque<std::string>::const_iterator itr = _uris.begin(); itr != _uris.end(); ++itr) {
if(((*itr).find(hostname) == std::string::npos) ||
(req.setUrl(*itr) && (req.getHost() != hostname))) {
newURIs.push_back(*itr);
}
}
_logger->debug("Removed %d duplicate hostname URIs for path=%s",
_uris.size()-newURIs.size(), getPath().c_str());
_uris = newURIs;
}
void FileEntry::removeIdenticalURI(const std::string& uri)
{
_uris.erase(std::remove(_uris.begin(), _uris.end(), uri), _uris.end());
}
void FileEntry::addURIResult(std::string uri, downloadresultcode::RESULT result)
{
_uriResults.push_back(URIResult(uri, result));
}
class FindURIResultByResult {
private:
downloadresultcode::RESULT _r;
public:
FindURIResultByResult(downloadresultcode::RESULT r):_r(r) {}
bool operator()(const URIResult& uriResult) const
{
return uriResult.getResult() == _r;
}
};
void FileEntry::extractURIResult
(std::deque<URIResult>& res, downloadresultcode::RESULT r)
{
std::deque<URIResult>::iterator i =
std::stable_partition(_uriResults.begin(), _uriResults.end(),
FindURIResultByResult(r));
std::copy(_uriResults.begin(), i, std::back_inserter(res));
_uriResults.erase(_uriResults.begin(), i);
}
} // namespace aria2 } // namespace aria2

View File

@ -44,11 +44,15 @@
#include "SharedHandle.h" #include "SharedHandle.h"
#include "File.h" #include "File.h"
#include "Request.h" #include "Request.h"
#include "URIResult.h"
#include "DownloadResultCode.h"
namespace aria2 { namespace aria2 {
class URISelector; class URISelector;
class Logger;
class FileEntry { class FileEntry {
private: private:
std::string path; std::string path;
@ -61,8 +65,13 @@ private:
std::deque<SharedHandle<Request> > _requestPool; std::deque<SharedHandle<Request> > _requestPool;
std::deque<SharedHandle<Request> > _inFlightRequests; std::deque<SharedHandle<Request> > _inFlightRequests;
std::string _contentType; std::string _contentType;
// URIResult is stored in the ascending order of the time when its result is
// available.
std::deque<URIResult> _uriResults;
Logger* _logger;
public: public:
FileEntry():length(0), offset(0), extracted(false), requested(false) {} FileEntry();
FileEntry(const std::string& path, uint64_t length, off_t offset, FileEntry(const std::string& path, uint64_t length, off_t offset,
const std::deque<std::string>& uris = std::deque<std::string>()); const std::deque<std::string>& uris = std::deque<std::string>());
@ -116,6 +125,11 @@ public:
return _uris; return _uris;
} }
std::deque<std::string>& getRemainingUris()
{
return _uris;
}
const std::deque<std::string>& getSpentUris() const const std::deque<std::string>& getSpentUris() const
{ {
return _spentUris; return _spentUris;
@ -159,6 +173,22 @@ public:
// Translate global offset goff to file local offset. // Translate global offset goff to file local offset.
off_t gtoloff(off_t goff) const; off_t gtoloff(off_t goff) const;
void removeURIWhoseHostnameIs(const std::string& hostname);
void removeIdenticalURI(const std::string& uri);
void addURIResult(std::string uri, downloadresultcode::RESULT result);
const std::deque<URIResult>& getURIResults() const
{
return _uriResults;
}
// Extracts URIResult whose _result is r and stores them into res.
// The extracted URIResults are removed from _uriResults.
void extractURIResult
(std::deque<URIResult>& res, downloadresultcode::RESULT r);
}; };
typedef SharedHandle<FileEntry> FileEntryHandle; typedef SharedHandle<FileEntry> FileEntryHandle;

View File

@ -65,6 +65,7 @@
#include "AuthConfigFactory.h" #include "AuthConfigFactory.h"
#include "AuthConfig.h" #include "AuthConfig.h"
#include "a2functional.h" #include "a2functional.h"
#include "URISelector.h"
namespace aria2 { namespace aria2 {
@ -106,10 +107,11 @@ bool FtpNegotiationCommand::executeInternal() {
SharedHandle<ServerHost> sv = SharedHandle<ServerHost> sv =
_requestGroup->searchServerHost(req->getHost()); _requestGroup->searchServerHost(req->getHost());
if(!sv.isNull()) { if(!sv.isNull()) {
_requestGroup->removeURIWhoseHostnameIs(sv->getHostname()); _fileEntry->removeURIWhoseHostnameIs(sv->getHostname());
} }
} }
_requestGroup->tuneDownloadCommand(command); _requestGroup->getURISelector()->tuneDownloadCommand
(_fileEntry->getRemainingUris(), command);
e->commands.push_back(command); e->commands.push_back(command);
return true; return true;
} else if(sequence == SEQ_HEAD_OK || sequence == SEQ_DOWNLOAD_ALREADY_COMPLETED) { } else if(sequence == SEQ_HEAD_OK || sequence == SEQ_DOWNLOAD_ALREADY_COMPLETED) {
@ -265,7 +267,8 @@ bool FtpNegotiationCommand::recvCwd() {
poolConnection(); poolConnection();
_requestGroup->increaseAndValidateFileNotFoundCount(); _requestGroup->increaseAndValidateFileNotFoundCount();
if (status == 550) if (status == 550)
throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND, DownloadResult::RESOURCE_NOT_FOUND); throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND,
downloadresultcode::RESOURCE_NOT_FOUND);
else else
throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str()); throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
} }
@ -579,7 +582,8 @@ bool FtpNegotiationCommand::recvRetr() {
if(status != 150 && status != 125) { if(status != 150 && status != 125) {
_requestGroup->increaseAndValidateFileNotFoundCount(); _requestGroup->increaseAndValidateFileNotFoundCount();
if (status == 550) if (status == 550)
throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND, DownloadResult::RESOURCE_NOT_FOUND); throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND,
downloadresultcode::RESOURCE_NOT_FOUND);
else else
throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str()); throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
} }

View File

@ -41,6 +41,7 @@
#include "HttpServerCommand.h" #include "HttpServerCommand.h"
#include "CUIDCounter.h" #include "CUIDCounter.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -66,6 +66,7 @@
#include "AuthConfigFactory.h" #include "AuthConfigFactory.h"
#include "AuthConfig.h" #include "AuthConfig.h"
#include "a2functional.h" #include "a2functional.h"
#include "URISelector.h"
namespace aria2 { namespace aria2 {
@ -131,7 +132,7 @@ bool HttpResponseCommand::executeInternal()
SharedHandle<ServerHost> sv = SharedHandle<ServerHost> sv =
_requestGroup->searchServerHost(req->getHost()); _requestGroup->searchServerHost(req->getHost());
if(!sv.isNull()) { if(!sv.isNull()) {
_requestGroup->removeURIWhoseHostnameIs(sv->getHostname()); _fileEntry->removeURIWhoseHostnameIs(sv->getHostname());
} }
} }
if(_requestGroup->getPieceStorage().isNull()) { if(_requestGroup->getPieceStorage().isNull()) {
@ -409,7 +410,8 @@ HttpDownloadCommand* HttpResponseCommand::createHttpDownloadCommand
_requestGroup->setFileAllocationEnabled(false); _requestGroup->setFileAllocationEnabled(false);
} }
_requestGroup->tuneDownloadCommand(command); _requestGroup->getURISelector()->tuneDownloadCommand
(_fileEntry->getRemainingUris(), command);
return command; return command;
} }

View File

@ -40,6 +40,7 @@
#include "HttpServerCommand.h" #include "HttpServerCommand.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "RecoverableException.h" #include "RecoverableException.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -171,7 +171,7 @@ bool HttpSkipResponseCommand::processResponse()
} }
}else if(_httpResponse->getResponseStatus() == HttpHeader::S404) { }else if(_httpResponse->getResponseStatus() == HttpHeader::S404) {
throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND, throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND,
DownloadResult::RESOURCE_NOT_FOUND); downloadresultcode::RESOURCE_NOT_FOUND);
} else { } else {
throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, Util::parseUInt(_httpResponse->getResponseStatus())).str()); throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, Util::parseUInt(_httpResponse->getResponseStatus())).str());
} }

View File

@ -34,6 +34,7 @@
/* copyright --> */ /* copyright --> */
#include "InOrderURISelector.h" #include "InOrderURISelector.h"
#include "A2STR.h" #include "A2STR.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {
@ -41,8 +42,9 @@ InOrderURISelector::InOrderURISelector() {}
InOrderURISelector::~InOrderURISelector() {} InOrderURISelector::~InOrderURISelector() {}
std::string InOrderURISelector::select(std::deque<std::string>& uris) std::string InOrderURISelector::select(FileEntry* fileEntry)
{ {
std::deque<std::string>& uris = fileEntry->getRemainingUris();
if(uris.empty()) { if(uris.empty()) {
return A2STR::NIL; return A2STR::NIL;
} else { } else {

View File

@ -44,7 +44,7 @@ public:
virtual ~InOrderURISelector(); virtual ~InOrderURISelector();
virtual std::string select(std::deque<std::string>& uris); virtual std::string select(FileEntry* fileEntry);
}; };
} // namespace aria2 } // namespace aria2

View File

@ -201,7 +201,8 @@ SRCS = Socket.h\
LongestSequencePieceSelector.cc LongestSequencePieceSelector.h\ LongestSequencePieceSelector.cc LongestSequencePieceSelector.h\
bitfield.h\ bitfield.h\
BDE.cc BDE.h\ BDE.cc BDE.h\
CreateRequestCommand.cc CreateRequestCommand.h CreateRequestCommand.cc CreateRequestCommand.h\
DownloadResultCode.h
if ENABLE_XML_RPC if ENABLE_XML_RPC
SRCS += XmlRpcRequestParserController.cc XmlRpcRequestParserController.h\ SRCS += XmlRpcRequestParserController.cc XmlRpcRequestParserController.h\

View File

@ -424,7 +424,8 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
SequentialDispatcherCommand.h PieceSelector.h \ SequentialDispatcherCommand.h PieceSelector.h \
LongestSequencePieceSelector.cc LongestSequencePieceSelector.h \ LongestSequencePieceSelector.cc LongestSequencePieceSelector.h \
bitfield.h BDE.cc BDE.h CreateRequestCommand.cc \ bitfield.h BDE.cc BDE.h CreateRequestCommand.cc \
CreateRequestCommand.h XmlRpcRequestParserController.cc \ CreateRequestCommand.h DownloadResultCode.h \
XmlRpcRequestParserController.cc \
XmlRpcRequestParserController.h \ XmlRpcRequestParserController.h \
XmlRpcRequestParserStateMachine.cc \ XmlRpcRequestParserStateMachine.cc \
XmlRpcRequestParserStateMachine.h XmlRpcRequestParserState.h \ XmlRpcRequestParserStateMachine.h XmlRpcRequestParserState.h \
@ -1178,15 +1179,15 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
SequentialDispatcherCommand.h PieceSelector.h \ SequentialDispatcherCommand.h PieceSelector.h \
LongestSequencePieceSelector.cc LongestSequencePieceSelector.h \ LongestSequencePieceSelector.cc LongestSequencePieceSelector.h \
bitfield.h BDE.cc BDE.h CreateRequestCommand.cc \ bitfield.h BDE.cc BDE.h CreateRequestCommand.cc \
CreateRequestCommand.h $(am__append_1) $(am__append_2) \ CreateRequestCommand.h DownloadResultCode.h $(am__append_1) \
$(am__append_3) $(am__append_4) $(am__append_5) \ $(am__append_2) $(am__append_3) $(am__append_4) \
$(am__append_6) $(am__append_7) $(am__append_8) \ $(am__append_5) $(am__append_6) $(am__append_7) \
$(am__append_9) $(am__append_10) $(am__append_11) \ $(am__append_8) $(am__append_9) $(am__append_10) \
$(am__append_12) $(am__append_13) $(am__append_14) \ $(am__append_11) $(am__append_12) $(am__append_13) \
$(am__append_15) $(am__append_16) $(am__append_17) \ $(am__append_14) $(am__append_15) $(am__append_16) \
$(am__append_18) $(am__append_19) $(am__append_20) \ $(am__append_17) $(am__append_18) $(am__append_19) \
$(am__append_21) $(am__append_22) $(am__append_23) \ $(am__append_20) $(am__append_21) $(am__append_22) \
$(am__append_24) $(am__append_25) $(am__append_23) $(am__append_24) $(am__append_25)
noinst_LIBRARIES = libaria2c.a noinst_LIBRARIES = libaria2c.a
libaria2c_a_SOURCES = $(SRCS) libaria2c_a_SOURCES = $(SRCS)
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\ aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\

View File

@ -169,13 +169,14 @@ Metalink2RequestGroup::createRequestGroup
if(itr != entry->resources.end()) { if(itr != entry->resources.end()) {
std::deque<std::string> uris; std::deque<std::string> uris;
uris.push_back((*itr)->url); uris.push_back((*itr)->url);
torrentRg.reset(new RequestGroup(option, uris)); torrentRg.reset(new RequestGroup(option));
SharedHandle<DownloadContext> dctx SharedHandle<DownloadContext> dctx
(new DownloadContext(option->getAsInt(PREF_SEGMENT_SIZE), (new DownloadContext(option->getAsInt(PREF_SEGMENT_SIZE),
0, 0,
A2STR::NIL)); A2STR::NIL));
// Since torrent is downloaded in memory, setting dir has no effect. // Since torrent is downloaded in memory, setting dir has no effect.
//dctx->setDir(_option->get(PREF_DIR)); //dctx->setDir(_option->get(PREF_DIR));
dctx->getFirstFileEntry()->setUris(uris);
torrentRg->setDownloadContext(dctx); torrentRg->setDownloadContext(dctx);
torrentRg->clearPreDowloadHandler(); torrentRg->clearPreDowloadHandler();
torrentRg->clearPostDowloadHandler(); torrentRg->clearPostDowloadHandler();
@ -196,7 +197,7 @@ Metalink2RequestGroup::createRequestGroup
std::deque<std::string> uris; std::deque<std::string> uris;
std::for_each(entry->resources.begin(), entry->resources.end(), std::for_each(entry->resources.begin(), entry->resources.end(),
AccumulateNonP2PUrl(uris)); AccumulateNonP2PUrl(uris));
SharedHandle<RequestGroup> rg(new RequestGroup(option, uris)); SharedHandle<RequestGroup> rg(new RequestGroup(option));
// If piece hash is specified in the metalink, // If piece hash is specified in the metalink,
// make segment size equal to piece hash size. // make segment size equal to piece hash size.
size_t pieceLength; size_t pieceLength;
@ -215,6 +216,7 @@ Metalink2RequestGroup::createRequestGroup
entry->getLength(), entry->getLength(),
strconcat(option->get(PREF_DIR), "/", entry->file->getPath()))); strconcat(option->get(PREF_DIR), "/", entry->file->getPath())));
dctx->setDir(option->get(PREF_DIR)); dctx->setDir(option->get(PREF_DIR));
dctx->getFirstFileEntry()->setUris(uris);
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
if(entry->chunkChecksum.isNull()) { if(entry->chunkChecksum.isNull()) {
if(!entry->checksum.isNull()) { if(!entry->checksum.isNull()) {

View File

@ -100,9 +100,9 @@ void MultiUrlRequestInfo::printMessageForContinue()
<< "\n"; << "\n";
} }
DownloadResult::RESULT MultiUrlRequestInfo::execute() downloadresultcode::RESULT MultiUrlRequestInfo::execute()
{ {
DownloadResult::RESULT returnValue = DownloadResult::FINISHED; downloadresultcode::RESULT returnValue = downloadresultcode::FINISHED;
try { try {
DownloadEngineHandle e = DownloadEngineHandle e =
DownloadEngineFactory().newDownloadEngine(_option.get(), _requestGroups); DownloadEngineFactory().newDownloadEngine(_option.get(), _requestGroups);
@ -190,9 +190,9 @@ DownloadResult::RESULT MultiUrlRequestInfo::execute()
RequestGroupMan::DownloadStat s = e->_requestGroupMan->getDownloadStat(); RequestGroupMan::DownloadStat s = e->_requestGroupMan->getDownloadStat();
if(!s.allCompleted()) { if(!s.allCompleted()) {
printMessageForContinue(); printMessageForContinue();
if(s.getLastErrorResult() == DownloadResult::FINISHED && if(s.getLastErrorResult() == downloadresultcode::FINISHED &&
s.getInProgress() > 0) { s.getInProgress() > 0) {
returnValue = DownloadResult::IN_PROGRESS; returnValue = downloadresultcode::IN_PROGRESS;
} else { } else {
returnValue = s.getLastErrorResult(); returnValue = s.getLastErrorResult();
} }

View File

@ -77,7 +77,7 @@ public:
* Returns FINISHED if all downloads have completed, otherwise returns the * Returns FINISHED if all downloads have completed, otherwise returns the
* last download result. * last download result.
*/ */
DownloadResult::RESULT execute(); downloadresultcode::RESULT execute();
}; };
typedef SharedHandle<MultiUrlRequestInfo> MultiUrlRequestInfoHandle; typedef SharedHandle<MultiUrlRequestInfo> MultiUrlRequestInfoHandle;

View File

@ -41,6 +41,7 @@
#include "Util.h" #include "Util.h"
#include "help_tags.h" #include "help_tags.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "File.h"
namespace aria2 { namespace aria2 {

View File

@ -47,6 +47,7 @@
#include "Logger.h" #include "Logger.h"
#include "Socket.h" #include "Socket.h"
#include "SimpleRandomizer.h" #include "SimpleRandomizer.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -35,13 +35,13 @@
#ifndef _D_RECOVERABLE_EXCEPTION_H_ #ifndef _D_RECOVERABLE_EXCEPTION_H_
#define _D_RECOVERABLE_EXCEPTION_H_ #define _D_RECOVERABLE_EXCEPTION_H_
#include "Exception.h" #include "Exception.h"
#include "DownloadResult.h" #include "DownloadResultCode.h"
namespace aria2 { namespace aria2 {
class RecoverableException:public Exception { class RecoverableException:public Exception {
private: private:
DownloadResult::RESULT _code; downloadresultcode::RESULT _code;
protected: protected:
virtual SharedHandle<Exception> copy() const virtual SharedHandle<Exception> copy() const
@ -52,23 +52,23 @@ protected:
public: public:
RecoverableException(const char* file, int line, const std::string& msg): RecoverableException(const char* file, int line, const std::string& msg):
Exception(file, line, msg), Exception(file, line, msg),
_code(DownloadResult::UNKNOWN_ERROR) {} _code(downloadresultcode::UNKNOWN_ERROR) {}
RecoverableException(const char* file, int line, const std::string& msg, RecoverableException(const char* file, int line, const std::string& msg,
const Exception& cause): const Exception& cause):
Exception(file, line, msg, cause), Exception(file, line, msg, cause),
_code(DownloadResult::UNKNOWN_ERROR) {} _code(downloadresultcode::UNKNOWN_ERROR) {}
RecoverableException(const char* file, int line, RecoverableException(const char* file, int line,
const RecoverableException& e): const RecoverableException& e):
Exception(file, line, e), Exception(file, line, e),
_code(DownloadResult::UNKNOWN_ERROR) {} _code(downloadresultcode::UNKNOWN_ERROR) {}
RecoverableException(const char* file, int line, const std::string& msg, RecoverableException(const char* file, int line, const std::string& msg,
DownloadResult::RESULT result): downloadresultcode::RESULT result):
Exception(file, line, msg), _code(result) {} Exception(file, line, msg), _code(result) {}
DownloadResult::RESULT getCode() const { return _code; } downloadresultcode::RESULT getCode() const { return _code; }
}; };
} // namespace aria2 } // namespace aria2

View File

@ -112,11 +112,9 @@ int32_t RequestGroup::_gidCounter = 0;
const std::string RequestGroup::ACCEPT_METALINK = "application/metalink+xml"; const std::string RequestGroup::ACCEPT_METALINK = "application/metalink+xml";
RequestGroup::RequestGroup(const SharedHandle<Option>& option, RequestGroup::RequestGroup(const SharedHandle<Option>& option):
const std::deque<std::string>& uris):
_gid(++_gidCounter), _gid(++_gidCounter),
_option(new Option(*option.get())), _option(new Option(*option.get())),
_uris(uris),
_numConcurrentCommand(option->getAsInt(PREF_SPLIT)), _numConcurrentCommand(option->getAsInt(PREF_SPLIT)),
_numStreamConnection(0), _numStreamConnection(0),
_numCommand(0), _numCommand(0),
@ -175,19 +173,19 @@ bool RequestGroup::allDownloadFinished() const
} }
} }
DownloadResult::RESULT RequestGroup::downloadResult() const downloadresultcode::RESULT RequestGroup::downloadResult() const
{ {
if (downloadFinished()) if (downloadFinished())
return DownloadResult::FINISHED; return downloadresultcode::FINISHED;
else { else {
if (_uriResults.empty()) { if (_lastUriResult.isNull()) {
if(_haltReason == RequestGroup::USER_REQUEST) { if(_haltReason == RequestGroup::USER_REQUEST) {
return DownloadResult::IN_PROGRESS; return downloadresultcode::IN_PROGRESS;
} else { } else {
return DownloadResult::UNKNOWN_ERROR; return downloadresultcode::UNKNOWN_ERROR;
} }
} else { } else {
return _uriResults.back().getResult(); return _lastUriResult->getResult();
} }
} }
} }
@ -403,6 +401,17 @@ void RequestGroup::processCheckIntegrityEntry(std::deque<Command*>& commands,
} }
} }
template<typename InputIterator>
static bool hasAssociatedUri(InputIterator first, InputIterator last)
{
for(; first != last; ++first) {
if((*first)->isRequested() && !(*first)->getRemainingUris().empty()) {
return true;
}
}
return false;
}
void RequestGroup::initPieceStorage() void RequestGroup::initPieceStorage()
{ {
if(_downloadContext->knowsTotalLength()) { if(_downloadContext->knowsTotalLength()) {
@ -411,9 +420,9 @@ void RequestGroup::initPieceStorage()
(new DefaultPieceStorage(_downloadContext, _option.get())); (new DefaultPieceStorage(_downloadContext, _option.get()));
// Use LongestSequencePieceSelector when HTTP/FTP/BitTorrent integrated // Use LongestSequencePieceSelector when HTTP/FTP/BitTorrent integrated
// downloads. Currently multi-file integrated download is not supported. // downloads. Currently multi-file integrated download is not supported.
if(!_uris.empty() && if(_downloadContext->hasAttribute(bittorrent::BITTORRENT) &&
_downloadContext->getFileEntries().size() == 1 && hasAssociatedUri(_downloadContext->getFileEntries().begin(),
_downloadContext->hasAttribute(bittorrent::BITTORRENT)) { _downloadContext->getFileEntries().end())) {
_logger->debug("Using LongestSequencePieceSelector"); _logger->debug("Using LongestSequencePieceSelector");
ps->setPieceSelector ps->setPieceSelector
(SharedHandle<PieceSelector>(new LongestSequencePieceSelector())); (SharedHandle<PieceSelector>(new LongestSequencePieceSelector()));
@ -578,14 +587,8 @@ void RequestGroup::createNextCommandWithAdj(std::deque<Command*>& commands,
if(getTotalLength() == 0) { if(getTotalLength() == 0) {
numCommand = 1+numAdj; numCommand = 1+numAdj;
} else { } else {
if(_numConcurrentCommand == 0) { numCommand = std::min(_downloadContext->getNumPieces(),
// TODO remove _uris.size() support _numConcurrentCommand);
numCommand = _uris.size();
} else {
numCommand = _numConcurrentCommand;
}
numCommand = std::min(static_cast<int>(_downloadContext->getNumPieces()),
numCommand);
numCommand += numAdj; numCommand += numAdj;
} }
if(numCommand > 0) { if(numCommand > 0) {
@ -599,40 +602,40 @@ void RequestGroup::createNextCommand(std::deque<Command*>& commands,
const std::string& method) const std::string& method)
{ {
// TODO1.5 The following block should be moved into FileEntry // TODO1.5 The following block should be moved into FileEntry
if(_option->getAsBool(PREF_REUSE_URI) && _uris.empty()) { // if(_option->getAsBool(PREF_REUSE_URI) && _uris.empty()) {
std::deque<std::string> uris = _spentUris; // std::deque<std::string> uris = _spentUris;
std::sort(uris.begin(), uris.end()); // std::sort(uris.begin(), uris.end());
uris.erase(std::unique(uris.begin(), uris.end()), uris.end()); // uris.erase(std::unique(uris.begin(), uris.end()), uris.end());
std::deque<std::string> errorUris(_uriResults.size()); // std::deque<std::string> errorUris(_uriResults.size());
std::transform(_uriResults.begin(), _uriResults.end(), // std::transform(_uriResults.begin(), _uriResults.end(),
errorUris.begin(), std::mem_fun_ref(&URIResult::getURI)); // errorUris.begin(), std::mem_fun_ref(&URIResult::getURI));
std::sort(errorUris.begin(), errorUris.end()); // std::sort(errorUris.begin(), errorUris.end());
errorUris.erase(std::unique(errorUris.begin(), errorUris.end()), // errorUris.erase(std::unique(errorUris.begin(), errorUris.end()),
errorUris.end()); // errorUris.end());
std::deque<std::string> reusableURIs; // std::deque<std::string> reusableURIs;
std::set_difference(uris.begin(), uris.end(), // std::set_difference(uris.begin(), uris.end(),
errorUris.begin(), errorUris.end(), // errorUris.begin(), errorUris.end(),
std::back_inserter(reusableURIs)); // std::back_inserter(reusableURIs));
size_t ininum = reusableURIs.size(); // size_t ininum = reusableURIs.size();
_logger->debug("Found %u reusable URIs", // _logger->debug("Found %u reusable URIs",
static_cast<unsigned int>(ininum)); // static_cast<unsigned int>(ininum));
// Reuse at least _numConcurrentCommand URIs here to avoid to // // Reuse at least _numConcurrentCommand URIs here to avoid to
// run this process repeatedly. // // run this process repeatedly.
if(ininum > 0 && ininum < _numConcurrentCommand) { // if(ininum > 0 && ininum < _numConcurrentCommand) {
_logger->debug("fewer than _numConcurrentCommand=%u", // _logger->debug("fewer than _numConcurrentCommand=%u",
_numConcurrentCommand); // _numConcurrentCommand);
for(size_t i = 0; i < _numConcurrentCommand/ininum; ++i) { // for(size_t i = 0; i < _numConcurrentCommand/ininum; ++i) {
_uris.insert(_uris.end(), reusableURIs.begin(), reusableURIs.end()); // _uris.insert(_uris.end(), reusableURIs.begin(), reusableURIs.end());
} // }
_uris.insert(_uris.end(), reusableURIs.begin(), // _uris.insert(_uris.end(), reusableURIs.begin(),
reusableURIs.begin()+(_numConcurrentCommand%ininum)); // reusableURIs.begin()+(_numConcurrentCommand%ininum));
_logger->debug("Duplication complete: now %u URIs for reuse", // _logger->debug("Duplication complete: now %u URIs for reuse",
static_cast<unsigned int>(_uris.size())); // static_cast<unsigned int>(_uris.size()));
} // }
} // }
std::deque<std::string> pendingURIs; // std::deque<std::string> pendingURIs;
for(; numCommand--; ) { for(; numCommand--; ) {
Command* command = new CreateRequestCommand(e->newCUID(), this, e); Command* command = new CreateRequestCommand(e->newCUID(), this, e);
@ -917,12 +920,6 @@ void RequestGroup::initializePostDownloadHandler()
#endif // ENABLE_METALINK #endif // ENABLE_METALINK
} }
void RequestGroup::getURIs(std::deque<std::string>& uris) const
{
uris.insert(uris.end(), _spentUris.begin(), _spentUris.end());
uris.insert(uris.end(), _uris.begin(), _uris.end());
}
bool RequestGroup::isDependencyResolved() bool RequestGroup::isDependencyResolved()
{ {
if(_dependency.isNull()) { if(_dependency.isNull()) {
@ -985,9 +982,6 @@ bool RequestGroup::needsFileAllocation() const
DownloadResultHandle RequestGroup::createDownloadResult() const DownloadResultHandle RequestGroup::createDownloadResult() const
{ {
std::deque<std::string> uris;
getURIs(uris);
uint64_t sessionDownloadLength = 0; uint64_t sessionDownloadLength = 0;
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
@ -1001,14 +995,12 @@ DownloadResultHandle RequestGroup::createDownloadResult() const
_segmentMan->calculateSessionDownloadLength(); _segmentMan->calculateSessionDownloadLength();
} }
// TODO1.5 Purge unnecessary data in FileEntry here.
return return
SharedHandle<DownloadResult> SharedHandle<DownloadResult>
(new DownloadResult(_gid, (new DownloadResult(_gid,
_downloadContext->getFileEntries(), _downloadContext->getFileEntries(),
_inMemoryDownload, _inMemoryDownload,
getTotalLength(),
uris.empty() ? A2STR::NIL:uris.front(),
uris.size(),
sessionDownloadLength, sessionDownloadLength,
_downloadContext->calculateSessionTime(), _downloadContext->calculateSessionTime(),
downloadResult())); downloadResult()));
@ -1072,26 +1064,6 @@ void RequestGroup::removeServerHost(int32_t cuid)
_serverHosts.erase(std::remove_if(_serverHosts.begin(), _serverHosts.end(), FindServerHostByCUID(cuid)), _serverHosts.end()); _serverHosts.erase(std::remove_if(_serverHosts.begin(), _serverHosts.end(), FindServerHostByCUID(cuid)), _serverHosts.end());
} }
void RequestGroup::removeURIWhoseHostnameIs(const std::string& hostname)
{
std::deque<std::string> newURIs;
Request req;
for(std::deque<std::string>::const_iterator itr = _uris.begin(); itr != _uris.end(); ++itr) {
if(((*itr).find(hostname) == std::string::npos) ||
(req.setUrl(*itr) && (req.getHost() != hostname))) {
newURIs.push_back(*itr);
}
}
_logger->debug("GUID#%d - Removed %d duplicate hostname URIs",
_gid, _uris.size()-newURIs.size());
_uris = newURIs;
}
void RequestGroup::removeIdenticalURI(const std::string& uri)
{
_uris.erase(std::remove(_uris.begin(), _uris.end(), uri), _uris.end());
}
void RequestGroup::reportDownloadFinished() void RequestGroup::reportDownloadFinished()
{ {
_logger->notice(MSG_FILE_DOWNLOAD_COMPLETED, _logger->notice(MSG_FILE_DOWNLOAD_COMPLETED,
@ -1155,7 +1127,7 @@ void RequestGroup::increaseAndValidateFileNotFoundCount()
_segmentMan->calculateSessionDownloadLength() == 0) { _segmentMan->calculateSessionDownloadLength() == 0) {
throw DOWNLOAD_FAILURE_EXCEPTION2 throw DOWNLOAD_FAILURE_EXCEPTION2
(StringFormat("Reached max-file-not-found count=%u", maxCount).str(), (StringFormat("Reached max-file-not-found count=%u", maxCount).str(),
DownloadResult::MAX_FILE_NOT_FOUND); downloadresultcode::MAX_FILE_NOT_FOUND);
} }
} }
@ -1164,38 +1136,6 @@ void RequestGroup::markInMemoryDownload()
_inMemoryDownload = true; _inMemoryDownload = true;
} }
void RequestGroup::tuneDownloadCommand(DownloadCommand* command)
{
_uriSelector->tuneDownloadCommand(_uris, command);
}
void RequestGroup::addURIResult(std::string uri, DownloadResult::RESULT result)
{
_uriResults.push_back(URIResult(uri, result));
}
class FindURIResultByResult {
private:
DownloadResult::RESULT _r;
public:
FindURIResultByResult(DownloadResult::RESULT r):_r(r) {}
bool operator()(const URIResult& uriResult) const
{
return uriResult.getResult() == _r;
}
};
void RequestGroup::extractURIResult
(std::deque<URIResult>& res, DownloadResult::RESULT r)
{
std::deque<URIResult>::iterator i =
std::stable_partition(_uriResults.begin(), _uriResults.end(),
FindURIResultByResult(r));
std::copy(_uriResults.begin(), i, std::back_inserter(res));
_uriResults.erase(_uriResults.begin(), i);
}
void RequestGroup::setTimeout(time_t timeout) void RequestGroup::setTimeout(time_t timeout)
{ {
_timeout = timeout; _timeout = timeout;
@ -1213,4 +1153,10 @@ bool RequestGroup::doesUploadSpeedExceed()
_maxUploadSpeedLimit < calculateStat().getUploadSpeed(); _maxUploadSpeedLimit < calculateStat().getUploadSpeed();
} }
void RequestGroup::setLastUriResult
(const std::string uri, downloadresultcode::RESULT result)
{
_lastUriResult.reset(new URIResult(uri, result));
}
} // namespace aria2 } // namespace aria2

View File

@ -44,8 +44,7 @@
#include "TransferStat.h" #include "TransferStat.h"
#include "TimeA2.h" #include "TimeA2.h"
#include "Request.h" #include "Request.h"
#include "DownloadResult.h" #include "DownloadResultCode.h"
#include "URIResult.h"
namespace aria2 { namespace aria2 {
@ -68,6 +67,7 @@ class CheckIntegrityEntry;
class DownloadResult; class DownloadResult;
class ServerHost; class ServerHost;
class URISelector; class URISelector;
class URIResult;
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
class BtRuntime; class BtRuntime;
class PeerStorage; class PeerStorage;
@ -87,10 +87,7 @@ private:
SharedHandle<Option> _option; SharedHandle<Option> _option;
std::deque<std::string> _uris; size_t _numConcurrentCommand;
std::deque<std::string> _spentUris;
unsigned int _numConcurrentCommand;
/** /**
* This is the number of connections used in streaming protocol(http/ftp) * This is the number of connections used in streaming protocol(http/ftp)
@ -124,10 +121,6 @@ private:
HaltReason _haltReason; HaltReason _haltReason;
// URIResult is stored in the ascending order of the time when its result is
// available.
std::deque<URIResult> _uriResults;
bool _singleHostMultiConnectionEnabled; bool _singleHostMultiConnectionEnabled;
std::deque<SharedHandle<PreDownloadHandler> > _preDownloadHandlers; std::deque<SharedHandle<PreDownloadHandler> > _preDownloadHandlers;
@ -159,6 +152,8 @@ private:
unsigned int _maxUploadSpeedLimit; unsigned int _maxUploadSpeedLimit;
SharedHandle<URIResult> _lastUriResult;
Logger* _logger; Logger* _logger;
void validateFilename(const std::string& expectedFilename, void validateFilename(const std::string& expectedFilename,
@ -170,15 +165,14 @@ private:
bool tryAutoFileRenaming(); bool tryAutoFileRenaming();
// Returns the result code of this RequestGroup. // Returns the result code of this RequestGroup. If the download
// If the download finished, then returns DownloadResult::FINISHED. // finished, then returns downloadresultcode::FINISHED. If the
// If the download didn't finish and error result is available in _uriResults, // download didn't finish and error result is available in
// then last result code is returned. // _uriResults, then last result code is returned. Otherwise
// Otherwise returns DownloadResult::UNKNOWN_ERROR. // returns downloadresultcode::UNKNOWN_ERROR.
DownloadResult::RESULT downloadResult() const; downloadresultcode::RESULT downloadResult() const;
public: public:
RequestGroup(const SharedHandle<Option>& option, RequestGroup(const SharedHandle<Option>& option);
const std::deque<std::string>& uris);
~RequestGroup(); ~RequestGroup();
/** /**
@ -210,11 +204,6 @@ public:
DownloadEngine* e, unsigned int numCommand, DownloadEngine* e, unsigned int numCommand,
const std::string& method = Request::METHOD_GET); const std::string& method = Request::METHOD_GET);
void addURI(const std::string& uri)
{
_uris.push_back(uri);
}
bool downloadFinished() const; bool downloadFinished() const;
bool allDownloadFinished() const; bool allDownloadFinished() const;
@ -227,18 +216,6 @@ public:
uint64_t getCompletedLength() const; uint64_t getCompletedLength() const;
const std::deque<std::string>& getRemainingUris() const
{
return _uris;
}
const std::deque<std::string>& getSpentUris() const
{
return _spentUris;
}
void getURIs(std::deque<std::string>& uris) const;
/** /**
* Compares expected filename with specified actualFilename. * Compares expected filename with specified actualFilename.
* The expected filename refers to FileEntry::getBasename() of the first * The expected filename refers to FileEntry::getBasename() of the first
@ -358,17 +335,6 @@ public:
return _forceHaltRequested; return _forceHaltRequested;
} }
void addURIResult(std::string uri, DownloadResult::RESULT result);
const std::deque<URIResult>& getURIResults() const
{
return _uriResults;
}
// Extracts URIResult whose _result is r and stores them into res.
// The extracted URIResults are removed from _uriResults.
void extractURIResult(std::deque<URIResult>& res, DownloadResult::RESULT r);
void dependsOn(const SharedHandle<Dependency>& dep); void dependsOn(const SharedHandle<Dependency>& dep);
bool isDependencyResolved(); bool isDependencyResolved();
@ -433,10 +399,6 @@ public:
void removeServerHost(int32_t cuid); void removeServerHost(int32_t cuid);
void removeURIWhoseHostnameIs(const std::string& hostname);
void removeIdenticalURI(const std::string& uri);
void reportDownloadFinished(); void reportDownloadFinished();
const std::deque<std::string>& getAcceptTypes() const const std::deque<std::string>& getAcceptTypes() const
@ -472,8 +434,6 @@ public:
return _inMemoryDownload; return _inMemoryDownload;
} }
void tuneDownloadCommand(DownloadCommand* command);
void setTimeout(time_t timeout); void setTimeout(time_t timeout);
time_t getTimeout() const time_t getTimeout() const
@ -511,6 +471,8 @@ public:
_maxUploadSpeedLimit = speed; _maxUploadSpeedLimit = speed;
} }
void setLastUriResult(std::string uri, downloadresultcode::RESULT result);
static void resetGIDCounter() { _gidCounter = 0; } static void resetGIDCounter() { _gidCounter = 0; }
}; };

View File

@ -249,10 +249,10 @@ static void executeStartHook
static void executeStopHook static void executeStopHook
(const SharedHandle<DownloadResult>& result, const Option* option) (const SharedHandle<DownloadResult>& result, const Option* option)
{ {
if(result->result == DownloadResult::FINISHED && if(result->result == downloadresultcode::FINISHED &&
!option->blank(PREF_ON_DOWNLOAD_COMPLETE)) { !option->blank(PREF_ON_DOWNLOAD_COMPLETE)) {
executeHook(option->get(PREF_ON_DOWNLOAD_COMPLETE), result->gid); executeHook(option->get(PREF_ON_DOWNLOAD_COMPLETE), result->gid);
} else if(result->result != DownloadResult::IN_PROGRESS && } else if(result->result != downloadresultcode::IN_PROGRESS &&
!option->blank(PREF_ON_DOWNLOAD_ERROR)) { !option->blank(PREF_ON_DOWNLOAD_ERROR)) {
executeHook(option->get(PREF_ON_DOWNLOAD_ERROR), result->gid); executeHook(option->get(PREF_ON_DOWNLOAD_ERROR), result->gid);
} else if(!option->blank(PREF_ON_DOWNLOAD_STOP)) { } else if(!option->blank(PREF_ON_DOWNLOAD_STOP)) {
@ -531,10 +531,10 @@ RequestGroupMan::DownloadStat RequestGroupMan::getDownloadStat() const
size_t finished = 0; size_t finished = 0;
size_t error = 0; size_t error = 0;
size_t inprogress = 0; size_t inprogress = 0;
DownloadResult::RESULT lastError = DownloadResult::FINISHED; downloadresultcode::RESULT lastError = downloadresultcode::FINISHED;
for(std::deque<SharedHandle<DownloadResult> >::const_iterator itr = _downloadResults.begin(); for(std::deque<SharedHandle<DownloadResult> >::const_iterator itr = _downloadResults.begin();
itr != _downloadResults.end(); ++itr) { itr != _downloadResults.end(); ++itr) {
if((*itr)->result == DownloadResult::FINISHED) { if((*itr)->result == downloadresultcode::FINISHED) {
++finished; ++finished;
} else { } else {
++error; ++error;
@ -544,7 +544,7 @@ RequestGroupMan::DownloadStat RequestGroupMan::getDownloadStat() const
for(RequestGroups::const_iterator itr = _requestGroups.begin(); for(RequestGroups::const_iterator itr = _requestGroups.begin();
itr != _requestGroups.end(); ++itr) { itr != _requestGroups.end(); ++itr) {
DownloadResultHandle result = (*itr)->createDownloadResult(); DownloadResultHandle result = (*itr)->createDownloadResult();
if(result->result == DownloadResult::FINISHED) { if(result->result == downloadresultcode::FINISHED) {
++finished; ++finished;
} else { } else {
++inprogress; ++inprogress;
@ -575,10 +575,10 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const
for(std::deque<SharedHandle<DownloadResult> >::const_iterator itr = _downloadResults.begin(); for(std::deque<SharedHandle<DownloadResult> >::const_iterator itr = _downloadResults.begin();
itr != _downloadResults.end(); ++itr) { itr != _downloadResults.end(); ++itr) {
std::string status; std::string status;
if((*itr)->result == DownloadResult::FINISHED) { if((*itr)->result == downloadresultcode::FINISHED) {
status = MARK_OK; status = MARK_OK;
++ok; ++ok;
} else if((*itr)->result == DownloadResult::IN_PROGRESS) { } else if((*itr)->result == downloadresultcode::IN_PROGRESS) {
status = MARK_INPR; status = MARK_INPR;
++inpr; ++inpr;
} else { } else {
@ -591,7 +591,7 @@ void RequestGroupMan::showDownloadResults(std::ostream& o) const
itr != _requestGroups.end(); ++itr) { itr != _requestGroups.end(); ++itr) {
DownloadResultHandle result = (*itr)->createDownloadResult(); DownloadResultHandle result = (*itr)->createDownloadResult();
std::string status; std::string status;
if(result->result == DownloadResult::FINISHED) { if(result->result == downloadresultcode::FINISHED) {
status = MARK_OK; status = MARK_OK;
++ok; ++ok;
} else { } else {
@ -639,16 +639,8 @@ std::string RequestGroupMan::formatDownloadResult(const std::string& status, con
o << "|"; o << "|";
const std::vector<SharedHandle<FileEntry> >& fileEntries = const std::vector<SharedHandle<FileEntry> >& fileEntries =
downloadResult->fileEntries; downloadResult->fileEntries;
if(downloadResult->result == DownloadResult::FINISHED || writeFilePath(fileEntries.begin(), fileEntries.end(), o,
downloadResult->numUri == 0) { downloadResult->inMemoryDownload);
writeFilePath(fileEntries.begin(), fileEntries.end(), o,
downloadResult->inMemoryDownload);
} else {
o << downloadResult->uri;
if(downloadResult->numUri > 1) {
o << " (" << downloadResult->numUri-1 << "more)";
}
}
return o.str(); return o.str();
} }

View File

@ -146,21 +146,21 @@ public:
size_t _error; size_t _error;
size_t _inProgress; size_t _inProgress;
size_t _waiting; size_t _waiting;
DownloadResult::RESULT _lastErrorResult; downloadresultcode::RESULT _lastErrorResult;
public: public:
DownloadStat(size_t completed, DownloadStat(size_t completed,
size_t error, size_t error,
size_t inProgress, size_t inProgress,
size_t waiting, size_t waiting,
DownloadResult::RESULT lastErrorResult = downloadresultcode::RESULT lastErrorResult =
DownloadResult::FINISHED): downloadresultcode::FINISHED):
_completed(completed), _completed(completed),
_error(error), _error(error),
_inProgress(inProgress), _inProgress(inProgress),
_waiting(waiting), _waiting(waiting),
_lastErrorResult(lastErrorResult) {} _lastErrorResult(lastErrorResult) {}
DownloadResult::RESULT getLastErrorResult() const downloadresultcode::RESULT getLastErrorResult() const
{ {
return _lastErrorResult; return _lastErrorResult;
} }

View File

@ -37,6 +37,7 @@
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "Logger.h" #include "Logger.h"
#include "message.h" #include "message.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -200,7 +200,7 @@ TrackerWatcherCommand::createRequestGroup(const std::string& uri)
{ {
std::deque<std::string> uris; std::deque<std::string> uris;
uris.push_back(uri); uris.push_back(uri);
RequestGroupHandle rg(new RequestGroup(getOption(), uris)); RequestGroupHandle rg(new RequestGroup(getOption()));
// If backup tracker is available, only try 2 times for each tracker // If backup tracker is available, only try 2 times for each tracker
// and if they all fails, then try next one. // and if they all fails, then try next one.
if(backupTrackerIsAvailable(_requestGroup->getDownloadContext())) { if(backupTrackerIsAvailable(_requestGroup->getDownloadContext())) {

View File

@ -36,7 +36,7 @@
namespace aria2 { namespace aria2 {
URIResult::URIResult(const std::string& uri, DownloadResult::RESULT result): URIResult::URIResult(const std::string& uri, downloadresultcode::RESULT result):
_uri(uri), _result(result) {} _uri(uri), _result(result) {}
} // namespace aria2 } // namespace aria2

View File

@ -39,7 +39,7 @@
#include <string> #include <string>
#include "DownloadResult.h" #include "DownloadResultCode.h"
namespace aria2 { namespace aria2 {
@ -48,16 +48,16 @@ class URIResult {
private: private:
std::string _uri; std::string _uri;
DownloadResult::RESULT _result; downloadresultcode::RESULT _result;
public: public:
URIResult(const std::string& uri, DownloadResult::RESULT result); URIResult(const std::string& uri, downloadresultcode::RESULT result);
const std::string& getURI() const const std::string& getURI() const
{ {
return _uri; return _uri;
} }
DownloadResult::RESULT getResult() const downloadresultcode::RESULT getResult() const
{ {
return _result; return _result;
} }

View File

@ -41,14 +41,15 @@
namespace aria2 { namespace aria2 {
class DownloadCommand; class DownloadCommand;
class FileEntry;
class URISelector { class URISelector {
public: public:
virtual ~URISelector() {} virtual ~URISelector() {}
virtual std::string select(std::deque<std::string>& uris) = 0; virtual std::string select(FileEntry* fileEntry) = 0;
virtual void tuneDownloadCommand(std::deque<std::string>& uris, virtual void tuneDownloadCommand(const std::deque<std::string>& uris,
DownloadCommand* command) {}; DownloadCommand* command) {};
virtual void resetCounters() { return; }; virtual void resetCounters() { return; };

View File

@ -344,9 +344,9 @@ static void gatherStoppedDownload
(BDE& entryDict, const SharedHandle<DownloadResult>& ds) (BDE& entryDict, const SharedHandle<DownloadResult>& ds)
{ {
entryDict["gid"] = Util::itos(ds->gid); entryDict["gid"] = Util::itos(ds->gid);
if(ds->result == DownloadResult::IN_PROGRESS) { if(ds->result == downloadresultcode::IN_PROGRESS) {
entryDict["status"] = BDE_REMOVED; entryDict["status"] = BDE_REMOVED;
} else if(ds->result == DownloadResult::FINISHED) { } else if(ds->result == downloadresultcode::FINISHED) {
entryDict["status"] = BDE_COMPLETE; entryDict["status"] = BDE_COMPLETE;
} else { } else {
entryDict["status"] = BDE_ERROR; entryDict["status"] = BDE_ERROR;
@ -428,7 +428,9 @@ BDE GetUrisXmlRpcMethod::process
} }
BDE uriList = BDE::list(); BDE uriList = BDE::list();
std::deque<std::string> uris; std::deque<std::string> uris;
group->getURIs(uris); // TODO1.5 getUris should return list of URIs attached to each FileEntry.
// Current implementation just returns first FileEntry's URIs.
group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
for(std::deque<std::string>::const_iterator i = uris.begin(); i != uris.end(); for(std::deque<std::string>::const_iterator i = uris.begin(); i != uris.end();
++i) { ++i) {
BDE entry = BDE::dict(); BDE entry = BDE::dict();

View File

@ -301,7 +301,8 @@ static void processRootDictionary
(const SharedHandle<DownloadContext>& ctx, (const SharedHandle<DownloadContext>& ctx,
const BDE& rootDict, const BDE& rootDict,
const std::string& defaultName, const std::string& defaultName,
const std::string& overrideName) const std::string& overrideName,
const std::deque<std::string>& uris)
{ {
if(!rootDict.isDict()) { if(!rootDict.isDict()) {
throw DL_ABORT_EX("torrent file does not contain a root dictionary."); throw DL_ABORT_EX("torrent file does not contain a root dictionary.");
@ -359,6 +360,9 @@ static void processRootDictionary
// see http://www.getright.com/seedtorrent.html // see http://www.getright.com/seedtorrent.html
std::vector<std::string> urlList; std::vector<std::string> urlList;
extractUrlList(urlList, rootDict[C_URL_LIST]); extractUrlList(urlList, rootDict[C_URL_LIST]);
urlList.insert(urlList.end(), uris.begin(), uris.end());
std::sort(urlList.begin(), urlList.end());
urlList.erase(std::unique(urlList.begin(), urlList.end()), urlList.end());
// retrieve file entries // retrieve file entries
extractFileEntries(ctx, torrent, infoDict, defaultName, overrideName, urlList); extractFileEntries(ctx, torrent, infoDict, defaultName, overrideName, urlList);
@ -380,8 +384,20 @@ void load(const std::string& torrentFile,
processRootDictionary(ctx, processRootDictionary(ctx,
bencode::decodeFromFile(torrentFile), bencode::decodeFromFile(torrentFile),
torrentFile, torrentFile,
overrideName); overrideName,
std::deque<std::string>());
}
void load(const std::string& torrentFile,
const SharedHandle<DownloadContext>& ctx,
const std::deque<std::string>& uris,
const std::string& overrideName)
{
processRootDictionary(ctx,
bencode::decodeFromFile(torrentFile),
torrentFile,
overrideName,
uris);
} }
void loadFromMemory(const unsigned char* content, void loadFromMemory(const unsigned char* content,
@ -393,7 +409,22 @@ void loadFromMemory(const unsigned char* content,
processRootDictionary(ctx, processRootDictionary(ctx,
bencode::decode(content, length), bencode::decode(content, length),
defaultName, defaultName,
overrideName); overrideName,
std::deque<std::string>());
}
void loadFromMemory(const unsigned char* content,
size_t length,
const SharedHandle<DownloadContext>& ctx,
const std::deque<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName)
{
processRootDictionary(ctx,
bencode::decode(content, length),
defaultName,
overrideName,
uris);
} }
void loadFromMemory(const std::string& context, void loadFromMemory(const std::string& context,
@ -405,7 +436,22 @@ void loadFromMemory(const std::string& context,
(ctx, (ctx,
bencode::decode(reinterpret_cast<const unsigned char*>(context.c_str()), bencode::decode(reinterpret_cast<const unsigned char*>(context.c_str()),
context.size()), context.size()),
defaultName, overrideName); defaultName, overrideName,
std::deque<std::string>());
}
void loadFromMemory(const std::string& context,
const SharedHandle<DownloadContext>& ctx,
const std::deque<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName)
{
processRootDictionary
(ctx,
bencode::decode(reinterpret_cast<const unsigned char*>(context.c_str()),
context.size()),
defaultName, overrideName,
uris);
} }
const unsigned char* const unsigned char*

View File

@ -39,6 +39,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <deque>
#include "SharedHandle.h" #include "SharedHandle.h"
#include "AnnounceTier.h" #include "AnnounceTier.h"
@ -78,13 +79,30 @@ void load(const std::string& torrentFile,
const SharedHandle<DownloadContext>& ctx, const SharedHandle<DownloadContext>& ctx,
const std::string& overrideName = ""); const std::string& overrideName = "");
void load(const std::string& torrentFile,
const SharedHandle<DownloadContext>& ctx,
const std::deque<std::string>& uris,
const std::string& overrideName = "");
void loadFromMemory(const unsigned char* content, size_t length, void loadFromMemory(const unsigned char* content, size_t length,
const SharedHandle<DownloadContext>& ctx, const SharedHandle<DownloadContext>& ctx,
const std::string& defaultName, const std::string& defaultName,
const std::string& overrideName = ""); const std::string& overrideName = "");
void loadFromMemory(const unsigned char* content, size_t length,
const SharedHandle<DownloadContext>& ctx,
const std::deque<std::string>& uris,
const std::string& defaultName,
const std::string& overrideName = "");
void loadFromMemory(const std::string& context,
const SharedHandle<DownloadContext>& ctx,
const std::string& defaultName,
const std::string& overrideName = "");
void loadFromMemory(const std::string& context, void loadFromMemory(const std::string& context,
const SharedHandle<DownloadContext>& ctx, const SharedHandle<DownloadContext>& ctx,
const std::deque<std::string>& uris,
const std::string& defaultName, const std::string& defaultName,
const std::string& overrideName = ""); const std::string& overrideName = "");

View File

@ -179,7 +179,7 @@ static SharedHandle<RequestGroup> createRequestGroup
(const SharedHandle<Option>& option, const std::deque<std::string>& uris, (const SharedHandle<Option>& option, const std::deque<std::string>& uris,
bool useOutOption = false) bool useOutOption = false)
{ {
SharedHandle<RequestGroup> rg(new RequestGroup(option, uris)); SharedHandle<RequestGroup> rg(new RequestGroup(option));
SharedHandle<DownloadContext> dctx SharedHandle<DownloadContext> dctx
(new DownloadContext (new DownloadContext
(option->getAsInt(PREF_SEGMENT_SIZE), (option->getAsInt(PREF_SEGMENT_SIZE),
@ -201,15 +201,16 @@ createBtRequestGroup(const std::string& torrentFilePath,
const std::deque<std::string>& auxUris, const std::deque<std::string>& auxUris,
const std::string& torrentData = "") const std::string& torrentData = "")
{ {
SharedHandle<RequestGroup> rg(new RequestGroup(option, auxUris)); SharedHandle<RequestGroup> rg(new RequestGroup(option));
SharedHandle<DownloadContext> dctx(new DownloadContext()); SharedHandle<DownloadContext> dctx(new DownloadContext());
dctx->setDir(option->get(PREF_DIR)); dctx->setDir(option->get(PREF_DIR));
// TODO1.5 Add additional argument auxUris for bittorrent::load* functions.
if(torrentData.empty()) { if(torrentData.empty()) {
bittorrent::load(torrentFilePath, dctx);// may throw exception bittorrent::load(torrentFilePath, dctx, auxUris);// may throw exception
} else { } else {
bittorrent::loadFromMemory(torrentData, dctx, "default"); // may bittorrent::loadFromMemory(torrentData, dctx, auxUris, "default"); // may
// throw // throw
// exception // exception
} }
dctx->setFileFilter(Util::parseIntRange(option->get(PREF_SELECT_FILE))); dctx->setFileFilter(Util::parseIntRange(option->get(PREF_SELECT_FILE)));
std::istringstream indexOutIn(option->get(PREF_INDEX_OUT)); std::istringstream indexOutIn(option->get(PREF_INDEX_OUT));

View File

@ -165,7 +165,7 @@ static void showFiles
extern void option_processing(Option& option, std::deque<std::string>& uris, extern void option_processing(Option& option, std::deque<std::string>& uris,
int argc, char* const argv[]); int argc, char* const argv[]);
DownloadResult::RESULT main(int argc, char* argv[]) downloadresultcode::RESULT main(int argc, char* argv[])
{ {
std::deque<std::string> args; std::deque<std::string> args;
SharedHandle<Option> op(new Option()); SharedHandle<Option> op(new Option());
@ -192,7 +192,7 @@ DownloadResult::RESULT main(int argc, char* argv[])
if(op->get(PREF_EVENT_POLL) == V_SELECT) { if(op->get(PREF_EVENT_POLL) == V_SELECT) {
SocketCore::useSelect(); SocketCore::useSelect();
} }
DownloadResult::RESULT exitStatus = DownloadResult::FINISHED; downloadresultcode::RESULT exitStatus = downloadresultcode::FINISHED;
try { try {
Logger* logger = LogFactory::getInstance(); Logger* logger = LogFactory::getInstance();
logger->info("<<--- --- --- ---"); logger->info("<<--- --- --- ---");
@ -253,7 +253,7 @@ DownloadResult::RESULT main(int argc, char* argv[])
} }
} catch(Exception& ex) { } catch(Exception& ex) {
std::cerr << EX_EXCEPTION_CAUGHT << "\n" << ex.stackTrace() << std::endl; std::cerr << EX_EXCEPTION_CAUGHT << "\n" << ex.stackTrace() << std::endl;
exitStatus = DownloadResult::UNKNOWN_ERROR; exitStatus = downloadresultcode::UNKNOWN_ERROR;
} }
LogFactory::release(); LogFactory::release();
return exitStatus; return exitStatus;
@ -264,7 +264,7 @@ DownloadResult::RESULT main(int argc, char* argv[])
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
aria2::Platform platform; aria2::Platform platform;
aria2::DownloadResult::RESULT r = aria2::main(argc, argv); aria2::downloadresultcode::RESULT r = aria2::main(argc, argv);
return r; return r;
} }

View File

@ -53,7 +53,7 @@
#include "File.h" #include "File.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "OptionHandlerException.h" #include "OptionHandlerException.h"
#include "DownloadResult.h" #include "DownloadResultCode.h"
#include "SimpleRandomizer.h" #include "SimpleRandomizer.h"
#include "bittorrent_helper.h" #include "bittorrent_helper.h"
@ -98,7 +98,7 @@ void option_processing(Option& op, std::deque<std::string>& uris,
if(op.defined("version")) { if(op.defined("version")) {
showVersion(); showVersion();
exit(DownloadResult::FINISHED); exit(downloadresultcode::FINISHED);
} }
if(op.defined("help")) { if(op.defined("help")) {
std::string keyword; std::string keyword;
@ -115,7 +115,7 @@ void option_processing(Option& op, std::deque<std::string>& uris,
} }
} }
showUsage(keyword, oparser); showUsage(keyword, oparser);
exit(DownloadResult::FINISHED); exit(downloadresultcode::FINISHED);
} }
} }
@ -137,18 +137,18 @@ void option_processing(Option& op, std::deque<std::string>& uris,
<< "Usage:" << "\n" << "Usage:" << "\n"
<< oparser.findByName(e.getOptionName())->getDescription() << oparser.findByName(e.getOptionName())->getDescription()
<< std::endl; << std::endl;
exit(DownloadResult::UNKNOWN_ERROR); exit(downloadresultcode::UNKNOWN_ERROR);
} catch(Exception& e) { } catch(Exception& e) {
std::cerr << "Parse error in " << cfname << "\n" std::cerr << "Parse error in " << cfname << "\n"
<< e.stackTrace() << std::endl; << e.stackTrace() << std::endl;
exit(DownloadResult::UNKNOWN_ERROR); exit(downloadresultcode::UNKNOWN_ERROR);
} }
} else if(!ucfname.empty()) { } else if(!ucfname.empty()) {
std::cerr << StringFormat("Configuration file %s is not found.", std::cerr << StringFormat("Configuration file %s is not found.",
cfname.c_str()) cfname.c_str())
<< "\n"; << "\n";
showUsage(TAG_HELP, oparser); showUsage(TAG_HELP, oparser);
exit(DownloadResult::UNKNOWN_ERROR); exit(downloadresultcode::UNKNOWN_ERROR);
} }
} }
// Override configuration with environment variables. // Override configuration with environment variables.
@ -168,11 +168,11 @@ void option_processing(Option& op, std::deque<std::string>& uris,
<< "Usage:" << "\n" << "Usage:" << "\n"
<< oparser.findByName(e.getOptionName()) << oparser.findByName(e.getOptionName())
<< std::endl; << std::endl;
exit(DownloadResult::UNKNOWN_ERROR); exit(downloadresultcode::UNKNOWN_ERROR);
} catch(Exception& e) { } catch(Exception& e) {
std::cerr << e.stackTrace() << std::endl; std::cerr << e.stackTrace() << std::endl;
showUsage(TAG_HELP, oparser); showUsage(TAG_HELP, oparser);
exit(DownloadResult::UNKNOWN_ERROR); exit(downloadresultcode::UNKNOWN_ERROR);
} }
if( if(
#ifdef ENABLE_XML_RPC #ifdef ENABLE_XML_RPC
@ -188,7 +188,7 @@ void option_processing(Option& op, std::deque<std::string>& uris,
if(uris.empty()) { if(uris.empty()) {
std::cerr << MSG_URI_REQUIRED << std::endl; std::cerr << MSG_URI_REQUIRED << std::endl;
showUsage(TAG_HELP, oparser); showUsage(TAG_HELP, oparser);
exit(DownloadResult::UNKNOWN_ERROR); exit(downloadresultcode::UNKNOWN_ERROR);
} }
} }
#ifdef HAVE_DAEMON #ifdef HAVE_DAEMON
@ -200,7 +200,7 @@ void option_processing(Option& op, std::deque<std::string>& uris,
} }
if(daemon(0, 0) < 0) { if(daemon(0, 0) < 0) {
perror(MSG_DAEMON_FAILED); perror(MSG_DAEMON_FAILED);
exit(DownloadResult::UNKNOWN_ERROR); exit(downloadresultcode::UNKNOWN_ERROR);
} }
} }
#endif // HAVE_DAEMON #endif // HAVE_DAEMON

View File

@ -27,8 +27,7 @@ class BtDependencyTest:public CppUnit::TestFixture {
SharedHandle<RequestGroup> createDependant(const SharedHandle<Option>& option) SharedHandle<RequestGroup> createDependant(const SharedHandle<Option>& option)
{ {
SharedHandle<RequestGroup> dependant SharedHandle<RequestGroup> dependant(new RequestGroup(option));
(new RequestGroup(option, std::deque<std::string>()));
SharedHandle<DownloadContext> dctx SharedHandle<DownloadContext> dctx
(new DownloadContext(0, 0, "/tmp/outfile.path")); (new DownloadContext(0, 0, "/tmp/outfile.path"));
dctx->setDir("/tmp"); dctx->setDir("/tmp");
@ -42,8 +41,7 @@ class BtDependencyTest:public CppUnit::TestFixture {
const std::string& torrentFile, const std::string& torrentFile,
int64_t length) int64_t length)
{ {
SharedHandle<RequestGroup> dependee SharedHandle<RequestGroup> dependee(new RequestGroup(option));
(new RequestGroup(option, std::deque<std::string>()));
SharedHandle<DownloadContext> dctx SharedHandle<DownloadContext> dctx
(new DownloadContext(1024*1024, length, torrentFile)); (new DownloadContext(1024*1024, length, torrentFile));
dctx->setDir("."); dctx->setDir(".");

View File

@ -36,7 +36,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( BtPostDownloadHandlerTest );
void BtPostDownloadHandlerTest::testCanHandle_extension() void BtPostDownloadHandlerTest::testCanHandle_extension()
{ {
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test.torrent")); SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test.torrent"));
RequestGroup rg(_option, std::deque<std::string>()); RequestGroup rg(_option);
rg.setDownloadContext(dctx); rg.setDownloadContext(dctx);
BtPostDownloadHandler handler; BtPostDownloadHandler handler;
@ -51,7 +51,7 @@ void BtPostDownloadHandlerTest::testCanHandle_contentType()
{ {
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test")); SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test"));
dctx->getFirstFileEntry()->setContentType("application/x-bittorrent"); dctx->getFirstFileEntry()->setContentType("application/x-bittorrent");
RequestGroup rg(_option, std::deque<std::string>()); RequestGroup rg(_option);
rg.setDownloadContext(dctx); rg.setDownloadContext(dctx);
BtPostDownloadHandler handler; BtPostDownloadHandler handler;
@ -66,7 +66,7 @@ void BtPostDownloadHandlerTest::testGetNextRequestGroups()
{ {
SharedHandle<DownloadContext> dctx SharedHandle<DownloadContext> dctx
(new DownloadContext(1024, 0, "test.torrent")); (new DownloadContext(1024, 0, "test.torrent"));
RequestGroup rg(_option, std::deque<std::string>()); RequestGroup rg(_option);
rg.setDownloadContext(dctx); rg.setDownloadContext(dctx);
rg.initPieceStorage(); rg.initPieceStorage();

View File

@ -10,6 +10,7 @@
#include "TimeA2.h" #include "TimeA2.h"
#include "CookieParser.h" #include "CookieParser.h"
#include "RecoverableException.h" #include "RecoverableException.h"
#include "File.h"
namespace aria2 { namespace aria2 {

View File

@ -137,7 +137,7 @@ public:
void setUp() { void setUp() {
_option.reset(new Option()); _option.reset(new Option());
_rg.reset(new RequestGroup(_option, std::deque<std::string>())); _rg.reset(new RequestGroup(_option));
_dctx.reset(new DownloadContext()); _dctx.reset(new DownloadContext());
bittorrent::load("test.torrent", _dctx); bittorrent::load("test.torrent", _dctx);

View File

@ -51,7 +51,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( DownloadHandlerFactoryTest );
void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_extension() void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_extension()
{ {
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test.metalink")); SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test.metalink"));
RequestGroup rg(_option, std::deque<std::string>()); RequestGroup rg(_option);
rg.setDownloadContext(dctx); rg.setDownloadContext(dctx);
SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler(); SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
@ -66,7 +66,7 @@ void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_contentType()
{ {
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test")); SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test"));
dctx->getFirstFileEntry()->setContentType("application/metalink+xml"); dctx->getFirstFileEntry()->setContentType("application/metalink+xml");
RequestGroup rg(_option, std::deque<std::string>()); RequestGroup rg(_option);
rg.setDownloadContext(dctx); rg.setDownloadContext(dctx);
SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler(); SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
@ -84,7 +84,7 @@ void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_contentType()
void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_extension() void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_extension()
{ {
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test.torrent")); SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test.torrent"));
RequestGroup rg(_option, std::deque<std::string>()); RequestGroup rg(_option);
rg.setDownloadContext(dctx); rg.setDownloadContext(dctx);
SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler(); SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();
@ -99,7 +99,7 @@ void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_contentType()
{ {
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test")); SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test"));
dctx->getFirstFileEntry()->setContentType("application/x-bittorrent"); dctx->getFirstFileEntry()->setContentType("application/x-bittorrent");
RequestGroup rg(_option, std::deque<std::string>()); RequestGroup rg(_option);
rg.setDownloadContext(dctx); rg.setDownloadContext(dctx);
SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler(); SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();

View File

@ -82,7 +82,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size()); CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
SharedHandle<RequestGroup> group = result[0]; SharedHandle<RequestGroup> group = result[0];
std::deque<std::string> uris; std::deque<std::string> uris;
group->getURIs(uris); group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size()); CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size());
for(size_t i = 0; i < arrayLength(array); ++i) { for(size_t i = 0; i < arrayLength(array); ++i) {
CPPUNIT_ASSERT_EQUAL(array[i], uris[i]); CPPUNIT_ASSERT_EQUAL(array[i], uris[i]);
@ -101,7 +101,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size()); CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
SharedHandle<RequestGroup> group = result[0]; SharedHandle<RequestGroup> group = result[0];
std::deque<std::string> uris; std::deque<std::string> uris;
group->getURIs(uris); group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)5, uris.size()); CPPUNIT_ASSERT_EQUAL((size_t)5, uris.size());
for(size_t i = 0; i < arrayLength(array); ++i) { for(size_t i = 0; i < arrayLength(array); ++i) {
CPPUNIT_ASSERT_EQUAL(array[i], uris[i]); CPPUNIT_ASSERT_EQUAL(array[i], uris[i]);
@ -120,7 +120,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size()); CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
SharedHandle<RequestGroup> group = result[0]; SharedHandle<RequestGroup> group = result[0];
std::deque<std::string> uris; std::deque<std::string> uris;
group->getURIs(uris); group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size()); CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size());
for(size_t i = 0; i < arrayLength(array); ++i) { for(size_t i = 0; i < arrayLength(array); ++i) {
CPPUNIT_ASSERT_EQUAL(array[i], uris[i]); CPPUNIT_ASSERT_EQUAL(array[i], uris[i]);
@ -138,7 +138,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
// for alpha server // for alpha server
SharedHandle<RequestGroup> alphaGroup = result[0]; SharedHandle<RequestGroup> alphaGroup = result[0];
std::deque<std::string> alphaURIs; std::deque<std::string> alphaURIs;
alphaGroup->getURIs(alphaURIs); alphaGroup->getDownloadContext()->getFirstFileEntry()->getUris(alphaURIs);
CPPUNIT_ASSERT_EQUAL((size_t)2, alphaURIs.size()); CPPUNIT_ASSERT_EQUAL((size_t)2, alphaURIs.size());
for(size_t i = 0; i < 2; ++i) { for(size_t i = 0; i < 2; ++i) {
CPPUNIT_ASSERT_EQUAL(array[0], uris[0]); CPPUNIT_ASSERT_EQUAL(array[0], uris[0]);
@ -171,7 +171,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri_parameterized()
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size()); CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
SharedHandle<RequestGroup> group = result[0]; SharedHandle<RequestGroup> group = result[0];
std::deque<std::string> uris; std::deque<std::string> uris;
group->getURIs(uris); group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size()); CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size());
CPPUNIT_ASSERT_EQUAL(std::string("http://alpha/file"), uris[0]); CPPUNIT_ASSERT_EQUAL(std::string("http://alpha/file"), uris[0]);
@ -206,7 +206,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri_BitTorrent()
CPPUNIT_ASSERT_EQUAL((size_t)2, result.size()); CPPUNIT_ASSERT_EQUAL((size_t)2, result.size());
SharedHandle<RequestGroup> group = result[0]; SharedHandle<RequestGroup> group = result[0];
std::deque<std::string> uris; std::deque<std::string> uris;
group->getURIs(uris); group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size()); CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size());
CPPUNIT_ASSERT_EQUAL(array[0], uris[0]); CPPUNIT_ASSERT_EQUAL(array[0], uris[0]);
@ -221,7 +221,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri_BitTorrent()
SharedHandle<RequestGroup> torrentGroup = result[1]; SharedHandle<RequestGroup> torrentGroup = result[1];
std::deque<std::string> auxURIs; std::deque<std::string> auxURIs;
torrentGroup->getURIs(auxURIs); torrentGroup->getDownloadContext()->getFirstFileEntry()->getUris(auxURIs);
CPPUNIT_ASSERT(auxURIs.empty()); CPPUNIT_ASSERT(auxURIs.empty());
CPPUNIT_ASSERT_EQUAL((unsigned int)3, CPPUNIT_ASSERT_EQUAL((unsigned int)3,
torrentGroup->getNumConcurrentCommand()); torrentGroup->getNumConcurrentCommand());
@ -262,7 +262,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri_Metalink()
SharedHandle<RequestGroup> group = result[0]; SharedHandle<RequestGroup> group = result[0];
std::deque<std::string> uris; std::deque<std::string> uris;
group->getURIs(uris); group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size()); CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size());
for(size_t i = 0; i < 3; ++i) { for(size_t i = 0; i < 3; ++i) {
CPPUNIT_ASSERT_EQUAL(array[i], uris[i]); CPPUNIT_ASSERT_EQUAL(array[i], uris[i]);
@ -304,7 +304,7 @@ void DownloadHelperTest::testCreateRequestGroupForUriList()
SharedHandle<RequestGroup> fileGroup = result[0]; SharedHandle<RequestGroup> fileGroup = result[0];
std::deque<std::string> fileURIs; std::deque<std::string> fileURIs;
fileGroup->getURIs(fileURIs); fileGroup->getDownloadContext()->getFirstFileEntry()->getUris(fileURIs);
CPPUNIT_ASSERT_EQUAL(std::string("http://alpha/file"), fileURIs[0]); CPPUNIT_ASSERT_EQUAL(std::string("http://alpha/file"), fileURIs[0]);
CPPUNIT_ASSERT_EQUAL(std::string("http://bravo/file"), fileURIs[1]); CPPUNIT_ASSERT_EQUAL(std::string("http://bravo/file"), fileURIs[1]);
CPPUNIT_ASSERT_EQUAL(std::string("http://charlie/file"), fileURIs[2]); CPPUNIT_ASSERT_EQUAL(std::string("http://charlie/file"), fileURIs[2]);
@ -344,13 +344,11 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
SharedHandle<RequestGroup> group = result[0]; SharedHandle<RequestGroup> group = result[0];
std::deque<std::string> uris; std::deque<std::string> uris;
group->getURIs(uris); group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)5, uris.size()); // See -s option is ignored
CPPUNIT_ASSERT_EQUAL((size_t)3, uris.size());
for(size_t i = 0; i < arrayLength(array); ++i) { for(size_t i = 0; i < arrayLength(array); ++i) {
CPPUNIT_ASSERT_EQUAL(array[i], uris[i]); CPPUNIT_ASSERT_EQUAL(array[i]+"/aria2-test/aria2/src/aria2c", uris[i]);
}
for(size_t i = 0; i < 5-arrayLength(array); ++i) {
CPPUNIT_ASSERT_EQUAL(array[i], uris[i+arrayLength(array)]);
} }
CPPUNIT_ASSERT_EQUAL((unsigned int)5, group->getNumConcurrentCommand()); CPPUNIT_ASSERT_EQUAL((unsigned int)5, group->getNumConcurrentCommand());
} }
@ -363,7 +361,7 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size()); CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
SharedHandle<RequestGroup> group = result[0]; SharedHandle<RequestGroup> group = result[0];
std::deque<std::string> uris; std::deque<std::string> uris;
group->getURIs(uris); group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)0, uris.size()); CPPUNIT_ASSERT_EQUAL((size_t)0, uris.size());
} }
_option->put(PREF_FORCE_SEQUENTIAL, V_TRUE); _option->put(PREF_FORCE_SEQUENTIAL, V_TRUE);
@ -398,7 +396,7 @@ void DownloadHelperTest::testCreateRequestGroupForMetalink()
#endif // !ENABLE_BITTORRENT #endif // !ENABLE_BITTORRENT
SharedHandle<RequestGroup> group = result[0]; SharedHandle<RequestGroup> group = result[0];
std::deque<std::string> uris; std::deque<std::string> uris;
group->getURIs(uris); group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
std::sort(uris.begin(), uris.end()); std::sort(uris.begin(), uris.end());
CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size()); CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size());
CPPUNIT_ASSERT_EQUAL(std::string("ftp://ftphost/aria2-0.5.2.tar.bz2"), CPPUNIT_ASSERT_EQUAL(std::string("ftp://ftphost/aria2-0.5.2.tar.bz2"),

View File

@ -1,7 +1,5 @@
#include "FeedbackURISelector.h" #include "FeedbackURISelector.h"
#include <iostream>
#include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/HelperMacros.h>
#include "Exception.h" #include "Exception.h"
@ -9,6 +7,7 @@
#include "array_fun.h" #include "array_fun.h"
#include "ServerStatMan.h" #include "ServerStatMan.h"
#include "ServerStat.h" #include "ServerStat.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {
@ -20,8 +19,7 @@ class FeedbackURISelectorTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testSelect_skipErrorHost); CPPUNIT_TEST(testSelect_skipErrorHost);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
FileEntry _fileEntry;
std::deque<std::string> uris;
SharedHandle<ServerStatMan> ssm; SharedHandle<ServerStatMan> ssm;
@ -35,8 +33,11 @@ public:
"ftp://alpha/file", "ftp://alpha/file",
"http://bravo/file" "http://bravo/file"
}; };
std::deque<std::string> uris;
uris.assign(&urisSrc[0], &urisSrc[arrayLength(urisSrc)]); uris.assign(&urisSrc[0], &urisSrc[arrayLength(urisSrc)]);
_fileEntry.setUris(uris);
ssm.reset(new ServerStatMan()); ssm.reset(new ServerStatMan());
sel.reset(new FeedbackURISelector(ssm)); sel.reset(new FeedbackURISelector(ssm));
} }
@ -56,9 +57,9 @@ CPPUNIT_TEST_SUITE_REGISTRATION(FeedbackURISelectorTest);
void FeedbackURISelectorTest::testSelect_withoutServerStat() void FeedbackURISelectorTest::testSelect_withoutServerStat()
{ {
// Without ServerStat, selector returns first URI // Without ServerStat, selector returns first URI
std::string uri = sel->select(uris); std::string uri = sel->select(&_fileEntry);
CPPUNIT_ASSERT_EQUAL(std::string("http://alpha/file"), uri); CPPUNIT_ASSERT_EQUAL(std::string("http://alpha/file"), uri);
CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size()); CPPUNIT_ASSERT_EQUAL((size_t)2, _fileEntry.getRemainingUris().size());
} }
void FeedbackURISelectorTest::testSelect() void FeedbackURISelectorTest::testSelect()
@ -75,11 +76,13 @@ void FeedbackURISelectorTest::testSelect()
ssm->add(alphaFTP); ssm->add(alphaFTP);
ssm->add(alphaHTTP); ssm->add(alphaHTTP);
CPPUNIT_ASSERT_EQUAL(std::string("http://bravo/file"), sel->select(uris)); CPPUNIT_ASSERT_EQUAL(std::string("http://bravo/file"),
CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size()); sel->select(&_fileEntry));
CPPUNIT_ASSERT_EQUAL((size_t)2, _fileEntry.getRemainingUris().size());
CPPUNIT_ASSERT_EQUAL(std::string("ftp://alpha/file"), sel->select(uris)); CPPUNIT_ASSERT_EQUAL(std::string("ftp://alpha/file"),
CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size()); sel->select(&_fileEntry));
CPPUNIT_ASSERT_EQUAL((size_t)1, _fileEntry.getRemainingUris().size());
} }
void FeedbackURISelectorTest::testSelect_skipErrorHost() void FeedbackURISelectorTest::testSelect_skipErrorHost()
@ -93,8 +96,9 @@ void FeedbackURISelectorTest::testSelect_skipErrorHost()
ssm->add(alphaFTP); ssm->add(alphaFTP);
// See error URIs are removed from URI List. // See error URIs are removed from URI List.
CPPUNIT_ASSERT_EQUAL(std::string("http://bravo/file"), sel->select(uris)); CPPUNIT_ASSERT_EQUAL(std::string("http://bravo/file"),
CPPUNIT_ASSERT_EQUAL((size_t)0, uris.size()); sel->select(&_fileEntry));
CPPUNIT_ASSERT_EQUAL((size_t)0, _fileEntry.getRemainingUris().size());
} }
} // namespace aria2 } // namespace aria2

View File

@ -7,11 +7,15 @@ class FileEntryTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(FileEntryTest); CPPUNIT_TEST_SUITE(FileEntryTest);
CPPUNIT_TEST(testSetupDir); CPPUNIT_TEST(testSetupDir);
CPPUNIT_TEST(testRemoveURIWhoseHostnameIs);
CPPUNIT_TEST(testExtractURIResult);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
public: public:
void setUp() {} void setUp() {}
void testSetupDir(); void testSetupDir();
void testRemoveURIWhoseHostnameIs();
void testExtractURIResult();
}; };
@ -34,4 +38,45 @@ void FileEntryTest::testSetupDir()
CPPUNIT_ASSERT(!f.exists()); CPPUNIT_ASSERT(!f.exists());
} }
void FileEntryTest::testRemoveURIWhoseHostnameIs()
{
const char* uris[] = { "http://localhost/aria2.zip",
"ftp://localhost/aria2.zip",
"http://mirror/aria2.zip" };
FileEntry fileEntry;
fileEntry.setUris(std::deque<std::string>(&uris[0], &uris[3]));
fileEntry.removeURIWhoseHostnameIs("localhost");
CPPUNIT_ASSERT_EQUAL((size_t)1, fileEntry.getRemainingUris().size());
CPPUNIT_ASSERT_EQUAL(std::string("http://mirror/aria2.zip"),
fileEntry.getRemainingUris()[0]);
}
void FileEntryTest::testExtractURIResult()
{
FileEntry fileEntry;
fileEntry.addURIResult("http://timeout/file", downloadresultcode::TIME_OUT);
fileEntry.addURIResult("http://finished/file", downloadresultcode::FINISHED);
fileEntry.addURIResult("http://timeout/file2", downloadresultcode::TIME_OUT);
fileEntry.addURIResult("http://unknownerror/file", downloadresultcode::UNKNOWN_ERROR);
std::deque<URIResult> res;
fileEntry.extractURIResult(res, downloadresultcode::TIME_OUT);
CPPUNIT_ASSERT_EQUAL((size_t)2, res.size());
CPPUNIT_ASSERT_EQUAL(std::string("http://timeout/file"), res[0].getURI());
CPPUNIT_ASSERT_EQUAL(std::string("http://timeout/file2"), res[1].getURI());
CPPUNIT_ASSERT_EQUAL((size_t)2, fileEntry.getURIResults().size());
CPPUNIT_ASSERT_EQUAL(std::string("http://finished/file"),
fileEntry.getURIResults()[0].getURI());
CPPUNIT_ASSERT_EQUAL(std::string("http://unknownerror/file"),
fileEntry.getURIResults()[1].getURI());
res.clear();
fileEntry.extractURIResult(res, downloadresultcode::TIME_OUT);
CPPUNIT_ASSERT(res.empty());
CPPUNIT_ASSERT_EQUAL((size_t)2, fileEntry.getURIResults().size());
}
} // namespace aria2 } // namespace aria2

View File

@ -1,9 +1,11 @@
#include "InOrderURISelector.h" #include "InOrderURISelector.h"
#include <cppunit/extensions/HelperMacros.h>
#include "Exception.h" #include "Exception.h"
#include "Util.h" #include "Util.h"
#include "array_fun.h" #include "array_fun.h"
#include <iostream> #include "FileEntry.h"
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 { namespace aria2 {
@ -13,8 +15,7 @@ class InOrderURISelectorTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testSelect); CPPUNIT_TEST(testSelect);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
FileEntry _fileEntry;
std::deque<std::string> uris;
SharedHandle<InOrderURISelector> sel; SharedHandle<InOrderURISelector> sel;
@ -26,8 +27,11 @@ public:
"ftp://alpha/file", "ftp://alpha/file",
"http://bravo/file" "http://bravo/file"
}; };
std::deque<std::string> uris;
uris.assign(&urisSrc[0], &urisSrc[arrayLength(urisSrc)]); uris.assign(&urisSrc[0], &urisSrc[arrayLength(urisSrc)]);
_fileEntry.setUris(uris);
sel.reset(new InOrderURISelector()); sel.reset(new InOrderURISelector());
} }
@ -41,10 +45,13 @@ CPPUNIT_TEST_SUITE_REGISTRATION(InOrderURISelectorTest);
void InOrderURISelectorTest::testSelect() void InOrderURISelectorTest::testSelect()
{ {
CPPUNIT_ASSERT_EQUAL(std::string("http://alpha/file"), sel->select(uris)); CPPUNIT_ASSERT_EQUAL(std::string("http://alpha/file"),
CPPUNIT_ASSERT_EQUAL(std::string("ftp://alpha/file"), sel->select(uris)); sel->select(&_fileEntry));
CPPUNIT_ASSERT_EQUAL(std::string("http://bravo/file"), sel->select(uris)); CPPUNIT_ASSERT_EQUAL(std::string("ftp://alpha/file"),
CPPUNIT_ASSERT_EQUAL(std::string(""), sel->select(uris)); sel->select(&_fileEntry));
CPPUNIT_ASSERT_EQUAL(std::string("http://bravo/file"),
sel->select(&_fileEntry));
CPPUNIT_ASSERT_EQUAL(std::string(""), sel->select(&_fileEntry));
} }
} // namespace aria2 } // namespace aria2

View File

@ -42,7 +42,7 @@ void Metalink2RequestGroupTest::testGenerate()
{ {
SharedHandle<RequestGroup> rg = groups[0]; SharedHandle<RequestGroup> rg = groups[0];
std::deque<std::string> uris; std::deque<std::string> uris;
rg->getURIs(uris); rg->getDownloadContext()->getFirstFileEntry()->getUris(uris);
std::sort(uris.begin(), uris.end()); std::sort(uris.begin(), uris.end());
CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size()); CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size());
CPPUNIT_ASSERT_EQUAL CPPUNIT_ASSERT_EQUAL
@ -68,7 +68,7 @@ void Metalink2RequestGroupTest::testGenerate()
{ {
SharedHandle<RequestGroup> rg = groups[1]; SharedHandle<RequestGroup> rg = groups[1];
std::deque<std::string> uris; std::deque<std::string> uris;
rg->getURIs(uris); rg->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size()); CPPUNIT_ASSERT_EQUAL((size_t)2, uris.size());
const SharedHandle<DownloadContext>& dctx = rg->getDownloadContext(); const SharedHandle<DownloadContext>& dctx = rg->getDownloadContext();
@ -90,7 +90,7 @@ void Metalink2RequestGroupTest::testGenerate()
{ {
SharedHandle<RequestGroup> rg = groups[4]; SharedHandle<RequestGroup> rg = groups[4];
std::deque<std::string> uris; std::deque<std::string> uris;
rg->getURIs(uris); rg->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size()); CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
CPPUNIT_ASSERT_EQUAL CPPUNIT_ASSERT_EQUAL
(std::string("http://host/torrent-http.integrated.torrent"), uris[0]); (std::string("http://host/torrent-http.integrated.torrent"), uris[0]);
@ -110,7 +110,7 @@ void Metalink2RequestGroupTest::testGenerate()
SharedHandle<RequestGroup> rg = groups[4]; SharedHandle<RequestGroup> rg = groups[4];
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
std::deque<std::string> uris; std::deque<std::string> uris;
rg->getURIs(uris); rg->getDownloadContext()->getFirstFileEntry()->getUris(uris);
CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size()); CPPUNIT_ASSERT_EQUAL((size_t)1, uris.size());
CPPUNIT_ASSERT_EQUAL CPPUNIT_ASSERT_EQUAL
(std::string("http://host/torrent-http.integrated"), uris[0]); (std::string("http://host/torrent-http.integrated"), uris[0]);

View File

@ -36,7 +36,7 @@ void MetalinkPostDownloadHandlerTest::testCanHandle_extension()
{ {
SharedHandle<DownloadContext> dctx SharedHandle<DownloadContext> dctx
(new DownloadContext(0, 0, "test.metalink")); (new DownloadContext(0, 0, "test.metalink"));
RequestGroup rg(_option, std::deque<std::string>()); RequestGroup rg(_option);
rg.setDownloadContext(dctx); rg.setDownloadContext(dctx);
MetalinkPostDownloadHandler handler; MetalinkPostDownloadHandler handler;
@ -51,7 +51,7 @@ void MetalinkPostDownloadHandlerTest::testCanHandle_contentType()
{ {
SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test")); SharedHandle<DownloadContext> dctx(new DownloadContext(0, 0, "test"));
dctx->getFirstFileEntry()->setContentType("application/metalink+xml"); dctx->getFirstFileEntry()->setContentType("application/metalink+xml");
RequestGroup rg(_option, std::deque<std::string>()); RequestGroup rg(_option);
rg.setDownloadContext(dctx); rg.setDownloadContext(dctx);
MetalinkPostDownloadHandler handler; MetalinkPostDownloadHandler handler;
@ -66,7 +66,7 @@ void MetalinkPostDownloadHandlerTest::testGetNextRequestGroups()
{ {
SharedHandle<DownloadContext> dctx SharedHandle<DownloadContext> dctx
(new DownloadContext(1024, 0, "test.xml")); (new DownloadContext(1024, 0, "test.xml"));
RequestGroup rg(_option, std::deque<std::string>()); RequestGroup rg(_option);
rg.setDownloadContext(dctx); rg.setDownloadContext(dctx);
rg.initPieceStorage(); rg.initPieceStorage();

View File

@ -43,10 +43,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION( RequestGroupManTest );
void RequestGroupManTest::testIsSameFileBeingDownloaded() void RequestGroupManTest::testIsSameFileBeingDownloaded()
{ {
std::deque<std::string> uris; SharedHandle<RequestGroup> rg1(new RequestGroup(_option));
uris.push_back("http://localhost/aria2.tar.bz2"); SharedHandle<RequestGroup> rg2(new RequestGroup(_option));
SharedHandle<RequestGroup> rg1(new RequestGroup(_option, uris));
SharedHandle<RequestGroup> rg2(new RequestGroup(_option, uris));
SharedHandle<DownloadContext> dctx1 SharedHandle<DownloadContext> dctx1
(new DownloadContext(0, 0, "aria2.tar.bz2")); (new DownloadContext(0, 0, "aria2.tar.bz2"));

View File

@ -7,6 +7,7 @@
#include "DownloadContext.h" #include "DownloadContext.h"
#include "FileEntry.h" #include "FileEntry.h"
#include "PieceStorage.h" #include "PieceStorage.h"
#include "DownloadResult.h"
namespace aria2 { namespace aria2 {
@ -14,10 +15,8 @@ class RequestGroupTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(RequestGroupTest); CPPUNIT_TEST_SUITE(RequestGroupTest);
CPPUNIT_TEST(testRegisterSearchRemove); CPPUNIT_TEST(testRegisterSearchRemove);
CPPUNIT_TEST(testRemoveURIWhoseHostnameIs);
CPPUNIT_TEST(testGetFirstFilePath); CPPUNIT_TEST(testGetFirstFilePath);
CPPUNIT_TEST(testCreateDownloadResult); CPPUNIT_TEST(testCreateDownloadResult);
CPPUNIT_TEST(testExtractURIResult);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
SharedHandle<Option> _option; SharedHandle<Option> _option;
@ -28,10 +27,8 @@ public:
} }
void testRegisterSearchRemove(); void testRegisterSearchRemove();
void testRemoveURIWhoseHostnameIs();
void testGetFirstFilePath(); void testGetFirstFilePath();
void testCreateDownloadResult(); void testCreateDownloadResult();
void testExtractURIResult();
}; };
@ -39,7 +36,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( RequestGroupTest );
void RequestGroupTest::testRegisterSearchRemove() void RequestGroupTest::testRegisterSearchRemove()
{ {
RequestGroup rg(_option, std::deque<std::string>()); RequestGroup rg(_option);
SharedHandle<ServerHost> sv1(new ServerHost(1, "localhost1")); SharedHandle<ServerHost> sv1(new ServerHost(1, "localhost1"));
SharedHandle<ServerHost> sv2(new ServerHost(2, "localhost2")); SharedHandle<ServerHost> sv2(new ServerHost(2, "localhost2"));
SharedHandle<ServerHost> sv3(new ServerHost(3, "localhost3")); SharedHandle<ServerHost> sv3(new ServerHost(3, "localhost3"));
@ -69,25 +66,12 @@ void RequestGroupTest::testRegisterSearchRemove()
} }
} }
void RequestGroupTest::testRemoveURIWhoseHostnameIs()
{
const char* uris[] = { "http://localhost/aria2.zip",
"ftp://localhost/aria2.zip",
"http://mirror/aria2.zip" };
RequestGroup rg(_option, std::deque<std::string>(&uris[0], &uris[3]));
rg.removeURIWhoseHostnameIs("localhost");
CPPUNIT_ASSERT_EQUAL((size_t)1, rg.getRemainingUris().size());
CPPUNIT_ASSERT_EQUAL(std::string("http://mirror/aria2.zip"),
rg.getRemainingUris()[0]);
}
void RequestGroupTest::testGetFirstFilePath() void RequestGroupTest::testGetFirstFilePath()
{ {
SharedHandle<DownloadContext> ctx SharedHandle<DownloadContext> ctx
(new DownloadContext(1024, 1024, "/tmp/myfile")); (new DownloadContext(1024, 1024, "/tmp/myfile"));
std::deque<std::string> uris;
RequestGroup group(_option, uris); RequestGroup group(_option);
group.setDownloadContext(ctx); group.setDownloadContext(ctx);
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), group.getFirstFilePath()); CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), group.getFirstFilePath());
@ -101,12 +85,7 @@ void RequestGroupTest::testCreateDownloadResult()
{ {
SharedHandle<DownloadContext> ctx SharedHandle<DownloadContext> ctx
(new DownloadContext(1024, 1024*1024, "/tmp/myfile")); (new DownloadContext(1024, 1024*1024, "/tmp/myfile"));
//ctx->setDir("/tmp"); RequestGroup group(_option);
std::deque<std::string> uris;
uris.push_back("http://first/file");
uris.push_back("http://second/file");
RequestGroup group(_option, uris);
group.setDownloadContext(ctx); group.setDownloadContext(ctx);
group.initPieceStorage(); group.initPieceStorage();
{ {
@ -114,64 +93,35 @@ void RequestGroupTest::testCreateDownloadResult()
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"),
result->fileEntries[0]->getPath()); result->fileEntries[0]->getPath());
CPPUNIT_ASSERT_EQUAL((uint64_t)1024*1024, result->totalLength); CPPUNIT_ASSERT_EQUAL((off_t)1024*1024,
CPPUNIT_ASSERT_EQUAL(std::string("http://first/file"), result->uri); result->fileEntries.back()->getLastOffset());
CPPUNIT_ASSERT_EQUAL((size_t)2, result->numUri);
CPPUNIT_ASSERT_EQUAL((uint64_t)0, result->sessionDownloadLength); CPPUNIT_ASSERT_EQUAL((uint64_t)0, result->sessionDownloadLength);
CPPUNIT_ASSERT_EQUAL((int64_t)0, result->sessionTime); CPPUNIT_ASSERT_EQUAL((int64_t)0, result->sessionTime);
// result is UNKNOWN_ERROR if download has not completed and no specific // result is UNKNOWN_ERROR if download has not completed and no specific
// error has been reported // error has been reported
CPPUNIT_ASSERT_EQUAL(DownloadResult::UNKNOWN_ERROR, result->result); CPPUNIT_ASSERT_EQUAL(downloadresultcode::UNKNOWN_ERROR, result->result);
// if haltReason is set to RequestGroup::USER_REQUEST, download // if haltReason is set to RequestGroup::USER_REQUEST, download
// result becomes IN_PROGRESS // result becomes IN_PROGRESS
group.setHaltRequested(true, RequestGroup::USER_REQUEST); group.setHaltRequested(true, RequestGroup::USER_REQUEST);
result = group.createDownloadResult(); result = group.createDownloadResult();
CPPUNIT_ASSERT_EQUAL(DownloadResult::IN_PROGRESS, result->result); CPPUNIT_ASSERT_EQUAL(downloadresultcode::IN_PROGRESS, result->result);
} }
{ {
group.addURIResult("http://first/file", DownloadResult::TIME_OUT); group.setLastUriResult
group.addURIResult("http://second/file",DownloadResult::RESOURCE_NOT_FOUND); ("http://second/file",downloadresultcode::RESOURCE_NOT_FOUND);
SharedHandle<DownloadResult> result = group.createDownloadResult(); SharedHandle<DownloadResult> result = group.createDownloadResult();
CPPUNIT_ASSERT_EQUAL(DownloadResult::RESOURCE_NOT_FOUND, result->result); CPPUNIT_ASSERT_EQUAL(downloadresultcode::RESOURCE_NOT_FOUND, result->result);
} }
{ {
group.getPieceStorage()->markAllPiecesDone(); group.getPieceStorage()->markAllPiecesDone();
SharedHandle<DownloadResult> result = group.createDownloadResult(); SharedHandle<DownloadResult> result = group.createDownloadResult();
CPPUNIT_ASSERT_EQUAL(DownloadResult::FINISHED, result->result); CPPUNIT_ASSERT_EQUAL(downloadresultcode::FINISHED, result->result);
} }
} }
void RequestGroupTest::testExtractURIResult()
{
RequestGroup group(_option, std::deque<std::string>());
group.addURIResult("http://timeout/file", DownloadResult::TIME_OUT);
group.addURIResult("http://finished/file", DownloadResult::FINISHED);
group.addURIResult("http://timeout/file2", DownloadResult::TIME_OUT);
group.addURIResult("http://unknownerror/file", DownloadResult::UNKNOWN_ERROR);
std::deque<URIResult> res;
group.extractURIResult(res, DownloadResult::TIME_OUT);
CPPUNIT_ASSERT_EQUAL((size_t)2, res.size());
CPPUNIT_ASSERT_EQUAL(std::string("http://timeout/file"), res[0].getURI());
CPPUNIT_ASSERT_EQUAL(std::string("http://timeout/file2"), res[1].getURI());
CPPUNIT_ASSERT_EQUAL((size_t)2, group.getURIResults().size());
CPPUNIT_ASSERT_EQUAL(std::string("http://finished/file"),
group.getURIResults()[0].getURI());
CPPUNIT_ASSERT_EQUAL(std::string("http://unknownerror/file"),
group.getURIResults()[1].getURI());
res.clear();
group.extractURIResult(res, DownloadResult::TIME_OUT);
CPPUNIT_ASSERT(res.empty());
CPPUNIT_ASSERT_EQUAL((size_t)2, group.getURIResults().size());
}
} // namespace aria2 } // namespace aria2

View File

@ -117,7 +117,7 @@ void XmlRpcMethodTest::testAddUri()
_e->_requestGroupMan->getReservedGroups(); _e->_requestGroupMan->getReservedGroups();
CPPUNIT_ASSERT_EQUAL((size_t)1, rgs.size()); CPPUNIT_ASSERT_EQUAL((size_t)1, rgs.size());
CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/"), CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/"),
rgs.front()->getRemainingUris().front()); rgs.front()->getDownloadContext()->getFirstFileEntry()->getRemainingUris().front());
} }
// with options // with options
BDE opt = BDE::dict(); BDE opt = BDE::dict();
@ -180,7 +180,7 @@ void XmlRpcMethodTest::testAddUri_withPosition()
m.execute(req2, _e.get()); m.execute(req2, _e.get());
std::string uri = std::string uri =
_e->_requestGroupMan->getReservedGroups()[0]->getRemainingUris()[0]; _e->_requestGroupMan->getReservedGroups()[0]->getDownloadContext()->getFirstFileEntry()->getRemainingUris()[0];
CPPUNIT_ASSERT_EQUAL(std::string("http://uri2"), uri); CPPUNIT_ASSERT_EQUAL(std::string("http://uri2"), uri);
} }
@ -215,9 +215,9 @@ void XmlRpcMethodTest::testAddTorrent()
CPPUNIT_ASSERT(!group.isNull()); CPPUNIT_ASSERT(!group.isNull());
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/aria2-0.8.2.tar.bz2"), CPPUNIT_ASSERT_EQUAL(std::string("/tmp/aria2-0.8.2.tar.bz2"),
group->getFirstFilePath()); group->getFirstFilePath());
CPPUNIT_ASSERT_EQUAL((size_t)1, group->getRemainingUris().size()); CPPUNIT_ASSERT_EQUAL((size_t)1, group->getDownloadContext()->getFirstFileEntry()->getRemainingUris().size());
CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/aria2-0.8.2.tar.bz2"), CPPUNIT_ASSERT_EQUAL(std::string("http://localhost/aria2-0.8.2.tar.bz2"),
group->getRemainingUris()[0]); group->getDownloadContext()->getFirstFileEntry()->getRemainingUris()[0]);
} }
// with options // with options
BDE opt = BDE::dict(); BDE opt = BDE::dict();
@ -349,8 +349,7 @@ void XmlRpcMethodTest::testAddMetalink_withPosition()
void XmlRpcMethodTest::testChangeOption() void XmlRpcMethodTest::testChangeOption()
{ {
SharedHandle<RequestGroup> group SharedHandle<RequestGroup> group(new RequestGroup(_option));
(new RequestGroup(_option, std::deque<std::string>()));
_e->_requestGroupMan->addReservedGroup(group); _e->_requestGroupMan->addReservedGroup(group);
ChangeOptionXmlRpcMethod m; ChangeOptionXmlRpcMethod m;
@ -374,8 +373,7 @@ void XmlRpcMethodTest::testChangeOption()
void XmlRpcMethodTest::testChangeOption_withBadOption() void XmlRpcMethodTest::testChangeOption_withBadOption()
{ {
SharedHandle<RequestGroup> group SharedHandle<RequestGroup> group(new RequestGroup(_option));
(new RequestGroup(_option, std::deque<std::string>()));
_e->_requestGroupMan->addReservedGroup(group); _e->_requestGroupMan->addReservedGroup(group);
ChangeOptionXmlRpcMethod m; ChangeOptionXmlRpcMethod m;