From 9afc36152a1ce428243a3ace608d0508716a2efb Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 8 Jun 2010 15:02:20 +0000 Subject: [PATCH] 2010-06-09 Tatsuhiro Tsujikawa Made protected member variables of Command private. Added accessor funcs. --- ChangeLog | 5 + src/AbstractCommand.cc | 214 +++++++++++++------------ src/ActivePeerConnectionCommand.cc | 6 +- src/BtStopDownloadCommand.cc | 6 +- src/CheckIntegrityCommand.cc | 20 ++- src/CheckIntegrityDispatcherCommand.cc | 7 +- src/Command.cc | 12 +- src/Command.h | 43 +++-- src/CreateRequestCommand.cc | 13 +- src/DHTAutoSaveCommand.cc | 15 +- src/DHTEntryPointNameResolveCommand.cc | 42 ++--- src/DHTGetPeersCommand.cc | 8 +- src/DHTInteractionCommand.cc | 2 +- src/DHTPeerAnnounceCommand.cc | 2 +- src/DHTTokenUpdateCommand.cc | 2 +- src/DownloadCommand.cc | 66 ++++---- src/FileAllocationCommand.cc | 17 +- src/FileAllocationDispatcherCommand.cc | 5 +- src/FillRequestGroupCommand.cc | 2 +- src/FtpDownloadCommand.cc | 7 +- src/FtpFinishDownloadCommand.cc | 2 +- src/FtpInitiateConnectionCommand.cc | 28 ++-- src/FtpNegotiationCommand.cc | 94 ++++++----- src/FtpTunnelRequestCommand.cc | 2 +- src/FtpTunnelResponseCommand.cc | 2 +- src/HttpDownloadCommand.cc | 2 +- src/HttpInitiateConnectionCommand.cc | 27 ++-- src/HttpListenCommand.cc | 22 +-- src/HttpProxyRequestCommand.cc | 2 +- src/HttpProxyResponseCommand.cc | 2 +- src/HttpRequestCommand.cc | 2 +- src/HttpResponseCommand.cc | 35 ++-- src/HttpServerBodyCommand.cc | 11 +- src/HttpServerCommand.cc | 20 +-- src/HttpServerResponseCommand.cc | 27 ++-- src/HttpSkipResponseCommand.cc | 4 +- src/InitiateConnectionCommand.cc | 10 +- src/InitiatorMSEHandshakeCommand.cc | 24 +-- src/LpdDispatchMessageCommand.cc | 10 +- src/LpdReceiveMessageCommand.cc | 27 ++-- src/PeerAbstractCommand.cc | 34 ++-- src/PeerInitiateConnectionCommand.cc | 13 +- src/PeerListenCommand.cc | 19 +-- src/PeerReceiveHandshakeCommand.cc | 12 +- src/ReceiverMSEHandshakeCommand.cc | 12 +- src/SeedCheckCommand.cc | 2 +- src/TimedHaltCommand.cc | 4 +- src/TrackerWatcherCommand.cc | 34 ++-- 48 files changed, 541 insertions(+), 436 deletions(-) diff --git a/ChangeLog b/ChangeLog index 54410146..8993df88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-06-09 Tatsuhiro Tsujikawa + + Made protected member variables of Command private. Added accessor + funcs. + 2010-06-08 Tatsuhiro Tsujikawa Made public member variables of DownloadEngine private. Added diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index 10423400..1973020d 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -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,39 +127,42 @@ bool AbstractCommand::execute() { !_requestGroup->getPieceStorage()->hasMissingUnusedPiece()) { SharedHandle 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(), - fasterRequest->getHost().c_str(), - fasterRequest->getPort()); + 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()); } // Cancel current Request object and use faster one. _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 = - _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, - DL_ABORT_EX2(StringFormat - ("URI=%s", req->getCurrentUri().c_str()).str(),err), - util::itos(cuid).c_str(), req->getUri().c_str()); + getLogger()->error + (MSG_DOWNLOAD_ABORTED, + DL_ABORT_EX2(StringFormat + ("URI=%s", req->getCurrentUri().c_str()).str(),err), + 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,23 +244,26 @@ bool AbstractCommand::execute() { return true; } catch(DlRetryEx& err) { assert(!req.isNull()); - if(logger->info()) { - logger->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()); + if(getLogger()->info()) { + getLogger()->info + (MSG_RESTARTING_DOWNLOAD, + DL_RETRY_EX2(StringFormat + ("URI=%s", req->getCurrentUri().c_str()).str(), + err), + 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(), - req->getUri().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()); if(err.getCode() == downloadresultcode::CANNOT_RESUME) { @@ -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." - " No reserved/pooled request is remaining and" - " total length is still unknown.", - util::itos(cuid).c_str()); + 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(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 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 = _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." - " 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()); + getLogger()->notice("CUID#%s - Failed to resume download." + " Download from scratch.", + 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,10 +390,10 @@ 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(), - static_cast(uris.size())); + if(getLogger()->debug()) { + getLogger()->debug("CUID#%s - %lu URIs found.", + util::itos(getCuid()).c_str(), + static_cast(uris.size())); } _fileEntry->addUris(uris.begin(), uris.end()); segmentMan->recognizeSegmentFor(_fileEntry); @@ -571,13 +584,14 @@ SharedHandle 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,10 +629,11 @@ 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(), - _asyncNameResolver->getHostname().c_str(), - _asyncNameResolver->getError().c_str()).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: return false; } @@ -678,10 +693,11 @@ std::string AbstractCommand::resolveHostname } res.resolve(addrs, hostname); } - if(logger->info()) { - logger->info(MSG_NAME_RESOLUTION_COMPLETE, util::itos(cuid).c_str(), - hostname.c_str(), - strjoin(addrs.begin(), addrs.end(), ", ").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()); } for(std::vector::const_iterator i = addrs.begin(), eoi = addrs.end(); i != eoi; ++i) { @@ -690,10 +706,10 @@ 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(), - strjoin(addrs.begin(), addrs.end(), ", ").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()); } } return ipaddr; @@ -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(), - connectedAddr.c_str(), connectedPort); + 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; diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc index 361e1097..32996b5d 100644 --- a/src/ActivePeerConnectionCommand.cc +++ b/src/ActivePeerConnectionCommand.cc @@ -145,9 +145,9 @@ void ActivePeerConnectionCommand::connectToPeer(const SharedHandle& 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()); } } diff --git a/src/BtStopDownloadCommand.cc b/src/BtStopDownloadCommand.cc index 2503b1fc..8f397ef3 100644 --- a/src/BtStopDownloadCommand.cc +++ b/src/BtStopDownloadCommand.cc @@ -60,9 +60,9 @@ void BtStopDownloadCommand::preProcess() _exit = true; } if(_checkPoint.difference(global::wallclock) >= _timeout) { - logger->notice("GID#%s Stop downloading torrent due to" - " --bt-stop-timeout option.", - util::itos(_requestGroup->getGID()).c_str()); + getLogger()->notice("GID#%s Stop downloading torrent due to" + " --bt-stop-timeout option.", + util::itos(_requestGroup->getGID()).c_str()); _requestGroup->setHaltRequested(true); _exit = true; } diff --git a/src/CheckIntegrityCommand.cc b/src/CheckIntegrityCommand.cc index ed5b8e8c..32748488 100644 --- a/src/CheckIntegrityCommand.cc +++ b/src/CheckIntegrityCommand.cc @@ -72,8 +72,9 @@ bool CheckIntegrityCommand::executeInternal() // needed. _requestGroup->enableSaveControlFile(); if(_requestGroup->downloadFinished()) { - logger->notice(MSG_VERIFICATION_SUCCESSFUL, - _requestGroup->getDownloadContext()->getBasePath().c_str()); + getLogger()->notice + (MSG_VERIFICATION_SUCCESSFUL, + _requestGroup->getDownloadContext()->getBasePath().c_str()); std::vector commands; try { _entry->onDownloadFinished(commands, _e); @@ -83,8 +84,9 @@ bool CheckIntegrityCommand::executeInternal() } _e->addCommand(commands); } else { - logger->error(MSG_VERIFICATION_FAILED, - _requestGroup->getDownloadContext()->getBasePath().c_str()); + getLogger()->error + (MSG_VERIFICATION_FAILED, + _requestGroup->getDownloadContext()->getBasePath().c_str()); std::vector commands; try { _entry->onDownloadIncomplete(commands,_e); @@ -105,10 +107,12 @@ 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(), - _requestGroup->getDownloadContext()->getBasePath().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; } diff --git a/src/CheckIntegrityDispatcherCommand.cc b/src/CheckIntegrityDispatcherCommand.cc index 5ab70128..388253e2 100644 --- a/src/CheckIntegrityDispatcherCommand.cc +++ b/src/CheckIntegrityDispatcherCommand.cc @@ -57,9 +57,10 @@ Command* CheckIntegrityDispatcherCommand::createCommand (const SharedHandle& 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); diff --git a/src/Command.cc b/src/Command.cc index 03d4b66d..42ac5b37 100644 --- a/src/Command.cc +++ b/src/Command.cc @@ -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() diff --git a/src/Command.h b/src/Command.h index 3b2377dd..1a10f24b 100644 --- a/src/Command.h +++ b/src/Command.h @@ -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(); diff --git a/src/CreateRequestCommand.cc b/src/CreateRequestCommand.cc index 15dd3431..40a6c6f6 100644 --- a/src/CreateRequestCommand.cc +++ b/src/CreateRequestCommand.cc @@ -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; } diff --git a/src/DHTAutoSaveCommand.cc b/src/DHTAutoSaveCommand.cc index 47f8fb0a..78d4fc7e 100644 --- a/src/DHTAutoSaveCommand.cc +++ b/src/DHTAutoSaveCommand.cc @@ -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,12 +128,12 @@ void DHTAutoSaveCommand::save() serializer.serialize(o); } if(!File(tempFile).renameTo(dhtFile)) { - logger->error("Cannot move file from %s to %s.", - tempFile.c_str(), dhtFile.c_str()); + 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", - e, dhtFile.c_str()); + getLogger()->error("Exception caught while saving DHT routing table to %s", + e, dhtFile.c_str()); } } diff --git a/src/DHTEntryPointNameResolveCommand.cc b/src/DHTEntryPointNameResolveCommand.cc index e4e83ca6..38ed3b36 100644 --- a/src/DHTEntryPointNameResolveCommand.cc +++ b/src/DHTEntryPointNameResolveCommand.cc @@ -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& addr) +void DHTEntryPointNameResolveCommand::addPingTask +(const std::pair& addr) { SharedHandle entryNode(new DHTNode()); entryNode->setIPAddress(addr.first); @@ -154,26 +156,26 @@ 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(), - resolver->getHostname().c_str(), - resolver->getResolvedAddresses().front().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()); } return true; break; 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& taskQueue) +void DHTEntryPointNameResolveCommand::setTaskQueue +(const SharedHandle& taskQueue) { _taskQueue = taskQueue; } -void DHTEntryPointNameResolveCommand::setTaskFactory(const SharedHandle& taskFactory) +void DHTEntryPointNameResolveCommand::setTaskFactory +(const SharedHandle& taskFactory) { _taskFactory = taskFactory; } -void DHTEntryPointNameResolveCommand::setRoutingTable(const SharedHandle& routingTable) +void DHTEntryPointNameResolveCommand::setRoutingTable +(const SharedHandle& routingTable) { _routingTable = routingTable; } -void DHTEntryPointNameResolveCommand::setLocalNode(const SharedHandle& localNode) +void DHTEntryPointNameResolveCommand::setLocalNode +(const SharedHandle& localNode) { _localNode = localNode; } diff --git a/src/DHTGetPeersCommand.cc b/src/DHTGetPeersCommand.cc index d8e13bd1..298f81e3 100644 --- a/src/DHTGetPeersCommand.cc +++ b/src/DHTGetPeersCommand.cc @@ -80,10 +80,10 @@ 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", - bittorrent::getInfoHashString - (_requestGroup->getDownloadContext()).c_str()); + if(getLogger()->debug()) { + getLogger()->debug("Issuing PeerLookup for infoHash=%s", + bittorrent::getInfoHashString + (_requestGroup->getDownloadContext()).c_str()); } _task = _taskFactory->createPeerLookupTask (_requestGroup->getDownloadContext(), _btRuntime, _peerStorage); diff --git a/src/DHTInteractionCommand.cc b/src/DHTInteractionCommand.cc index 5e8be604..2302cc17 100644 --- a/src/DHTInteractionCommand.cc +++ b/src/DHTInteractionCommand.cc @@ -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; diff --git a/src/DHTPeerAnnounceCommand.cc b/src/DHTPeerAnnounceCommand.cc index 9831c026..f2b81f8c 100644 --- a/src/DHTPeerAnnounceCommand.cc +++ b/src/DHTPeerAnnounceCommand.cc @@ -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); } } diff --git a/src/DHTTokenUpdateCommand.cc b/src/DHTTokenUpdateCommand.cc index 16e73fb5..ea57e335 100644 --- a/src/DHTTokenUpdateCommand.cc +++ b/src/DHTTokenUpdateCommand.cc @@ -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); } } diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index 1a0c4740..96b12d97 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -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(_fileEntry->getLastOffset()-segment->getPositionToWrite()), BUFSIZE); + bufSize = + std::min(static_cast + (_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,43 +211,48 @@ 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", - static_cast(segment->getIndex())); + if(getLogger()->debug()) { + getLogger()->debug + ("Hash is available! index=%lu", + static_cast(segment->getIndex())); } - validatePieceHash(segment, expectedPieceHash, segment->getHashString()); + validatePieceHash + (segment, expectedPieceHash, segment->getHashString()); } else { _messageDigestContext->digestReset(); - validatePieceHash(segment, expectedPieceHash, - MessageDigestHelper::digest - (_messageDigestContext.get(), - _requestGroup->getPieceStorage()->getDiskAdaptor(), - segment->getPosition(), - segment->getLength())); + validatePieceHash + (segment, expectedPieceHash, + MessageDigestHelper::digest + (_messageDigestContext.get(), + _requestGroup->getPieceStorage()->getDiskAdaptor(), + segment->getPosition(), + 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 = _requestGroup->getSegmentMan(); SharedHandle 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, 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, - segment->getIndex(), - util::itos(segment->getPosition(), true).c_str(), - expectedPieceHash.c_str(), - actualPieceHash.c_str()); + 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()); } diff --git a/src/FileAllocationCommand.cc b/src/FileAllocationCommand.cc index 94c2dd87..7e615c95 100644 --- a/src/FileAllocationCommand.cc +++ b/src/FileAllocationCommand.cc @@ -68,10 +68,11 @@ bool FileAllocationCommand::executeInternal() } _fileAllocationEntry->allocateChunk(); if(_fileAllocationEntry->finished()) { - if(logger->debug()) { - logger->debug(MSG_ALLOCATION_COMPLETED, - _timer.difference(global::wallclock), - util::itos(_requestGroup->getTotalLength(), true).c_str()); + if(getLogger()->debug()) { + getLogger()->debug + (MSG_ALLOCATION_COMPLETED, + _timer.difference(global::wallclock), + util::itos(_requestGroup->getTotalLength(), true).c_str()); } _e->getFileAllocationMan()->dropPickedEntry(); @@ -94,9 +95,11 @@ 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(), - _requestGroup->getDownloadContext()->getBasePath().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; } diff --git a/src/FileAllocationDispatcherCommand.cc b/src/FileAllocationDispatcherCommand.cc index a8e08167..cb41f60d 100644 --- a/src/FileAllocationDispatcherCommand.cc +++ b/src/FileAllocationDispatcherCommand.cc @@ -54,8 +54,9 @@ Command* FileAllocationDispatcherCommand::createCommand (const SharedHandle& 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); diff --git a/src/FillRequestGroupCommand.cc b/src/FillRequestGroupCommand.cc index d3157a76..f9bc38b0 100644 --- a/src/FillRequestGroupCommand.cc +++ b/src/FillRequestGroupCommand.cc @@ -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(); diff --git a/src/FtpDownloadCommand.cc b/src/FtpDownloadCommand.cc index 8d4cc556..cb735f3a 100644 --- a/src/FtpDownloadCommand.cc +++ b/src/FtpDownloadCommand.cc @@ -70,9 +70,12 @@ FtpDownloadCommand::~FtpDownloadCommand() {} bool FtpDownloadCommand::prepareForNextSegment() { if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION) && - static_cast(_fileEntry->gtoloff(_segments.front()->getPositionToWrite())) == _fileEntry->getLength()) { + static_cast + (_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()) { diff --git a/src/FtpFinishDownloadCommand.cc b/src/FtpFinishDownloadCommand.cc index 23ba5d99..e143743a 100644 --- a/src/FtpFinishDownloadCommand.cc +++ b/src/FtpFinishDownloadCommand.cc @@ -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; diff --git a/src/FtpInitiateConnectionCommand.cc b/src/FtpInitiateConnectionCommand.cc index fad8b94d..3fd52954 100644 --- a/src/FtpInitiateConnectionCommand.cc +++ b/src/FtpInitiateConnectionCommand.cc @@ -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 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 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"]); diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc index b91ccb3a..303de573 100644 --- a/src/FtpNegotiationCommand.cc +++ b/src/FtpNegotiationCommand.cc @@ -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,9 +388,9 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength) _requestGroup->getPieceStorage()->markAllPiecesDone(); sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED; - logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED, - util::itos(_requestGroup->getGID()).c_str(), - _requestGroup->getFirstFilePath().c_str()); + getLogger()->notice(MSG_DOWNLOAD_ALREADY_COMPLETED, + util::itos(_requestGroup->getGID()).c_str(), + _requestGroup->getFirstFilePath().c_str()); poolConnection(); @@ -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,15 +424,18 @@ 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, - util::itos(_requestGroup->getGID()).c_str(), - _requestGroup->getFirstFilePath().c_str()); + getLogger()->notice(MSG_DOWNLOAD_ALREADY_COMPLETED, + util::itos(_requestGroup->getGID()).c_str(), + _requestGroup->getFirstFilePath().c_str()); poolConnection(); @@ -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,10 +562,10 @@ 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(), - dest.first.c_str(), - dest.second); + if(getLogger()->info()) { + getLogger()->info(MSG_CONNECTING_TO_SERVER, util::itos(getCuid()).c_str(), + dest.first.c_str(), + dest.second); } dataSocket.reset(new SocketCore()); dataSocket->establishConnection(dest.first, 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(), - _proxyAddr.c_str(), proxyReq->getPort()); + 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,15 +614,16 @@ 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(), - _proxyAddr.c_str(), proxyReq->getPort()); + 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(), - _proxyAddr.c_str(), proxyReq->getPort()); + if(getLogger()->info()) { + getLogger()->info(MSG_CONNECTING_TO_SERVER, + util::itos(getCuid()).c_str(), + _proxyAddr.c_str(), proxyReq->getPort()); } dataSocket->establishConnection(_proxyAddr, proxyReq->getPort()); return false; diff --git a/src/FtpTunnelRequestCommand.cc b/src/FtpTunnelRequestCommand.cc index 613e144d..2fcfbcd3 100644 --- a/src/FtpTunnelRequestCommand.cc +++ b/src/FtpTunnelRequestCommand.cc @@ -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 diff --git a/src/FtpTunnelResponseCommand.cc b/src/FtpTunnelResponseCommand.cc index 61f85588..d1d1afb1 100644 --- a/src/FtpTunnelResponseCommand.cc +++ b/src/FtpTunnelResponseCommand.cc @@ -59,7 +59,7 @@ FtpTunnelResponseCommand::~FtpTunnelResponseCommand() {} Command* FtpTunnelResponseCommand::getNextCommand() { - return new FtpNegotiationCommand(cuid, req, _fileEntry, + return new FtpNegotiationCommand(getCuid(), req, _fileEntry, _requestGroup, e, socket); } diff --git a/src/HttpDownloadCommand.cc b/src/HttpDownloadCommand.cc index 5816b13a..3121da3f 100644 --- a/src/HttpDownloadCommand.cc +++ b/src/HttpDownloadCommand.cc @@ -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 diff --git a/src/HttpInitiateConnectionCommand.cc b/src/HttpInitiateConnectionCommand.cc index b16b9d8c..c940a071 100644 --- a/src/HttpInitiateConnectionCommand.cc +++ b/src/HttpInitiateConnectionCommand.cc @@ -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 - (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 - (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 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(new HttpConnection(cuid, socket, getOption().get())); + SharedHandle 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); diff --git a/src/HttpListenCommand.cc b/src/HttpListenCommand.cc index 4c0b5529..d690391b 100644 --- a/src/HttpListenCommand.cc +++ b/src/HttpListenCommand.cc @@ -74,8 +74,8 @@ bool HttpListenCommand::execute() std::pair peerInfo; socket->getPeerInfo(peerInfo); - logger->info("XML-RPC: Accepted the connection from %s:%u.", - peerInfo.first.c_str(), peerInfo.second); + getLogger()->info("XML-RPC: Accepted the connection from %s:%u.", + peerInfo.first.c_str(), peerInfo.second); HttpServerCommand* c = new HttpServerCommand(_e->newCUID(), _e, socket); @@ -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); } diff --git a/src/HttpProxyRequestCommand.cc b/src/HttpProxyRequestCommand.cc index 677c0bda..7de74682 100644 --- a/src/HttpProxyRequestCommand.cc +++ b/src/HttpProxyRequestCommand.cc @@ -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 diff --git a/src/HttpProxyResponseCommand.cc b/src/HttpProxyResponseCommand.cc index efcb809d..b577017f 100644 --- a/src/HttpProxyResponseCommand.cc +++ b/src/HttpProxyResponseCommand.cc @@ -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); } diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc index fa377b43..85b2a244 100644 --- a/src/HttpRequestCommand.cc +++ b/src/HttpRequestCommand.cc @@ -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); diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index fce986ed..02991f7d 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -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,13 +227,16 @@ 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, - util::itos(_requestGroup->getGID()).c_str(), - _requestGroup->getFirstFilePath().c_str()); + getLogger()->notice(MSG_DOWNLOAD_ALREADY_COMPLETED, + util::itos(_requestGroup->getGID()).c_str(), + _requestGroup->getFirstFilePath().c_str()); return true; } @@ -242,7 +246,7 @@ bool HttpResponseCommand::handleDefaultEncoding // have segment after PieceStorage is initialized. See // AbstractCommand::execute() SharedHandle 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,9 +330,9 @@ bool HttpResponseCommand::handleOtherEncoding _requestGroup->initPieceStorage(); _requestGroup->getPieceStorage()->markAllPiecesDone(); - logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED, - util::itos(_requestGroup->getGID()).c_str(), - _requestGroup->getFirstFilePath().c_str()); + getLogger()->notice(MSG_DOWNLOAD_ALREADY_COMPLETED, + util::itos(_requestGroup->getGID()).c_str(), + _requestGroup->getFirstFilePath().c_str()); poolConnection(); return true; @@ -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 diff --git a/src/HttpServerBodyCommand.cc b/src/HttpServerBodyCommand.cc index 5067a843..6c8c8e40 100644 --- a/src/HttpServerBodyCommand.cc +++ b/src/HttpServerBodyCommand.cc @@ -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; } diff --git a/src/HttpServerCommand.cc b/src/HttpServerCommand.cc index 87ea8fb0..06521cbb 100644 --- a/src/HttpServerCommand.cc +++ b/src/HttpServerCommand.cc @@ -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 (_e->getOption()->getAsInt(PREF_XML_RPC_MAX_REQUEST_SIZE)) < _httpServer->getContentLength()) { - logger->info("Request too long. ContentLength=%s." - " See --xml-rpc-max-request-size option to loose" - " this limitation.", - util::uitos(_httpServer->getContentLength()).c_str()); + 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; } diff --git a/src/HttpServerResponseCommand.cc b/src/HttpServerResponseCommand.cc index dd464a97..4b98b193 100644 --- a/src/HttpServerResponseCommand.cc +++ b/src/HttpServerResponseCommand.cc @@ -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 { diff --git a/src/HttpSkipResponseCommand.cc b/src/HttpSkipResponseCommand.cc index 51dbfebf..974b4a82 100644 --- a/src/HttpSkipResponseCommand.cc +++ b/src/HttpSkipResponseCommand.cc @@ -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(); } diff --git a/src/InitiateConnectionCommand.cc b/src/InitiateConnectionCommand.cc index 05729419..6ef9e9c2 100644 --- a/src/InitiateConnectionCommand.cc +++ b/src/InitiateConnectionCommand.cc @@ -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; diff --git a/src/InitiatorMSEHandshakeCommand.cc b/src/InitiatorMSEHandshakeCommand.cc index 062199ca..6756b34f 100644 --- a/src/InitiatorMSEHandshakeCommand.cc +++ b/src/InitiatorMSEHandshakeCommand.cc @@ -150,14 +150,15 @@ bool InitiatorMSEHandshakeCommand::executeInternal() { case INITIATOR_RECEIVE_PAD_D: { if(_mseHandshake->receivePad()) { SharedHandle 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" - " handshake is disabled by preference.", - util::itos(cuid).c_str()); + if(getLogger()->info()) { + getLogger()->info + ("CUID#%s - Establishing connection using legacy BitTorrent" + " handshake is disabled by preference.", + util::itos(getCuid()).c_str()); } if(_peerStorage->isPeerAvailable() && _btRuntime->lessThanEqMinPeers()) { SharedHandle 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); diff --git a/src/LpdDispatchMessageCommand.cc b/src/LpdDispatchMessageCommand.cc index fd7c350e..778baf46 100644 --- a/src/LpdDispatchMessageCommand.cc +++ b/src/LpdDispatchMessageCommand.cc @@ -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; } diff --git a/src/LpdReceiveMessageCommand.cc b/src/LpdReceiveMessageCommand.cc index b067e760..7bc14be5 100644 --- a/src/LpdReceiveMessageCommand.cc +++ b/src/LpdReceiveMessageCommand.cc @@ -94,17 +94,18 @@ bool LpdReceiveMessageCommand::execute() SharedHandle dctx = reg->getDownloadContext(m->getInfoHash()); if(dctx.isNull()) { - if(logger->debug()) { - logger->debug("Download Context is null for infohash=%s.", - util::toHex(m->getInfoHash()).c_str()); + if(getLogger()->debug()) { + getLogger()->debug("Download Context is null for infohash=%s.", + util::toHex(m->getInfoHash()).c_str()); } continue; } 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,16 +118,16 @@ bool LpdReceiveMessageCommand::execute() assert(!peerStorage.isNull()); SharedHandle peer = m->getPeer(); if(peerStorage->addPeer(peer)) { - if(logger->debug()) { - logger->debug("LPD peer %s:%u local=%d added.", - peer->ipaddr.c_str(), peer->port, - peer->isLocalPeer()?1:0); + 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.", - peer->ipaddr.c_str(), peer->port, - peer->isLocalPeer()?1:0); + if(getLogger()->debug()) { + getLogger()->debug("LPD peer %s:%u local=%d not added.", + peer->ipaddr.c_str(), peer->port, + peer->isLocalPeer()?1:0); } } } diff --git a/src/PeerAbstractCommand.cc b/src/PeerAbstractCommand.cc index 0259ee08..e9071b77 100644 --- a/src/PeerAbstractCommand.cc +++ b/src/PeerAbstractCommand.cc @@ -81,12 +81,13 @@ PeerAbstractCommand::~PeerAbstractCommand() bool PeerAbstractCommand::execute() { - if(logger->debug()) { - logger->debug("CUID#%s -" - " socket: read:%d, write:%d, hup:%d, err:%d, noCheck:%d", - util::itos(cuid).c_str(), - _readEvent, _writeEvent, _hupEvent, _errorEvent, - noCheck); + if(getLogger()->debug()) { + getLogger()->debug("CUID#%s -" + " socket: read:%d, write:%d, hup:%d, err:%d, noCheck:%d", + util::itos(getCuid()).c_str(), + readEventEnabled(), writeEventEnabled(), + hupEventEnabled(), errorEventEnabled(), + noCheck); } if(exitBeforeExecute()) { onAbort(); @@ -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); diff --git a/src/PeerInitiateConnectionCommand.cc b/src/PeerInitiateConnectionCommand.cc index 8374222a..30b83768 100644 --- a/src/PeerInitiateConnectionCommand.cc +++ b/src/PeerInitiateConnectionCommand.cc @@ -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(), - peer->port); + 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); } diff --git a/src/PeerListenCommand.cc b/src/PeerListenCommand.cc index 133845d7..2d9eacc3 100644 --- a/src/PeerListenCommand.cc +++ b/src/PeerListenCommand.cc @@ -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.", - peer->ipaddr.c_str(), - peer->port); - logger->debug("Added CUID#%s to receive BitTorrent/MSE handshake.", - util::itos(cuid).c_str()); + if(getLogger()->debug()) { + getLogger()->debug("Accepted the connection from %s:%u.", + peer->ipaddr.c_str(), + peer->port); + 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); diff --git a/src/PeerReceiveHandshakeCommand.cc b/src/PeerReceiveHandshakeCommand.cc index 323fb9f7..341cbc8e 100644 --- a/src/PeerReceiveHandshakeCommand.cc +++ b/src/PeerReceiveHandshakeCommand.cc @@ -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,10 +145,10 @@ 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(), - util::itos(peer->usedBy()).c_str()); + if(getLogger()->debug()) { + getLogger()->debug(MSG_INCOMING_PEER_CONNECTION, + util::itos(getCuid()).c_str(), + util::itos(peer->usedBy()).c_str()); } } } diff --git a/src/ReceiverMSEHandshakeCommand.cc b/src/ReceiverMSEHandshakeCommand.cc index 822da7ff..5edf1030 100644 --- a/src/ReceiverMSEHandshakeCommand.cc +++ b/src/ReceiverMSEHandshakeCommand.cc @@ -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 - (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 - (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); } diff --git a/src/SeedCheckCommand.cc b/src/SeedCheckCommand.cc index e7515fd6..5e3a4528 100644 --- a/src/SeedCheckCommand.cc +++ b/src/SeedCheckCommand.cc @@ -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); } } diff --git a/src/TimedHaltCommand.cc b/src/TimedHaltCommand.cc index fc0a3b99..1921466f 100644 --- a/src/TimedHaltCommand.cc +++ b/src/TimedHaltCommand.cc @@ -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(); diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc index 9426e4a4..38829411 100644 --- a/src/TrackerWatcherCommand.cc +++ b/src/TrackerWatcherCommand.cc @@ -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,10 +180,10 @@ 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(), - util::itos(peer->usedBy()).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 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,9 +253,9 @@ 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", - util::itos(rg->getGID()).c_str()); + if(getLogger()->info()) { + getLogger()->info("Creating tracker request group GID#%s", + util::itos(rg->getGID()).c_str()); } return rg; }