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

Removed ServerHost. Same functionality is implemented using
	FileEntry's in-flight Request objects.
	* src/AbstractCommand.cc
	* src/BtDependency.cc
	* src/CreateRequestCommand.cc
	* src/FileEntry.cc
	* src/FileEntry.h
	* src/FtpNegotiationCommand.cc
	* src/HttpResponseCommand.cc
	* src/Makefile.am
	* src/Metalink2RequestGroup.cc
	* src/RequestGroup.cc
	* src/RequestGroup.h
	* src/ServerHost.cc: Removed
	* src/ServerHost.h: Removed
	* test/BtDependencyTest.cc
	* test/FileEntryTest.cc
	* test/RequestGroupTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-06-29 16:43:41 +00:00
parent c4d79d7160
commit cece2bc896
18 changed files with 189 additions and 368 deletions

View File

@ -1,3 +1,24 @@
2009-06-30 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed ServerHost. Same functionality is implemented using
FileEntry's in-flight Request objects.
* src/AbstractCommand.cc
* src/BtDependency.cc
* src/CreateRequestCommand.cc
* src/FileEntry.cc
* src/FileEntry.h
* src/FtpNegotiationCommand.cc
* src/HttpResponseCommand.cc
* src/Makefile.am
* src/Metalink2RequestGroup.cc
* src/RequestGroup.cc
* src/RequestGroup.h
* src/ServerHost.cc: Removed
* src/ServerHost.h: Removed
* test/BtDependencyTest.cc
* test/FileEntryTest.cc
* test/RequestGroupTest.cc
2009-06-30 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten PeerStat handling. In the previous implementation,

View File

@ -140,10 +140,6 @@ bool AbstractCommand::execute() {
Command* command =
InitiateConnectionCommandFactory::createInitiateConnectionCommand
(cuid, fasterRequest, _fileEntry, _requestGroup, e);
// TODO1.5 Here is ServerHost stuff
//ServerHostHandle sv(new ServerHost(command->getCuid(), req->getHost()));
//registerServerHost(sv);
e->setNoWait(true);
e->commands.push_back(command);
return true;
@ -248,7 +244,6 @@ bool AbstractCommand::execute() {
}
void AbstractCommand::tryReserved() {
_requestGroup->removeServerHost(cuid);
if(_requestGroup->getDownloadContext()->getFileEntries().size() == 1) {
const SharedHandle<FileEntry>& entry =
_requestGroup->getDownloadContext()->getFirstFileEntry();

View File

@ -80,12 +80,17 @@ bool BtDependency::resolve()
}
// Copy file path in _dependant's FileEntries to newly created
// context's FileEntries to endorse the path structure of
// _dependant.
// _dependant. URIs and singleHostMultiConnection are also copied.
for(std::vector<SharedHandle<FileEntry> >::const_iterator s =
_dependant->getDownloadContext()->getFileEntries().begin(),
d = context->getFileEntries().begin();
d != context->getFileEntries().end(); ++s, ++d) {
(*d)->setPath((*s)->getPath());
(*d)->addUris((*s)->getRemainingUris().begin(),
(*s)->getRemainingUris().end());
if(!(*s)->isSingleHostMultiConnectionEnabled()) {
(*d)->disableSingleHostMultiConnection();
}
}
} catch(RecoverableException& e) {
_logger->error(EX_EXCEPTION_CAUGHT, e);

View File

@ -75,8 +75,6 @@ bool CreateRequestCommand::executeInternal()
Command* command =
InitiateConnectionCommandFactory::createInitiateConnectionCommand
(cuid, req, _fileEntry, _requestGroup, e);
//ServerHostHandle sv(new ServerHost(command->getCuid(), req->getHost()));
//registerServerHost(sv);
e->setNoWait(true);
e->commands.push_back(command);
return true;

View File

@ -49,10 +49,12 @@ FileEntry::FileEntry(const std::string& path,
const std::deque<std::string>& uris):
path(path), _uris(uris), length(length), offset(offset),
extracted(false), requested(true),
_singleHostMultiConnection(true),
_logger(LogFactory::getInstance()) {}
FileEntry::FileEntry():
length(0), offset(0), extracted(false), requested(false),
_singleHostMultiConnection(true),
_logger(LogFactory::getInstance()) {}
FileEntry::~FileEntry() {}
@ -101,11 +103,26 @@ std::string FileEntry::selectUri(const SharedHandle<URISelector>& uriSelector)
return uriSelector->select(this);
}
template<typename InputIterator>
static bool inFlightHost(InputIterator first, InputIterator last,
const std::string& hostname)
{
// TODO1.5 redirection should be considered here. We need to parse
// original URI to get hostname.
for(; first != last; ++first) {
if((*first)->getHost() == hostname) {
return true;
}
}
return false;
}
SharedHandle<Request>
FileEntry::getRequest(const SharedHandle<URISelector>& selector)
{
SharedHandle<Request> req;
if(_requestPool.empty()) {
std::deque<std::string> pending;
while(1) {
std::string uri = selector->select(this);
if(uri.empty()) {
@ -113,19 +130,28 @@ FileEntry::getRequest(const SharedHandle<URISelector>& selector)
}
req.reset(new Request());
if(req->setUrl(uri)) {
if(!_singleHostMultiConnection) {
if(inFlightHost(_inFlightRequests.begin(), _inFlightRequests.end(),
req->getHost())) {
pending.push_back(uri);
req.reset();
continue;
}
}
_spentUris.push_back(uri);
_inFlightRequests.push_back(req);
return req;
break;
} else {
req.reset();
}
}
_uris.insert(_uris.begin(), pending.begin(), pending.end());
} else {
req = _requestPool.front();
_requestPool.pop_front();
_inFlightRequests.push_back(req);
return req;
}
return req;
}
SharedHandle<Request>

View File

@ -68,7 +68,7 @@ private:
// URIResult is stored in the ascending order of the time when its result is
// available.
std::deque<URIResult> _uriResults;
bool _singleHostMultiConnection;
Logger* _logger;
void storePool(const SharedHandle<Request>& request);
@ -142,6 +142,12 @@ public:
_uris = uris;
}
template<typename InputIterator>
void addUris(InputIterator first, InputIterator last)
{
_uris.insert(_uris.end(), first, last);
}
// Inserts _uris and _spentUris into uris.
void getUris(std::deque<std::string>& uris) const;
@ -201,6 +207,16 @@ public:
// The extracted URIResults are removed from _uriResults.
void extractURIResult
(std::deque<URIResult>& res, downloadresultcode::RESULT r);
void disableSingleHostMultiConnection()
{
_singleHostMultiConnection = false;
}
bool isSingleHostMultiConnectionEnabled() const
{
return _singleHostMultiConnection;
}
};
typedef SharedHandle<FileEntry> FileEntryHandle;

View File

