mirror of https://github.com/aria2/aria2
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
parent
3940da7562
commit
580098eb49
|
@ -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>
|
||||
|
||||
Made DHTBucketTreeNode non-copyable.
|
||||
|
|
|
@ -36,24 +36,21 @@
|
|||
#include "Peer.h"
|
||||
#include "PieceStorage.h"
|
||||
#include "BtMessageValidator.h"
|
||||
#include "LogFactory.h"
|
||||
#include "Logger.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
AbstractBtMessage::AbstractBtMessage(uint8_t id, const std::string& name):
|
||||
BtMessage(id),
|
||||
sendingInProgress_(false),
|
||||
invalidate_(false),
|
||||
uploading_(false),
|
||||
cuid_(0),
|
||||
name_(name),
|
||||
dispatcher_(0),
|
||||
messageFactory_(0),
|
||||
requestFactory_(0),
|
||||
peerConnection_(0),
|
||||
metadataGetMode_(false),
|
||||
logger_(LogFactory::getInstance())
|
||||
AbstractBtMessage::AbstractBtMessage(uint8_t id, const std::string& name)
|
||||
: BtMessage(id),
|
||||
sendingInProgress_(false),
|
||||
invalidate_(false),
|
||||
uploading_(false),
|
||||
cuid_(0),
|
||||
name_(name),
|
||||
dispatcher_(0),
|
||||
messageFactory_(0),
|
||||
requestFactory_(0),
|
||||
peerConnection_(0),
|
||||
metadataGetMode_(false)
|
||||
{}
|
||||
|
||||
AbstractBtMessage::~AbstractBtMessage() {}
|
||||
|
|
|
@ -47,7 +47,6 @@ class BtMessageFactory;
|
|||
class BtRequestFactory;
|
||||
class PeerConnection;
|
||||
class BtMessageValidator;
|
||||
class Logger;
|
||||
|
||||
class AbstractBtMessage : public BtMessage {
|
||||
private:
|
||||
|
@ -73,14 +72,7 @@ private:
|
|||
SharedHandle<BtMessageValidator> validator_;
|
||||
|
||||
bool metadataGetMode_;
|
||||
|
||||
Logger* logger_;
|
||||
protected:
|
||||
Logger* getLogger() const
|
||||
{
|
||||
return logger_;
|
||||
}
|
||||
|
||||
const SharedHandle<PieceStorage>& getPieceStorage() const
|
||||
{
|
||||
return pieceStorage_;
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include "message.h"
|
||||
#include "prefs.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
#include "ServerStat.h"
|
||||
#include "RequestGroupMan.h"
|
||||
#include "A2STR.h"
|
||||
|
@ -113,24 +114,20 @@ AbstractCommand::~AbstractCommand() {
|
|||
}
|
||||
|
||||
bool AbstractCommand::execute() {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - socket: read:%d, write:%d, hup:%d, err:%d",
|
||||
util::itos(getCuid()).c_str(),
|
||||
readEventEnabled(),
|
||||
writeEventEnabled(),
|
||||
hupEventEnabled(),
|
||||
errorEventEnabled());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("CUID#%s - socket: read:%d, write:%d, hup:%d, err:%d",
|
||||
util::itos(getCuid()).c_str(),
|
||||
readEventEnabled(),
|
||||
writeEventEnabled(),
|
||||
hupEventEnabled(),
|
||||
errorEventEnabled()));
|
||||
try {
|
||||
if(requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) {
|
||||
return true;
|
||||
}
|
||||
if(req_ && req_->removalRequested()) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug
|
||||
("CUID#%s - Discard original URI=%s because it is requested.",
|
||||
util::itos(getCuid()).c_str(), req_->getUri().c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("CUID#%s - Discard original URI=%s because it is"
|
||||
" requested.",
|
||||
util::itos(getCuid()).c_str(), req_->getUri().c_str()));
|
||||
return prepareForRetry(0);
|
||||
}
|
||||
if(getPieceStorage()) {
|
||||
|
@ -140,11 +137,9 @@ bool AbstractCommand::execute() {
|
|||
// This command previously has assigned segments, but it is
|
||||
// canceled. So discard current request chain. Plus, if no
|
||||
// segment is available when http pipelining is used.
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - It seems previously assigned segments"
|
||||
" are canceled. Restart.",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("CUID#%s - It seems previously assigned segments"
|
||||
" are canceled. Restart.",
|
||||
util::itos(getCuid()).c_str()));
|
||||
// Request::isPipeliningEnabled() == true means aria2
|
||||
// accessed the remote server and discovered that the server
|
||||
// supports pipelining.
|
||||
|
@ -159,12 +154,10 @@ bool AbstractCommand::execute() {
|
|||
!getPieceStorage()->hasMissingUnusedPiece()) {
|
||||
SharedHandle<Request> fasterRequest = fileEntry_->findFasterRequest(req_);
|
||||
if(fasterRequest) {
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info("CUID#%s - Use faster Request hostname=%s, port=%u",
|
||||
util::itos(getCuid()).c_str(),
|
||||
fasterRequest->getHost().c_str(),
|
||||
fasterRequest->getPort());
|
||||
}
|
||||
A2_LOG_INFO(fmt("CUID#%s - Use faster Request hostname=%s, port=%u",
|
||||
util::itos(getCuid()).c_str(),
|
||||
fasterRequest->getHost().c_str(),
|
||||
fasterRequest->getPort()));
|
||||
// Cancel current Request object and use faster one.
|
||||
fileEntry_->removeRequest(req_);
|
||||
Command* command =
|
||||
|
@ -206,16 +199,12 @@ bool AbstractCommand::execute() {
|
|||
// TODO socket could be pooled here if pipelining is
|
||||
// enabled... Hmm, I don't think if pipelining is enabled
|
||||
// it does not go here.
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_NO_SEGMENT_AVAILABLE,
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_NO_SEGMENT_AVAILABLE,
|
||||
util::itos(getCuid()).c_str()));
|
||||
// When all segments are ignored in SegmentMan, there are
|
||||
// no URIs available, so don't retry.
|
||||
if(getSegmentMan()->allSegmentsIgnored()) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("All segments are ignored.");
|
||||
}
|
||||
A2_LOG_DEBUG("All segments are ignored.");
|
||||
return true;
|
||||
} else {
|
||||
return prepareForRetry(1);
|
||||
|
@ -247,21 +236,17 @@ bool AbstractCommand::execute() {
|
|||
req_->getProtocol());
|
||||
ss->setError();
|
||||
// Purging IP address cache to renew IP address.
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Marking IP address %s as bad",
|
||||
util::itos(getCuid()).c_str(),
|
||||
req_->getConnectedAddr().c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("CUID#%s - Marking IP address %s as bad",
|
||||
util::itos(getCuid()).c_str(),
|
||||
req_->getConnectedAddr().c_str()));
|
||||
e_->markBadIPAddress(req_->getConnectedHostname(),
|
||||
req_->getConnectedAddr(),
|
||||
req_->getConnectedPort());
|
||||
if(e_->findCachedIPAddress
|
||||
(req_->getConnectedHostname(), req_->getConnectedPort()).empty()) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - All IP addresses were marked bad."
|
||||
" Removing Entry.",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("CUID#%s - All IP addresses were marked bad."
|
||||
" Removing Entry.",
|
||||
util::itos(getCuid()).c_str()));
|
||||
e_->removeCachedIPAddress
|
||||
(req_->getConnectedHostname(), req_->getConnectedPort());
|
||||
}
|
||||
|
@ -272,15 +257,13 @@ bool AbstractCommand::execute() {
|
|||
}
|
||||
} catch(DlAbortEx& err) {
|
||||
if(!req_) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug(EX_EXCEPTION_CAUGHT, err);
|
||||
}
|
||||
A2_LOG_DEBUG_EX(EX_EXCEPTION_CAUGHT, err);
|
||||
} else {
|
||||
getLogger()->error
|
||||
(MSG_DOWNLOAD_ABORTED,
|
||||
DL_ABORT_EX2(StringFormat
|
||||
("URI=%s", req_->getCurrentUri().c_str()).str(),err),
|
||||
util::itos(getCuid()).c_str(), req_->getUri().c_str());
|
||||
A2_LOG_ERROR_EX(fmt(MSG_DOWNLOAD_ABORTED,
|
||||
util::itos(getCuid()).c_str(),
|
||||
req_->getUri().c_str()),
|
||||
DL_ABORT_EX2(fmt("URI=%s", req_->getCurrentUri().c_str()),
|
||||
err));
|
||||
fileEntry_->addURIResult(req_->getUri(), err.getCode());
|
||||
requestGroup_->setLastUriResult(req_->getUri(), err.getCode());
|
||||
if(err.getCode() == downloadresultcode::CANNOT_RESUME) {
|
||||
|
@ -292,27 +275,23 @@ bool AbstractCommand::execute() {
|
|||
return true;
|
||||
} catch(DlRetryEx& err) {
|
||||
assert(req_);
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info
|
||||
(MSG_RESTARTING_DOWNLOAD,
|
||||
DL_RETRY_EX2(StringFormat
|
||||
("URI=%s", req_->getCurrentUri().c_str()).str(),
|
||||
err),
|
||||
util::itos(getCuid()).c_str(), req_->getUri().c_str());
|
||||
}
|
||||
A2_LOG_INFO_EX(fmt(MSG_RESTARTING_DOWNLOAD,
|
||||
util::itos(getCuid()).c_str(), req_->getUri().c_str()),
|
||||
DL_RETRY_EX2(fmt("URI=%s", req_->getCurrentUri().c_str()),
|
||||
err));
|
||||
req_->addTryCount();
|
||||
req_->resetRedirectCount();
|
||||
req_->resetUri();
|
||||
const unsigned int maxTries = getOption()->getAsInt(PREF_MAX_TRIES);
|
||||
bool isAbort = maxTries != 0 && req_->getTryCount() >= maxTries;
|
||||
if(isAbort) {
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_MAX_TRY,
|
||||
util::itos(getCuid()).c_str(), req_->getTryCount());
|
||||
}
|
||||
getLogger()->error(MSG_DOWNLOAD_ABORTED, err,
|
||||
util::itos(getCuid()).c_str(),
|
||||
req_->getUri().c_str());
|
||||
A2_LOG_INFO(fmt(MSG_MAX_TRY,
|
||||
util::itos(getCuid()).c_str(),
|
||||
req_->getTryCount()));
|
||||
A2_LOG_ERROR_EX(fmt(MSG_DOWNLOAD_ABORTED,
|
||||
util::itos(getCuid()).c_str(),
|
||||
req_->getUri().c_str()),
|
||||
err);
|
||||
fileEntry_->addURIResult(req_->getUri(), err.getCode());
|
||||
requestGroup_->setLastUriResult(req_->getUri(), err.getCode());
|
||||
if(err.getCode() == downloadresultcode::CANNOT_RESUME) {
|
||||
|
@ -325,7 +304,7 @@ bool AbstractCommand::execute() {
|
|||
return prepareForRetry(0);
|
||||
}
|
||||
} catch(DownloadFailureException& err) {
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, err);
|
||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, err);
|
||||
if(req_) {
|
||||
fileEntry_->addURIResult(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
|
||||
// can assume that there are no in-flight request object.
|
||||
if(entry->getLength() == 0 && entry->getRemainingUris().empty()) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Not trying next request."
|
||||
" No reserved/pooled request is remaining and"
|
||||
" total length is still unknown.",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("CUID#%s - Not trying next request."
|
||||
" No reserved/pooled request is remaining and"
|
||||
" total length is still unknown.",
|
||||
util::itos(getCuid()).c_str()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Trying reserved/pooled request.",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("CUID#%s - Trying reserved/pooled request.",
|
||||
util::itos(getCuid()).c_str()));
|
||||
std::vector<Command*> commands;
|
||||
requestGroup_->createNextCommand(commands, e_, 1);
|
||||
e_->setNoWait(true);
|
||||
|
@ -368,10 +343,8 @@ bool AbstractCommand::prepareForRetry(time_t wait) {
|
|||
}
|
||||
if(req_) {
|
||||
fileEntry_->poolRequest(req_);
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Pooling request URI=%s",
|
||||
util::itos(getCuid()).c_str(), req_->getUri().c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("CUID#%s - Pooling request URI=%s",
|
||||
util::itos(getCuid()).c_str(), req_->getUri().c_str()));
|
||||
if(getSegmentMan()) {
|
||||
getSegmentMan()->recognizeSegmentFor(fileEntry_);
|
||||
}
|
||||
|
@ -394,10 +367,8 @@ void AbstractCommand::onAbort() {
|
|||
fileEntry_->removeIdenticalURI(req_->getUri());
|
||||
fileEntry_->removeRequest(req_);
|
||||
}
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Aborting download",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("CUID#%s - Aborting download",
|
||||
util::itos(getCuid()).c_str()));
|
||||
if(getPieceStorage()) {
|
||||
getSegmentMan()->cancelSegment(getCuid());
|
||||
// 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
|
||||
// ones) doesn't support resume. Let's restart download from
|
||||
// scratch.
|
||||
getLogger()->notice("CUID#%s - Failed to resume download."
|
||||
" Download from scratch.",
|
||||
util::itos(getCuid()).c_str());
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug
|
||||
("CUID#%s - Gathering URIs that has CANNOT_RESUME error",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
A2_LOG_NOTICE(fmt("CUID#%s - Failed to resume download."
|
||||
" Download from scratch.",
|
||||
util::itos(getCuid()).c_str()));
|
||||
A2_LOG_DEBUG(fmt("CUID#%s - Gathering URIs that has CANNOT_RESUME"
|
||||
" error",
|
||||
util::itos(getCuid()).c_str()));
|
||||
// Set PREF_ALWAYS_RESUME to A2_V_TRUE to avoid repeating this
|
||||
// process.
|
||||
getOption()->put(PREF_ALWAYS_RESUME, A2_V_TRUE);
|
||||
|
@ -435,11 +404,9 @@ void AbstractCommand::onAbort() {
|
|||
uris.reserve(res.size());
|
||||
std::transform(res.begin(), res.end(), std::back_inserter(uris),
|
||||
std::mem_fun_ref(&URIResult::getURI));
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - %lu URIs found.",
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long int>(uris.size()));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("CUID#%s - %lu URIs found.",
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long int>(uris.size())));
|
||||
fileEntry_->addUris(uris.begin(), uris.end());
|
||||
getSegmentMan()->recognizeSegmentFor(fileEntry_);
|
||||
}
|
||||
|
@ -640,15 +607,10 @@ SharedHandle<Request> AbstractCommand::createProxyRequest() const
|
|||
if(!proxy.empty()) {
|
||||
proxyRequest.reset(new Request());
|
||||
if(proxyRequest->setUri(proxy)) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Using proxy",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("CUID#%s - Using proxy", util::itos(getCuid()).c_str()));
|
||||
} else {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - Failed to parse proxy string",
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("CUID#%s - Failed to parse proxy string",
|
||||
util::itos(getCuid()).c_str()));
|
||||
proxyRequest.reset();
|
||||
}
|
||||
}
|
||||
|
@ -671,10 +633,9 @@ void AbstractCommand::initAsyncNameResolver(const std::string& hostname)
|
|||
family = AF_INET;
|
||||
}
|
||||
asyncNameResolver_.reset(new AsyncNameResolver(family));
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_RESOLVING_HOSTNAME,
|
||||
util::itos(getCuid()).c_str(), hostname.c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_RESOLVING_HOSTNAME,
|
||||
util::itos(getCuid()).c_str(),
|
||||
hostname.c_str()));
|
||||
asyncNameResolver_->resolve(hostname);
|
||||
setNameResolverCheck(asyncNameResolver_);
|
||||
}
|
||||
|
@ -759,12 +720,10 @@ std::string AbstractCommand::resolveHostname
|
|||
}
|
||||
res.resolve(addrs, hostname);
|
||||
}
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_NAME_RESOLUTION_COMPLETE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
hostname.c_str(),
|
||||
strjoin(addrs.begin(), addrs.end(), ", ").c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_COMPLETE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
hostname.c_str(),
|
||||
strjoin(addrs.begin(), addrs.end(), ", ").c_str()));
|
||||
for(std::vector<std::string>::const_iterator i = addrs.begin(),
|
||||
eoi = addrs.end(); i != eoi; ++i) {
|
||||
e_->cacheIPAddress(hostname, *i, port);
|
||||
|
@ -772,11 +731,10 @@ std::string AbstractCommand::resolveHostname
|
|||
ipaddr = e_->findCachedIPAddress(hostname, port);
|
||||
} else {
|
||||
ipaddr = addrs.front();
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_DNS_CACHE_HIT,
|
||||
util::itos(getCuid()).c_str(), hostname.c_str(),
|
||||
strjoin(addrs.begin(), addrs.end(), ", ").c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_DNS_CACHE_HIT,
|
||||
util::itos(getCuid()).c_str(),
|
||||
hostname.c_str(),
|
||||
strjoin(addrs.begin(), addrs.end(), ", ").c_str()));
|
||||
}
|
||||
return ipaddr;
|
||||
}
|
||||
|
@ -804,11 +762,9 @@ bool AbstractCommand::checkIfConnectionEstablished
|
|||
// See also InitiateConnectionCommand::executeInternal()
|
||||
e_->markBadIPAddress(connectedHostname, connectedAddr, connectedPort);
|
||||
if(!e_->findCachedIPAddress(connectedHostname, connectedPort).empty()) {
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_CONNECT_FAILED_AND_RETRY,
|
||||
util::itos(getCuid()).c_str(),
|
||||
connectedAddr.c_str(), connectedPort);
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_CONNECT_FAILED_AND_RETRY,
|
||||
util::itos(getCuid()).c_str(),
|
||||
connectedAddr.c_str(), connectedPort));
|
||||
Command* command =
|
||||
InitiateConnectionCommandFactory::createInitiateConnectionCommand
|
||||
(getCuid(), req_, fileEntry_, requestGroup_, e_);
|
||||
|
|
|
@ -47,8 +47,6 @@
|
|||
#include "File.h"
|
||||
#include "util.h"
|
||||
#include "message.h"
|
||||
#include "LogFactory.h"
|
||||
#include "Logger.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "a2io.h"
|
||||
#include "StringFormat.h"
|
||||
|
@ -56,12 +54,12 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
AbstractDiskWriter::AbstractDiskWriter(const std::string& filename):
|
||||
filename_(filename),
|
||||
fd_(-1),
|
||||
readOnly_(false),
|
||||
directIOAllowed_(false),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
AbstractDiskWriter::AbstractDiskWriter(const std::string& filename)
|
||||
: filename_(filename),
|
||||
fd_(-1),
|
||||
readOnly_(false),
|
||||
directIOAllowed_(false)
|
||||
{}
|
||||
|
||||
AbstractDiskWriter::~AbstractDiskWriter()
|
||||
{
|
||||
|
|
|
@ -40,8 +40,6 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
class Logger;
|
||||
|
||||
class AbstractDiskWriter : public DiskWriter {
|
||||
private:
|
||||
std::string filename_;
|
||||
|
@ -51,8 +49,6 @@ private:
|
|||
|
||||
bool directIOAllowed_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
ssize_t writeDataInternal(const unsigned char* data, size_t len);
|
||||
ssize_t readDataInternal(unsigned char* data, size_t len);
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "BtRuntime.h"
|
||||
#include "Peer.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "prefs.h"
|
||||
#include "Option.h"
|
||||
#include "BtConstants.h"
|
||||
|
@ -51,6 +52,7 @@
|
|||
#include "bittorrent_helper.h"
|
||||
#include "wallclock.h"
|
||||
#include "util.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -59,12 +61,11 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand
|
|||
RequestGroup* requestGroup,
|
||||
DownloadEngine* e,
|
||||
time_t interval)
|
||||
:
|
||||
Command(cuid),
|
||||
requestGroup_(requestGroup),
|
||||
interval_(interval),
|
||||
e_(e),
|
||||
numNewConnection_(5)
|
||||
: Command(cuid),
|
||||
requestGroup_(requestGroup),
|
||||
interval_(interval),
|
||||
e_(e),
|
||||
numNewConnection_(5)
|
||||
{
|
||||
requestGroup_->increaseNumCommand();
|
||||
}
|
||||
|
@ -141,11 +142,9 @@ void ActivePeerConnectionCommand::connectToPeer(const SharedHandle<Peer>& peer)
|
|||
command->setPeerStorage(peerStorage_);
|
||||
command->setPieceStorage(pieceStorage_);
|
||||
e_->addCommand(command);
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_CONNECTING_TO_PEER,
|
||||
util::itos(getCuid()).c_str(),
|
||||
peer->getIPAddress().c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_CONNECTING_TO_PEER,
|
||||
util::itos(getCuid()).c_str(),
|
||||
peer->getIPAddress().c_str()));
|
||||
}
|
||||
|
||||
void ActivePeerConnectionCommand::setBtRuntime
|
||||
|
|
|
@ -45,9 +45,11 @@
|
|||
namespace aria2 {
|
||||
|
||||
AdaptiveFileAllocationIterator::AdaptiveFileAllocationIterator
|
||||
(BinaryStream* stream, off_t offset, uint64_t totalLength):
|
||||
stream_(stream), offset_(offset), totalLength_(totalLength),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
(BinaryStream* stream, off_t offset, uint64_t totalLength)
|
||||
: stream_(stream),
|
||||
offset_(offset),
|
||||
totalLength_(totalLength)
|
||||
{}
|
||||
|
||||
AdaptiveFileAllocationIterator::~AdaptiveFileAllocationIterator() {}
|
||||
|
||||
|
@ -56,23 +58,17 @@ void AdaptiveFileAllocationIterator::allocateChunk()
|
|||
if(!allocator_) {
|
||||
#ifdef HAVE_FALLOCATE
|
||||
try {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Testing file system supports fallocate.");
|
||||
}
|
||||
A2_LOG_DEBUG("Testing file system supports fallocate.");
|
||||
if(static_cast<uint64_t>(offset_) < totalLength_) {
|
||||
off_t len = std::min(totalLength_-offset_, static_cast<uint64_t>(4096));
|
||||
stream_->allocate(offset_, len);
|
||||
offset_ += len;
|
||||
}
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("File system supports fallocate.");
|
||||
}
|
||||
A2_LOG_DEBUG("File system supports fallocate.");
|
||||
allocator_.reset
|
||||
(new FallocFileAllocationIterator(stream_, offset_, totalLength_));
|
||||
} catch(RecoverableException& e) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("File system does not support fallocate.");
|
||||
}
|
||||
A2_LOG_DEBUG("File system does not support fallocate.");
|
||||
SharedHandle<SingleFileAllocationIterator> salloc
|
||||
(new SingleFileAllocationIterator(stream_, offset_, totalLength_));
|
||||
salloc->init();
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
namespace aria2 {
|
||||
|
||||
class BinaryStream;
|
||||
class Logger;
|
||||
|
||||
class AdaptiveFileAllocationIterator:public FileAllocationIterator
|
||||
{
|
||||
|
@ -52,8 +51,6 @@ private:
|
|||
off_t offset_;
|
||||
|
||||
uint64_t totalLength_;
|
||||
|
||||
Logger* logger_;
|
||||
public:
|
||||
AdaptiveFileAllocationIterator
|
||||
(BinaryStream* stream, off_t offset, uint64_t totalLength);
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "ServerStatMan.h"
|
||||
#include "ServerStat.h"
|
||||
#include "RequestGroup.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "A2STR.h"
|
||||
#include "prefs.h"
|
||||
|
@ -52,6 +53,7 @@
|
|||
#include "SocketCore.h"
|
||||
#include "FileEntry.h"
|
||||
#include "uri.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -63,10 +65,9 @@ namespace aria2 {
|
|||
*/
|
||||
|
||||
AdaptiveURISelector::AdaptiveURISelector
|
||||
(const SharedHandle<ServerStatMan>& serverStatMan, RequestGroup* requestGroup):
|
||||
serverStatMan_(serverStatMan),
|
||||
requestGroup_(requestGroup),
|
||||
logger_(LogFactory::getInstance())
|
||||
(const SharedHandle<ServerStatMan>& serverStatMan, RequestGroup* requestGroup)
|
||||
: serverStatMan_(serverStatMan),
|
||||
requestGroup_(requestGroup)
|
||||
{
|
||||
resetCounters();
|
||||
}
|
||||
|
@ -77,10 +78,8 @@ std::string AdaptiveURISelector::select
|
|||
(FileEntry* fileEntry,
|
||||
const std::vector<std::pair<size_t, std::string> >& usedHosts)
|
||||
{
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("AdaptiveURISelector: called %d",
|
||||
requestGroup_->getNumConnection());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("AdaptiveURISelector: called %d",
|
||||
requestGroup_->getNumConnection()));
|
||||
std::deque<std::string>& uris = fileEntry->getRemainingUris();
|
||||
if (uris.empty() && requestGroup_->getNumConnection() <= 1) {
|
||||
// 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::mem_fun_ref(&URIResult::getURI));
|
||||
|
||||
if(logger_->debug()) {
|
||||
if(A2_LOG_DEBUG_ENABLED) {
|
||||
for(std::deque<std::string>::const_iterator i = uris.begin(),
|
||||
eoi = uris.end(); i != eoi; ++i) {
|
||||
logger_->debug("AdaptiveURISelector: will retry server with increased"
|
||||
" timeout (%ld s): %s",
|
||||
static_cast<long int>(requestGroup_->getTimeout()),
|
||||
(*i).c_str());
|
||||
A2_LOG_DEBUG(fmt("AdaptiveURISelector: will retry server with increased"
|
||||
" timeout (%ld s): %s",
|
||||
static_cast<long int>(requestGroup_->getTimeout()),
|
||||
(*i).c_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,10 +139,9 @@ std::string AdaptiveURISelector::selectOne(const std::deque<std::string>& uris)
|
|||
if(getNbTestedServers(uris) < 3) {
|
||||
std::string notTested = getFirstNotTestedUri(uris);
|
||||
if(notTested != A2STR::NIL) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("AdaptiveURISelector: choosing the first non tested"
|
||||
" mirror: %s", notTested.c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("AdaptiveURISelector: choosing the first non tested"
|
||||
" mirror: %s",
|
||||
notTested.c_str()));
|
||||
--nbServerToEvaluate_;
|
||||
return notTested;
|
||||
}
|
||||
|
@ -154,21 +152,17 @@ std::string AdaptiveURISelector::selectOne(const std::deque<std::string>& uris)
|
|||
std::string notTested = getFirstNotTestedUri(uris);
|
||||
if(notTested != A2STR::NIL) {
|
||||
/* Here we return the first untested mirror */
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("AdaptiveURISelector: choosing non tested mirror %s"
|
||||
A2_LOG_DEBUG(fmt("AdaptiveURISelector: choosing non tested mirror %s"
|
||||
" for connection #%d",
|
||||
notTested.c_str(), nbConnections_);
|
||||
}
|
||||
notTested.c_str(), nbConnections_));
|
||||
return notTested;
|
||||
} else {
|
||||
/* Here we return a mirror which need to be tested again */
|
||||
std::string toReTest = getFirstToTestUri(uris);
|
||||
if(toReTest != A2STR::NIL) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("AdaptiveURISelector: choosing mirror %s which has"
|
||||
A2_LOG_DEBUG(fmt("AdaptiveURISelector: choosing mirror %s which has"
|
||||
" not been tested recently for connection #%d",
|
||||
toReTest.c_str(), nbConnections_);
|
||||
}
|
||||
toReTest.c_str(), nbConnections_));
|
||||
return toReTest;
|
||||
} else {
|
||||
return getBestMirror(uris);
|
||||
|
@ -191,19 +185,18 @@ std::string AdaptiveURISelector::getBestMirror
|
|||
|
||||
if (bests.size() < 2) {
|
||||
std::string uri = getMaxDownloadSpeedUri(uris);
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("AdaptiveURISelector: choosing the best mirror :"
|
||||
A2_LOG_DEBUG(fmt("AdaptiveURISelector: choosing the best mirror :"
|
||||
" %.2fKB/s %s (other mirrors are at least 25%% slower)",
|
||||
(float) max/1024, uri.c_str());
|
||||
}
|
||||
(float) max/1024,
|
||||
uri.c_str()));
|
||||
return uri;
|
||||
} else {
|
||||
std::string uri = selectRandomUri(bests);
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("AdaptiveURISelector: choosing randomly one of the best"
|
||||
A2_LOG_DEBUG(fmt("AdaptiveURISelector: choosing randomly one of the best"
|
||||
" 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;
|
||||
}
|
||||
}
|
||||
|
@ -230,12 +223,17 @@ void AdaptiveURISelector::adjustLowestSpeedLimit
|
|||
unsigned int low_lowest = 4 * 1024;
|
||||
unsigned int max = getMaxDownloadSpeed(uris);
|
||||
if (max > 0 && lowest > max / 4) {
|
||||
logger_->notice("Lowering lowest-speed-limit since known max speed is too"
|
||||
" near (new:%d was:%d max:%d)", max / 4, lowest, max);
|
||||
A2_LOG_NOTICE(fmt("Lowering lowest-speed-limit since known max speed is"
|
||||
" too near (new:%d was:%d max:%d)",
|
||||
max / 4,
|
||||
lowest,
|
||||
max));
|
||||
command->setLowestDownloadSpeedLimit(max / 4);
|
||||
} else if (max == 0 && lowest > low_lowest) {
|
||||
logger_->notice("Lowering lowest-speed-limit since we have no clue about"
|
||||
" available speed (now:%d was:%d)", low_lowest, lowest);
|
||||
A2_LOG_NOTICE(fmt("Lowering lowest-speed-limit since we have no clue"
|
||||
" about available speed (now:%d was:%d)",
|
||||
low_lowest,
|
||||
lowest));
|
||||
command->setLowestDownloadSpeedLimit(low_lowest);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@ namespace aria2 {
|
|||
class ServerStatMan;
|
||||
class RequestGroup;
|
||||
class ServerStat;
|
||||
class Logger;
|
||||
|
||||
class AdaptiveURISelector:public URISelector {
|
||||
private:
|
||||
|
@ -55,8 +54,6 @@ private:
|
|||
|
||||
static const time_t MAX_TIMEOUT = 60;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
void mayRetryWithIncreasedTimeout(FileEntry* fileEntry);
|
||||
|
||||
std::string selectOne(const std::deque<std::string>& uris);
|
||||
|
|
|
@ -48,15 +48,17 @@
|
|||
#include "bittorrent_helper.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
#include "FileEntry.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
BtDependency::BtDependency(RequestGroup* dependant,
|
||||
const SharedHandle<RequestGroup>& dependee):
|
||||
dependant_(dependant),
|
||||
dependee_(dependee),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
BtDependency::BtDependency
|
||||
(RequestGroup* dependant,
|
||||
const SharedHandle<RequestGroup>& dependee)
|
||||
: dependant_(dependant),
|
||||
dependee_(dependee)
|
||||
{}
|
||||
|
||||
BtDependency::~BtDependency() {}
|
||||
|
||||
|
@ -136,27 +138,21 @@ bool BtDependency::resolve()
|
|||
}
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
logger_->error(EX_EXCEPTION_CAUGHT, e);
|
||||
if(logger_->info()) {
|
||||
logger_->info("BtDependency for GID#%s failed. Go without Bt.",
|
||||
util::itos(dependant_->getGID()).c_str());
|
||||
}
|
||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
||||
A2_LOG_INFO(fmt("BtDependency for GID#%s failed. Go without Bt.",
|
||||
util::itos(dependant_->getGID()).c_str()));
|
||||
return true;
|
||||
}
|
||||
if(logger_->info()) {
|
||||
logger_->info("Dependency resolved for GID#%s",
|
||||
util::itos(dependant_->getGID()).c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt("Dependency resolved for GID#%s",
|
||||
util::itos(dependant_->getGID()).c_str()));
|
||||
dependant_->setDownloadContext(context);
|
||||
return true;
|
||||
} else if(dependee_->getNumCommand() == 0) {
|
||||
// dependee_'s download failed.
|
||||
// cut reference here
|
||||
dependee_.reset();
|
||||
if(logger_->info()) {
|
||||
logger_->info("BtDependency for GID#%s failed. Go without Bt.",
|
||||
util::itos(dependant_->getGID()).c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt("BtDependency for GID#%s failed. Go without Bt.",
|
||||
util::itos(dependant_->getGID()).c_str()));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -41,14 +41,12 @@ namespace aria2 {
|
|||
|
||||
class RequestGroup;
|
||||
class Option;
|
||||
class Logger;
|
||||
|
||||
class BtDependency : public Dependency
|
||||
{
|
||||
private:
|
||||
RequestGroup* dependant_;
|
||||
SharedHandle<RequestGroup> dependee_;
|
||||
Logger* logger_;
|
||||
public:
|
||||
BtDependency(RequestGroup* dependant,
|
||||
const SharedHandle<RequestGroup>& dependee);
|
||||
|
|
|
@ -41,13 +41,14 @@
|
|||
#include "LogFactory.h"
|
||||
#include "SimpleRandomizer.h"
|
||||
#include "wallclock.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
BtLeecherStateChoke::BtLeecherStateChoke():
|
||||
round_(0),
|
||||
lastRound_(0),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
BtLeecherStateChoke::BtLeecherStateChoke()
|
||||
: round_(0),
|
||||
lastRound_(0)
|
||||
{}
|
||||
|
||||
BtLeecherStateChoke::~BtLeecherStateChoke() {}
|
||||
|
||||
|
@ -142,8 +143,8 @@ void BtLeecherStateChoke::plannedOptimisticUnchoke
|
|||
std::random_shuffle(peerEntries.begin(), i,
|
||||
*(SimpleRandomizer::getInstance().get()));
|
||||
(*peerEntries.begin()).enableOptUnchoking();
|
||||
logger_->info
|
||||
("POU: %s", (*peerEntries.begin()).getPeer()->getIPAddress().c_str());
|
||||
A2_LOG_INFO(fmt("POU: %s",
|
||||
(*peerEntries.begin()).getPeer()->getIPAddress().c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,9 +163,9 @@ void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
|
|||
std::vector<PeerEntry>::iterator peerIter = peerEntries.begin();
|
||||
for(;peerIter != rest && count; ++peerIter, --count) {
|
||||
(*peerIter).disableChokingRequired();
|
||||
logger_->info("RU: %s, dlspd=%u",
|
||||
(*peerIter).getPeer()->getIPAddress().c_str(),
|
||||
(*peerIter).getDownloadSpeed());
|
||||
A2_LOG_INFO(fmt("RU: %s, dlspd=%u",
|
||||
(*peerIter).getPeer()->getIPAddress().c_str(),
|
||||
(*peerIter).getDownloadSpeed()));
|
||||
if((*peerIter).getPeer()->optUnchoking()) {
|
||||
fastOptUnchoker = true;
|
||||
(*peerIter).disableOptUnchoking();
|
||||
|
@ -177,11 +178,11 @@ void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
|
|||
eoi = peerEntries.end(); i != eoi; ++i) {
|
||||
if((*i).getPeer()->peerInterested()) {
|
||||
(*i).enableOptUnchoking();
|
||||
logger_->info("OU: %s", (*i).getPeer()->getIPAddress().c_str());
|
||||
A2_LOG_INFO(fmt("OU: %s", (*i).getPeer()->getIPAddress().c_str()));
|
||||
break;
|
||||
} else {
|
||||
(*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
|
||||
(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;
|
||||
|
||||
std::vector<PeerEntry> peerEntries;
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
namespace aria2 {
|
||||
|
||||
class Peer;
|
||||
class Logger;
|
||||
|
||||
class BtLeecherStateChoke {
|
||||
private:
|
||||
|
@ -53,8 +52,6 @@ private:
|
|||
|
||||
Timer lastRound_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
class PeerEntry {
|
||||
private:
|
||||
SharedHandle<Peer> peer_;
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "MessageDigestHelper.h"
|
||||
#include "DiskAdaptor.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "Peer.h"
|
||||
#include "Piece.h"
|
||||
#include "PieceStorage.h"
|
||||
|
@ -53,6 +54,7 @@
|
|||
#include "BtRequestFactory.h"
|
||||
#include "PeerConnection.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
#include "DownloadContext.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
@ -60,13 +62,13 @@ namespace aria2 {
|
|||
const std::string BtPieceMessage::NAME("piece");
|
||||
|
||||
BtPieceMessage::BtPieceMessage
|
||||
(size_t index, uint32_t begin, size_t blockLength):
|
||||
AbstractBtMessage(ID, NAME),
|
||||
index_(index),
|
||||
begin_(begin),
|
||||
blockLength_(blockLength),
|
||||
block_(0),
|
||||
rawData_(0)
|
||||
(size_t index, uint32_t begin, size_t blockLength)
|
||||
: AbstractBtMessage(ID, NAME),
|
||||
index_(index),
|
||||
begin_(begin),
|
||||
blockLength_(blockLength),
|
||||
block_(0),
|
||||
rawData_(0)
|
||||
{
|
||||
setUploading(true);
|
||||
}
|
||||
|
@ -107,22 +109,19 @@ void BtPieceMessage::doReceivedAction()
|
|||
getPeer()->snubbing(false);
|
||||
SharedHandle<Piece> piece = getPieceStorage()->getPiece(index_);
|
||||
off_t offset = (off_t)index_*downloadContext_->getPieceLength()+begin_;
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug(MSG_PIECE_RECEIVED,
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long>(index_),
|
||||
begin_, blockLength_,
|
||||
static_cast<long long int>(offset),
|
||||
static_cast<unsigned long>(slot.getBlockIndex()));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt(MSG_PIECE_RECEIVED,
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long>(index_),
|
||||
begin_,
|
||||
blockLength_,
|
||||
static_cast<long long int>(offset),
|
||||
static_cast<unsigned long>(slot.getBlockIndex())));
|
||||
getPieceStorage()->getDiskAdaptor()->writeData
|
||||
(block_, blockLength_, offset);
|
||||
piece->completeBlock(slot.getBlockIndex());
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug(MSG_PIECE_BITFIELD, util::itos(getCuid()).c_str(),
|
||||
util::toHex(piece->getBitfield(),
|
||||
piece->getBitfieldLength()).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt(MSG_PIECE_BITFIELD, util::itos(getCuid()).c_str(),
|
||||
util::toHex(piece->getBitfield(),
|
||||
piece->getBitfieldLength()).c_str()));
|
||||
piece->updateHash(begin_, block_, blockLength_);
|
||||
getBtMessageDispatcher()->removeOutstandingRequest(slot);
|
||||
if(piece->pieceComplete()) {
|
||||
|
@ -134,11 +133,10 @@ void BtPieceMessage::doReceivedAction()
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("CUID#%s - RequestSlot not found, index=%lu, begin=%u",
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long>(index_), begin_);
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("CUID#%s - RequestSlot not found, index=%lu, begin=%u",
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long>(index_),
|
||||
begin_));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,19 +171,15 @@ void BtPieceMessage::send()
|
|||
}
|
||||
size_t writtenLength;
|
||||
if(!isSendingInProgress()) {
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_SEND_PEER_MESSAGE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
getPeer()->getIPAddress().c_str(),
|
||||
getPeer()->getPort(),
|
||||
toString().c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_SEND_PEER_MESSAGE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
getPeer()->getIPAddress().c_str(),
|
||||
getPeer()->getPort(),
|
||||
toString().c_str()));
|
||||
unsigned char* msgHdr = createMessageHeader();
|
||||
size_t msgHdrLen = getMessageHeaderLength();
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("msglength = %lu bytes",
|
||||
static_cast<unsigned long>(msgHdrLen+blockLength_));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("msglength = %lu bytes",
|
||||
static_cast<unsigned long>(msgHdrLen+blockLength_)));
|
||||
getPeerConnection()->pushBytes(msgHdr, msgHdrLen);
|
||||
getPeerConnection()->sendPendingData();
|
||||
off_t pieceDataOffset =
|
||||
|
@ -226,10 +220,8 @@ std::string BtPieceMessage::toString() const
|
|||
bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)
|
||||
{
|
||||
if(!getPieceStorage()->isEndGame() && piece->isHashCalculated()) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("Hash is available!! index=%lu",
|
||||
static_cast<unsigned long>(piece->getIndex()));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Hash is available!! index=%lu",
|
||||
static_cast<unsigned long>(piece->getIndex())));
|
||||
return
|
||||
piece->getHashString()==downloadContext_->getPieceHash(piece->getIndex());
|
||||
} else {
|
||||
|
@ -243,22 +235,18 @@ bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)
|
|||
|
||||
void BtPieceMessage::onNewPiece(const SharedHandle<Piece>& piece)
|
||||
{
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_GOT_NEW_PIECE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long>(piece->getIndex()));
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_GOT_NEW_PIECE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long>(piece->getIndex())));
|
||||
getPieceStorage()->completePiece(piece);
|
||||
getPieceStorage()->advertisePiece(getCuid(), piece->getIndex());
|
||||
}
|
||||
|
||||
void BtPieceMessage::onWrongPiece(const SharedHandle<Piece>& piece)
|
||||
{
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_GOT_WRONG_PIECE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long>(piece->getIndex()));
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_GOT_WRONG_PIECE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long>(piece->getIndex())));
|
||||
erasePieceOnDisk(piece);
|
||||
piece->clearAllBlock();
|
||||
piece->destroyHashContext();
|
||||
|
@ -286,12 +274,11 @@ void BtPieceMessage::onChokingEvent(const BtChokingEvent& event)
|
|||
if(!isInvalidate() &&
|
||||
!isSendingInProgress() &&
|
||||
!getPeer()->isInAmAllowedIndexSet(index_)) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug(MSG_REJECT_PIECE_CHOKED,
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long>(index_),
|
||||
begin_, blockLength_);
|
||||
}
|
||||
A2_LOG_DEBUG(fmt(MSG_REJECT_PIECE_CHOKED,
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long>(index_),
|
||||
begin_,
|
||||
blockLength_));
|
||||
if(getPeer()->isFastExtensionEnabled()) {
|
||||
BtMessageHandle rej =
|
||||
getBtMessageFactory()->createRejectMessage
|
||||
|
@ -310,12 +297,11 @@ void BtPieceMessage::onCancelSendingPieceEvent
|
|||
index_ == event.getIndex() &&
|
||||
begin_ == event.getBegin() &&
|
||||
blockLength_ == event.getLength()) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug(MSG_REJECT_PIECE_CANCEL,
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long>(index_),
|
||||
begin_, blockLength_);
|
||||
}
|
||||
A2_LOG_DEBUG(fmt(MSG_REJECT_PIECE_CANCEL,
|
||||
util::itos(getCuid()).c_str(),
|
||||
static_cast<unsigned long>(index_),
|
||||
begin_,
|
||||
blockLength_));
|
||||
if(getPeer()->isFastExtensionEnabled()) {
|
||||
BtMessageHandle rej =
|
||||
getBtMessageFactory()->createRejectMessage
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "util.h"
|
||||
#include "message.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "Peer.h"
|
||||
#include "DHTNode.h"
|
||||
#include "DHTRoutingTable.h"
|
||||
|
@ -45,19 +46,21 @@
|
|||
#include "DHTTaskFactory.h"
|
||||
#include "DHTTask.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
#include "a2functional.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
const std::string BtPortMessage::NAME("port");
|
||||
|
||||
BtPortMessage::BtPortMessage(uint16_t port):
|
||||
SimpleBtMessage(ID, NAME), port_(port),
|
||||
localNode_(0),
|
||||
routingTable_(0),
|
||||
taskQueue_(0),
|
||||
taskFactory_(0)
|
||||
{}
|
||||
BtPortMessage::BtPortMessage(uint16_t port)
|
||||
: SimpleBtMessage(ID, NAME),
|
||||
port_(port),
|
||||
localNode_(0),
|
||||
routingTable_(0),
|
||||
taskQueue_(0),
|
||||
taskFactory_(0)
|
||||
{}
|
||||
|
||||
SharedHandle<BtPortMessage> BtPortMessage::create
|
||||
(const unsigned char* data, size_t dataLength)
|
||||
|
@ -73,9 +76,7 @@ void BtPortMessage::doReceivedAction()
|
|||
{
|
||||
if(taskFactory_ && taskQueue_) {
|
||||
if(port_ == 0) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("Ignored port 0.");
|
||||
}
|
||||
A2_LOG_DEBUG("Ignored port 0.");
|
||||
return;
|
||||
}
|
||||
// node id is random at this point. When ping reply received, new DHTNode
|
||||
|
@ -89,12 +90,12 @@ void BtPortMessage::doReceivedAction()
|
|||
}
|
||||
if(routingTable_->countBucket() == 1) {
|
||||
// initiate bootstrap
|
||||
getLogger()->info("Dispatch node_lookup since too few buckets.");
|
||||
A2_LOG_INFO("Dispatch node_lookup since too few buckets.");
|
||||
taskQueue_->addImmediateTask
|
||||
(taskFactory_->createNodeLookupTask(localNode_->getID()));
|
||||
}
|
||||
} else {
|
||||
getLogger()->info
|
||||
A2_LOG_INFO
|
||||
("DHT port message received while localhost didn't declare support it.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "RequestGroup.h"
|
||||
#include "Option.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "DownloadHandlerConstants.h"
|
||||
#include "File.h"
|
||||
#include "PieceStorage.h"
|
||||
|
@ -46,6 +47,7 @@
|
|||
#include "Exception.h"
|
||||
#include "DownloadContext.h"
|
||||
#include "download_helper.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -66,8 +68,8 @@ void BtPostDownloadHandler::getNextRequestGroups
|
|||
(std::vector<SharedHandle<RequestGroup> >& groups,
|
||||
RequestGroup* requestGroup)
|
||||
{
|
||||
getLogger()->info("Generating RequestGroups for Torrent file %s",
|
||||
requestGroup->getFirstFilePath().c_str());
|
||||
A2_LOG_INFO(fmt("Generating RequestGroups for Torrent file %s",
|
||||
requestGroup->getFirstFilePath().c_str()));
|
||||
std::string content;
|
||||
try {
|
||||
requestGroup->getPieceStorage()->getDiskAdaptor()->openExistingFile();
|
||||
|
|
|
@ -41,13 +41,14 @@
|
|||
#include "LogFactory.h"
|
||||
#include "SimpleRandomizer.h"
|
||||
#include "wallclock.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
BtSeederStateChoke::BtSeederStateChoke():
|
||||
round_(0),
|
||||
lastRound_(0),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
BtSeederStateChoke::BtSeederStateChoke()
|
||||
: round_(0),
|
||||
lastRound_(0)
|
||||
{}
|
||||
|
||||
BtSeederStateChoke::~BtSeederStateChoke() {}
|
||||
|
||||
|
@ -123,8 +124,9 @@ void BtSeederStateChoke::unchoke
|
|||
for(std::vector<PeerEntry>::iterator eoi = peers.end();
|
||||
r != eoi && count; ++r, --count) {
|
||||
(*r).getPeer()->chokingRequired(false);
|
||||
logger_->info("RU: %s, ulspd=%u", (*r).getPeer()->getIPAddress().c_str(),
|
||||
(*r).getUploadSpeed());
|
||||
A2_LOG_INFO(fmt("RU: %s, ulspd=%u",
|
||||
(*r).getPeer()->getIPAddress().c_str(),
|
||||
(*r).getUploadSpeed()));
|
||||
}
|
||||
|
||||
if(round_ < 2) {
|
||||
|
@ -134,7 +136,7 @@ void BtSeederStateChoke::unchoke
|
|||
std::random_shuffle(r, peers.end(),
|
||||
*(SimpleRandomizer::getInstance().get()));
|
||||
(*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
|
||||
(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;
|
||||
|
||||
std::vector<PeerEntry> peerEntries;
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
namespace aria2 {
|
||||
|
||||
class Peer;
|
||||
class Logger;
|
||||
|
||||
class BtSeederStateChoke {
|
||||
private:
|
||||
|
@ -53,8 +52,6 @@ private:
|
|||
|
||||
Timer lastRound_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
class PeerEntry {
|
||||
private:
|
||||
SharedHandle<Peer> peer_;
|
||||
|
|
|
@ -83,10 +83,11 @@
|
|||
#include "DownloadContext.h"
|
||||
#include "PieceStorage.h"
|
||||
#include "PeerStorage.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
BtSetup::BtSetup():logger_(LogFactory::getInstance()) {}
|
||||
BtSetup::BtSetup() {}
|
||||
|
||||
void BtSetup::setup(std::vector<Command*>& commands,
|
||||
RequestGroup* requestGroup,
|
||||
|
@ -221,7 +222,7 @@ void BtSetup::setup(std::vector<Command*>& commands,
|
|||
if(option->getAsBool(PREF_BT_ENABLE_LPD) &&
|
||||
(metadataGetMode || !torrentAttrs->privateTorrent)) {
|
||||
if(LpdReceiveMessageCommand::getNumInstance() == 0) {
|
||||
logger_->info("Initializing LpdMessageReceiver.");
|
||||
A2_LOG_INFO("Initializing LpdMessageReceiver.");
|
||||
SharedHandle<LpdMessageReceiver> receiver
|
||||
(new LpdMessageReceiver(LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT));
|
||||
bool initialized = false;
|
||||
|
@ -245,15 +246,15 @@ void BtSetup::setup(std::vector<Command*>& commands,
|
|||
}
|
||||
}
|
||||
if(initialized) {
|
||||
logger_->info("LpdMessageReceiver initialized. multicastAddr=%s:%u,"
|
||||
" localAddr=%s",
|
||||
LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT,
|
||||
receiver->getLocalAddress().c_str());
|
||||
A2_LOG_INFO(fmt("LpdMessageReceiver initialized. multicastAddr=%s:%u,"
|
||||
" localAddr=%s",
|
||||
LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT,
|
||||
receiver->getLocalAddress().c_str()));
|
||||
LpdReceiveMessageCommand* cmd =
|
||||
LpdReceiveMessageCommand::getInstance(e, receiver);
|
||||
e->addCommand(cmd);
|
||||
} else {
|
||||
logger_->info("LpdMessageReceiver not initialized.");
|
||||
A2_LOG_INFO("LpdMessageReceiver not initialized.");
|
||||
}
|
||||
}
|
||||
if(LpdReceiveMessageCommand::getNumInstance()) {
|
||||
|
@ -261,20 +262,20 @@ void BtSetup::setup(std::vector<Command*>& commands,
|
|||
bittorrent::getInfoHash(requestGroup->getDownloadContext());
|
||||
SharedHandle<LpdMessageReceiver> receiver =
|
||||
LpdReceiveMessageCommand::getInstance()->getLpdMessageReceiver();
|
||||
logger_->info("Initializing LpdMessageDispatcher.");
|
||||
A2_LOG_INFO("Initializing LpdMessageDispatcher.");
|
||||
SharedHandle<LpdMessageDispatcher> dispatcher
|
||||
(new LpdMessageDispatcher
|
||||
(std::string(&infoHash[0], &infoHash[INFO_HASH_LENGTH]),
|
||||
btRuntime->getListenPort(),
|
||||
LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT));
|
||||
if(dispatcher->init(receiver->getLocalAddress(), /*ttl*/1, /*loop*/0)) {
|
||||
logger_->info("LpdMessageDispatcher initialized.");
|
||||
A2_LOG_INFO("LpdMessageDispatcher initialized.");
|
||||
LpdDispatchMessageCommand* cmd =
|
||||
new LpdDispatchMessageCommand(e->newCUID(), dispatcher, e);
|
||||
cmd->setBtRuntime(btRuntime);
|
||||
e->addCommand(cmd);
|
||||
} else {
|
||||
logger_->info("LpdMessageDispatcher not initialized.");
|
||||
A2_LOG_INFO("LpdMessageDispatcher not initialized.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,15 +40,12 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
class Logger;
|
||||
class RequestGroup;
|
||||
class DownloadEngine;
|
||||
class Option;
|
||||
class Command;
|
||||
|
||||
class BtSetup {
|
||||
private:
|
||||
Logger* logger_;
|
||||
public:
|
||||
BtSetup();
|
||||
|
||||
|
|
|
@ -37,8 +37,10 @@
|
|||
#include "RequestGroup.h"
|
||||
#include "BtRuntime.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "wallclock.h"
|
||||
#include "util.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -46,10 +48,10 @@ BtStopDownloadCommand::BtStopDownloadCommand
|
|||
(cuid_t cuid,
|
||||
RequestGroup* requestGroup,
|
||||
DownloadEngine* e,
|
||||
time_t timeout):
|
||||
TimeBasedCommand(cuid, e, 1),
|
||||
requestGroup_(requestGroup),
|
||||
timeout_(timeout)
|
||||
time_t timeout)
|
||||
: TimeBasedCommand(cuid, e, 1),
|
||||
requestGroup_(requestGroup),
|
||||
timeout_(timeout)
|
||||
{}
|
||||
|
||||
void BtStopDownloadCommand::preProcess()
|
||||
|
@ -58,9 +60,9 @@ void BtStopDownloadCommand::preProcess()
|
|||
enableExit();
|
||||
}
|
||||
if(checkPoint_.difference(global::wallclock) >= timeout_) {
|
||||
getLogger()->notice("GID#%s Stop downloading torrent due to"
|
||||
" --bt-stop-timeout option.",
|
||||
util::itos(requestGroup_->getGID()).c_str());
|
||||
A2_LOG_NOTICE(fmt("GID#%s Stop downloading torrent due to"
|
||||
" --bt-stop-timeout option.",
|
||||
util::itos(requestGroup_->getGID()).c_str()));
|
||||
requestGroup_->setForceHaltRequested(true);
|
||||
enableExit();
|
||||
}
|
||||
|
|
|
@ -37,12 +37,14 @@
|
|||
#include "DownloadEngine.h"
|
||||
#include "RequestGroup.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "message.h"
|
||||
#include "prefs.h"
|
||||
#include "DownloadContext.h"
|
||||
#include "a2functional.h"
|
||||
#include "RecoverableException.h"
|
||||
#include "util.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -69,18 +71,18 @@ bool CheckIntegrityCommand::executeInternal()
|
|||
// needed.
|
||||
getRequestGroup()->enableSaveControlFile();
|
||||
if(getRequestGroup()->downloadFinished()) {
|
||||
getLogger()->notice
|
||||
(MSG_VERIFICATION_SUCCESSFUL,
|
||||
getRequestGroup()->getDownloadContext()->getBasePath().c_str());
|
||||
A2_LOG_NOTICE
|
||||
(fmt(MSG_VERIFICATION_SUCCESSFUL,
|
||||
getRequestGroup()->getDownloadContext()->getBasePath().c_str()));
|
||||
std::vector<Command*>* commands = new std::vector<Command*>();
|
||||
auto_delete_container<std::vector<Command*> > commandsDel(commands);
|
||||
entry_->onDownloadFinished(*commands, getDownloadEngine());
|
||||
getDownloadEngine()->addCommand(*commands);
|
||||
commands->clear();
|
||||
} else {
|
||||
getLogger()->error
|
||||
(MSG_VERIFICATION_FAILED,
|
||||
getRequestGroup()->getDownloadContext()->getBasePath().c_str());
|
||||
A2_LOG_ERROR
|
||||
(fmt(MSG_VERIFICATION_FAILED,
|
||||
getRequestGroup()->getDownloadContext()->getBasePath().c_str()));
|
||||
std::vector<Command*>* commands = new std::vector<Command*>();
|
||||
auto_delete_container<std::vector<Command*> > commandsDel(commands);
|
||||
entry_->onDownloadIncomplete(*commands, getDownloadEngine());
|
||||
|
@ -98,12 +100,13 @@ bool CheckIntegrityCommand::executeInternal()
|
|||
bool CheckIntegrityCommand::handleException(Exception& e)
|
||||
{
|
||||
getDownloadEngine()->getCheckIntegrityMan()->dropPickedEntry();
|
||||
getLogger()->error(MSG_FILE_VALIDATION_FAILURE, e,
|
||||
util::itos(getCuid()).c_str());
|
||||
getLogger()->error
|
||||
(MSG_DOWNLOAD_NOT_COMPLETE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
getRequestGroup()->getDownloadContext()->getBasePath().c_str());
|
||||
A2_LOG_ERROR_EX(fmt(MSG_FILE_VALIDATION_FAILURE,
|
||||
util::itos(getCuid()).c_str()),
|
||||
e);
|
||||
A2_LOG_ERROR
|
||||
(fmt(MSG_DOWNLOAD_NOT_COMPLETE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
getRequestGroup()->getDownloadContext()->getBasePath().c_str()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,15 +37,17 @@
|
|||
#include "CheckIntegrityCommand.h"
|
||||
#include "message.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "util.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
CheckIntegrityDispatcherCommand::CheckIntegrityDispatcherCommand
|
||||
(cuid_t cuid,
|
||||
const SharedHandle<CheckIntegrityMan>& fileAllocMan,
|
||||
DownloadEngine* e):SequentialDispatcherCommand<CheckIntegrityEntry>
|
||||
(cuid, fileAllocMan, e)
|
||||
DownloadEngine* e)
|
||||
: SequentialDispatcherCommand<CheckIntegrityEntry>(cuid, fileAllocMan, e)
|
||||
{
|
||||
setStatusRealtime();
|
||||
}
|
||||
|
@ -54,11 +56,9 @@ Command* CheckIntegrityDispatcherCommand::createCommand
|
|||
(const SharedHandle<CheckIntegrityEntry>& entry)
|
||||
{
|
||||
cuid_t newCUID = getDownloadEngine()->newCUID();
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info("CUID#%s - Dispatching CheckIntegrityCommand CUID#%s.",
|
||||
util::itos(getCuid()).c_str(),
|
||||
util::itos(newCUID).c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt("CUID#%s - Dispatching CheckIntegrityCommand CUID#%s.",
|
||||
util::itos(getCuid()).c_str(),
|
||||
util::itos(newCUID).c_str()));
|
||||
return new CheckIntegrityCommand
|
||||
(newCUID, entry->getRequestGroup(), getDownloadEngine(), entry);
|
||||
}
|
||||
|
|
|
@ -34,17 +34,17 @@
|
|||
/* copyright --> */
|
||||
#include "Command.h"
|
||||
#include "LogFactory.h"
|
||||
#include "Logger.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
Command::Command(cuid_t cuid):status_(STATUS_INACTIVE),
|
||||
cuid_(cuid),
|
||||
logger_(LogFactory::getInstance()),
|
||||
readEvent_(false),
|
||||
writeEvent_(false),
|
||||
errorEvent_(false),
|
||||
hupEvent_(false) {}
|
||||
Command::Command(cuid_t cuid)
|
||||
: status_(STATUS_INACTIVE),
|
||||
cuid_(cuid),
|
||||
readEvent_(false),
|
||||
writeEvent_(false),
|
||||
errorEvent_(false),
|
||||
hupEvent_(false)
|
||||
{}
|
||||
|
||||
void Command::transitStatus()
|
||||
{
|
||||
|
|
|
@ -39,8 +39,6 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
class Logger;
|
||||
|
||||
typedef int64_t cuid_t;
|
||||
|
||||
class Command {
|
||||
|
@ -56,18 +54,12 @@ private:
|
|||
STATUS status_;
|
||||
|
||||
cuid_t cuid_;
|
||||
Logger* logger_;
|
||||
|
||||
bool readEvent_;
|
||||
bool writeEvent_;
|
||||
bool errorEvent_;
|
||||
bool hupEvent_;
|
||||
protected:
|
||||
Logger* getLogger() const
|
||||
{
|
||||
return logger_;
|
||||
}
|
||||
|
||||
bool readEventEnabled() const
|
||||
{
|
||||
return readEvent_;
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "Logger.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
#include "NsCookieParser.h"
|
||||
#include "File.h"
|
||||
#include "a2functional.h"
|
||||
|
@ -139,7 +140,7 @@ bool CookieStorage::DomainEntry::operator<(const DomainEntry& de) const
|
|||
return key_ < de.key_;
|
||||
}
|
||||
|
||||
CookieStorage::CookieStorage():logger_(LogFactory::getInstance()) {}
|
||||
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
|
||||
std::ifstream s(filename.c_str(), std::ios::binary);
|
||||
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;
|
||||
}
|
||||
s.get(header, sizeof(header));
|
||||
if(!s) {
|
||||
logger_->error("Failed to read header of cookie file %s",
|
||||
filename.c_str());
|
||||
A2_LOG_ERROR(fmt("Failed to read header of cookie file %s",
|
||||
filename.c_str()));
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
|
@ -342,11 +343,9 @@ bool CookieStorage::load(const std::string& filename, time_t now)
|
|||
try {
|
||||
Sqlite3MozCookieParser(filename).parse(cookies);
|
||||
} catch(RecoverableException& e) {
|
||||
if(logger_->info()) {
|
||||
logger_->info(EX_EXCEPTION_CAUGHT, e);
|
||||
logger_->info("This does not look like Firefox3 cookie file."
|
||||
" Retrying, assuming it is Chromium cookie file.");
|
||||
}
|
||||
A2_LOG_INFO_EX(EX_EXCEPTION_CAUGHT, e);
|
||||
A2_LOG_INFO("This does not look like Firefox3 cookie file."
|
||||
" Retrying, assuming it is Chromium cookie file.");
|
||||
// Try chrome cookie format
|
||||
Sqlite3ChromiumCookieParser(filename).parse(cookies);
|
||||
}
|
||||
|
@ -362,7 +361,7 @@ bool CookieStorage::load(const std::string& filename, time_t now)
|
|||
}
|
||||
return true;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
@ -373,7 +372,7 @@ bool CookieStorage::saveNsFormat(const std::string& filename)
|
|||
{
|
||||
std::ofstream o(tempfilename.c_str(), std::ios::binary);
|
||||
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;
|
||||
}
|
||||
for(std::deque<DomainEntry>::const_iterator i = domains_.begin(),
|
||||
|
@ -382,15 +381,16 @@ bool CookieStorage::saveNsFormat(const std::string& filename)
|
|||
}
|
||||
o.flush();
|
||||
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;
|
||||
}
|
||||
}
|
||||
if(File(tempfilename).renameTo(filename)) {
|
||||
return true;
|
||||
} else {
|
||||
logger_->error("Could not rename file %s as %s",
|
||||
tempfilename.c_str(), filename.c_str());
|
||||
A2_LOG_ERROR(fmt("Could not rename file %s as %s",
|
||||
tempfilename.c_str(),
|
||||
filename.c_str()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,8 +47,6 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
class Logger;
|
||||
|
||||
class CookieStorage {
|
||||
public:
|
||||
|
||||
|
@ -122,8 +120,6 @@ public:
|
|||
private:
|
||||
std::deque<DomainEntry> domains_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
template<typename InputIterator>
|
||||
void storeCookies(InputIterator first, InputIterator last, time_t now)
|
||||
{
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include "util.h"
|
||||
#include "DHTIDCloser.h"
|
||||
#include "a2functional.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -102,19 +103,15 @@ private:
|
|||
sendMessage();
|
||||
}
|
||||
if(inFlightMessage_ == 0) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("Finished node_lookup for node ID %s",
|
||||
util::toHex(targetID_, DHT_ID_LENGTH).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Finished node_lookup for node ID %s",
|
||||
util::toHex(targetID_, DHT_ID_LENGTH).c_str()));
|
||||
onFinish();
|
||||
updateBucket();
|
||||
setFinished(true);
|
||||
} else {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("%lu in flight message for node ID %s",
|
||||
static_cast<unsigned long>(inFlightMessage_),
|
||||
util::toHex(targetID_, DHT_ID_LENGTH).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("%lu in flight message for node ID %s",
|
||||
static_cast<unsigned long>(inFlightMessage_),
|
||||
util::toHex(targetID_, DHT_ID_LENGTH).c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,9 +164,7 @@ public:
|
|||
inFlightMessage_ = 0;
|
||||
sendMessage();
|
||||
if(inFlightMessage_ == 0) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("No message was sent in this lookup stage. Finished.");
|
||||
}
|
||||
A2_LOG_DEBUG("No message was sent in this lookup stage. Finished.");
|
||||
setFinished(true);
|
||||
}
|
||||
}
|
||||
|
@ -191,27 +186,21 @@ public:
|
|||
DHT_ID_LENGTH) != 0) {
|
||||
entries_.push_front(*i);
|
||||
++count;
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("Received nodes: id=%s, ip=%s",
|
||||
util::toHex((*i)->node->getID(),
|
||||
DHT_ID_LENGTH).c_str(),
|
||||
(*i)->node->getIPAddress().c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Received nodes: id=%s, ip=%s",
|
||||
util::toHex((*i)->node->getID(),
|
||||
DHT_ID_LENGTH).c_str(),
|
||||
(*i)->node->getIPAddress().c_str()));
|
||||
}
|
||||
}
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("%lu node lookup entries added.",
|
||||
static_cast<unsigned long>(count));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("%lu node lookup entries added.",
|
||||
static_cast<unsigned long>(count)));
|
||||
std::stable_sort(entries_.begin(), entries_.end(), DHTIDCloser(targetID_));
|
||||
entries_.erase
|
||||
(std::unique(entries_.begin(), entries_.end(),
|
||||
DerefEqualTo<SharedHandle<DHTNodeLookupEntry> >()),
|
||||
entries_.end());
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("%lu node lookup entries are unique.",
|
||||
static_cast<unsigned long>(entries_.size()));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("%lu node lookup entries are unique.",
|
||||
static_cast<unsigned long>(entries_.size())));
|
||||
if(entries_.size() > DHTBucket::K) {
|
||||
entries_.erase(entries_.begin()+DHTBucket::K, entries_.end());
|
||||
}
|
||||
|
@ -220,10 +209,8 @@ public:
|
|||
|
||||
void onTimeout(const SharedHandle<DHTNode>& node)
|
||||
{
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("node lookup message timeout for node ID=%s",
|
||||
util::toHex(node->getID(), DHT_ID_LENGTH).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("node lookup message timeout for node ID=%s",
|
||||
util::toHex(node->getID(), DHT_ID_LENGTH).c_str()));
|
||||
--inFlightMessage_;
|
||||
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::iterator i =
|
||||
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
|
||||
|
|
|
@ -41,14 +41,12 @@
|
|||
#include "DHTMessageCallback.h"
|
||||
#include "DHTBucket.h"
|
||||
#include "DHTTaskQueue.h"
|
||||
#include "LogFactory.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTAbstractTask::DHTAbstractTask():
|
||||
finished_(false),
|
||||
logger_(LogFactory::getInstance()),
|
||||
routingTable_(0),
|
||||
dispatcher_(0),
|
||||
factory_(0),
|
||||
|
|
|
@ -48,14 +48,10 @@ class DHTMessageFactory;
|
|||
class DHTMessage;
|
||||
class DHTTaskQueue;
|
||||
|
||||
class Logger;
|
||||
|
||||
class DHTAbstractTask:public DHTTask {
|
||||
private:
|
||||
bool finished_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
SharedHandle<DHTNode> localNode_;
|
||||
|
||||
DHTRoutingTable* routingTable_;
|
||||
|
@ -70,11 +66,6 @@ protected:
|
|||
{
|
||||
finished_ = f;
|
||||
}
|
||||
|
||||
Logger* getLogger() const
|
||||
{
|
||||
return logger_;
|
||||
}
|
||||
public:
|
||||
DHTAbstractTask();
|
||||
|
||||
|
|
|
@ -49,17 +49,20 @@
|
|||
#include "Option.h"
|
||||
#include "message.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "a2functional.h"
|
||||
#include "FileEntry.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTAutoSaveCommand::DHTAutoSaveCommand
|
||||
(cuid_t cuid, DownloadEngine* e, int family, time_t interval):
|
||||
TimeBasedCommand(cuid, e, interval),
|
||||
family_(family) {}
|
||||
(cuid_t cuid, DownloadEngine* e, int family, time_t interval)
|
||||
: TimeBasedCommand(cuid, e, interval),
|
||||
family_(family)
|
||||
{}
|
||||
|
||||
DHTAutoSaveCommand::~DHTAutoSaveCommand() {}
|
||||
|
||||
|
@ -82,7 +85,7 @@ void DHTAutoSaveCommand::save()
|
|||
std::string dhtFile =
|
||||
getDownloadEngine()->getOption()->
|
||||
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");
|
||||
// Removing tempFile is unnecessary because the file is truncated on
|
||||
|
@ -118,12 +121,13 @@ void DHTAutoSaveCommand::save()
|
|||
serializer.serialize(o);
|
||||
}
|
||||
if(!tempFile.renameTo(dhtFile)) {
|
||||
getLogger()->error("Cannot move file from %s to %s.",
|
||||
tempFile.getPath().c_str(), dhtFile.c_str());
|
||||
A2_LOG_ERROR(fmt("Cannot move file from %s to %s.",
|
||||
tempFile.getPath().c_str(), dhtFile.c_str()));
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
getLogger()->error("Exception caught while saving DHT routing table to %s",
|
||||
e, dhtFile.c_str());
|
||||
A2_LOG_ERROR_EX(fmt("Exception caught while saving DHT routing table to %s",
|
||||
dhtFile.c_str()),
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,26 +47,26 @@
|
|||
#include "bittorrent_helper.h"
|
||||
#include "bitfield.h"
|
||||
#include "wallclock.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTBucket::DHTBucket(size_t prefixLength,
|
||||
const unsigned char* max, const unsigned char* min,
|
||||
const SharedHandle<DHTNode>& localNode):
|
||||
prefixLength_(prefixLength),
|
||||
localNode_(localNode),
|
||||
lastUpdated_(global::wallclock),
|
||||
logger_(LogFactory::getInstance())
|
||||
DHTBucket::DHTBucket
|
||||
(size_t prefixLength,
|
||||
const unsigned char* max, const unsigned char* min,
|
||||
const SharedHandle<DHTNode>& localNode)
|
||||
: prefixLength_(prefixLength),
|
||||
localNode_(localNode),
|
||||
lastUpdated_(global::wallclock)
|
||||
{
|
||||
memcpy(max_, max, DHT_ID_LENGTH);
|
||||
memcpy(min_, min, DHT_ID_LENGTH);
|
||||
}
|
||||
|
||||
DHTBucket::DHTBucket(const SharedHandle<DHTNode>& localNode):
|
||||
prefixLength_(0),
|
||||
localNode_(localNode),
|
||||
lastUpdated_(global::wallclock),
|
||||
logger_(LogFactory::getInstance())
|
||||
DHTBucket::DHTBucket(const SharedHandle<DHTNode>& localNode)
|
||||
: prefixLength_(0),
|
||||
localNode_(localNode),
|
||||
lastUpdated_(global::wallclock)
|
||||
{
|
||||
memset(max_, 0xffu, DHT_ID_LENGTH);
|
||||
memset(min_, 0, DHT_ID_LENGTH);
|
||||
|
@ -206,16 +206,14 @@ SharedHandle<DHTBucket> DHTBucket::split()
|
|||
}
|
||||
nodes_ = lNodes;
|
||||
// TODO create toString() and use it.
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("New bucket. prefixLength=%u, Range:%s-%s",
|
||||
A2_LOG_DEBUG(fmt("New bucket. prefixLength=%u, Range:%s-%s",
|
||||
static_cast<unsigned int>(rBucket->getPrefixLength()),
|
||||
util::toHex(rBucket->getMinID(), DHT_ID_LENGTH).c_str(),
|
||||
util::toHex(rBucket->getMaxID(), DHT_ID_LENGTH).c_str());
|
||||
logger_->debug("Existing bucket. prefixLength=%u, Range:%s-%s",
|
||||
util::toHex(rBucket->getMaxID(), DHT_ID_LENGTH).c_str()));
|
||||
A2_LOG_DEBUG(fmt("Existing bucket. prefixLength=%u, Range:%s-%s",
|
||||
static_cast<unsigned int>(prefixLength_),
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
namespace aria2 {
|
||||
|
||||
class DHTNode;
|
||||
class Logger;
|
||||
|
||||
class DHTBucket {
|
||||
private:
|
||||
|
@ -70,8 +69,6 @@ private:
|
|||
|
||||
Timer lastUpdated_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
bool isInRange(const unsigned char* nodeID,
|
||||
const unsigned char* max, const unsigned char* min) const;
|
||||
public:
|
||||
|
|
|
@ -41,7 +41,9 @@
|
|||
#include "DHTNodeLookupEntry.h"
|
||||
#include "util.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "DHTMessageCallback.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -67,8 +69,8 @@ void DHTBucketRefreshTask::startup()
|
|||
task->setTaskQueue(getTaskQueue());
|
||||
task->setLocalNode(getLocalNode());
|
||||
|
||||
getLogger()->info("Dispating bucket refresh. targetID=%s",
|
||||
util::toHex(targetID, DHT_ID_LENGTH).c_str());
|
||||
A2_LOG_INFO(fmt("Dispating bucket refresh. targetID=%s",
|
||||
util::toHex(targetID, DHT_ID_LENGTH).c_str()));
|
||||
getTaskQueue()->addPeriodicTask1(task);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,13 +43,14 @@
|
|||
#include "util.h"
|
||||
#include "Socket.h"
|
||||
#include "SimpleRandomizer.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTConnectionImpl::DHTConnectionImpl(int family):
|
||||
socket_(new SocketCore(SOCK_DGRAM)),
|
||||
family_(family),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
DHTConnectionImpl::DHTConnectionImpl(int family)
|
||||
: socket_(new SocketCore(SOCK_DGRAM)),
|
||||
family_(family)
|
||||
{}
|
||||
|
||||
DHTConnectionImpl::~DHTConnectionImpl() {}
|
||||
|
||||
|
@ -86,10 +87,11 @@ bool DHTConnectionImpl::bind(uint16_t& port, const std::string& addr)
|
|||
std::pair<std::string, uint16_t> svaddr;
|
||||
socket_->getAddrInfo(svaddr);
|
||||
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;
|
||||
} 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;
|
||||
}
|
||||
|
|
|
@ -42,15 +42,12 @@
|
|||
namespace aria2 {
|
||||
|
||||
class SocketCore;
|
||||
class Logger;
|
||||
|
||||
class DHTConnectionImpl:public DHTConnection {
|
||||
private:
|
||||
SharedHandle<SocketCore> socket_;
|
||||
|
||||
int family_;
|
||||
|
||||
Logger* logger_;
|
||||
public:
|
||||
DHTConnectionImpl(int family);
|
||||
|
||||
|
|
|
@ -47,7 +47,9 @@
|
|||
#include "DHTTask.h"
|
||||
#include "RequestGroupMan.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
#ifdef ENABLE_ASYNC_DNS
|
||||
#include "AsyncNameResolver.h"
|
||||
#endif // ENABLE_ASYNC_DNS
|
||||
|
@ -108,7 +110,7 @@ bool DHTEntryPointNameResolveCommand::execute()
|
|||
return false;
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, e);
|
||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
resolver_->reset();
|
||||
entryPoints_.pop_front();
|
||||
|
@ -129,7 +131,7 @@ bool DHTEntryPointNameResolveCommand::execute()
|
|||
resolvedEntryPoints_.push_back(p);
|
||||
addPingTask(p);
|
||||
} catch(RecoverableException& e) {
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, e);
|
||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
entryPoints_.pop_front();
|
||||
}
|
||||
|
@ -140,7 +142,7 @@ bool DHTEntryPointNameResolveCommand::execute()
|
|||
taskQueue_->addPeriodicTask1(taskFactory_->createBucketRefreshTask());
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, e);
|
||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -163,20 +165,17 @@ bool DHTEntryPointNameResolveCommand::resolveHostname
|
|||
{
|
||||
switch(resolver->getStatus()) {
|
||||
case AsyncNameResolver::STATUS_READY:
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_RESOLVING_HOSTNAME,
|
||||
util::itos(getCuid()).c_str(), hostname.c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_RESOLVING_HOSTNAME,
|
||||
util::itos(getCuid()).c_str(),
|
||||
hostname.c_str()));
|
||||
resolver->resolve(hostname);
|
||||
setNameResolverCheck(resolver);
|
||||
return false;
|
||||
case AsyncNameResolver::STATUS_SUCCESS:
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_NAME_RESOLUTION_COMPLETE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
resolver->getHostname().c_str(),
|
||||
resolver->getResolvedAddresses().front().c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_NAME_RESOLUTION_COMPLETE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
resolver->getHostname().c_str(),
|
||||
resolver->getResolvedAddresses().front().c_str()));
|
||||
return true;
|
||||
break;
|
||||
case AsyncNameResolver::STATUS_ERROR:
|
||||
|
|
|
@ -44,20 +44,23 @@
|
|||
#include "PeerStorage.h"
|
||||
#include "Peer.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "bittorrent_helper.h"
|
||||
#include "DownloadContext.h"
|
||||
#include "wallclock.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTGetPeersCommand::DHTGetPeersCommand(cuid_t cuid,
|
||||
RequestGroup* requestGroup,
|
||||
DownloadEngine* e):
|
||||
Command(cuid),
|
||||
requestGroup_(requestGroup),
|
||||
e_(e),
|
||||
numRetry_(0),
|
||||
lastGetPeerTime_(0)
|
||||
DHTGetPeersCommand::DHTGetPeersCommand
|
||||
(cuid_t cuid,
|
||||
RequestGroup* requestGroup,
|
||||
DownloadEngine* e)
|
||||
: Command(cuid),
|
||||
requestGroup_(requestGroup),
|
||||
e_(e),
|
||||
numRetry_(0),
|
||||
lastGetPeerTime_(0)
|
||||
{
|
||||
requestGroup_->increaseNumCommand();
|
||||
}
|
||||
|
@ -79,11 +82,9 @@ bool DHTGetPeersCommand::execute()
|
|||
(btRuntime_->lessThanMinPeers() &&
|
||||
lastGetPeerTime_.difference(global::wallclock) >= GET_PEER_MIN_INTERVAL
|
||||
&& !requestGroup_->downloadFinished()))) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("Issuing PeerLookup for infoHash=%s",
|
||||
bittorrent::getInfoHashString
|
||||
(requestGroup_->getDownloadContext()).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Issuing PeerLookup for infoHash=%s",
|
||||
bittorrent::getInfoHashString
|
||||
(requestGroup_->getDownloadContext()).c_str()));
|
||||
task_ = taskFactory_->createPeerLookupTask
|
||||
(requestGroup_->getDownloadContext(), btRuntime_, peerStorage_);
|
||||
taskQueue_->addPeriodicTask2(task_);
|
||||
|
|
|
@ -43,14 +43,17 @@
|
|||
#include "message.h"
|
||||
#include "RequestGroupMan.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "DHTMessageCallback.h"
|
||||
#include "DHTNode.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTInteractionCommand::DHTInteractionCommand(cuid_t cuid, DownloadEngine* e):
|
||||
Command(cuid),
|
||||
e_(e) {}
|
||||
DHTInteractionCommand::DHTInteractionCommand(cuid_t cuid, DownloadEngine* e)
|
||||
: Command(cuid),
|
||||
e_(e)
|
||||
{}
|
||||
|
||||
DHTInteractionCommand::~DHTInteractionCommand()
|
||||
{
|
||||
|
@ -86,7 +89,7 @@ bool DHTInteractionCommand::execute()
|
|||
try {
|
||||
dispatcher_->sendMessages();
|
||||
} catch(RecoverableException& e) {
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, e);
|
||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
e_->addCommand(this);
|
||||
return false;
|
||||
|
|
|
@ -42,15 +42,16 @@
|
|||
#include "Logger.h"
|
||||
#include "DHTConstants.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
#include "DHTNode.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTMessageDispatcherImpl::DHTMessageDispatcherImpl
|
||||
(const SharedHandle<DHTMessageTracker>& tracker):
|
||||
tracker_(tracker),
|
||||
timeout_(DHT_MESSAGE_TIMEOUT),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
(const SharedHandle<DHTMessageTracker>& tracker)
|
||||
: tracker_(tracker),
|
||||
timeout_(DHT_MESSAGE_TIMEOUT)
|
||||
{}
|
||||
|
||||
DHTMessageDispatcherImpl::~DHTMessageDispatcherImpl() {}
|
||||
|
||||
|
@ -82,15 +83,14 @@ DHTMessageDispatcherImpl::sendMessage
|
|||
if(!entry->message->isReply()) {
|
||||
tracker_->addMessage(entry->message, entry->timeout, entry->callback);
|
||||
}
|
||||
if(logger_->info()) {
|
||||
logger_->info("Message sent: %s", entry->message->toString().c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt("Message sent: %s", entry->message->toString().c_str()));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
logger_->info("Failed to send message: %s",
|
||||
e, entry->message->toString().c_str());
|
||||
A2_LOG_INFO_EX(fmt("Failed to send message: %s",
|
||||
entry->message->toString().c_str()),
|
||||
e);
|
||||
// Add message to DHTMessageTracker with timeout 0 to treat it as
|
||||
// time out. Without this, we have untracked message and some of
|
||||
// DHTTask(such as DHTAbstractNodeLookupTask) don't finish
|
||||
|
@ -114,10 +114,8 @@ void DHTMessageDispatcherImpl::sendMessages()
|
|||
}
|
||||
}
|
||||
messageQueue_.erase(messageQueue_.begin(), itr);
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("%lu dht messages remaining in the queue.",
|
||||
static_cast<unsigned long>(messageQueue_.size()));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("%lu dht messages remaining in the queue.",
|
||||
static_cast<unsigned long>(messageQueue_.size())));
|
||||
}
|
||||
|
||||
size_t DHTMessageDispatcherImpl::countMessageInQueue() const
|
||||
|
|
|
@ -42,7 +42,6 @@ namespace aria2 {
|
|||
|
||||
class DHTMessageTracker;
|
||||
struct DHTMessageEntry;
|
||||
class Logger;
|
||||
|
||||
class DHTMessageDispatcherImpl:public DHTMessageDispatcher {
|
||||
private:
|
||||
|
@ -52,8 +51,6 @@ private:
|
|||
|
||||
time_t timeout_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
bool sendMessage(const SharedHandle<DHTMessageEntry>& msg);
|
||||
public:
|
||||
DHTMessageDispatcherImpl(const SharedHandle<DHTMessageTracker>& tracker);
|
||||
|
|
|
@ -61,17 +61,18 @@
|
|||
#include "Peer.h"
|
||||
#include "Logger.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTMessageFactoryImpl::DHTMessageFactoryImpl(int family):
|
||||
family_(family),
|
||||
connection_(0),
|
||||
dispatcher_(0),
|
||||
routingTable_(0),
|
||||
peerAnnounceStorage_(0),
|
||||
tokenTracker_(0),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
DHTMessageFactoryImpl::DHTMessageFactoryImpl(int family)
|
||||
: family_(family),
|
||||
connection_(0),
|
||||
dispatcher_(0),
|
||||
routingTable_(0),
|
||||
peerAnnounceStorage_(0),
|
||||
tokenTracker_(0)
|
||||
{}
|
||||
|
||||
DHTMessageFactoryImpl::~DHTMessageFactoryImpl() {}
|
||||
|
||||
|
@ -256,15 +257,11 @@ DHTMessageFactoryImpl::createResponseMessage
|
|||
// for now, just report error message arrived and throw exception.
|
||||
const List* e = getList(dict, DHTUnknownMessage::E);
|
||||
if(e->size() == 2) {
|
||||
if(logger_->info()) {
|
||||
logger_->info("Received Error DHT message. code=%s, msg=%s",
|
||||
A2_LOG_INFO(fmt("Received Error DHT message. code=%s, msg=%s",
|
||||
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 {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("e doesn't have 2 elements.");
|
||||
}
|
||||
A2_LOG_DEBUG("e doesn't have 2 elements.");
|
||||
}
|
||||
throw DL_ABORT_EX("Received Error DHT message.");
|
||||
} else if(y->s() != DHTResponseMessage::R) {
|
||||
|
|
|
@ -45,7 +45,6 @@ class DHTMessageDispatcher;
|
|||
class DHTRoutingTable;
|
||||
class DHTPeerAnnounceStorage;
|
||||
class DHTTokenTracker;
|
||||
class Logger;
|
||||
class DHTMessage;
|
||||
class DHTAbstractMessage;
|
||||
|
||||
|
@ -64,8 +63,6 @@ private:
|
|||
DHTPeerAnnounceStorage* peerAnnounceStorage_;
|
||||
|
||||
DHTTokenTracker* tokenTracker_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
// search node in routingTable. If it is not found, create new one.
|
||||
SharedHandle<DHTNode> getRemoteNode
|
||||
|
|
|
@ -52,12 +52,13 @@
|
|||
#include "Logger.h"
|
||||
#include "util.h"
|
||||
#include "bencode2.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTMessageReceiver::DHTMessageReceiver(const SharedHandle<DHTMessageTracker>& tracker):
|
||||
tracker_(tracker),
|
||||
logger_(LogFactory::getInstance())
|
||||
DHTMessageReceiver::DHTMessageReceiver
|
||||
(const SharedHandle<DHTMessageTracker>& tracker)
|
||||
: tracker_(tracker)
|
||||
{}
|
||||
|
||||
DHTMessageReceiver::~DHTMessageReceiver() {}
|
||||
|
@ -84,13 +85,14 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
|
|||
isReply = true;
|
||||
}
|
||||
} else {
|
||||
logger_->info("Malformed DHT message. Missing 'y' key. From:%s:%u",
|
||||
remoteAddr.c_str(), remotePort);
|
||||
A2_LOG_INFO(fmt("Malformed DHT message. Missing 'y' key. From:%s:%u",
|
||||
remoteAddr.c_str(), remotePort));
|
||||
return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort);
|
||||
}
|
||||
} else {
|
||||
logger_->info("Malformed DHT message. This is not a bencoded directory."
|
||||
" From:%s:%u", remoteAddr.c_str(), remotePort);
|
||||
A2_LOG_INFO(fmt("Malformed DHT message. This is not a bencoded directory."
|
||||
" From:%s:%u",
|
||||
remoteAddr.c_str(), remotePort));
|
||||
return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort);
|
||||
}
|
||||
if(isReply) {
|
||||
|
@ -111,14 +113,14 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
|
|||
factory_->createQueryMessage(dict, remoteAddr, remotePort);
|
||||
if(*message->getLocalNode() == *message->getRemoteNode()) {
|
||||
// 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);
|
||||
}
|
||||
onMessageReceived(message);
|
||||
return message;
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
@ -126,9 +128,7 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
|
|||
void DHTMessageReceiver::onMessageReceived
|
||||
(const SharedHandle<DHTMessage>& message)
|
||||
{
|
||||
if(logger_->info()) {
|
||||
logger_->info("Message received: %s", message->toString().c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt("Message received: %s", message->toString().c_str()));
|
||||
message->validate();
|
||||
message->doReceivedAction();
|
||||
message->getRemoteNode()->markGood();
|
||||
|
@ -149,9 +149,7 @@ DHTMessageReceiver::handleUnknownMessage(const unsigned char* data,
|
|||
{
|
||||
SharedHandle<DHTMessage> m =
|
||||
factory_->createUnknownMessage(data, length, remoteAddr, remotePort);
|
||||
if(logger_->info()) {
|
||||
logger_->info("Message received: %s", m->toString().c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt("Message received: %s", m->toString().c_str()));
|
||||
return m;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,8 +46,6 @@ class DHTConnection;
|
|||
class DHTMessageFactory;
|
||||
class DHTRoutingTable;
|
||||
|
||||
class Logger;
|
||||
|
||||
class DHTMessageReceiver {
|
||||
private:
|
||||
SharedHandle<DHTMessageTracker> tracker_;
|
||||
|
@ -58,8 +56,6 @@ private:
|
|||
|
||||
SharedHandle<DHTRoutingTable> routingTable_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
SharedHandle<DHTMessage>
|
||||
handleUnknownMessage(const unsigned char* data, size_t length,
|
||||
const std::string& remoteAddr, uint16_t remotePort);
|
||||
|
|
|
@ -48,11 +48,11 @@
|
|||
#include "DlAbortEx.h"
|
||||
#include "DHTConstants.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
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",
|
||||
ipaddr.c_str(), port).str());
|
||||
}
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Searching tracker entry for TransactionID=%s, Remote=%s:%u",
|
||||
util::toHex(tid->s()).c_str(), ipaddr.c_str(), port);
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Searching tracker entry for TransactionID=%s, Remote=%s:%u",
|
||||
util::toHex(tid->s()).c_str(),
|
||||
ipaddr.c_str(), port));
|
||||
for(std::deque<SharedHandle<DHTMessageTrackerEntry> >::iterator i =
|
||||
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
|
||||
if((*i)->match(tid->s(), ipaddr, port)) {
|
||||
SharedHandle<DHTMessageTrackerEntry> entry = *i;
|
||||
entries_.erase(i);
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Tracker entry found.");
|
||||
}
|
||||
A2_LOG_DEBUG("Tracker entry found.");
|
||||
SharedHandle<DHTNode> targetNode = entry->getTargetNode();
|
||||
try {
|
||||
SharedHandle<DHTResponseMessage> message =
|
||||
|
@ -91,9 +88,7 @@ DHTMessageTracker::messageArrived
|
|||
targetNode->getPort());
|
||||
|
||||
int64_t rtt = entry->getElapsedMillis();
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("RTT is %s", util::itos(rtt).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("RTT is %s", util::itos(rtt).c_str()));
|
||||
message->getRemoteNode()->updateRTT(rtt);
|
||||
SharedHandle<DHTMessageCallback> callback = entry->getCallback();
|
||||
return std::make_pair(message, callback);
|
||||
|
@ -103,9 +98,7 @@ DHTMessageTracker::messageArrived
|
|||
}
|
||||
}
|
||||
}
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Tracker entry not found.");
|
||||
}
|
||||
A2_LOG_DEBUG("Tracker entry not found.");
|
||||
return std::pair<SharedHandle<DHTResponseMessage>,
|
||||
SharedHandle<DHTMessageCallback> >();
|
||||
}
|
||||
|
@ -115,17 +108,13 @@ void DHTMessageTracker::handleTimeoutEntry
|
|||
{
|
||||
try {
|
||||
SharedHandle<DHTNode> node = entry->getTargetNode();
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Message timeout: To:%s:%u",
|
||||
node->getIPAddress().c_str(), node->getPort());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Message timeout: To:%s:%u",
|
||||
node->getIPAddress().c_str(), node->getPort()));
|
||||
node->updateRTT(entry->getElapsedMillis());
|
||||
node->timeout();
|
||||
if(node->isBad()) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Marked bad: %s:%u",
|
||||
node->getIPAddress().c_str(), node->getPort());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Marked bad: %s:%u",
|
||||
node->getIPAddress().c_str(), node->getPort()));
|
||||
routingTable_->dropNode(node);
|
||||
}
|
||||
SharedHandle<DHTMessageCallback> callback = entry->getCallback();
|
||||
|
@ -133,7 +122,7 @@ void DHTMessageTracker::handleTimeoutEntry
|
|||
callback->onTimeout(node);
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
logger_->info("Exception thrown while handling timeouts.", e);
|
||||
A2_LOG_INFO_EX("Exception thrown while handling timeouts.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,6 @@ class DHTMessageCallback;
|
|||
class DHTRoutingTable;
|
||||
class DHTMessageFactory;
|
||||
class DHTMessageTrackerEntry;
|
||||
class Logger;
|
||||
|
||||
class DHTMessageTracker {
|
||||
private:
|
||||
|
@ -62,8 +61,6 @@ private:
|
|||
|
||||
SharedHandle<DHTMessageFactory> factory_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
void handleTimeoutEntry(const SharedHandle<DHTMessageTrackerEntry>& entry);
|
||||
public:
|
||||
DHTMessageTracker();
|
||||
|
|
|
@ -39,12 +39,14 @@
|
|||
#include "RecoverableException.h"
|
||||
#include "message.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTPeerAnnounceCommand::DHTPeerAnnounceCommand
|
||||
(cuid_t cuid, DownloadEngine* e, time_t interval):
|
||||
TimeBasedCommand(cuid, e, interval) {}
|
||||
(cuid_t cuid, DownloadEngine* e, time_t interval)
|
||||
: TimeBasedCommand(cuid, e, interval)
|
||||
{}
|
||||
|
||||
DHTPeerAnnounceCommand::~DHTPeerAnnounceCommand() {}
|
||||
|
||||
|
@ -61,7 +63,7 @@ void DHTPeerAnnounceCommand::process()
|
|||
try {
|
||||
peerAnnounceStorage_->handleTimeout();
|
||||
} catch(RecoverableException& e) {
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, e);
|
||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,11 +48,11 @@
|
|||
#include "util.h"
|
||||
#include "a2functional.h"
|
||||
#include "wallclock.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTPeerAnnounceStorage::DHTPeerAnnounceStorage():
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
DHTPeerAnnounceStorage::DHTPeerAnnounceStorage() {}
|
||||
|
||||
DHTPeerAnnounceStorage::~DHTPeerAnnounceStorage() {}
|
||||
|
||||
|
@ -89,11 +89,9 @@ void
|
|||
DHTPeerAnnounceStorage::addPeerAnnounce(const unsigned char* infoHash,
|
||||
const std::string& ipaddr, uint16_t port)
|
||||
{
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Adding %s:%u to peer announce list: infoHash=%s",
|
||||
A2_LOG_DEBUG(fmt("Adding %s:%u to peer announce list: infoHash=%s",
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -131,25 +129,19 @@ public:
|
|||
|
||||
void DHTPeerAnnounceStorage::handleTimeout()
|
||||
{
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Now purge peer announces(%lu entries) which are timed out.",
|
||||
static_cast<unsigned long>(entries_.size()));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Now purge peer announces(%lu entries) which are timed out.",
|
||||
static_cast<unsigned long>(entries_.size())));
|
||||
std::for_each(entries_.begin(), entries_.end(), RemoveStalePeerAddrEntry());
|
||||
entries_.erase(std::remove_if(entries_.begin(), entries_.end(),
|
||||
mem_fun_sh(&DHTPeerAnnounceEntry::empty)),
|
||||
entries_.end());
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Currently %lu peer announce entries",
|
||||
static_cast<unsigned long>(entries_.size()));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Currently %lu peer announce entries",
|
||||
static_cast<unsigned long>(entries_.size())));
|
||||
}
|
||||
|
||||
void DHTPeerAnnounceStorage::announcePeer()
|
||||
{
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Now announcing peer.");
|
||||
}
|
||||
A2_LOG_DEBUG("Now announcing peer.");
|
||||
for(std::deque<SharedHandle<DHTPeerAnnounceEntry> >::iterator i =
|
||||
entries_.begin(), eoi = entries_.end(); i != eoi; ++i) {
|
||||
if((*i)->getLastUpdated().
|
||||
|
@ -158,10 +150,9 @@ void DHTPeerAnnounceStorage::announcePeer()
|
|||
SharedHandle<DHTTask> task =
|
||||
taskFactory_->createPeerAnnounceTask((*i)->getInfoHash());
|
||||
taskQueue_->addPeriodicTask2(task);
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Added 1 peer announce: infoHash=%s",
|
||||
util::toHex((*i)->getInfoHash(), DHT_ID_LENGTH).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG
|
||||
(fmt("Added 1 peer announce: infoHash=%s",
|
||||
util::toHex((*i)->getInfoHash(), DHT_ID_LENGTH).c_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,6 @@ class Peer;
|
|||
class DHTPeerAnnounceEntry;
|
||||
class DHTTaskQueue;
|
||||
class DHTTaskFactory;
|
||||
class Logger;
|
||||
|
||||
class DHTPeerAnnounceStorage {
|
||||
private:
|
||||
|
@ -59,8 +58,6 @@ private:
|
|||
SharedHandle<DHTTaskQueue> taskQueue_;
|
||||
|
||||
SharedHandle<DHTTaskFactory> taskFactory_;
|
||||
|
||||
Logger* logger_;
|
||||
public:
|
||||
DHTPeerAnnounceStorage();
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "Peer.h"
|
||||
#include "DHTGetPeersReplyMessage.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "DHTMessageFactory.h"
|
||||
#include "DHTNode.h"
|
||||
#include "DHTNodeLookupEntry.h"
|
||||
|
@ -48,13 +49,15 @@
|
|||
#include "bittorrent_helper.h"
|
||||
#include "DHTPeerLookupTaskCallback.h"
|
||||
#include "DHTQueryMessage.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTPeerLookupTask::DHTPeerLookupTask
|
||||
(const SharedHandle<DownloadContext>& downloadContext):
|
||||
DHTAbstractNodeLookupTask<DHTGetPeersReplyMessage>
|
||||
(bittorrent::getInfoHash(downloadContext)) {}
|
||||
(const SharedHandle<DownloadContext>& downloadContext)
|
||||
: DHTAbstractNodeLookupTask<DHTGetPeersReplyMessage>
|
||||
(bittorrent::getInfoHash(downloadContext))
|
||||
{}
|
||||
|
||||
void
|
||||
DHTPeerLookupTask::getNodesFromMessage
|
||||
|
@ -75,8 +78,8 @@ void DHTPeerLookupTask::onReceivedInternal
|
|||
peerStorage_->addPeer(message->getValues());
|
||||
peers_.insert(peers_.end(),
|
||||
message->getValues().begin(), message->getValues().end());
|
||||
getLogger()->info("Received %lu peers.",
|
||||
static_cast<unsigned long>(message->getValues().size()));
|
||||
A2_LOG_INFO(fmt("Received %lu peers.",
|
||||
static_cast<unsigned long>(message->getValues().size())));
|
||||
}
|
||||
|
||||
SharedHandle<DHTMessage> DHTPeerLookupTask::createMessage
|
||||
|
@ -93,10 +96,8 @@ SharedHandle<DHTMessageCallback> DHTPeerLookupTask::createCallback()
|
|||
|
||||
void DHTPeerLookupTask::onFinish()
|
||||
{
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug("Peer lookup for %s finished",
|
||||
util::toHex(getTargetID(), DHT_ID_LENGTH).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Peer lookup for %s finished",
|
||||
util::toHex(getTargetID(), DHT_ID_LENGTH).c_str()));
|
||||
// send announce_peer message to K closest nodes
|
||||
size_t num = DHTBucket::K;
|
||||
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::const_iterator i =
|
||||
|
|
|
@ -39,17 +39,19 @@
|
|||
#include "DHTMessageFactory.h"
|
||||
#include "DHTMessageDispatcher.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "DHTPingReplyMessageCallback.h"
|
||||
#include "DHTQueryMessage.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTReplaceNodeTask::DHTReplaceNodeTask(const SharedHandle<DHTBucket>& bucket,
|
||||
const SharedHandle<DHTNode>& newNode):
|
||||
bucket_(bucket),
|
||||
newNode_(newNode),
|
||||
numRetry_(0),
|
||||
timeout_(DHT_MESSAGE_TIMEOUT)
|
||||
DHTReplaceNodeTask::DHTReplaceNodeTask
|
||||
(const SharedHandle<DHTBucket>& bucket, const SharedHandle<DHTNode>& newNode)
|
||||
: bucket_(bucket),
|
||||
newNode_(newNode),
|
||||
numRetry_(0),
|
||||
timeout_(DHT_MESSAGE_TIMEOUT)
|
||||
{}
|
||||
|
||||
DHTReplaceNodeTask::~DHTReplaceNodeTask() {}
|
||||
|
@ -75,8 +77,8 @@ void DHTReplaceNodeTask::sendMessage()
|
|||
|
||||
void DHTReplaceNodeTask::onReceived(const DHTPingReplyMessage* message)
|
||||
{
|
||||
getLogger()->info("ReplaceNode: Ping reply received from %s.",
|
||||
message->getRemoteNode()->toString().c_str());
|
||||
A2_LOG_INFO(fmt("ReplaceNode: Ping reply received from %s.",
|
||||
message->getRemoteNode()->toString().c_str()));
|
||||
setFinished(true);
|
||||
}
|
||||
|
||||
|
@ -84,16 +86,16 @@ void DHTReplaceNodeTask::onTimeout(const SharedHandle<DHTNode>& node)
|
|||
{
|
||||
++numRetry_;
|
||||
if(numRetry_ >= MAX_RETRY) {
|
||||
getLogger()->info("ReplaceNode: Ping failed %lu times. Replace %s with %s.",
|
||||
static_cast<unsigned long>(numRetry_),
|
||||
node->toString().c_str(),
|
||||
newNode_->toString().c_str());
|
||||
A2_LOG_INFO(fmt("ReplaceNode: Ping failed %lu times. Replace %s with %s.",
|
||||
static_cast<unsigned long>(numRetry_),
|
||||
node->toString().c_str(),
|
||||
newNode_->toString().c_str()));
|
||||
node->markBad();
|
||||
bucket_->addNode(newNode_);
|
||||
setFinished(true);
|
||||
} else {
|
||||
getLogger()->info("ReplaceNode: Ping reply timeout from %s. Try once more.",
|
||||
node->toString().c_str());
|
||||
A2_LOG_INFO(fmt("ReplaceNode: Ping reply timeout from %s. Try once more.",
|
||||
node->toString().c_str()));
|
||||
sendMessage();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "util.h"
|
||||
#include "LogFactory.h"
|
||||
#include "Logger.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -52,8 +53,7 @@ DHTRoutingTable::DHTRoutingTable(const SharedHandle<DHTNode>& localNode)
|
|||
: localNode_(localNode),
|
||||
root_(new DHTBucketTreeNode
|
||||
(SharedHandle<DHTBucket>(new DHTBucket(localNode_)))),
|
||||
numBucket_(1),
|
||||
logger_(LogFactory::getInstance())
|
||||
numBucket_(1)
|
||||
{}
|
||||
|
||||
DHTRoutingTable::~DHTRoutingTable()
|
||||
|
@ -73,30 +73,21 @@ bool DHTRoutingTable::addGoodNode(const SharedHandle<DHTNode>& node)
|
|||
|
||||
bool DHTRoutingTable::addNode(const SharedHandle<DHTNode>& node, bool good)
|
||||
{
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Trying to add node:%s", node->toString().c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Trying to add node:%s", node->toString().c_str()));
|
||||
if(*localNode_ == *node) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Adding node with the same ID with localnode is not"
|
||||
" allowed.");
|
||||
}
|
||||
A2_LOG_DEBUG("Adding node with the same ID with localnode is not allowed.");
|
||||
return false;
|
||||
}
|
||||
DHTBucketTreeNode* treeNode = dht::findTreeNodeFor(root_, node->getID());
|
||||
while(1) {
|
||||
const SharedHandle<DHTBucket>& bucket = treeNode->getBucket();
|
||||
if(bucket->addNode(node)) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Added DHTNode.");
|
||||
}
|
||||
A2_LOG_DEBUG("Added DHTNode.");
|
||||
return true;
|
||||
} else if(bucket->splitAllowed()) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Splitting bucket. Range:%s-%s",
|
||||
A2_LOG_DEBUG(fmt("Splitting bucket. Range:%s-%s",
|
||||
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();
|
||||
++numBucket_;
|
||||
if(treeNode->getLeft()->isInRange(node->getID())) {
|
||||
|
@ -107,9 +98,7 @@ bool DHTRoutingTable::addNode(const SharedHandle<DHTNode>& node, bool good)
|
|||
} else {
|
||||
if(good) {
|
||||
bucket->cacheNode(node);
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Cached node=%s", node->toString().c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Cached node=%s", node->toString().c_str()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,6 @@ class DHTBucket;
|
|||
class DHTTaskQueue;
|
||||
class DHTTaskFactory;
|
||||
class DHTBucketTreeNode;
|
||||
class Logger;
|
||||
|
||||
class DHTRoutingTable {
|
||||
private:
|
||||
|
@ -63,8 +62,6 @@ private:
|
|||
|
||||
SharedHandle<DHTTaskFactory> taskFactory_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
bool addNode(const SharedHandle<DHTNode>& node, bool good);
|
||||
public:
|
||||
DHTRoutingTable(const SharedHandle<DHTNode>& localNode);
|
||||
|
|
|
@ -69,10 +69,11 @@
|
|||
#include "RecoverableException.h"
|
||||
#include "a2functional.h"
|
||||
#include "DownloadEngine.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTSetup::DHTSetup():logger_(LogFactory::getInstance()) {}
|
||||
DHTSetup::DHTSetup() {}
|
||||
|
||||
DHTSetup::~DHTSetup() {}
|
||||
|
||||
|
@ -105,8 +106,10 @@ void DHTSetup::setup
|
|||
deserializer.deserialize(in);
|
||||
localNode = deserializer.getLocalNode();
|
||||
} catch(RecoverableException& e) {
|
||||
logger_->error("Exception caught while loading DHT routing table from %s",
|
||||
e, dhtFile.c_str());
|
||||
A2_LOG_ERROR_EX
|
||||
(fmt("Exception caught while loading DHT routing table from %s",
|
||||
dhtFile.c_str()),
|
||||
e);
|
||||
}
|
||||
if(!localNode) {
|
||||
localNode.reset(new DHTNode());
|
||||
|
@ -125,10 +128,8 @@ void DHTSetup::setup
|
|||
}
|
||||
localNode->setPort(port);
|
||||
}
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Initialized local node ID=%s",
|
||||
util::toHex(localNode->getID(), DHT_ID_LENGTH).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Initialized local node ID=%s",
|
||||
util::toHex(localNode->getID(), DHT_ID_LENGTH).c_str()));
|
||||
SharedHandle<DHTRoutingTable> routingTable(new DHTRoutingTable(localNode));
|
||||
|
||||
SharedHandle<DHTMessageFactoryImpl> factory
|
||||
|
@ -240,7 +241,7 @@ void DHTSetup::setup
|
|||
tempCommands->push_back(command);
|
||||
}
|
||||
} else {
|
||||
logger_->info("No DHT entry point specified.");
|
||||
A2_LOG_INFO("No DHT entry point specified.");
|
||||
}
|
||||
{
|
||||
DHTInteractionCommand* command =
|
||||
|
@ -288,8 +289,9 @@ void DHTSetup::setup
|
|||
commands.insert(commands.end(), tempCommands->begin(), tempCommands->end());
|
||||
tempCommands->clear();
|
||||
} catch(RecoverableException& e) {
|
||||
logger_->error("Exception caught while initializing DHT functionality."
|
||||
" DHT is disabled.", e);
|
||||
A2_LOG_ERROR_EX(fmt("Exception caught while initializing DHT functionality."
|
||||
" DHT is disabled."),
|
||||
e);
|
||||
if(family == AF_INET) {
|
||||
DHTRegistry::clearData();
|
||||
} else {
|
||||
|
|
|
@ -39,13 +39,11 @@
|
|||
#include <vector>
|
||||
|
||||
namespace aria2 {
|
||||
class Logger;
|
||||
|
||||
class DownloadEngine;
|
||||
class Command;
|
||||
|
||||
class DHTSetup {
|
||||
private:
|
||||
Logger* logger_;
|
||||
public:
|
||||
DHTSetup();
|
||||
|
||||
|
|
|
@ -40,12 +40,13 @@
|
|||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "a2functional.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTTaskExecutor::DHTTaskExecutor(size_t numConcurrent):
|
||||
numConcurrent_(numConcurrent),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
DHTTaskExecutor::DHTTaskExecutor(size_t numConcurrent)
|
||||
: numConcurrent_(numConcurrent)
|
||||
{}
|
||||
|
||||
DHTTaskExecutor::~DHTTaskExecutor() {}
|
||||
|
||||
|
@ -64,11 +65,9 @@ void DHTTaskExecutor::update()
|
|||
--r;
|
||||
}
|
||||
}
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Executing %u Task(s). Queue has %u task(s).",
|
||||
A2_LOG_DEBUG(fmt("Executing %u Task(s). Queue has %u task(s).",
|
||||
static_cast<unsigned int>(getExecutingTaskSize()),
|
||||
static_cast<unsigned int>(getQueueSize()));
|
||||
}
|
||||
static_cast<unsigned int>(getQueueSize())));
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -45,14 +45,12 @@
|
|||
namespace aria2 {
|
||||
|
||||
class DHTTask;
|
||||
class Logger;
|
||||
|
||||
class DHTTaskExecutor {
|
||||
private:
|
||||
size_t numConcurrent_;
|
||||
std::vector<SharedHandle<DHTTask> > execTasks_;
|
||||
std::deque<SharedHandle<DHTTask> > queue_;
|
||||
Logger* logger_;
|
||||
public:
|
||||
DHTTaskExecutor(size_t numConcurrent);
|
||||
|
||||
|
|
|
@ -38,8 +38,6 @@
|
|||
#include "DHTMessageDispatcher.h"
|
||||
#include "DHTMessageFactory.h"
|
||||
#include "DHTTaskQueue.h"
|
||||
#include "LogFactory.h"
|
||||
#include "Logger.h"
|
||||
#include "DHTPingTask.h"
|
||||
#include "DHTNodeLookupTask.h"
|
||||
#include "DHTBucketRefreshTask.h"
|
||||
|
@ -53,13 +51,13 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
DHTTaskFactoryImpl::DHTTaskFactoryImpl():
|
||||
routingTable_(0),
|
||||
dispatcher_(0),
|
||||
factory_(0),
|
||||
taskQueue_(0),
|
||||
timeout_(DHT_MESSAGE_TIMEOUT),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
DHTTaskFactoryImpl::DHTTaskFactoryImpl()
|
||||
: routingTable_(0),
|
||||
dispatcher_(0),
|
||||
factory_(0),
|
||||
taskQueue_(0),
|
||||
timeout_(DHT_MESSAGE_TIMEOUT)
|
||||
{}
|
||||
|
||||
DHTTaskFactoryImpl::~DHTTaskFactoryImpl() {}
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ class DHTMessageDispatcher;
|
|||
class DHTMessageFactory;
|
||||
class DHTTaskQueue;
|
||||
class DHTAbstractTask;
|
||||
class Logger;
|
||||
|
||||
class DHTTaskFactoryImpl:public DHTTaskFactory {
|
||||
private:
|
||||
|
@ -62,8 +61,6 @@ private:
|
|||
|
||||
time_t timeout_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
void setCommonProperty(const SharedHandle<DHTAbstractTask>& task);
|
||||
public:
|
||||
DHTTaskFactoryImpl();
|
||||
|
|
|
@ -43,27 +43,21 @@ namespace {
|
|||
const size_t NUM_CONCURRENT_TASK = 5;
|
||||
} // namespace
|
||||
|
||||
DHTTaskQueueImpl::DHTTaskQueueImpl():
|
||||
periodicTaskQueue1_(NUM_CONCURRENT_TASK),
|
||||
periodicTaskQueue2_(NUM_CONCURRENT_TASK),
|
||||
immediateTaskQueue_(NUM_CONCURRENT_TASK),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
DHTTaskQueueImpl::DHTTaskQueueImpl()
|
||||
: periodicTaskQueue1_(NUM_CONCURRENT_TASK),
|
||||
periodicTaskQueue2_(NUM_CONCURRENT_TASK),
|
||||
immediateTaskQueue_(NUM_CONCURRENT_TASK)
|
||||
{}
|
||||
|
||||
DHTTaskQueueImpl::~DHTTaskQueueImpl() {}
|
||||
|
||||
void DHTTaskQueueImpl::executeTask()
|
||||
{
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Updating periodicTaskQueue1");
|
||||
}
|
||||
A2_LOG_DEBUG("Updating periodicTaskQueue1");
|
||||
periodicTaskQueue1_.update();
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Updating periodicTaskQueue2");
|
||||
}
|
||||
A2_LOG_DEBUG("Updating periodicTaskQueue2");
|
||||
periodicTaskQueue2_.update();
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Updating immediateTaskQueue");
|
||||
}
|
||||
A2_LOG_DEBUG("Updating immediateTaskQueue");
|
||||
immediateTaskQueue_.update();
|
||||
}
|
||||
|
||||
|
|
|
@ -40,8 +40,6 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
class Logger;
|
||||
|
||||
class DHTTaskQueueImpl:public DHTTaskQueue {
|
||||
private:
|
||||
DHTTaskExecutor periodicTaskQueue1_;
|
||||
|
@ -49,8 +47,6 @@ private:
|
|||
DHTTaskExecutor periodicTaskQueue2_;
|
||||
|
||||
DHTTaskExecutor immediateTaskQueue_;
|
||||
|
||||
Logger* logger_;
|
||||
public:
|
||||
DHTTaskQueueImpl();
|
||||
|
||||
|
|
|
@ -39,13 +39,14 @@
|
|||
#include "RecoverableException.h"
|
||||
#include "message.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DHTTokenUpdateCommand::DHTTokenUpdateCommand(cuid_t cuid,
|
||||
DownloadEngine* e,
|
||||
time_t interval):
|
||||
TimeBasedCommand(cuid, e, interval) {}
|
||||
DHTTokenUpdateCommand::DHTTokenUpdateCommand
|
||||
(cuid_t cuid, DownloadEngine* e, time_t interval)
|
||||
: TimeBasedCommand(cuid, e, interval)
|
||||
{}
|
||||
|
||||
DHTTokenUpdateCommand::~DHTTokenUpdateCommand() {}
|
||||
|
||||
|
@ -62,7 +63,7 @@ void DHTTokenUpdateCommand::process()
|
|||
try {
|
||||
tokenTracker_->updateTokenSecret();
|
||||
} catch(RecoverableException& e) {
|
||||
getLogger()->error(EX_EXCEPTION_CAUGHT, e);
|
||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "Peer.h"
|
||||
#include "Option.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
#include "A2STR.h"
|
||||
#include "bencode2.h"
|
||||
#include "bittorrent_helper.h"
|
||||
|
@ -57,19 +58,18 @@ namespace aria2 {
|
|||
|
||||
DefaultBtAnnounce::DefaultBtAnnounce
|
||||
(const SharedHandle<DownloadContext>& downloadContext,
|
||||
const Option* option):
|
||||
downloadContext_(downloadContext),
|
||||
trackers_(0),
|
||||
prevAnnounceTimer_(0),
|
||||
interval_(DEFAULT_ANNOUNCE_INTERVAL),
|
||||
minInterval_(DEFAULT_ANNOUNCE_INTERVAL),
|
||||
userDefinedInterval_(0),
|
||||
complete_(0),
|
||||
incomplete_(0),
|
||||
announceList_(bittorrent::getTorrentAttrs(downloadContext)->announceList),
|
||||
option_(option),
|
||||
logger_(LogFactory::getInstance()),
|
||||
randomizer_(SimpleRandomizer::getInstance())
|
||||
const Option* option)
|
||||
: downloadContext_(downloadContext),
|
||||
trackers_(0),
|
||||
prevAnnounceTimer_(0),
|
||||
interval_(DEFAULT_ANNOUNCE_INTERVAL),
|
||||
minInterval_(DEFAULT_ANNOUNCE_INTERVAL),
|
||||
userDefinedInterval_(0),
|
||||
complete_(0),
|
||||
incomplete_(0),
|
||||
announceList_(bittorrent::getTorrentAttrs(downloadContext)->announceList),
|
||||
option_(option),
|
||||
randomizer_(SimpleRandomizer::getInstance())
|
||||
{}
|
||||
|
||||
DefaultBtAnnounce::~DefaultBtAnnounce() {
|
||||
|
@ -218,9 +218,7 @@ void
|
|||
DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
|
||||
size_t trackerResponseLength)
|
||||
{
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Now processing tracker response.");
|
||||
}
|
||||
A2_LOG_DEBUG("Now processing tracker response.");
|
||||
SharedHandle<ValueBase> decodedValue =
|
||||
bencode2::decode(trackerResponse, trackerResponseLength);
|
||||
const Dict* dict = asDict(decodedValue);
|
||||
|
@ -234,28 +232,22 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
|
|||
}
|
||||
const String* warn = asString(dict->get(BtAnnounce::WARNING_MESSAGE));
|
||||
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));
|
||||
if(tid) {
|
||||
trackerId_ = tid->s();
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Tracker ID:%s", trackerId_.c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Tracker ID:%s", trackerId_.c_str()));
|
||||
}
|
||||
const Integer* ival = asInteger(dict->get(BtAnnounce::INTERVAL));
|
||||
if(ival && ival->i() > 0) {
|
||||
interval_ = ival->i();
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Interval:%ld", static_cast<long int>(interval_));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Interval:%ld", static_cast<long int>(interval_)));
|
||||
}
|
||||
const Integer* mival = asInteger(dict->get(BtAnnounce::MIN_INTERVAL));
|
||||
if(mival && mival->i() > 0) {
|
||||
minInterval_ = mival->i();
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Min interval:%ld", static_cast<long int>(minInterval_));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Min interval:%ld", static_cast<long int>(minInterval_)));
|
||||
minInterval_ = std::min(minInterval_, interval_);
|
||||
} else {
|
||||
// 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));
|
||||
if(comp) {
|
||||
complete_ = comp->i();
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Complete:%d", complete_);
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Complete:%d", complete_));
|
||||
}
|
||||
const Integer* incomp = asInteger(dict->get(BtAnnounce::INCOMPLETE));
|
||||
if(incomp) {
|
||||
incomplete_ = incomp->i();
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Incomplete:%d", incomplete_);
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Incomplete:%d", incomplete_));
|
||||
}
|
||||
const SharedHandle<ValueBase>& peerData = dict->get(BtAnnounce::PEERS);
|
||||
if(!peerData) {
|
||||
logger_->info(MSG_NO_PEER_LIST_RECEIVED);
|
||||
A2_LOG_INFO(MSG_NO_PEER_LIST_RECEIVED);
|
||||
} else {
|
||||
if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) {
|
||||
std::vector<SharedHandle<Peer> > peers;
|
||||
|
@ -287,7 +275,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
|
|||
}
|
||||
const SharedHandle<ValueBase>& peer6Data = dict->get(BtAnnounce::PEERS6);
|
||||
if(!peer6Data) {
|
||||
logger_->info("No peers6 received.");
|
||||
A2_LOG_INFO("No peers6 received.");
|
||||
} else {
|
||||
if(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) {
|
||||
std::vector<SharedHandle<Peer> > peers;
|
||||
|
|
|
@ -43,7 +43,6 @@ namespace aria2 {
|
|||
|
||||
class DownloadContext;
|
||||
class Option;
|
||||
class Logger;
|
||||
class BtRuntime;
|
||||
class PieceStorage;
|
||||
class PeerStorage;
|
||||
|
@ -62,7 +61,6 @@ private:
|
|||
AnnounceList announceList_;
|
||||
std::string trackerId_;
|
||||
const Option* option_;
|
||||
Logger* logger_;
|
||||
SharedHandle<Randomizer> randomizer_;
|
||||
SharedHandle<BtRuntime> btRuntime_;
|
||||
SharedHandle<PieceStorage> pieceStorage_;
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
#include "RequestGroup.h"
|
||||
#include "RequestGroupMan.h"
|
||||
#include "bittorrent_helper.h"
|
||||
|
@ -79,25 +80,23 @@ namespace aria2 {
|
|||
DefaultBtInteractive::DefaultBtInteractive
|
||||
(const SharedHandle<DownloadContext>& downloadContext,
|
||||
const SharedHandle<Peer>& peer)
|
||||
:
|
||||
downloadContext_(downloadContext),
|
||||
peer_(peer),
|
||||
metadataGetMode_(false),
|
||||
localNode_(0),
|
||||
logger_(LogFactory::getInstance()),
|
||||
allowedFastSetSize_(10),
|
||||
haveTimer_(global::wallclock),
|
||||
keepAliveTimer_(global::wallclock),
|
||||
floodingTimer_(global::wallclock),
|
||||
inactiveTimer_(global::wallclock),
|
||||
pexTimer_(global::wallclock),
|
||||
perSecTimer_(global::wallclock),
|
||||
keepAliveInterval_(120),
|
||||
utPexEnabled_(false),
|
||||
dhtEnabled_(false),
|
||||
numReceivedMessage_(0),
|
||||
maxOutstandingRequest_(DEFAULT_MAX_OUTSTANDING_REQUEST),
|
||||
requestGroupMan_(0)
|
||||
: downloadContext_(downloadContext),
|
||||
peer_(peer),
|
||||
metadataGetMode_(false),
|
||||
localNode_(0),
|
||||
allowedFastSetSize_(10),
|
||||
haveTimer_(global::wallclock),
|
||||
keepAliveTimer_(global::wallclock),
|
||||
floodingTimer_(global::wallclock),
|
||||
inactiveTimer_(global::wallclock),
|
||||
pexTimer_(global::wallclock),
|
||||
perSecTimer_(global::wallclock),
|
||||
keepAliveInterval_(120),
|
||||
utPexEnabled_(false),
|
||||
dhtEnabled_(false),
|
||||
numReceivedMessage_(0),
|
||||
maxOutstandingRequest_(DEFAULT_MAX_OUTSTANDING_REQUEST),
|
||||
requestGroupMan_(0)
|
||||
{}
|
||||
|
||||
DefaultBtInteractive::~DefaultBtInteractive() {}
|
||||
|
@ -139,30 +138,22 @@ BtMessageHandle DefaultBtInteractive::receiveHandshake(bool quickReply) {
|
|||
|
||||
if(message->isFastExtensionSupported()) {
|
||||
peer_->setFastExtensionEnabled(true);
|
||||
if(logger_->info()) {
|
||||
logger_->info(MSG_FAST_EXTENSION_ENABLED, util::itos(cuid_).c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_FAST_EXTENSION_ENABLED, util::itos(cuid_).c_str()));
|
||||
}
|
||||
if(message->isExtendedMessagingEnabled()) {
|
||||
peer_->setExtendedMessagingEnabled(true);
|
||||
if(!utPexEnabled_) {
|
||||
extensionMessageRegistry_->removeExtension("ut_pex");
|
||||
}
|
||||
if(logger_->info()) {
|
||||
logger_->info(MSG_EXTENDED_MESSAGING_ENABLED, util::itos(cuid_).c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_EXTENDED_MESSAGING_ENABLED, util::itos(cuid_).c_str()));
|
||||
}
|
||||
if(message->isDHTEnabled()) {
|
||||
peer_->setDHTEnabled(true);
|
||||
if(logger_->info()) {
|
||||
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_DHT_ENABLED_PEER, util::itos(cuid_).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;
|
||||
}
|
||||
|
||||
|
@ -296,11 +287,10 @@ size_t DefaultBtInteractive::receiveMessages() {
|
|||
break;
|
||||
}
|
||||
++msgcount;
|
||||
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()));
|
||||
message->doReceivedAction();
|
||||
|
||||
switch(message->getId()) {
|
||||
|
@ -338,17 +328,13 @@ size_t DefaultBtInteractive::receiveMessages() {
|
|||
void DefaultBtInteractive::decideInterest() {
|
||||
if(pieceStorage_->hasMissingPiece(peer_)) {
|
||||
if(!peer_->amInterested()) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug(MSG_PEER_INTERESTED, util::itos(cuid_).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt(MSG_PEER_INTERESTED, util::itos(cuid_).c_str()));
|
||||
dispatcher_->
|
||||
addMessageToQueue(messageFactory_->createInterestedMessage());
|
||||
}
|
||||
} else {
|
||||
if(peer_->amInterested()) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug(MSG_PEER_NOT_INTERESTED, util::itos(cuid_).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt(MSG_PEER_NOT_INTERESTED, util::itos(cuid_).c_str()));
|
||||
dispatcher_->
|
||||
addMessageToQueue(messageFactory_->createNotInterestedMessage());
|
||||
}
|
||||
|
@ -425,10 +411,8 @@ void DefaultBtInteractive::cancelAllPiece() {
|
|||
utMetadataRequestTracker_->getAllTrackedIndex();
|
||||
for(std::vector<size_t>::const_iterator i = metadataRequests.begin(),
|
||||
eoi = metadataRequests.end(); i != eoi; ++i) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Cancel metadata: piece=%lu",
|
||||
static_cast<unsigned long>(*i));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Cancel metadata: piece=%lu",
|
||||
static_cast<unsigned long>(*i)));
|
||||
pieceStorage_->cancelPiece(pieceStorage_->getPiece(*i));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,6 @@ class PeerConnection;
|
|||
class ExtensionMessageFactory;
|
||||
class ExtensionMessageRegistry;
|
||||
class DHTNode;
|
||||
class Logger;
|
||||
class RequestGroupMan;
|
||||
class UTMetadataRequestFactory;
|
||||
class UTMetadataRequestTracker;
|
||||
|
@ -126,7 +125,6 @@ private:
|
|||
|
||||
DHTNode* localNode_;
|
||||
|
||||
Logger* logger_;
|
||||
size_t allowedFastSetSize_;
|
||||
Timer haveTimer_;
|
||||
Timer keepAliveTimer_;
|
||||
|
|
|
@ -55,21 +55,20 @@
|
|||
#include "RequestGroupMan.h"
|
||||
#include "RequestGroup.h"
|
||||
#include "util.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DefaultBtMessageDispatcher::DefaultBtMessageDispatcher():
|
||||
cuid(0),
|
||||
messageFactory_(0),
|
||||
requestGroupMan_(0),
|
||||
requestTimeout_(0),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
DefaultBtMessageDispatcher::DefaultBtMessageDispatcher()
|
||||
: cuid(0),
|
||||
messageFactory_(0),
|
||||
requestGroupMan_(0),
|
||||
requestTimeout_(0)
|
||||
{}
|
||||
|
||||
DefaultBtMessageDispatcher::~DefaultBtMessageDispatcher()
|
||||
{
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("DefaultBtMessageDispatcher::deleted");
|
||||
}
|
||||
A2_LOG_DEBUG("DefaultBtMessageDispatcher::deleted");
|
||||
}
|
||||
|
||||
void DefaultBtMessageDispatcher::addMessageToQueue
|
||||
|
@ -147,22 +146,19 @@ class AbortOutstandingRequest {
|
|||
private:
|
||||
SharedHandle<Piece> piece_;
|
||||
cuid_t cuid_;
|
||||
Logger* logger_;
|
||||
public:
|
||||
AbortOutstandingRequest(const SharedHandle<Piece>& piece, cuid_t cuid):
|
||||
piece_(piece),
|
||||
cuid_(cuid),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
AbortOutstandingRequest(const SharedHandle<Piece>& piece, cuid_t cuid)
|
||||
: piece_(piece),
|
||||
cuid_(cuid)
|
||||
{}
|
||||
|
||||
void operator()(const RequestSlot& slot) const
|
||||
{
|
||||
if(logger_->debug()) {
|
||||
logger_->debug(MSG_DELETING_REQUEST_SLOT,
|
||||
A2_LOG_DEBUG(fmt(MSG_DELETING_REQUEST_SLOT,
|
||||
util::itos(cuid_).c_str(),
|
||||
static_cast<unsigned long>(slot.getIndex()),
|
||||
slot.getBegin(),
|
||||
static_cast<unsigned long>(slot.getBlockIndex()));
|
||||
}
|
||||
static_cast<unsigned long>(slot.getBlockIndex())));
|
||||
piece_->cancelBlock(slot.getBlockIndex());
|
||||
}
|
||||
};
|
||||
|
@ -196,26 +192,24 @@ private:
|
|||
cuid_t cuid_;
|
||||
SharedHandle<Peer> peer_;
|
||||
SharedHandle<PieceStorage> pieceStorage_;
|
||||
Logger* logger_;
|
||||
public:
|
||||
ProcessChokedRequestSlot(cuid_t cuid,
|
||||
const SharedHandle<Peer>& peer,
|
||||
const SharedHandle<PieceStorage>& pieceStorage):
|
||||
cuid_(cuid),
|
||||
peer_(peer),
|
||||
pieceStorage_(pieceStorage),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
ProcessChokedRequestSlot
|
||||
(cuid_t cuid,
|
||||
const SharedHandle<Peer>& peer,
|
||||
const SharedHandle<PieceStorage>& pieceStorage)
|
||||
: cuid_(cuid),
|
||||
peer_(peer),
|
||||
pieceStorage_(pieceStorage)
|
||||
{}
|
||||
|
||||
void operator()(const RequestSlot& slot) const
|
||||
{
|
||||
if(!peer_->isInPeerAllowedIndexSet(slot.getIndex())) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug(MSG_DELETING_REQUEST_SLOT_CHOKED,
|
||||
A2_LOG_DEBUG(fmt(MSG_DELETING_REQUEST_SLOT_CHOKED,
|
||||
util::itos(cuid_).c_str(),
|
||||
static_cast<unsigned long>(slot.getIndex()),
|
||||
slot.getBegin(),
|
||||
static_cast<unsigned long>(slot.getBlockIndex()));
|
||||
}
|
||||
static_cast<unsigned long>(slot.getBlockIndex())));
|
||||
SharedHandle<Piece> piece = pieceStorage_->getPiece(slot.getIndex());
|
||||
piece->cancelBlock(slot.getBlockIndex());
|
||||
}
|
||||
|
@ -270,41 +264,37 @@ private:
|
|||
BtMessageDispatcher* messageDispatcher_;
|
||||
BtMessageFactory* messageFactory_;
|
||||
time_t requestTimeout_;
|
||||
Logger* logger_;
|
||||
public:
|
||||
ProcessStaleRequestSlot(cuid_t cuid, const SharedHandle<Peer>& peer,
|
||||
const SharedHandle<PieceStorage>& pieceStorage,
|
||||
BtMessageDispatcher* dispatcher,
|
||||
BtMessageFactory* factory,
|
||||
time_t requestTimeout):
|
||||
cuid_(cuid),
|
||||
peer_(peer),
|
||||
pieceStorage_(pieceStorage),
|
||||
messageDispatcher_(dispatcher),
|
||||
messageFactory_(factory),
|
||||
requestTimeout_(requestTimeout),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
ProcessStaleRequestSlot
|
||||
(cuid_t cuid, const SharedHandle<Peer>& peer,
|
||||
const SharedHandle<PieceStorage>& pieceStorage,
|
||||
BtMessageDispatcher* dispatcher,
|
||||
BtMessageFactory* factory,
|
||||
time_t requestTimeout)
|
||||
: cuid_(cuid),
|
||||
peer_(peer),
|
||||
pieceStorage_(pieceStorage),
|
||||
messageDispatcher_(dispatcher),
|
||||
messageFactory_(factory),
|
||||
requestTimeout_(requestTimeout)
|
||||
{}
|
||||
|
||||
void operator()(const RequestSlot& slot)
|
||||
{
|
||||
if(slot.isTimeout(requestTimeout_)) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug(MSG_DELETING_REQUEST_SLOT_TIMEOUT,
|
||||
A2_LOG_DEBUG(fmt(MSG_DELETING_REQUEST_SLOT_TIMEOUT,
|
||||
util::itos(cuid_).c_str(),
|
||||
static_cast<unsigned long>(slot.getIndex()),
|
||||
slot.getBegin(),
|
||||
static_cast<unsigned long>(slot.getBlockIndex()));
|
||||
}
|
||||
static_cast<unsigned long>(slot.getBlockIndex())));
|
||||
slot.getPiece()->cancelBlock(slot.getBlockIndex());
|
||||
peer_->snubbing(true);
|
||||
} else if(slot.getPiece()->hasBlock(slot.getBlockIndex())) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug(MSG_DELETING_REQUEST_SLOT_ACQUIRED,
|
||||
A2_LOG_DEBUG(fmt(MSG_DELETING_REQUEST_SLOT_ACQUIRED,
|
||||
util::itos(cuid_).c_str(),
|
||||
static_cast<unsigned long>(slot.getIndex()),
|
||||
slot.getBegin(),
|
||||
static_cast<unsigned long>(slot.getBlockIndex()));
|
||||
}
|
||||
static_cast<unsigned long>(slot.getBlockIndex())));
|
||||
messageDispatcher_->addMessageToQueue
|
||||
(messageFactory_->createCancelMessage(slot.getIndex(),
|
||||
slot.getBegin(),
|
||||
|
|
|
@ -51,7 +51,6 @@ class BtMessage;
|
|||
class BtMessageFactory;
|
||||
class Peer;
|
||||
class Piece;
|
||||
class Logger;
|
||||
class RequestGroupMan;
|
||||
|
||||
class DefaultBtMessageDispatcher : public BtMessageDispatcher {
|
||||
|
@ -66,7 +65,6 @@ private:
|
|||
SharedHandle<Peer> peer_;
|
||||
RequestGroupMan* requestGroupMan_;
|
||||
time_t requestTimeout_;
|
||||
Logger* logger_;
|
||||
public:
|
||||
DefaultBtMessageDispatcher();
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ class Peer;
|
|||
class PeerConnection;
|
||||
class BtMessageDispatcher;
|
||||
class BtMessageFactory;
|
||||
class Logger;
|
||||
|
||||
class DefaultBtMessageReceiver : public BtMessageReceiver {
|
||||
private:
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include "a2io.h"
|
||||
#include "DownloadFailureException.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
#include "array_fun.h"
|
||||
#include "DownloadContext.h"
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
|
@ -78,12 +79,11 @@ std::string createFilename
|
|||
DefaultBtProgressInfoFile::DefaultBtProgressInfoFile
|
||||
(const SharedHandle<DownloadContext>& dctx,
|
||||
const PieceStorageHandle& pieceStorage,
|
||||
const Option* option):
|
||||
dctx_(dctx),
|
||||
pieceStorage_(pieceStorage),
|
||||
option_(option),
|
||||
logger_(LogFactory::getInstance()),
|
||||
filename_(createFilename(dctx_, getSuffix()))
|
||||
const Option* option)
|
||||
: dctx_(dctx),
|
||||
pieceStorage_(pieceStorage),
|
||||
option_(option),
|
||||
filename_(createFilename(dctx_, getSuffix()))
|
||||
{}
|
||||
|
||||
DefaultBtProgressInfoFile::~DefaultBtProgressInfoFile() {}
|
||||
|
@ -105,7 +105,7 @@ bool DefaultBtProgressInfoFile::isTorrentDownload()
|
|||
// Since version 0001, Integers are saved in binary form, network byte order.
|
||||
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::ofstream o(filenameTemp.c_str(), std::ios::out|std::ios::binary);
|
||||
|
@ -201,7 +201,7 @@ void DefaultBtProgressInfoFile::save()
|
|||
throw DL_ABORT_EX
|
||||
(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_)) {
|
||||
throw DL_ABORT_EX
|
||||
|
@ -225,7 +225,7 @@ void DefaultBtProgressInfoFile::save()
|
|||
// 2) network byte order if version == 0001
|
||||
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);
|
||||
if(!in) {
|
||||
throw DL_ABORT_EX
|
||||
|
@ -251,9 +251,7 @@ void DefaultBtProgressInfoFile::load()
|
|||
bool infoHashCheckEnabled = false;
|
||||
if(extension[3]&1 && isTorrentDownload()) {
|
||||
infoHashCheckEnabled = true;
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("InfoHash checking enabled.");
|
||||
}
|
||||
A2_LOG_DEBUG("InfoHash checking enabled.");
|
||||
}
|
||||
|
||||
uint32_t infoHashLength;
|
||||
|
@ -422,7 +420,7 @@ void DefaultBtProgressInfoFile::load()
|
|||
util::convertBitfield(&dest, &src);
|
||||
pieceStorage_->setBitfield(dest.getBitfield(), dest.getBitfieldLength());
|
||||
}
|
||||
logger_->info(MSG_LOADED_SEGMENT_FILE);
|
||||
A2_LOG_INFO(MSG_LOADED_SEGMENT_FILE);
|
||||
}
|
||||
|
||||
void DefaultBtProgressInfoFile::removeFile()
|
||||
|
@ -437,10 +435,10 @@ bool DefaultBtProgressInfoFile::exists()
|
|||
{
|
||||
File f(filename_);
|
||||
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;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@ class DownloadContext;
|
|||
class PieceStorage;
|
||||
class PeerStorage;
|
||||
class BtRuntime;
|
||||
class Logger;
|
||||
class Option;
|
||||
|
||||
class DefaultBtProgressInfoFile : public BtProgressInfoFile {
|
||||
|
@ -55,7 +54,6 @@ private:
|
|||
SharedHandle<BtRuntime> btRuntime_;
|
||||
#endif // ENABLE_BITTORRENT
|
||||
const Option* option_;
|
||||
Logger* logger_;
|
||||
std::string filename_;
|
||||
|
||||
bool isTorrentDownload();
|
||||
|
|
|
@ -47,25 +47,16 @@
|
|||
#include "a2functional.h"
|
||||
#include "SimpleRandomizer.h"
|
||||
#include "array_fun.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DefaultBtRequestFactory::DefaultBtRequestFactory():
|
||||
dispatcher_(0),
|
||||
messageFactory_(0),
|
||||
logger_(LogFactory::getInstance())
|
||||
{
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("DefaultBtRequestFactory::instantiated");
|
||||
}
|
||||
}
|
||||
DefaultBtRequestFactory::DefaultBtRequestFactory()
|
||||
: dispatcher_(0),
|
||||
messageFactory_(0)
|
||||
{}
|
||||
|
||||
DefaultBtRequestFactory::~DefaultBtRequestFactory()
|
||||
{
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("DefaultBtRequestFactory::deleted");
|
||||
}
|
||||
}
|
||||
DefaultBtRequestFactory::~DefaultBtRequestFactory() {}
|
||||
|
||||
void DefaultBtRequestFactory::addTargetPiece(const SharedHandle<Piece>& piece)
|
||||
{
|
||||
|
@ -176,14 +167,12 @@ void DefaultBtRequestFactory::createRequestMessages
|
|||
getnum -= blockIndexes.size();
|
||||
for(std::vector<size_t>::const_iterator i = blockIndexes.begin(),
|
||||
eoi2 = blockIndexes.end(); i != eoi2; ++i) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug
|
||||
("Creating RequestMessage index=%lu, begin=%u,"
|
||||
" blockIndex=%lu",
|
||||
static_cast<unsigned long>(piece->getIndex()),
|
||||
static_cast<unsigned int>((*i)*piece->getBlockLength()),
|
||||
static_cast<unsigned long>(*i));
|
||||
}
|
||||
A2_LOG_DEBUG
|
||||
(fmt("Creating RequestMessage index=%lu, begin=%u,"
|
||||
" blockIndex=%lu",
|
||||
static_cast<unsigned long>(piece->getIndex()),
|
||||
static_cast<unsigned int>((*i)*piece->getBlockLength()),
|
||||
static_cast<unsigned long>(*i)));
|
||||
requests.push_back
|
||||
(messageFactory_->createRequestMessage(piece, *i));
|
||||
}
|
||||
|
@ -222,14 +211,12 @@ void DefaultBtRequestFactory::createRequestMessagesOnEndGame
|
|||
const size_t& blockIndex = *bitr;
|
||||
if(!dispatcher_->isOutstandingRequest(piece->getIndex(),
|
||||
blockIndex)) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug
|
||||
("Creating RequestMessage index=%lu, begin=%u,"
|
||||
" blockIndex=%lu",
|
||||
static_cast<unsigned long>(piece->getIndex()),
|
||||
static_cast<unsigned int>(blockIndex*piece->getBlockLength()),
|
||||
static_cast<unsigned long>(blockIndex));
|
||||
}
|
||||
A2_LOG_DEBUG
|
||||
(fmt("Creating RequestMessage index=%lu, begin=%u,"
|
||||
" blockIndex=%lu",
|
||||
static_cast<unsigned long>(piece->getIndex()),
|
||||
static_cast<unsigned int>(blockIndex*piece->getBlockLength()),
|
||||
static_cast<unsigned long>(blockIndex)));
|
||||
requests.push_back(messageFactory_->createRequestMessage
|
||||
(piece, blockIndex));
|
||||
}
|
||||
|
|
|
@ -48,7 +48,6 @@ class Peer;
|
|||
class BtMessageDispatcher;
|
||||
class BtMessageFactory;
|
||||
class Piece;
|
||||
class Logger;
|
||||
|
||||
class DefaultBtRequestFactory : public BtRequestFactory {
|
||||
private:
|
||||
|
@ -57,7 +56,6 @@ private:
|
|||
BtMessageDispatcher* dispatcher_;
|
||||
BtMessageFactory* messageFactory_;
|
||||
std::deque<SharedHandle<Piece> > pieces_;
|
||||
Logger* logger_;
|
||||
public:
|
||||
DefaultBtRequestFactory();
|
||||
|
||||
|
|
|
@ -37,8 +37,6 @@
|
|||
#include "DlAbortEx.h"
|
||||
#include "HandshakeExtensionMessage.h"
|
||||
#include "UTPexExtensionMessage.h"
|
||||
#include "LogFactory.h"
|
||||
#include "Logger.h"
|
||||
#include "StringFormat.h"
|
||||
#include "PeerStorage.h"
|
||||
#include "ExtensionMessageRegistry.h"
|
||||
|
@ -56,18 +54,18 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
DefaultExtensionMessageFactory::DefaultExtensionMessageFactory():
|
||||
messageFactory_(0),
|
||||
dispatcher_(0),
|
||||
tracker_(0),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
DefaultExtensionMessageFactory::DefaultExtensionMessageFactory()
|
||||
: messageFactory_(0),
|
||||
dispatcher_(0),
|
||||
tracker_(0)
|
||||
{}
|
||||
|
||||
DefaultExtensionMessageFactory::DefaultExtensionMessageFactory
|
||||
(const SharedHandle<Peer>& peer,
|
||||
const SharedHandle<ExtensionMessageRegistry>& registry):
|
||||
peer_(peer),
|
||||
registry_(registry),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
const SharedHandle<ExtensionMessageRegistry>& registry)
|
||||
: peer_(peer),
|
||||
registry_(registry)
|
||||
{}
|
||||
|
||||
DefaultExtensionMessageFactory::~DefaultExtensionMessageFactory() {}
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@ namespace aria2 {
|
|||
|
||||
class PeerStorage;
|
||||
class Peer;
|
||||
class Logger;
|
||||
class ExtensionMessageRegistry;
|
||||
class DownloadContext;
|
||||
class BtMessageFactory;
|
||||
|
@ -63,9 +62,6 @@ private:
|
|||
BtMessageDispatcher* dispatcher_;
|
||||
|
||||
UTMetadataRequestTracker* tracker_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
public:
|
||||
DefaultExtensionMessageFactory();
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include "PieceStorage.h"
|
||||
#include "wallclock.h"
|
||||
#include "a2functional.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -53,13 +54,12 @@ namespace {
|
|||
const int MAX_PEER_LIST_SIZE = 1024;
|
||||
} // namespace
|
||||
|
||||
DefaultPeerStorage::DefaultPeerStorage():
|
||||
logger_(LogFactory::getInstance()),
|
||||
removedPeerSessionDownloadLength_(0),
|
||||
removedPeerSessionUploadLength_(0),
|
||||
seederStateChoke_(new BtSeederStateChoke()),
|
||||
leecherStateChoke_(new BtLeecherStateChoke()),
|
||||
lastTransferStatMapUpdated_(0)
|
||||
DefaultPeerStorage::DefaultPeerStorage()
|
||||
: removedPeerSessionDownloadLength_(0),
|
||||
removedPeerSessionUploadLength_(0),
|
||||
seederStateChoke_(new BtSeederStateChoke()),
|
||||
leecherStateChoke_(new BtLeecherStateChoke()),
|
||||
lastTransferStatMapUpdated_(0)
|
||||
{}
|
||||
|
||||
DefaultPeerStorage::~DefaultPeerStorage()
|
||||
|
@ -103,10 +103,9 @@ size_t calculateMaxPeerListSize(const SharedHandle<BtRuntime>& btRuntime)
|
|||
|
||||
bool DefaultPeerStorage::addPeer(const SharedHandle<Peer>& peer) {
|
||||
if(isPeerAlreadyAdded(peer)) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Adding %s:%u is rejected because it has been already"
|
||||
" added.", peer->getIPAddress().c_str(), peer->getPort());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Adding %s:%u is rejected because it has been already"
|
||||
" added.",
|
||||
peer->getIPAddress().c_str(), peer->getPort()));
|
||||
return false;
|
||||
}
|
||||
size_t maxPeerListSize = calculateMaxPeerListSize(btRuntime_);
|
||||
|
@ -123,10 +122,8 @@ void DefaultPeerStorage::addPeer(const std::vector<SharedHandle<Peer> >& peers)
|
|||
eoi = peers.end(); itr != eoi; ++itr) {
|
||||
const SharedHandle<Peer>& peer = *itr;
|
||||
if(addPeer(peer)) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug(MSG_ADDING_PEER,
|
||||
peer->getIPAddress().c_str(), peer->getPort());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt(MSG_ADDING_PEER,
|
||||
peer->getIPAddress().c_str(), peer->getPort()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -241,9 +238,7 @@ TransferStat DefaultPeerStorage::calculateStat()
|
|||
{
|
||||
TransferStat stat;
|
||||
if(lastTransferStatMapUpdated_.differenceInMillis(global::wallclock) >= 250) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Updating TransferStat of PeerStorage");
|
||||
}
|
||||
A2_LOG_DEBUG("Updating TransferStat of PeerStorage");
|
||||
lastTransferStatMapUpdated_ = global::wallclock;
|
||||
peerTransferStatMap_.clear();
|
||||
std::vector<SharedHandle<Peer> > activePeers;
|
||||
|
@ -272,9 +267,7 @@ TransferStat DefaultPeerStorage::calculateStat()
|
|||
|
||||
void DefaultPeerStorage::updateTransferStatFor(const SharedHandle<Peer>& peer)
|
||||
{
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Updating TransferStat for peer %s", peer->getID().c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Updating TransferStat for peer %s", peer->getID().c_str()));
|
||||
std::map<std::string, TransferStat>::iterator itr =
|
||||
peerTransferStatMap_.find(peer->getID());
|
||||
if(itr == peerTransferStatMap_.end()) {
|
||||
|
@ -340,10 +333,8 @@ void DefaultPeerStorage::returnPeer(const SharedHandle<Peer>& peer)
|
|||
std::deque<SharedHandle<Peer> >::iterator itr =
|
||||
std::find_if(peers_.begin(), peers_.end(), derefEqual(peer));
|
||||
if(itr == peers_.end()) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Cannot find peer %s:%u in PeerStorage.",
|
||||
peer->getIPAddress().c_str(), peer->getPort());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Cannot find peer %s:%u in PeerStorage.",
|
||||
peer->getIPAddress().c_str(), peer->getPort()));
|
||||
} else {
|
||||
peers_.erase(itr);
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
class Logger;
|
||||
class BtRuntime;
|
||||
class BtSeederStateChoke;
|
||||
class BtLeecherStateChoke;
|
||||
|
@ -55,7 +54,6 @@ private:
|
|||
SharedHandle<PieceStorage> pieceStorage_;
|
||||
std::deque<SharedHandle<Peer> > peers_;
|
||||
std::deque<SharedHandle<Peer> > droppedPeers_;
|
||||
Logger* logger_;
|
||||
uint64_t removedPeerSessionDownloadLength_;
|
||||
uint64_t removedPeerSessionUploadLength_;
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include "a2functional.h"
|
||||
#include "Option.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
#include "RarestPieceSelector.h"
|
||||
#include "array_fun.h"
|
||||
#include "PieceStatMan.h"
|
||||
|
@ -67,20 +68,20 @@
|
|||
namespace aria2 {
|
||||
|
||||
DefaultPieceStorage::DefaultPieceStorage
|
||||
(const SharedHandle<DownloadContext>& downloadContext, const Option* option):
|
||||
downloadContext_(downloadContext),
|
||||
bitfieldMan_(new BitfieldMan(downloadContext->getPieceLength(),
|
||||
downloadContext->getTotalLength())),
|
||||
diskWriterFactory_(new DefaultDiskWriterFactory()),
|
||||
endGame_(false),
|
||||
endGamePieceNum_(END_GAME_PIECE_NUM),
|
||||
logger_(LogFactory::getInstance()),
|
||||
option_(option),
|
||||
pieceStatMan_(new PieceStatMan(downloadContext->getNumPieces(), true)),
|
||||
pieceSelector_(new RarestPieceSelector(pieceStatMan_))
|
||||
(const SharedHandle<DownloadContext>& downloadContext, const Option* option)
|
||||
: downloadContext_(downloadContext),
|
||||
bitfieldMan_(new BitfieldMan(downloadContext->getPieceLength(),
|
||||
downloadContext->getTotalLength())),
|
||||
diskWriterFactory_(new DefaultDiskWriterFactory()),
|
||||
endGame_(false),
|
||||
endGamePieceNum_(END_GAME_PIECE_NUM),
|
||||
option_(option),
|
||||
pieceStatMan_(new PieceStatMan(downloadContext->getNumPieces(), true)),
|
||||
pieceSelector_(new RarestPieceSelector(pieceStatMan_))
|
||||
{}
|
||||
|
||||
DefaultPieceStorage::~DefaultPieceStorage() {
|
||||
DefaultPieceStorage::~DefaultPieceStorage()
|
||||
{
|
||||
delete bitfieldMan_;
|
||||
}
|
||||
|
||||
|
@ -130,10 +131,8 @@ void DefaultPieceStorage::addUsedPiece(const SharedHandle<Piece>& piece)
|
|||
std::lower_bound(usedPieces_.begin(), usedPieces_.end(), piece,
|
||||
DerefLess<SharedHandle<Piece> >());
|
||||
usedPieces_.insert(i, piece);
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("usedPieces_.size()=%lu",
|
||||
static_cast<unsigned long>(usedPieces_.size()));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("usedPieces_.size()=%lu",
|
||||
static_cast<unsigned long>(usedPieces_.size())));
|
||||
}
|
||||
|
||||
SharedHandle<Piece> DefaultPieceStorage::findUsedPiece(size_t index) const
|
||||
|
@ -428,12 +427,12 @@ void DefaultPieceStorage::completePiece(const SharedHandle<Piece>& piece)
|
|||
if(downloadFinished()) {
|
||||
downloadContext_->resetDownloadStopTime();
|
||||
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
|
||||
// message after user-specified files were downloaded.
|
||||
//finishSelectiveDownloadingMode();
|
||||
} else {
|
||||
logger_->info(MSG_DOWNLOAD_COMPLETED);
|
||||
A2_LOG_INFO(MSG_DOWNLOAD_COMPLETED);
|
||||
}
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
if(downloadContext_->hasAttribute(bittorrent::BITTORRENT)) {
|
||||
|
@ -561,9 +560,7 @@ bool DefaultPieceStorage::allDownloadFinished()
|
|||
void DefaultPieceStorage::initStorage()
|
||||
{
|
||||
if(downloadContext_->getFileEntries().size() == 1) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Instantiating DirectDiskAdaptor");
|
||||
}
|
||||
A2_LOG_DEBUG("Instantiating DirectDiskAdaptor");
|
||||
DirectDiskAdaptorHandle directDiskAdaptor(new DirectDiskAdaptor());
|
||||
directDiskAdaptor->setTotalLength(downloadContext_->getTotalLength());
|
||||
directDiskAdaptor->setFileEntries
|
||||
|
@ -579,9 +576,7 @@ void DefaultPieceStorage::initStorage()
|
|||
directDiskAdaptor->setDiskWriter(writer);
|
||||
diskAdaptor_ = directDiskAdaptor;
|
||||
} else {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Instantiating MultiDiskAdaptor");
|
||||
}
|
||||
A2_LOG_DEBUG("Instantiating MultiDiskAdaptor");
|
||||
MultiDiskAdaptorHandle multiDiskAdaptor(new MultiDiskAdaptor());
|
||||
multiDiskAdaptor->setFileEntries(downloadContext_->getFileEntries().begin(),
|
||||
downloadContext_->getFileEntries().end());
|
||||
|
@ -671,10 +666,8 @@ void DefaultPieceStorage::removeAdvertisedPiece(time_t elapsed)
|
|||
std::deque<HaveEntry>::iterator itr =
|
||||
std::find_if(haves_.begin(), haves_.end(), FindElapsedHave(elapsed));
|
||||
if(itr != haves_.end()) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug(MSG_REMOVED_HAVE_ENTRY,
|
||||
static_cast<unsigned long>(haves_.end()-itr));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt(MSG_REMOVED_HAVE_ENTRY,
|
||||
static_cast<unsigned long>(haves_.end()-itr)));
|
||||
haves_.erase(itr, haves_.end());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@ namespace aria2 {
|
|||
|
||||
class DownloadContext;
|
||||
class BitfieldMan;
|
||||
class Logger;
|
||||
class Option;
|
||||
class DiskWriterFactory;
|
||||
class FileEntry;
|
||||
|
@ -80,7 +79,6 @@ private:
|
|||
|
||||
bool endGame_;
|
||||
size_t endGamePieceNum_;
|
||||
Logger* logger_;
|
||||
const Option* option_;
|
||||
std::deque<HaveEntry> haves_;
|
||||
|
||||
|
|
|
@ -34,14 +34,12 @@
|
|||
/* copyright --> */
|
||||
#include "DiskAdaptor.h"
|
||||
#include "FileEntry.h"
|
||||
#include "LogFactory.h"
|
||||
#include "Logger.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DiskAdaptor::DiskAdaptor():
|
||||
fallocate_(false),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
DiskAdaptor::DiskAdaptor()
|
||||
: fallocate_(false)
|
||||
{}
|
||||
|
||||
DiskAdaptor::~DiskAdaptor() {}
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
namespace aria2 {
|
||||
|
||||
class FileEntry;
|
||||
class Logger;
|
||||
class FileAllocationIterator;
|
||||
|
||||
class DiskAdaptor:public BinaryStream {
|
||||
|
@ -53,13 +52,6 @@ private:
|
|||
std::vector<SharedHandle<FileEntry> > fileEntries_;
|
||||
|
||||
bool fallocate_;
|
||||
|
||||
Logger* logger_;
|
||||
protected:
|
||||
Logger* getLogger() const
|
||||
{
|
||||
return logger_;
|
||||
}
|
||||
public:
|
||||
DiskAdaptor();
|
||||
virtual ~DiskAdaptor();
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "SegmentMan.h"
|
||||
#include "Segment.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "ChecksumCheckIntegrityEntry.h"
|
||||
#include "PieceStorage.h"
|
||||
#include "CheckIntegrityCommand.h"
|
||||
|
@ -56,6 +57,7 @@
|
|||
#include "message.h"
|
||||
#include "prefs.h"
|
||||
#include "StringFormat.h"
|
||||
#include "fmt.h"
|
||||
#include "RequestGroupMan.h"
|
||||
#include "wallclock.h"
|
||||
#include "SinkStreamFilter.h"
|
||||
|
@ -197,10 +199,8 @@ bool DownloadCommand::executeInternal() {
|
|||
// If segment->getLength() == 0, the server doesn't provide
|
||||
// content length, but the client detected that download
|
||||
// completed.
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_SEGMENT_DOWNLOAD_COMPLETED,
|
||||
util::itos(getCuid()).c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_SEGMENT_DOWNLOAD_COMPLETED,
|
||||
util::itos(getCuid()).c_str()));
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
|
||||
{
|
||||
|
@ -213,11 +213,8 @@ bool DownloadCommand::executeInternal() {
|
|||
!getDownloadContext()->hasAttribute(bittorrent::BITTORRENT)) &&
|
||||
#endif // ENABLE_BITTORRENT
|
||||
segment->isHashCalculated()) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug
|
||||
("Hash is available! index=%lu",
|
||||
static_cast<unsigned long>(segment->getIndex()));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Hash is available! index=%lu",
|
||||
static_cast<unsigned long>(segment->getIndex())));
|
||||
validatePieceHash
|
||||
(segment, expectedPieceHash, segment->getHashString());
|
||||
} else {
|
||||
|
@ -340,14 +337,14 @@ void DownloadCommand::validatePieceHash(const SharedHandle<Segment>& segment,
|
|||
const std::string& actualPieceHash)
|
||||
{
|
||||
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);
|
||||
} else {
|
||||
getLogger()->info(EX_INVALID_CHUNK_CHECKSUM,
|
||||
static_cast<unsigned long>(segment->getIndex()),
|
||||
util::itos(segment->getPosition(), true).c_str(),
|
||||
expectedPieceHash.c_str(),
|
||||
actualPieceHash.c_str());
|
||||
A2_LOG_INFO(fmt(EX_INVALID_CHUNK_CHECKSUM,
|
||||
static_cast<unsigned long>(segment->getIndex()),
|
||||
util::itos(segment->getPosition(), true).c_str(),
|
||||
expectedPieceHash.c_str(),
|
||||
actualPieceHash.c_str()));
|
||||
segment->clear();
|
||||
getSegmentMan()->cancelSegment(getCuid());
|
||||
throw DL_RETRY_EX
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
#include "CheckIntegrityEntry.h"
|
||||
#include "BtProgressInfoFile.h"
|
||||
#include "DownloadContext.h"
|
||||
#include "fmt.h"
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
# include "BtRegistry.h"
|
||||
#endif // ENABLE_BITTORRENT
|
||||
|
@ -85,17 +86,16 @@ volatile sig_atomic_t globalHaltRequested = 0;
|
|||
|
||||
} // namespace global
|
||||
|
||||
DownloadEngine::DownloadEngine(const SharedHandle<EventPoll>& eventPoll):
|
||||
eventPoll_(eventPoll),
|
||||
logger_(LogFactory::getInstance()),
|
||||
haltRequested_(false),
|
||||
noWait_(false),
|
||||
refreshInterval_(DEFAULT_REFRESH_INTERVAL),
|
||||
cookieStorage_(new CookieStorage()),
|
||||
DownloadEngine::DownloadEngine(const SharedHandle<EventPoll>& eventPoll)
|
||||
: eventPoll_(eventPoll),
|
||||
haltRequested_(false),
|
||||
noWait_(false),
|
||||
refreshInterval_(DEFAULT_REFRESH_INTERVAL),
|
||||
cookieStorage_(new CookieStorage()),
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
btRegistry_(new BtRegistry()),
|
||||
btRegistry_(new BtRegistry()),
|
||||
#endif // ENABLE_BITTORRENT
|
||||
dnsCache_(new DNSCache())
|
||||
dnsCache_(new DNSCache())
|
||||
{
|
||||
unsigned char sessionId[20];
|
||||
util::generateRandomKey(sessionId);
|
||||
|
@ -217,14 +217,14 @@ void DownloadEngine::afterEachIteration()
|
|||
{
|
||||
requestGroupMan_->calculateStat();
|
||||
if(global::globalHaltRequested == 1) {
|
||||
logger_->notice(_("Shutdown sequence commencing..."
|
||||
" Press Ctrl-C again for emergency shutdown."));
|
||||
A2_LOG_NOTICE(_("Shutdown sequence commencing..."
|
||||
" Press Ctrl-C again for emergency shutdown."));
|
||||
requestHalt();
|
||||
global::globalHaltRequested = 2;
|
||||
setNoWait(true);
|
||||
setRefreshInterval(0);
|
||||
} else if(global::globalHaltRequested == 3) {
|
||||
logger_->notice(_("Emergency shutdown sequence commencing..."));
|
||||
A2_LOG_NOTICE(_("Emergency shutdown sequence commencing..."));
|
||||
requestForceHalt();
|
||||
global::globalHaltRequested = 4;
|
||||
setNoWait(true);
|
||||
|
@ -276,15 +276,13 @@ void DownloadEngine::addRoutineCommand(Command* command)
|
|||
void DownloadEngine::poolSocket(const std::string& key,
|
||||
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);
|
||||
socketPool_.insert(p);
|
||||
|
||||
if(lastSocketPoolScan_.difference(global::wallclock) >= 60) {
|
||||
std::multimap<std::string, SocketPoolEntry> newPool;
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Scaning SocketPool and erasing timed out entry.");
|
||||
}
|
||||
A2_LOG_DEBUG("Scaning SocketPool and erasing timed out entry.");
|
||||
lastSocketPoolScan_ = global::wallclock;
|
||||
for(std::multimap<std::string, SocketPoolEntry>::iterator i =
|
||||
socketPool_.begin(), eoi = socketPool_.end(); i != eoi; ++i) {
|
||||
|
@ -292,11 +290,9 @@ void DownloadEngine::poolSocket(const std::string& key,
|
|||
newPool.insert(*i);
|
||||
}
|
||||
}
|
||||
if(logger_->debug()) {
|
||||
logger_->debug
|
||||
("%lu entries removed.",
|
||||
static_cast<unsigned long>(socketPool_.size()-newPool.size()));
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("%lu entries removed.",
|
||||
static_cast<unsigned long>
|
||||
(socketPool_.size()-newPool.size())));
|
||||
socketPool_ = newPool;
|
||||
}
|
||||
}
|
||||
|
@ -402,7 +398,7 @@ DownloadEngine::findSocketPoolEntry(const std::string& key)
|
|||
// We assume that if socket is readable it means peer shutdowns
|
||||
// connection and the socket will receive EOF. So skip it.
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,6 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
class Logger;
|
||||
class Option;
|
||||
class RequestGroupMan;
|
||||
class StatCalc;
|
||||
|
@ -78,8 +77,6 @@ private:
|
|||
|
||||
SharedHandle<EventPoll> eventPoll_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
SharedHandle<StatCalc> statCalc_;
|
||||
|
||||
bool haltRequested_;
|
||||
|
|
|
@ -36,8 +36,6 @@
|
|||
|
||||
#include <algorithm>
|
||||
|
||||
#include "LogFactory.h"
|
||||
#include "Logger.h"
|
||||
#include "Option.h"
|
||||
#include "RequestGroup.h"
|
||||
#include "DownloadEngine.h"
|
||||
|
@ -80,8 +78,7 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
DownloadEngineFactory::DownloadEngineFactory():
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
DownloadEngineFactory::DownloadEngineFactory() {}
|
||||
|
||||
DownloadEngineHandle
|
||||
DownloadEngineFactory::newDownloadEngine
|
||||
|
|
|
@ -43,14 +43,11 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
class Logger;
|
||||
class Option;
|
||||
class RequestGroup;
|
||||
class DownloadEngine;
|
||||
|
||||
class DownloadEngineFactory {
|
||||
private:
|
||||
Logger* logger_;
|
||||
public:
|
||||
DownloadEngineFactory();
|
||||
|
||||
|
|
|
@ -33,15 +33,13 @@
|
|||
*/
|
||||
/* copyright --> */
|
||||
#include "DownloadHandler.h"
|
||||
#include "LogFactory.h"
|
||||
#include "Logger.h"
|
||||
#include "RequestGroup.h"
|
||||
#include "RequestGroupCriteria.h"
|
||||
#include "DownloadContext.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
DownloadHandler::DownloadHandler():logger_(LogFactory::getInstance()) {}
|
||||
DownloadHandler::DownloadHandler() {}
|
||||
|
||||
DownloadHandler::~DownloadHandler() {}
|
||||
|
||||
|
|
|
@ -44,20 +44,12 @@
|
|||
namespace aria2 {
|
||||
|
||||
class RequestGroup;
|
||||
class Logger;
|
||||
class RequestGroupCriteria;
|
||||
|
||||
class DownloadHandler
|
||||
{
|
||||
private:
|
||||
SharedHandle<RequestGroupCriteria> criteria_;
|
||||
|
||||
Logger* logger_;
|
||||
protected:
|
||||
Logger* getLogger() const
|
||||
{
|
||||
return logger_;
|
||||
}
|
||||
public:
|
||||
DownloadHandler();
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "Logger.h"
|
||||
#include "util.h"
|
||||
#include "a2functional.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -80,10 +81,9 @@ struct epoll_event EpollEventPoll::KSocketEntry::getEvents()
|
|||
return epEvent;
|
||||
}
|
||||
|
||||
EpollEventPoll::EpollEventPoll():
|
||||
epEventsSize_(EPOLL_EVENTS_MAX),
|
||||
epEvents_(new struct epoll_event[epEventsSize_]),
|
||||
logger_(LogFactory::getInstance())
|
||||
EpollEventPoll::EpollEventPoll()
|
||||
: epEventsSize_(EPOLL_EVENTS_MAX),
|
||||
epEvents_(new struct epoll_event[epEventsSize_])
|
||||
{
|
||||
epfd_ = epoll_create(EPOLL_EVENTS_MAX);
|
||||
}
|
||||
|
@ -95,9 +95,10 @@ EpollEventPoll::~EpollEventPoll()
|
|||
while((r = close(epfd_)) == -1 && errno == EINTR);
|
||||
int errNum = errno;
|
||||
if(r == -1) {
|
||||
logger_->error("Error occurred while closing epoll file descriptor"
|
||||
" %d: %s",
|
||||
epfd_, util::safeStrerror(errNum).c_str());
|
||||
A2_LOG_ERROR(fmt("Error occurred while closing epoll file descriptor"
|
||||
" %d: %s",
|
||||
epfd_,
|
||||
util::safeStrerror(errNum).c_str()));
|
||||
}
|
||||
}
|
||||
delete [] epEvents_;
|
||||
|
@ -201,10 +202,9 @@ bool EpollEventPoll::addEvents(sock_t socket,
|
|||
errNum = errno;
|
||||
}
|
||||
if(r == -1) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Failed to add socket event %d:%s",
|
||||
socket, util::safeStrerror(errNum).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Failed to add socket event %d:%s",
|
||||
socket,
|
||||
util::safeStrerror(errNum).c_str()));
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
@ -253,25 +253,19 @@ bool EpollEventPoll::deleteEvents(sock_t socket,
|
|||
r = epoll_ctl(epfd_, EPOLL_CTL_MOD, (*i)->getSocket(), &epEvent);
|
||||
errNum = r;
|
||||
if(r == -1) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Failed to delete socket event, but may be ignored:%s",
|
||||
util::safeStrerror(errNum).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Failed to delete socket event, but may be ignored:%s",
|
||||
util::safeStrerror(errNum).c_str()));
|
||||
}
|
||||
}
|
||||
if(r == -1) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Failed to delete socket event:%s",
|
||||
util::safeStrerror(errNum).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Failed to delete socket event:%s",
|
||||
util::safeStrerror(errNum).c_str()));
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Socket %d is not found in SocketEntries.", socket);
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,8 +48,6 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
class Logger;
|
||||
|
||||
class EpollEventPoll : public EventPoll {
|
||||
private:
|
||||
class KSocketEntry;
|
||||
|
@ -84,8 +82,6 @@ private:
|
|||
|
||||
static const size_t EPOLL_EVENTS_MAX = 1024;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
bool addEvents(sock_t socket, const KEvent& event);
|
||||
|
||||
bool deleteEvents(sock_t socket, const KEvent& event);
|
||||
|
|
|
@ -45,13 +45,14 @@
|
|||
#include "LogFactory.h"
|
||||
#include "a2algo.h"
|
||||
#include "uri.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
FeedbackURISelector::FeedbackURISelector
|
||||
(const SharedHandle<ServerStatMan>& serverStatMan):
|
||||
serverStatMan_(serverStatMan),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
(const SharedHandle<ServerStatMan>& serverStatMan)
|
||||
: serverStatMan_(serverStatMan)
|
||||
{}
|
||||
|
||||
FeedbackURISelector::~FeedbackURISelector() {}
|
||||
|
||||
|
@ -71,12 +72,12 @@ std::string FeedbackURISelector::select
|
|||
(FileEntry* fileEntry,
|
||||
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 =
|
||||
usedHosts.begin(), eoi = usedHosts.end(); i != eoi; ++i) {
|
||||
logger_->debug("UsedHost=%lu, %s",
|
||||
static_cast<unsigned long>((*i).first),
|
||||
(*i).second.c_str());
|
||||
A2_LOG_DEBUG(fmt("UsedHost=%lu, %s",
|
||||
static_cast<unsigned long>((*i).first),
|
||||
(*i).second.c_str()));
|
||||
}
|
||||
}
|
||||
if(fileEntry->getRemainingUris().empty()) {
|
||||
|
@ -86,18 +87,14 @@ std::string FeedbackURISelector::select
|
|||
// it again without usedHosts.
|
||||
std::string uri = selectFaster(fileEntry->getRemainingUris(), usedHosts);
|
||||
if(uri.empty()) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("No URI returned from selectFaster()");
|
||||
}
|
||||
A2_LOG_DEBUG("No URI returned from selectFaster()");
|
||||
uri = selectRarer(fileEntry->getRemainingUris(), usedHosts);
|
||||
}
|
||||
if(!uri.empty()) {
|
||||
std::deque<std::string>& uris = fileEntry->getRemainingUris();
|
||||
uris.erase(std::find(uris.begin(), uris.end(), uri));
|
||||
}
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("FeedbackURISelector selected %s", uri.c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("FeedbackURISelector selected %s", uri.c_str()));
|
||||
return uri;
|
||||
}
|
||||
|
||||
|
@ -116,9 +113,7 @@ std::string FeedbackURISelector::selectRarer
|
|||
SharedHandle<ServerStat> ss =
|
||||
serverStatMan_->find(us.host, us.protocol);
|
||||
if(ss && ss->isError()) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Error not considered: %s", (*i).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Error not considered: %s", (*i).c_str()));
|
||||
continue;
|
||||
}
|
||||
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) !=
|
||||
usedHosts.end()) {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("%s is in usedHosts, not considered", (*i).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("%s is in usedHosts, not considered", (*i).c_str()));
|
||||
continue;
|
||||
}
|
||||
SharedHandle<ServerStat> ss =
|
||||
|
@ -175,15 +168,11 @@ std::string FeedbackURISelector::selectFaster
|
|||
if(normCands.empty()) {
|
||||
return A2STR::NIL;
|
||||
} else {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Selected from normCands");
|
||||
}
|
||||
A2_LOG_DEBUG("Selected from normCands");
|
||||
return normCands.front();
|
||||
}
|
||||
} else {
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Selected from fastCands");
|
||||
}
|
||||
A2_LOG_DEBUG("Selected from fastCands");
|
||||
std::sort(fastCands.begin(), fastCands.end(), ServerStatFaster());
|
||||
return fastCands.front().second;
|
||||
}
|
||||
|
|
|
@ -40,14 +40,11 @@
|
|||
namespace aria2 {
|
||||
|
||||
class ServerStatMan;
|
||||
class Logger;
|
||||
|
||||
class FeedbackURISelector:public URISelector {
|
||||
private:
|
||||
SharedHandle<ServerStatMan> serverStatMan_;
|
||||
|
||||
Logger* logger_;
|
||||
|
||||
std::string selectRarer
|
||||
(const std::deque<std::string>& uris,
|
||||
const std::vector<std::pair<size_t, std::string> >& usedHosts);
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "DownloadEngine.h"
|
||||
#include "RequestGroup.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "message.h"
|
||||
#include "prefs.h"
|
||||
#include "util.h"
|
||||
|
@ -47,6 +48,7 @@
|
|||
#include "RecoverableException.h"
|
||||
#include "wallclock.h"
|
||||
#include "RequestGroupMan.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -66,12 +68,10 @@ bool FileAllocationCommand::executeInternal()
|
|||
}
|
||||
fileAllocationEntry_->allocateChunk();
|
||||
if(fileAllocationEntry_->finished()) {
|
||||
if(getLogger()->debug()) {
|
||||
getLogger()->debug
|
||||
(MSG_ALLOCATION_COMPLETED,
|
||||
static_cast<long int>(timer_.difference(global::wallclock)),
|
||||
util::itos(getRequestGroup()->getTotalLength(), true).c_str());
|
||||
}
|
||||
A2_LOG_DEBUG
|
||||
(fmt(MSG_ALLOCATION_COMPLETED,
|
||||
static_cast<long int>(timer_.difference(global::wallclock)),
|
||||
util::itos(getRequestGroup()->getTotalLength(), true).c_str()));
|
||||
getDownloadEngine()->getFileAllocationMan()->dropPickedEntry();
|
||||
|
||||
std::vector<Command*>* commands = new std::vector<Command*>();
|
||||
|
@ -90,11 +90,13 @@ bool FileAllocationCommand::executeInternal()
|
|||
bool FileAllocationCommand::handleException(Exception& e)
|
||||
{
|
||||
getDownloadEngine()->getFileAllocationMan()->dropPickedEntry();
|
||||
getLogger()->error
|
||||
(MSG_FILE_ALLOCATION_FAILURE, e, util::itos(getCuid()).c_str());
|
||||
getLogger()->error
|
||||
(MSG_DOWNLOAD_NOT_COMPLETE, util::itos(getCuid()).c_str(),
|
||||
getRequestGroup()->getDownloadContext()->getBasePath().c_str());
|
||||
A2_LOG_ERROR_EX(fmt(MSG_FILE_ALLOCATION_FAILURE,
|
||||
util::itos(getCuid()).c_str()),
|
||||
e);
|
||||
A2_LOG_ERROR
|
||||
(fmt(MSG_DOWNLOAD_NOT_COMPLETE,
|
||||
util::itos(getCuid()).c_str(),
|
||||
getRequestGroup()->getDownloadContext()->getBasePath().c_str()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,9 @@
|
|||
#include "FileAllocationCommand.h"
|
||||
#include "message.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "util.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -51,10 +53,7 @@ Command* FileAllocationDispatcherCommand::createCommand
|
|||
(const SharedHandle<FileAllocationEntry>& entry)
|
||||
{
|
||||
cuid_t newCUID = getDownloadEngine()->newCUID();
|
||||
if(getLogger()->info()) {
|
||||
getLogger()->info(MSG_FILE_ALLOCATION_DISPATCH,
|
||||
util::itos(newCUID).c_str());
|
||||
}
|
||||
A2_LOG_INFO(fmt(MSG_FILE_ALLOCATION_DISPATCH, util::itos(newCUID).c_str()));
|
||||
FileAllocationCommand* command =
|
||||
new FileAllocationCommand(newCUID, entry->getRequestGroup(),
|
||||
getDownloadEngine(), entry);
|
||||
|
|
|
@ -39,31 +39,38 @@
|
|||
|
||||
#include "util.h"
|
||||
#include "URISelector.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "wallclock.h"
|
||||
#include "a2algo.h"
|
||||
#include "uri.h"
|
||||
#include "PeerStat.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
FileEntry::FileEntry(const std::string& path,
|
||||
uint64_t length,
|
||||
off_t offset,
|
||||
const std::vector<std::string>& uris):
|
||||
path_(path), uris_(uris.begin(), uris.end()), length_(length),
|
||||
offset_(offset),
|
||||
requested_(true),
|
||||
uniqueProtocol_(false),
|
||||
maxConnectionPerServer_(1),
|
||||
lastFasterReplace_(0),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
FileEntry::FileEntry
|
||||
(const std::string& path,
|
||||
uint64_t length,
|
||||
off_t offset,
|
||||
const std::vector<std::string>& uris)
|
||||
: path_(path),
|
||||
uris_(uris.begin(), uris.end()),
|
||||
length_(length),
|
||||
offset_(offset),
|
||||
requested_(true),
|
||||
uniqueProtocol_(false),
|
||||
maxConnectionPerServer_(1),
|
||||
lastFasterReplace_(0)
|
||||
{}
|
||||
|
||||
FileEntry::FileEntry():
|
||||
length_(0), offset_(0), requested_(false),
|
||||
uniqueProtocol_(false),
|
||||
maxConnectionPerServer_(1),
|
||||
logger_(LogFactory::getInstance()) {}
|
||||
FileEntry::FileEntry()
|
||||
: length_(0),
|
||||
offset_(0),
|
||||
requested_(false),
|
||||
uniqueProtocol_(false),
|
||||
maxConnectionPerServer_(1)
|
||||
{}
|
||||
|
||||
FileEntry::~FileEntry() {}
|
||||
|
||||
|
@ -172,9 +179,7 @@ FileEntry::getRequest
|
|||
req = requestPool_.front();
|
||||
requestPool_.pop_front();
|
||||
inFlightRequests_.push_back(req);
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Picked up from pool: %s", req->getUri().c_str());
|
||||
}
|
||||
A2_LOG_DEBUG(fmt("Picked up from pool: %s", req->getUri().c_str()));
|
||||
}
|
||||
return req;
|
||||
}
|
||||
|
@ -273,11 +278,9 @@ void FileEntry::removeURIWhoseHostnameIs(const std::string& hostname)
|
|||
newURIs.push_back(*itr);
|
||||
}
|
||||
}
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Removed %lu duplicate hostname URIs for path=%s",
|
||||
A2_LOG_DEBUG(fmt("Removed %lu duplicate hostname URIs for path=%s",
|
||||
static_cast<unsigned long>(uris_.size()-newURIs.size()),
|
||||
getPath().c_str());
|
||||
}
|
||||
getPath().c_str()));
|
||||
uris_.swap(newURIs);
|
||||
}
|
||||
|
||||
|
@ -317,10 +320,10 @@ void FileEntry::extractURIResult
|
|||
|
||||
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(),
|
||||
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_;
|
||||
|
@ -333,10 +336,10 @@ void FileEntry::reuseUri(const std::vector<std::string>& ignore)
|
|||
std::sort(errorUris.begin(), errorUris.end());
|
||||
errorUris.erase(std::unique(errorUris.begin(), errorUris.end()),
|
||||
errorUris.end());
|
||||
if(logger_->debug()) {
|
||||
if(A2_LOG_DEBUG_ENABLED) {
|
||||
for(std::vector<std::string>::const_iterator i = errorUris.begin(),
|
||||
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;
|
||||
|
@ -357,11 +360,12 @@ void FileEntry::reuseUri(const std::vector<std::string>& ignore)
|
|||
}
|
||||
reusableURIs.erase(insertionPoint, reusableURIs.end());
|
||||
size_t ininum = reusableURIs.size();
|
||||
if(logger_->debug()) {
|
||||
logger_->debug("Found %u reusable URIs", static_cast<unsigned int>(ininum));
|
||||
if(A2_LOG_DEBUG_ENABLED) {
|
||||
A2_LOG_DEBUG(fmt("Found %u reusable URIs",
|
||||
static_cast<unsigned int>(ininum)));
|
||||
for(std::vector<std::string>::const_iterator i = reusableURIs.begin(),
|
||||
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());
|
||||
|
|
|
@ -54,8 +54,6 @@ namespace aria2 {
|
|||
|
||||
class URISelector;
|
||||
|
||||
class Logger;
|
||||
|
||||
class FileEntry {
|
||||
private:
|
||||
std::string path_;
|
||||
|
@ -74,7 +72,6 @@ private:
|
|||
size_t maxConnectionPerServer_;
|
||||
std::string originalName_;
|
||||
Timer lastFasterReplace_;
|
||||
Logger* logger_;
|
||||
|
||||
void storePool(const SharedHandle<Request>& request);
|
||||
public:
|
||||
|
|
|
@ -39,7 +39,9 @@
|
|||
#include "RecoverableException.h"
|
||||
#include "message.h"
|
||||
#include "Logger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "DownloadContext.h"
|
||||
#include "fmt.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -68,7 +70,7 @@ bool FillRequestGroupCommand::execute()
|
|||
rgman->clearQueueCheck();
|
||||
rgman->fillRequestGroupFromReserver(e_);
|
||||
} 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
|
||||
// downloads, some might come after this exception.
|
||||
rgman->requestQueueCheck();
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue