2010-11-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Rewritten Logger interface. Logger now writes source file name and
	line number in log file.
pull/1/head
Tatsuhiro Tsujikawa 2010-11-20 08:21:36 +00:00
parent 3940da7562
commit 580098eb49
197 changed files with 2063 additions and 2704 deletions

View File

@ -1,3 +1,8 @@
2010-11-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten Logger interface. Logger now writes source file name and
line number in log file.
2010-11-18 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2010-11-18 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Made DHTBucketTreeNode non-copyable. Made DHTBucketTreeNode non-copyable.

View File

@ -36,24 +36,21 @@
#include "Peer.h" #include "Peer.h"
#include "PieceStorage.h" #include "PieceStorage.h"
#include "BtMessageValidator.h" #include "BtMessageValidator.h"
#include "LogFactory.h"
#include "Logger.h"
namespace aria2 { namespace aria2 {
AbstractBtMessage::AbstractBtMessage(uint8_t id, const std::string& name): AbstractBtMessage::AbstractBtMessage(uint8_t id, const std::string& name)
BtMessage(id), : BtMessage(id),
sendingInProgress_(false), sendingInProgress_(false),
invalidate_(false), invalidate_(false),
uploading_(false), uploading_(false),
cuid_(0), cuid_(0),
name_(name), name_(name),
dispatcher_(0), dispatcher_(0),
messageFactory_(0), messageFactory_(0),
requestFactory_(0), requestFactory_(0),
peerConnection_(0), peerConnection_(0),
metadataGetMode_(false), metadataGetMode_(false)
logger_(LogFactory::getInstance())
{} {}
AbstractBtMessage::~AbstractBtMessage() {} AbstractBtMessage::~AbstractBtMessage() {}

View File

@ -47,7 +47,6 @@ class BtMessageFactory;
class BtRequestFactory; class BtRequestFactory;
class PeerConnection; class PeerConnection;
class BtMessageValidator; class BtMessageValidator;
class Logger;
class AbstractBtMessage : public BtMessage { class AbstractBtMessage : public BtMessage {
private: private:
@ -73,14 +72,7 @@ private:
SharedHandle<BtMessageValidator> validator_; SharedHandle<BtMessageValidator> validator_;
bool metadataGetMode_; bool metadataGetMode_;
Logger* logger_;
protected: protected:
Logger* getLogger() const
{
return logger_;
}
const SharedHandle<PieceStorage>& getPieceStorage() const const SharedHandle<PieceStorage>& getPieceStorage() const
{ {
return pieceStorage_; return pieceStorage_;

View File

@ -55,6 +55,7 @@
#include "message.h" #include "message.h"
#include "prefs.h" #include "prefs.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
#include "ServerStat.h" #include "ServerStat.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "A2STR.h" #include "A2STR.h"
@ -113,24 +114,20 @@ AbstractCommand::~AbstractCommand() {
} }
bool AbstractCommand::execute() { bool AbstractCommand::execute() {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("CUID#%s - socket: read:%d, write:%d, hup:%d, err:%d",
getLogger()->debug("CUID#%s - socket: read:%d, write:%d, hup:%d, err:%d", util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), readEventEnabled(),
readEventEnabled(), writeEventEnabled(),
writeEventEnabled(), hupEventEnabled(),
hupEventEnabled(), errorEventEnabled()));
errorEventEnabled());
}
try { try {
if(requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) { if(requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) {
return true; return true;
} }
if(req_ && req_->removalRequested()) { if(req_ && req_->removalRequested()) {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("CUID#%s - Discard original URI=%s because it is"
getLogger()->debug " requested.",
("CUID#%s - Discard original URI=%s because it is requested.", util::itos(getCuid()).c_str(), req_->getUri().c_str()));
util::itos(getCuid()).c_str(), req_->getUri().c_str());
}
return prepareForRetry(0); return prepareForRetry(0);
} }
if(getPieceStorage()) { if(getPieceStorage()) {
@ -140,11 +137,9 @@ bool AbstractCommand::execute() {
// This command previously has assigned segments, but it is // This command previously has assigned segments, but it is
// canceled. So discard current request chain. Plus, if no // canceled. So discard current request chain. Plus, if no
// segment is available when http pipelining is used. // segment is available when http pipelining is used.
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("CUID#%s - It seems previously assigned segments"
getLogger()->debug("CUID#%s - It seems previously assigned segments" " are canceled. Restart.",
" are canceled. Restart.", util::itos(getCuid()).c_str()));
util::itos(getCuid()).c_str());
}
// Request::isPipeliningEnabled() == true means aria2 // Request::isPipeliningEnabled() == true means aria2
// accessed the remote server and discovered that the server // accessed the remote server and discovered that the server
// supports pipelining. // supports pipelining.
@ -159,12 +154,10 @@ bool AbstractCommand::execute() {
!getPieceStorage()->hasMissingUnusedPiece()) { !getPieceStorage()->hasMissingUnusedPiece()) {
SharedHandle<Request> fasterRequest = fileEntry_->findFasterRequest(req_); SharedHandle<Request> fasterRequest = fileEntry_->findFasterRequest(req_);
if(fasterRequest) { if(fasterRequest) {
if(getLogger()->info()) { A2_LOG_INFO(fmt("CUID#%s - Use faster Request hostname=%s, port=%u",
getLogger()->info("CUID#%s - Use faster Request hostname=%s, port=%u", util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), fasterRequest->getHost().c_str(),
fasterRequest->getHost().c_str(), fasterRequest->getPort()));
fasterRequest->getPort());
}
// Cancel current Request object and use faster one. // Cancel current Request object and use faster one.
fileEntry_->removeRequest(req_); fileEntry_->removeRequest(req_);
Command* command = Command* command =
@ -206,16 +199,12 @@ bool AbstractCommand::execute() {
// TODO socket could be pooled here if pipelining is // TODO socket could be pooled here if pipelining is
// enabled... Hmm, I don't think if pipelining is enabled // enabled... Hmm, I don't think if pipelining is enabled
// it does not go here. // it does not go here.
if(getLogger()->info()) { A2_LOG_INFO(fmt(MSG_NO_SEGMENT_AVAILABLE,
getLogger()->info(MSG_NO_SEGMENT_AVAILABLE, util::itos(getCuid()).c_str()));
util::itos(getCuid()).c_str());
}
// When all segments are ignored in SegmentMan, there are // When all segments are ignored in SegmentMan, there are
// no URIs available, so don't retry. // no URIs available, so don't retry.
if(getSegmentMan()->allSegmentsIgnored()) { if(getSegmentMan()->allSegmentsIgnored()) {
if(getLogger()->debug()) { A2_LOG_DEBUG("All segments are ignored.");
getLogger()->debug("All segments are ignored.");
}
return true; return true;
} else { } else {
return prepareForRetry(1); return prepareForRetry(1);
@ -247,21 +236,17 @@ bool AbstractCommand::execute() {
req_->getProtocol()); req_->getProtocol());
ss->setError(); ss->setError();
// Purging IP address cache to renew IP address. // Purging IP address cache to renew IP address.
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("CUID#%s - Marking IP address %s as bad",
getLogger()->debug("CUID#%s - Marking IP address %s as bad", util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), req_->getConnectedAddr().c_str()));
req_->getConnectedAddr().c_str());
}
e_->markBadIPAddress(req_->getConnectedHostname(), e_->markBadIPAddress(req_->getConnectedHostname(),
req_->getConnectedAddr(), req_->getConnectedAddr(),
req_->getConnectedPort()); req_->getConnectedPort());
if(e_->findCachedIPAddress if(e_->findCachedIPAddress
(req_->getConnectedHostname(), req_->getConnectedPort()).empty()) { (req_->getConnectedHostname(), req_->getConnectedPort()).empty()) {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("CUID#%s - All IP addresses were marked bad."
getLogger()->debug("CUID#%s - All IP addresses were marked bad." " Removing Entry.",
" Removing Entry.", util::itos(getCuid()).c_str()));
util::itos(getCuid()).c_str());
}
e_->removeCachedIPAddress e_->removeCachedIPAddress
(req_->getConnectedHostname(), req_->getConnectedPort()); (req_->getConnectedHostname(), req_->getConnectedPort());
} }
@ -272,15 +257,13 @@ bool AbstractCommand::execute() {
} }
} catch(DlAbortEx& err) { } catch(DlAbortEx& err) {
if(!req_) { if(!req_) {
if(getLogger()->debug()) { A2_LOG_DEBUG_EX(EX_EXCEPTION_CAUGHT, err);
getLogger()->debug(EX_EXCEPTION_CAUGHT, err);
}
} else { } else {
getLogger()->error A2_LOG_ERROR_EX(fmt(MSG_DOWNLOAD_ABORTED,
(MSG_DOWNLOAD_ABORTED, util::itos(getCuid()).c_str(),
DL_ABORT_EX2(StringFormat req_->getUri().c_str()),
("URI=%s", req_->getCurrentUri().c_str()).str(),err), DL_ABORT_EX2(fmt("URI=%s", req_->getCurrentUri().c_str()),
util::itos(getCuid()).c_str(), req_->getUri().c_str()); err));
fileEntry_->addURIResult(req_->getUri(), err.getCode()); fileEntry_->addURIResult(req_->getUri(), err.getCode());
requestGroup_->setLastUriResult(req_->getUri(), err.getCode()); requestGroup_->setLastUriResult(req_->getUri(), err.getCode());
if(err.getCode() == downloadresultcode::CANNOT_RESUME) { if(err.getCode() == downloadresultcode::CANNOT_RESUME) {
@ -292,27 +275,23 @@ bool AbstractCommand::execute() {
return true; return true;
} catch(DlRetryEx& err) { } catch(DlRetryEx& err) {
assert(req_); assert(req_);
if(getLogger()->info()) { A2_LOG_INFO_EX(fmt(MSG_RESTARTING_DOWNLOAD,
getLogger()->info util::itos(getCuid()).c_str(), req_->getUri().c_str()),
(MSG_RESTARTING_DOWNLOAD, DL_RETRY_EX2(fmt("URI=%s", req_->getCurrentUri().c_str()),
DL_RETRY_EX2(StringFormat err));
("URI=%s", req_->getCurrentUri().c_str()).str(),
err),
util::itos(getCuid()).c_str(), req_->getUri().c_str());
}
req_->addTryCount(); req_->addTryCount();
req_->resetRedirectCount(); req_->resetRedirectCount();
req_->resetUri(); req_->resetUri();
const unsigned int maxTries = getOption()->getAsInt(PREF_MAX_TRIES); const unsigned int maxTries = getOption()->getAsInt(PREF_MAX_TRIES);
bool isAbort = maxTries != 0 && req_->getTryCount() >= maxTries; bool isAbort = maxTries != 0 && req_->getTryCount() >= maxTries;
if(isAbort) { if(isAbort) {
if(getLogger()->info()) { A2_LOG_INFO(fmt(MSG_MAX_TRY,
getLogger()->info(MSG_MAX_TRY, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), req_->getTryCount()); req_->getTryCount()));
} A2_LOG_ERROR_EX(fmt(MSG_DOWNLOAD_ABORTED,
getLogger()->error(MSG_DOWNLOAD_ABORTED, err, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), req_->getUri().c_str()),
req_->getUri().c_str()); err);
fileEntry_->addURIResult(req_->getUri(), err.getCode()); fileEntry_->addURIResult(req_->getUri(), err.getCode());
requestGroup_->setLastUriResult(req_->getUri(), err.getCode()); requestGroup_->setLastUriResult(req_->getUri(), err.getCode());
if(err.getCode() == downloadresultcode::CANNOT_RESUME) { if(err.getCode() == downloadresultcode::CANNOT_RESUME) {
@ -325,7 +304,7 @@ bool AbstractCommand::execute() {
return prepareForRetry(0); return prepareForRetry(0);
} }
} catch(DownloadFailureException& err) { } catch(DownloadFailureException& err) {
getLogger()->error(EX_EXCEPTION_CAUGHT, err); A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, err);
if(req_) { if(req_) {
fileEntry_->addURIResult(req_->getUri(), err.getCode()); fileEntry_->addURIResult(req_->getUri(), err.getCode());
requestGroup_->setLastUriResult(req_->getUri(), err.getCode()); requestGroup_->setLastUriResult(req_->getUri(), err.getCode());
@ -343,19 +322,15 @@ void AbstractCommand::tryReserved() {
// and there are no URI left. Because file length is unknown, we // and there are no URI left. Because file length is unknown, we
// can assume that there are no in-flight request object. // can assume that there are no in-flight request object.
if(entry->getLength() == 0 && entry->getRemainingUris().empty()) { if(entry->getLength() == 0 && entry->getRemainingUris().empty()) {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("CUID#%s - Not trying next request."
getLogger()->debug("CUID#%s - Not trying next request." " No reserved/pooled request is remaining and"
" No reserved/pooled request is remaining and" " total length is still unknown.",
" total length is still unknown.", util::itos(getCuid()).c_str()));
util::itos(getCuid()).c_str());
}
return; return;
} }
} }
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("CUID#%s - Trying reserved/pooled request.",
getLogger()->debug("CUID#%s - Trying reserved/pooled request.", util::itos(getCuid()).c_str()));
util::itos(getCuid()).c_str());
}
std::vector<Command*> commands; std::vector<Command*> commands;
requestGroup_->createNextCommand(commands, e_, 1); requestGroup_->createNextCommand(commands, e_, 1);
e_->setNoWait(true); e_->setNoWait(true);
@ -368,10 +343,8 @@ bool AbstractCommand::prepareForRetry(time_t wait) {
} }
if(req_) { if(req_) {
fileEntry_->poolRequest(req_); fileEntry_->poolRequest(req_);
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("CUID#%s - Pooling request URI=%s",
getLogger()->debug("CUID#%s - Pooling request URI=%s", util::itos(getCuid()).c_str(), req_->getUri().c_str()));
util::itos(getCuid()).c_str(), req_->getUri().c_str());
}
if(getSegmentMan()) { if(getSegmentMan()) {
getSegmentMan()->recognizeSegmentFor(fileEntry_); getSegmentMan()->recognizeSegmentFor(fileEntry_);
} }
@ -394,10 +367,8 @@ void AbstractCommand::onAbort() {
fileEntry_->removeIdenticalURI(req_->getUri()); fileEntry_->removeIdenticalURI(req_->getUri());
fileEntry_->removeRequest(req_); fileEntry_->removeRequest(req_);
} }
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("CUID#%s - Aborting download",
getLogger()->debug("CUID#%s - Aborting download", util::itos(getCuid()).c_str()));
util::itos(getCuid()).c_str());
}
if(getPieceStorage()) { if(getPieceStorage()) {
getSegmentMan()->cancelSegment(getCuid()); getSegmentMan()->cancelSegment(getCuid());
// Don't do following process if BitTorrent is involved or files // Don't do following process if BitTorrent is involved or files
@ -414,14 +385,12 @@ void AbstractCommand::onAbort() {
// Local file exists, but given servers(or at least contacted // Local file exists, but given servers(or at least contacted
// ones) doesn't support resume. Let's restart download from // ones) doesn't support resume. Let's restart download from
// scratch. // scratch.
getLogger()->notice("CUID#%s - Failed to resume download." A2_LOG_NOTICE(fmt("CUID#%s - Failed to resume download."
" Download from scratch.", " Download from scratch.",
util::itos(getCuid()).c_str()); util::itos(getCuid()).c_str()));
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("CUID#%s - Gathering URIs that has CANNOT_RESUME"
getLogger()->debug " error",
("CUID#%s - Gathering URIs that has CANNOT_RESUME error", util::itos(getCuid()).c_str()));
util::itos(getCuid()).c_str());
}
// Set PREF_ALWAYS_RESUME to A2_V_TRUE to avoid repeating this // Set PREF_ALWAYS_RESUME to A2_V_TRUE to avoid repeating this
// process. // process.
getOption()->put(PREF_ALWAYS_RESUME, A2_V_TRUE); getOption()->put(PREF_ALWAYS_RESUME, A2_V_TRUE);
@ -435,11 +404,9 @@ void AbstractCommand::onAbort() {
uris.reserve(res.size()); uris.reserve(res.size());
std::transform(res.begin(), res.end(), std::back_inserter(uris), std::transform(res.begin(), res.end(), std::back_inserter(uris),
std::mem_fun_ref(&URIResult::getURI)); std::mem_fun_ref(&URIResult::getURI));
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("CUID#%s - %lu URIs found.",
getLogger()->debug("CUID#%s - %lu URIs found.", util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), static_cast<unsigned long int>(uris.size())));
static_cast<unsigned long int>(uris.size()));
}
fileEntry_->addUris(uris.begin(), uris.end()); fileEntry_->addUris(uris.begin(), uris.end());
getSegmentMan()->recognizeSegmentFor(fileEntry_); getSegmentMan()->recognizeSegmentFor(fileEntry_);
} }
@ -640,15 +607,10 @@ SharedHandle<Request> AbstractCommand::createProxyRequest() const
if(!proxy.empty()) { if(!proxy.empty()) {
proxyRequest.reset(new Request()); proxyRequest.reset(new Request());
if(proxyRequest->setUri(proxy)) { if(proxyRequest->setUri(proxy)) {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("CUID#%s - Using proxy", util::itos(getCuid()).c_str()));
getLogger()->debug("CUID#%s - Using proxy",
util::itos(getCuid()).c_str());
}
} else { } else {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("CUID#%s - Failed to parse proxy string",
getLogger()->debug("CUID#%s - Failed to parse proxy string", util::itos(getCuid()).c_str()));
util::itos(getCuid()).c_str());
}
proxyRequest.reset(); proxyRequest.reset();
} }
} }
@ -671,10 +633,9 @@ void AbstractCommand::initAsyncNameResolver(const std::string& hostname)
family = AF_INET; family = AF_INET;
} }
asyncNameResolver_.reset(new AsyncNameResolver(family)); asyncNameResolver_.reset(new AsyncNameResolver(family));
if(getLogger()->info()) { A2_LOG_INFO(fmt(MSG_RESOLVING_HOSTNAME,
getLogger()->info(MSG_RESOLVING_HOSTNAME, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), hostname.c_str()); hostname.c_str()));
}
asyncNameResolver_->resolve(hostname); asyncNameResolver_->resolve(hostname);
setNameResolverCheck(asyncNameResolver_); setNameResolverCheck(asyncNameResolver_);
} }
@ -759,12 +720,10 @@ std::string AbstractCommand::resolveHostname
} }
res.resolve(addrs, hostname); res.resolve(addrs, hostname);
} }
if(getLogger()->info()) { A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_COMPLETE,
getLogger()->info(MSG_NAME_RESOLUTION_COMPLETE, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), hostname.c_str(),
hostname.c_str(), strjoin(addrs.begin(), addrs.end(), ", ").c_str()));
strjoin(addrs.begin(), addrs.end(), ", ").c_str());
}
for(std::vector<std::string>::const_iterator i = addrs.begin(), for(std::vector<std::string>::const_iterator i = addrs.begin(),
eoi = addrs.end(); i != eoi; ++i) { eoi = addrs.end(); i != eoi; ++i) {
e_->cacheIPAddress(hostname, *i, port); e_->cacheIPAddress(hostname, *i, port);
@ -772,11 +731,10 @@ std::string AbstractCommand::resolveHostname
ipaddr = e_->findCachedIPAddress(hostname, port); ipaddr = e_->findCachedIPAddress(hostname, port);
} else { } else {
ipaddr = addrs.front(); ipaddr = addrs.front();
if(getLogger()->info()) { A2_LOG_INFO(fmt(MSG_DNS_CACHE_HIT,
getLogger()->info(MSG_DNS_CACHE_HIT, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), hostname.c_str(), hostname.c_str(),
strjoin(addrs.begin(), addrs.end(), ", ").c_str()); strjoin(addrs.begin(), addrs.end(), ", ").c_str()));
}
} }
return ipaddr; return ipaddr;
} }
@ -804,11 +762,9 @@ bool AbstractCommand::checkIfConnectionEstablished
// See also InitiateConnectionCommand::executeInternal() // See also InitiateConnectionCommand::executeInternal()
e_->markBadIPAddress(connectedHostname, connectedAddr, connectedPort); e_->markBadIPAddress(connectedHostname, connectedAddr, connectedPort);
if(!e_->findCachedIPAddress(connectedHostname, connectedPort).empty()) { if(!e_->findCachedIPAddress(connectedHostname, connectedPort).empty()) {
if(getLogger()->info()) { A2_LOG_INFO(fmt(MSG_CONNECT_FAILED_AND_RETRY,
getLogger()->info(MSG_CONNECT_FAILED_AND_RETRY, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), connectedAddr.c_str(), connectedPort));
connectedAddr.c_str(), connectedPort);
}
Command* command = Command* command =
InitiateConnectionCommandFactory::createInitiateConnectionCommand InitiateConnectionCommandFactory::createInitiateConnectionCommand
(getCuid(), req_, fileEntry_, requestGroup_, e_); (getCuid(), req_, fileEntry_, requestGroup_, e_);

View File

@ -47,8 +47,6 @@
#include "File.h" #include "File.h"
#include "util.h" #include "util.h"
#include "message.h" #include "message.h"
#include "LogFactory.h"
#include "Logger.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "a2io.h" #include "a2io.h"
#include "StringFormat.h" #include "StringFormat.h"
@ -56,12 +54,12 @@
namespace aria2 { namespace aria2 {
AbstractDiskWriter::AbstractDiskWriter(const std::string& filename): AbstractDiskWriter::AbstractDiskWriter(const std::string& filename)
filename_(filename), : filename_(filename),
fd_(-1), fd_(-1),
readOnly_(false), readOnly_(false),
directIOAllowed_(false), directIOAllowed_(false)
logger_(LogFactory::getInstance()) {} {}
AbstractDiskWriter::~AbstractDiskWriter() AbstractDiskWriter::~AbstractDiskWriter()
{ {

View File

@ -40,8 +40,6 @@
namespace aria2 { namespace aria2 {
class Logger;
class AbstractDiskWriter : public DiskWriter { class AbstractDiskWriter : public DiskWriter {
private: private:
std::string filename_; std::string filename_;
@ -51,8 +49,6 @@ private:
bool directIOAllowed_; bool directIOAllowed_;
Logger* logger_;
ssize_t writeDataInternal(const unsigned char* data, size_t len); ssize_t writeDataInternal(const unsigned char* data, size_t len);
ssize_t readDataInternal(unsigned char* data, size_t len); ssize_t readDataInternal(unsigned char* data, size_t len);

View File

@ -41,6 +41,7 @@
#include "BtRuntime.h" #include "BtRuntime.h"
#include "Peer.h" #include "Peer.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "prefs.h" #include "prefs.h"
#include "Option.h" #include "Option.h"
#include "BtConstants.h" #include "BtConstants.h"
@ -51,6 +52,7 @@
#include "bittorrent_helper.h" #include "bittorrent_helper.h"
#include "wallclock.h" #include "wallclock.h"
#include "util.h" #include "util.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
@ -59,12 +61,11 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand
RequestGroup* requestGroup, RequestGroup* requestGroup,
DownloadEngine* e, DownloadEngine* e,
time_t interval) time_t interval)
: : Command(cuid),
Command(cuid), requestGroup_(requestGroup),
requestGroup_(requestGroup), interval_(interval),
interval_(interval), e_(e),
e_(e), numNewConnection_(5)
numNewConnection_(5)
{ {
requestGroup_->increaseNumCommand(); requestGroup_->increaseNumCommand();
} }
@ -141,11 +142,9 @@ void ActivePeerConnectionCommand::connectToPeer(const SharedHandle<Peer>& peer)
command->setPeerStorage(peerStorage_); command->setPeerStorage(peerStorage_);
command->setPieceStorage(pieceStorage_); command->setPieceStorage(pieceStorage_);
e_->addCommand(command); e_->addCommand(command);
if(getLogger()->info()) { A2_LOG_INFO(fmt(MSG_CONNECTING_TO_PEER,
getLogger()->info(MSG_CONNECTING_TO_PEER, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), peer->getIPAddress().c_str()));
peer->getIPAddress().c_str());
}
} }
void ActivePeerConnectionCommand::setBtRuntime void ActivePeerConnectionCommand::setBtRuntime

View File

@ -45,9 +45,11 @@
namespace aria2 { namespace aria2 {
AdaptiveFileAllocationIterator::AdaptiveFileAllocationIterator AdaptiveFileAllocationIterator::AdaptiveFileAllocationIterator
(BinaryStream* stream, off_t offset, uint64_t totalLength): (BinaryStream* stream, off_t offset, uint64_t totalLength)
stream_(stream), offset_(offset), totalLength_(totalLength), : stream_(stream),
logger_(LogFactory::getInstance()) {} offset_(offset),
totalLength_(totalLength)
{}
AdaptiveFileAllocationIterator::~AdaptiveFileAllocationIterator() {} AdaptiveFileAllocationIterator::~AdaptiveFileAllocationIterator() {}
@ -56,23 +58,17 @@ void AdaptiveFileAllocationIterator::allocateChunk()
if(!allocator_) { if(!allocator_) {
#ifdef HAVE_FALLOCATE #ifdef HAVE_FALLOCATE
try { try {
if(logger_->debug()) { A2_LOG_DEBUG("Testing file system supports fallocate.");
logger_->debug("Testing file system supports fallocate.");
}
if(static_cast<uint64_t>(offset_) < totalLength_) { if(static_cast<uint64_t>(offset_) < totalLength_) {
off_t len = std::min(totalLength_-offset_, static_cast<uint64_t>(4096)); off_t len = std::min(totalLength_-offset_, static_cast<uint64_t>(4096));
stream_->allocate(offset_, len); stream_->allocate(offset_, len);
offset_ += len; offset_ += len;
} }
if(logger_->debug()) { A2_LOG_DEBUG("File system supports fallocate.");
logger_->debug("File system supports fallocate.");
}
allocator_.reset allocator_.reset
(new FallocFileAllocationIterator(stream_, offset_, totalLength_)); (new FallocFileAllocationIterator(stream_, offset_, totalLength_));
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
if(logger_->debug()) { A2_LOG_DEBUG("File system does not support fallocate.");
logger_->debug("File system does not support fallocate.");
}
SharedHandle<SingleFileAllocationIterator> salloc SharedHandle<SingleFileAllocationIterator> salloc
(new SingleFileAllocationIterator(stream_, offset_, totalLength_)); (new SingleFileAllocationIterator(stream_, offset_, totalLength_));
salloc->init(); salloc->init();

View File

@ -40,7 +40,6 @@
namespace aria2 { namespace aria2 {
class BinaryStream; class BinaryStream;
class Logger;
class AdaptiveFileAllocationIterator:public FileAllocationIterator class AdaptiveFileAllocationIterator:public FileAllocationIterator
{ {
@ -52,8 +51,6 @@ private:
off_t offset_; off_t offset_;
uint64_t totalLength_; uint64_t totalLength_;
Logger* logger_;
public: public:
AdaptiveFileAllocationIterator AdaptiveFileAllocationIterator
(BinaryStream* stream, off_t offset, uint64_t totalLength); (BinaryStream* stream, off_t offset, uint64_t totalLength);

View File

@ -44,6 +44,7 @@
#include "ServerStatMan.h" #include "ServerStatMan.h"
#include "ServerStat.h" #include "ServerStat.h"
#include "RequestGroup.h" #include "RequestGroup.h"
#include "Logger.h"
#include "LogFactory.h" #include "LogFactory.h"
#include "A2STR.h" #include "A2STR.h"
#include "prefs.h" #include "prefs.h"
@ -52,6 +53,7 @@
#include "SocketCore.h" #include "SocketCore.h"
#include "FileEntry.h" #include "FileEntry.h"
#include "uri.h" #include "uri.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
@ -63,10 +65,9 @@ namespace aria2 {
*/ */
AdaptiveURISelector::AdaptiveURISelector AdaptiveURISelector::AdaptiveURISelector
(const SharedHandle<ServerStatMan>& serverStatMan, RequestGroup* requestGroup): (const SharedHandle<ServerStatMan>& serverStatMan, RequestGroup* requestGroup)
serverStatMan_(serverStatMan), : serverStatMan_(serverStatMan),
requestGroup_(requestGroup), requestGroup_(requestGroup)
logger_(LogFactory::getInstance())
{ {
resetCounters(); resetCounters();
} }
@ -77,10 +78,8 @@ std::string AdaptiveURISelector::select
(FileEntry* fileEntry, (FileEntry* fileEntry,
const std::vector<std::pair<size_t, std::string> >& usedHosts) const std::vector<std::pair<size_t, std::string> >& usedHosts)
{ {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("AdaptiveURISelector: called %d",
logger_->debug("AdaptiveURISelector: called %d", requestGroup_->getNumConnection()));
requestGroup_->getNumConnection());
}
std::deque<std::string>& uris = fileEntry->getRemainingUris(); std::deque<std::string>& uris = fileEntry->getRemainingUris();
if (uris.empty() && requestGroup_->getNumConnection() <= 1) { if (uris.empty() && requestGroup_->getNumConnection() <= 1) {
// here we know the download will fail, trying to find previously // here we know the download will fail, trying to find previously
@ -108,13 +107,13 @@ void AdaptiveURISelector::mayRetryWithIncreasedTimeout(FileEntry* fileEntry)
std::transform(timeouts.begin(), timeouts.end(), std::back_inserter(uris), std::transform(timeouts.begin(), timeouts.end(), std::back_inserter(uris),
std::mem_fun_ref(&URIResult::getURI)); std::mem_fun_ref(&URIResult::getURI));
if(logger_->debug()) { if(A2_LOG_DEBUG_ENABLED) {
for(std::deque<std::string>::const_iterator i = uris.begin(), for(std::deque<std::string>::const_iterator i = uris.begin(),
eoi = uris.end(); i != eoi; ++i) { eoi = uris.end(); i != eoi; ++i) {
logger_->debug("AdaptiveURISelector: will retry server with increased" A2_LOG_DEBUG(fmt("AdaptiveURISelector: will retry server with increased"
" timeout (%ld s): %s", " timeout (%ld s): %s",
static_cast<long int>(requestGroup_->getTimeout()), static_cast<long int>(requestGroup_->getTimeout()),
(*i).c_str()); (*i).c_str()));
} }
} }
} }
@ -140,10 +139,9 @@ std::string AdaptiveURISelector::selectOne(const std::deque<std::string>& uris)
if(getNbTestedServers(uris) < 3) { if(getNbTestedServers(uris) < 3) {
std::string notTested = getFirstNotTestedUri(uris); std::string notTested = getFirstNotTestedUri(uris);
if(notTested != A2STR::NIL) { if(notTested != A2STR::NIL) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("AdaptiveURISelector: choosing the first non tested"
logger_->debug("AdaptiveURISelector: choosing the first non tested" " mirror: %s",
" mirror: %s", notTested.c_str()); notTested.c_str()));
}
--nbServerToEvaluate_; --nbServerToEvaluate_;
return notTested; return notTested;
} }
@ -154,21 +152,17 @@ std::string AdaptiveURISelector::selectOne(const std::deque<std::string>& uris)
std::string notTested = getFirstNotTestedUri(uris); std::string notTested = getFirstNotTestedUri(uris);
if(notTested != A2STR::NIL) { if(notTested != A2STR::NIL) {
/* Here we return the first untested mirror */ /* Here we return the first untested mirror */
if(logger_->debug()) { A2_LOG_DEBUG(fmt("AdaptiveURISelector: choosing non tested mirror %s"
logger_->debug("AdaptiveURISelector: choosing non tested mirror %s"
" for connection #%d", " for connection #%d",
notTested.c_str(), nbConnections_); notTested.c_str(), nbConnections_));
}
return notTested; return notTested;
} else { } else {
/* Here we return a mirror which need to be tested again */ /* Here we return a mirror which need to be tested again */
std::string toReTest = getFirstToTestUri(uris); std::string toReTest = getFirstToTestUri(uris);
if(toReTest != A2STR::NIL) { if(toReTest != A2STR::NIL) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("AdaptiveURISelector: choosing mirror %s which has"
logger_->debug("AdaptiveURISelector: choosing mirror %s which has"
" not been tested recently for connection #%d", " not been tested recently for connection #%d",
toReTest.c_str(), nbConnections_); toReTest.c_str(), nbConnections_));
}
return toReTest; return toReTest;
} else { } else {
return getBestMirror(uris); return getBestMirror(uris);
@ -191,19 +185,18 @@ std::string AdaptiveURISelector::getBestMirror
if (bests.size() < 2) { if (bests.size() < 2) {
std::string uri = getMaxDownloadSpeedUri(uris); std::string uri = getMaxDownloadSpeedUri(uris);
if(logger_->debug()) { A2_LOG_DEBUG(fmt("AdaptiveURISelector: choosing the best mirror :"
logger_->debug("AdaptiveURISelector: choosing the best mirror :"
" %.2fKB/s %s (other mirrors are at least 25%% slower)", " %.2fKB/s %s (other mirrors are at least 25%% slower)",
(float) max/1024, uri.c_str()); (float) max/1024,
} uri.c_str()));
return uri; return uri;
} else { } else {
std::string uri = selectRandomUri(bests); std::string uri = selectRandomUri(bests);
if(logger_->debug()) { A2_LOG_DEBUG(fmt("AdaptiveURISelector: choosing randomly one of the best"
logger_->debug("AdaptiveURISelector: choosing randomly one of the best"
" mirrors (range [%.2fKB/s, %.2fKB/s]): %s", " mirrors (range [%.2fKB/s, %.2fKB/s]): %s",
(float) min/1024, (float) max/1024, uri.c_str()); (float) min/1024,
} (float) max/1024,
uri.c_str()));
return uri; return uri;
} }
} }
@ -230,12 +223,17 @@ void AdaptiveURISelector::adjustLowestSpeedLimit
unsigned int low_lowest = 4 * 1024; unsigned int low_lowest = 4 * 1024;
unsigned int max = getMaxDownloadSpeed(uris); unsigned int max = getMaxDownloadSpeed(uris);
if (max > 0 && lowest > max / 4) { if (max > 0 && lowest > max / 4) {
logger_->notice("Lowering lowest-speed-limit since known max speed is too" A2_LOG_NOTICE(fmt("Lowering lowest-speed-limit since known max speed is"
" near (new:%d was:%d max:%d)", max / 4, lowest, max); " too near (new:%d was:%d max:%d)",
max / 4,
lowest,
max));
command->setLowestDownloadSpeedLimit(max / 4); command->setLowestDownloadSpeedLimit(max / 4);
} else if (max == 0 && lowest > low_lowest) { } else if (max == 0 && lowest > low_lowest) {
logger_->notice("Lowering lowest-speed-limit since we have no clue about" A2_LOG_NOTICE(fmt("Lowering lowest-speed-limit since we have no clue"
" available speed (now:%d was:%d)", low_lowest, lowest); " about available speed (now:%d was:%d)",
low_lowest,
lowest));
command->setLowestDownloadSpeedLimit(low_lowest); command->setLowestDownloadSpeedLimit(low_lowest);
} }
} }

View File

@ -43,7 +43,6 @@ namespace aria2 {
class ServerStatMan; class ServerStatMan;
class RequestGroup; class RequestGroup;
class ServerStat; class ServerStat;
class Logger;
class AdaptiveURISelector:public URISelector { class AdaptiveURISelector:public URISelector {
private: private:
@ -55,8 +54,6 @@ private:
static const time_t MAX_TIMEOUT = 60; static const time_t MAX_TIMEOUT = 60;
Logger* logger_;
void mayRetryWithIncreasedTimeout(FileEntry* fileEntry); void mayRetryWithIncreasedTimeout(FileEntry* fileEntry);
std::string selectOne(const std::deque<std::string>& uris); std::string selectOne(const std::deque<std::string>& uris);

View File

@ -48,15 +48,17 @@
#include "bittorrent_helper.h" #include "bittorrent_helper.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
#include "FileEntry.h" #include "FileEntry.h"
namespace aria2 { namespace aria2 {
BtDependency::BtDependency(RequestGroup* dependant, BtDependency::BtDependency
const SharedHandle<RequestGroup>& dependee): (RequestGroup* dependant,
dependant_(dependant), const SharedHandle<RequestGroup>& dependee)
dependee_(dependee), : dependant_(dependant),
logger_(LogFactory::getInstance()) {} dependee_(dependee)
{}
BtDependency::~BtDependency() {} BtDependency::~BtDependency() {}
@ -136,27 +138,21 @@ bool BtDependency::resolve()
} }
} }
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
logger_->error(EX_EXCEPTION_CAUGHT, e); A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
if(logger_->info()) { A2_LOG_INFO(fmt("BtDependency for GID#%s failed. Go without Bt.",
logger_->info("BtDependency for GID#%s failed. Go without Bt.", util::itos(dependant_->getGID()).c_str()));
util::itos(dependant_->getGID()).c_str());
}
return true; return true;
} }
if(logger_->info()) { A2_LOG_INFO(fmt("Dependency resolved for GID#%s",
logger_->info("Dependency resolved for GID#%s", util::itos(dependant_->getGID()).c_str()));
util::itos(dependant_->getGID()).c_str());
}
dependant_->setDownloadContext(context); dependant_->setDownloadContext(context);
return true; return true;
} else if(dependee_->getNumCommand() == 0) { } else if(dependee_->getNumCommand() == 0) {
// dependee_'s download failed. // dependee_'s download failed.
// cut reference here // cut reference here
dependee_.reset(); dependee_.reset();
if(logger_->info()) { A2_LOG_INFO(fmt("BtDependency for GID#%s failed. Go without Bt.",
logger_->info("BtDependency for GID#%s failed. Go without Bt.", util::itos(dependant_->getGID()).c_str()));
util::itos(dependant_->getGID()).c_str());
}
return true; return true;
} else { } else {
return false; return false;

View File

@ -41,14 +41,12 @@ namespace aria2 {
class RequestGroup; class RequestGroup;
class Option; class Option;
class Logger;
class BtDependency : public Dependency class BtDependency : public Dependency
{ {
private: private:
RequestGroup* dependant_; RequestGroup* dependant_;
SharedHandle<RequestGroup> dependee_; SharedHandle<RequestGroup> dependee_;
Logger* logger_;
public: public:
BtDependency(RequestGroup* dependant, BtDependency(RequestGroup* dependant,
const SharedHandle<RequestGroup>& dependee); const SharedHandle<RequestGroup>& dependee);

View File

@ -41,13 +41,14 @@
#include "LogFactory.h" #include "LogFactory.h"
#include "SimpleRandomizer.h" #include "SimpleRandomizer.h"
#include "wallclock.h" #include "wallclock.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
BtLeecherStateChoke::BtLeecherStateChoke(): BtLeecherStateChoke::BtLeecherStateChoke()
round_(0), : round_(0),
lastRound_(0), lastRound_(0)
logger_(LogFactory::getInstance()) {} {}
BtLeecherStateChoke::~BtLeecherStateChoke() {} BtLeecherStateChoke::~BtLeecherStateChoke() {}
@ -142,8 +143,8 @@ void BtLeecherStateChoke::plannedOptimisticUnchoke
std::random_shuffle(peerEntries.begin(), i, std::random_shuffle(peerEntries.begin(), i,
*(SimpleRandomizer::getInstance().get())); *(SimpleRandomizer::getInstance().get()));
(*peerEntries.begin()).enableOptUnchoking(); (*peerEntries.begin()).enableOptUnchoking();
logger_->info A2_LOG_INFO(fmt("POU: %s",
("POU: %s", (*peerEntries.begin()).getPeer()->getIPAddress().c_str()); (*peerEntries.begin()).getPeer()->getIPAddress().c_str()));
} }
} }
@ -162,9 +163,9 @@ void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
std::vector<PeerEntry>::iterator peerIter = peerEntries.begin(); std::vector<PeerEntry>::iterator peerIter = peerEntries.begin();
for(;peerIter != rest && count; ++peerIter, --count) { for(;peerIter != rest && count; ++peerIter, --count) {
(*peerIter).disableChokingRequired(); (*peerIter).disableChokingRequired();
logger_->info("RU: %s, dlspd=%u", A2_LOG_INFO(fmt("RU: %s, dlspd=%u",
(*peerIter).getPeer()->getIPAddress().c_str(), (*peerIter).getPeer()->getIPAddress().c_str(),
(*peerIter).getDownloadSpeed()); (*peerIter).getDownloadSpeed()));
if((*peerIter).getPeer()->optUnchoking()) { if((*peerIter).getPeer()->optUnchoking()) {
fastOptUnchoker = true; fastOptUnchoker = true;
(*peerIter).disableOptUnchoking(); (*peerIter).disableOptUnchoking();
@ -177,11 +178,11 @@ void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
eoi = peerEntries.end(); i != eoi; ++i) { eoi = peerEntries.end(); i != eoi; ++i) {
if((*i).getPeer()->peerInterested()) { if((*i).getPeer()->peerInterested()) {
(*i).enableOptUnchoking(); (*i).enableOptUnchoking();
logger_->info("OU: %s", (*i).getPeer()->getIPAddress().c_str()); A2_LOG_INFO(fmt("OU: %s", (*i).getPeer()->getIPAddress().c_str()));
break; break;
} else { } else {
(*i).disableChokingRequired(); (*i).disableChokingRequired();
logger_->info("OU: %s", (*i).getPeer()->getIPAddress().c_str()); A2_LOG_INFO(fmt("OU: %s", (*i).getPeer()->getIPAddress().c_str()));
} }
} }
} }
@ -191,7 +192,7 @@ void
BtLeecherStateChoke::executeChoke BtLeecherStateChoke::executeChoke
(const std::vector<SharedHandle<Peer> >& peerSet) (const std::vector<SharedHandle<Peer> >& peerSet)
{ {
logger_->info("Leecher state, %d choke round started", round_); A2_LOG_INFO(fmt("Leecher state, %d choke round started", round_));
lastRound_ = global::wallclock; lastRound_ = global::wallclock;
std::vector<PeerEntry> peerEntries; std::vector<PeerEntry> peerEntries;

View File

@ -45,7 +45,6 @@
namespace aria2 { namespace aria2 {
class Peer; class Peer;
class Logger;
class BtLeecherStateChoke { class BtLeecherStateChoke {
private: private:
@ -53,8 +52,6 @@ private:
Timer lastRound_; Timer lastRound_;
Logger* logger_;
class PeerEntry { class PeerEntry {
private: private:
SharedHandle<Peer> peer_; SharedHandle<Peer> peer_;

View File

@ -45,6 +45,7 @@
#include "MessageDigestHelper.h" #include "MessageDigestHelper.h"
#include "DiskAdaptor.h" #include "DiskAdaptor.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "Peer.h" #include "Peer.h"
#include "Piece.h" #include "Piece.h"
#include "PieceStorage.h" #include "PieceStorage.h"
@ -53,6 +54,7 @@
#include "BtRequestFactory.h" #include "BtRequestFactory.h"
#include "PeerConnection.h" #include "PeerConnection.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
#include "DownloadContext.h" #include "DownloadContext.h"
namespace aria2 { namespace aria2 {
@ -60,13 +62,13 @@ namespace aria2 {
const std::string BtPieceMessage::NAME("piece"); const std::string BtPieceMessage::NAME("piece");
BtPieceMessage::BtPieceMessage BtPieceMessage::BtPieceMessage
(size_t index, uint32_t begin, size_t blockLength): (size_t index, uint32_t begin, size_t blockLength)
AbstractBtMessage(ID, NAME), : AbstractBtMessage(ID, NAME),
index_(index), index_(index),
begin_(begin), begin_(begin),
blockLength_(blockLength), blockLength_(blockLength),
block_(0), block_(0),
rawData_(0) rawData_(0)
{ {
setUploading(true); setUploading(true);
} }
@ -107,22 +109,19 @@ void BtPieceMessage::doReceivedAction()
getPeer()->snubbing(false); getPeer()->snubbing(false);
SharedHandle<Piece> piece = getPieceStorage()->getPiece(index_); SharedHandle<Piece> piece = getPieceStorage()->getPiece(index_);
off_t offset = (off_t)index_*downloadContext_->getPieceLength()+begin_; off_t offset = (off_t)index_*downloadContext_->getPieceLength()+begin_;
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt(MSG_PIECE_RECEIVED,
getLogger()->debug(MSG_PIECE_RECEIVED, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), static_cast<unsigned long>(index_),
static_cast<unsigned long>(index_), begin_,
begin_, blockLength_, blockLength_,
static_cast<long long int>(offset), static_cast<long long int>(offset),
static_cast<unsigned long>(slot.getBlockIndex())); static_cast<unsigned long>(slot.getBlockIndex())));
}
getPieceStorage()->getDiskAdaptor()->writeData getPieceStorage()->getDiskAdaptor()->writeData
(block_, blockLength_, offset); (block_, blockLength_, offset);
piece->completeBlock(slot.getBlockIndex()); piece->completeBlock(slot.getBlockIndex());
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt(MSG_PIECE_BITFIELD, util::itos(getCuid()).c_str(),
getLogger()->debug(MSG_PIECE_BITFIELD, util::itos(getCuid()).c_str(), util::toHex(piece->getBitfield(),
util::toHex(piece->getBitfield(), piece->getBitfieldLength()).c_str()));
piece->getBitfieldLength()).c_str());
}
piece->updateHash(begin_, block_, blockLength_); piece->updateHash(begin_, block_, blockLength_);
getBtMessageDispatcher()->removeOutstandingRequest(slot); getBtMessageDispatcher()->removeOutstandingRequest(slot);
if(piece->pieceComplete()) { if(piece->pieceComplete()) {
@ -134,11 +133,10 @@ void BtPieceMessage::doReceivedAction()
} }
} }
} else { } else {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("CUID#%s - RequestSlot not found, index=%lu, begin=%u",
getLogger()->debug("CUID#%s - RequestSlot not found, index=%lu, begin=%u", util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), static_cast<unsigned long>(index_),
static_cast<unsigned long>(index_), begin_); begin_));
}
} }
} }
@ -173,19 +171,15 @@ void BtPieceMessage::send()
} }
size_t writtenLength; size_t writtenLength;
if(!isSendingInProgress()) { if(!isSendingInProgress()) {
if(getLogger()->info()) { A2_LOG_INFO(fmt(MSG_SEND_PEER_MESSAGE,
getLogger()->info(MSG_SEND_PEER_MESSAGE, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), getPeer()->getIPAddress().c_str(),
getPeer()->getIPAddress().c_str(), getPeer()->getPort(),
getPeer()->getPort(), toString().c_str()));
toString().c_str());
}
unsigned char* msgHdr = createMessageHeader(); unsigned char* msgHdr = createMessageHeader();
size_t msgHdrLen = getMessageHeaderLength(); size_t msgHdrLen = getMessageHeaderLength();
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("msglength = %lu bytes",
getLogger()->debug("msglength = %lu bytes", static_cast<unsigned long>(msgHdrLen+blockLength_)));
static_cast<unsigned long>(msgHdrLen+blockLength_));
}
getPeerConnection()->pushBytes(msgHdr, msgHdrLen); getPeerConnection()->pushBytes(msgHdr, msgHdrLen);
getPeerConnection()->sendPendingData(); getPeerConnection()->sendPendingData();
off_t pieceDataOffset = off_t pieceDataOffset =
@ -226,10 +220,8 @@ std::string BtPieceMessage::toString() const
bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece) bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)
{ {
if(!getPieceStorage()->isEndGame() && piece->isHashCalculated()) { if(!getPieceStorage()->isEndGame() && piece->isHashCalculated()) {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("Hash is available!! index=%lu",
getLogger()->debug("Hash is available!! index=%lu", static_cast<unsigned long>(piece->getIndex())));
static_cast<unsigned long>(piece->getIndex()));
}
return return
piece->getHashString()==downloadContext_->getPieceHash(piece->getIndex()); piece->getHashString()==downloadContext_->getPieceHash(piece->getIndex());
} else { } else {
@ -243,22 +235,18 @@ bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)
void BtPieceMessage::onNewPiece(const SharedHandle<Piece>& piece) void BtPieceMessage::onNewPiece(const SharedHandle<Piece>& piece)
{ {
if(getLogger()->info()) { A2_LOG_INFO(fmt(MSG_GOT_NEW_PIECE,
getLogger()->info(MSG_GOT_NEW_PIECE, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), static_cast<unsigned long>(piece->getIndex())));
static_cast<unsigned long>(piece->getIndex()));
}
getPieceStorage()->completePiece(piece); getPieceStorage()->completePiece(piece);
getPieceStorage()->advertisePiece(getCuid(), piece->getIndex()); getPieceStorage()->advertisePiece(getCuid(), piece->getIndex());
} }
void BtPieceMessage::onWrongPiece(const SharedHandle<Piece>& piece) void BtPieceMessage::onWrongPiece(const SharedHandle<Piece>& piece)
{ {
if(getLogger()->info()) { A2_LOG_INFO(fmt(MSG_GOT_WRONG_PIECE,
getLogger()->info(MSG_GOT_WRONG_PIECE, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), static_cast<unsigned long>(piece->getIndex())));
static_cast<unsigned long>(piece->getIndex()));
}
erasePieceOnDisk(piece); erasePieceOnDisk(piece);
piece->clearAllBlock(); piece->clearAllBlock();
piece->destroyHashContext(); piece->destroyHashContext();
@ -286,12 +274,11 @@ void BtPieceMessage::onChokingEvent(const BtChokingEvent& event)
if(!isInvalidate() && if(!isInvalidate() &&
!isSendingInProgress() && !isSendingInProgress() &&
!getPeer()->isInAmAllowedIndexSet(index_)) { !getPeer()->isInAmAllowedIndexSet(index_)) {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt(MSG_REJECT_PIECE_CHOKED,
getLogger()->debug(MSG_REJECT_PIECE_CHOKED, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), static_cast<unsigned long>(index_),
static_cast<unsigned long>(index_), begin_,
begin_, blockLength_); blockLength_));
}
if(getPeer()->isFastExtensionEnabled()) { if(getPeer()->isFastExtensionEnabled()) {
BtMessageHandle rej = BtMessageHandle rej =
getBtMessageFactory()->createRejectMessage getBtMessageFactory()->createRejectMessage
@ -310,12 +297,11 @@ void BtPieceMessage::onCancelSendingPieceEvent
index_ == event.getIndex() && index_ == event.getIndex() &&
begin_ == event.getBegin() && begin_ == event.getBegin() &&
blockLength_ == event.getLength()) { blockLength_ == event.getLength()) {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt(MSG_REJECT_PIECE_CANCEL,
getLogger()->debug(MSG_REJECT_PIECE_CANCEL, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), static_cast<unsigned long>(index_),
static_cast<unsigned long>(index_), begin_,
begin_, blockLength_); blockLength_));
}
if(getPeer()->isFastExtensionEnabled()) { if(getPeer()->isFastExtensionEnabled()) {
BtMessageHandle rej = BtMessageHandle rej =
getBtMessageFactory()->createRejectMessage getBtMessageFactory()->createRejectMessage

View File

@ -38,6 +38,7 @@
#include "util.h" #include "util.h"
#include "message.h" #include "message.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "Peer.h" #include "Peer.h"
#include "DHTNode.h" #include "DHTNode.h"
#include "DHTRoutingTable.h" #include "DHTRoutingTable.h"
@ -45,19 +46,21 @@
#include "DHTTaskFactory.h" #include "DHTTaskFactory.h"
#include "DHTTask.h" #include "DHTTask.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
#include "a2functional.h" #include "a2functional.h"
namespace aria2 { namespace aria2 {
const std::string BtPortMessage::NAME("port"); const std::string BtPortMessage::NAME("port");
BtPortMessage::BtPortMessage(uint16_t port): BtPortMessage::BtPortMessage(uint16_t port)
SimpleBtMessage(ID, NAME), port_(port), : SimpleBtMessage(ID, NAME),
localNode_(0), port_(port),
routingTable_(0), localNode_(0),
taskQueue_(0), routingTable_(0),
taskFactory_(0) taskQueue_(0),
{} taskFactory_(0)
{}
SharedHandle<BtPortMessage> BtPortMessage::create SharedHandle<BtPortMessage> BtPortMessage::create
(const unsigned char* data, size_t dataLength) (const unsigned char* data, size_t dataLength)
@ -73,9 +76,7 @@ void BtPortMessage::doReceivedAction()
{ {
if(taskFactory_ && taskQueue_) { if(taskFactory_ && taskQueue_) {
if(port_ == 0) { if(port_ == 0) {
if(getLogger()->debug()) { A2_LOG_DEBUG("Ignored port 0.");
getLogger()->debug("Ignored port 0.");
}
return; return;
} }
// node id is random at this point. When ping reply received, new DHTNode // node id is random at this point. When ping reply received, new DHTNode
@ -89,12 +90,12 @@ void BtPortMessage::doReceivedAction()
} }
if(routingTable_->countBucket() == 1) { if(routingTable_->countBucket() == 1) {
// initiate bootstrap // initiate bootstrap
getLogger()->info("Dispatch node_lookup since too few buckets."); A2_LOG_INFO("Dispatch node_lookup since too few buckets.");
taskQueue_->addImmediateTask taskQueue_->addImmediateTask
(taskFactory_->createNodeLookupTask(localNode_->getID())); (taskFactory_->createNodeLookupTask(localNode_->getID()));
} }
} else { } else {
getLogger()->info A2_LOG_INFO
("DHT port message received while localhost didn't declare support it."); ("DHT port message received while localhost didn't declare support it.");
} }
} }

View File

@ -37,6 +37,7 @@
#include "RequestGroup.h" #include "RequestGroup.h"
#include "Option.h" #include "Option.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "DownloadHandlerConstants.h" #include "DownloadHandlerConstants.h"
#include "File.h" #include "File.h"
#include "PieceStorage.h" #include "PieceStorage.h"
@ -46,6 +47,7 @@
#include "Exception.h" #include "Exception.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "download_helper.h" #include "download_helper.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
@ -66,8 +68,8 @@ void BtPostDownloadHandler::getNextRequestGroups
(std::vector<SharedHandle<RequestGroup> >& groups, (std::vector<SharedHandle<RequestGroup> >& groups,
RequestGroup* requestGroup) RequestGroup* requestGroup)
{ {
getLogger()->info("Generating RequestGroups for Torrent file %s", A2_LOG_INFO(fmt("Generating RequestGroups for Torrent file %s",
requestGroup->getFirstFilePath().c_str()); requestGroup->getFirstFilePath().c_str()));
std::string content; std::string content;
try { try {
requestGroup->getPieceStorage()->getDiskAdaptor()->openExistingFile(); requestGroup->getPieceStorage()->getDiskAdaptor()->openExistingFile();

View File

@ -41,13 +41,14 @@
#include "LogFactory.h" #include "LogFactory.h"
#include "SimpleRandomizer.h" #include "SimpleRandomizer.h"
#include "wallclock.h" #include "wallclock.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
BtSeederStateChoke::BtSeederStateChoke(): BtSeederStateChoke::BtSeederStateChoke()
round_(0), : round_(0),
lastRound_(0), lastRound_(0)
logger_(LogFactory::getInstance()) {} {}
BtSeederStateChoke::~BtSeederStateChoke() {} BtSeederStateChoke::~BtSeederStateChoke() {}
@ -123,8 +124,9 @@ void BtSeederStateChoke::unchoke
for(std::vector<PeerEntry>::iterator eoi = peers.end(); for(std::vector<PeerEntry>::iterator eoi = peers.end();
r != eoi && count; ++r, --count) { r != eoi && count; ++r, --count) {
(*r).getPeer()->chokingRequired(false); (*r).getPeer()->chokingRequired(false);
logger_->info("RU: %s, ulspd=%u", (*r).getPeer()->getIPAddress().c_str(), A2_LOG_INFO(fmt("RU: %s, ulspd=%u",
(*r).getUploadSpeed()); (*r).getPeer()->getIPAddress().c_str(),
(*r).getUploadSpeed()));
} }
if(round_ < 2) { if(round_ < 2) {
@ -134,7 +136,7 @@ void BtSeederStateChoke::unchoke
std::random_shuffle(r, peers.end(), std::random_shuffle(r, peers.end(),
*(SimpleRandomizer::getInstance().get())); *(SimpleRandomizer::getInstance().get()));
(*r).getPeer()->optUnchoking(true); (*r).getPeer()->optUnchoking(true);
logger_->info("POU: %s", (*r).getPeer()->getIPAddress().c_str()); A2_LOG_INFO(fmt("POU: %s", (*r).getPeer()->getIPAddress().c_str()));
} }
} }
} }
@ -153,7 +155,7 @@ void
BtSeederStateChoke::executeChoke BtSeederStateChoke::executeChoke
(const std::vector<SharedHandle<Peer> >& peerSet) (const std::vector<SharedHandle<Peer> >& peerSet)
{ {
logger_->info("Seeder state, %d choke round started", round_); A2_LOG_INFO(fmt("Seeder state, %d choke round started", round_));
lastRound_ = global::wallclock; lastRound_ = global::wallclock;
std::vector<PeerEntry> peerEntries; std::vector<PeerEntry> peerEntries;

View File

@ -45,7 +45,6 @@
namespace aria2 { namespace aria2 {
class Peer; class Peer;
class Logger;
class BtSeederStateChoke { class BtSeederStateChoke {
private: private:
@ -53,8 +52,6 @@ private:
Timer lastRound_; Timer lastRound_;
Logger* logger_;
class PeerEntry { class PeerEntry {
private: private:
SharedHandle<Peer> peer_; SharedHandle<Peer> peer_;

View File

@ -83,10 +83,11 @@
#include "DownloadContext.h" #include "DownloadContext.h"
#include "PieceStorage.h" #include "PieceStorage.h"
#include "PeerStorage.h" #include "PeerStorage.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
BtSetup::BtSetup():logger_(LogFactory::getInstance()) {} BtSetup::BtSetup() {}
void BtSetup::setup(std::vector<Command*>& commands, void BtSetup::setup(std::vector<Command*>& commands,
RequestGroup* requestGroup, RequestGroup* requestGroup,
@ -221,7 +222,7 @@ void BtSetup::setup(std::vector<Command*>& commands,
if(option->getAsBool(PREF_BT_ENABLE_LPD) && if(option->getAsBool(PREF_BT_ENABLE_LPD) &&
(metadataGetMode || !torrentAttrs->privateTorrent)) { (metadataGetMode || !torrentAttrs->privateTorrent)) {
if(LpdReceiveMessageCommand::getNumInstance() == 0) { if(LpdReceiveMessageCommand::getNumInstance() == 0) {
logger_->info("Initializing LpdMessageReceiver."); A2_LOG_INFO("Initializing LpdMessageReceiver.");
SharedHandle<LpdMessageReceiver> receiver SharedHandle<LpdMessageReceiver> receiver
(new LpdMessageReceiver(LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT)); (new LpdMessageReceiver(LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT));
bool initialized = false; bool initialized = false;
@ -245,15 +246,15 @@ void BtSetup::setup(std::vector<Command*>& commands,
} }
} }
if(initialized) { if(initialized) {
logger_->info("LpdMessageReceiver initialized. multicastAddr=%s:%u," A2_LOG_INFO(fmt("LpdMessageReceiver initialized. multicastAddr=%s:%u,"
" localAddr=%s", " localAddr=%s",
LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT, LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT,
receiver->getLocalAddress().c_str()); receiver->getLocalAddress().c_str()));
LpdReceiveMessageCommand* cmd = LpdReceiveMessageCommand* cmd =
LpdReceiveMessageCommand::getInstance(e, receiver); LpdReceiveMessageCommand::getInstance(e, receiver);
e->addCommand(cmd); e->addCommand(cmd);
} else { } else {
logger_->info("LpdMessageReceiver not initialized."); A2_LOG_INFO("LpdMessageReceiver not initialized.");
} }
} }
if(LpdReceiveMessageCommand::getNumInstance()) { if(LpdReceiveMessageCommand::getNumInstance()) {
@ -261,20 +262,20 @@ void BtSetup::setup(std::vector<Command*>& commands,
bittorrent::getInfoHash(requestGroup->getDownloadContext()); bittorrent::getInfoHash(requestGroup->getDownloadContext());
SharedHandle<LpdMessageReceiver> receiver = SharedHandle<LpdMessageReceiver> receiver =
LpdReceiveMessageCommand::getInstance()->getLpdMessageReceiver(); LpdReceiveMessageCommand::getInstance()->getLpdMessageReceiver();
logger_->info("Initializing LpdMessageDispatcher."); A2_LOG_INFO("Initializing LpdMessageDispatcher.");
SharedHandle<LpdMessageDispatcher> dispatcher SharedHandle<LpdMessageDispatcher> dispatcher
(new LpdMessageDispatcher (new LpdMessageDispatcher
(std::string(&infoHash[0], &infoHash[INFO_HASH_LENGTH]), (std::string(&infoHash[0], &infoHash[INFO_HASH_LENGTH]),
btRuntime->getListenPort(), btRuntime->getListenPort(),
LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT)); LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT));
if(dispatcher->init(receiver->getLocalAddress(), /*ttl*/1, /*loop*/0)) { if(dispatcher->init(receiver->getLocalAddress(), /*ttl*/1, /*loop*/0)) {
logger_->info("LpdMessageDispatcher initialized."); A2_LOG_INFO("LpdMessageDispatcher initialized.");
LpdDispatchMessageCommand* cmd = LpdDispatchMessageCommand* cmd =
new LpdDispatchMessageCommand(e->newCUID(), dispatcher, e); new LpdDispatchMessageCommand(e->newCUID(), dispatcher, e);
cmd->setBtRuntime(btRuntime); cmd->setBtRuntime(btRuntime);
e->addCommand(cmd); e->addCommand(cmd);
} else { } else {
logger_->info("LpdMessageDispatcher not initialized."); A2_LOG_INFO("LpdMessageDispatcher not initialized.");
} }
} }
} }

View File

@ -40,15 +40,12 @@
namespace aria2 { namespace aria2 {
class Logger;
class RequestGroup; class RequestGroup;
class DownloadEngine; class DownloadEngine;
class Option; class Option;
class Command; class Command;
class BtSetup { class BtSetup {
private:
Logger* logger_;
public: public:
BtSetup(); BtSetup();

View File

@ -37,8 +37,10 @@
#include "RequestGroup.h" #include "RequestGroup.h"
#include "BtRuntime.h" #include "BtRuntime.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "wallclock.h" #include "wallclock.h"
#include "util.h" #include "util.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
@ -46,10 +48,10 @@ BtStopDownloadCommand::BtStopDownloadCommand
(cuid_t cuid, (cuid_t cuid,
RequestGroup* requestGroup, RequestGroup* requestGroup,
DownloadEngine* e, DownloadEngine* e,
time_t timeout): time_t timeout)
TimeBasedCommand(cuid, e, 1), : TimeBasedCommand(cuid, e, 1),
requestGroup_(requestGroup), requestGroup_(requestGroup),
timeout_(timeout) timeout_(timeout)
{} {}
void BtStopDownloadCommand::preProcess() void BtStopDownloadCommand::preProcess()
@ -58,9 +60,9 @@ void BtStopDownloadCommand::preProcess()
enableExit(); enableExit();
} }
if(checkPoint_.difference(global::wallclock) >= timeout_) { if(checkPoint_.difference(global::wallclock) >= timeout_) {
getLogger()->notice("GID#%s Stop downloading torrent due to" A2_LOG_NOTICE(fmt("GID#%s Stop downloading torrent due to"
" --bt-stop-timeout option.", " --bt-stop-timeout option.",
util::itos(requestGroup_->getGID()).c_str()); util::itos(requestGroup_->getGID()).c_str()));
requestGroup_->setForceHaltRequested(true); requestGroup_->setForceHaltRequested(true);
enableExit(); enableExit();
} }

View File

@ -37,12 +37,14 @@
#include "DownloadEngine.h" #include "DownloadEngine.h"
#include "RequestGroup.h" #include "RequestGroup.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "message.h" #include "message.h"
#include "prefs.h" #include "prefs.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "a2functional.h" #include "a2functional.h"
#include "RecoverableException.h" #include "RecoverableException.h"
#include "util.h" #include "util.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
@ -69,18 +71,18 @@ bool CheckIntegrityCommand::executeInternal()
// needed. // needed.
getRequestGroup()->enableSaveControlFile(); getRequestGroup()->enableSaveControlFile();
if(getRequestGroup()->downloadFinished()) { if(getRequestGroup()->downloadFinished()) {
getLogger()->notice A2_LOG_NOTICE
(MSG_VERIFICATION_SUCCESSFUL, (fmt(MSG_VERIFICATION_SUCCESSFUL,
getRequestGroup()->getDownloadContext()->getBasePath().c_str()); getRequestGroup()->getDownloadContext()->getBasePath().c_str()));
std::vector<Command*>* commands = new std::vector<Command*>(); std::vector<Command*>* commands = new std::vector<Command*>();
auto_delete_container<std::vector<Command*> > commandsDel(commands); auto_delete_container<std::vector<Command*> > commandsDel(commands);
entry_->onDownloadFinished(*commands, getDownloadEngine()); entry_->onDownloadFinished(*commands, getDownloadEngine());
getDownloadEngine()->addCommand(*commands); getDownloadEngine()->addCommand(*commands);
commands->clear(); commands->clear();
} else { } else {
getLogger()->error A2_LOG_ERROR
(MSG_VERIFICATION_FAILED, (fmt(MSG_VERIFICATION_FAILED,
getRequestGroup()->getDownloadContext()->getBasePath().c_str()); getRequestGroup()->getDownloadContext()->getBasePath().c_str()));
std::vector<Command*>* commands = new std::vector<Command*>(); std::vector<Command*>* commands = new std::vector<Command*>();
auto_delete_container<std::vector<Command*> > commandsDel(commands); auto_delete_container<std::vector<Command*> > commandsDel(commands);
entry_->onDownloadIncomplete(*commands, getDownloadEngine()); entry_->onDownloadIncomplete(*commands, getDownloadEngine());
@ -98,12 +100,13 @@ bool CheckIntegrityCommand::executeInternal()
bool CheckIntegrityCommand::handleException(Exception& e) bool CheckIntegrityCommand::handleException(Exception& e)
{ {
getDownloadEngine()->getCheckIntegrityMan()->dropPickedEntry(); getDownloadEngine()->getCheckIntegrityMan()->dropPickedEntry();
getLogger()->error(MSG_FILE_VALIDATION_FAILURE, e, A2_LOG_ERROR_EX(fmt(MSG_FILE_VALIDATION_FAILURE,
util::itos(getCuid()).c_str()); util::itos(getCuid()).c_str()),
getLogger()->error e);
(MSG_DOWNLOAD_NOT_COMPLETE, A2_LOG_ERROR
util::itos(getCuid()).c_str(), (fmt(MSG_DOWNLOAD_NOT_COMPLETE,
getRequestGroup()->getDownloadContext()->getBasePath().c_str()); util::itos(getCuid()).c_str(),
getRequestGroup()->getDownloadContext()->getBasePath().c_str()));
return true; return true;
} }

View File

@ -37,15 +37,17 @@
#include "CheckIntegrityCommand.h" #include "CheckIntegrityCommand.h"
#include "message.h" #include "message.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "util.h" #include "util.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
CheckIntegrityDispatcherCommand::CheckIntegrityDispatcherCommand CheckIntegrityDispatcherCommand::CheckIntegrityDispatcherCommand
(cuid_t cuid, (cuid_t cuid,
const SharedHandle<CheckIntegrityMan>& fileAllocMan, const SharedHandle<CheckIntegrityMan>& fileAllocMan,
DownloadEngine* e):SequentialDispatcherCommand<CheckIntegrityEntry> DownloadEngine* e)
(cuid, fileAllocMan, e) : SequentialDispatcherCommand<CheckIntegrityEntry>(cuid, fileAllocMan, e)
{ {
setStatusRealtime(); setStatusRealtime();
} }
@ -54,11 +56,9 @@ Command* CheckIntegrityDispatcherCommand::createCommand
(const SharedHandle<CheckIntegrityEntry>& entry) (const SharedHandle<CheckIntegrityEntry>& entry)
{ {
cuid_t newCUID = getDownloadEngine()->newCUID(); cuid_t newCUID = getDownloadEngine()->newCUID();
if(getLogger()->info()) { A2_LOG_INFO(fmt("CUID#%s - Dispatching CheckIntegrityCommand CUID#%s.",
getLogger()->info("CUID#%s - Dispatching CheckIntegrityCommand CUID#%s.", util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), util::itos(newCUID).c_str()));
util::itos(newCUID).c_str());
}
return new CheckIntegrityCommand return new CheckIntegrityCommand
(newCUID, entry->getRequestGroup(), getDownloadEngine(), entry); (newCUID, entry->getRequestGroup(), getDownloadEngine(), entry);
} }

View File

@ -34,17 +34,17 @@
/* copyright --> */ /* copyright --> */
#include "Command.h" #include "Command.h"
#include "LogFactory.h" #include "LogFactory.h"
#include "Logger.h"
namespace aria2 { namespace aria2 {
Command::Command(cuid_t cuid):status_(STATUS_INACTIVE), Command::Command(cuid_t cuid)
cuid_(cuid), : status_(STATUS_INACTIVE),
logger_(LogFactory::getInstance()), cuid_(cuid),
readEvent_(false), readEvent_(false),
writeEvent_(false), writeEvent_(false),
errorEvent_(false), errorEvent_(false),
hupEvent_(false) {} hupEvent_(false)
{}
void Command::transitStatus() void Command::transitStatus()
{ {

View File

@ -39,8 +39,6 @@
namespace aria2 { namespace aria2 {
class Logger;
typedef int64_t cuid_t; typedef int64_t cuid_t;
class Command { class Command {
@ -56,18 +54,12 @@ private:
STATUS status_; STATUS status_;
cuid_t cuid_; cuid_t cuid_;
Logger* logger_;
bool readEvent_; bool readEvent_;
bool writeEvent_; bool writeEvent_;
bool errorEvent_; bool errorEvent_;
bool hupEvent_; bool hupEvent_;
protected: protected:
Logger* getLogger() const
{
return logger_;
}
bool readEventEnabled() const bool readEventEnabled() const
{ {
return readEvent_; return readEvent_;

View File

@ -43,6 +43,7 @@
#include "Logger.h" #include "Logger.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
#include "NsCookieParser.h" #include "NsCookieParser.h"
#include "File.h" #include "File.h"
#include "a2functional.h" #include "a2functional.h"
@ -139,7 +140,7 @@ bool CookieStorage::DomainEntry::operator<(const DomainEntry& de) const
return key_ < de.key_; return key_ < de.key_;
} }
CookieStorage::CookieStorage():logger_(LogFactory::getInstance()) {} CookieStorage::CookieStorage() {}
CookieStorage::~CookieStorage() {} CookieStorage::~CookieStorage() {}
@ -326,13 +327,13 @@ bool CookieStorage::load(const std::string& filename, time_t now)
char header[16]; // "SQLite format 3" plus \0 char header[16]; // "SQLite format 3" plus \0
std::ifstream s(filename.c_str(), std::ios::binary); std::ifstream s(filename.c_str(), std::ios::binary);
if(!s) { if(!s) {
logger_->error("Failed to open cookie file %s", filename.c_str()); A2_LOG_ERROR(fmt("Failed to open cookie file %s", filename.c_str()));
return false; return false;
} }
s.get(header, sizeof(header)); s.get(header, sizeof(header));
if(!s) { if(!s) {
logger_->error("Failed to read header of cookie file %s", A2_LOG_ERROR(fmt("Failed to read header of cookie file %s",
filename.c_str()); filename.c_str()));
return false; return false;
} }
try { try {
@ -342,11 +343,9 @@ bool CookieStorage::load(const std::string& filename, time_t now)
try { try {
Sqlite3MozCookieParser(filename).parse(cookies); Sqlite3MozCookieParser(filename).parse(cookies);
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
if(logger_->info()) { A2_LOG_INFO_EX(EX_EXCEPTION_CAUGHT, e);
logger_->info(EX_EXCEPTION_CAUGHT, e); A2_LOG_INFO("This does not look like Firefox3 cookie file."
logger_->info("This does not look like Firefox3 cookie file." " Retrying, assuming it is Chromium cookie file.");
" Retrying, assuming it is Chromium cookie file.");
}
// Try chrome cookie format // Try chrome cookie format
Sqlite3ChromiumCookieParser(filename).parse(cookies); Sqlite3ChromiumCookieParser(filename).parse(cookies);
} }
@ -362,7 +361,7 @@ bool CookieStorage::load(const std::string& filename, time_t now)
} }
return true; return true;
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
logger_->error("Failed to load cookies from %s", filename.c_str()); A2_LOG_ERROR(fmt("Failed to load cookies from %s", filename.c_str()));
return false; return false;
} }
} }
@ -373,7 +372,7 @@ bool CookieStorage::saveNsFormat(const std::string& filename)
{ {
std::ofstream o(tempfilename.c_str(), std::ios::binary); std::ofstream o(tempfilename.c_str(), std::ios::binary);
if(!o) { if(!o) {
logger_->error("Cannot create cookie file %s", filename.c_str()); A2_LOG_ERROR(fmt("Cannot create cookie file %s", filename.c_str()));
return false; return false;
} }
for(std::deque<DomainEntry>::const_iterator i = domains_.begin(), for(std::deque<DomainEntry>::const_iterator i = domains_.begin(),
@ -382,15 +381,16 @@ bool CookieStorage::saveNsFormat(const std::string& filename)
} }
o.flush(); o.flush();
if(!o) { if(!o) {
logger_->error("Failed to save cookies to %s", filename.c_str()); A2_LOG_ERROR(fmt("Failed to save cookies to %s", filename.c_str()));
return false; return false;
} }
} }
if(File(tempfilename).renameTo(filename)) { if(File(tempfilename).renameTo(filename)) {
return true; return true;
} else { } else {
logger_->error("Could not rename file %s as %s", A2_LOG_ERROR(fmt("Could not rename file %s as %s",
tempfilename.c_str(), filename.c_str()); tempfilename.c_str(),
filename.c_str()));
return false; return false;
} }
} }

View File

@ -47,8 +47,6 @@
namespace aria2 { namespace aria2 {
class Logger;
class CookieStorage { class CookieStorage {
public: public:
@ -122,8 +120,6 @@ public:
private: private:
std::deque<DomainEntry> domains_; std::deque<DomainEntry> domains_;
Logger* logger_;
template<typename InputIterator> template<typename InputIterator>
void storeCookies(InputIterator first, InputIterator last, time_t now) void storeCookies(InputIterator first, InputIterator last, time_t now)
{ {

View File

@ -55,6 +55,7 @@
#include "util.h" #include "util.h"
#include "DHTIDCloser.h" #include "DHTIDCloser.h"
#include "a2functional.h" #include "a2functional.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
@ -102,19 +103,15 @@ private:
sendMessage(); sendMessage();
} }
if(inFlightMessage_ == 0) { if(inFlightMessage_ == 0) {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("Finished node_lookup for node ID %s",
getLogger()->debug("Finished node_lookup for node ID %s", util::toHex(targetID_, DHT_ID_LENGTH).c_str()));
util::toHex(targetID_, DHT_ID_LENGTH).c_str());
}
onFinish(); onFinish();
updateBucket(); updateBucket();
setFinished(true); setFinished(true);
} else { } else {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("%lu in flight message for node ID %s",
getLogger()->debug("%lu in flight message for node ID %s", static_cast<unsigned long>(inFlightMessage_),
static_cast<unsigned long>(inFlightMessage_), util::toHex(targetID_, DHT_ID_LENGTH).c_str()));
util::toHex(targetID_, DHT_ID_LENGTH).c_str());
}
} }
} }
@ -167,9 +164,7 @@ public:
inFlightMessage_ = 0; inFlightMessage_ = 0;
sendMessage(); sendMessage();
if(inFlightMessage_ == 0) { if(inFlightMessage_ == 0) {
if(getLogger()->debug()) { A2_LOG_DEBUG("No message was sent in this lookup stage. Finished.");
getLogger()->debug("No message was sent in this lookup stage. Finished.");
}
setFinished(true); setFinished(true);
} }
} }
@ -191,27 +186,21 @@ public:
DHT_ID_LENGTH) != 0) { DHT_ID_LENGTH) != 0) {
entries_.push_front(*i); entries_.push_front(*i);
++count; ++count;
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("Received nodes: id=%s, ip=%s",
getLogger()->debug("Received nodes: id=%s, ip=%s", util::toHex((*i)->node->getID(),
util::toHex((*i)->node->getID(), DHT_ID_LENGTH).c_str(),
DHT_ID_LENGTH).c_str(), (*i)->node->getIPAddress().c_str()));
(*i)->node->getIPAddress().c_str());
}
} }
} }
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("%lu node lookup entries added.",
getLogger()->debug("%lu node lookup entries added.", static_cast<unsigned long>(count)));
static_cast<unsigned long>(count));
}
std::stable_sort(entries_.begin(), entries_.end(), DHTIDCloser(targetID_)); std::stable_sort(entries_.begin(), entries_.end(), DHTIDCloser(targetID_));
entries_.erase entries_.erase
(std::unique(entries_.begin(), entries_.end(), (std::unique(entries_.begin(), entries_.end(),
DerefEqualTo<SharedHandle<DHTNodeLookupEntry> >()), DerefEqualTo<SharedHandle<DHTNodeLookupEntry> >()),
entries_.end()); entries_.end());
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("%lu node lookup entries are unique.",
getLogger()->debug("%lu node lookup entries are unique.", static_cast<unsigned long>(entries_.size())));
static_cast<unsigned long>(entries_.size()));
}
if(entries_.size() > DHTBucket::K) { if(entries_.size() > DHTBucket::K) {
entries_.erase(entries_.begin()+DHTBucket::K, entries_.end()); entries_.erase(entries_.begin()+DHTBucket::K, entries_.end());
} }
@ -220,10 +209,8 @@ public:
void onTimeout(const SharedHandle<DHTNode>& node) void onTimeout(const SharedHandle<DHTNode>& node)
{ {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("node lookup message timeout for node ID=%s",
getLogger()->debug("node lookup message timeout for node ID=%s", util::toHex(node->getID(), DHT_ID_LENGTH).c_str()));
util::toHex(node->getID(), DHT_ID_LENGTH).c_str());
}
--inFlightMessage_; --inFlightMessage_;
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i = for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i =
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) { entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {

View File

@ -41,14 +41,12 @@
#include "DHTMessageCallback.h" #include "DHTMessageCallback.h"
#include "DHTBucket.h" #include "DHTBucket.h"
#include "DHTTaskQueue.h" #include "DHTTaskQueue.h"
#include "LogFactory.h"
#include "util.h" #include "util.h"
namespace aria2 { namespace aria2 {
DHTAbstractTask::DHTAbstractTask(): DHTAbstractTask::DHTAbstractTask():
finished_(false), finished_(false),
logger_(LogFactory::getInstance()),
routingTable_(0), routingTable_(0),
dispatcher_(0), dispatcher_(0),
factory_(0), factory_(0),

View File

@ -48,14 +48,10 @@ class DHTMessageFactory;
class DHTMessage; class DHTMessage;
class DHTTaskQueue; class DHTTaskQueue;
class Logger;
class DHTAbstractTask:public DHTTask { class DHTAbstractTask:public DHTTask {
private: private:
bool finished_; bool finished_;
Logger* logger_;
SharedHandle<DHTNode> localNode_; SharedHandle<DHTNode> localNode_;
DHTRoutingTable* routingTable_; DHTRoutingTable* routingTable_;
@ -70,11 +66,6 @@ protected:
{ {
finished_ = f; finished_ = f;
} }
Logger* getLogger() const
{
return logger_;
}
public: public:
DHTAbstractTask(); DHTAbstractTask();

View File

@ -49,17 +49,20 @@
#include "Option.h" #include "Option.h"
#include "message.h" #include "message.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "a2functional.h" #include "a2functional.h"
#include "FileEntry.h" #include "FileEntry.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DHTAutoSaveCommand::DHTAutoSaveCommand DHTAutoSaveCommand::DHTAutoSaveCommand
(cuid_t cuid, DownloadEngine* e, int family, time_t interval): (cuid_t cuid, DownloadEngine* e, int family, time_t interval)
TimeBasedCommand(cuid, e, interval), : TimeBasedCommand(cuid, e, interval),
family_(family) {} family_(family)
{}
DHTAutoSaveCommand::~DHTAutoSaveCommand() {} DHTAutoSaveCommand::~DHTAutoSaveCommand() {}
@ -82,7 +85,7 @@ void DHTAutoSaveCommand::save()
std::string dhtFile = std::string dhtFile =
getDownloadEngine()->getOption()-> getDownloadEngine()->getOption()->
get(family_ == AF_INET? PREF_DHT_FILE_PATH : PREF_DHT_FILE_PATH6); get(family_ == AF_INET? PREF_DHT_FILE_PATH : PREF_DHT_FILE_PATH6);
getLogger()->info("Saving DHT routing table to %s.", dhtFile.c_str()); A2_LOG_INFO(fmt("Saving DHT routing table to %s.", dhtFile.c_str()));
File tempFile(dhtFile+"__temp"); File tempFile(dhtFile+"__temp");
// Removing tempFile is unnecessary because the file is truncated on // Removing tempFile is unnecessary because the file is truncated on
@ -118,12 +121,13 @@ void DHTAutoSaveCommand::save()
serializer.serialize(o); serializer.serialize(o);
} }
if(!tempFile.renameTo(dhtFile)) { if(!tempFile.renameTo(dhtFile)) {
getLogger()->error("Cannot move file from %s to %s.", A2_LOG_ERROR(fmt("Cannot move file from %s to %s.",
tempFile.getPath().c_str(), dhtFile.c_str()); tempFile.getPath().c_str(), dhtFile.c_str()));
} }
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
getLogger()->error("Exception caught while saving DHT routing table to %s", A2_LOG_ERROR_EX(fmt("Exception caught while saving DHT routing table to %s",
e, dhtFile.c_str()); dhtFile.c_str()),
e);
} }
} }

View File

@ -47,26 +47,26 @@
#include "bittorrent_helper.h" #include "bittorrent_helper.h"
#include "bitfield.h" #include "bitfield.h"
#include "wallclock.h" #include "wallclock.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DHTBucket::DHTBucket(size_t prefixLength, DHTBucket::DHTBucket
const unsigned char* max, const unsigned char* min, (size_t prefixLength,
const SharedHandle<DHTNode>& localNode): const unsigned char* max, const unsigned char* min,
prefixLength_(prefixLength), const SharedHandle<DHTNode>& localNode)
localNode_(localNode), : prefixLength_(prefixLength),
lastUpdated_(global::wallclock), localNode_(localNode),
logger_(LogFactory::getInstance()) lastUpdated_(global::wallclock)
{ {
memcpy(max_, max, DHT_ID_LENGTH); memcpy(max_, max, DHT_ID_LENGTH);
memcpy(min_, min, DHT_ID_LENGTH); memcpy(min_, min, DHT_ID_LENGTH);
} }
DHTBucket::DHTBucket(const SharedHandle<DHTNode>& localNode): DHTBucket::DHTBucket(const SharedHandle<DHTNode>& localNode)
prefixLength_(0), : prefixLength_(0),
localNode_(localNode), localNode_(localNode),
lastUpdated_(global::wallclock), lastUpdated_(global::wallclock)
logger_(LogFactory::getInstance())
{ {
memset(max_, 0xffu, DHT_ID_LENGTH); memset(max_, 0xffu, DHT_ID_LENGTH);
memset(min_, 0, DHT_ID_LENGTH); memset(min_, 0, DHT_ID_LENGTH);
@ -206,16 +206,14 @@ SharedHandle<DHTBucket> DHTBucket::split()
} }
nodes_ = lNodes; nodes_ = lNodes;
// TODO create toString() and use it. // TODO create toString() and use it.
if(logger_->debug()) { A2_LOG_DEBUG(fmt("New bucket. prefixLength=%u, Range:%s-%s",
logger_->debug("New bucket. prefixLength=%u, Range:%s-%s",
static_cast<unsigned int>(rBucket->getPrefixLength()), static_cast<unsigned int>(rBucket->getPrefixLength()),
util::toHex(rBucket->getMinID(), DHT_ID_LENGTH).c_str(), util::toHex(rBucket->getMinID(), DHT_ID_LENGTH).c_str(),
util::toHex(rBucket->getMaxID(), DHT_ID_LENGTH).c_str()); util::toHex(rBucket->getMaxID(), DHT_ID_LENGTH).c_str()));
logger_->debug("Existing bucket. prefixLength=%u, Range:%s-%s", A2_LOG_DEBUG(fmt("Existing bucket. prefixLength=%u, Range:%s-%s",
static_cast<unsigned int>(prefixLength_), static_cast<unsigned int>(prefixLength_),
util::toHex(getMinID(), DHT_ID_LENGTH).c_str(), util::toHex(getMinID(), DHT_ID_LENGTH).c_str(),
util::toHex(getMaxID(), DHT_ID_LENGTH).c_str()); util::toHex(getMaxID(), DHT_ID_LENGTH).c_str()));
}
return rBucket; return rBucket;
} }

View File

@ -48,7 +48,6 @@
namespace aria2 { namespace aria2 {
class DHTNode; class DHTNode;
class Logger;
class DHTBucket { class DHTBucket {
private: private:
@ -70,8 +69,6 @@ private:
Timer lastUpdated_; Timer lastUpdated_;
Logger* logger_;
bool isInRange(const unsigned char* nodeID, bool isInRange(const unsigned char* nodeID,
const unsigned char* max, const unsigned char* min) const; const unsigned char* max, const unsigned char* min) const;
public: public:

View File

@ -41,7 +41,9 @@
#include "DHTNodeLookupEntry.h" #include "DHTNodeLookupEntry.h"
#include "util.h" #include "util.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "DHTMessageCallback.h" #include "DHTMessageCallback.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
@ -67,8 +69,8 @@ void DHTBucketRefreshTask::startup()
task->setTaskQueue(getTaskQueue()); task->setTaskQueue(getTaskQueue());
task->setLocalNode(getLocalNode()); task->setLocalNode(getLocalNode());
getLogger()->info("Dispating bucket refresh. targetID=%s", A2_LOG_INFO(fmt("Dispating bucket refresh. targetID=%s",
util::toHex(targetID, DHT_ID_LENGTH).c_str()); util::toHex(targetID, DHT_ID_LENGTH).c_str()));
getTaskQueue()->addPeriodicTask1(task); getTaskQueue()->addPeriodicTask1(task);
} }
} }

View File

@ -43,13 +43,14 @@
#include "util.h" #include "util.h"
#include "Socket.h" #include "Socket.h"
#include "SimpleRandomizer.h" #include "SimpleRandomizer.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DHTConnectionImpl::DHTConnectionImpl(int family): DHTConnectionImpl::DHTConnectionImpl(int family)
socket_(new SocketCore(SOCK_DGRAM)), : socket_(new SocketCore(SOCK_DGRAM)),
family_(family), family_(family)
logger_(LogFactory::getInstance()) {} {}
DHTConnectionImpl::~DHTConnectionImpl() {} DHTConnectionImpl::~DHTConnectionImpl() {}
@ -86,10 +87,11 @@ bool DHTConnectionImpl::bind(uint16_t& port, const std::string& addr)
std::pair<std::string, uint16_t> svaddr; std::pair<std::string, uint16_t> svaddr;
socket_->getAddrInfo(svaddr); socket_->getAddrInfo(svaddr);
port = svaddr.second; port = svaddr.second;
logger_->notice("IPv%d DHT: listening to port %d", ipv, port); A2_LOG_NOTICE(fmt("IPv%d DHT: listening to port %d", ipv, port));
return true; return true;
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
logger_->error("Failed to bind for IPv%d DHT. port=%u", e, ipv, port); A2_LOG_ERROR_EX(fmt("Failed to bind for IPv%d DHT. port=%u", ipv, port),
e);
} }
return false; return false;
} }

View File

@ -42,15 +42,12 @@
namespace aria2 { namespace aria2 {
class SocketCore; class SocketCore;
class Logger;
class DHTConnectionImpl:public DHTConnection { class DHTConnectionImpl:public DHTConnection {
private: private:
SharedHandle<SocketCore> socket_; SharedHandle<SocketCore> socket_;
int family_; int family_;
Logger* logger_;
public: public:
DHTConnectionImpl(int family); DHTConnectionImpl(int family);

View File

@ -47,7 +47,9 @@
#include "DHTTask.h" #include "DHTTask.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
#ifdef ENABLE_ASYNC_DNS #ifdef ENABLE_ASYNC_DNS
#include "AsyncNameResolver.h" #include "AsyncNameResolver.h"
#endif // ENABLE_ASYNC_DNS #endif // ENABLE_ASYNC_DNS
@ -108,7 +110,7 @@ bool DHTEntryPointNameResolveCommand::execute()
return false; return false;
} }
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
getLogger()->error(EX_EXCEPTION_CAUGHT, e); A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
} }
resolver_->reset(); resolver_->reset();
entryPoints_.pop_front(); entryPoints_.pop_front();
@ -129,7 +131,7 @@ bool DHTEntryPointNameResolveCommand::execute()
resolvedEntryPoints_.push_back(p); resolvedEntryPoints_.push_back(p);
addPingTask(p); addPingTask(p);
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
getLogger()->error(EX_EXCEPTION_CAUGHT, e); A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
} }
entryPoints_.pop_front(); entryPoints_.pop_front();
} }
@ -140,7 +142,7 @@ bool DHTEntryPointNameResolveCommand::execute()
taskQueue_->addPeriodicTask1(taskFactory_->createBucketRefreshTask()); taskQueue_->addPeriodicTask1(taskFactory_->createBucketRefreshTask());
} }
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
getLogger()->error(EX_EXCEPTION_CAUGHT, e); A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
} }
return true; return true;
} }
@ -163,20 +165,17 @@ bool DHTEntryPointNameResolveCommand::resolveHostname
{ {
switch(resolver->getStatus()) { switch(resolver->getStatus()) {
case AsyncNameResolver::STATUS_READY: case AsyncNameResolver::STATUS_READY:
if(getLogger()->info()) { A2_LOG_INFO(fmt(MSG_RESOLVING_HOSTNAME,
getLogger()->info(MSG_RESOLVING_HOSTNAME, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), hostname.c_str()); hostname.c_str()));
}
resolver->resolve(hostname); resolver->resolve(hostname);
setNameResolverCheck(resolver); setNameResolverCheck(resolver);
return false; return false;
case AsyncNameResolver::STATUS_SUCCESS: case AsyncNameResolver::STATUS_SUCCESS:
if(getLogger()->info()) { A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_COMPLETE,
getLogger()->info(MSG_NAME_RESOLUTION_COMPLETE, util::itos(getCuid()).c_str(),
util::itos(getCuid()).c_str(), resolver->getHostname().c_str(),
resolver->getHostname().c_str(), resolver->getResolvedAddresses().front().c_str()));
resolver->getResolvedAddresses().front().c_str());
}
return true; return true;
break; break;
case AsyncNameResolver::STATUS_ERROR: case AsyncNameResolver::STATUS_ERROR:

View File

@ -44,20 +44,23 @@
#include "PeerStorage.h" #include "PeerStorage.h"
#include "Peer.h" #include "Peer.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "bittorrent_helper.h" #include "bittorrent_helper.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "wallclock.h" #include "wallclock.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DHTGetPeersCommand::DHTGetPeersCommand(cuid_t cuid, DHTGetPeersCommand::DHTGetPeersCommand
RequestGroup* requestGroup, (cuid_t cuid,
DownloadEngine* e): RequestGroup* requestGroup,
Command(cuid), DownloadEngine* e)
requestGroup_(requestGroup), : Command(cuid),
e_(e), requestGroup_(requestGroup),
numRetry_(0), e_(e),
lastGetPeerTime_(0) numRetry_(0),
lastGetPeerTime_(0)
{ {
requestGroup_->increaseNumCommand(); requestGroup_->increaseNumCommand();
} }
@ -79,11 +82,9 @@ bool DHTGetPeersCommand::execute()
(btRuntime_->lessThanMinPeers() && (btRuntime_->lessThanMinPeers() &&
lastGetPeerTime_.difference(global::wallclock) >= GET_PEER_MIN_INTERVAL lastGetPeerTime_.difference(global::wallclock) >= GET_PEER_MIN_INTERVAL
&& !requestGroup_->downloadFinished()))) { && !requestGroup_->downloadFinished()))) {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("Issuing PeerLookup for infoHash=%s",
getLogger()->debug("Issuing PeerLookup for infoHash=%s", bittorrent::getInfoHashString
bittorrent::getInfoHashString (requestGroup_->getDownloadContext()).c_str()));
(requestGroup_->getDownloadContext()).c_str());
}
task_ = taskFactory_->createPeerLookupTask task_ = taskFactory_->createPeerLookupTask
(requestGroup_->getDownloadContext(), btRuntime_, peerStorage_); (requestGroup_->getDownloadContext(), btRuntime_, peerStorage_);
taskQueue_->addPeriodicTask2(task_); taskQueue_->addPeriodicTask2(task_);

View File

@ -43,14 +43,17 @@
#include "message.h" #include "message.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "DHTMessageCallback.h" #include "DHTMessageCallback.h"
#include "DHTNode.h" #include "DHTNode.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DHTInteractionCommand::DHTInteractionCommand(cuid_t cuid, DownloadEngine* e): DHTInteractionCommand::DHTInteractionCommand(cuid_t cuid, DownloadEngine* e)
Command(cuid), : Command(cuid),
e_(e) {} e_(e)
{}
DHTInteractionCommand::~DHTInteractionCommand() DHTInteractionCommand::~DHTInteractionCommand()
{ {
@ -86,7 +89,7 @@ bool DHTInteractionCommand::execute()
try { try {
dispatcher_->sendMessages(); dispatcher_->sendMessages();
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
getLogger()->error(EX_EXCEPTION_CAUGHT, e); A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
} }
e_->addCommand(this); e_->addCommand(this);
return false; return false;

View File

@ -42,15 +42,16 @@
#include "Logger.h" #include "Logger.h"
#include "DHTConstants.h" #include "DHTConstants.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
#include "DHTNode.h" #include "DHTNode.h"
namespace aria2 { namespace aria2 {
DHTMessageDispatcherImpl::DHTMessageDispatcherImpl DHTMessageDispatcherImpl::DHTMessageDispatcherImpl
(const SharedHandle<DHTMessageTracker>& tracker): (const SharedHandle<DHTMessageTracker>& tracker)
tracker_(tracker), : tracker_(tracker),
timeout_(DHT_MESSAGE_TIMEOUT), timeout_(DHT_MESSAGE_TIMEOUT)
logger_(LogFactory::getInstance()) {} {}
DHTMessageDispatcherImpl::~DHTMessageDispatcherImpl() {} DHTMessageDispatcherImpl::~DHTMessageDispatcherImpl() {}
@ -82,15 +83,14 @@ DHTMessageDispatcherImpl::sendMessage
if(!entry->message->isReply()) { if(!entry->message->isReply()) {
tracker_->addMessage(entry->message, entry->timeout, entry->callback); tracker_->addMessage(entry->message, entry->timeout, entry->callback);
} }
if(logger_->info()) { A2_LOG_INFO(fmt("Message sent: %s", entry->message->toString().c_str()));
logger_->info("Message sent: %s", entry->message->toString().c_str());
}
} else { } else {
return false; return false;
} }
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
logger_->info("Failed to send message: %s", A2_LOG_INFO_EX(fmt("Failed to send message: %s",
e, entry->message->toString().c_str()); entry->message->toString().c_str()),
e);
// Add message to DHTMessageTracker with timeout 0 to treat it as // Add message to DHTMessageTracker with timeout 0 to treat it as
// time out. Without this, we have untracked message and some of // time out. Without this, we have untracked message and some of
// DHTTask(such as DHTAbstractNodeLookupTask) don't finish // DHTTask(such as DHTAbstractNodeLookupTask) don't finish
@ -114,10 +114,8 @@ void DHTMessageDispatcherImpl::sendMessages()
} }
} }
messageQueue_.erase(messageQueue_.begin(), itr); messageQueue_.erase(messageQueue_.begin(), itr);
if(logger_->debug()) { A2_LOG_DEBUG(fmt("%lu dht messages remaining in the queue.",
logger_->debug("%lu dht messages remaining in the queue.", static_cast<unsigned long>(messageQueue_.size())));
static_cast<unsigned long>(messageQueue_.size()));
}
} }
size_t DHTMessageDispatcherImpl::countMessageInQueue() const size_t DHTMessageDispatcherImpl::countMessageInQueue() const

View File

@ -42,7 +42,6 @@ namespace aria2 {
class DHTMessageTracker; class DHTMessageTracker;
struct DHTMessageEntry; struct DHTMessageEntry;
class Logger;
class DHTMessageDispatcherImpl:public DHTMessageDispatcher { class DHTMessageDispatcherImpl:public DHTMessageDispatcher {
private: private:
@ -52,8 +51,6 @@ private:
time_t timeout_; time_t timeout_;
Logger* logger_;
bool sendMessage(const SharedHandle<DHTMessageEntry>& msg); bool sendMessage(const SharedHandle<DHTMessageEntry>& msg);
public: public:
DHTMessageDispatcherImpl(const SharedHandle<DHTMessageTracker>& tracker); DHTMessageDispatcherImpl(const SharedHandle<DHTMessageTracker>& tracker);

View File

@ -61,17 +61,18 @@
#include "Peer.h" #include "Peer.h"
#include "Logger.h" #include "Logger.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DHTMessageFactoryImpl::DHTMessageFactoryImpl(int family): DHTMessageFactoryImpl::DHTMessageFactoryImpl(int family)
family_(family), : family_(family),
connection_(0), connection_(0),
dispatcher_(0), dispatcher_(0),
routingTable_(0), routingTable_(0),
peerAnnounceStorage_(0), peerAnnounceStorage_(0),
tokenTracker_(0), tokenTracker_(0)
logger_(LogFactory::getInstance()) {} {}
DHTMessageFactoryImpl::~DHTMessageFactoryImpl() {} DHTMessageFactoryImpl::~DHTMessageFactoryImpl() {}
@ -256,15 +257,11 @@ DHTMessageFactoryImpl::createResponseMessage
// for now, just report error message arrived and throw exception. // for now, just report error message arrived and throw exception.
const List* e = getList(dict, DHTUnknownMessage::E); const List* e = getList(dict, DHTUnknownMessage::E);
if(e->size() == 2) { if(e->size() == 2) {
if(logger_->info()) { A2_LOG_INFO(fmt("Received Error DHT message. code=%s, msg=%s",
logger_->info("Received Error DHT message. code=%s, msg=%s",
util::itos(getInteger(e, 0)->i()).c_str(), util::itos(getInteger(e, 0)->i()).c_str(),
util::percentEncode(getString(e, 1)->s()).c_str()); util::percentEncode(getString(e, 1)->s()).c_str()));
}
} else { } else {
if(logger_->debug()) { A2_LOG_DEBUG("e doesn't have 2 elements.");
logger_->debug("e doesn't have 2 elements.");
}
} }
throw DL_ABORT_EX("Received Error DHT message."); throw DL_ABORT_EX("Received Error DHT message.");
} else if(y->s() != DHTResponseMessage::R) { } else if(y->s() != DHTResponseMessage::R) {

View File

@ -45,7 +45,6 @@ class DHTMessageDispatcher;
class DHTRoutingTable; class DHTRoutingTable;
class DHTPeerAnnounceStorage; class DHTPeerAnnounceStorage;
class DHTTokenTracker; class DHTTokenTracker;
class Logger;
class DHTMessage; class DHTMessage;
class DHTAbstractMessage; class DHTAbstractMessage;
@ -65,8 +64,6 @@ private:
DHTTokenTracker* tokenTracker_; DHTTokenTracker* tokenTracker_;
Logger* logger_;
// search node in routingTable. If it is not found, create new one. // search node in routingTable. If it is not found, create new one.
SharedHandle<DHTNode> getRemoteNode SharedHandle<DHTNode> getRemoteNode
(const unsigned char* id, const std::string& ipaddr, uint16_t port) const; (const unsigned char* id, const std::string& ipaddr, uint16_t port) const;

View File

@ -52,12 +52,13 @@
#include "Logger.h" #include "Logger.h"
#include "util.h" #include "util.h"
#include "bencode2.h" #include "bencode2.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DHTMessageReceiver::DHTMessageReceiver(const SharedHandle<DHTMessageTracker>& tracker): DHTMessageReceiver::DHTMessageReceiver
tracker_(tracker), (const SharedHandle<DHTMessageTracker>& tracker)
logger_(LogFactory::getInstance()) : tracker_(tracker)
{} {}
DHTMessageReceiver::~DHTMessageReceiver() {} DHTMessageReceiver::~DHTMessageReceiver() {}
@ -84,13 +85,14 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
isReply = true; isReply = true;
} }
} else { } else {
logger_->info("Malformed DHT message. Missing 'y' key. From:%s:%u", A2_LOG_INFO(fmt("Malformed DHT message. Missing 'y' key. From:%s:%u",
remoteAddr.c_str(), remotePort); remoteAddr.c_str(), remotePort));
return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort); return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort);
} }
} else { } else {
logger_->info("Malformed DHT message. This is not a bencoded directory." A2_LOG_INFO(fmt("Malformed DHT message. This is not a bencoded directory."
" From:%s:%u", remoteAddr.c_str(), remotePort); " From:%s:%u",
remoteAddr.c_str(), remotePort));
return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort); return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort);
} }
if(isReply) { if(isReply) {
@ -111,14 +113,14 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
factory_->createQueryMessage(dict, remoteAddr, remotePort); factory_->createQueryMessage(dict, remoteAddr, remotePort);
if(*message->getLocalNode() == *message->getRemoteNode()) { if(*message->getLocalNode() == *message->getRemoteNode()) {
// drop message from localnode // drop message from localnode
logger_->info("Received DHT message from localnode."); A2_LOG_INFO("Received DHT message from localnode.");
return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort); return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort);
} }
onMessageReceived(message); onMessageReceived(message);
return message; return message;
} }
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
logger_->info("Exception thrown while receiving DHT message.", e); A2_LOG_INFO_EX("Exception thrown while receiving DHT message.", e);
return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort); return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort);
} }
} }
@ -126,9 +128,7 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
void DHTMessageReceiver::onMessageReceived void DHTMessageReceiver::onMessageReceived
(const SharedHandle<DHTMessage>& message) (const SharedHandle<DHTMessage>& message)
{ {
if(logger_->info()) { A2_LOG_INFO(fmt("Message received: %s", message->toString().c_str()));
logger_->info("Message received: %s", message->toString().c_str());
}
message->validate(); message->validate();
message->doReceivedAction(); message->doReceivedAction();
message->getRemoteNode()->markGood(); message->getRemoteNode()->markGood();
@ -149,9 +149,7 @@ DHTMessageReceiver::handleUnknownMessage(const unsigned char* data,
{ {
SharedHandle<DHTMessage> m = SharedHandle<DHTMessage> m =
factory_->createUnknownMessage(data, length, remoteAddr, remotePort); factory_->createUnknownMessage(data, length, remoteAddr, remotePort);
if(logger_->info()) { A2_LOG_INFO(fmt("Message received: %s", m->toString().c_str()));
logger_->info("Message received: %s", m->toString().c_str());
}
return m; return m;
} }

View File

@ -46,8 +46,6 @@ class DHTConnection;
class DHTMessageFactory; class DHTMessageFactory;
class DHTRoutingTable; class DHTRoutingTable;
class Logger;
class DHTMessageReceiver { class DHTMessageReceiver {
private: private:
SharedHandle<DHTMessageTracker> tracker_; SharedHandle<DHTMessageTracker> tracker_;
@ -58,8 +56,6 @@ private:
SharedHandle<DHTRoutingTable> routingTable_; SharedHandle<DHTRoutingTable> routingTable_;
Logger* logger_;
SharedHandle<DHTMessage> SharedHandle<DHTMessage>
handleUnknownMessage(const unsigned char* data, size_t length, handleUnknownMessage(const unsigned char* data, size_t length,
const std::string& remoteAddr, uint16_t remotePort); const std::string& remoteAddr, uint16_t remotePort);

View File

@ -48,11 +48,11 @@
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "DHTConstants.h" #include "DHTConstants.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DHTMessageTracker::DHTMessageTracker(): DHTMessageTracker::DHTMessageTracker() {}
logger_(LogFactory::getInstance()) {}
DHTMessageTracker::~DHTMessageTracker() {} DHTMessageTracker::~DHTMessageTracker() {}
@ -71,18 +71,15 @@ DHTMessageTracker::messageArrived
throw DL_ABORT_EX(StringFormat("Malformed DHT message. From:%s:%u", throw DL_ABORT_EX(StringFormat("Malformed DHT message. From:%s:%u",
ipaddr.c_str(), port).str()); ipaddr.c_str(), port).str());
} }
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Searching tracker entry for TransactionID=%s, Remote=%s:%u",
logger_->debug("Searching tracker entry for TransactionID=%s, Remote=%s:%u", util::toHex(tid->s()).c_str(),
util::toHex(tid->s()).c_str(), ipaddr.c_str(), port); ipaddr.c_str(), port));
}
for(std::deque<SharedHandle<DHTMessageTrackerEntry> >::iterator i = for(std::deque<SharedHandle<DHTMessageTrackerEntry> >::iterator i =
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) { entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
if((*i)->match(tid->s(), ipaddr, port)) { if((*i)->match(tid->s(), ipaddr, port)) {
SharedHandle<DHTMessageTrackerEntry> entry = *i; SharedHandle<DHTMessageTrackerEntry> entry = *i;
entries_.erase(i); entries_.erase(i);
if(logger_->debug()) { A2_LOG_DEBUG("Tracker entry found.");
logger_->debug("Tracker entry found.");
}
SharedHandle<DHTNode> targetNode = entry->getTargetNode(); SharedHandle<DHTNode> targetNode = entry->getTargetNode();
try { try {
SharedHandle<DHTResponseMessage> message = SharedHandle<DHTResponseMessage> message =
@ -91,9 +88,7 @@ DHTMessageTracker::messageArrived
targetNode->getPort()); targetNode->getPort());
int64_t rtt = entry->getElapsedMillis(); int64_t rtt = entry->getElapsedMillis();
if(logger_->debug()) { A2_LOG_DEBUG(fmt("RTT is %s", util::itos(rtt).c_str()));
logger_->debug("RTT is %s", util::itos(rtt).c_str());
}
message->getRemoteNode()->updateRTT(rtt); message->getRemoteNode()->updateRTT(rtt);
SharedHandle<DHTMessageCallback> callback = entry->getCallback(); SharedHandle<DHTMessageCallback> callback = entry->getCallback();
return std::make_pair(message, callback); return std::make_pair(message, callback);
@ -103,9 +98,7 @@ DHTMessageTracker::messageArrived
} }
} }
} }
if(logger_->debug()) { A2_LOG_DEBUG("Tracker entry not found.");
logger_->debug("Tracker entry not found.");
}
return std::pair<SharedHandle<DHTResponseMessage>, return std::pair<SharedHandle<DHTResponseMessage>,
SharedHandle<DHTMessageCallback> >(); SharedHandle<DHTMessageCallback> >();
} }
@ -115,17 +108,13 @@ void DHTMessageTracker::handleTimeoutEntry
{ {
try { try {
SharedHandle<DHTNode> node = entry->getTargetNode(); SharedHandle<DHTNode> node = entry->getTargetNode();
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Message timeout: To:%s:%u",
logger_->debug("Message timeout: To:%s:%u", node->getIPAddress().c_str(), node->getPort()));
node->getIPAddress().c_str(), node->getPort());
}
node->updateRTT(entry->getElapsedMillis()); node->updateRTT(entry->getElapsedMillis());
node->timeout(); node->timeout();
if(node->isBad()) { if(node->isBad()) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Marked bad: %s:%u",
logger_->debug("Marked bad: %s:%u", node->getIPAddress().c_str(), node->getPort()));
node->getIPAddress().c_str(), node->getPort());
}
routingTable_->dropNode(node); routingTable_->dropNode(node);
} }
SharedHandle<DHTMessageCallback> callback = entry->getCallback(); SharedHandle<DHTMessageCallback> callback = entry->getCallback();
@ -133,7 +122,7 @@ void DHTMessageTracker::handleTimeoutEntry
callback->onTimeout(node); callback->onTimeout(node);
} }
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
logger_->info("Exception thrown while handling timeouts.", e); A2_LOG_INFO_EX("Exception thrown while handling timeouts.", e);
} }
} }

View File

@ -52,7 +52,6 @@ class DHTMessageCallback;
class DHTRoutingTable; class DHTRoutingTable;
class DHTMessageFactory; class DHTMessageFactory;
class DHTMessageTrackerEntry; class DHTMessageTrackerEntry;
class Logger;
class DHTMessageTracker { class DHTMessageTracker {
private: private:
@ -62,8 +61,6 @@ private:
SharedHandle<DHTMessageFactory> factory_; SharedHandle<DHTMessageFactory> factory_;
Logger* logger_;
void handleTimeoutEntry(const SharedHandle<DHTMessageTrackerEntry>& entry); void handleTimeoutEntry(const SharedHandle<DHTMessageTrackerEntry>& entry);
public: public:
DHTMessageTracker(); DHTMessageTracker();

View File

@ -39,12 +39,14 @@
#include "RecoverableException.h" #include "RecoverableException.h"
#include "message.h" #include "message.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
namespace aria2 { namespace aria2 {
DHTPeerAnnounceCommand::DHTPeerAnnounceCommand DHTPeerAnnounceCommand::DHTPeerAnnounceCommand
(cuid_t cuid, DownloadEngine* e, time_t interval): (cuid_t cuid, DownloadEngine* e, time_t interval)
TimeBasedCommand(cuid, e, interval) {} : TimeBasedCommand(cuid, e, interval)
{}
DHTPeerAnnounceCommand::~DHTPeerAnnounceCommand() {} DHTPeerAnnounceCommand::~DHTPeerAnnounceCommand() {}
@ -61,7 +63,7 @@ void DHTPeerAnnounceCommand::process()
try { try {
peerAnnounceStorage_->handleTimeout(); peerAnnounceStorage_->handleTimeout();
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
getLogger()->error(EX_EXCEPTION_CAUGHT, e); A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
} }
} }

View File

@ -48,11 +48,11 @@
#include "util.h" #include "util.h"
#include "a2functional.h" #include "a2functional.h"
#include "wallclock.h" #include "wallclock.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DHTPeerAnnounceStorage::DHTPeerAnnounceStorage(): DHTPeerAnnounceStorage::DHTPeerAnnounceStorage() {}
logger_(LogFactory::getInstance()) {}
DHTPeerAnnounceStorage::~DHTPeerAnnounceStorage() {} DHTPeerAnnounceStorage::~DHTPeerAnnounceStorage() {}
@ -89,11 +89,9 @@ void
DHTPeerAnnounceStorage::addPeerAnnounce(const unsigned char* infoHash, DHTPeerAnnounceStorage::addPeerAnnounce(const unsigned char* infoHash,
const std::string& ipaddr, uint16_t port) const std::string& ipaddr, uint16_t port)
{ {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Adding %s:%u to peer announce list: infoHash=%s",
logger_->debug("Adding %s:%u to peer announce list: infoHash=%s",
ipaddr.c_str(), port, ipaddr.c_str(), port,
util::toHex(infoHash, DHT_ID_LENGTH).c_str()); util::toHex(infoHash, DHT_ID_LENGTH).c_str()));
}
getPeerAnnounceEntry(infoHash)->addPeerAddrEntry(PeerAddrEntry(ipaddr, port)); getPeerAnnounceEntry(infoHash)->addPeerAddrEntry(PeerAddrEntry(ipaddr, port));
} }
@ -131,25 +129,19 @@ public:
void DHTPeerAnnounceStorage::handleTimeout() void DHTPeerAnnounceStorage::handleTimeout()
{ {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Now purge peer announces(%lu entries) which are timed out.",
logger_->debug("Now purge peer announces(%lu entries) which are timed out.", static_cast<unsigned long>(entries_.size())));
static_cast<unsigned long>(entries_.size()));
}
std::for_each(entries_.begin(), entries_.end(), RemoveStalePeerAddrEntry()); std::for_each(entries_.begin(), entries_.end(), RemoveStalePeerAddrEntry());
entries_.erase(std::remove_if(entries_.begin(), entries_.end(), entries_.erase(std::remove_if(entries_.begin(), entries_.end(),
mem_fun_sh(&DHTPeerAnnounceEntry::empty)), mem_fun_sh(&DHTPeerAnnounceEntry::empty)),
entries_.end()); entries_.end());
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Currently %lu peer announce entries",
logger_->debug("Currently %lu peer announce entries", static_cast<unsigned long>(entries_.size())));
static_cast<unsigned long>(entries_.size()));
}
} }
void DHTPeerAnnounceStorage::announcePeer() void DHTPeerAnnounceStorage::announcePeer()
{ {
if(logger_->debug()) { A2_LOG_DEBUG("Now announcing peer.");
logger_->debug("Now announcing peer.");
}
for(std::deque<SharedHandle<DHTPeerAnnounceEntry> >::iterator i = for(std::deque<SharedHandle<DHTPeerAnnounceEntry> >::iterator i =
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) { entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
if((*i)->getLastUpdated(). if((*i)->getLastUpdated().
@ -158,10 +150,9 @@ void DHTPeerAnnounceStorage::announcePeer()
SharedHandle<DHTTask> task = SharedHandle<DHTTask> task =
taskFactory_->createPeerAnnounceTask((*i)->getInfoHash()); taskFactory_->createPeerAnnounceTask((*i)->getInfoHash());
taskQueue_->addPeriodicTask2(task); taskQueue_->addPeriodicTask2(task);
if(logger_->debug()) { A2_LOG_DEBUG
logger_->debug("Added 1 peer announce: infoHash=%s", (fmt("Added 1 peer announce: infoHash=%s",
util::toHex((*i)->getInfoHash(), DHT_ID_LENGTH).c_str()); util::toHex((*i)->getInfoHash(), DHT_ID_LENGTH).c_str()));
}
} }
} }
} }

View File

@ -48,7 +48,6 @@ class Peer;
class DHTPeerAnnounceEntry; class DHTPeerAnnounceEntry;
class DHTTaskQueue; class DHTTaskQueue;
class DHTTaskFactory; class DHTTaskFactory;
class Logger;
class DHTPeerAnnounceStorage { class DHTPeerAnnounceStorage {
private: private:
@ -59,8 +58,6 @@ private:
SharedHandle<DHTTaskQueue> taskQueue_; SharedHandle<DHTTaskQueue> taskQueue_;
SharedHandle<DHTTaskFactory> taskFactory_; SharedHandle<DHTTaskFactory> taskFactory_;
Logger* logger_;
public: public:
DHTPeerAnnounceStorage(); DHTPeerAnnounceStorage();

View File

@ -36,6 +36,7 @@
#include "Peer.h" #include "Peer.h"
#include "DHTGetPeersReplyMessage.h" #include "DHTGetPeersReplyMessage.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "DHTMessageFactory.h" #include "DHTMessageFactory.h"
#include "DHTNode.h" #include "DHTNode.h"
#include "DHTNodeLookupEntry.h" #include "DHTNodeLookupEntry.h"
@ -48,13 +49,15 @@
#include "bittorrent_helper.h" #include "bittorrent_helper.h"
#include "DHTPeerLookupTaskCallback.h" #include "DHTPeerLookupTaskCallback.h"
#include "DHTQueryMessage.h" #include "DHTQueryMessage.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DHTPeerLookupTask::DHTPeerLookupTask DHTPeerLookupTask::DHTPeerLookupTask
(const SharedHandle<DownloadContext>& downloadContext): (const SharedHandle<DownloadContext>& downloadContext)
DHTAbstractNodeLookupTask<DHTGetPeersReplyMessage> : DHTAbstractNodeLookupTask<DHTGetPeersReplyMessage>
(bittorrent::getInfoHash(downloadContext)) {} (bittorrent::getInfoHash(downloadContext))
{}
void void
DHTPeerLookupTask::getNodesFromMessage DHTPeerLookupTask::getNodesFromMessage
@ -75,8 +78,8 @@ void DHTPeerLookupTask::onReceivedInternal
peerStorage_->addPeer(message->getValues()); peerStorage_->addPeer(message->getValues());
peers_.insert(peers_.end(), peers_.insert(peers_.end(),
message->getValues().begin(), message->getValues().end()); message->getValues().begin(), message->getValues().end());
getLogger()->info("Received %lu peers.", A2_LOG_INFO(fmt("Received %lu peers.",
static_cast<unsigned long>(message->getValues().size())); static_cast<unsigned long>(message->getValues().size())));
} }
SharedHandle<DHTMessage> DHTPeerLookupTask::createMessage SharedHandle<DHTMessage> DHTPeerLookupTask::createMessage
@ -93,10 +96,8 @@ SharedHandle<DHTMessageCallback> DHTPeerLookupTask::createCallback()
void DHTPeerLookupTask::onFinish() void DHTPeerLookupTask::onFinish()
{ {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("Peer lookup for %s finished",
getLogger()->debug("Peer lookup for %s finished", util::toHex(getTargetID(), DHT_ID_LENGTH).c_str()));
util::toHex(getTargetID(), DHT_ID_LENGTH).c_str());
}
// send announce_peer message to K closest nodes // send announce_peer message to K closest nodes
size_t num = DHTBucket::K; size_t num = DHTBucket::K;
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::const_iterator i = for(std::deque<SharedHandle<DHTNodeLookupEntry> >::const_iterator i =

View File

@ -39,17 +39,19 @@
#include "DHTMessageFactory.h" #include "DHTMessageFactory.h"
#include "DHTMessageDispatcher.h" #include "DHTMessageDispatcher.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "DHTPingReplyMessageCallback.h" #include "DHTPingReplyMessageCallback.h"
#include "DHTQueryMessage.h" #include "DHTQueryMessage.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DHTReplaceNodeTask::DHTReplaceNodeTask(const SharedHandle<DHTBucket>& bucket, DHTReplaceNodeTask::DHTReplaceNodeTask
const SharedHandle<DHTNode>& newNode): (const SharedHandle<DHTBucket>& bucket, const SharedHandle<DHTNode>& newNode)
bucket_(bucket), : bucket_(bucket),
newNode_(newNode), newNode_(newNode),
numRetry_(0), numRetry_(0),
timeout_(DHT_MESSAGE_TIMEOUT) timeout_(DHT_MESSAGE_TIMEOUT)
{} {}
DHTReplaceNodeTask::~DHTReplaceNodeTask() {} DHTReplaceNodeTask::~DHTReplaceNodeTask() {}
@ -75,8 +77,8 @@ void DHTReplaceNodeTask::sendMessage()
void DHTReplaceNodeTask::onReceived(const DHTPingReplyMessage* message) void DHTReplaceNodeTask::onReceived(const DHTPingReplyMessage* message)
{ {
getLogger()->info("ReplaceNode: Ping reply received from %s.", A2_LOG_INFO(fmt("ReplaceNode: Ping reply received from %s.",
message->getRemoteNode()->toString().c_str()); message->getRemoteNode()->toString().c_str()));
setFinished(true); setFinished(true);
} }
@ -84,16 +86,16 @@ void DHTReplaceNodeTask::onTimeout(const SharedHandle<DHTNode>& node)
{ {
++numRetry_; ++numRetry_;
if(numRetry_ >= MAX_RETRY) { if(numRetry_ >= MAX_RETRY) {
getLogger()->info("ReplaceNode: Ping failed %lu times. Replace %s with %s.", A2_LOG_INFO(fmt("ReplaceNode: Ping failed %lu times. Replace %s with %s.",
static_cast<unsigned long>(numRetry_), static_cast<unsigned long>(numRetry_),
node->toString().c_str(), node->toString().c_str(),
newNode_->toString().c_str()); newNode_->toString().c_str()));
node->markBad(); node->markBad();
bucket_->addNode(newNode_); bucket_->addNode(newNode_);
setFinished(true); setFinished(true);
} else { } else {
getLogger()->info("ReplaceNode: Ping reply timeout from %s. Try once more.", A2_LOG_INFO(fmt("ReplaceNode: Ping reply timeout from %s. Try once more.",
node->toString().c_str()); node->toString().c_str()));
sendMessage(); sendMessage();
} }
} }

View File

@ -45,6 +45,7 @@
#include "util.h" #include "util.h"
#include "LogFactory.h" #include "LogFactory.h"
#include "Logger.h" #include "Logger.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
@ -52,8 +53,7 @@ DHTRoutingTable::DHTRoutingTable(const SharedHandle<DHTNode>& localNode)
: localNode_(localNode), : localNode_(localNode),
root_(new DHTBucketTreeNode root_(new DHTBucketTreeNode
(SharedHandle<DHTBucket>(new DHTBucket(localNode_)))), (SharedHandle<DHTBucket>(new DHTBucket(localNode_)))),
numBucket_(1), numBucket_(1)
logger_(LogFactory::getInstance())
{} {}
DHTRoutingTable::~DHTRoutingTable() DHTRoutingTable::~DHTRoutingTable()
@ -73,30 +73,21 @@ bool DHTRoutingTable::addGoodNode(const SharedHandle<DHTNode>& node)
bool DHTRoutingTable::addNode(const SharedHandle<DHTNode>& node, bool good) bool DHTRoutingTable::addNode(const SharedHandle<DHTNode>& node, bool good)
{ {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Trying to add node:%s", node->toString().c_str()));
logger_->debug("Trying to add node:%s", node->toString().c_str());
}
if(*localNode_ == *node) { if(*localNode_ == *node) {
if(logger_->debug()) { A2_LOG_DEBUG("Adding node with the same ID with localnode is not allowed.");
logger_->debug("Adding node with the same ID with localnode is not"
" allowed.");
}
return false; return false;
} }
DHTBucketTreeNode* treeNode = dht::findTreeNodeFor(root_, node->getID()); DHTBucketTreeNode* treeNode = dht::findTreeNodeFor(root_, node->getID());
while(1) { while(1) {
const SharedHandle<DHTBucket>& bucket = treeNode->getBucket(); const SharedHandle<DHTBucket>& bucket = treeNode->getBucket();
if(bucket->addNode(node)) { if(bucket->addNode(node)) {
if(logger_->debug()) { A2_LOG_DEBUG("Added DHTNode.");
logger_->debug("Added DHTNode.");
}
return true; return true;
} else if(bucket->splitAllowed()) { } else if(bucket->splitAllowed()) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Splitting bucket. Range:%s-%s",
logger_->debug("Splitting bucket. Range:%s-%s",
util::toHex(bucket->getMinID(), DHT_ID_LENGTH).c_str(), util::toHex(bucket->getMinID(), DHT_ID_LENGTH).c_str(),
util::toHex(bucket->getMaxID(), DHT_ID_LENGTH).c_str()); util::toHex(bucket->getMaxID(), DHT_ID_LENGTH).c_str()));
}
treeNode->split(); treeNode->split();
++numBucket_; ++numBucket_;
if(treeNode->getLeft()->isInRange(node->getID())) { if(treeNode->getLeft()->isInRange(node->getID())) {
@ -107,9 +98,7 @@ bool DHTRoutingTable::addNode(const SharedHandle<DHTNode>& node, bool good)
} else { } else {
if(good) { if(good) {
bucket->cacheNode(node); bucket->cacheNode(node);
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Cached node=%s", node->toString().c_str()));
logger_->debug("Cached node=%s", node->toString().c_str());
}
} }
return false; return false;
} }

View File

@ -49,7 +49,6 @@ class DHTBucket;
class DHTTaskQueue; class DHTTaskQueue;
class DHTTaskFactory; class DHTTaskFactory;
class DHTBucketTreeNode; class DHTBucketTreeNode;
class Logger;
class DHTRoutingTable { class DHTRoutingTable {
private: private:
@ -63,8 +62,6 @@ private:
SharedHandle<DHTTaskFactory> taskFactory_; SharedHandle<DHTTaskFactory> taskFactory_;
Logger* logger_;
bool addNode(const SharedHandle<DHTNode>& node, bool good); bool addNode(const SharedHandle<DHTNode>& node, bool good);
public: public:
DHTRoutingTable(const SharedHandle<DHTNode>& localNode); DHTRoutingTable(const SharedHandle<DHTNode>& localNode);

View File

@ -69,10 +69,11 @@
#include "RecoverableException.h" #include "RecoverableException.h"
#include "a2functional.h" #include "a2functional.h"
#include "DownloadEngine.h" #include "DownloadEngine.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DHTSetup::DHTSetup():logger_(LogFactory::getInstance()) {} DHTSetup::DHTSetup() {}
DHTSetup::~DHTSetup() {} DHTSetup::~DHTSetup() {}
@ -105,8 +106,10 @@ void DHTSetup::setup
deserializer.deserialize(in); deserializer.deserialize(in);
localNode = deserializer.getLocalNode(); localNode = deserializer.getLocalNode();
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
logger_->error("Exception caught while loading DHT routing table from %s", A2_LOG_ERROR_EX
e, dhtFile.c_str()); (fmt("Exception caught while loading DHT routing table from %s",
dhtFile.c_str()),
e);
} }
if(!localNode) { if(!localNode) {
localNode.reset(new DHTNode()); localNode.reset(new DHTNode());
@ -125,10 +128,8 @@ void DHTSetup::setup
} }
localNode->setPort(port); localNode->setPort(port);
} }
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Initialized local node ID=%s",
logger_->debug("Initialized local node ID=%s", util::toHex(localNode->getID(), DHT_ID_LENGTH).c_str()));
util::toHex(localNode->getID(), DHT_ID_LENGTH).c_str());
}
SharedHandle<DHTRoutingTable> routingTable(new DHTRoutingTable(localNode)); SharedHandle<DHTRoutingTable> routingTable(new DHTRoutingTable(localNode));
SharedHandle<DHTMessageFactoryImpl> factory SharedHandle<DHTMessageFactoryImpl> factory
@ -240,7 +241,7 @@ void DHTSetup::setup
tempCommands->push_back(command); tempCommands->push_back(command);
} }
} else { } else {
logger_->info("No DHT entry point specified."); A2_LOG_INFO("No DHT entry point specified.");
} }
{ {
DHTInteractionCommand* command = DHTInteractionCommand* command =
@ -288,8 +289,9 @@ void DHTSetup::setup
commands.insert(commands.end(), tempCommands->begin(), tempCommands->end()); commands.insert(commands.end(), tempCommands->begin(), tempCommands->end());
tempCommands->clear(); tempCommands->clear();
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
logger_->error("Exception caught while initializing DHT functionality." A2_LOG_ERROR_EX(fmt("Exception caught while initializing DHT functionality."
" DHT is disabled.", e); " DHT is disabled."),
e);
if(family == AF_INET) { if(family == AF_INET) {
DHTRegistry::clearData(); DHTRegistry::clearData();
} else { } else {

View File

@ -39,13 +39,11 @@
#include <vector> #include <vector>
namespace aria2 { namespace aria2 {
class Logger;
class DownloadEngine; class DownloadEngine;
class Command; class Command;
class DHTSetup { class DHTSetup {
private:
Logger* logger_;
public: public:
DHTSetup(); DHTSetup();

View File

@ -40,12 +40,13 @@
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h" #include "LogFactory.h"
#include "a2functional.h" #include "a2functional.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DHTTaskExecutor::DHTTaskExecutor(size_t numConcurrent): DHTTaskExecutor::DHTTaskExecutor(size_t numConcurrent)
numConcurrent_(numConcurrent), : numConcurrent_(numConcurrent)
logger_(LogFactory::getInstance()) {} {}
DHTTaskExecutor::~DHTTaskExecutor() {} DHTTaskExecutor::~DHTTaskExecutor() {}
@ -64,11 +65,9 @@ void DHTTaskExecutor::update()
--r; --r;
} }
} }
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Executing %u Task(s). Queue has %u task(s).",
logger_->debug("Executing %u Task(s). Queue has %u task(s).",
static_cast<unsigned int>(getExecutingTaskSize()), static_cast<unsigned int>(getExecutingTaskSize()),
static_cast<unsigned int>(getQueueSize())); static_cast<unsigned int>(getQueueSize())));
}
} }
} // namespace aria2 } // namespace aria2

View File

@ -45,14 +45,12 @@
namespace aria2 { namespace aria2 {
class DHTTask; class DHTTask;
class Logger;
class DHTTaskExecutor { class DHTTaskExecutor {
private: private:
size_t numConcurrent_; size_t numConcurrent_;
std::vector<SharedHandle<DHTTask> > execTasks_; std::vector<SharedHandle<DHTTask> > execTasks_;
std::deque<SharedHandle<DHTTask> > queue_; std::deque<SharedHandle<DHTTask> > queue_;
Logger* logger_;
public: public:
DHTTaskExecutor(size_t numConcurrent); DHTTaskExecutor(size_t numConcurrent);

View File

@ -38,8 +38,6 @@
#include "DHTMessageDispatcher.h" #include "DHTMessageDispatcher.h"
#include "DHTMessageFactory.h" #include "DHTMessageFactory.h"
#include "DHTTaskQueue.h" #include "DHTTaskQueue.h"
#include "LogFactory.h"
#include "Logger.h"
#include "DHTPingTask.h" #include "DHTPingTask.h"
#include "DHTNodeLookupTask.h" #include "DHTNodeLookupTask.h"
#include "DHTBucketRefreshTask.h" #include "DHTBucketRefreshTask.h"
@ -53,13 +51,13 @@
namespace aria2 { namespace aria2 {
DHTTaskFactoryImpl::DHTTaskFactoryImpl(): DHTTaskFactoryImpl::DHTTaskFactoryImpl()
routingTable_(0), : routingTable_(0),
dispatcher_(0), dispatcher_(0),
factory_(0), factory_(0),
taskQueue_(0), taskQueue_(0),
timeout_(DHT_MESSAGE_TIMEOUT), timeout_(DHT_MESSAGE_TIMEOUT)
logger_(LogFactory::getInstance()) {} {}
DHTTaskFactoryImpl::~DHTTaskFactoryImpl() {} DHTTaskFactoryImpl::~DHTTaskFactoryImpl() {}

View File

@ -46,7 +46,6 @@ class DHTMessageDispatcher;
class DHTMessageFactory; class DHTMessageFactory;
class DHTTaskQueue; class DHTTaskQueue;
class DHTAbstractTask; class DHTAbstractTask;
class Logger;
class DHTTaskFactoryImpl:public DHTTaskFactory { class DHTTaskFactoryImpl:public DHTTaskFactory {
private: private:
@ -62,8 +61,6 @@ private:
time_t timeout_; time_t timeout_;
Logger* logger_;
void setCommonProperty(const SharedHandle<DHTAbstractTask>& task); void setCommonProperty(const SharedHandle<DHTAbstractTask>& task);
public: public:
DHTTaskFactoryImpl(); DHTTaskFactoryImpl();

View File

@ -43,27 +43,21 @@ namespace {
const size_t NUM_CONCURRENT_TASK = 5; const size_t NUM_CONCURRENT_TASK = 5;
} // namespace } // namespace
DHTTaskQueueImpl::DHTTaskQueueImpl(): DHTTaskQueueImpl::DHTTaskQueueImpl()
periodicTaskQueue1_(NUM_CONCURRENT_TASK), : periodicTaskQueue1_(NUM_CONCURRENT_TASK),
periodicTaskQueue2_(NUM_CONCURRENT_TASK), periodicTaskQueue2_(NUM_CONCURRENT_TASK),
immediateTaskQueue_(NUM_CONCURRENT_TASK), immediateTaskQueue_(NUM_CONCURRENT_TASK)
logger_(LogFactory::getInstance()) {} {}
DHTTaskQueueImpl::~DHTTaskQueueImpl() {} DHTTaskQueueImpl::~DHTTaskQueueImpl() {}
void DHTTaskQueueImpl::executeTask() void DHTTaskQueueImpl::executeTask()
{ {
if(logger_->debug()) { A2_LOG_DEBUG("Updating periodicTaskQueue1");
logger_->debug("Updating periodicTaskQueue1");
}
periodicTaskQueue1_.update(); periodicTaskQueue1_.update();
if(logger_->debug()) { A2_LOG_DEBUG("Updating periodicTaskQueue2");
logger_->debug("Updating periodicTaskQueue2");
}
periodicTaskQueue2_.update(); periodicTaskQueue2_.update();
if(logger_->debug()) { A2_LOG_DEBUG("Updating immediateTaskQueue");
logger_->debug("Updating immediateTaskQueue");
}
immediateTaskQueue_.update(); immediateTaskQueue_.update();
} }

View File

@ -40,8 +40,6 @@
namespace aria2 { namespace aria2 {
class Logger;
class DHTTaskQueueImpl:public DHTTaskQueue { class DHTTaskQueueImpl:public DHTTaskQueue {
private: private:
DHTTaskExecutor periodicTaskQueue1_; DHTTaskExecutor periodicTaskQueue1_;
@ -49,8 +47,6 @@ private:
DHTTaskExecutor periodicTaskQueue2_; DHTTaskExecutor periodicTaskQueue2_;
DHTTaskExecutor immediateTaskQueue_; DHTTaskExecutor immediateTaskQueue_;
Logger* logger_;
public: public:
DHTTaskQueueImpl(); DHTTaskQueueImpl();

View File

@ -39,13 +39,14 @@
#include "RecoverableException.h" #include "RecoverableException.h"
#include "message.h" #include "message.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
namespace aria2 { namespace aria2 {
DHTTokenUpdateCommand::DHTTokenUpdateCommand(cuid_t cuid, DHTTokenUpdateCommand::DHTTokenUpdateCommand
DownloadEngine* e, (cuid_t cuid, DownloadEngine* e, time_t interval)
time_t interval): : TimeBasedCommand(cuid, e, interval)
TimeBasedCommand(cuid, e, interval) {} {}
DHTTokenUpdateCommand::~DHTTokenUpdateCommand() {} DHTTokenUpdateCommand::~DHTTokenUpdateCommand() {}
@ -62,7 +63,7 @@ void DHTTokenUpdateCommand::process()
try { try {
tokenTracker_->updateTokenSecret(); tokenTracker_->updateTokenSecret();
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
getLogger()->error(EX_EXCEPTION_CAUGHT, e); A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
} }
} }

View File

@ -47,6 +47,7 @@
#include "Peer.h" #include "Peer.h"
#include "Option.h" #include "Option.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
#include "A2STR.h" #include "A2STR.h"
#include "bencode2.h" #include "bencode2.h"
#include "bittorrent_helper.h" #include "bittorrent_helper.h"
@ -57,19 +58,18 @@ namespace aria2 {
DefaultBtAnnounce::DefaultBtAnnounce DefaultBtAnnounce::DefaultBtAnnounce
(const SharedHandle<DownloadContext>& downloadContext, (const SharedHandle<DownloadContext>& downloadContext,
const Option* option): const Option* option)
downloadContext_(downloadContext), : downloadContext_(downloadContext),
trackers_(0), trackers_(0),
prevAnnounceTimer_(0), prevAnnounceTimer_(0),
interval_(DEFAULT_ANNOUNCE_INTERVAL), interval_(DEFAULT_ANNOUNCE_INTERVAL),
minInterval_(DEFAULT_ANNOUNCE_INTERVAL), minInterval_(DEFAULT_ANNOUNCE_INTERVAL),
userDefinedInterval_(0), userDefinedInterval_(0),
complete_(0), complete_(0),
incomplete_(0), incomplete_(0),
announceList_(bittorrent::getTorrentAttrs(downloadContext)->announceList), announceList_(bittorrent::getTorrentAttrs(downloadContext)->announceList),
option_(option), option_(option),
logger_(LogFactory::getInstance()), randomizer_(SimpleRandomizer::getInstance())
randomizer_(SimpleRandomizer::getInstance())
{} {}
DefaultBtAnnounce::~DefaultBtAnnounce() { DefaultBtAnnounce::~DefaultBtAnnounce() {
@ -218,9 +218,7 @@ void
DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse, DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
size_t trackerResponseLength) size_t trackerResponseLength)
{ {
if(logger_->debug()) { A2_LOG_DEBUG("Now processing tracker response.");
logger_->debug("Now processing tracker response.");
}
SharedHandle<ValueBase> decodedValue = SharedHandle<ValueBase> decodedValue =
bencode2::decode(trackerResponse, trackerResponseLength); bencode2::decode(trackerResponse, trackerResponseLength);
const Dict* dict = asDict(decodedValue); const Dict* dict = asDict(decodedValue);
@ -234,28 +232,22 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
} }
const String* warn = asString(dict->get(BtAnnounce::WARNING_MESSAGE)); const String* warn = asString(dict->get(BtAnnounce::WARNING_MESSAGE));
if(warn) { if(warn) {
logger_->warn(MSG_TRACKER_WARNING_MESSAGE, warn->s().c_str()); A2_LOG_WARN(fmt(MSG_TRACKER_WARNING_MESSAGE, warn->s().c_str()));
} }
const String* tid = asString(dict->get(BtAnnounce::TRACKER_ID)); const String* tid = asString(dict->get(BtAnnounce::TRACKER_ID));
if(tid) { if(tid) {
trackerId_ = tid->s(); trackerId_ = tid->s();
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Tracker ID:%s", trackerId_.c_str()));
logger_->debug("Tracker ID:%s", trackerId_.c_str());
}
} }
const Integer* ival = asInteger(dict->get(BtAnnounce::INTERVAL)); const Integer* ival = asInteger(dict->get(BtAnnounce::INTERVAL));
if(ival && ival->i() > 0) { if(ival && ival->i() > 0) {
interval_ = ival->i(); interval_ = ival->i();
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Interval:%ld", static_cast<long int>(interval_)));
logger_->debug("Interval:%ld", static_cast<long int>(interval_));
}
} }
const Integer* mival = asInteger(dict->get(BtAnnounce::MIN_INTERVAL)); const Integer* mival = asInteger(dict->get(BtAnnounce::MIN_INTERVAL));
if(mival && mival->i() > 0) { if(mival && mival->i() > 0) {
minInterval_ = mival->i(); minInterval_ = mival->i();
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Min interval:%ld", static_cast<long int>(minInterval_)));
logger_->debug("Min interval:%ld", static_cast<long int>(minInterval_));
}
minInterval_ = std::min(minInterval_, interval_); minInterval_ = std::min(minInterval_, interval_);
} else { } else {
// Use interval as a minInterval if minInterval is not supplied. // Use interval as a minInterval if minInterval is not supplied.
@ -264,20 +256,16 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
const Integer* comp = asInteger(dict->get(BtAnnounce::COMPLETE)); const Integer* comp = asInteger(dict->get(BtAnnounce::COMPLETE));
if(comp) { if(comp) {
complete_ = comp->i(); complete_ = comp->i();
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Complete:%d", complete_));
logger_->debug("Complete:%d", complete_);
}
} }
const Integer* incomp = asInteger(dict->get(BtAnnounce::INCOMPLETE)); const Integer* incomp = asInteger(dict->get(BtAnnounce::INCOMPLETE));
if(incomp) { if(incomp) {
incomplete_ = incomp->i(); incomplete_ = incomp->i();
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Incomplete:%d", incomplete_));
logger_->debug("Incomplete:%d", incomplete_);
}
} }
const SharedHandle<ValueBase>& peerData = dict->get(BtAnnounce::PEERS); const SharedHandle<ValueBase>& peerData = dict->get(BtAnnounce::PEERS);
if(!peerData) { if(!peerData) {
logger_->info(MSG_NO_PEER_LIST_RECEIVED); A2_LOG_INFO(MSG_NO_PEER_LIST_RECEIVED);
} else { } else {
if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) { if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) {
std::vector<SharedHandle<Peer> > peers; std::vector<SharedHandle<Peer> > peers;
@ -287,7 +275,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
} }
const SharedHandle<ValueBase>& peer6Data = dict->get(BtAnnounce::PEERS6); const SharedHandle<ValueBase>& peer6Data = dict->get(BtAnnounce::PEERS6);
if(!peer6Data) { if(!peer6Data) {
logger_->info("No peers6 received."); A2_LOG_INFO("No peers6 received.");
} else { } else {
if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) { if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) {
std::vector<SharedHandle<Peer> > peers; std::vector<SharedHandle<Peer> > peers;

View File

@ -43,7 +43,6 @@ namespace aria2 {
class DownloadContext; class DownloadContext;
class Option; class Option;
class Logger;
class BtRuntime; class BtRuntime;
class PieceStorage; class PieceStorage;
class PeerStorage; class PeerStorage;
@ -62,7 +61,6 @@ private:
AnnounceList announceList_; AnnounceList announceList_;
std::string trackerId_; std::string trackerId_;
const Option* option_; const Option* option_;
Logger* logger_;
SharedHandle<Randomizer> randomizer_; SharedHandle<Randomizer> randomizer_;
SharedHandle<BtRuntime> btRuntime_; SharedHandle<BtRuntime> btRuntime_;
SharedHandle<PieceStorage> pieceStorage_; SharedHandle<PieceStorage> pieceStorage_;

View File

@ -67,6 +67,7 @@
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h" #include "LogFactory.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
#include "RequestGroup.h" #include "RequestGroup.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "bittorrent_helper.h" #include "bittorrent_helper.h"
@ -79,25 +80,23 @@ namespace aria2 {
DefaultBtInteractive::DefaultBtInteractive DefaultBtInteractive::DefaultBtInteractive
(const SharedHandle<DownloadContext>& downloadContext, (const SharedHandle<DownloadContext>& downloadContext,
const SharedHandle<Peer>& peer) const SharedHandle<Peer>& peer)
: : downloadContext_(downloadContext),
downloadContext_(downloadContext), peer_(peer),
peer_(peer), metadataGetMode_(false),
metadataGetMode_(false), localNode_(0),
localNode_(0), allowedFastSetSize_(10),
logger_(LogFactory::getInstance()), haveTimer_(global::wallclock),
allowedFastSetSize_(10), keepAliveTimer_(global::wallclock),
haveTimer_(global::wallclock), floodingTimer_(global::wallclock),
keepAliveTimer_(global::wallclock), inactiveTimer_(global::wallclock),
floodingTimer_(global::wallclock), pexTimer_(global::wallclock),
inactiveTimer_(global::wallclock), perSecTimer_(global::wallclock),
pexTimer_(global::wallclock), keepAliveInterval_(120),
perSecTimer_(global::wallclock), utPexEnabled_(false),
keepAliveInterval_(120), dhtEnabled_(false),
utPexEnabled_(false), numReceivedMessage_(0),
dhtEnabled_(false), maxOutstandingRequest_(DEFAULT_MAX_OUTSTANDING_REQUEST),
numReceivedMessage_(0), requestGroupMan_(0)
maxOutstandingRequest_(DEFAULT_MAX_OUTSTANDING_REQUEST),
requestGroupMan_(0)
{} {}
DefaultBtInteractive::~DefaultBtInteractive() {} DefaultBtInteractive::~DefaultBtInteractive() {}
@ -139,30 +138,22 @@ BtMessageHandle DefaultBtInteractive::receiveHandshake(bool quickReply) {
if(message->isFastExtensionSupported()) { if(message->isFastExtensionSupported()) {
peer_->setFastExtensionEnabled(true); peer_->setFastExtensionEnabled(true);
if(logger_->info()) { A2_LOG_INFO(fmt(MSG_FAST_EXTENSION_ENABLED, util::itos(cuid_).c_str()));
logger_->info(MSG_FAST_EXTENSION_ENABLED, util::itos(cuid_).c_str());
}
} }
if(message->isExtendedMessagingEnabled()) { if(message->isExtendedMessagingEnabled()) {
peer_->setExtendedMessagingEnabled(true); peer_->setExtendedMessagingEnabled(true);
if(!utPexEnabled_) { if(!utPexEnabled_) {
extensionMessageRegistry_->removeExtension("ut_pex"); extensionMessageRegistry_->removeExtension("ut_pex");
} }
if(logger_->info()) { A2_LOG_INFO(fmt(MSG_EXTENDED_MESSAGING_ENABLED, util::itos(cuid_).c_str()));
logger_->info(MSG_EXTENDED_MESSAGING_ENABLED, util::itos(cuid_).c_str());
}
} }
if(message->isDHTEnabled()) { if(message->isDHTEnabled()) {
peer_->setDHTEnabled(true); peer_->setDHTEnabled(true);
if(logger_->info()) { A2_LOG_INFO(fmt(MSG_DHT_ENABLED_PEER, util::itos(cuid_).c_str()));
logger_->info(MSG_DHT_ENABLED_PEER, util::itos(cuid_).c_str());
}
}
if(logger_->info()) {
logger_->info(MSG_RECEIVE_PEER_MESSAGE, util::itos(cuid_).c_str(),
peer_->getIPAddress().c_str(), peer_->getPort(),
message->toString().c_str());
} }
A2_LOG_INFO(fmt(MSG_RECEIVE_PEER_MESSAGE, util::itos(cuid_).c_str(),
peer_->getIPAddress().c_str(), peer_->getPort(),
message->toString().c_str()));
return message; return message;
} }
@ -296,11 +287,10 @@ size_t DefaultBtInteractive::receiveMessages() {
break; break;
} }
++msgcount; ++msgcount;
if(logger_->info()) { A2_LOG_INFO(fmt(MSG_RECEIVE_PEER_MESSAGE,
logger_->info(MSG_RECEIVE_PEER_MESSAGE, util::itos(cuid_).c_str(), util::itos(cuid_).c_str(),
peer_->getIPAddress().c_str(), peer_->getPort(), peer_->getIPAddress().c_str(), peer_->getPort(),
message->toString().c_str()); message->toString().c_str()));
}
message->doReceivedAction(); message->doReceivedAction();
switch(message->getId()) { switch(message->getId()) {
@ -338,17 +328,13 @@ size_t DefaultBtInteractive::receiveMessages() {
void DefaultBtInteractive::decideInterest() { void DefaultBtInteractive::decideInterest() {
if(pieceStorage_->hasMissingPiece(peer_)) { if(pieceStorage_->hasMissingPiece(peer_)) {
if(!peer_->amInterested()) { if(!peer_->amInterested()) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt(MSG_PEER_INTERESTED, util::itos(cuid_).c_str()));
logger_->debug(MSG_PEER_INTERESTED, util::itos(cuid_).c_str());
}
dispatcher_-> dispatcher_->
addMessageToQueue(messageFactory_->createInterestedMessage()); addMessageToQueue(messageFactory_->createInterestedMessage());
} }
} else { } else {
if(peer_->amInterested()) { if(peer_->amInterested()) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt(MSG_PEER_NOT_INTERESTED, util::itos(cuid_).c_str()));
logger_->debug(MSG_PEER_NOT_INTERESTED, util::itos(cuid_).c_str());
}
dispatcher_-> dispatcher_->
addMessageToQueue(messageFactory_->createNotInterestedMessage()); addMessageToQueue(messageFactory_->createNotInterestedMessage());
} }
@ -425,10 +411,8 @@ void DefaultBtInteractive::cancelAllPiece() {
utMetadataRequestTracker_->getAllTrackedIndex(); utMetadataRequestTracker_->getAllTrackedIndex();
for(std::vector<size_t>::const_iterator i = metadataRequests.begin(), for(std::vector<size_t>::const_iterator i = metadataRequests.begin(),
eoi = metadataRequests.end(); i != eoi; ++i) { eoi = metadataRequests.end(); i != eoi; ++i) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Cancel metadata: piece=%lu",
logger_->debug("Cancel metadata: piece=%lu", static_cast<unsigned long>(*i)));
static_cast<unsigned long>(*i));
}
pieceStorage_->cancelPiece(pieceStorage_->getPiece(*i)); pieceStorage_->cancelPiece(pieceStorage_->getPiece(*i));
} }
} }

View File

@ -58,7 +58,6 @@ class PeerConnection;
class ExtensionMessageFactory; class ExtensionMessageFactory;
class ExtensionMessageRegistry; class ExtensionMessageRegistry;
class DHTNode; class DHTNode;
class Logger;
class RequestGroupMan; class RequestGroupMan;
class UTMetadataRequestFactory; class UTMetadataRequestFactory;
class UTMetadataRequestTracker; class UTMetadataRequestTracker;
@ -126,7 +125,6 @@ private:
DHTNode* localNode_; DHTNode* localNode_;
Logger* logger_;
size_t allowedFastSetSize_; size_t allowedFastSetSize_;
Timer haveTimer_; Timer haveTimer_;
Timer keepAliveTimer_; Timer keepAliveTimer_;

View File

@ -55,21 +55,20 @@
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "RequestGroup.h" #include "RequestGroup.h"
#include "util.h" #include "util.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DefaultBtMessageDispatcher::DefaultBtMessageDispatcher(): DefaultBtMessageDispatcher::DefaultBtMessageDispatcher()
cuid(0), : cuid(0),
messageFactory_(0), messageFactory_(0),
requestGroupMan_(0), requestGroupMan_(0),
requestTimeout_(0), requestTimeout_(0)
logger_(LogFactory::getInstance()) {} {}
DefaultBtMessageDispatcher::~DefaultBtMessageDispatcher() DefaultBtMessageDispatcher::~DefaultBtMessageDispatcher()
{ {
if(logger_->debug()) { A2_LOG_DEBUG("DefaultBtMessageDispatcher::deleted");
logger_->debug("DefaultBtMessageDispatcher::deleted");
}
} }
void DefaultBtMessageDispatcher::addMessageToQueue void DefaultBtMessageDispatcher::addMessageToQueue
@ -147,22 +146,19 @@ class AbortOutstandingRequest {
private: private:
SharedHandle<Piece> piece_; SharedHandle<Piece> piece_;
cuid_t cuid_; cuid_t cuid_;
Logger* logger_;
public: public:
AbortOutstandingRequest(const SharedHandle<Piece>& piece, cuid_t cuid): AbortOutstandingRequest(const SharedHandle<Piece>& piece, cuid_t cuid)
piece_(piece), : piece_(piece),
cuid_(cuid), cuid_(cuid)
logger_(LogFactory::getInstance()) {} {}
void operator()(const RequestSlot& slot) const void operator()(const RequestSlot& slot) const
{ {
if(logger_->debug()) { A2_LOG_DEBUG(fmt(MSG_DELETING_REQUEST_SLOT,
logger_->debug(MSG_DELETING_REQUEST_SLOT,
util::itos(cuid_).c_str(), util::itos(cuid_).c_str(),
static_cast<unsigned long>(slot.getIndex()), static_cast<unsigned long>(slot.getIndex()),
slot.getBegin(), slot.getBegin(),
static_cast<unsigned long>(slot.getBlockIndex())); static_cast<unsigned long>(slot.getBlockIndex())));
}
piece_->cancelBlock(slot.getBlockIndex()); piece_->cancelBlock(slot.getBlockIndex());
} }
}; };
@ -196,26 +192,24 @@ private:
cuid_t cuid_; cuid_t cuid_;
SharedHandle<Peer> peer_; SharedHandle<Peer> peer_;
SharedHandle<PieceStorage> pieceStorage_; SharedHandle<PieceStorage> pieceStorage_;
Logger* logger_;
public: public:
ProcessChokedRequestSlot(cuid_t cuid, ProcessChokedRequestSlot
const SharedHandle<Peer>& peer, (cuid_t cuid,
const SharedHandle<PieceStorage>& pieceStorage): const SharedHandle<Peer>& peer,
cuid_(cuid), const SharedHandle<PieceStorage>& pieceStorage)
peer_(peer), : cuid_(cuid),
pieceStorage_(pieceStorage), peer_(peer),
logger_(LogFactory::getInstance()) {} pieceStorage_(pieceStorage)
{}
void operator()(const RequestSlot& slot) const void operator()(const RequestSlot& slot) const
{ {
if(!peer_->isInPeerAllowedIndexSet(slot.getIndex())) { if(!peer_->isInPeerAllowedIndexSet(slot.getIndex())) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt(MSG_DELETING_REQUEST_SLOT_CHOKED,
logger_->debug(MSG_DELETING_REQUEST_SLOT_CHOKED,
util::itos(cuid_).c_str(), util::itos(cuid_).c_str(),
static_cast<unsigned long>(slot.getIndex()), static_cast<unsigned long>(slot.getIndex()),
slot.getBegin(), slot.getBegin(),
static_cast<unsigned long>(slot.getBlockIndex())); static_cast<unsigned long>(slot.getBlockIndex())));
}
SharedHandle<Piece> piece = pieceStorage_->getPiece(slot.getIndex()); SharedHandle<Piece> piece = pieceStorage_->getPiece(slot.getIndex());
piece->cancelBlock(slot.getBlockIndex()); piece->cancelBlock(slot.getBlockIndex());
} }
@ -270,41 +264,37 @@ private:
BtMessageDispatcher* messageDispatcher_; BtMessageDispatcher* messageDispatcher_;
BtMessageFactory* messageFactory_; BtMessageFactory* messageFactory_;
time_t requestTimeout_; time_t requestTimeout_;
Logger* logger_;
public: public:
ProcessStaleRequestSlot(cuid_t cuid, const SharedHandle<Peer>& peer, ProcessStaleRequestSlot
const SharedHandle<PieceStorage>& pieceStorage, (cuid_t cuid, const SharedHandle<Peer>& peer,
BtMessageDispatcher* dispatcher, const SharedHandle<PieceStorage>& pieceStorage,
BtMessageFactory* factory, BtMessageDispatcher* dispatcher,
time_t requestTimeout): BtMessageFactory* factory,
cuid_(cuid), time_t requestTimeout)
peer_(peer), : cuid_(cuid),
pieceStorage_(pieceStorage), peer_(peer),
messageDispatcher_(dispatcher), pieceStorage_(pieceStorage),
messageFactory_(factory), messageDispatcher_(dispatcher),
requestTimeout_(requestTimeout), messageFactory_(factory),
logger_(LogFactory::getInstance()) {} requestTimeout_(requestTimeout)
{}
void operator()(const RequestSlot& slot) void operator()(const RequestSlot& slot)
{ {
if(slot.isTimeout(requestTimeout_)) { if(slot.isTimeout(requestTimeout_)) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt(MSG_DELETING_REQUEST_SLOT_TIMEOUT,
logger_->debug(MSG_DELETING_REQUEST_SLOT_TIMEOUT,
util::itos(cuid_).c_str(), util::itos(cuid_).c_str(),
static_cast<unsigned long>(slot.getIndex()), static_cast<unsigned long>(slot.getIndex()),
slot.getBegin(), slot.getBegin(),
static_cast<unsigned long>(slot.getBlockIndex())); static_cast<unsigned long>(slot.getBlockIndex())));
}
slot.getPiece()->cancelBlock(slot.getBlockIndex()); slot.getPiece()->cancelBlock(slot.getBlockIndex());
peer_->snubbing(true); peer_->snubbing(true);
} else if(slot.getPiece()->hasBlock(slot.getBlockIndex())) { } else if(slot.getPiece()->hasBlock(slot.getBlockIndex())) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt(MSG_DELETING_REQUEST_SLOT_ACQUIRED,
logger_->debug(MSG_DELETING_REQUEST_SLOT_ACQUIRED,
util::itos(cuid_).c_str(), util::itos(cuid_).c_str(),
static_cast<unsigned long>(slot.getIndex()), static_cast<unsigned long>(slot.getIndex()),
slot.getBegin(), slot.getBegin(),
static_cast<unsigned long>(slot.getBlockIndex())); static_cast<unsigned long>(slot.getBlockIndex())));
}
messageDispatcher_->addMessageToQueue messageDispatcher_->addMessageToQueue
(messageFactory_->createCancelMessage(slot.getIndex(), (messageFactory_->createCancelMessage(slot.getIndex(),
slot.getBegin(), slot.getBegin(),

View File

@ -51,7 +51,6 @@ class BtMessage;
class BtMessageFactory; class BtMessageFactory;
class Peer; class Peer;
class Piece; class Piece;
class Logger;
class RequestGroupMan; class RequestGroupMan;
class DefaultBtMessageDispatcher : public BtMessageDispatcher { class DefaultBtMessageDispatcher : public BtMessageDispatcher {
@ -66,7 +65,6 @@ private:
SharedHandle<Peer> peer_; SharedHandle<Peer> peer_;
RequestGroupMan* requestGroupMan_; RequestGroupMan* requestGroupMan_;
time_t requestTimeout_; time_t requestTimeout_;
Logger* logger_;
public: public:
DefaultBtMessageDispatcher(); DefaultBtMessageDispatcher();

View File

@ -45,7 +45,6 @@ class Peer;
class PeerConnection; class PeerConnection;
class BtMessageDispatcher; class BtMessageDispatcher;
class BtMessageFactory; class BtMessageFactory;
class Logger;
class DefaultBtMessageReceiver : public BtMessageReceiver { class DefaultBtMessageReceiver : public BtMessageReceiver {
private: private:

View File

@ -52,6 +52,7 @@
#include "a2io.h" #include "a2io.h"
#include "DownloadFailureException.h" #include "DownloadFailureException.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
#include "array_fun.h" #include "array_fun.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
@ -78,12 +79,11 @@ std::string createFilename
DefaultBtProgressInfoFile::DefaultBtProgressInfoFile DefaultBtProgressInfoFile::DefaultBtProgressInfoFile
(const SharedHandle<DownloadContext>& dctx, (const SharedHandle<DownloadContext>& dctx,
const PieceStorageHandle& pieceStorage, const PieceStorageHandle& pieceStorage,
const Option* option): const Option* option)
dctx_(dctx), : dctx_(dctx),
pieceStorage_(pieceStorage), pieceStorage_(pieceStorage),
option_(option), option_(option),
logger_(LogFactory::getInstance()), filename_(createFilename(dctx_, getSuffix()))
filename_(createFilename(dctx_, getSuffix()))
{} {}
DefaultBtProgressInfoFile::~DefaultBtProgressInfoFile() {} DefaultBtProgressInfoFile::~DefaultBtProgressInfoFile() {}
@ -105,7 +105,7 @@ bool DefaultBtProgressInfoFile::isTorrentDownload()
// Since version 0001, Integers are saved in binary form, network byte order. // Since version 0001, Integers are saved in binary form, network byte order.
void DefaultBtProgressInfoFile::save() void DefaultBtProgressInfoFile::save()
{ {
logger_->info(MSG_SAVING_SEGMENT_FILE, filename_.c_str()); A2_LOG_INFO(fmt(MSG_SAVING_SEGMENT_FILE, filename_.c_str()));
std::string filenameTemp = filename_+"__temp"; std::string filenameTemp = filename_+"__temp";
{ {
std::ofstream o(filenameTemp.c_str(), std::ios::out|std::ios::binary); std::ofstream o(filenameTemp.c_str(), std::ios::out|std::ios::binary);
@ -201,7 +201,7 @@ void DefaultBtProgressInfoFile::save()
throw DL_ABORT_EX throw DL_ABORT_EX
(StringFormat(EX_SEGMENT_FILE_WRITE, filename_.c_str()).str()); (StringFormat(EX_SEGMENT_FILE_WRITE, filename_.c_str()).str());
} }
logger_->info(MSG_SAVED_SEGMENT_FILE); A2_LOG_INFO(MSG_SAVED_SEGMENT_FILE);
} }
if(!File(filenameTemp).renameTo(filename_)) { if(!File(filenameTemp).renameTo(filename_)) {
throw DL_ABORT_EX throw DL_ABORT_EX
@ -225,7 +225,7 @@ void DefaultBtProgressInfoFile::save()
// 2) network byte order if version == 0001 // 2) network byte order if version == 0001
void DefaultBtProgressInfoFile::load() void DefaultBtProgressInfoFile::load()
{ {
logger_->info(MSG_LOADING_SEGMENT_FILE, filename_.c_str()); A2_LOG_INFO(fmt(MSG_LOADING_SEGMENT_FILE, filename_.c_str()));
std::ifstream in(filename_.c_str(), std::ios::in|std::ios::binary); std::ifstream in(filename_.c_str(), std::ios::in|std::ios::binary);
if(!in) { if(!in) {
throw DL_ABORT_EX throw DL_ABORT_EX
@ -251,9 +251,7 @@ void DefaultBtProgressInfoFile::load()
bool infoHashCheckEnabled = false; bool infoHashCheckEnabled = false;
if(extension[3]&1 && isTorrentDownload()) { if(extension[3]&1 && isTorrentDownload()) {
infoHashCheckEnabled = true; infoHashCheckEnabled = true;
if(logger_->debug()) { A2_LOG_DEBUG("InfoHash checking enabled.");
logger_->debug("InfoHash checking enabled.");
}
} }
uint32_t infoHashLength; uint32_t infoHashLength;
@ -422,7 +420,7 @@ void DefaultBtProgressInfoFile::load()
util::convertBitfield(&dest, &src); util::convertBitfield(&dest, &src);
pieceStorage_->setBitfield(dest.getBitfield(), dest.getBitfieldLength()); pieceStorage_->setBitfield(dest.getBitfield(), dest.getBitfieldLength());
} }
logger_->info(MSG_LOADED_SEGMENT_FILE); A2_LOG_INFO(MSG_LOADED_SEGMENT_FILE);
} }
void DefaultBtProgressInfoFile::removeFile() void DefaultBtProgressInfoFile::removeFile()
@ -437,10 +435,10 @@ bool DefaultBtProgressInfoFile::exists()
{ {
File f(filename_); File f(filename_);
if(f.isFile()) { if(f.isFile()) {
logger_->info(MSG_SEGMENT_FILE_EXISTS, filename_.c_str()); A2_LOG_INFO(fmt(MSG_SEGMENT_FILE_EXISTS, filename_.c_str()));
return true; return true;
} else { } else {
logger_->info(MSG_SEGMENT_FILE_DOES_NOT_EXIST, filename_.c_str()); A2_LOG_INFO(fmt(MSG_SEGMENT_FILE_DOES_NOT_EXIST, filename_.c_str()));
return false; return false;
} }
} }

View File

@ -43,7 +43,6 @@ class DownloadContext;
class PieceStorage; class PieceStorage;
class PeerStorage; class PeerStorage;
class BtRuntime; class BtRuntime;
class Logger;
class Option; class Option;
class DefaultBtProgressInfoFile : public BtProgressInfoFile { class DefaultBtProgressInfoFile : public BtProgressInfoFile {
@ -55,7 +54,6 @@ private:
SharedHandle<BtRuntime> btRuntime_; SharedHandle<BtRuntime> btRuntime_;
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
const Option* option_; const Option* option_;
Logger* logger_;
std::string filename_; std::string filename_;
bool isTorrentDownload(); bool isTorrentDownload();

View File

@ -47,25 +47,16 @@
#include "a2functional.h" #include "a2functional.h"
#include "SimpleRandomizer.h" #include "SimpleRandomizer.h"
#include "array_fun.h" #include "array_fun.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
DefaultBtRequestFactory::DefaultBtRequestFactory(): DefaultBtRequestFactory::DefaultBtRequestFactory()
dispatcher_(0), : dispatcher_(0),
messageFactory_(0), messageFactory_(0)
logger_(LogFactory::getInstance()) {}
{
if(logger_->debug()) {
logger_->debug("DefaultBtRequestFactory::instantiated");
}
}
DefaultBtRequestFactory::~DefaultBtRequestFactory() DefaultBtRequestFactory::~DefaultBtRequestFactory() {}
{
if(logger_->debug()) {
logger_->debug("DefaultBtRequestFactory::deleted");
}
}
void DefaultBtRequestFactory::addTargetPiece(const SharedHandle<Piece>& piece) void DefaultBtRequestFactory::addTargetPiece(const SharedHandle<Piece>& piece)
{ {
@ -176,14 +167,12 @@ void DefaultBtRequestFactory::createRequestMessages
getnum -= blockIndexes.size(); getnum -= blockIndexes.size();
for(std::vector<size_t>::const_iterator i = blockIndexes.begin(), for(std::vector<size_t>::const_iterator i = blockIndexes.begin(),
eoi2 = blockIndexes.end(); i != eoi2; ++i) { eoi2 = blockIndexes.end(); i != eoi2; ++i) {
if(logger_->debug()) { A2_LOG_DEBUG
logger_->debug (fmt("Creating RequestMessage index=%lu, begin=%u,"
("Creating RequestMessage index=%lu, begin=%u," " blockIndex=%lu",
" blockIndex=%lu", static_cast<unsigned long>(piece->getIndex()),
static_cast<unsigned long>(piece->getIndex()), static_cast<unsigned int>((*i)*piece->getBlockLength()),
static_cast<unsigned int>((*i)*piece->getBlockLength()), static_cast<unsigned long>(*i)));
static_cast<unsigned long>(*i));
}
requests.push_back requests.push_back
(messageFactory_->createRequestMessage(piece, *i)); (messageFactory_->createRequestMessage(piece, *i));
} }
@ -222,14 +211,12 @@ void DefaultBtRequestFactory::createRequestMessagesOnEndGame
const size_t& blockIndex = *bitr; const size_t& blockIndex = *bitr;
if(!dispatcher_->isOutstandingRequest(piece->getIndex(), if(!dispatcher_->isOutstandingRequest(piece->getIndex(),
blockIndex)) { blockIndex)) {
if(logger_->debug()) { A2_LOG_DEBUG
logger_->debug (fmt("Creating RequestMessage index=%lu, begin=%u,"
("Creating RequestMessage index=%lu, begin=%u," " blockIndex=%lu",
" blockIndex=%lu", static_cast<unsigned long>(piece->getIndex()),
static_cast<unsigned long>(piece->getIndex()), static_cast<unsigned int>(blockIndex*piece->getBlockLength()),
static_cast<unsigned int>(blockIndex*piece->getBlockLength()), static_cast<unsigned long>(blockIndex)));
static_cast<unsigned long>(blockIndex));
}
requests.push_back(messageFactory_->createRequestMessage requests.push_back(messageFactory_->createRequestMessage
(piece, blockIndex)); (piece, blockIndex));
} }

View File

@ -48,7 +48,6 @@ class Peer;
class BtMessageDispatcher; class BtMessageDispatcher;
class BtMessageFactory; class BtMessageFactory;
class Piece; class Piece;
class Logger;
class DefaultBtRequestFactory : public BtRequestFactory { class DefaultBtRequestFactory : public BtRequestFactory {
private: private:
@ -57,7 +56,6 @@ private:
BtMessageDispatcher* dispatcher_; BtMessageDispatcher* dispatcher_;
BtMessageFactory* messageFactory_; BtMessageFactory* messageFactory_;
std::deque<SharedHandle<Piece> > pieces_; std::deque<SharedHandle<Piece> > pieces_;
Logger* logger_;
public: public:
DefaultBtRequestFactory(); DefaultBtRequestFactory();

View File

@ -37,8 +37,6 @@
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "HandshakeExtensionMessage.h" #include "HandshakeExtensionMessage.h"
#include "UTPexExtensionMessage.h" #include "UTPexExtensionMessage.h"
#include "LogFactory.h"
#include "Logger.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "PeerStorage.h" #include "PeerStorage.h"
#include "ExtensionMessageRegistry.h" #include "ExtensionMessageRegistry.h"
@ -56,18 +54,18 @@
namespace aria2 { namespace aria2 {
DefaultExtensionMessageFactory::DefaultExtensionMessageFactory(): DefaultExtensionMessageFactory::DefaultExtensionMessageFactory()
messageFactory_(0), : messageFactory_(0),
dispatcher_(0), dispatcher_(0),
tracker_(0), tracker_(0)
logger_(LogFactory::getInstance()) {} {}
DefaultExtensionMessageFactory::DefaultExtensionMessageFactory DefaultExtensionMessageFactory::DefaultExtensionMessageFactory
(const SharedHandle<Peer>& peer, (const SharedHandle<Peer>& peer,
const SharedHandle<ExtensionMessageRegistry>& registry): const SharedHandle<ExtensionMessageRegistry>& registry)
peer_(peer), : peer_(peer),
registry_(registry), registry_(registry)
logger_(LogFactory::getInstance()) {} {}
DefaultExtensionMessageFactory::~DefaultExtensionMessageFactory() {} DefaultExtensionMessageFactory::~DefaultExtensionMessageFactory() {}

View File

@ -41,7 +41,6 @@ namespace aria2 {
class PeerStorage; class PeerStorage;
class Peer; class Peer;
class Logger;
class ExtensionMessageRegistry; class ExtensionMessageRegistry;
class DownloadContext; class DownloadContext;
class BtMessageFactory; class BtMessageFactory;
@ -63,9 +62,6 @@ private:
BtMessageDispatcher* dispatcher_; BtMessageDispatcher* dispatcher_;
UTMetadataRequestTracker* tracker_; UTMetadataRequestTracker* tracker_;
Logger* logger_;
public: public:
DefaultExtensionMessageFactory(); DefaultExtensionMessageFactory();

View File

@ -46,6 +46,7 @@
#include "PieceStorage.h" #include "PieceStorage.h"
#include "wallclock.h" #include "wallclock.h"
#include "a2functional.h" #include "a2functional.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
@ -53,13 +54,12 @@ namespace {
const int MAX_PEER_LIST_SIZE = 1024; const int MAX_PEER_LIST_SIZE = 1024;
} // namespace } // namespace
DefaultPeerStorage::DefaultPeerStorage(): DefaultPeerStorage::DefaultPeerStorage()
logger_(LogFactory::getInstance()), : removedPeerSessionDownloadLength_(0),
removedPeerSessionDownloadLength_(0), removedPeerSessionUploadLength_(0),
removedPeerSessionUploadLength_(0), seederStateChoke_(new BtSeederStateChoke()),
seederStateChoke_(new BtSeederStateChoke()), leecherStateChoke_(new BtLeecherStateChoke()),
leecherStateChoke_(new BtLeecherStateChoke()), lastTransferStatMapUpdated_(0)
lastTransferStatMapUpdated_(0)
{} {}
DefaultPeerStorage::~DefaultPeerStorage() DefaultPeerStorage::~DefaultPeerStorage()
@ -103,10 +103,9 @@ size_t calculateMaxPeerListSize(const SharedHandle<BtRuntime>& btRuntime)
bool DefaultPeerStorage::addPeer(const SharedHandle<Peer>& peer) { bool DefaultPeerStorage::addPeer(const SharedHandle<Peer>& peer) {
if(isPeerAlreadyAdded(peer)) { if(isPeerAlreadyAdded(peer)) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Adding %s:%u is rejected because it has been already"
logger_->debug("Adding %s:%u is rejected because it has been already" " added.",
" added.", peer->getIPAddress().c_str(), peer->getPort()); peer->getIPAddress().c_str(), peer->getPort()));
}
return false; return false;
} }
size_t maxPeerListSize = calculateMaxPeerListSize(btRuntime_); size_t maxPeerListSize = calculateMaxPeerListSize(btRuntime_);
@ -123,10 +122,8 @@ void DefaultPeerStorage::addPeer(const std::vector<SharedHandle<Peer> >& peers)
eoi = peers.end(); itr != eoi; ++itr) { eoi = peers.end(); itr != eoi; ++itr) {
const SharedHandle<Peer>& peer = *itr; const SharedHandle<Peer>& peer = *itr;
if(addPeer(peer)) { if(addPeer(peer)) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt(MSG_ADDING_PEER,
logger_->debug(MSG_ADDING_PEER, peer->getIPAddress().c_str(), peer->getPort()));
peer->getIPAddress().c_str(), peer->getPort());
}
} }
} }
} }
@ -241,9 +238,7 @@ TransferStat DefaultPeerStorage::calculateStat()
{ {
TransferStat stat; TransferStat stat;
if(lastTransferStatMapUpdated_.differenceInMillis(global::wallclock) >= 250) { if(lastTransferStatMapUpdated_.differenceInMillis(global::wallclock) >= 250) {
if(logger_->debug()) { A2_LOG_DEBUG("Updating TransferStat of PeerStorage");
logger_->debug("Updating TransferStat of PeerStorage");
}
lastTransferStatMapUpdated_ = global::wallclock; lastTransferStatMapUpdated_ = global::wallclock;
peerTransferStatMap_.clear(); peerTransferStatMap_.clear();
std::vector<SharedHandle<Peer> > activePeers; std::vector<SharedHandle<Peer> > activePeers;
@ -272,9 +267,7 @@ TransferStat DefaultPeerStorage::calculateStat()
void DefaultPeerStorage::updateTransferStatFor(const SharedHandle<Peer>& peer) void DefaultPeerStorage::updateTransferStatFor(const SharedHandle<Peer>& peer)
{ {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Updating TransferStat for peer %s", peer->getID().c_str()));
logger_->debug("Updating TransferStat for peer %s", peer->getID().c_str());
}
std::map<std::string, TransferStat>::iterator itr = std::map<std::string, TransferStat>::iterator itr =
peerTransferStatMap_.find(peer->getID()); peerTransferStatMap_.find(peer->getID());
if(itr == peerTransferStatMap_.end()) { if(itr == peerTransferStatMap_.end()) {
@ -340,10 +333,8 @@ void DefaultPeerStorage::returnPeer(const SharedHandle<Peer>& peer)
std::deque<SharedHandle<Peer> >::iterator itr = std::deque<SharedHandle<Peer> >::iterator itr =
std::find_if(peers_.begin(), peers_.end(), derefEqual(peer)); std::find_if(peers_.begin(), peers_.end(), derefEqual(peer));
if(itr == peers_.end()) { if(itr == peers_.end()) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Cannot find peer %s:%u in PeerStorage.",
logger_->debug("Cannot find peer %s:%u in PeerStorage.", peer->getIPAddress().c_str(), peer->getPort()));
peer->getIPAddress().c_str(), peer->getPort());
}
} else { } else {
peers_.erase(itr); peers_.erase(itr);

View File

@ -43,7 +43,6 @@
namespace aria2 { namespace aria2 {
class Logger;
class BtRuntime; class BtRuntime;
class BtSeederStateChoke; class BtSeederStateChoke;
class BtLeecherStateChoke; class BtLeecherStateChoke;
@ -55,7 +54,6 @@ private:
SharedHandle<PieceStorage> pieceStorage_; SharedHandle<PieceStorage> pieceStorage_;
std::deque<SharedHandle<Peer> > peers_; std::deque<SharedHandle<Peer> > peers_;
std::deque<SharedHandle<Peer> > droppedPeers_; std::deque<SharedHandle<Peer> > droppedPeers_;
Logger* logger_;
uint64_t removedPeerSessionDownloadLength_; uint64_t removedPeerSessionDownloadLength_;
uint64_t removedPeerSessionUploadLength_; uint64_t removedPeerSessionUploadLength_;

View File

@ -55,6 +55,7 @@
#include "a2functional.h" #include "a2functional.h"
#include "Option.h" #include "Option.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
#include "RarestPieceSelector.h" #include "RarestPieceSelector.h"
#include "array_fun.h" #include "array_fun.h"
#include "PieceStatMan.h" #include "PieceStatMan.h"
@ -67,20 +68,20 @@
namespace aria2 { namespace aria2 {
DefaultPieceStorage::DefaultPieceStorage DefaultPieceStorage::DefaultPieceStorage
(const SharedHandle<DownloadContext>& downloadContext, const Option* option): (const SharedHandle<DownloadContext>& downloadContext, const Option* option)
downloadContext_(downloadContext), : downloadContext_(downloadContext),
bitfieldMan_(new BitfieldMan(downloadContext->getPieceLength(), bitfieldMan_(new BitfieldMan(downloadContext->getPieceLength(),
downloadContext->getTotalLength())), downloadContext->getTotalLength())),
diskWriterFactory_(new DefaultDiskWriterFactory()), diskWriterFactory_(new DefaultDiskWriterFactory()),
endGame_(false), endGame_(false),
endGamePieceNum_(END_GAME_PIECE_NUM), endGamePieceNum_(END_GAME_PIECE_NUM),
logger_(LogFactory::getInstance()), option_(option),
option_(option), pieceStatMan_(new PieceStatMan(downloadContext->getNumPieces(), true)),
pieceStatMan_(new PieceStatMan(downloadContext->getNumPieces(), true)), pieceSelector_(new RarestPieceSelector(pieceStatMan_))
pieceSelector_(new RarestPieceSelector(pieceStatMan_))
{} {}
DefaultPieceStorage::~DefaultPieceStorage() { DefaultPieceStorage::~DefaultPieceStorage()
{
delete bitfieldMan_; delete bitfieldMan_;
} }
@ -130,10 +131,8 @@ void DefaultPieceStorage::addUsedPiece(const SharedHandle<Piece>& piece)
std::lower_bound(usedPieces_.begin(), usedPieces_.end(), piece, std::lower_bound(usedPieces_.begin(), usedPieces_.end(), piece,
DerefLess<SharedHandle<Piece> >()); DerefLess<SharedHandle<Piece> >());
usedPieces_.insert(i, piece); usedPieces_.insert(i, piece);
if(logger_->debug()) { A2_LOG_DEBUG(fmt("usedPieces_.size()=%lu",
logger_->debug("usedPieces_.size()=%lu", static_cast<unsigned long>(usedPieces_.size())));
static_cast<unsigned long>(usedPieces_.size()));
}
} }
SharedHandle<Piece> DefaultPieceStorage::findUsedPiece(size_t index) const SharedHandle<Piece> DefaultPieceStorage::findUsedPiece(size_t index) const
@ -428,12 +427,12 @@ void DefaultPieceStorage::completePiece(const SharedHandle<Piece>& piece)
if(downloadFinished()) { if(downloadFinished()) {
downloadContext_->resetDownloadStopTime(); downloadContext_->resetDownloadStopTime();
if(isSelectiveDownloadingMode()) { if(isSelectiveDownloadingMode()) {
logger_->notice(MSG_SELECTIVE_DOWNLOAD_COMPLETED); A2_LOG_NOTICE(MSG_SELECTIVE_DOWNLOAD_COMPLETED);
// following line was commented out in order to stop sending request // following line was commented out in order to stop sending request
// message after user-specified files were downloaded. // message after user-specified files were downloaded.
//finishSelectiveDownloadingMode(); //finishSelectiveDownloadingMode();
} else { } else {
logger_->info(MSG_DOWNLOAD_COMPLETED); A2_LOG_INFO(MSG_DOWNLOAD_COMPLETED);
} }
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
if(downloadContext_->hasAttribute(bittorrent::BITTORRENT)) { if(downloadContext_->hasAttribute(bittorrent::BITTORRENT)) {
@ -561,9 +560,7 @@ bool DefaultPieceStorage::allDownloadFinished()
void DefaultPieceStorage::initStorage() void DefaultPieceStorage::initStorage()
{ {
if(downloadContext_->getFileEntries().size() == 1) { if(downloadContext_->getFileEntries().size() == 1) {
if(logger_->debug()) { A2_LOG_DEBUG("Instantiating DirectDiskAdaptor");
logger_->debug("Instantiating DirectDiskAdaptor");
}
DirectDiskAdaptorHandle directDiskAdaptor(new DirectDiskAdaptor()); DirectDiskAdaptorHandle directDiskAdaptor(new DirectDiskAdaptor());
directDiskAdaptor->setTotalLength(downloadContext_->getTotalLength()); directDiskAdaptor->setTotalLength(downloadContext_->getTotalLength());
directDiskAdaptor->setFileEntries directDiskAdaptor->setFileEntries
@ -579,9 +576,7 @@ void DefaultPieceStorage::initStorage()
directDiskAdaptor->setDiskWriter(writer); directDiskAdaptor->setDiskWriter(writer);
diskAdaptor_ = directDiskAdaptor; diskAdaptor_ = directDiskAdaptor;
} else { } else {
if(logger_->debug()) { A2_LOG_DEBUG("Instantiating MultiDiskAdaptor");
logger_->debug("Instantiating MultiDiskAdaptor");
}
MultiDiskAdaptorHandle multiDiskAdaptor(new MultiDiskAdaptor()); MultiDiskAdaptorHandle multiDiskAdaptor(new MultiDiskAdaptor());
multiDiskAdaptor->setFileEntries(downloadContext_->getFileEntries().begin(), multiDiskAdaptor->setFileEntries(downloadContext_->getFileEntries().begin(),
downloadContext_->getFileEntries().end()); downloadContext_->getFileEntries().end());
@ -671,10 +666,8 @@ void DefaultPieceStorage::removeAdvertisedPiece(time_t elapsed)
std::deque<HaveEntry>::iterator itr = std::deque<HaveEntry>::iterator itr =
std::find_if(haves_.begin(), haves_.end(), FindElapsedHave(elapsed)); std::find_if(haves_.begin(), haves_.end(), FindElapsedHave(elapsed));
if(itr != haves_.end()) { if(itr != haves_.end()) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt(MSG_REMOVED_HAVE_ENTRY,
logger_->debug(MSG_REMOVED_HAVE_ENTRY, static_cast<unsigned long>(haves_.end()-itr)));
static_cast<unsigned long>(haves_.end()-itr));
}
haves_.erase(itr, haves_.end()); haves_.erase(itr, haves_.end());
} }
} }

View File

@ -43,7 +43,6 @@ namespace aria2 {
class DownloadContext; class DownloadContext;
class BitfieldMan; class BitfieldMan;
class Logger;
class Option; class Option;
class DiskWriterFactory; class DiskWriterFactory;
class FileEntry; class FileEntry;
@ -80,7 +79,6 @@ private:
bool endGame_; bool endGame_;
size_t endGamePieceNum_; size_t endGamePieceNum_;
Logger* logger_;
const Option* option_; const Option* option_;
std::deque<HaveEntry> haves_; std::deque<HaveEntry> haves_;

View File

@ -34,14 +34,12 @@
/* copyright --> */ /* copyright --> */
#include "DiskAdaptor.h" #include "DiskAdaptor.h"
#include "FileEntry.h" #include "FileEntry.h"
#include "LogFactory.h"
#include "Logger.h"
namespace aria2 { namespace aria2 {
DiskAdaptor::DiskAdaptor(): DiskAdaptor::DiskAdaptor()
fallocate_(false), : fallocate_(false)
logger_(LogFactory::getInstance()) {} {}
DiskAdaptor::~DiskAdaptor() {} DiskAdaptor::~DiskAdaptor() {}

View File

@ -45,7 +45,6 @@
namespace aria2 { namespace aria2 {
class FileEntry; class FileEntry;
class Logger;
class FileAllocationIterator; class FileAllocationIterator;
class DiskAdaptor:public BinaryStream { class DiskAdaptor:public BinaryStream {
@ -53,13 +52,6 @@ private:
std::vector<SharedHandle<FileEntry> > fileEntries_; std::vector<SharedHandle<FileEntry> > fileEntries_;
bool fallocate_; bool fallocate_;
Logger* logger_;
protected:
Logger* getLogger() const
{
return logger_;
}
public: public:
DiskAdaptor(); DiskAdaptor();
virtual ~DiskAdaptor(); virtual ~DiskAdaptor();

View File

@ -45,6 +45,7 @@
#include "SegmentMan.h" #include "SegmentMan.h"
#include "Segment.h" #include "Segment.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "ChecksumCheckIntegrityEntry.h" #include "ChecksumCheckIntegrityEntry.h"
#include "PieceStorage.h" #include "PieceStorage.h"
#include "CheckIntegrityCommand.h" #include "CheckIntegrityCommand.h"
@ -56,6 +57,7 @@
#include "message.h" #include "message.h"
#include "prefs.h" #include "prefs.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "fmt.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "wallclock.h" #include "wallclock.h"
#include "SinkStreamFilter.h" #include "SinkStreamFilter.h"
@ -197,10 +199,8 @@ bool DownloadCommand::executeInternal() {
// If segment->getLength() == 0, the server doesn't provide // If segment->getLength() == 0, the server doesn't provide
// content length, but the client detected that download // content length, but the client detected that download
// completed. // completed.
if(getLogger()->info()) { A2_LOG_INFO(fmt(MSG_SEGMENT_DOWNLOAD_COMPLETED,
getLogger()->info(MSG_SEGMENT_DOWNLOAD_COMPLETED, util::itos(getCuid()).c_str()));
util::itos(getCuid()).c_str());
}
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
{ {
@ -213,11 +213,8 @@ bool DownloadCommand::executeInternal() {
!getDownloadContext()->hasAttribute(bittorrent::BITTORRENT)) && !getDownloadContext()->hasAttribute(bittorrent::BITTORRENT)) &&
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
segment->isHashCalculated()) { segment->isHashCalculated()) {
if(getLogger()->debug()) { A2_LOG_DEBUG(fmt("Hash is available! index=%lu",
getLogger()->debug static_cast<unsigned long>(segment->getIndex())));
("Hash is available! index=%lu",
static_cast<unsigned long>(segment->getIndex()));
}
validatePieceHash validatePieceHash
(segment, expectedPieceHash, segment->getHashString()); (segment, expectedPieceHash, segment->getHashString());
} else { } else {
@ -340,14 +337,14 @@ void DownloadCommand::validatePieceHash(const SharedHandle<Segment>& segment,
const std::string& actualPieceHash) const std::string& actualPieceHash)
{ {
if(actualPieceHash == expectedPieceHash) { if(actualPieceHash == expectedPieceHash) {
getLogger()->info(MSG_GOOD_CHUNK_CHECKSUM, actualPieceHash.c_str()); A2_LOG_INFO(fmt(MSG_GOOD_CHUNK_CHECKSUM, actualPieceHash.c_str()));
getSegmentMan()->completeSegment(getCuid(), segment); getSegmentMan()->completeSegment(getCuid(), segment);
} else { } else {
getLogger()->info(EX_INVALID_CHUNK_CHECKSUM, A2_LOG_INFO(fmt(EX_INVALID_CHUNK_CHECKSUM,
static_cast<unsigned long>(segment->getIndex()), static_cast<unsigned long>(segment->getIndex()),
util::itos(segment->getPosition(), true).c_str(), util::itos(segment->getPosition(), true).c_str(),
expectedPieceHash.c_str(), expectedPieceHash.c_str(),
actualPieceHash.c_str()); actualPieceHash.c_str()));
segment->clear(); segment->clear();
getSegmentMan()->cancelSegment(getCuid()); getSegmentMan()->cancelSegment(getCuid());
throw DL_RETRY_EX throw DL_RETRY_EX

View File

@ -64,6 +64,7 @@
#include "CheckIntegrityEntry.h" #include "CheckIntegrityEntry.h"
#include "BtProgressInfoFile.h" #include "BtProgressInfoFile.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "fmt.h"
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
# include "BtRegistry.h" # include "BtRegistry.h"
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
@ -85,17 +86,16 @@ volatile sig_atomic_t globalHaltRequested = 0;
} // namespace global } // namespace global
DownloadEngine::DownloadEngine(const SharedHandle<EventPoll>& eventPoll): DownloadEngine::DownloadEngine(const SharedHandle<EventPoll>& eventPoll)
eventPoll_(eventPoll), : eventPoll_(eventPoll),
logger_(LogFactory::getInstance()), haltRequested_(false),
haltRequested_(false), noWait_(false),
noWait_(false), refreshInterval_(DEFAULT_REFRESH_INTERVAL),
refreshInterval_(DEFAULT_REFRESH_INTERVAL), cookieStorage_(new CookieStorage()),
cookieStorage_(new CookieStorage()),
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
btRegistry_(new BtRegistry()), btRegistry_(new BtRegistry()),
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
dnsCache_(new DNSCache()) dnsCache_(new DNSCache())
{ {
unsigned char sessionId[20]; unsigned char sessionId[20];
util::generateRandomKey(sessionId); util::generateRandomKey(sessionId);
@ -217,14 +217,14 @@ void DownloadEngine::afterEachIteration()
{ {
requestGroupMan_->calculateStat(); requestGroupMan_->calculateStat();
if(global::globalHaltRequested == 1) { if(global::globalHaltRequested == 1) {
logger_->notice(_("Shutdown sequence commencing..." A2_LOG_NOTICE(_("Shutdown sequence commencing..."
" Press Ctrl-C again for emergency shutdown.")); " Press Ctrl-C again for emergency shutdown."));
requestHalt(); requestHalt();
global::globalHaltRequested = 2; global::globalHaltRequested = 2;
setNoWait(true); setNoWait(true);
setRefreshInterval(0); setRefreshInterval(0);
} else if(global::globalHaltRequested == 3) { } else if(global::globalHaltRequested == 3) {
logger_->notice(_("Emergency shutdown sequence commencing...")); A2_LOG_NOTICE(_("Emergency shutdown sequence commencing..."));
requestForceHalt(); requestForceHalt();
global::globalHaltRequested = 4; global::globalHaltRequested = 4;
setNoWait(true); setNoWait(true);
@ -276,15 +276,13 @@ void DownloadEngine::addRoutineCommand(Command* command)
void DownloadEngine::poolSocket(const std::string& key, void DownloadEngine::poolSocket(const std::string& key,
const SocketPoolEntry& entry) const SocketPoolEntry& entry)
{ {
logger_->info("Pool socket for %s", key.c_str()); A2_LOG_INFO(fmt("Pool socket for %s", key.c_str()));
std::multimap<std::string, SocketPoolEntry>::value_type p(key, entry); std::multimap<std::string, SocketPoolEntry>::value_type p(key, entry);
socketPool_.insert(p); socketPool_.insert(p);
if(lastSocketPoolScan_.difference(global::wallclock) >= 60) { if(lastSocketPoolScan_.difference(global::wallclock) >= 60) {
std::multimap<std::string, SocketPoolEntry> newPool; std::multimap<std::string, SocketPoolEntry> newPool;
if(logger_->debug()) { A2_LOG_DEBUG("Scaning SocketPool and erasing timed out entry.");
logger_->debug("Scaning SocketPool and erasing timed out entry.");
}
lastSocketPoolScan_ = global::wallclock; lastSocketPoolScan_ = global::wallclock;
for(std::multimap<std::string, SocketPoolEntry>::iterator i = for(std::multimap<std::string, SocketPoolEntry>::iterator i =
socketPool_.begin(), eoi = socketPool_.end(); i != eoi; ++i) { socketPool_.begin(), eoi = socketPool_.end(); i != eoi; ++i) {
@ -292,11 +290,9 @@ void DownloadEngine::poolSocket(const std::string& key,
newPool.insert(*i); newPool.insert(*i);
} }
} }
if(logger_->debug()) { A2_LOG_DEBUG(fmt("%lu entries removed.",
logger_->debug static_cast<unsigned long>
("%lu entries removed.", (socketPool_.size()-newPool.size())));
static_cast<unsigned long>(socketPool_.size()-newPool.size()));
}
socketPool_ = newPool; socketPool_ = newPool;
} }
} }
@ -402,7 +398,7 @@ DownloadEngine::findSocketPoolEntry(const std::string& key)
// We assume that if socket is readable it means peer shutdowns // We assume that if socket is readable it means peer shutdowns
// connection and the socket will receive EOF. So skip it. // connection and the socket will receive EOF. So skip it.
if(!e.isTimeout() && !e.getSocket()->isReadable(0)) { if(!e.isTimeout() && !e.getSocket()->isReadable(0)) {
logger_->info("Found socket for %s", key.c_str()); A2_LOG_INFO(fmt("Found socket for %s", key.c_str()));
return i; return i;
} }
} }

View File

@ -56,7 +56,6 @@
namespace aria2 { namespace aria2 {
class Logger;
class Option; class Option;
class RequestGroupMan; class RequestGroupMan;
class StatCalc; class StatCalc;
@ -78,8 +77,6 @@ private:
SharedHandle<EventPoll> eventPoll_; SharedHandle<EventPoll> eventPoll_;
Logger* logger_;
SharedHandle<StatCalc> statCalc_; SharedHandle<StatCalc> statCalc_;
bool haltRequested_; bool haltRequested_;

View File

@ -36,8 +36,6 @@
#include <algorithm> #include <algorithm>
#include "LogFactory.h"
#include "Logger.h"
#include "Option.h" #include "Option.h"
#include "RequestGroup.h" #include "RequestGroup.h"
#include "DownloadEngine.h" #include "DownloadEngine.h"
@ -80,8 +78,7 @@
namespace aria2 { namespace aria2 {
DownloadEngineFactory::DownloadEngineFactory(): DownloadEngineFactory::DownloadEngineFactory() {}
logger_(LogFactory::getInstance()) {}
DownloadEngineHandle DownloadEngineHandle
DownloadEngineFactory::newDownloadEngine DownloadEngineFactory::newDownloadEngine

View File

@ -43,14 +43,11 @@
namespace aria2 { namespace aria2 {
class Logger;
class Option; class Option;
class RequestGroup; class RequestGroup;
class DownloadEngine; class DownloadEngine;
class DownloadEngineFactory { class DownloadEngineFactory {
private:
Logger* logger_;
public: public:
DownloadEngineFactory(); DownloadEngineFactory();

View File

@ -33,15 +33,13 @@
*/ */
/* copyright --> */ /* copyright --> */
#include "DownloadHandler.h" #include "DownloadHandler.h"
#include "LogFactory.h"
#include "Logger.h"
#include "RequestGroup.h" #include "RequestGroup.h"
#include "RequestGroupCriteria.h" #include "RequestGroupCriteria.h"
#include "DownloadContext.h" #include "DownloadContext.h"
namespace aria2 { namespace aria2 {
DownloadHandler::DownloadHandler():logger_(LogFactory::getInstance()) {} DownloadHandler::DownloadHandler() {}
DownloadHandler::~DownloadHandler() {} DownloadHandler::~DownloadHandler() {}

View File

@ -44,20 +44,12 @@
namespace aria2 { namespace aria2 {
class RequestGroup; class RequestGroup;
class Logger;
class RequestGroupCriteria; class RequestGroupCriteria;
class DownloadHandler class DownloadHandler
{ {
private: private:
SharedHandle<RequestGroupCriteria> criteria_; SharedHandle<RequestGroupCriteria> criteria_;
Logger* logger_;
protected:
Logger* getLogger() const
{
return logger_;
}
public: public:
DownloadHandler(); DownloadHandler();

View File

@ -44,6 +44,7 @@
#include "Logger.h" #include "Logger.h"
#include "util.h" #include "util.h"
#include "a2functional.h" #include "a2functional.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
@ -80,10 +81,9 @@ struct epoll_event EpollEventPoll::KSocketEntry::getEvents()
return epEvent; return epEvent;
} }
EpollEventPoll::EpollEventPoll(): EpollEventPoll::EpollEventPoll()
epEventsSize_(EPOLL_EVENTS_MAX), : epEventsSize_(EPOLL_EVENTS_MAX),
epEvents_(new struct epoll_event[epEventsSize_]), epEvents_(new struct epoll_event[epEventsSize_])
logger_(LogFactory::getInstance())
{ {
epfd_ = epoll_create(EPOLL_EVENTS_MAX); epfd_ = epoll_create(EPOLL_EVENTS_MAX);
} }
@ -95,9 +95,10 @@ EpollEventPoll::~EpollEventPoll()
while((r = close(epfd_)) == -1 && errno == EINTR); while((r = close(epfd_)) == -1 && errno == EINTR);
int errNum = errno; int errNum = errno;
if(r == -1) { if(r == -1) {
logger_->error("Error occurred while closing epoll file descriptor" A2_LOG_ERROR(fmt("Error occurred while closing epoll file descriptor"
" %d: %s", " %d: %s",
epfd_, util::safeStrerror(errNum).c_str()); epfd_,
util::safeStrerror(errNum).c_str()));
} }
} }
delete [] epEvents_; delete [] epEvents_;
@ -201,10 +202,9 @@ bool EpollEventPoll::addEvents(sock_t socket,
errNum = errno; errNum = errno;
} }
if(r == -1) { if(r == -1) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Failed to add socket event %d:%s",
logger_->debug("Failed to add socket event %d:%s", socket,
socket, util::safeStrerror(errNum).c_str()); util::safeStrerror(errNum).c_str()));
}
return false; return false;
} else { } else {
return true; return true;
@ -253,25 +253,19 @@ bool EpollEventPoll::deleteEvents(sock_t socket,
r = epoll_ctl(epfd_, EPOLL_CTL_MOD, (*i)->getSocket(), &epEvent); r = epoll_ctl(epfd_, EPOLL_CTL_MOD, (*i)->getSocket(), &epEvent);
errNum = r; errNum = r;
if(r == -1) { if(r == -1) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Failed to delete socket event, but may be ignored:%s",
logger_->debug("Failed to delete socket event, but may be ignored:%s", util::safeStrerror(errNum).c_str()));
util::safeStrerror(errNum).c_str());
}
} }
} }
if(r == -1) { if(r == -1) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Failed to delete socket event:%s",
logger_->debug("Failed to delete socket event:%s", util::safeStrerror(errNum).c_str()));
util::safeStrerror(errNum).c_str());
}
return false; return false;
} else { } else {
return true; return true;
} }
} else { } else {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
logger_->debug("Socket %d is not found in SocketEntries.", socket);
}
return false; return false;
} }
} }

View File

@ -48,8 +48,6 @@
namespace aria2 { namespace aria2 {
class Logger;
class EpollEventPoll : public EventPoll { class EpollEventPoll : public EventPoll {
private: private:
class KSocketEntry; class KSocketEntry;
@ -84,8 +82,6 @@ private:
static const size_t EPOLL_EVENTS_MAX = 1024; static const size_t EPOLL_EVENTS_MAX = 1024;
Logger* logger_;
bool addEvents(sock_t socket, const KEvent& event); bool addEvents(sock_t socket, const KEvent& event);
bool deleteEvents(sock_t socket, const KEvent& event); bool deleteEvents(sock_t socket, const KEvent& event);

View File

@ -45,13 +45,14 @@
#include "LogFactory.h" #include "LogFactory.h"
#include "a2algo.h" #include "a2algo.h"
#include "uri.h" #include "uri.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
FeedbackURISelector::FeedbackURISelector FeedbackURISelector::FeedbackURISelector
(const SharedHandle<ServerStatMan>& serverStatMan): (const SharedHandle<ServerStatMan>& serverStatMan)
serverStatMan_(serverStatMan), : serverStatMan_(serverStatMan)
logger_(LogFactory::getInstance()) {} {}
FeedbackURISelector::~FeedbackURISelector() {} FeedbackURISelector::~FeedbackURISelector() {}
@ -71,12 +72,12 @@ std::string FeedbackURISelector::select
(FileEntry* fileEntry, (FileEntry* fileEntry,
const std::vector<std::pair<size_t, std::string> >& usedHosts) const std::vector<std::pair<size_t, std::string> >& usedHosts)
{ {
if(logger_->debug()) { if(A2_LOG_DEBUG_ENABLED) {
for(std::vector<std::pair<size_t, std::string> >::const_iterator i = for(std::vector<std::pair<size_t, std::string> >::const_iterator i =
usedHosts.begin(), eoi = usedHosts.end(); i != eoi; ++i) { usedHosts.begin(), eoi = usedHosts.end(); i != eoi; ++i) {
logger_->debug("UsedHost=%lu, %s", A2_LOG_DEBUG(fmt("UsedHost=%lu, %s",
static_cast<unsigned long>((*i).first), static_cast<unsigned long>((*i).first),
(*i).second.c_str()); (*i).second.c_str()));
} }
} }
if(fileEntry->getRemainingUris().empty()) { if(fileEntry->getRemainingUris().empty()) {
@ -86,18 +87,14 @@ std::string FeedbackURISelector::select
// it again without usedHosts. // it again without usedHosts.
std::string uri = selectFaster(fileEntry->getRemainingUris(), usedHosts); std::string uri = selectFaster(fileEntry->getRemainingUris(), usedHosts);
if(uri.empty()) { if(uri.empty()) {
if(logger_->debug()) { A2_LOG_DEBUG("No URI returned from selectFaster()");
logger_->debug("No URI returned from selectFaster()");
}
uri = selectRarer(fileEntry->getRemainingUris(), usedHosts); uri = selectRarer(fileEntry->getRemainingUris(), usedHosts);
} }
if(!uri.empty()) { if(!uri.empty()) {
std::deque<std::string>& uris = fileEntry->getRemainingUris(); std::deque<std::string>& uris = fileEntry->getRemainingUris();
uris.erase(std::find(uris.begin(), uris.end(), uri)); uris.erase(std::find(uris.begin(), uris.end(), uri));
} }
if(logger_->debug()) { A2_LOG_DEBUG(fmt("FeedbackURISelector selected %s", uri.c_str()));
logger_->debug("FeedbackURISelector selected %s", uri.c_str());
}
return uri; return uri;
} }
@ -116,9 +113,7 @@ std::string FeedbackURISelector::selectRarer
SharedHandle<ServerStat> ss = SharedHandle<ServerStat> ss =
serverStatMan_->find(us.host, us.protocol); serverStatMan_->find(us.host, us.protocol);
if(ss && ss->isError()) { if(ss && ss->isError()) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Error not considered: %s", (*i).c_str()));
logger_->debug("Error not considered: %s", (*i).c_str());
}
continue; continue;
} }
cands.push_back(std::make_pair(us.host, *i)); cands.push_back(std::make_pair(us.host, *i));
@ -154,9 +149,7 @@ std::string FeedbackURISelector::selectFaster
} }
if(findSecond(usedHosts.begin(), usedHosts.end(), us.host) != if(findSecond(usedHosts.begin(), usedHosts.end(), us.host) !=
usedHosts.end()) { usedHosts.end()) {
if(logger_->debug()) { A2_LOG_DEBUG(fmt("%s is in usedHosts, not considered", (*i).c_str()));
logger_->debug("%s is in usedHosts, not considered", (*i).c_str());
}
continue; continue;
} }
SharedHandle<ServerStat> ss = SharedHandle<ServerStat> ss =
@ -175,15 +168,11 @@ std::string FeedbackURISelector::selectFaster
if(normCands.empty()) { if(normCands.empty()) {
return A2STR::NIL; return A2STR::NIL;
} else { } else {
if(logger_->debug()) { A2_LOG_DEBUG("Selected from normCands");
logger_->debug("Selected from normCands");
}
return normCands.front(); return normCands.front();
} }
} else { } else {
if(logger_->debug()) { A2_LOG_DEBUG("Selected from fastCands");
logger_->debug("Selected from fastCands");
}
std::sort(fastCands.begin(), fastCands.end(), ServerStatFaster()); std::sort(fastCands.begin(), fastCands.end(), ServerStatFaster());
return fastCands.front().second; return fastCands.front().second;
} }

View File

@ -40,14 +40,11 @@
namespace aria2 { namespace aria2 {
class ServerStatMan; class ServerStatMan;
class Logger;
class FeedbackURISelector:public URISelector { class FeedbackURISelector:public URISelector {
private: private:
SharedHandle<ServerStatMan> serverStatMan_; SharedHandle<ServerStatMan> serverStatMan_;
Logger* logger_;
std::string selectRarer std::string selectRarer
(const std::deque<std::string>& uris, (const std::deque<std::string>& uris,
const std::vector<std::pair<size_t, std::string> >& usedHosts); const std::vector<std::pair<size_t, std::string> >& usedHosts);

View File

@ -38,6 +38,7 @@
#include "DownloadEngine.h" #include "DownloadEngine.h"
#include "RequestGroup.h" #include "RequestGroup.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "message.h" #include "message.h"
#include "prefs.h" #include "prefs.h"
#include "util.h" #include "util.h"
@ -47,6 +48,7 @@
#include "RecoverableException.h" #include "RecoverableException.h"
#include "wallclock.h" #include "wallclock.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
@ -66,12 +68,10 @@ bool FileAllocationCommand::executeInternal()
} }
fileAllocationEntry_->allocateChunk(); fileAllocationEntry_->allocateChunk();
if(fileAllocationEntry_->finished()) { if(fileAllocationEntry_->finished()) {
if(getLogger()->debug()) { A2_LOG_DEBUG
getLogger()->debug (fmt(MSG_ALLOCATION_COMPLETED,
(MSG_ALLOCATION_COMPLETED, static_cast<long int>(timer_.difference(global::wallclock)),
static_cast<long int>(timer_.difference(global::wallclock)), util::itos(getRequestGroup()->getTotalLength(), true).c_str()));
util::itos(getRequestGroup()->getTotalLength(), true).c_str());
}
getDownloadEngine()->getFileAllocationMan()->dropPickedEntry(); getDownloadEngine()->getFileAllocationMan()->dropPickedEntry();
std::vector<Command*>* commands = new std::vector<Command*>(); std::vector<Command*>* commands = new std::vector<Command*>();
@ -90,11 +90,13 @@ bool FileAllocationCommand::executeInternal()
bool FileAllocationCommand::handleException(Exception& e) bool FileAllocationCommand::handleException(Exception& e)
{ {
getDownloadEngine()->getFileAllocationMan()->dropPickedEntry(); getDownloadEngine()->getFileAllocationMan()->dropPickedEntry();
getLogger()->error A2_LOG_ERROR_EX(fmt(MSG_FILE_ALLOCATION_FAILURE,
(MSG_FILE_ALLOCATION_FAILURE, e, util::itos(getCuid()).c_str()); util::itos(getCuid()).c_str()),
getLogger()->error e);
(MSG_DOWNLOAD_NOT_COMPLETE, util::itos(getCuid()).c_str(), A2_LOG_ERROR
getRequestGroup()->getDownloadContext()->getBasePath().c_str()); (fmt(MSG_DOWNLOAD_NOT_COMPLETE,
util::itos(getCuid()).c_str(),
getRequestGroup()->getDownloadContext()->getBasePath().c_str()));
return true; return true;
} }

View File

@ -37,7 +37,9 @@
#include "FileAllocationCommand.h" #include "FileAllocationCommand.h"
#include "message.h" #include "message.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "util.h" #include "util.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
@ -51,10 +53,7 @@ Command* FileAllocationDispatcherCommand::createCommand
(const SharedHandle<FileAllocationEntry>& entry) (const SharedHandle<FileAllocationEntry>& entry)
{ {
cuid_t newCUID = getDownloadEngine()->newCUID(); cuid_t newCUID = getDownloadEngine()->newCUID();
if(getLogger()->info()) { A2_LOG_INFO(fmt(MSG_FILE_ALLOCATION_DISPATCH, util::itos(newCUID).c_str()));
getLogger()->info(MSG_FILE_ALLOCATION_DISPATCH,
util::itos(newCUID).c_str());
}
FileAllocationCommand* command = FileAllocationCommand* command =
new FileAllocationCommand(newCUID, entry->getRequestGroup(), new FileAllocationCommand(newCUID, entry->getRequestGroup(),
getDownloadEngine(), entry); getDownloadEngine(), entry);

View File

@ -39,31 +39,38 @@
#include "util.h" #include "util.h"
#include "URISelector.h" #include "URISelector.h"
#include "Logger.h"
#include "LogFactory.h" #include "LogFactory.h"
#include "wallclock.h" #include "wallclock.h"
#include "a2algo.h" #include "a2algo.h"
#include "uri.h" #include "uri.h"
#include "PeerStat.h" #include "PeerStat.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
FileEntry::FileEntry(const std::string& path, FileEntry::FileEntry
uint64_t length, (const std::string& path,
off_t offset, uint64_t length,
const std::vector<std::string>& uris): off_t offset,
path_(path), uris_(uris.begin(), uris.end()), length_(length), const std::vector<std::string>& uris)
offset_(offset), : path_(path),
requested_(true), uris_(uris.begin(), uris.end()),
uniqueProtocol_(false), length_(length),
maxConnectionPerServer_(1), offset_(offset),
lastFasterReplace_(0), requested_(true),
logger_(LogFactory::getInstance()) {} uniqueProtocol_(false),
maxConnectionPerServer_(1),
lastFasterReplace_(0)
{}
FileEntry::FileEntry(): FileEntry::FileEntry()
length_(0), offset_(0), requested_(false), : length_(0),
uniqueProtocol_(false), offset_(0),
maxConnectionPerServer_(1), requested_(false),
logger_(LogFactory::getInstance()) {} uniqueProtocol_(false),
maxConnectionPerServer_(1)
{}
FileEntry::~FileEntry() {} FileEntry::~FileEntry() {}
@ -172,9 +179,7 @@ FileEntry::getRequest
req = requestPool_.front(); req = requestPool_.front();
requestPool_.pop_front(); requestPool_.pop_front();
inFlightRequests_.push_back(req); inFlightRequests_.push_back(req);
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Picked up from pool: %s", req->getUri().c_str()));
logger_->debug("Picked up from pool: %s", req->getUri().c_str());
}
} }
return req; return req;
} }
@ -273,11 +278,9 @@ void FileEntry::removeURIWhoseHostnameIs(const std::string& hostname)
newURIs.push_back(*itr); newURIs.push_back(*itr);
} }
} }
if(logger_->debug()) { A2_LOG_DEBUG(fmt("Removed %lu duplicate hostname URIs for path=%s",
logger_->debug("Removed %lu duplicate hostname URIs for path=%s",
static_cast<unsigned long>(uris_.size()-newURIs.size()), static_cast<unsigned long>(uris_.size()-newURIs.size()),
getPath().c_str()); getPath().c_str()));
}
uris_.swap(newURIs); uris_.swap(newURIs);
} }
@ -317,10 +320,10 @@ void FileEntry::extractURIResult
void FileEntry::reuseUri(const std::vector<std::string>& ignore) void FileEntry::reuseUri(const std::vector<std::string>& ignore)
{ {
if(logger_->debug()) { if(A2_LOG_DEBUG_ENABLED) {
for(std::vector<std::string>::const_iterator i = ignore.begin(), for(std::vector<std::string>::const_iterator i = ignore.begin(),
eoi = ignore.end(); i != eoi; ++i) { eoi = ignore.end(); i != eoi; ++i) {
logger_->debug("ignore host=%s", (*i).c_str()); A2_LOG_DEBUG(fmt("ignore host=%s", (*i).c_str()));
} }
} }
std::deque<std::string> uris = spentUris_; std::deque<std::string> uris = spentUris_;
@ -333,10 +336,10 @@ void FileEntry::reuseUri(const std::vector<std::string>& ignore)
std::sort(errorUris.begin(), errorUris.end()); std::sort(errorUris.begin(), errorUris.end());
errorUris.erase(std::unique(errorUris.begin(), errorUris.end()), errorUris.erase(std::unique(errorUris.begin(), errorUris.end()),
errorUris.end()); errorUris.end());
if(logger_->debug()) { if(A2_LOG_DEBUG_ENABLED) {
for(std::vector<std::string>::const_iterator i = errorUris.begin(), for(std::vector<std::string>::const_iterator i = errorUris.begin(),
eoi = errorUris.end(); i != eoi; ++i) { eoi = errorUris.end(); i != eoi; ++i) {
logger_->debug("error URI=%s", (*i).c_str()); A2_LOG_DEBUG(fmt("error URI=%s", (*i).c_str()));
} }
} }
std::vector<std::string> reusableURIs; std::vector<std::string> reusableURIs;
@ -357,11 +360,12 @@ void FileEntry::reuseUri(const std::vector<std::string>& ignore)
} }
reusableURIs.erase(insertionPoint, reusableURIs.end()); reusableURIs.erase(insertionPoint, reusableURIs.end());
size_t ininum = reusableURIs.size(); size_t ininum = reusableURIs.size();
if(logger_->debug()) { if(A2_LOG_DEBUG_ENABLED) {
logger_->debug("Found %u reusable URIs", static_cast<unsigned int>(ininum)); A2_LOG_DEBUG(fmt("Found %u reusable URIs",
static_cast<unsigned int>(ininum)));
for(std::vector<std::string>::const_iterator i = reusableURIs.begin(), for(std::vector<std::string>::const_iterator i = reusableURIs.begin(),
eoi = reusableURIs.end(); i != eoi; ++i) { eoi = reusableURIs.end(); i != eoi; ++i) {
logger_->debug("URI=%s", (*i).c_str()); A2_LOG_DEBUG(fmt("URI=%s", (*i).c_str()));
} }
} }
uris_.insert(uris_.end(), reusableURIs.begin(), reusableURIs.end()); uris_.insert(uris_.end(), reusableURIs.begin(), reusableURIs.end());

View File

@ -54,8 +54,6 @@ namespace aria2 {
class URISelector; class URISelector;
class Logger;
class FileEntry { class FileEntry {
private: private:
std::string path_; std::string path_;
@ -74,7 +72,6 @@ private:
size_t maxConnectionPerServer_; size_t maxConnectionPerServer_;
std::string originalName_; std::string originalName_;
Timer lastFasterReplace_; Timer lastFasterReplace_;
Logger* logger_;
void storePool(const SharedHandle<Request>& request); void storePool(const SharedHandle<Request>& request);
public: public:

View File

@ -39,7 +39,9 @@
#include "RecoverableException.h" #include "RecoverableException.h"
#include "message.h" #include "message.h"
#include "Logger.h" #include "Logger.h"
#include "LogFactory.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "fmt.h"
namespace aria2 { namespace aria2 {
@ -68,7 +70,7 @@ bool FillRequestGroupCommand::execute()
rgman->clearQueueCheck(); rgman->clearQueueCheck();
rgman->fillRequestGroupFromReserver(e_); rgman->fillRequestGroupFromReserver(e_);
} catch(RecoverableException& ex) { } catch(RecoverableException& ex) {
getLogger()->error(EX_EXCEPTION_CAUGHT, ex); A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, ex);
// Re-request queue check to fulfill the requests of all // Re-request queue check to fulfill the requests of all
// downloads, some might come after this exception. // downloads, some might come after this exception.
rgman->requestQueueCheck(); rgman->requestQueueCheck();

Some files were not shown because too many files have changed in this diff Show More