@ -57,7 +57,6 @@
#include "DefaultBtProgressInfoFile.h"
#include "RequestGroupMan.h"
#include "DownloadFailureException.h"
#include "ServerHost.h"
#include "Socket.h"
#include "StringFormat.h"
#include "DiskAdaptor.h"
@ -103,12 +102,8 @@ bool FtpNegotiationCommand::executeInternal() {
(cuid, req, _fileEntry, _requestGroup, ftp, e, dataSocket, socket);
command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
command->setLowestDownloadSpeedLimit(getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
if(!_requestGroup->isSingleHostMultiConnectionEnabled()) {
SharedHandle<ServerHost> sv =
_requestGroup->searchServerHost(req->getHost());
if(!sv.isNull()) {
_fileEntry->removeURIWhoseHostnameIs(sv->getHostname());
}
if(!_fileEntry->isSingleHostMultiConnectionEnabled()) {
_fileEntry->removeURIWhoseHostnameIs(req->getHost());
}
_requestGroup->getURISelector()->tuneDownloadCommand
(_fileEntry->getRemainingUris(), command);

View File

@ -37,7 +37,6 @@
#include "DownloadContext.h"
#include "FileEntry.h"
#include "RequestGroup.h"
#include "ServerHost.h"
#include "RequestGroupMan.h"
#include "Request.h"
#include "HttpRequest.h"
@ -122,18 +121,10 @@ bool HttpResponseCommand::executeInternal()
}
return skipResponseBody(httpResponse);
}
if(!_requestGroup->isSingleHostMultiConnectionEnabled()) {
// Query by hostname. Searching by CUID may returns NULL. In case
// when resuming download, ServerHost is registered with CUID A.
// Then if requested range is not equal to saved one,
// StreamFileAllocationEntry is created with _nextCommand NULL.
// This results creating new command CUID, say B and same URI. So
// searching ServerHost by CUID B fails.
SharedHandle<ServerHost> sv =
_requestGroup->searchServerHost(req->getHost());
if(!sv.isNull()) {
_fileEntry->removeURIWhoseHostnameIs(sv->getHostname());
}
if(!_fileEntry->isSingleHostMultiConnectionEnabled()) {
// TODO1.5 redirection should be considered here. We need to parse
// original URI to get hostname.
_fileEntry->removeURIWhoseHostnameIs(req->getHost());
}
if(_requestGroup->getPieceStorage().isNull()) {
uint64_t totalLength = httpResponse->getEntityLength();

View File

@ -150,7 +150,6 @@ SRCS = Socket.h\
PeerConnection.cc PeerConnection.h\
ByteArrayDiskWriter.cc ByteArrayDiskWriter.h\
ByteArrayDiskWriterFactory.cc ByteArrayDiskWriterFactory.h\
ServerHost.cc ServerHost.h\
DownloadContext.cc DownloadContext.h\
TimedHaltCommand.cc TimedHaltCommand.h\
CUIDCounter.h\

View File

@ -398,27 +398,26 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
MultiFileAllocationIterator.cc MultiFileAllocationIterator.h \
PeerConnection.cc PeerConnection.h ByteArrayDiskWriter.cc \
ByteArrayDiskWriter.h ByteArrayDiskWriterFactory.cc \
ByteArrayDiskWriterFactory.h ServerHost.cc ServerHost.h \
DownloadContext.cc DownloadContext.h TimedHaltCommand.cc \
TimedHaltCommand.h CUIDCounter.h DNSCache.h DownloadResult.h \
Sequence.h IntSequence.h PostDownloadHandler.h \
PreDownloadHandler.h SingletonHolder.h \
TrueRequestGroupCriteria.h a2algo.h a2functional.h a2io.h \
a2netcompat.h a2time.h array_fun.h help_tags.h prefs.cc \
prefs.h usage_text.h ProtocolDetector.cc ProtocolDetector.h \
NullStatCalc.h StringFormat.cc StringFormat.h \
HttpSkipResponseCommand.cc HttpSkipResponseCommand.h \
InitiateConnectionCommand.cc InitiateConnectionCommand.h \
FtpFinishDownloadCommand.cc FtpFinishDownloadCommand.h \
A2STR.cc A2STR.h RarestPieceSelector.cc RarestPieceSelector.h \
Decoder.h ChunkedDecoder.cc ChunkedDecoder.h Signature.cc \
Signature.h ServerStat.cc ServerStat.h ServerStatMan.cc \
ServerStatMan.h URISelector.h AdaptiveURISelector.cc \
AdaptiveURISelector.h InOrderURISelector.cc \
InOrderURISelector.h FeedbackURISelector.cc \
FeedbackURISelector.h NsCookieParser.cc NsCookieParser.h \
CookieStorage.cc CookieStorage.h SocketBuffer.cc \
SocketBuffer.h OptionHandlerException.cc \
ByteArrayDiskWriterFactory.h DownloadContext.cc \
DownloadContext.h TimedHaltCommand.cc TimedHaltCommand.h \
CUIDCounter.h DNSCache.h DownloadResult.h Sequence.h \
IntSequence.h PostDownloadHandler.h PreDownloadHandler.h \
SingletonHolder.h TrueRequestGroupCriteria.h a2algo.h \
a2functional.h a2io.h a2netcompat.h a2time.h array_fun.h \
help_tags.h prefs.cc prefs.h usage_text.h ProtocolDetector.cc \
ProtocolDetector.h NullStatCalc.h StringFormat.cc \
StringFormat.h HttpSkipResponseCommand.cc \
HttpSkipResponseCommand.h InitiateConnectionCommand.cc \
InitiateConnectionCommand.h FtpFinishDownloadCommand.cc \
FtpFinishDownloadCommand.h A2STR.cc A2STR.h \
RarestPieceSelector.cc RarestPieceSelector.h Decoder.h \
ChunkedDecoder.cc ChunkedDecoder.h Signature.cc Signature.h \
ServerStat.cc ServerStat.h ServerStatMan.cc ServerStatMan.h \
URISelector.h AdaptiveURISelector.cc AdaptiveURISelector.h \
InOrderURISelector.cc InOrderURISelector.h \
FeedbackURISelector.cc FeedbackURISelector.h NsCookieParser.cc \
NsCookieParser.h CookieStorage.cc CookieStorage.h \
SocketBuffer.cc SocketBuffer.h OptionHandlerException.cc \
OptionHandlerException.h URIResult.cc URIResult.h EventPoll.h \
SelectEventPoll.cc SelectEventPoll.h SequentialPicker.h \
SequentialDispatcherCommand.h PieceSelector.h \
@ -830,10 +829,10 @@ am__objects_26 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
PeerSessionResource.$(OBJEXT) BtRegistry.$(OBJEXT) \
MultiFileAllocationIterator.$(OBJEXT) PeerConnection.$(OBJEXT) \
ByteArrayDiskWriter.$(OBJEXT) \
ByteArrayDiskWriterFactory.$(OBJEXT) ServerHost.$(OBJEXT) \
DownloadContext.$(OBJEXT) TimedHaltCommand.$(OBJEXT) \
prefs.$(OBJEXT) ProtocolDetector.$(OBJEXT) \
StringFormat.$(OBJEXT) HttpSkipResponseCommand.$(OBJEXT) \
ByteArrayDiskWriterFactory.$(OBJEXT) DownloadContext.$(OBJEXT) \
TimedHaltCommand.$(OBJEXT) prefs.$(OBJEXT) \
ProtocolDetector.$(OBJEXT) StringFormat.$(OBJEXT) \
HttpSkipResponseCommand.$(OBJEXT) \
InitiateConnectionCommand.$(OBJEXT) \
FtpFinishDownloadCommand.$(OBJEXT) A2STR.$(OBJEXT) \
RarestPieceSelector.$(OBJEXT) ChunkedDecoder.$(OBJEXT) \
@ -1153,27 +1152,26 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
MultiFileAllocationIterator.cc MultiFileAllocationIterator.h \
PeerConnection.cc PeerConnection.h ByteArrayDiskWriter.cc \
ByteArrayDiskWriter.h ByteArrayDiskWriterFactory.cc \
ByteArrayDiskWriterFactory.h ServerHost.cc ServerHost.h \
DownloadContext.cc DownloadContext.h TimedHaltCommand.cc \
TimedHaltCommand.h CUIDCounter.h DNSCache.h DownloadResult.h \
Sequence.h IntSequence.h PostDownloadHandler.h \
PreDownloadHandler.h SingletonHolder.h \
TrueRequestGroupCriteria.h a2algo.h a2functional.h a2io.h \
a2netcompat.h a2time.h array_fun.h help_tags.h prefs.cc \
prefs.h usage_text.h ProtocolDetector.cc ProtocolDetector.h \
NullStatCalc.h StringFormat.cc StringFormat.h \
HttpSkipResponseCommand.cc HttpSkipResponseCommand.h \
InitiateConnectionCommand.cc InitiateConnectionCommand.h \
FtpFinishDownloadCommand.cc FtpFinishDownloadCommand.h \
A2STR.cc A2STR.h RarestPieceSelector.cc RarestPieceSelector.h \
Decoder.h ChunkedDecoder.cc ChunkedDecoder.h Signature.cc \
Signature.h ServerStat.cc ServerStat.h ServerStatMan.cc \
ServerStatMan.h URISelector.h AdaptiveURISelector.cc \
AdaptiveURISelector.h InOrderURISelector.cc \
InOrderURISelector.h FeedbackURISelector.cc \
FeedbackURISelector.h NsCookieParser.cc NsCookieParser.h \
CookieStorage.cc CookieStorage.h SocketBuffer.cc \
SocketBuffer.h OptionHandlerException.cc \
ByteArrayDiskWriterFactory.h DownloadContext.cc \
DownloadContext.h TimedHaltCommand.cc TimedHaltCommand.h \
CUIDCounter.h DNSCache.h DownloadResult.h Sequence.h \
IntSequence.h PostDownloadHandler.h PreDownloadHandler.h \
SingletonHolder.h TrueRequestGroupCriteria.h a2algo.h \
a2functional.h a2io.h a2netcompat.h a2time.h array_fun.h \
help_tags.h prefs.cc prefs.h usage_text.h ProtocolDetector.cc \
ProtocolDetector.h NullStatCalc.h StringFormat.cc \
StringFormat.h HttpSkipResponseCommand.cc \
HttpSkipResponseCommand.h InitiateConnectionCommand.cc \
InitiateConnectionCommand.h FtpFinishDownloadCommand.cc \
FtpFinishDownloadCommand.h A2STR.cc A2STR.h \
RarestPieceSelector.cc RarestPieceSelector.h Decoder.h \
ChunkedDecoder.cc ChunkedDecoder.h Signature.cc Signature.h \
ServerStat.cc ServerStat.h ServerStatMan.cc ServerStatMan.h \
URISelector.h AdaptiveURISelector.cc AdaptiveURISelector.h \
InOrderURISelector.cc InOrderURISelector.h \
FeedbackURISelector.cc FeedbackURISelector.h NsCookieParser.cc \
NsCookieParser.h CookieStorage.cc CookieStorage.h \
SocketBuffer.cc SocketBuffer.h OptionHandlerException.cc \
OptionHandlerException.h URIResult.cc URIResult.h EventPoll.h \
SelectEventPoll.cc SelectEventPoll.h SequentialPicker.h \
SequentialDispatcherCommand.h PieceSelector.h \
@ -1527,7 +1525,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SeedCheckCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SegmentMan.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SelectEventPoll.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ServerHost.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ServerStat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ServerStatMan.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Signature.Po@am__quote@

View File

@ -217,6 +217,9 @@ Metalink2RequestGroup::createRequestGroup
strconcat(option->get(PREF_DIR), "/", entry->file->getPath())));
dctx->setDir(option->get(PREF_DIR));
dctx->getFirstFileEntry()->setUris(uris);
if(option->getAsBool(PREF_METALINK_ENABLE_UNIQUE_PROTOCOL)) {
dctx->getFirstFileEntry()->disableSingleHostMultiConnection();
}
#ifdef ENABLE_MESSAGE_DIGEST
if(entry->chunkChecksum.isNull()) {
if(!entry->checksum.isNull()) {
@ -236,8 +239,6 @@ Metalink2RequestGroup::createRequestGroup
option->getAsInt(PREF_METALINK_SERVERS) :
std::min(option->getAsInt(PREF_METALINK_SERVERS),
static_cast<int32_t>(entry->maxConnections)));
// In metalink, multi connection to a single host is not allowed by default.
rg->setSingleHostMultiConnectionEnabled(!option->getAsBool(PREF_METALINK_ENABLE_UNIQUE_PROTOCOL));
// remove "metalink" from Accept Type list to avoid loop in tranparent
// metalink
rg->removeAcceptType(RequestGroup::ACCEPT_METALINK);

View File

@ -65,7 +65,6 @@
#include "DownloadHandlerFactory.h"
#include "MemoryBufferPreDownloadHandler.h"
#include "DownloadHandlerConstants.h"
#include "ServerHost.h"
#include "Option.h"
#include "FileEntry.h"
#include "Request.h"
@ -124,7 +123,6 @@ RequestGroup::RequestGroup(const SharedHandle<Option>& option):
_haltRequested(false),
_forceHaltRequested(false),
_haltReason(RequestGroup::NONE),
_singleHostMultiConnectionEnabled(true),
_uriSelector(new InOrderURISelector()),
_lastModifiedTime(Time::null()),
_fileNotFoundCount(0),
@ -641,41 +639,7 @@ void RequestGroup::createNextCommand(std::deque<Command*>& commands,
Command* command = new CreateRequestCommand(e->newCUID(), this, e);
_logger->debug("filePath=%s", _downloadContext->getFileEntries().front()->getPath().c_str());
commands.push_back(command);
// TODO1.5 ServerHost stuff should be moved into FileEntry or
// CreateRequestCommand
// std::string uri = _uriSelector->select(_uris);
// if(uri.empty())
// continue;
// RequestHandle req(new Request());
// if(req->setUrl(uri)) {
// ServerHostHandle sv;
// if(!_singleHostMultiConnectionEnabled){
// sv = searchServerHost(req->getHost());
// }
// if(sv.isNull()) {
// _spentUris.push_back(uri);
// req->setReferer(_option->get(PREF_REFERER));
// req->setMethod(method);
// Command* command =
// InitiateConnectionCommandFactory::createInitiateConnectionCommand
// (e->newCUID(), req, this, e);
// ServerHostHandle sv(new ServerHost(command->getCuid(), req->getHost()));
// registerServerHost(sv);
// // give a chance to be executed in the next loop in DownloadEngine
// command->setStatus(Command::STATUS_ONESHOT_REALTIME);
// commands.push_back(command);
// } else {
// pendingURIs.push_back(uri);
// }
// } else {
// _logger->error(MSG_UNRECOGNIZED_URI, req->getUrl().c_str());
// }
// }
}
// _uris.insert(_uris.begin(), pendingURIs.begin(), pendingURIs.end());
if(!commands.empty()) {
e->setNoWait(true);
}
@ -1005,64 +969,6 @@ DownloadResultHandle RequestGroup::createDownloadResult() const
_downloadContext->calculateSessionTime(),
downloadResult()));
}
void RequestGroup::registerServerHost(const ServerHostHandle& serverHost)
{
_serverHosts.push_back(serverHost);
}
class FindServerHostByCUID
{
private:
int32_t _cuid;
public:
FindServerHostByCUID(int32_t cuid):_cuid(cuid) {}
bool operator()(const ServerHostHandle& sv) const
{
return sv->getCuid() == _cuid;
}
};
ServerHostHandle RequestGroup::searchServerHost(int32_t cuid) const
{
std::deque<SharedHandle<ServerHost> >::const_iterator itr =
std::find_if(_serverHosts.begin(), _serverHosts.end(), FindServerHostByCUID(cuid));
if(itr == _serverHosts.end()) {
return SharedHandle<ServerHost>();
} else {
return *itr;
}
}
class FindServerHostByHostname
{
private:
std::string _hostname;
public:
FindServerHostByHostname(const std::string& hostname):_hostname(hostname) {}
bool operator()(const ServerHostHandle& sv) const
{
return sv->getHostname() == _hostname;
}
};
ServerHostHandle RequestGroup::searchServerHost(const std::string& hostname) const
{
std::deque<SharedHandle<ServerHost> >::const_iterator itr =
std::find_if(_serverHosts.begin(), _serverHosts.end(), FindServerHostByHostname(hostname));
if(itr == _serverHosts.end()) {
return SharedHandle<ServerHost>();
} else {
return *itr;
}
}
void RequestGroup::removeServerHost(int32_t cuid)
{
_serverHosts.erase(std::remove_if(_serverHosts.begin(), _serverHosts.end(), FindServerHostByCUID(cuid)), _serverHosts.end());
}
void RequestGroup::reportDownloadFinished()
{

View File

@ -65,7 +65,6 @@ class Logger;
class RequestGroup;
class CheckIntegrityEntry;
class DownloadResult;
class ServerHost;
class URISelector;
class URIResult;
#ifdef ENABLE_BITTORRENT
@ -109,8 +108,6 @@ private:
SharedHandle<Dependency> _dependency;
std::deque<SharedHandle<ServerHost> > _serverHosts;
bool _fileAllocationEnabled;
bool _preLocalFileCheckEnabled;
@ -121,8 +118,6 @@ private:
HaltReason _haltReason;
bool _singleHostMultiConnectionEnabled;
std::deque<SharedHandle<PreDownloadHandler> > _preDownloadHandlers;
std::deque<SharedHandle<PostDownloadHandler> > _postDownloadHandlers;
@ -377,31 +372,6 @@ public:
return _option;
}
bool isSingleHostMultiConnectionEnabled() const
{
return _singleHostMultiConnectionEnabled;
}
void setSingleHostMultiConnectionEnabled(bool f)
{
_singleHostMultiConnectionEnabled = f;
}
/**
* Registers given ServerHost.
*/
void registerServerHost(const SharedHandle<ServerHost>& serverHost);
/**
* Returns ServerHost whose cuid is given cuid. If it is not found, returns
* 0.
*/
SharedHandle<ServerHost> searchServerHost(int32_t cuid) const;
SharedHandle<ServerHost> searchServerHost(const std::string& hostname) const;
void removeServerHost(int32_t cuid);
void reportDownloadFinished();
const std::deque<std::string>& getAcceptTypes() const

