mirror of https://github.com/aria2/aria2
2010-06-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Made protected member variables of Command private. Added accessor funcs.pull/1/head
parent
7cd9b21937
commit
9afc36152a
|
@ -1,3 +1,8 @@
|
|||
2010-06-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Made protected member variables of Command private. Added accessor
|
||||
funcs.
|
||||
|
||||
2010-06-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Made public member variables of DownloadEngine private. Added
|
||||
|
|
|
@ -101,20 +101,23 @@ AbstractCommand::~AbstractCommand() {
|
|||
}
|
||||
|
||||
bool AbstractCommand::execute() {
|
||||
if(logger->debug()) {
|
||||
logger->debug("CUID#%s - socket: read:%d, write:%d, hup:%d, err:%d",
|
||||
util::itos(cuid).c_str(), _readEvent, _writeEvent, _hupEvent,
|
||||
_errorEvent);
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - socket: read:%d, write:%d, hup:%d, err:%d",
|
||||
util::itos(getCuid()).c_str(),
|
||||
readEventEnabled(),
|
||||
writeEventEnabled(),
|
||||
hupEventEnabled(),
|
||||
errorEventEnabled());
|
||||
}
|
||||
try {
|
||||
if(_requestGroup->downloadFinished() || _requestGroup->isHaltRequested()) {
|
||||
return true;
|
||||
}
|
||||
if(!req.isNull() && req->removalRequested()) {
|
||||
if(logger->debug()) {
|
||||
logger->debug
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug
|
||||
("CUID#%s - Discard original URI=%s because it is requested.",
|
||||
util::itos(cuid).c_str(), req->getUri().c_str());
|
||||
util::itos(getCuid()).c_str(), req->getUri().c_str());
|
||||
}
|
||||
return prepareForRetry(0);
|
||||
}
|
||||
|
@ -124,9 +127,9 @@ bool AbstractCommand::execute() {
|
|||
!_requestGroup->getPieceStorage()->hasMissingUnusedPiece()) {
|
||||
SharedHandle<Request> fasterRequest = _fileEntry->findFasterRequest(req);
|
||||
if(!fasterRequest.isNull()) {
|
||||
if(logger->info()) {
|
||||
logger->info("CUID#%s - Use faster Request hostname=%s, port=%u",
|
||||
util::itos(cuid).c_str(),
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info("CUID#%s - Use faster Request hostname=%s, port=%u",
|
||||
util::itos(getCuid()).c_str(),
|
||||
fasterRequest->getHost().c_str(),
|
||||
fasterRequest->getPort());
|
||||
}
|
||||
|
@ -134,29 +137,32 @@ bool AbstractCommand::execute() {
|
|||
_fileEntry->removeRequest(req);
|
||||
Command* command =
|
||||
InitiateConnectionCommandFactory::createInitiateConnectionCommand
|
||||
(cuid, fasterRequest, _fileEntry, _requestGroup, e);
|
||||
(getCuid(), fasterRequest, _fileEntry, _requestGroup, e);
|
||||
e->setNoWait(true);
|
||||
e->addCommand(command);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if((checkSocketIsReadable && _readEvent) ||
|
||||
(checkSocketIsWritable && _writeEvent) ||
|
||||
_hupEvent ||
|
||||
if((checkSocketIsReadable && readEventEnabled()) ||
|
||||
(checkSocketIsWritable && writeEventEnabled()) ||
|
||||
hupEventEnabled() ||
|
||||
#ifdef ENABLE_ASYNC_DNS
|
||||
(nameResolverCheck && nameResolveFinished()) ||
|
||||
#endif // ENABLE_ASYNC_DNS
|
||||
(!checkSocketIsReadable && !checkSocketIsWritable && !nameResolverCheck)) {
|
||||
(!checkSocketIsReadable && !checkSocketIsWritable &&
|
||||
!nameResolverCheck)) {
|
||||
checkPoint = global::wallclock;
|
||||
if(!_requestGroup->getPieceStorage().isNull()) {
|
||||
_segments.clear();
|
||||
_requestGroup->getSegmentMan()->getInFlightSegment(_segments, cuid);
|
||||
_requestGroup->getSegmentMan()->getInFlightSegment
|
||||
(_segments, getCuid());
|
||||
if(!req.isNull() && _segments.empty()) {
|
||||
// This command previously has assigned segments, but it is
|
||||
// canceled. So discard current request chain.
|
||||
if(logger->debug()) {
|
||||
logger->debug("CUID#%s - It seems previously assigned segments are"
|
||||
" canceled. Restart.", util::itos(cuid).c_str());
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - It seems previously assigned segments"
|
||||
" are canceled. Restart.",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
return prepareForRetry(0);
|
||||
}
|
||||
|
@ -164,21 +170,22 @@ bool AbstractCommand::execute() {
|
|||
_requestGroup->getDownloadContext()->getFileEntries().size() == 1) {
|
||||
if(_segments.empty()) {
|
||||
SharedHandle<Segment> segment =
|
||||
_requestGroup->getSegmentMan()->getSegment(cuid);
|
||||
_requestGroup->getSegmentMan()->getSegment(getCuid());
|
||||
if(!segment.isNull()) {
|
||||
_segments.push_back(segment);
|
||||
}
|
||||
}
|
||||
if(_segments.empty()) {
|
||||
// TODO socket could be pooled here if pipelining is enabled...
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_NO_SEGMENT_AVAILABLE, util::itos(cuid).c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_NO_SEGMENT_AVAILABLE,
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
// When all segments are ignored in SegmentMan, there are
|
||||
// no URIs available, so don't retry.
|
||||
if(_requestGroup->getSegmentMan()->allSegmentsIgnored()) {
|
||||
if(logger->debug()) {
|
||||
logger->debug("All segments are ignored.");
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("All segments are ignored.");
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
|
@ -189,7 +196,7 @@ bool AbstractCommand::execute() {
|
|||
size_t maxSegments = req->getMaxPipelinedRequest();
|
||||
if(_segments.size() < maxSegments) {
|
||||
_requestGroup->getSegmentMan()->getSegment
|
||||
(_segments, cuid, _fileEntry, maxSegments);
|
||||
(_segments, getCuid(), _fileEntry, maxSegments);
|
||||
}
|
||||
if(_segments.empty()) {
|
||||
return prepareForRetry(0);
|
||||
|
@ -197,7 +204,7 @@ bool AbstractCommand::execute() {
|
|||
}
|
||||
}
|
||||
return executeInternal();
|
||||
} else if(_errorEvent) {
|
||||
} else if(errorEventEnabled()) {
|
||||
throw DL_RETRY_EX
|
||||
(StringFormat(MSG_NETWORK_PROBLEM,
|
||||
socket->getSocketError().c_str()).str());
|
||||
|
@ -217,14 +224,15 @@ bool AbstractCommand::execute() {
|
|||
}
|
||||
} catch(DlAbortEx& err) {
|
||||
if(req.isNull()) {
|
||||
if(logger->debug()) {
|
||||
logger->debug(EX_EXCEPTION_CAUGHT, err);
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug(EX_EXCEPTION_CAUGHT, err);
|
||||
}
|
||||
} else {
|
||||
logger->error(MSG_DOWNLOAD_ABORTED,
|
||||
getLogger()->error
|
||||
(MSG_DOWNLOAD_ABORTED,
|
||||
DL_ABORT_EX2(StringFormat
|
||||
("URI=%s", req->getCurrentUri().c_str()).str(),err),
|
||||
util::itos(cuid).c_str(), req->getUri().c_str());
|
||||
util::itos(getCuid()).c_str(), req->getUri().c_str());
|
||||
_fileEntry->addURIResult(req->getUri(), err.getCode());
|
||||
_requestGroup->setLastUriResult(req->getUri(), err.getCode());
|
||||
if(err.getCode() == downloadresultcode::CANNOT_RESUME) {
|
||||
|
@ -236,22 +244,25 @@ bool AbstractCommand::execute() {
|
|||
return true;
|
||||
} catch(DlRetryEx& err) {
|
||||
assert(!req.isNull());
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_RESTARTING_DOWNLOAD,
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info
|
||||
(MSG_RESTARTING_DOWNLOAD,
|
||||
DL_RETRY_EX2(StringFormat
|
||||
("URI=%s", req->getCurrentUri().c_str()).str(),
|
||||
err),
|
||||
util::itos(cuid).c_str(), req->getUri().c_str());
|
||||
util::itos(getCuid()).c_str(), req->getUri().c_str());
|
||||
}
|
||||
req->addTryCount();
|
||||
req->resetRedirectCount();
|
||||
const unsigned int maxTries = getOption()->getAsInt(PREF_MAX_TRIES);
|
||||
bool isAbort = maxTries != 0 && req->getTryCount() >= maxTries;
|
||||
if(isAbort) {
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_MAX_TRY, util::itos(cuid).c_str(), req->getTryCount());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_MAX_TRY,
|
||||
util::itos(getCuid()).c_str(), req->getTryCount());
|
||||
}
|
||||
logger->error(MSG_DOWNLOAD_ABORTED, err, util::itos(cuid).c_str(),
|
||||
getLogger()->error(MSG_DOWNLOAD_ABORTED, err,
|
||||
util::itos(getCuid()).c_str(),
|
||||
req->getUri().c_str());
|
||||
_fileEntry->addURIResult(req->getUri(), err.getCode());
|
||||
_requestGroup->setLastUriResult(req->getUri(), err.getCode());
|
||||
|
@ -265,7 +276,7 @@ bool AbstractCommand::execute() {
|
|||
return prepareForRetry(0);
|
||||
}
|
||||
} catch(DownloadFailureException& err) {
|
||||
logger->error(EX_EXCEPTION_CAUGHT, err);
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, err);
|
||||
if(!req.isNull()) {
|
||||
_fileEntry->addURIResult(req->getUri(), err.getCode());
|
||||
_requestGroup->setLastUriResult(req->getUri(), err.getCode());
|
||||
|
@ -283,18 +294,18 @@ void AbstractCommand::tryReserved() {
|
|||
// and there are no URI left. Because file length is unknown, we
|
||||
// can assume that there are no in-flight request object.
|
||||
if(entry->getLength() == 0 && entry->getRemainingUris().empty()) {
|
||||
if(logger->debug()) {
|
||||
logger->debug("CUID#%s - Not trying next request."
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Not trying next request."
|
||||
" No reserved/pooled request is remaining and"
|
||||
" total length is still unknown.",
|
||||
util::itos(cuid).c_str());
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(logger->debug()) {
|
||||
logger->debug("CUID#%s - Trying reserved/pooled request.",
|
||||
util::itos(cuid).c_str());
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Trying reserved/pooled request.",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
std::vector<Command*> commands;
|
||||
_requestGroup->createNextCommand(commands, e, 1);
|
||||
|
@ -304,25 +315,25 @@ void AbstractCommand::tryReserved() {
|
|||
|
||||
bool AbstractCommand::prepareForRetry(time_t wait) {
|
||||
if(!_requestGroup->getPieceStorage().isNull()) {
|
||||
_requestGroup->getSegmentMan()->cancelSegment(cuid);
|
||||
_requestGroup->getSegmentMan()->cancelSegment(getCuid());
|
||||
}
|
||||
if(!req.isNull()) {
|
||||
_fileEntry->poolRequest(req);
|
||||
if(logger->debug()) {
|
||||
logger->debug("CUID#%s - Pooling request URI=%s",
|
||||
util::itos(cuid).c_str(), req->getUri().c_str());
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Pooling request URI=%s",
|
||||
util::itos(getCuid()).c_str(), req->getUri().c_str());
|
||||
}
|
||||
if(!_requestGroup->getSegmentMan().isNull()) {
|
||||
_requestGroup->getSegmentMan()->recognizeSegmentFor(_fileEntry);
|
||||
}
|
||||
}
|
||||
|
||||
Command* command = new CreateRequestCommand(cuid, _requestGroup, e);
|
||||
Command* command = new CreateRequestCommand(getCuid(), _requestGroup, e);
|
||||
if(wait == 0) {
|
||||
e->setNoWait(true);
|
||||
e->addCommand(command);
|
||||
} else {
|
||||
SleepCommand* scom = new SleepCommand(cuid, e, _requestGroup,
|
||||
SleepCommand* scom = new SleepCommand(getCuid(), e, _requestGroup,
|
||||
command, wait);
|
||||
e->addCommand(scom);
|
||||
}
|
||||
|
@ -332,17 +343,18 @@ bool AbstractCommand::prepareForRetry(time_t wait) {
|
|||
void AbstractCommand::onAbort() {
|
||||
if(!req.isNull()) {
|
||||
// TODO This might be a problem if the failure is caused by proxy.
|
||||
e->getRequestGroupMan()->getOrCreateServerStat(req->getHost(),
|
||||
req->getProtocol())->setError();
|
||||
e->getRequestGroupMan()->getOrCreateServerStat
|
||||
(req->getHost(), req->getProtocol())->setError();
|
||||
_fileEntry->removeIdenticalURI(req->getUri());
|
||||
_fileEntry->removeRequest(req);
|
||||
}
|
||||
if(logger->debug()) {
|
||||
logger->debug("CUID#%s - Aborting download", util::itos(cuid).c_str());
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Aborting download",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
if(!_requestGroup->getPieceStorage().isNull()) {
|
||||
SharedHandle<SegmentMan> segmentMan = _requestGroup->getSegmentMan();
|
||||
segmentMan->cancelSegment(cuid);
|
||||
segmentMan->cancelSegment(getCuid());
|
||||
// Don't do following process if BitTorrent is involved or files
|
||||
// in DownloadContext is more than 1. The latter condition is
|
||||
// limitation of current implementation.
|
||||
|
@ -357,12 +369,13 @@ void AbstractCommand::onAbort() {
|
|||
// Local file exists, but given servers(or at least contacted
|
||||
// ones) doesn't support resume. Let's restart download from
|
||||
// scratch.
|
||||
logger->notice("CUID#%s - Failed to resume download."
|
||||
getLogger()->notice("CUID#%s - Failed to resume download."
|
||||
" Download from scratch.",
|
||||
util::itos(cuid).c_str());
|
||||
if(logger->debug()) {
|
||||
logger->debug("CUID#%s - Gathering URIs that has CANNOT_RESUME error",
|
||||
util::itos(cuid).c_str());
|
||||
util::itos(getCuid()).c_str());
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug
|
||||
("CUID#%s - Gathering URIs that has CANNOT_RESUME error",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
// Set PREF_ALWAYS_RESUME to V_TRUE to avoid repeating this
|
||||
// process.
|
||||
|
@ -377,9 +390,9 @@ void AbstractCommand::onAbort() {
|
|||
uris.reserve(res.size());
|
||||
std::transform(res.begin(), res.end(), std::back_inserter(uris),
|
||||
std::mem_fun_ref(&URIResult::getURI));
|
||||
if(logger->debug()) {
|
||||
logger->debug("CUID#%s - %lu URIs found.",
|
||||
util::itos(cuid).c_str(),
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - %lu URIs found.",
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long int>(uris.size()));
|
||||
}
|
||||
_fileEntry->addUris(uris.begin(), uris.end());
|
||||
|
@ -571,13 +584,14 @@ SharedHandle<Request> AbstractCommand::createProxyRequest() const
|
|||
if(!proxy.empty()) {
|
||||
proxyRequest.reset(new Request());
|
||||
if(proxyRequest->setUri(proxy)) {
|
||||
if(logger->debug()) {
|
||||
logger->debug("CUID#%s - Using proxy", util::itos(cuid).c_str());
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Using proxy",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
} else {
|
||||
if(logger->debug()) {
|
||||
logger->debug("CUID#%s - Failed to parse proxy string",
|
||||
util::itos(cuid).c_str());
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Failed to parse proxy string",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
proxyRequest.reset();
|
||||
}
|
||||
|
@ -595,9 +609,9 @@ bool AbstractCommand::isAsyncNameResolverInitialized() const
|
|||
void AbstractCommand::initAsyncNameResolver(const std::string& hostname)
|
||||
{
|
||||
_asyncNameResolver.reset(new AsyncNameResolver());
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_RESOLVING_HOSTNAME,
|
||||
util::itos(cuid).c_str(), hostname.c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_RESOLVING_HOSTNAME,
|
||||
util::itos(getCuid()).c_str(), hostname.c_str());
|
||||
}
|
||||
_asyncNameResolver->resolve(hostname);
|
||||
setNameResolverCheck(_asyncNameResolver);
|
||||
|
@ -615,8 +629,9 @@ bool AbstractCommand::asyncResolveHostname()
|
|||
e->getRequestGroupMan()->getOrCreateServerStat
|
||||
(req->getHost(), req->getProtocol())->setError();
|
||||
}
|
||||
throw DL_ABORT_EX(StringFormat(MSG_NAME_RESOLUTION_FAILED,
|
||||
util::itos(cuid).c_str(),
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat(MSG_NAME_RESOLUTION_FAILED,
|
||||
util::itos(getCuid()).c_str(),
|
||||
_asyncNameResolver->getHostname().c_str(),
|
||||
_asyncNameResolver->getError().c_str()).str());
|
||||
default:
|
||||
|
@ -678,8 +693,9 @@ std::string AbstractCommand::resolveHostname
|
|||
}
|
||||
res.resolve(addrs, hostname);
|
||||
}
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_NAME_RESOLUTION_COMPLETE, util::itos(cuid).c_str(),
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_NAME_RESOLUTION_COMPLETE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
hostname.c_str(),
|
||||
strjoin(addrs.begin(), addrs.end(), ", ").c_str());
|
||||
}
|
||||
|
@ -690,9 +706,9 @@ std::string AbstractCommand::resolveHostname
|
|||
ipaddr = e->findCachedIPAddress(hostname, port);
|
||||
} else {
|
||||
ipaddr = addrs.front();
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_DNS_CACHE_HIT,
|
||||
util::itos(cuid).c_str(), hostname.c_str(),
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_DNS_CACHE_HIT,
|
||||
util::itos(getCuid()).c_str(), hostname.c_str(),
|
||||
strjoin(addrs.begin(), addrs.end(), ", ").c_str());
|
||||
}
|
||||
}
|
||||
|
@ -730,14 +746,14 @@ bool AbstractCommand::checkIfConnectionEstablished
|
|||
// See also InitiateConnectionCommand::executeInternal()
|
||||
e->markBadIPAddress(connectedHostname, connectedAddr, connectedPort);
|
||||
if(!e->findCachedIPAddress(connectedHostname, connectedPort).empty()) {
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_CONNECT_FAILED_AND_RETRY,
|
||||
util::itos(cuid).c_str(),
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_CONNECT_FAILED_AND_RETRY,
|
||||
util::itos(getCuid()).c_str(),
|
||||
connectedAddr.c_str(), connectedPort);
|
||||
}
|
||||
Command* command =
|
||||
InitiateConnectionCommandFactory::createInitiateConnectionCommand
|
||||
(cuid, req, _fileEntry, _requestGroup, e);
|
||||
(getCuid(), req, _fileEntry, _requestGroup, e);
|
||||
e->setNoWait(true);
|
||||
e->addCommand(command);
|
||||
return false;
|
||||
|
|
|
@ -145,9 +145,9 @@ void ActivePeerConnectionCommand::connectToPeer(const SharedHandle<Peer>& peer)
|
|||
command->setPeerStorage(_peerStorage);
|
||||
command->setPieceStorage(_pieceStorage);
|
||||
e->addCommand(command);
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_CONNECTING_TO_PEER,
|
||||
util::itos(cuid).c_str(), peer->ipaddr.c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_CONNECTING_TO_PEER,
|
||||
util::itos(getCuid()).c_str(), peer->ipaddr.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ void BtStopDownloadCommand::preProcess()
|
|||
_exit = true;
|
||||
}
|
||||
if(_checkPoint.difference(global::wallclock) >= _timeout) {
|
||||
logger->notice("GID#%s Stop downloading torrent due to"
|
||||
getLogger()->notice("GID#%s Stop downloading torrent due to"
|
||||
" --bt-stop-timeout option.",
|
||||
util::itos(_requestGroup->getGID()).c_str());
|
||||
_requestGroup->setHaltRequested(true);
|
||||
|
|
|
@ -72,7 +72,8 @@ bool CheckIntegrityCommand::executeInternal()
|
|||
// needed.
|
||||
_requestGroup->enableSaveControlFile();
|
||||
if(_requestGroup->downloadFinished()) {
|
||||
logger->notice(MSG_VERIFICATION_SUCCESSFUL,
|
||||
getLogger()->notice
|
||||
(MSG_VERIFICATION_SUCCESSFUL,
|
||||
_requestGroup->getDownloadContext()->getBasePath().c_str());
|
||||
std::vector<Command*> commands;
|
||||
try {
|
||||
|
@ -83,7 +84,8 @@ bool CheckIntegrityCommand::executeInternal()
|
|||
}
|
||||
_e->addCommand(commands);
|
||||
} else {
|
||||
logger->error(MSG_VERIFICATION_FAILED,
|
||||
getLogger()->error
|
||||
(MSG_VERIFICATION_FAILED,
|
||||
_requestGroup->getDownloadContext()->getBasePath().c_str());
|
||||
std::vector<Command*> commands;
|
||||
try {
|
||||
|
@ -105,9 +107,11 @@ bool CheckIntegrityCommand::executeInternal()
|
|||
bool CheckIntegrityCommand::handleException(Exception& e)
|
||||
{
|
||||
_e->getCheckIntegrityMan()->dropPickedEntry();
|
||||
logger->error(MSG_FILE_VALIDATION_FAILURE, e, util::itos(cuid).c_str());
|
||||
logger->error(MSG_DOWNLOAD_NOT_COMPLETE,
|
||||
util::itos(cuid).c_str(),
|
||||
getLogger()->error(MSG_FILE_VALIDATION_FAILURE, e,
|
||||
util::itos(getCuid()).c_str());
|
||||
getLogger()->error
|
||||
(MSG_DOWNLOAD_NOT_COMPLETE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
_requestGroup->getDownloadContext()->getBasePath().c_str());
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -57,9 +57,10 @@ Command* CheckIntegrityDispatcherCommand::createCommand
|
|||
(const SharedHandle<CheckIntegrityEntry>& entry)
|
||||
{
|
||||
cuid_t newCUID = _e->newCUID();
|
||||
if(logger->info()) {
|
||||
logger->info("CUID#%s - Dispatching CheckIntegrityCommand CUID#%s.",
|
||||
util::itos(cuid).c_str(), util::itos(newCUID).c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info("CUID#%s - Dispatching CheckIntegrityCommand CUID#%s.",
|
||||
util::itos(getCuid()).c_str(),
|
||||
util::itos(newCUID).c_str());
|
||||
}
|
||||
return new CheckIntegrityCommand
|
||||
(newCUID, entry->getRequestGroup(), _e, entry);
|
||||
|
|
|
@ -41,9 +41,9 @@ namespace aria2 {
|
|||
int32_t Command::uuidGen = 0;
|
||||
|
||||
Command::Command(cuid_t cuid):uuid(uuidGen++),
|
||||
status(STATUS_INACTIVE),
|
||||
cuid(cuid),
|
||||
logger(LogFactory::getInstance()),
|
||||
_status(STATUS_INACTIVE),
|
||||
_cuid(cuid),
|
||||
_logger(LogFactory::getInstance()),
|
||||
_readEvent(false),
|
||||
_writeEvent(false),
|
||||
_errorEvent(false),
|
||||
|
@ -51,17 +51,17 @@ Command::Command(cuid_t cuid):uuid(uuidGen++),
|
|||
|
||||
void Command::transitStatus()
|
||||
{
|
||||
switch(status) {
|
||||
switch(_status) {
|
||||
case STATUS_REALTIME:
|
||||
break;
|
||||
default:
|
||||
status = STATUS_INACTIVE;
|
||||
_status = STATUS_INACTIVE;
|
||||
}
|
||||
}
|
||||
|
||||
void Command::setStatus(STATUS status)
|
||||
{
|
||||
this->status = status;
|
||||
_status = status;
|
||||
}
|
||||
|
||||
void Command::readEventReceived()
|
||||
|
|
|
@ -58,15 +58,40 @@ public:
|
|||
private:
|
||||
CommandUuid uuid;
|
||||
static int32_t uuidGen;
|
||||
STATUS status;
|
||||
protected:
|
||||
cuid_t cuid;
|
||||
Logger* logger;
|
||||
STATUS _status;
|
||||
|
||||
cuid_t _cuid;
|
||||
Logger* _logger;
|
||||
|
||||
bool _readEvent;
|
||||
bool _writeEvent;
|
||||
bool _errorEvent;
|
||||
bool _hupEvent;
|
||||
protected:
|
||||
Logger* getLogger() const
|
||||
{
|
||||
return _logger;
|
||||
}
|
||||
|
||||
bool readEventEnabled() const
|
||||
{
|
||||
return _readEvent;
|
||||
}
|
||||
|
||||
bool writeEventEnabled() const
|
||||
{
|
||||
return _writeEvent;
|
||||
}
|
||||
|
||||
bool errorEventEnabled() const
|
||||
{
|
||||
return _errorEvent;
|
||||
}
|
||||
|
||||
bool hupEventEnabled() const
|
||||
{
|
||||
return _hupEvent;
|
||||
}
|
||||
public:
|
||||
Command(cuid_t cuid);
|
||||
|
||||
|
@ -74,21 +99,21 @@ public:
|
|||
|
||||
virtual bool execute() = 0;
|
||||
|
||||
cuid_t getCuid() const { return cuid; }
|
||||
cuid_t getCuid() const { return _cuid; }
|
||||
|
||||
const CommandUuid& getUuid() const { return uuid; }
|
||||
|
||||
void setStatusActive() { this->status = STATUS_ACTIVE; }
|
||||
void setStatusActive() { _status = STATUS_ACTIVE; }
|
||||
|
||||
void setStatusInactive() { this->status = STATUS_INACTIVE; }
|
||||
void setStatusInactive() { _status = STATUS_INACTIVE; }
|
||||
|
||||
void setStatusRealtime() { this->status = STATUS_REALTIME; }
|
||||
void setStatusRealtime() { _status = STATUS_REALTIME; }
|
||||
|
||||
void setStatus(STATUS status);
|
||||
|
||||
bool statusMatch(Command::STATUS statusFilter) const
|
||||
{
|
||||
return statusFilter <= status;
|
||||
return statusFilter <= _status;
|
||||
}
|
||||
|
||||
void transitStatus();
|
||||
|
|
|
@ -97,7 +97,7 @@ bool CreateRequestCommand::executeInternal()
|
|||
|
||||
Command* command =
|
||||
InitiateConnectionCommandFactory::createInitiateConnectionCommand
|
||||
(cuid, req, _fileEntry, _requestGroup, e);
|
||||
(getCuid(), req, _fileEntry, _requestGroup, e);
|
||||
e->setNoWait(true);
|
||||
e->addCommand(command);
|
||||
return true;
|
||||
|
@ -114,13 +114,14 @@ bool CreateRequestCommand::prepareForRetry(time_t wait)
|
|||
// CreateRequestCommand is deleted one second later: This is not
|
||||
// efficient. For this reason, reuse current CreateRequestCommand.
|
||||
if(!_requestGroup->getPieceStorage().isNull()) {
|
||||
_requestGroup->getSegmentMan()->cancelSegment(cuid);
|
||||
_requestGroup->getSegmentMan()->cancelSegment(getCuid());
|
||||
}
|
||||
if(logger->debug()) {
|
||||
logger->debug("CUID#%s - Reusing CreateRequestCommand",
|
||||
util::itos(cuid).c_str());
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Reusing CreateRequestCommand",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
SleepCommand* scom = new SleepCommand(cuid, e, _requestGroup, this, wait);
|
||||
SleepCommand* scom = new SleepCommand
|
||||
(getCuid(), e, _requestGroup, this, wait);
|
||||
e->addCommand(scom);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ void DHTAutoSaveCommand::process()
|
|||
void DHTAutoSaveCommand::save()
|
||||
{
|
||||
std::string dhtFile = _e->getOption()->get(PREF_DHT_FILE_PATH);
|
||||
logger->info("Saving DHT routing table to %s.", dhtFile.c_str());
|
||||
getLogger()->info("Saving DHT routing table to %s.", dhtFile.c_str());
|
||||
|
||||
std::string tempFile = dhtFile;
|
||||
tempFile += "__temp";
|
||||
|
@ -92,11 +92,12 @@ void DHTAutoSaveCommand::save()
|
|||
File dir(f.getDirname());
|
||||
if(!dir.exists()) {
|
||||
if(!dir.mkdirs()) {
|
||||
logger->info(EX_MAKE_DIR, dir.getPath().c_str(), strerror(errno));
|
||||
getLogger()->info(EX_MAKE_DIR,
|
||||
dir.getPath().c_str(), strerror(errno));
|
||||
return;
|
||||
}
|
||||
} else if(!dir.isDir()) {
|
||||
logger->info(EX_NOT_DIRECTORY, dir.getPath().c_str());
|
||||
getLogger()->info(EX_NOT_DIRECTORY, dir.getPath().c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -127,11 +128,11 @@ void DHTAutoSaveCommand::save()
|
|||
serializer.serialize(o);
|
||||
}
|
||||
if(!File(tempFile).renameTo(dhtFile)) {
|
||||
logger->error("Cannot move file from %s to %s.",
|
||||
getLogger()->error("Cannot move file from %s to %s.",
|
||||
tempFile.c_str(), dhtFile.c_str());
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
logger->error("Exception caught while saving DHT routing table to %s",
|
||||
getLogger()->error("Exception caught while saving DHT routing table to %s",
|
||||
e, dhtFile.c_str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ bool DHTEntryPointNameResolveCommand::execute()
|
|||
return false;
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
logger->error(EX_EXCEPTION_CAUGHT, e);
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
_resolver->reset();
|
||||
_entryPoints.pop_front();
|
||||
|
@ -122,22 +122,24 @@ bool DHTEntryPointNameResolveCommand::execute()
|
|||
_resolvedEntryPoints.push_back(p);
|
||||
addPingTask(p);
|
||||
} catch(RecoverableException& e) {
|
||||
logger->error(EX_EXCEPTION_CAUGHT, e);
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
_entryPoints.pop_front();
|
||||
}
|
||||
}
|
||||
if(_bootstrapEnabled && _resolvedEntryPoints.size()) {
|
||||
_taskQueue->addPeriodicTask1(_taskFactory->createNodeLookupTask(_localNode->getID()));
|
||||
_taskQueue->addPeriodicTask1(_taskFactory->createNodeLookupTask
|
||||
(_localNode->getID()));
|
||||
_taskQueue->addPeriodicTask1(_taskFactory->createBucketRefreshTask());
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
logger->error(EX_EXCEPTION_CAUGHT, e);
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DHTEntryPointNameResolveCommand::addPingTask(const std::pair<std::string, uint16_t>& addr)
|
||||
void DHTEntryPointNameResolveCommand::addPingTask
|
||||
(const std::pair<std::string, uint16_t>& addr)
|
||||
{
|
||||
SharedHandle<DHTNode> entryNode(new DHTNode());
|
||||
entryNode->setIPAddress(addr.first);
|
||||
|
@ -154,17 +156,17 @@ bool DHTEntryPointNameResolveCommand::resolveHostname
|
|||
{
|
||||
switch(resolver->getStatus()) {
|
||||
case AsyncNameResolver::STATUS_READY:
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_RESOLVING_HOSTNAME,
|
||||
util::itos(cuid).c_str(), hostname.c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_RESOLVING_HOSTNAME,
|
||||
util::itos(getCuid()).c_str(), hostname.c_str());
|
||||
}
|
||||
resolver->resolve(hostname);
|
||||
setNameResolverCheck(resolver);
|
||||
return false;
|
||||
case AsyncNameResolver::STATUS_SUCCESS:
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_NAME_RESOLUTION_COMPLETE,
|
||||
util::itos(cuid).c_str(),
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_NAME_RESOLUTION_COMPLETE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
resolver->getHostname().c_str(),
|
||||
resolver->getResolvedAddresses().front().c_str());
|
||||
}
|
||||
|
@ -173,7 +175,7 @@ bool DHTEntryPointNameResolveCommand::resolveHostname
|
|||
case AsyncNameResolver::STATUS_ERROR:
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat(MSG_NAME_RESOLUTION_FAILED,
|
||||
util::itos(cuid).c_str(),
|
||||
util::itos(getCuid()).c_str(),
|
||||
hostname.c_str(),
|
||||
resolver->getError().c_str()).str());
|
||||
default:
|
||||
|
@ -199,22 +201,26 @@ void DHTEntryPointNameResolveCommand::setBootstrapEnabled(bool f)
|
|||
_bootstrapEnabled = f;
|
||||
}
|
||||
|
||||
void DHTEntryPointNameResolveCommand::setTaskQueue(const SharedHandle<DHTTaskQueue>& taskQueue)
|
||||
void DHTEntryPointNameResolveCommand::setTaskQueue
|
||||
(const SharedHandle<DHTTaskQueue>& taskQueue)
|
||||
{
|
||||
_taskQueue = taskQueue;
|
||||
}
|
||||
|
||||
void DHTEntryPointNameResolveCommand::setTaskFactory(const SharedHandle<DHTTaskFactory>& taskFactory)
|
||||
void DHTEntryPointNameResolveCommand::setTaskFactory
|
||||
(const SharedHandle<DHTTaskFactory>& taskFactory)
|
||||
{
|
||||
_taskFactory = taskFactory;
|
||||
}
|
||||
|
||||
void DHTEntryPointNameResolveCommand::setRoutingTable(const SharedHandle<DHTRoutingTable>& routingTable)
|
||||
void DHTEntryPointNameResolveCommand::setRoutingTable
|
||||
(const SharedHandle<DHTRoutingTable>& routingTable)
|
||||
{
|
||||
_routingTable = routingTable;
|
||||
}
|
||||
|
||||
void DHTEntryPointNameResolveCommand::setLocalNode(const SharedHandle<DHTNode>& localNode)
|
||||
void DHTEntryPointNameResolveCommand::setLocalNode
|
||||
(const SharedHandle<DHTNode>& localNode)
|
||||
{
|
||||
_localNode = localNode;
|
||||
}
|
||||
|
|
|
@ -80,8 +80,8 @@ bool DHTGetPeersCommand::execute()
|
|||
((_numRetry > 0 &&
|
||||
_lastGetPeerTime.difference(global::wallclock) >= (time_t)_numRetry*5) ||
|
||||
_lastGetPeerTime.difference(global::wallclock) >= GET_PEER_INTERVAL)) {
|
||||
if(logger->debug()) {
|
||||
logger->debug("Issuing PeerLookup for infoHash=%s",
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("Issuing PeerLookup for infoHash=%s",
|
||||
bittorrent::getInfoHashString
|
||||
(_requestGroup->getDownloadContext()).c_str());
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ bool DHTInteractionCommand::execute()
|
|||
try {
|
||||
_dispatcher->sendMessages();
|
||||
} catch(RecoverableException& e) {
|
||||
logger->error(EX_EXCEPTION_CAUGHT, e);
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
_e->addCommand(this);
|
||||
return false;
|
||||
|
|
|
@ -62,7 +62,7 @@ void DHTPeerAnnounceCommand::process()
|
|||
try {
|
||||
_peerAnnounceStorage->handleTimeout();
|
||||
} catch(RecoverableException& e) {
|
||||
logger->error(EX_EXCEPTION_CAUGHT, e);
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ void DHTTokenUpdateCommand::process()
|
|||
try {
|
||||
_tokenTracker->updateTokenSecret();
|
||||
} catch(RecoverableException& e) {
|
||||
logger->error(EX_EXCEPTION_CAUGHT, e);
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,8 @@ DownloadCommand::DownloadCommand(cuid_t cuid,
|
|||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
{
|
||||
if(getOption()->getAsBool(PREF_REALTIME_CHUNK_CHECKSUM)) {
|
||||
std::string algo = _requestGroup->getDownloadContext()->getPieceHashAlgo();
|
||||
std::string algo =
|
||||
_requestGroup->getDownloadContext()->getPieceHashAlgo();
|
||||
if(MessageDigestContext::supports(algo)) {
|
||||
_messageDigestContext.reset(new MessageDigestContext());
|
||||
_messageDigestContext->trySetAlgo(algo);
|
||||
|
@ -124,7 +125,10 @@ bool DownloadCommand::executeInternal() {
|
|||
bufSize = std::min(segment->getLength()-segment->getWrittenLength(),
|
||||
BUFSIZE);
|
||||
} else {
|
||||
bufSize = std::min(static_cast<size_t>(_fileEntry->getLastOffset()-segment->getPositionToWrite()), BUFSIZE);
|
||||
bufSize =
|
||||
std::min(static_cast<size_t>
|
||||
(_fileEntry->getLastOffset()-segment->getPositionToWrite()),
|
||||
BUFSIZE);
|
||||
}
|
||||
} else {
|
||||
bufSize = BUFSIZE;
|
||||
|
@ -185,7 +189,8 @@ bool DownloadCommand::executeInternal() {
|
|||
segmentPartComplete = true;
|
||||
}
|
||||
} else if(!_transferEncodingDecoder.isNull() &&
|
||||
(segment->complete() || segment->getPositionToWrite() == _fileEntry->getLastOffset())) {
|
||||
(segment->complete() ||
|
||||
segment->getPositionToWrite() == _fileEntry->getLastOffset())) {
|
||||
// In this case, transferEncodingDecoder is used and
|
||||
// Content-Length is known.
|
||||
segmentPartComplete = true;
|
||||
|
@ -206,24 +211,29 @@ bool DownloadCommand::executeInternal() {
|
|||
// If segment->getLength() == 0, the server doesn't provide
|
||||
// content length, but the client detected that download
|
||||
// completed.
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_SEGMENT_DOWNLOAD_COMPLETED, util::itos(cuid).c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_SEGMENT_DOWNLOAD_COMPLETED,
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
|
||||
{
|
||||
const std::string& expectedPieceHash =
|
||||
_requestGroup->getDownloadContext()->getPieceHash(segment->getIndex());
|
||||
_requestGroup->getDownloadContext()->getPieceHash
|
||||
(segment->getIndex());
|
||||
if(_pieceHashValidationEnabled && !expectedPieceHash.empty()) {
|
||||
if(segment->isHashCalculated()) {
|
||||
if(logger->debug()) {
|
||||
logger->debug("Hash is available! index=%lu",
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug
|
||||
("Hash is available! index=%lu",
|
||||
static_cast<unsigned long>(segment->getIndex()));
|
||||
}
|
||||
validatePieceHash(segment, expectedPieceHash, segment->getHashString());
|
||||
validatePieceHash
|
||||
(segment, expectedPieceHash, segment->getHashString());
|
||||
} else {
|
||||
_messageDigestContext->digestReset();
|
||||
validatePieceHash(segment, expectedPieceHash,
|
||||
validatePieceHash
|
||||
(segment, expectedPieceHash,
|
||||
MessageDigestHelper::digest
|
||||
(_messageDigestContext.get(),
|
||||
_requestGroup->getPieceStorage()->getDiskAdaptor(),
|
||||
|
@ -231,18 +241,18 @@ bool DownloadCommand::executeInternal() {
|
|||
segment->getLength()));
|
||||
}
|
||||
} else {
|
||||
_requestGroup->getSegmentMan()->completeSegment(cuid, segment);
|
||||
_requestGroup->getSegmentMan()->completeSegment(getCuid(), segment);
|
||||
}
|
||||
}
|
||||
|
||||
#else // !ENABLE_MESSAGE_DIGEST
|
||||
_requestGroup->getSegmentMan()->completeSegment(cuid, segment);
|
||||
_requestGroup->getSegmentMan()->completeSegment(getCuid(), segment);
|
||||
#endif // !ENABLE_MESSAGE_DIGEST
|
||||
} else {
|
||||
// If segment is not canceled here, in the next pipelining
|
||||
// request, aria2 requests bad range
|
||||
// [FileEntry->getLastOffset(), FileEntry->getLastOffset())
|
||||
_requestGroup->getSegmentMan()->cancelSegment(cuid, segment);
|
||||
_requestGroup->getSegmentMan()->cancelSegment(getCuid(), segment);
|
||||
}
|
||||
checkLowestDownloadSpeed();
|
||||
// this unit is going to download another segment.
|
||||
|
@ -314,7 +324,7 @@ bool DownloadCommand::prepareForNextSegment() {
|
|||
SharedHandle<SegmentMan> segmentMan = _requestGroup->getSegmentMan();
|
||||
SharedHandle<Segment> nextSegment =
|
||||
segmentMan->getCleanSegmentIfOwnerIsIdle
|
||||
(cuid, tempSegment->getIndex()+1);
|
||||
(getCuid(), tempSegment->getIndex()+1);
|
||||
if(nextSegment.isNull()) {
|
||||
return prepareForRetry(0);
|
||||
} else {
|
||||
|
@ -334,16 +344,16 @@ void DownloadCommand::validatePieceHash(const SharedHandle<Segment>& segment,
|
|||
const std::string& actualPieceHash)
|
||||
{
|
||||
if(actualPieceHash == expectedPieceHash) {
|
||||
logger->info(MSG_GOOD_CHUNK_CHECKSUM, actualPieceHash.c_str());
|
||||
_requestGroup->getSegmentMan()->completeSegment(cuid, segment);
|
||||
getLogger()->info(MSG_GOOD_CHUNK_CHECKSUM, actualPieceHash.c_str());
|
||||
_requestGroup->getSegmentMan()->completeSegment(getCuid(), segment);
|
||||
} else {
|
||||
logger->info(EX_INVALID_CHUNK_CHECKSUM,
|
||||
getLogger()->info(EX_INVALID_CHUNK_CHECKSUM,
|
||||
segment->getIndex(),
|
||||
util::itos(segment->getPosition(), true).c_str(),
|
||||
expectedPieceHash.c_str(),
|
||||
actualPieceHash.c_str());
|
||||
segment->clear();
|
||||
_requestGroup->getSegmentMan()->cancelSegment(cuid);
|
||||
_requestGroup->getSegmentMan()->cancelSegment(getCuid());
|
||||
throw DL_RETRY_EX
|
||||
(StringFormat("Invalid checksum index=%d", segment->getIndex()).str());
|
||||
}
|
||||
|
|
|
@ -68,8 +68,9 @@ bool FileAllocationCommand::executeInternal()
|
|||
}
|
||||
_fileAllocationEntry->allocateChunk();
|
||||
if(_fileAllocationEntry->finished()) {
|
||||
if(logger->debug()) {
|
||||
logger->debug(MSG_ALLOCATION_COMPLETED,
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug
|
||||
(MSG_ALLOCATION_COMPLETED,
|
||||
_timer.difference(global::wallclock),
|
||||
util::itos(_requestGroup->getTotalLength(), true).c_str());
|
||||
}
|
||||
|
@ -94,8 +95,10 @@ bool FileAllocationCommand::executeInternal()
|
|||
bool FileAllocationCommand::handleException(Exception& e)
|
||||
{
|
||||
_e->getFileAllocationMan()->dropPickedEntry();
|
||||
logger->error(MSG_FILE_ALLOCATION_FAILURE, e, util::itos(cuid).c_str());
|
||||
logger->error(MSG_DOWNLOAD_NOT_COMPLETE, util::itos(cuid).c_str(),
|
||||
getLogger()->error
|
||||
(MSG_FILE_ALLOCATION_FAILURE, e, util::itos(getCuid()).c_str());
|
||||
getLogger()->error
|
||||
(MSG_DOWNLOAD_NOT_COMPLETE, util::itos(getCuid()).c_str(),
|
||||
_requestGroup->getDownloadContext()->getBasePath().c_str());
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -54,8 +54,9 @@ Command* FileAllocationDispatcherCommand::createCommand
|
|||
(const SharedHandle<FileAllocationEntry>& entry)
|
||||
{
|
||||
cuid_t newCUID = _e->newCUID();
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_FILE_ALLOCATION_DISPATCH, util::itos(newCUID).c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_FILE_ALLOCATION_DISPATCH,
|
||||
util::itos(newCUID).c_str());
|
||||
}
|
||||
FileAllocationCommand* command =
|
||||
new FileAllocationCommand(newCUID, entry->getRequestGroup(), _e, entry);
|
||||
|
|
|
@ -70,7 +70,7 @@ bool FillRequestGroupCommand::execute()
|
|||
rgman->clearQueueCheck();
|
||||
rgman->fillRequestGroupFromReserver(_e);
|
||||
} catch(RecoverableException& ex) {
|
||||
logger->error(EX_EXCEPTION_CAUGHT, ex);
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, ex);
|
||||
// Re-request queue check to fulfill the requests of all
|
||||
// downloads, some might come after this exception.
|
||||
rgman->requestQueueCheck();
|
||||
|
|
|
@ -70,9 +70,12 @@ FtpDownloadCommand::~FtpDownloadCommand() {}
|
|||
bool FtpDownloadCommand::prepareForNextSegment()
|
||||
{
|
||||
if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION) &&
|
||||
static_cast<uint64_t>(_fileEntry->gtoloff(_segments.front()->getPositionToWrite())) == _fileEntry->getLength()) {
|
||||
static_cast<uint64_t>
|
||||
(_fileEntry->gtoloff(_segments.front()->getPositionToWrite())) ==
|
||||
_fileEntry->getLength()) {
|
||||
Command* command = new FtpFinishDownloadCommand
|
||||
(cuid, req, _fileEntry, _requestGroup, _ftpConnection, e, ctrlSocket);
|
||||
(getCuid(), req, _fileEntry, _requestGroup, _ftpConnection, e,
|
||||
ctrlSocket);
|
||||
e->addCommand(command);
|
||||
|
||||
if(_requestGroup->downloadFinished()) {
|
||||
|
|
|
@ -90,7 +90,7 @@ bool FtpFinishDownloadCommand::execute()
|
|||
socket, options);
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
logger->info(EX_EXCEPTION_CAUGHT, e);
|
||||
getLogger()->info(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
if(_requestGroup->downloadFinished()) {
|
||||
return true;
|
||||
|
|
|
@ -93,9 +93,9 @@ Command* FtpInitiateConnectionCommand::createNextCommand
|
|||
proxyRequest->getHost(), proxyRequest->getPort());
|
||||
}
|
||||
if(pooledSocket.isNull()) {
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_CONNECTING_TO_SERVER,
|
||||
util::itos(cuid).c_str(), addr.c_str(), port);
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_CONNECTING_TO_SERVER,
|
||||
util::itos(getCuid()).c_str(), addr.c_str(), port);
|
||||
}
|
||||
socket.reset(new SocketCore());
|
||||
socket->establishConnection(addr, port);
|
||||
|
@ -104,17 +104,17 @@ Command* FtpInitiateConnectionCommand::createNextCommand
|
|||
// Use GET for FTP via HTTP proxy.
|
||||
req->setMethod(Request::METHOD_GET);
|
||||
SharedHandle<HttpConnection> hc
|
||||
(new HttpConnection(cuid, socket, getOption().get()));
|
||||
(new HttpConnection(getCuid(), socket, getOption().get()));
|
||||
|
||||
HttpRequestCommand* c =
|
||||
new HttpRequestCommand(cuid, req, _fileEntry,
|
||||
new HttpRequestCommand(getCuid(), req, _fileEntry,
|
||||
_requestGroup, hc, e, socket);
|
||||
c->setConnectedAddr(hostname, addr, port);
|
||||
c->setProxyRequest(proxyRequest);
|
||||
command = c;
|
||||
} else if(proxyMethod == V_TUNNEL) {
|
||||
FtpTunnelRequestCommand* c =
|
||||
new FtpTunnelRequestCommand(cuid, req, _fileEntry,
|
||||
new FtpTunnelRequestCommand(getCuid(), req, _fileEntry,
|
||||
_requestGroup, e,
|
||||
proxyRequest, socket);
|
||||
c->setConnectedAddr(hostname, addr, port);
|
||||
|
@ -126,7 +126,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
|
|||
} else {
|
||||
if(proxyMethod == V_TUNNEL) {
|
||||
command =
|
||||
new FtpNegotiationCommand(cuid, req, _fileEntry,
|
||||
new FtpNegotiationCommand(getCuid(), req, _fileEntry,
|
||||
_requestGroup, e, pooledSocket,
|
||||
FtpNegotiationCommand::SEQ_SEND_CWD,
|
||||
options["baseWorkingDir"]);
|
||||
|
@ -134,10 +134,10 @@ Command* FtpInitiateConnectionCommand::createNextCommand
|
|||
// Use GET for FTP via HTTP proxy.
|
||||
req->setMethod(Request::METHOD_GET);
|
||||
SharedHandle<HttpConnection> hc
|
||||
(new HttpConnection(cuid, pooledSocket, getOption().get()));
|
||||
(new HttpConnection(getCuid(), pooledSocket, getOption().get()));
|
||||
|
||||
HttpRequestCommand* c =
|
||||
new HttpRequestCommand(cuid, req, _fileEntry,
|
||||
new HttpRequestCommand(getCuid(), req, _fileEntry,
|
||||
_requestGroup, hc, e, pooledSocket);
|
||||
c->setProxyRequest(proxyRequest);
|
||||
command = c;
|
||||
|
@ -153,20 +153,20 @@ Command* FtpInitiateConnectionCommand::createNextCommand
|
|||
e->getAuthConfigFactory()->createAuthConfig
|
||||
(req, getOption().get())->getUser());
|
||||
if(pooledSocket.isNull()) {
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_CONNECTING_TO_SERVER,
|
||||
util::itos(cuid).c_str(), addr.c_str(), port);
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_CONNECTING_TO_SERVER,
|
||||
util::itos(getCuid()).c_str(), addr.c_str(), port);
|
||||
}
|
||||
socket.reset(new SocketCore());
|
||||
socket->establishConnection(addr, port);
|
||||
FtpNegotiationCommand* c =
|
||||
new FtpNegotiationCommand(cuid, req, _fileEntry,
|
||||
new FtpNegotiationCommand(getCuid(), req, _fileEntry,
|
||||
_requestGroup, e, socket);
|
||||
c->setConnectedAddr(hostname, addr, port);
|
||||
command = c;
|
||||
} else {
|
||||
command =
|
||||
new FtpNegotiationCommand(cuid, req, _fileEntry,
|
||||
new FtpNegotiationCommand(getCuid(), req, _fileEntry,
|
||||
_requestGroup, e, pooledSocket,
|
||||
FtpNegotiationCommand::SEQ_SEND_CWD,
|
||||
options["baseWorkingDir"]);
|
||||
|
|
|
@ -109,9 +109,10 @@ bool FtpNegotiationCommand::executeInternal() {
|
|||
} else if(sequence == SEQ_NEGOTIATION_COMPLETED) {
|
||||
FtpDownloadCommand* command =
|
||||
new FtpDownloadCommand
|
||||
(cuid, req, _fileEntry, _requestGroup, ftp, e, dataSocket, socket);
|
||||
(getCuid(), req, _fileEntry, _requestGroup, ftp, e, dataSocket, socket);
|
||||
command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
|
||||
command->setLowestDownloadSpeedLimit(getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
|
||||
command->setLowestDownloadSpeedLimit
|
||||
(getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
|
||||
if(!_fileEntry->isSingleHostMultiConnectionEnabled()) {
|
||||
_fileEntry->removeURIWhoseHostnameIs(req->getHost());
|
||||
}
|
||||
|
@ -119,7 +120,8 @@ bool FtpNegotiationCommand::executeInternal() {
|
|||
(_fileEntry->getRemainingUris(), command);
|
||||
e->addCommand(command);
|
||||
return true;
|
||||
} else if(sequence == SEQ_HEAD_OK || sequence == SEQ_DOWNLOAD_ALREADY_COMPLETED) {
|
||||
} else if(sequence == SEQ_HEAD_OK ||
|
||||
sequence == SEQ_DOWNLOAD_ALREADY_COMPLETED) {
|
||||
return true;
|
||||
} else if(sequence == SEQ_FILE_PREPARATION) {
|
||||
if(getOption()->getAsBool(PREF_FTP_PASV)) {
|
||||
|
@ -252,9 +254,9 @@ bool FtpNegotiationCommand::recvPwd()
|
|||
throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
|
||||
}
|
||||
ftp->setBaseWorkingDir(pwd);
|
||||
if(logger->info()) {
|
||||
logger->info("CUID#%s - base working directory is '%s'",
|
||||
util::itos(cuid).c_str(), pwd.c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info("CUID#%s - base working directory is '%s'",
|
||||
util::itos(getCuid()).c_str(), pwd.c_str());
|
||||
}
|
||||
sequence = SEQ_SEND_CWD;
|
||||
return true;
|
||||
|
@ -318,23 +320,24 @@ bool FtpNegotiationCommand::recvMdtm()
|
|||
time_t t = lastModifiedTime.getTime();
|
||||
struct tm* tms = gmtime(&t); // returned struct is statically allocated.
|
||||
if(tms) {
|
||||
if(logger->debug()) {
|
||||
logger->debug("MDTM result was parsed as: %s GMT", asctime(tms));
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("MDTM result was parsed as: %s GMT", asctime(tms));
|
||||
}
|
||||
} else {
|
||||
if(logger->debug()) {
|
||||
logger->debug("gmtime() failed for MDTM result.");
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("gmtime() failed for MDTM result.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(logger->debug()) {
|
||||
logger->debug("MDTM response was returned, but it seems not to be a"
|
||||
" time value as in specified in RFC3659.");
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("MDTM response was returned, but it seems not to be"
|
||||
" a time value as in specified in RFC3659.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(logger->info()) {
|
||||
logger->info("CUID#%s - MDTM command failed.", util::itos(cuid).c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info("CUID#%s - MDTM command failed.",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
}
|
||||
sequence = SEQ_SEND_SIZE;
|
||||
|
@ -385,7 +388,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
|||
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
||||
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
|
||||
|
||||
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||
getLogger()->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||
util::itos(_requestGroup->getGID()).c_str(),
|
||||
_requestGroup->getFirstFilePath().c_str());
|
||||
|
||||
|
@ -406,7 +409,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
|||
// We have to make sure that command that has Request object must
|
||||
// have segment after PieceStorage is initialized. See
|
||||
// AbstractCommand::execute()
|
||||
_requestGroup->getSegmentMan()->getSegment(cuid, 0);
|
||||
_requestGroup->getSegmentMan()->getSegment(getCuid(), 0);
|
||||
return true;
|
||||
} else {
|
||||
_requestGroup->adjustFilename
|
||||
|
@ -421,13 +424,16 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
|||
return false;
|
||||
}
|
||||
|
||||
BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), getOption().get()));
|
||||
BtProgressInfoFileHandle infoFile
|
||||
(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(),
|
||||
_requestGroup->getPieceStorage(),
|
||||
getOption().get()));
|
||||
if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
|
||||
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
||||
|
||||
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
|
||||
|
||||
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||
getLogger()->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||
util::itos(_requestGroup->getGID()).c_str(),
|
||||
_requestGroup->getFirstFilePath().c_str());
|
||||
|
||||
|
@ -439,7 +445,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
|||
// We have to make sure that command that has Request object must
|
||||
// have segment after PieceStorage is initialized. See
|
||||
// AbstractCommand::execute()
|
||||
_requestGroup->getSegmentMan()->getSegment(cuid, 0);
|
||||
_requestGroup->getSegmentMan()->getSegment(getCuid(), 0);
|
||||
|
||||
prepareForNextAction(this);
|
||||
|
||||
|
@ -458,7 +464,8 @@ bool FtpNegotiationCommand::recvSize() {
|
|||
|
||||
if(size > INT64_MAX) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat(EX_TOO_LARGE_FILE, util::uitos(size, true).c_str()).str());
|
||||
(StringFormat(EX_TOO_LARGE_FILE,
|
||||
util::uitos(size, true).c_str()).str());
|
||||
}
|
||||
if(_requestGroup->getPieceStorage().isNull()) {
|
||||
|
||||
|
@ -470,9 +477,9 @@ bool FtpNegotiationCommand::recvSize() {
|
|||
}
|
||||
|
||||
} else {
|
||||
if(logger->info()) {
|
||||
logger->info("CUID#%s - The remote FTP Server doesn't recognize SIZE"
|
||||
" command. Continue.", util::itos(cuid).c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info("CUID#%s - The remote FTP Server doesn't recognize SIZE"
|
||||
" command. Continue.", util::itos(getCuid()).c_str());
|
||||
}
|
||||
// Even if one of the other servers waiting in the queue supports SIZE
|
||||
// command, resuming and segmented downloading are disabled when the first
|
||||
|
@ -555,8 +562,8 @@ bool FtpNegotiationCommand::recvPasv() {
|
|||
return true;
|
||||
} else {
|
||||
// make a data connection to the server.
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_CONNECTING_TO_SERVER, util::itos(cuid).c_str(),
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_CONNECTING_TO_SERVER, util::itos(getCuid()).c_str(),
|
||||
dest.first.c_str(),
|
||||
dest.second);
|
||||
}
|
||||
|
@ -578,15 +585,15 @@ bool FtpNegotiationCommand::resolveProxy()
|
|||
if(_proxyAddr.empty()) {
|
||||
return false;
|
||||
}
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_CONNECTING_TO_SERVER, util::itos(cuid).c_str(),
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_CONNECTING_TO_SERVER, util::itos(getCuid()).c_str(),
|
||||
_proxyAddr.c_str(), proxyReq->getPort());
|
||||
}
|
||||
dataSocket.reset(new SocketCore());
|
||||
dataSocket->establishConnection(_proxyAddr, proxyReq->getPort());
|
||||
disableReadCheckSocket();
|
||||
setWriteCheckSocket(dataSocket);
|
||||
_http.reset(new HttpConnection(cuid, dataSocket, getOption().get()));
|
||||
_http.reset(new HttpConnection(getCuid(), dataSocket, getOption().get()));
|
||||
sequence = SEQ_SEND_TUNNEL_REQUEST;
|
||||
return false;
|
||||
}
|
||||
|
@ -607,14 +614,15 @@ bool FtpNegotiationCommand::sendTunnelRequest()
|
|||
(StringFormat(MSG_ESTABLISHING_CONNECTION_FAILED,
|
||||
error.c_str()).str());
|
||||
} else {
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_CONNECT_FAILED_AND_RETRY,
|
||||
util::itos(cuid).c_str(),
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_CONNECT_FAILED_AND_RETRY,
|
||||
util::itos(getCuid()).c_str(),
|
||||
_proxyAddr.c_str(), proxyReq->getPort());
|
||||
}
|
||||
_proxyAddr = nextProxyAddr;
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_CONNECTING_TO_SERVER, util::itos(cuid).c_str(),
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_CONNECTING_TO_SERVER,
|
||||
util::itos(getCuid()).c_str(),
|
||||
_proxyAddr.c_str(), proxyReq->getPort());
|
||||
}
|
||||
dataSocket->establishConnection(_proxyAddr, proxyReq->getPort());
|
||||
|
|
|
@ -58,7 +58,7 @@ FtpTunnelRequestCommand::~FtpTunnelRequestCommand() {}
|
|||
Command* FtpTunnelRequestCommand::getNextCommand()
|
||||
{
|
||||
return new FtpTunnelResponseCommand
|
||||
(cuid, req, _fileEntry, _requestGroup, httpConnection, e, socket);
|
||||
(getCuid(), req, _fileEntry, _requestGroup, httpConnection, e, socket);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -59,7 +59,7 @@ FtpTunnelResponseCommand::~FtpTunnelResponseCommand() {}
|
|||
|
||||
Command* FtpTunnelResponseCommand::getNextCommand()
|
||||
{
|
||||
return new FtpNegotiationCommand(cuid, req, _fileEntry,
|
||||
return new FtpNegotiationCommand(getCuid(), req, _fileEntry,
|
||||
_requestGroup, e, socket);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ bool HttpDownloadCommand::prepareForNextSegment() {
|
|||
bool downloadFinished = _requestGroup->downloadFinished();
|
||||
if(req->isPipeliningEnabled() && !downloadFinished) {
|
||||
HttpRequestCommand* command =
|
||||
new HttpRequestCommand(cuid, req, _fileEntry,
|
||||
new HttpRequestCommand(getCuid(), req, _fileEntry,
|
||||
_requestGroup, _httpConnection, e,
|
||||
socket);
|
||||
// Set proxy request here. aria2 sends the HTTP request specialized for
|
||||
|
|
|
@ -77,24 +77,24 @@ Command* HttpInitiateConnectionCommand::createNextCommand
|
|||
proxyRequest->getHost(), proxyRequest->getPort());
|
||||
std::string proxyMethod = resolveProxyMethod(req->getProtocol());
|
||||
if(pooledSocket.isNull()) {
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_CONNECTING_TO_SERVER,
|
||||
util::itos(cuid).c_str(), addr.c_str(), port);
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_CONNECTING_TO_SERVER,
|
||||
util::itos(getCuid()).c_str(), addr.c_str(), port);
|
||||
}
|
||||
socket.reset(new SocketCore());
|
||||
socket->establishConnection(addr, port);
|
||||
|
||||
if(proxyMethod == V_TUNNEL) {
|
||||
HttpProxyRequestCommand* c =
|
||||
new HttpProxyRequestCommand(cuid, req, _fileEntry,
|
||||
new HttpProxyRequestCommand(getCuid(), req, _fileEntry,
|
||||
_requestGroup, e,
|
||||
proxyRequest, socket);
|
||||
c->setConnectedAddr(hostname, addr, port);
|
||||
command = c;
|
||||
} else if(proxyMethod == V_GET) {
|
||||
SharedHandle<HttpConnection> httpConnection
|
||||
(new HttpConnection(cuid, socket, getOption().get()));
|
||||
HttpRequestCommand* c = new HttpRequestCommand(cuid, req,
|
||||
(new HttpConnection(getCuid(), socket, getOption().get()));
|
||||
HttpRequestCommand* c = new HttpRequestCommand(getCuid(), req,
|
||||
_fileEntry,
|
||||
_requestGroup,
|
||||
httpConnection, e,
|
||||
|
@ -108,8 +108,8 @@ Command* HttpInitiateConnectionCommand::createNextCommand
|
|||
}
|
||||
} else {
|
||||
SharedHandle<HttpConnection> httpConnection
|
||||
(new HttpConnection(cuid, pooledSocket, getOption().get()));
|
||||
HttpRequestCommand* c = new HttpRequestCommand(cuid, req,
|
||||
(new HttpConnection(getCuid(), pooledSocket, getOption().get()));
|
||||
HttpRequestCommand* c = new HttpRequestCommand(getCuid(), req,
|
||||
_fileEntry,
|
||||
_requestGroup,
|
||||
httpConnection, e,
|
||||
|
@ -123,18 +123,19 @@ Command* HttpInitiateConnectionCommand::createNextCommand
|
|||
SharedHandle<SocketCore> pooledSocket =
|
||||
e->popPooledSocket(resolvedAddresses, req->getPort());
|
||||
if(pooledSocket.isNull()) {
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_CONNECTING_TO_SERVER,
|
||||
util::itos(cuid).c_str(), addr.c_str(), port);
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_CONNECTING_TO_SERVER,
|
||||
util::itos(getCuid()).c_str(), addr.c_str(), port);
|
||||
}
|
||||
socket.reset(new SocketCore());
|
||||
socket->establishConnection(addr, port);
|
||||
} else {
|
||||
socket = pooledSocket;
|
||||
}
|
||||
SharedHandle<HttpConnection> httpConnection(new HttpConnection(cuid, socket, getOption().get()));
|
||||
SharedHandle<HttpConnection> httpConnection
|
||||
(new HttpConnection(getCuid(), socket, getOption().get()));
|
||||
HttpRequestCommand* c =
|
||||
new HttpRequestCommand(cuid, req, _fileEntry, _requestGroup,
|
||||
new HttpRequestCommand(getCuid(), req, _fileEntry, _requestGroup,
|
||||
httpConnection, e, socket);
|
||||
if(pooledSocket.isNull()) {
|
||||
c->setConnectedAddr(hostname, addr, port);
|
||||
|
|
|
@ -74,7 +74,7 @@ bool HttpListenCommand::execute()
|
|||
std::pair<std::string, uint16_t> peerInfo;
|
||||
socket->getPeerInfo(peerInfo);
|
||||
|
||||
logger->info("XML-RPC: Accepted the connection from %s:%u.",
|
||||
getLogger()->info("XML-RPC: Accepted the connection from %s:%u.",
|
||||
peerInfo.first.c_str(), peerInfo.second);
|
||||
|
||||
HttpServerCommand* c =
|
||||
|
@ -83,8 +83,8 @@ bool HttpListenCommand::execute()
|
|||
_e->addCommand(c);
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
if(logger->debug()) {
|
||||
logger->debug(MSG_ACCEPT_FAILURE, e, util::itos(cuid).c_str());
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug(MSG_ACCEPT_FAILURE, e, util::itos(getCuid()).c_str());
|
||||
}
|
||||
}
|
||||
_e->addCommand(this);
|
||||
|
@ -97,9 +97,9 @@ bool HttpListenCommand::bindPort(uint16_t port)
|
|||
_e->deleteSocketForReadCheck(_serverSocket, this);
|
||||
}
|
||||
_serverSocket.reset(new SocketCore());
|
||||
if(logger->info()) {
|
||||
logger->info("CUID#%s - Setting up HttpListenCommand",
|
||||
util::itos(cuid).c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info("CUID#%s - Setting up HttpListenCommand",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
try {
|
||||
int flags = 0;
|
||||
|
@ -109,13 +109,15 @@ bool HttpListenCommand::bindPort(uint16_t port)
|
|||
_serverSocket->bind(port, flags);
|
||||
_serverSocket->beginListen();
|
||||
_serverSocket->setNonBlockingMode();
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_LISTENING_PORT, util::itos(cuid).c_str(), port);
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_LISTENING_PORT,
|
||||
util::itos(getCuid()).c_str(), port);
|
||||
}
|
||||
_e->addSocketForReadCheck(_serverSocket, this);
|
||||
return true;
|
||||
} catch(RecoverableException& e) {
|
||||
logger->error(MSG_BIND_FAILURE, e, util::itos(cuid).c_str(), port);
|
||||
getLogger()->error(MSG_BIND_FAILURE, e,
|
||||
util::itos(getCuid()).c_str(), port);
|
||||
if(!_serverSocket.isNull()) {
|
||||
_e->deleteSocketForReadCheck(_serverSocket, this);
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ HttpProxyRequestCommand::~HttpProxyRequestCommand() {}
|
|||
Command* HttpProxyRequestCommand::getNextCommand()
|
||||
{
|
||||
return new HttpProxyResponseCommand
|
||||
(cuid, req, _fileEntry, _requestGroup, httpConnection, e, socket);
|
||||
(getCuid(), req, _fileEntry, _requestGroup, httpConnection, e, socket);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -59,7 +59,7 @@ HttpProxyResponseCommand::~HttpProxyResponseCommand() {}
|
|||
|
||||
Command* HttpProxyResponseCommand::getNextCommand()
|
||||
{
|
||||
return new HttpRequestCommand(cuid, req, _fileEntry,
|
||||
return new HttpRequestCommand(getCuid(), req, _fileEntry,
|
||||
_requestGroup, httpConnection, e, socket);
|
||||
}
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ bool HttpRequestCommand::executeInternal() {
|
|||
_httpConnection->sendPendingData();
|
||||
}
|
||||
if(_httpConnection->sendBufferIsEmpty()) {
|
||||
Command* command = new HttpResponseCommand(cuid, req, _fileEntry,
|
||||
Command* command = new HttpResponseCommand(getCuid(), req, _fileEntry,
|
||||
_requestGroup,
|
||||
_httpConnection, e, socket);
|
||||
e->addCommand(command);
|
||||
|
|
|
@ -115,7 +115,8 @@ bool HttpResponseCommand::executeInternal()
|
|||
req->supportsPersistentConnection
|
||||
(httpResponse->supportsPersistentConnection());
|
||||
if(req->isPipeliningEnabled()) {
|
||||
req->setMaxPipelinedRequest(getOption()->getAsInt(PREF_MAX_HTTP_PIPELINING));
|
||||
req->setMaxPipelinedRequest
|
||||
(getOption()->getAsInt(PREF_MAX_HTTP_PIPELINING));
|
||||
}
|
||||
|
||||
if(httpResponse->getResponseStatus() >= HttpHeader::S300) {
|
||||
|
@ -181,8 +182,8 @@ bool HttpResponseCommand::executeInternal()
|
|||
getTransferEncodingDecoder(httpResponse),
|
||||
getContentEncodingDecoder(httpResponse)));
|
||||
} else {
|
||||
e->addCommand(createHttpDownloadCommand(httpResponse,
|
||||
getTransferEncodingDecoder(httpResponse)));
|
||||
e->addCommand(createHttpDownloadCommand
|
||||
(httpResponse, getTransferEncodingDecoder(httpResponse)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -226,11 +227,14 @@ bool HttpResponseCommand::handleDefaultEncoding
|
|||
return true;
|
||||
}
|
||||
|
||||
BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), getOption().get()));
|
||||
BtProgressInfoFileHandle infoFile
|
||||
(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(),
|
||||
_requestGroup->getPieceStorage(),
|
||||
getOption().get()));
|
||||
if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
|
||||
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
||||
|
||||
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||
getLogger()->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||
util::itos(_requestGroup->getGID()).c_str(),
|
||||
_requestGroup->getFirstFilePath().c_str());
|
||||
|
||||
|
@ -242,7 +246,7 @@ bool HttpResponseCommand::handleDefaultEncoding
|
|||
// have segment after PieceStorage is initialized. See
|
||||
// AbstractCommand::execute()
|
||||
SharedHandle<Segment> segment =
|
||||
_requestGroup->getSegmentMan()->getSegment(cuid, 0);
|
||||
_requestGroup->getSegmentMan()->getSegment(getCuid(), 0);
|
||||
// pipelining requires implicit range specified. But the request for
|
||||
// this response most likely dones't contains range header. This means
|
||||
// we can't continue to use this socket because server sends all entity
|
||||
|
@ -255,7 +259,7 @@ bool HttpResponseCommand::handleDefaultEncoding
|
|||
command = createHttpDownloadCommand
|
||||
(httpResponse, getTransferEncodingDecoder(httpResponse));
|
||||
} else {
|
||||
_requestGroup->getSegmentMan()->cancelSegment(cuid);
|
||||
_requestGroup->getSegmentMan()->cancelSegment(getCuid());
|
||||
_fileEntry->poolRequest(req);
|
||||
}
|
||||
// After command is passed to prepareForNextAction(), it is managed
|
||||
|
@ -326,7 +330,7 @@ bool HttpResponseCommand::handleOtherEncoding
|
|||
_requestGroup->initPieceStorage();
|
||||
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
||||
|
||||
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||
getLogger()->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
||||
util::itos(_requestGroup->getGID()).c_str(),
|
||||
_requestGroup->getFirstFilePath().c_str());
|
||||
|
||||
|
@ -348,7 +352,7 @@ bool HttpResponseCommand::handleOtherEncoding
|
|||
// We have to make sure that command that has Request object must
|
||||
// have segment after PieceStorage is initialized. See
|
||||
// AbstractCommand::execute()
|
||||
_requestGroup->getSegmentMan()->getSegment(cuid, 0);
|
||||
_requestGroup->getSegmentMan()->getSegment(getCuid(), 0);
|
||||
|
||||
e->addCommand
|
||||
(createHttpDownloadCommand(httpResponse,
|
||||
|
@ -365,7 +369,8 @@ bool HttpResponseCommand::skipResponseBody
|
|||
// thrown away.
|
||||
|
||||
HttpSkipResponseCommand* command = new HttpSkipResponseCommand
|
||||
(cuid, req, _fileEntry, _requestGroup, httpConnection, httpResponse, e, socket);
|
||||
(getCuid(), req, _fileEntry, _requestGroup, httpConnection, httpResponse,
|
||||
e, socket);
|
||||
command->setTransferEncodingDecoder(decoder);
|
||||
|
||||
// If request method is HEAD or the response body is zero-length,
|
||||
|
@ -390,7 +395,7 @@ HttpDownloadCommand* HttpResponseCommand::createHttpDownloadCommand
|
|||
{
|
||||
|
||||
HttpDownloadCommand* command =
|
||||
new HttpDownloadCommand(cuid, req, _fileEntry, _requestGroup,
|
||||
new HttpDownloadCommand(getCuid(), req, _fileEntry, _requestGroup,
|
||||
httpResponse, httpConnection, e, socket);
|
||||
command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
|
||||
command->setLowestDownloadSpeedLimit
|
||||
|
|
|
@ -99,7 +99,7 @@ bool HttpServerBodyCommand::execute()
|
|||
std::string responseData = res.toXml(gzip);
|
||||
_httpServer->feedResponse(responseData, "text/xml");
|
||||
Command* command =
|
||||
new HttpServerResponseCommand(cuid, _httpServer, _e, _socket);
|
||||
new HttpServerResponseCommand(getCuid(), _httpServer, _e, _socket);
|
||||
_e->addCommand(command);
|
||||
_e->setNoWait(true);
|
||||
return true;
|
||||
|
@ -112,7 +112,7 @@ bool HttpServerBodyCommand::execute()
|
|||
}
|
||||
} else {
|
||||
if(_timeoutTimer.difference(global::wallclock) >= 30) {
|
||||
logger->info("HTTP request body timeout.");
|
||||
getLogger()->info("HTTP request body timeout.");
|
||||
return true;
|
||||
} else {
|
||||
_e->addCommand(this);
|
||||
|
@ -120,9 +120,10 @@ bool HttpServerBodyCommand::execute()
|
|||
}
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
if(logger->info()) {
|
||||
logger->info("CUID#%s - Error occurred while reading HTTP request body",
|
||||
e, util::itos(cuid).c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info
|
||||
("CUID#%s - Error occurred while reading HTTP request body",
|
||||
e, util::itos(getCuid()).c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ bool HttpServerCommand::execute()
|
|||
"WWW-Authenticate: Basic realm=\"aria2\"",
|
||||
"","text/html");
|
||||
Command* command =
|
||||
new HttpServerResponseCommand(cuid, _httpServer, _e, _socket);
|
||||
new HttpServerResponseCommand(getCuid(), _httpServer, _e, _socket);
|
||||
_e->addCommand(command);
|
||||
_e->setNoWait(true);
|
||||
return true;
|
||||
|
@ -119,20 +119,20 @@ bool HttpServerCommand::execute()
|
|||
if(static_cast<uint64_t>
|
||||
(_e->getOption()->getAsInt(PREF_XML_RPC_MAX_REQUEST_SIZE)) <
|
||||
_httpServer->getContentLength()) {
|
||||
logger->info("Request too long. ContentLength=%s."
|
||||
getLogger()->info("Request too long. ContentLength=%s."
|
||||
" See --xml-rpc-max-request-size option to loose"
|
||||
" this limitation.",
|
||||
util::uitos(_httpServer->getContentLength()).c_str());
|
||||
return true;
|
||||
}
|
||||
Command* command = new HttpServerBodyCommand(cuid, _httpServer, _e,
|
||||
Command* command = new HttpServerBodyCommand(getCuid(), _httpServer, _e,
|
||||
_socket);
|
||||
_e->addCommand(command);
|
||||
_e->setNoWait(true);
|
||||
return true;
|
||||
} else {
|
||||
if(_timeoutTimer.difference(global::wallclock) >= 30) {
|
||||
logger->info("HTTP request timeout.");
|
||||
getLogger()->info("HTTP request timeout.");
|
||||
return true;
|
||||
} else {
|
||||
_e->addCommand(this);
|
||||
|
@ -140,9 +140,9 @@ bool HttpServerCommand::execute()
|
|||
}
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
if(logger->info()) {
|
||||
logger->info("CUID#%s - Error occurred while reading HTTP request",
|
||||
e, util::itos(cuid).c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info("CUID#%s - Error occurred while reading HTTP request",
|
||||
e, util::itos(getCuid()).c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -76,29 +76,32 @@ bool HttpServerResponseCommand::execute()
|
|||
try {
|
||||
_httpServer->sendResponse();
|
||||
} catch(RecoverableException& e) {
|
||||
if(logger->info()) {
|
||||
logger->info("CUID#%s - Error occurred while transmitting response body.",
|
||||
e, util::itos(cuid).c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info
|
||||
("CUID#%s - Error occurred while transmitting response body.",
|
||||
e, util::itos(getCuid()).c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if(_httpServer->sendBufferIsEmpty()) {
|
||||
if(logger->info()) {
|
||||
logger->info("CUID#%s - HttpServer: all response transmitted.",
|
||||
util::itos(cuid).c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info("CUID#%s - HttpServer: all response transmitted.",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
if(_httpServer->supportsPersistentConnection()) {
|
||||
if(logger->info()) {
|
||||
logger->info("CUID#%s - Persist connection.", util::itos(cuid).c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info("CUID#%s - Persist connection.",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
_e->addCommand(new HttpServerCommand(cuid, _httpServer, _e, _socket));
|
||||
_e->addCommand
|
||||
(new HttpServerCommand(getCuid(), _httpServer, _e, _socket));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
if(_timeoutTimer.difference(global::wallclock) >= 10) {
|
||||
if(logger->info()) {
|
||||
logger->info("CUID#%s - HttpServer: Timeout while trasmitting"
|
||||
" response.", util::itos(cuid).c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info("CUID#%s - HttpServer: Timeout while trasmitting"
|
||||
" response.", util::itos(getCuid()).c_str());
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
|
|
|
@ -118,8 +118,8 @@ bool HttpSkipResponseCommand::executeInternal()
|
|||
throw DL_RETRY_EX(EX_GOT_EOF);
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
if(logger->debug()) {
|
||||
logger->debug(EX_EXCEPTION_CAUGHT, e);
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
return processResponse();
|
||||
}
|
||||
|
|
|
@ -101,14 +101,14 @@ bool InitiateConnectionCommand::executeInternal() {
|
|||
// TODO ipaddr might not be used if pooled sockt was found.
|
||||
e->markBadIPAddress(hostname, ipaddr, port);
|
||||
if(!e->findCachedIPAddress(hostname, port).empty()) {
|
||||
if(logger->info()) {
|
||||
logger->info(EX_EXCEPTION_CAUGHT, ex);
|
||||
logger->info(MSG_CONNECT_FAILED_AND_RETRY,
|
||||
util::itos(cuid).c_str(), ipaddr.c_str(), port);
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(EX_EXCEPTION_CAUGHT, ex);
|
||||
getLogger()->info(MSG_CONNECT_FAILED_AND_RETRY,
|
||||
util::itos(getCuid()).c_str(), ipaddr.c_str(), port);
|
||||
}
|
||||
Command* command =
|
||||
InitiateConnectionCommandFactory::createInitiateConnectionCommand
|
||||
(cuid, req, _fileEntry, _requestGroup, e);
|
||||
(getCuid(), req, _fileEntry, _requestGroup, e);
|
||||
e->setNoWait(true);
|
||||
e->addCommand(command);
|
||||
return true;
|
||||
|
|
|
@ -150,14 +150,15 @@ bool InitiatorMSEHandshakeCommand::executeInternal() {
|
|||
case INITIATOR_RECEIVE_PAD_D: {
|
||||
if(_mseHandshake->receivePad()) {
|
||||
SharedHandle<PeerConnection> peerConnection
|
||||
(new PeerConnection(cuid, socket));
|
||||
if(_mseHandshake->getNegotiatedCryptoType() == MSEHandshake::CRYPTO_ARC4) {
|
||||
(new PeerConnection(getCuid(), socket));
|
||||
if(_mseHandshake->getNegotiatedCryptoType() == MSEHandshake::CRYPTO_ARC4){
|
||||
peerConnection->enableEncryption(_mseHandshake->getEncryptor(),
|
||||
_mseHandshake->getDecryptor());
|
||||
}
|
||||
PeerInteractionCommand* c =
|
||||
new PeerInteractionCommand
|
||||
(cuid, _requestGroup, peer, e, _btRuntime, _pieceStorage, _peerStorage,
|
||||
(getCuid(), _requestGroup, peer, e, _btRuntime, _pieceStorage,
|
||||
_peerStorage,
|
||||
socket,
|
||||
PeerInteractionCommand::INITIATOR_SEND_HANDSHAKE,
|
||||
peerConnection);
|
||||
|
@ -174,10 +175,11 @@ bool InitiatorMSEHandshakeCommand::executeInternal() {
|
|||
bool InitiatorMSEHandshakeCommand::prepareForNextPeer(time_t wait)
|
||||
{
|
||||
if(getOption()->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
|
||||
if(logger->info()) {
|
||||
logger->info("CUID#%s - Establishing connection using legacy BitTorrent"
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info
|
||||
("CUID#%s - Establishing connection using legacy BitTorrent"
|
||||
" handshake is disabled by preference.",
|
||||
util::itos(cuid).c_str());
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
if(_peerStorage->isPeerAvailable() && _btRuntime->lessThanEqMinPeers()) {
|
||||
SharedHandle<Peer> peer = _peerStorage->getUnusedPeer();
|
||||
|
@ -192,12 +194,12 @@ bool InitiatorMSEHandshakeCommand::prepareForNextPeer(time_t wait)
|
|||
return true;
|
||||
} else {
|
||||
// try legacy BitTorrent handshake
|
||||
if(logger->info()) {
|
||||
logger->info("CUID#%s - Retry using legacy BitTorrent handshake.",
|
||||
util::itos(cuid).c_str());
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info("CUID#%s - Retry using legacy BitTorrent handshake.",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
PeerInitiateConnectionCommand* command =
|
||||
new PeerInitiateConnectionCommand(cuid, _requestGroup, peer, e,
|
||||
new PeerInitiateConnectionCommand(getCuid(), _requestGroup, peer, e,
|
||||
_btRuntime, false);
|
||||
command->setPeerStorage(_peerStorage);
|
||||
command->setPieceStorage(_pieceStorage);
|
||||
|
|
|
@ -64,24 +64,24 @@ bool LpdDispatchMessageCommand::execute()
|
|||
}
|
||||
if(_dispatcher->isAnnounceReady()) {
|
||||
try {
|
||||
logger->info("Dispatching LPD message for infohash=%s",
|
||||
getLogger()->info("Dispatching LPD message for infohash=%s",
|
||||
util::toHex(_dispatcher->getInfoHash()).c_str());
|
||||
if(_dispatcher->sendMessage()) {
|
||||
logger->info("Sending LPD message is complete.");
|
||||
getLogger()->info("Sending LPD message is complete.");
|
||||
_dispatcher->resetAnnounceTimer();
|
||||
_tryCount = 0;
|
||||
} else {
|
||||
++_tryCount;
|
||||
if(_tryCount >= 5) {
|
||||
logger->info("Sending LPD message %u times but all failed.");
|
||||
getLogger()->info("Sending LPD message %u times but all failed.");
|
||||
_dispatcher->resetAnnounceTimer();
|
||||
_tryCount = 0;
|
||||
} else {
|
||||
logger->info("Could not send LPD message, retry shortly.");
|
||||
getLogger()->info("Could not send LPD message, retry shortly.");
|
||||
}
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
logger->info("Failed to send LPD message.", e);
|
||||
getLogger()->info("Failed to send LPD message.", e);
|
||||
_dispatcher->resetAnnounceTimer();
|
||||
_tryCount = 0;
|
||||
}
|
||||
|
|
|
@ -94,8 +94,8 @@ bool LpdReceiveMessageCommand::execute()
|
|||
SharedHandle<DownloadContext> dctx =
|
||||
reg->getDownloadContext(m->getInfoHash());
|
||||
if(dctx.isNull()) {
|
||||
if(logger->debug()) {
|
||||
logger->debug("Download Context is null for infohash=%s.",
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("Download Context is null for infohash=%s.",
|
||||
util::toHex(m->getInfoHash()).c_str());
|
||||
}
|
||||
continue;
|
||||
|
@ -103,8 +103,9 @@ bool LpdReceiveMessageCommand::execute()
|
|||
const BDE& torrentAttrs = dctx->getAttribute(bittorrent::BITTORRENT);
|
||||
if(torrentAttrs.containsKey(bittorrent::PRIVATE)) {
|
||||
if(torrentAttrs[bittorrent::PRIVATE].i() == 1) {
|
||||
if(logger->debug()) {
|
||||
logger->debug("Ignore LPD message because the torrent is private.");
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug
|
||||
("Ignore LPD message because the torrent is private.");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -117,14 +118,14 @@ bool LpdReceiveMessageCommand::execute()
|
|||
assert(!peerStorage.isNull());
|
||||
SharedHandle<Peer> peer = m->getPeer();
|
||||
if(peerStorage->addPeer(peer)) {
|
||||
if(logger->debug()) {
|
||||
logger->debug("LPD peer %s:%u local=%d added.",
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("LPD peer %s:%u local=%d added.",
|
||||
peer->ipaddr.c_str(), peer->port,
|
||||
peer->isLocalPeer()?1:0);
|
||||
}
|
||||
} else {
|
||||
if(logger->debug()) {
|
||||
logger->debug("LPD peer %s:%u local=%d not added.",
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("LPD peer %s:%u local=%d not added.",
|
||||
peer->ipaddr.c_str(), peer->port,
|
||||
peer->isLocalPeer()?1:0);
|
||||
}
|
||||
|
|
|
@ -81,11 +81,12 @@ PeerAbstractCommand::~PeerAbstractCommand()
|
|||
|
||||
bool PeerAbstractCommand::execute()
|
||||
{
|
||||
if(logger->debug()) {
|
||||
logger->debug("CUID#%s -"
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s -"
|
||||
" socket: read:%d, write:%d, hup:%d, err:%d, noCheck:%d",
|
||||
util::itos(cuid).c_str(),
|
||||
_readEvent, _writeEvent, _hupEvent, _errorEvent,
|
||||
util::itos(getCuid()).c_str(),
|
||||
readEventEnabled(), writeEventEnabled(),
|
||||
hupEventEnabled(), errorEventEnabled(),
|
||||
noCheck);
|
||||
}
|
||||
if(exitBeforeExecute()) {
|
||||
|
@ -94,11 +95,11 @@ bool PeerAbstractCommand::execute()
|
|||
}
|
||||
try {
|
||||
if(noCheck ||
|
||||
(checkSocketIsReadable && _readEvent) ||
|
||||
(checkSocketIsWritable && _writeEvent) ||
|
||||
_hupEvent) {
|
||||
(checkSocketIsReadable && readEventEnabled()) ||
|
||||
(checkSocketIsWritable && writeEventEnabled()) ||
|
||||
hupEventEnabled()) {
|
||||
checkPoint = global::wallclock;
|
||||
} else if(_errorEvent) {
|
||||
} else if(errorEventEnabled()) {
|
||||
throw DL_ABORT_EX
|
||||
(StringFormat(MSG_NETWORK_PROBLEM,
|
||||
socket->getSocketError().c_str()).str());
|
||||
|
@ -108,16 +109,17 @@ bool PeerAbstractCommand::execute()
|
|||
}
|
||||
return executeInternal();
|
||||
} catch(DownloadFailureException& err) {
|
||||
logger->error(EX_DOWNLOAD_ABORTED, err);
|
||||
getLogger()->error(EX_DOWNLOAD_ABORTED, err);
|
||||
onAbort();
|
||||
onFailure();
|
||||
return true;
|
||||
} catch(RecoverableException& err) {
|
||||
if(logger->debug()) {
|
||||
logger->debug(MSG_TORRENT_DOWNLOAD_ABORTED, err,
|
||||
util::itos(cuid).c_str());
|
||||
logger->debug(MSG_PEER_BANNED,
|
||||
util::itos(cuid).c_str(), peer->ipaddr.c_str(), peer->port);
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug(MSG_TORRENT_DOWNLOAD_ABORTED, err,
|
||||
util::itos(getCuid()).c_str());
|
||||
getLogger()->debug(MSG_PEER_BANNED,
|
||||
util::itos(getCuid()).c_str(), peer->ipaddr.c_str(),
|
||||
peer->port);
|
||||
}
|
||||
onAbort();
|
||||
return prepareForNextPeer(0);
|
||||
|
|
|
@ -80,16 +80,16 @@ PeerInitiateConnectionCommand::~PeerInitiateConnectionCommand()
|
|||
}
|
||||
|
||||
bool PeerInitiateConnectionCommand::executeInternal() {
|
||||
if(logger->info()) {
|
||||
logger->info(MSG_CONNECTING_TO_SERVER,
|
||||
util::itos(cuid).c_str(), peer->ipaddr.c_str(),
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_CONNECTING_TO_SERVER,
|
||||
util::itos(getCuid()).c_str(), peer->ipaddr.c_str(),
|
||||
peer->port);
|
||||
}
|
||||
socket.reset(new SocketCore());
|
||||
socket->establishConnection(peer->ipaddr, peer->port);
|
||||
if(_mseHandshakeEnabled) {
|
||||
InitiatorMSEHandshakeCommand* c =
|
||||
new InitiatorMSEHandshakeCommand(cuid, _requestGroup, peer, e,
|
||||
new InitiatorMSEHandshakeCommand(getCuid(), _requestGroup, peer, e,
|
||||
_btRuntime, socket);
|
||||
c->setPeerStorage(_peerStorage);
|
||||
c->setPieceStorage(_pieceStorage);
|
||||
|
@ -97,7 +97,8 @@ bool PeerInitiateConnectionCommand::executeInternal() {
|
|||
} else {
|
||||
PeerInteractionCommand* command =
|
||||
new PeerInteractionCommand
|
||||
(cuid, _requestGroup, peer, e, _btRuntime, _pieceStorage, _peerStorage,
|
||||
(getCuid(), _requestGroup, peer, e, _btRuntime, _pieceStorage,
|
||||
_peerStorage,
|
||||
socket, PeerInteractionCommand::INITIATOR_SEND_HANDSHAKE);
|
||||
e->addCommand(command);
|
||||
}
|
||||
|
|
|
@ -89,10 +89,11 @@ bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq)
|
|||
socket->bind(port);
|
||||
socket->beginListen();
|
||||
socket->setNonBlockingMode();
|
||||
logger->notice("BitTorrent: listening to port %d", port);
|
||||
getLogger()->notice("BitTorrent: listening to port %d", port);
|
||||
return true;
|
||||
} catch(RecoverableException& ex) {
|
||||
logger->error(MSG_BIND_FAILURE, ex, util::itos(cuid).c_str(), port);
|
||||
getLogger()->error(MSG_BIND_FAILURE, ex,
|
||||
util::itos(getCuid()).c_str(), port);
|
||||
socket->closeConnection();
|
||||
}
|
||||
}
|
||||
|
@ -128,15 +129,15 @@ bool PeerListenCommand::execute() {
|
|||
Command* command =
|
||||
new ReceiverMSEHandshakeCommand(cuid, peer, e, peerSocket);
|
||||
e->addCommand(command);
|
||||
if(logger->debug()) {
|
||||
logger->debug("Accepted the connection from %s:%u.",
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("Accepted the connection from %s:%u.",
|
||||
peer->ipaddr.c_str(),
|
||||
peer->port);
|
||||
logger->debug("Added CUID#%s to receive BitTorrent/MSE handshake.",
|
||||
getLogger()->debug("Added CUID#%s to receive BitTorrent/MSE handshake.",
|
||||
util::itos(cuid).c_str());
|
||||
}
|
||||
} catch(RecoverableException& ex) {
|
||||
logger->debug(MSG_ACCEPT_FAILURE, ex, util::itos(cuid).c_str());
|
||||
getLogger()->debug(MSG_ACCEPT_FAILURE, ex, util::itos(getCuid()).c_str());
|
||||
}
|
||||
}
|
||||
e->addCommand(this);
|
||||
|
|
|
@ -130,11 +130,11 @@ bool PeerReceiveHandshakeCommand::executeInternal()
|
|||
btRuntime->lessThanMaxPeers()) {
|
||||
if(peerStorage->addPeer(peer)) {
|
||||
|
||||
peer->usedBy(cuid);
|
||||
peer->usedBy(getCuid());
|
||||
|
||||
PeerInteractionCommand* command =
|
||||
new PeerInteractionCommand
|
||||
(cuid,
|
||||
(getCuid(),
|
||||
downloadContext->getOwnerRequestGroup(),
|
||||
peer,
|
||||
e,
|
||||
|
@ -145,9 +145,9 @@ bool PeerReceiveHandshakeCommand::executeInternal()
|
|||
PeerInteractionCommand::RECEIVER_WAIT_HANDSHAKE,
|
||||
_peerConnection);
|
||||
e->addCommand(command);
|
||||
if(logger->debug()) {
|
||||
logger->debug(MSG_INCOMING_PEER_CONNECTION,
|
||||
util::itos(cuid).c_str(),
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug(MSG_INCOMING_PEER_CONNECTION,
|
||||
util::itos(getCuid()).c_str(),
|
||||
util::itos(peer->usedBy()).c_str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,13 +98,15 @@ bool ReceiverMSEHandshakeCommand::executeInternal()
|
|||
break;
|
||||
case MSEHandshake::HANDSHAKE_LEGACY: {
|
||||
if(e->getOption()->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
|
||||
throw DL_ABORT_EX("The legacy BitTorrent handshake is not acceptable by the preference.");
|
||||
throw DL_ABORT_EX
|
||||
("The legacy BitTorrent handshake is not acceptable by the"
|
||||
" preference.");
|
||||
}
|
||||
SharedHandle<PeerConnection> peerConnection
|
||||
(new PeerConnection(cuid, socket));
|
||||
(new PeerConnection(getCuid(), socket));
|
||||
peerConnection->presetBuffer(_mseHandshake->getBuffer(),
|
||||
_mseHandshake->getBufferLength());
|
||||
Command* c = new PeerReceiveHandshakeCommand(cuid, peer, e, socket,
|
||||
Command* c = new PeerReceiveHandshakeCommand(getCuid(), peer, e, socket,
|
||||
peerConnection);
|
||||
e->addCommand(c);
|
||||
return true;
|
||||
|
@ -185,7 +187,7 @@ bool ReceiverMSEHandshakeCommand::executeInternal()
|
|||
void ReceiverMSEHandshakeCommand::createCommand()
|
||||
{
|
||||
SharedHandle<PeerConnection> peerConnection
|
||||
(new PeerConnection(cuid, socket));
|
||||
(new PeerConnection(getCuid(), socket));
|
||||
if(_mseHandshake->getNegotiatedCryptoType() == MSEHandshake::CRYPTO_ARC4) {
|
||||
peerConnection->enableEncryption(_mseHandshake->getEncryptor(),
|
||||
_mseHandshake->getDecryptor());
|
||||
|
@ -198,7 +200,7 @@ void ReceiverMSEHandshakeCommand::createCommand()
|
|||
// as a hint. If this info hash and one in BitTorrent Handshake does not
|
||||
// match, then drop connection.
|
||||
Command* c =
|
||||
new PeerReceiveHandshakeCommand(cuid, peer, e, socket, peerConnection);
|
||||
new PeerReceiveHandshakeCommand(getCuid(), peer, e, socket, peerConnection);
|
||||
e->addCommand(c);
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ bool SeedCheckCommand::execute() {
|
|||
}
|
||||
if(checkStarted) {
|
||||
if(seedCriteria->evaluate()) {
|
||||
logger->notice(MSG_SEEDING_END);
|
||||
getLogger()->notice(MSG_SEEDING_END);
|
||||
_btRuntime->setHalt(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,9 +62,9 @@ void TimedHaltCommand::preProcess()
|
|||
void TimedHaltCommand::process()
|
||||
{
|
||||
if(!_e->isHaltRequested()) {
|
||||
logger->notice(MSG_TIME_HAS_PASSED, _interval);
|
||||
getLogger()->notice(MSG_TIME_HAS_PASSED, _interval);
|
||||
if(_forceHalt) {
|
||||
logger->notice("This is emergency shutdown.");
|
||||
getLogger()->notice("This is emergency shutdown.");
|
||||
_e->requestForceHalt();
|
||||
} else {
|
||||
_e->requestHalt();
|
||||
|
|
|
@ -96,8 +96,8 @@ bool TrackerWatcherCommand::execute() {
|
|||
}
|
||||
}
|
||||
if(_btAnnounce->noMoreAnnounce()) {
|
||||
if(logger->debug()) {
|
||||
logger->debug("no more announce");
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("no more announce");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -108,13 +108,13 @@ bool TrackerWatcherCommand::execute() {
|
|||
try {
|
||||
_trackerRequestGroup->createInitialCommand(commands, e);
|
||||
} catch(RecoverableException& ex) {
|
||||
logger->error(EX_EXCEPTION_CAUGHT, ex);
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, ex);
|
||||
std::for_each(commands.begin(), commands.end(), Deleter());
|
||||
commands.clear();
|
||||
}
|
||||
e->addCommand(commands);
|
||||
if(logger->debug()) {
|
||||
logger->debug("added tracker request command");
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("added tracker request command");
|
||||
}
|
||||
}
|
||||
} else if(_trackerRequestGroup->downloadFinished()){
|
||||
|
@ -125,7 +125,7 @@ bool TrackerWatcherCommand::execute() {
|
|||
_btAnnounce->announceSuccess();
|
||||
_btAnnounce->resetAnnounce();
|
||||
} catch(RecoverableException& ex) {
|
||||
logger->error(EX_EXCEPTION_CAUGHT, ex);
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, ex);
|
||||
_btAnnounce->announceFailure();
|
||||
if(_btAnnounce->isAllAnnounceFailed()) {
|
||||
_btAnnounce->resetAnnounce();
|
||||
|
@ -180,9 +180,9 @@ void TrackerWatcherCommand::processTrackerResponse
|
|||
command->setPeerStorage(_peerStorage);
|
||||
command->setPieceStorage(_pieceStorage);
|
||||
e->addCommand(command);
|
||||
if(logger->debug()) {
|
||||
logger->debug("CUID#%s - Adding new command CUID#%s",
|
||||
util::itos(cuid).c_str(),
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Adding new command CUID#%s",
|
||||
util::itos(getCuid()).c_str(),
|
||||
util::itos(peer->usedBy()).c_str());
|
||||
}
|
||||
}
|
||||
|
@ -222,12 +222,12 @@ TrackerWatcherCommand::createRequestGroup(const std::string& uri)
|
|||
uris.push_back(uri);
|
||||
SharedHandle<RequestGroup> rg(new RequestGroup(getOption()));
|
||||
if(backupTrackerIsAvailable(_requestGroup->getDownloadContext())) {
|
||||
if(logger->debug()) {
|
||||
logger->debug("This is multi-tracker announce.");
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("This is multi-tracker announce.");
|
||||
}
|
||||
} else {
|
||||
if(logger->debug()) {
|
||||
logger->debug("This is single-tracker announce.");
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("This is single-tracker announce.");
|
||||
}
|
||||
}
|
||||
// If backup tracker is available, try 2 times for each tracker
|
||||
|
@ -253,8 +253,8 @@ TrackerWatcherCommand::createRequestGroup(const std::string& uri)
|
|||
rg->setFileAllocationEnabled(false);
|
||||
rg->setPreLocalFileCheckEnabled(false);
|
||||
util::removeMetalinkContentTypes(rg);
|
||||
if(logger->info()) {
|
||||
logger->info("Creating tracker request group GID#%s",
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info("Creating tracker request group GID#%s",
|
||||
util::itos(rg->getGID()).c_str());
|
||||
}
|
||||
return rg;
|
||||
|
|
Loading…
Reference in New Issue