View File

@ -1,44 +0,0 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2006 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 --> */
#include "ServerHost.h"
namespace aria2 {
ServerHost::ServerHost(int32_t cuid, const std::string& hostname):
_cuid(cuid), _hostname(hostname) {}
ServerHost::~ServerHost() {}
} // namespace aria2

View File

@ -1,75 +0,0 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2006 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_SERVER_HOST_H_
#define _D_SERVER_HOST_H_
#include "common.h"
#include "SharedHandle.h"
#include <string>
namespace aria2 {
class ServerHost {
private:
int32_t _cuid;
std::string _hostname;
public:
ServerHost(int32_t cuid, const std::string& hostname);
~ServerHost();
int32_t getCuid() const
{
return _cuid;
}
const std::string& getHostname() const
{
return _hostname;
}
bool operator<(const ServerHost& server) const
{
return this->_cuid < server._cuid;
}
};
typedef SharedHandle<ServerHost> ServerHostHandle;
} // namespace aria2
#endif // _D_SERVER_HOST_H_

View File

@ -31,6 +31,9 @@ class BtDependencyTest:public CppUnit::TestFixture {
SharedHandle<DownloadContext> dctx
(new DownloadContext(0, 0, "/tmp/outfile.path"));
dctx->setDir("/tmp");
std::deque<std::string> uris;
uris.push_back("http://localhost/outfile.path");
dctx->getFirstFileEntry()->setUris(uris);
dependant->setDownloadContext(dctx);
return dependant;
}
@ -83,8 +86,11 @@ void BtDependencyTest::testResolve()
CPPUNIT_ASSERT_EQUAL
(std::string("cd41c7fdddfd034a15a04d7ff881216e01c4ceaf"),
bittorrent::getInfoHashString(dependant->getDownloadContext()));
const SharedHandle<FileEntry>& firstFileEntry =
dependant->getDownloadContext()->getFirstFileEntry();
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/outfile.path"),
dependant->getFirstFilePath());
firstFileEntry->getPath());
CPPUNIT_ASSERT_EQUAL((size_t)1, firstFileEntry->getRemainingUris().size());
}
void BtDependencyTest::testResolve_loadError()

View File

@ -1,6 +1,9 @@
#include "FileEntry.h"
#include <cppunit/extensions/HelperMacros.h>
#include "InOrderURISelector.h"
namespace aria2 {
class FileEntryTest : public CppUnit::TestFixture {
@ -9,6 +12,8 @@ class FileEntryTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testSetupDir);
CPPUNIT_TEST(testRemoveURIWhoseHostnameIs);
CPPUNIT_TEST(testExtractURIResult);
CPPUNIT_TEST(testGetRequest);
CPPUNIT_TEST(testGetRequest_disableSingleHostMultiConnection);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
@ -16,11 +21,23 @@ public:
void testSetupDir();
void testRemoveURIWhoseHostnameIs();
void testExtractURIResult();
void testGetRequest();
void testGetRequest_disableSingleHostMultiConnection();
};
CPPUNIT_TEST_SUITE_REGISTRATION( FileEntryTest );
static SharedHandle<FileEntry> createFileEntry()
{
const char* uris[] = { "http://localhost/aria2.zip",
"ftp://localhost/aria2.zip",
"http://mirror/aria2.zip" };
SharedHandle<FileEntry> fileEntry(new FileEntry());
fileEntry->setUris(std::deque<std::string>(&uris[0], &uris[3]));
return fileEntry;
}
void FileEntryTest::testSetupDir()
{
std::string dir = "/tmp/aria2-FileEntryTest-testSetupDir";
@ -40,15 +57,11 @@ void FileEntryTest::testSetupDir()
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());
SharedHandle<FileEntry> fileEntry = createFileEntry();
fileEntry->removeURIWhoseHostnameIs("localhost");
CPPUNIT_ASSERT_EQUAL((size_t)1, fileEntry->getRemainingUris().size());
CPPUNIT_ASSERT_EQUAL(std::string("http://mirror/aria2.zip"),
fileEntry.getRemainingUris()[0]);
fileEntry->getRemainingUris()[0]);
}
@ -79,4 +92,40 @@ void FileEntryTest::testExtractURIResult()
CPPUNIT_ASSERT_EQUAL((size_t)2, fileEntry.getURIResults().size());
}
void FileEntryTest::testGetRequest()
{
SharedHandle<FileEntry> fileEntry = createFileEntry();
SharedHandle<InOrderURISelector> selector(new InOrderURISelector());
SharedHandle<Request> req = fileEntry->getRequest(selector);
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req->getHost());
CPPUNIT_ASSERT_EQUAL(std::string("http"), req->getProtocol());
fileEntry->poolRequest(req);
SharedHandle<Request> req2nd = fileEntry->getRequest(selector);
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req2nd->getHost());
CPPUNIT_ASSERT_EQUAL(std::string("http"), req2nd->getProtocol());
SharedHandle<Request> req3rd = fileEntry->getRequest(selector);
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req3rd->getHost());
CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req3rd->getProtocol());
}
void FileEntryTest::testGetRequest_disableSingleHostMultiConnection()
{
SharedHandle<FileEntry> fileEntry = createFileEntry();
fileEntry->disableSingleHostMultiConnection();
SharedHandle<InOrderURISelector> selector(new InOrderURISelector());
SharedHandle<Request> req = fileEntry->getRequest(selector);
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req->getHost());
CPPUNIT_ASSERT_EQUAL(std::string("http"), req->getProtocol());
SharedHandle<Request> req2nd = fileEntry->getRequest(selector);
CPPUNIT_ASSERT_EQUAL(std::string("mirror"), req2nd->getHost());
CPPUNIT_ASSERT_EQUAL(std::string("http"), req2nd->getProtocol());
SharedHandle<Request> req3rd = fileEntry->getRequest(selector);
CPPUNIT_ASSERT(req3rd.isNull());
}
} // namespace aria2

View File

@ -2,7 +2,6 @@
#include <cppunit/extensions/HelperMacros.h>
#include "ServerHost.h"
#include "Option.h"
#include "DownloadContext.h"
#include "FileEntry.h"
@ -14,7 +13,6 @@ namespace aria2 {
class RequestGroupTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(RequestGroupTest);
CPPUNIT_TEST(testRegisterSearchRemove);
CPPUNIT_TEST(testGetFirstFilePath);
CPPUNIT_TEST(testCreateDownloadResult);
CPPUNIT_TEST_SUITE_END();
@ -26,7 +24,6 @@ public:
_option.reset(new Option());
}
void testRegisterSearchRemove();
void testGetFirstFilePath();
void testCreateDownloadResult();
};
@ -34,38 +31,6 @@ public:
CPPUNIT_TEST_SUITE_REGISTRATION( RequestGroupTest );
void RequestGroupTest::testRegisterSearchRemove()
{
RequestGroup rg(_option);
SharedHandle<ServerHost> sv1(new ServerHost(1, "localhost1"));
SharedHandle<ServerHost> sv2(new ServerHost(2, "localhost2"));
SharedHandle<ServerHost> sv3(new ServerHost(3, "localhost3"));
rg.registerServerHost(sv3);
rg.registerServerHost(sv1);
rg.registerServerHost(sv2);
CPPUNIT_ASSERT(rg.searchServerHost(0).isNull());
{
SharedHandle<ServerHost> sv = rg.searchServerHost(1);
CPPUNIT_ASSERT(!sv.isNull());
CPPUNIT_ASSERT_EQUAL(std::string("localhost1"), sv->getHostname());
}
rg.removeServerHost(1);
{
SharedHandle<ServerHost> sv = rg.searchServerHost(1);
CPPUNIT_ASSERT(sv.isNull());
}
{
SharedHandle<ServerHost> sv = rg.searchServerHost(2);
CPPUNIT_ASSERT(!sv.isNull());
CPPUNIT_ASSERT_EQUAL(std::string("localhost2"), sv->getHostname());
}
}
void RequestGroupTest::testGetFirstFilePath()
{
SharedHandle<DownloadContext> ctx