mirror of https://github.com/aria2/aria2
To add LogFactory which creates singleton logger:
* src/LogFactory.h: New class. * src/LogFactory.cc: New class. * src/Command.h (logger): New variable. (Constructor): Use LogFactory. * src/AbstractCommand.cc: Use Command::logger * src/PeerConnection.cc (Constructor): Deleted the argument logger. Use LogFactory. * src/SegmentSplitter.h : Made logger protected. * src/SegmentSplitter.cc (Constructor): Use LogFactory. * src/SegmentMan.cc (Constructor): Use LogFactory. * src/DownloadEngine.h : Made logger protected. * src/DownloadEngine.cc (Constructor): Use LogFactory. * src/PeerInteractionCommand.cc : Use Command::logger. * src/HttpResponseCommand.cc : Use Command::logger. * src/SegmentMan.h : Made logger private. * src/TorrentMan.h : Made logger private. * src/TorrentMan.cc : Use LogFactory. * src/FtpNegotiateCommand.cc : Use Command::logger. * src/HttpConnection.h (Constructor): Deleted the argument logger. * src/HttpConnection.cc (Constructor): Deleted the argument logger. Use LogFactory. * src/FtpConnection.h (Constructor): Deleted the argument logger. * src/FtpConnection.cc (Constructor): Deleted the argument logger. Use LogFactory. * src/DownloadCommand.cc : Use Command::logger. * src/PeerAbstractCommand.cc : Use Command::logger. * src/PeerListenCommand.cc : Use Command::logger. * src/PeerInitiateConnectionCommand.cc : Use Command::logger. * src/HttpInitiateConnectionCommand.cc : Use Command::logger. * src/FtpInitiateConnectionCommand.cc : Use Command::logger. * src/TrackerWatcherCommand.cc : Use Command::logger. * src/TrackerUpdateCommand.cc : Use Command::logger. * src/TrackerDownloadCommand.cc : Use Command::logger. * src/RequestSlotMan.cc (Constructor): Deleted the argument logger. Use LogFactory. * src/SendMessageQueue.h (Constructor): Deleted the argument logger. * src/SendMessageQueue.cc (Constructor): Deleted the argument logger. Use LogFactory. * src/main.cc (main): Use LogFactory. * src/DiskAdaptor.h (logger): New variable. * src/DiskAdaptor.cc (Constructor): Use LogFactory. * src/CopyDiskAdaptor.cc (fixFilename): Added a log message.pull/1/head
parent
dcc225a145
commit
39276dcb00
47
ChangeLog
47
ChangeLog
|
@ -1,3 +1,50 @@
|
|||
2006-04-18 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
To add LogFactory which creates singleton logger:
|
||||
|
||||
* src/LogFactory.h: New class.
|
||||
* src/LogFactory.cc: New class.
|
||||
* src/Command.h (logger): New variable.
|
||||
(Constructor): Use LogFactory.
|
||||
* src/AbstractCommand.cc: Use Command::logger
|
||||
* src/PeerConnection.cc (Constructor): Deleted the argument logger.
|
||||
Use LogFactory.
|
||||
* src/SegmentSplitter.h : Made logger protected.
|
||||
* src/SegmentSplitter.cc (Constructor): Use LogFactory.
|
||||
* src/SegmentMan.cc (Constructor): Use LogFactory.
|
||||
* src/DownloadEngine.h : Made logger protected.
|
||||
* src/DownloadEngine.cc (Constructor): Use LogFactory.
|
||||
* src/PeerInteractionCommand.cc : Use Command::logger.
|
||||
* src/HttpResponseCommand.cc : Use Command::logger.
|
||||
* src/SegmentMan.h : Made logger private.
|
||||
* src/TorrentMan.h : Made logger private.
|
||||
* src/TorrentMan.cc : Use LogFactory.
|
||||
* src/FtpNegotiateCommand.cc : Use Command::logger.
|
||||
* src/HttpConnection.h (Constructor): Deleted the argument logger.
|
||||
* src/HttpConnection.cc (Constructor): Deleted the argument logger.
|
||||
Use LogFactory.
|
||||
* src/FtpConnection.h (Constructor): Deleted the argument logger.
|
||||
* src/FtpConnection.cc (Constructor): Deleted the argument logger.
|
||||
Use LogFactory.
|
||||
* src/DownloadCommand.cc : Use Command::logger.
|
||||
* src/PeerAbstractCommand.cc : Use Command::logger.
|
||||
* src/PeerListenCommand.cc : Use Command::logger.
|
||||
* src/PeerInitiateConnectionCommand.cc : Use Command::logger.
|
||||
* src/HttpInitiateConnectionCommand.cc : Use Command::logger.
|
||||
* src/FtpInitiateConnectionCommand.cc : Use Command::logger.
|
||||
* src/TrackerWatcherCommand.cc : Use Command::logger.
|
||||
* src/TrackerUpdateCommand.cc : Use Command::logger.
|
||||
* src/TrackerDownloadCommand.cc : Use Command::logger.
|
||||
* src/RequestSlotMan.cc (Constructor): Deleted the argument logger.
|
||||
Use LogFactory.
|
||||
* src/SendMessageQueue.h (Constructor): Deleted the argument logger.
|
||||
* src/SendMessageQueue.cc (Constructor): Deleted the argument logger.
|
||||
Use LogFactory.
|
||||
* src/main.cc (main): Use LogFactory.
|
||||
* src/DiskAdaptor.h (logger): New variable.
|
||||
* src/DiskAdaptor.cc (Constructor): Use LogFactory.
|
||||
* src/CopyDiskAdaptor.cc (fixFilename): Added a log message.
|
||||
|
||||
2006-04-17 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
* src/TrackerInitCommand.cc (TrackerInitCommand): Added a "key"
|
||||
|
|
1
TODO
1
TODO
|
@ -14,7 +14,6 @@
|
|||
|
||||
0.4.0 release
|
||||
* try to use ftruncate to allocate file.
|
||||
* Add loggerfactory
|
||||
* add log message when download completes
|
||||
|
||||
0.4.1 release
|
||||
|
|
|
@ -23,11 +23,11 @@
|
|||
#include "DlAbortEx.h"
|
||||
#include "DlRetryEx.h"
|
||||
#include "InitiateConnectionCommandFactory.h"
|
||||
#include <sys/time.h>
|
||||
#include "Util.h"
|
||||
#include "message.h"
|
||||
#include "SleepCommand.h"
|
||||
#include "prefs.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
AbstractCommand::AbstractCommand(int cuid, Request* req, DownloadEngine* e, const Socket* s):
|
||||
Command(cuid), req(req), e(e), checkSocketIsReadable(false), checkSocketIsWritable(false) {
|
||||
|
@ -86,19 +86,19 @@ bool AbstractCommand::execute() {
|
|||
// get segment information in order to set Range header.
|
||||
if(!e->segmentMan->getSegment(seg, cuid)) {
|
||||
// no segment available
|
||||
e->logger->info(MSG_NO_SEGMENT_AVAILABLE, cuid);
|
||||
logger->info(MSG_NO_SEGMENT_AVAILABLE, cuid);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return executeInternal(seg);
|
||||
} catch(DlAbortEx* err) {
|
||||
e->logger->error(MSG_DOWNLOAD_ABORTED, err, cuid);
|
||||
logger->error(MSG_DOWNLOAD_ABORTED, err, cuid);
|
||||
onAbort(err);
|
||||
delete(err);
|
||||
req->resetUrl();
|
||||
return true;
|
||||
} catch(DlRetryEx* err) {
|
||||
e->logger->error(MSG_RESTARTING_DOWNLOAD, err, cuid);
|
||||
logger->error(MSG_RESTARTING_DOWNLOAD, err, cuid);
|
||||
req->addTryCount();
|
||||
bool isAbort = e->option->getAsInt(PREF_MAX_TRIES) != 0 &&
|
||||
req->getTryCount() >= e->option->getAsInt(PREF_MAX_TRIES);
|
||||
|
@ -107,7 +107,7 @@ bool AbstractCommand::execute() {
|
|||
}
|
||||
delete(err);
|
||||
if(isAbort) {
|
||||
e->logger->error(MSG_MAX_TRY, cuid, req->getTryCount());
|
||||
logger->error(MSG_MAX_TRY, cuid, req->getTryCount());
|
||||
return true;
|
||||
} else {
|
||||
return prepareForRetry(e->option->getAsInt(PREF_RETRY_WAIT));
|
||||
|
@ -127,7 +127,7 @@ bool AbstractCommand::prepareForRetry(int wait) {
|
|||
}
|
||||
|
||||
void AbstractCommand::onAbort(Exception* ex) {
|
||||
e->logger->debug(MSG_UNREGISTER_CUID, cuid);
|
||||
logger->debug(MSG_UNREGISTER_CUID, cuid);
|
||||
e->segmentMan->unregisterId(cuid);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,16 @@
|
|||
#define _D_COMMAND_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "LogFactory.h"
|
||||
|
||||
class Command {
|
||||
protected:
|
||||
int cuid;
|
||||
const Logger* logger;
|
||||
public:
|
||||
Command(int cuid):cuid(cuid) {}
|
||||
Command(int cuid):cuid(cuid) {
|
||||
logger = LogFactory::getInstance();
|
||||
}
|
||||
virtual ~Command() {}
|
||||
virtual bool execute() = 0;
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ void CopyDiskAdaptor::fixFilename() {
|
|||
itr != fileEntries.end(); itr++) {
|
||||
if(!itr->extracted && itr->requested) {
|
||||
string dest = storeDir+"/"+itr->path;
|
||||
//logger->info("writing file %s", dest.c_str());
|
||||
logger->info("writing file %s", dest.c_str());
|
||||
Util::rangedFileCopy(dest, getFilePath(), offset, itr->length);
|
||||
itr->extracted = true;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,18 @@
|
|||
/* copyright --> */
|
||||
#include "DiskAdaptor.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "LogFactory.h"
|
||||
|
||||
DiskAdaptor::DiskAdaptor(DiskWriter* diskWriter):diskWriter(diskWriter), topDir(NULL) {
|
||||
logger = LogFactory::getInstance();
|
||||
}
|
||||
|
||||
DiskAdaptor::~DiskAdaptor() {
|
||||
delete diskWriter;
|
||||
if(topDir != NULL) {
|
||||
delete topDir;
|
||||
}
|
||||
}
|
||||
|
||||
void DiskAdaptor::openFile() {
|
||||
diskWriter->openFile(getFilePath());
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "FileEntry.h"
|
||||
#include "Directory.h"
|
||||
#include "DiskWriter.h"
|
||||
#include "Logger.h"
|
||||
|
||||
class DiskAdaptor {
|
||||
protected:
|
||||
|
@ -33,15 +34,11 @@ protected:
|
|||
string storeDir;
|
||||
FileEntries fileEntries;
|
||||
const Directory* topDir;
|
||||
const Logger* logger;
|
||||
virtual string getFilePath() const = 0;
|
||||
public:
|
||||
DiskAdaptor(DiskWriter* diskWriter):diskWriter(diskWriter), topDir(NULL) {}
|
||||
virtual ~DiskAdaptor() {
|
||||
delete diskWriter;
|
||||
if(topDir != NULL) {
|
||||
delete topDir;
|
||||
}
|
||||
}
|
||||
DiskAdaptor(DiskWriter* diskWriter);
|
||||
virtual ~DiskAdaptor();
|
||||
|
||||
virtual void openFile();
|
||||
virtual void closeFile();
|
||||
|
|
|
@ -74,7 +74,7 @@ bool DownloadCommand::executeInternal(Segment seg) {
|
|||
|| te == NULL && seg.ds >= seg.ep-seg.sp+1
|
||||
|| bufSize == 0) {
|
||||
if(te != NULL) te->end();
|
||||
e->logger->info(MSG_DOWNLOAD_COMPLETED, cuid);
|
||||
logger->info(MSG_DOWNLOAD_COMPLETED, cuid);
|
||||
seg.ds = seg.ep-seg.sp+1;
|
||||
seg.finish = true;
|
||||
e->segmentMan->updateSegment(seg);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
/* copyright --> */
|
||||
#include "DownloadEngine.h"
|
||||
#include "Util.h"
|
||||
#include "LogFactory.h"
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -29,7 +30,9 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
DownloadEngine::DownloadEngine():noWait(false), segmentMan(NULL) {}
|
||||
DownloadEngine::DownloadEngine():noWait(false), segmentMan(NULL) {
|
||||
logger = LogFactory::getInstance();
|
||||
}
|
||||
|
||||
DownloadEngine::~DownloadEngine() {
|
||||
assert(rsockets.empty());
|
||||
|
|
|
@ -48,6 +48,7 @@ private:
|
|||
bool addSocket(Sockets& sockets, Socket* socket);
|
||||
bool deleteSocket(Sockets& sockets, Socket* socket);
|
||||
protected:
|
||||
const Logger* logger;
|
||||
virtual void initStatistics() = 0;
|
||||
virtual void calculateStatistics() = 0;
|
||||
virtual void onEndOfRun() = 0;
|
||||
|
@ -57,7 +58,6 @@ public:
|
|||
Commands commands;
|
||||
SegmentMan* segmentMan;
|
||||
DiskWriter* diskWriter;
|
||||
const Logger* logger;
|
||||
const Option* option;
|
||||
|
||||
DownloadEngine();
|
||||
|
|
|
@ -25,8 +25,11 @@
|
|||
#include "DlRetryEx.h"
|
||||
#include "message.h"
|
||||
#include "prefs.h"
|
||||
#include "LogFactory.h"
|
||||
|
||||
FtpConnection::FtpConnection(int cuid, const Socket* socket, const Request* req, const Option* op, const Logger* logger):cuid(cuid), socket(socket), req(req), option(op), logger(logger) {}
|
||||
FtpConnection::FtpConnection(int cuid, const Socket* socket, const Request* req, const Option* op):cuid(cuid), socket(socket), req(req), option(op) {
|
||||
logger = LogFactory::getInstance();
|
||||
}
|
||||
|
||||
FtpConnection::~FtpConnection() {}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ private:
|
|||
bool isEndOfResponse(int status, const string& response) const;
|
||||
bool bulkReceiveResponse(pair<int, string>& response);
|
||||
public:
|
||||
FtpConnection(int cuid, const Socket* socket, const Request* req, const Option* op, const Logger* logger);
|
||||
FtpConnection(int cuid, const Socket* socket, const Request* req, const Option* op);
|
||||
~FtpConnection();
|
||||
void sendUser() const;
|
||||
void sendPass() const;
|
||||
|
|
|
@ -47,9 +47,9 @@ bool FtpInitiateConnectionCommand::executeInternal(Segment segment) {
|
|||
socket = new Socket();
|
||||
Command* command;
|
||||
if(useHttpProxy()) {
|
||||
e->logger->info(MSG_CONNECTING_TO_SERVER, cuid,
|
||||
e->option->get(PREF_HTTP_PROXY_HOST).c_str(),
|
||||
e->option->getAsInt(PREF_HTTP_PROXY_PORT));
|
||||
logger->info(MSG_CONNECTING_TO_SERVER, cuid,
|
||||
e->option->get(PREF_HTTP_PROXY_HOST).c_str(),
|
||||
e->option->getAsInt(PREF_HTTP_PROXY_PORT));
|
||||
socket->establishConnection(e->option->get(PREF_HTTP_PROXY_HOST),
|
||||
e->option->getAsInt(PREF_HTTP_PROXY_PORT));
|
||||
|
||||
|
@ -62,8 +62,8 @@ bool FtpInitiateConnectionCommand::executeInternal(Segment segment) {
|
|||
throw new DlAbortEx("ERROR");
|
||||
}
|
||||
} else {
|
||||
e->logger->info(MSG_CONNECTING_TO_SERVER, cuid, req->getHost().c_str(),
|
||||
req->getPort());
|
||||
logger->info(MSG_CONNECTING_TO_SERVER, cuid, req->getHost().c_str(),
|
||||
req->getPort());
|
||||
socket->establishConnection(req->getHost(), req->getPort());
|
||||
command = new FtpNegotiationCommand(cuid, req, e, socket);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ FtpNegotiationCommand::FtpNegotiationCommand(int cuid, Request* req, DownloadEng
|
|||
AbstractCommand(cuid, req, e, s),
|
||||
dataSocket(NULL), serverSocket(NULL), sequence(SEQ_RECV_GREETING)
|
||||
{
|
||||
ftp = new FtpConnection(cuid, socket, req, e->option, e->logger);
|
||||
ftp = new FtpConnection(cuid, socket, req, e->option);
|
||||
setReadCheckSocket(NULL);
|
||||
setWriteCheckSocket(socket);
|
||||
}
|
||||
|
@ -221,9 +221,9 @@ bool FtpNegotiationCommand::recvPasv() {
|
|||
// make a data connection to the server.
|
||||
dataSocket = new Socket();
|
||||
|
||||
e->logger->info(MSG_CONNECTING_TO_SERVER, cuid,
|
||||
dest.first.c_str(),
|
||||
dest.second);
|
||||
logger->info(MSG_CONNECTING_TO_SERVER, cuid,
|
||||
dest.first.c_str(),
|
||||
dest.second);
|
||||
dataSocket->establishConnection(dest.first, dest.second);
|
||||
|
||||
setReadCheckSocket(NULL);
|
||||
|
|
|
@ -32,7 +32,7 @@ FtpTunnelRequestCommand::~FtpTunnelRequestCommand() {}
|
|||
|
||||
bool FtpTunnelRequestCommand::executeInternal(Segment segment) {
|
||||
socket->setBlockingMode();
|
||||
HttpConnection httpConnection(cuid, socket, req, e->option, e->logger);
|
||||
HttpConnection httpConnection(cuid, socket, req, e->option);
|
||||
httpConnection.sendProxyRequest();
|
||||
|
||||
FtpTunnelResponseCommand* command = new FtpTunnelResponseCommand(cuid, req, e, socket);
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "message.h"
|
||||
|
||||
FtpTunnelResponseCommand::FtpTunnelResponseCommand(int cuid, Request* req, DownloadEngine* e, const Socket* s):AbstractCommand(cuid, req, e, s) {
|
||||
http = new HttpConnection(cuid, socket, req, e->option, e->logger);
|
||||
http = new HttpConnection(cuid, socket, req, e->option);
|
||||
}
|
||||
|
||||
FtpTunnelResponseCommand::~FtpTunnelResponseCommand() {
|
||||
|
|
|
@ -25,9 +25,12 @@
|
|||
#include "Base64.h"
|
||||
#include "message.h"
|
||||
#include "prefs.h"
|
||||
#include "LogFactory.h"
|
||||
|
||||
HttpConnection::HttpConnection(int cuid, const Socket* socket, const Request* req, const Option* op, const Logger* logger):
|
||||
cuid(cuid), socket(socket), req(req), option(op), logger(logger), headerBufLength(0) {}
|
||||
HttpConnection::HttpConnection(int cuid, const Socket* socket, const Request* req, const Option* op):
|
||||
cuid(cuid), socket(socket), req(req), option(op), headerBufLength(0) {
|
||||
logger = LogFactory::getInstance();
|
||||
}
|
||||
|
||||
void HttpConnection::sendRequest(const Segment& segment) const {
|
||||
string request = createRequest(segment);
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "Logger.h"
|
||||
#include "HttpHeader.h"
|
||||
#include "common.h"
|
||||
#include "Logger.h"
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
@ -52,7 +53,7 @@ private:
|
|||
char headerBuf[HEADERBUF_SIZE+1];
|
||||
int headerBufLength;
|
||||
public:
|
||||
HttpConnection(int cuid, const Socket* socket, const Request* req, const Option* op, const Logger* logger);
|
||||
HttpConnection(int cuid, const Socket* socket, const Request* req, const Option* op);
|
||||
|
||||
/**
|
||||
* Sends Http request.
|
||||
|
|
|
@ -36,9 +36,9 @@ bool HttpInitiateConnectionCommand::executeInternal(Segment segment) {
|
|||
// socket->establishConnection(...);
|
||||
Command* command;
|
||||
if(useProxy()) {
|
||||
e->logger->info(MSG_CONNECTING_TO_SERVER, cuid,
|
||||
e->option->get(PREF_HTTP_PROXY_HOST).c_str(),
|
||||
e->option->getAsInt(PREF_HTTP_PROXY_PORT));
|
||||
logger->info(MSG_CONNECTING_TO_SERVER, cuid,
|
||||
e->option->get(PREF_HTTP_PROXY_HOST).c_str(),
|
||||
e->option->getAsInt(PREF_HTTP_PROXY_PORT));
|
||||
socket->establishConnection(e->option->get(PREF_HTTP_PROXY_HOST),
|
||||
e->option->getAsInt(PREF_HTTP_PROXY_PORT));
|
||||
if(useProxyTunnel()) {
|
||||
|
@ -50,8 +50,8 @@ bool HttpInitiateConnectionCommand::executeInternal(Segment segment) {
|
|||
throw new DlAbortEx("ERROR");
|
||||
}
|
||||
} else {
|
||||
e->logger->info(MSG_CONNECTING_TO_SERVER, cuid, req->getHost().c_str(),
|
||||
req->getPort());
|
||||
logger->info(MSG_CONNECTING_TO_SERVER, cuid, req->getHost().c_str(),
|
||||
req->getPort());
|
||||
socket->establishConnection(req->getHost(), req->getPort());
|
||||
command = new HttpRequestCommand(cuid, req, e, socket);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ HttpProxyRequestCommand::~HttpProxyRequestCommand() {}
|
|||
|
||||
bool HttpProxyRequestCommand::executeInternal(Segment segment) {
|
||||
socket->setBlockingMode();
|
||||
HttpConnection httpConnection(cuid, socket, req, e->option, e->logger);
|
||||
HttpConnection httpConnection(cuid, socket, req, e->option);
|
||||
httpConnection.sendProxyRequest();
|
||||
|
||||
HttpProxyResponseCommand* command = new HttpProxyResponseCommand(cuid, req, e, socket);
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "message.h"
|
||||
|
||||
HttpProxyResponseCommand::HttpProxyResponseCommand(int cuid, Request* req, DownloadEngine* e, const Socket* s):AbstractCommand(cuid, req, e, s) {
|
||||
http = new HttpConnection(cuid, socket, req, e->option, e->logger);
|
||||
http = new HttpConnection(cuid, socket, req, e->option);
|
||||
}
|
||||
|
||||
HttpProxyResponseCommand::~HttpProxyResponseCommand() {
|
||||
|
|
|
@ -35,7 +35,7 @@ bool HttpRequestCommand::executeInternal(Segment seg) {
|
|||
if(req->getProtocol() == "https") {
|
||||
socket->initiateSecureConnection();
|
||||
}
|
||||
HttpConnection http(cuid, socket, req, e->option, e->logger);
|
||||
HttpConnection http(cuid, socket, req, e->option);
|
||||
// set seg to request in order to remember the request range
|
||||
req->seg = seg;
|
||||
http.sendRequest(seg);
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
HttpResponseCommand::HttpResponseCommand(int cuid, Request* req, DownloadEngine* e, const Socket* s):
|
||||
AbstractCommand(cuid, req, e, s) {
|
||||
http = new HttpConnection(cuid, socket, req, e->option, e->logger);
|
||||
http = new HttpConnection(cuid, socket, req, e->option);
|
||||
}
|
||||
|
||||
HttpResponseCommand::~HttpResponseCommand() {
|
||||
|
@ -41,7 +41,7 @@ HttpResponseCommand::~HttpResponseCommand() {
|
|||
|
||||
bool HttpResponseCommand::executeInternal(Segment seg) {
|
||||
if(req->seg.sp != seg.sp) {
|
||||
e->logger->info(MSG_SEGMENT_CHANGED, cuid);
|
||||
logger->info(MSG_SEGMENT_CHANGED, cuid);
|
||||
return prepareForRetry(0);
|
||||
}
|
||||
HttpHeader headers;
|
||||
|
@ -86,7 +86,7 @@ void HttpResponseCommand::checkResponse(int status, const Segment& segment) {
|
|||
|
||||
bool HttpResponseCommand::handleRedirect(string url, const HttpHeader& headers) {
|
||||
req->redirectUrl(url);
|
||||
e->logger->info(MSG_REDIRECT, cuid, url.c_str());
|
||||
logger->info(MSG_REDIRECT, cuid, url.c_str());
|
||||
e->noWait = true;
|
||||
return prepareForRetry(0);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - a simple utility for downloading files faster
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "LogFactory.h"
|
||||
#include "SimpleLogger.h"
|
||||
|
||||
string LogFactory::filename;
|
||||
Logger* LogFactory::logger = NULL;
|
||||
|
||||
Logger* LogFactory::getInstance() {
|
||||
if(logger == NULL) {
|
||||
if(filename.empty()) {
|
||||
logger = new SimpleLogger("/dev/null");
|
||||
} else {
|
||||
logger = new SimpleLogger(filename);
|
||||
}
|
||||
}
|
||||
return logger;
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - a simple utility for downloading files faster
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_LOG_FACTORY_H_
|
||||
#define _D_LOG_FACTORY_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "Logger.h"
|
||||
|
||||
class LogFactory {
|
||||
private:
|
||||
static string filename;
|
||||
static Logger* logger;
|
||||
public:
|
||||
/**
|
||||
* Get logger instance. Returned logger is singleton.
|
||||
* This function is not thread-safe.
|
||||
*/
|
||||
static Logger* getInstance();
|
||||
|
||||
/**
|
||||
* Set a filename to write log.
|
||||
*/
|
||||
static void setLogFile(const string& name) {
|
||||
filename = name;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _D_LOG_FACTORY_H_
|
|
@ -84,7 +84,8 @@ SRCS = Socket.cc Socket.h\
|
|||
CopyDiskAdaptor.cc CopyDiskAdaptor.h\
|
||||
DirectDiskAdaptor.cc DirectDiskAdaptor.h\
|
||||
MultiDiskAdaptor.cc MultiDiskAdaptor.h\
|
||||
FileEntry.h
|
||||
FileEntry.h\
|
||||
LogFactory.cc LogFactory.h
|
||||
noinst_LIBRARIES = libaria2c.a
|
||||
libaria2c_a_SOURCES = $(SRCS)
|
||||
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
|
||||
|
|
|
@ -100,7 +100,8 @@ am__objects_1 = Socket.$(OBJEXT) SocketCore.$(OBJEXT) \
|
|||
Directory.$(OBJEXT) TrackerWatcherCommand.$(OBJEXT) \
|
||||
SendMessageQueue.$(OBJEXT) MultiDiskWriter.$(OBJEXT) \
|
||||
DiskAdaptor.$(OBJEXT) CopyDiskAdaptor.$(OBJEXT) \
|
||||
DirectDiskAdaptor.$(OBJEXT) MultiDiskAdaptor.$(OBJEXT)
|
||||
DirectDiskAdaptor.$(OBJEXT) MultiDiskAdaptor.$(OBJEXT) \
|
||||
LogFactory.$(OBJEXT)
|
||||
am_libaria2c_a_OBJECTS = $(am__objects_1)
|
||||
libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS)
|
||||
am__installdirs = "$(DESTDIR)$(bindir)"
|
||||
|
@ -334,7 +335,8 @@ SRCS = Socket.cc Socket.h\
|
|||
CopyDiskAdaptor.cc CopyDiskAdaptor.h\
|
||||
DirectDiskAdaptor.cc DirectDiskAdaptor.h\
|
||||
MultiDiskAdaptor.cc MultiDiskAdaptor.h\
|
||||
FileEntry.h
|
||||
FileEntry.h\
|
||||
LogFactory.cc LogFactory.h
|
||||
|
||||
noinst_LIBRARIES = libaria2c.a
|
||||
libaria2c_a_SOURCES = $(SRCS)
|
||||
|
@ -453,6 +455,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HttpResponseCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/InitiateConnectionCommandFactory.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/List.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LogFactory.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MetaFileUtil.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MultiDiskAdaptor.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MultiDiskWriter.Po@am__quote@
|
||||
|
|
|
@ -22,10 +22,10 @@
|
|||
#include "PeerAbstractCommand.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "DlRetryEx.h"
|
||||
#include <sys/time.h>
|
||||
#include "Util.h"
|
||||
#include "message.h"
|
||||
#include "prefs.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
PeerAbstractCommand::PeerAbstractCommand(int cuid, Peer* peer, TorrentDownloadEngine* e, const Socket* s):
|
||||
Command(cuid), e(e), peer(peer), checkSocketIsReadable(false), checkSocketIsWritable(false) {
|
||||
|
@ -90,13 +90,13 @@ bool PeerAbstractCommand::execute() {
|
|||
//e->torrentMan->updatePeer(peer);
|
||||
return returnValue;
|
||||
} catch(Exception* err) {
|
||||
e->logger->error(MSG_DOWNLOAD_ABORTED, err, cuid);
|
||||
logger->error(MSG_DOWNLOAD_ABORTED, err, cuid);
|
||||
onAbort(err);
|
||||
delete(err);
|
||||
return prepareForNextPeer(0);
|
||||
}
|
||||
/*catch(DlRetryEx* err) {
|
||||
e->logger->error(MSG_RESTARTING_DOWNLOAD, err, cuid);
|
||||
logger->error(MSG_RESTARTING_DOWNLOAD, err, cuid);
|
||||
peer->tryCount++;
|
||||
bool isAbort = e->option->getAsInt(PREF_MAX_TRIES) != 0 &&
|
||||
peer->tryCount >= e->option->getAsInt(PREF_MAX_TRIES);
|
||||
|
@ -106,7 +106,7 @@ bool PeerAbstractCommand::execute() {
|
|||
}
|
||||
delete(err);
|
||||
if(isAbort) {
|
||||
e->logger->error(MSG_MAX_TRY, cuid, tryCount);
|
||||
logger->error(MSG_MAX_TRY, cuid, tryCount);
|
||||
return true;
|
||||
} else {
|
||||
return prepareForRetry(e->option->getAsInt(PREF_RETRY_WAIT));
|
||||
|
@ -136,7 +136,7 @@ void PeerAbstractCommand::onAbort(Exception* ex) {
|
|||
peer->amInterested = false;
|
||||
peer->peerChoking = true;
|
||||
peer->peerInterested = false;
|
||||
e->logger->debug("CUID#%d - peer %s:%d banned.", cuid, peer->ipaddr.c_str(), peer->port);
|
||||
logger->debug("CUID#%d - peer %s:%d banned.", cuid, peer->ipaddr.c_str(), peer->port);
|
||||
}
|
||||
|
||||
void PeerAbstractCommand::setReadCheckSocket(Socket* socket) {
|
||||
|
|
|
@ -24,14 +24,17 @@
|
|||
#include "DlAbortEx.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "LogFactory.h"
|
||||
#include <netinet/in.h>
|
||||
|
||||
PeerConnection::PeerConnection(int cuid, const Socket* socket,
|
||||
const Option* op, const Logger* logger,
|
||||
const Option* op,
|
||||
Peer* peer, TorrentMan* torrentMan)
|
||||
:cuid(cuid), socket(socket), option(op), logger(logger), peer(peer),
|
||||
torrentMan(torrentMan),
|
||||
resbufLength(0), currentPayloadLength(0), lenbufLength(0) {}
|
||||
resbufLength(0), currentPayloadLength(0), lenbufLength(0) {
|
||||
logger = LogFactory::getInstance();
|
||||
}
|
||||
|
||||
PeerConnection::~PeerConnection() {}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ private:
|
|||
void writeOutgoingMessageLog(const char* msg, int index, int begin, int length) const;
|
||||
public:
|
||||
PeerConnection(int cuid, const Socket* socket, const Option* op,
|
||||
const Logger* logger, Peer* peer, TorrentMan* torrenMan);
|
||||
Peer* peer, TorrentMan* torrenMan);
|
||||
~PeerConnection();
|
||||
|
||||
void sendHandshake() const;
|
||||
|
|
|
@ -38,8 +38,8 @@ bool PeerInitiateConnectionCommand::executeInternal() {
|
|||
// socket->establishConnection(...);
|
||||
|
||||
Command* command;
|
||||
e->logger->info(MSG_CONNECTING_TO_SERVER, cuid, peer->ipaddr.c_str(),
|
||||
peer->port);
|
||||
logger->info(MSG_CONNECTING_TO_SERVER, cuid, peer->ipaddr.c_str(),
|
||||
peer->port);
|
||||
socket->establishConnection(peer->ipaddr, peer->port);
|
||||
command = new PeerInteractionCommand(cuid, peer, e, socket, PeerInteractionCommand::INITIATOR_SEND_HANDSHAKE);
|
||||
|
||||
|
|
|
@ -37,10 +37,8 @@ PeerInteractionCommand::PeerInteractionCommand(int cuid, Peer* peer,
|
|||
setWriteCheckSocket(socket);
|
||||
setTimeout(e->option->getAsInt(PREF_PEER_CONNECTION_TIMEOUT));
|
||||
}
|
||||
peerConnection = new PeerConnection(cuid, socket, e->option, e->logger,
|
||||
peer, e->torrentMan);
|
||||
sendMessageQueue = new SendMessageQueue(cuid, peerConnection, e->torrentMan,
|
||||
e->logger);
|
||||
peerConnection = new PeerConnection(cuid, socket, e->option, peer, e->torrentMan);
|
||||
sendMessageQueue = new SendMessageQueue(cuid, peerConnection, e->torrentMan);
|
||||
piece = Piece::nullPiece;
|
||||
keepAliveCheckPoint.tv_sec = 0;
|
||||
keepAliveCheckPoint.tv_usec = 0;
|
||||
|
@ -78,9 +76,9 @@ bool PeerInteractionCommand::executeInternal() {
|
|||
break;
|
||||
}
|
||||
peer->setPeerId(handshakeMessage->peerId);
|
||||
e->logger->info(MSG_RECEIVE_PEER_MESSAGE, cuid,
|
||||
peer->ipaddr.c_str(), peer->port,
|
||||
handshakeMessage->toString().c_str());
|
||||
logger->info(MSG_RECEIVE_PEER_MESSAGE, cuid,
|
||||
peer->ipaddr.c_str(), peer->port,
|
||||
handshakeMessage->toString().c_str());
|
||||
delete handshakeMessage;
|
||||
if(e->torrentMan->getDownloadLength() > 0) {
|
||||
peerConnection->sendBitfield();
|
||||
|
@ -94,9 +92,9 @@ bool PeerInteractionCommand::executeInternal() {
|
|||
break;
|
||||
}
|
||||
peer->setPeerId(handshakeMessage->peerId);
|
||||
e->logger->info(MSG_RECEIVE_PEER_MESSAGE, cuid,
|
||||
peer->ipaddr.c_str(), peer->port,
|
||||
handshakeMessage->toString().c_str());
|
||||
logger->info(MSG_RECEIVE_PEER_MESSAGE, cuid,
|
||||
peer->ipaddr.c_str(), peer->port,
|
||||
handshakeMessage->toString().c_str());
|
||||
delete handshakeMessage;
|
||||
peerConnection->sendHandshake();
|
||||
if(e->torrentMan->getDownloadLength() > 0) {
|
||||
|
@ -217,9 +215,9 @@ void PeerInteractionCommand::receiveMessage() {
|
|||
if(message == NULL) {
|
||||
return;
|
||||
}
|
||||
e->logger->info(MSG_RECEIVE_PEER_MESSAGE, cuid,
|
||||
peer->ipaddr.c_str(), peer->port,
|
||||
message->toString().c_str());
|
||||
logger->info(MSG_RECEIVE_PEER_MESSAGE, cuid,
|
||||
peer->ipaddr.c_str(), peer->port,
|
||||
message->toString().c_str());
|
||||
try {
|
||||
switch(message->getId()) {
|
||||
case PeerMessage::KEEP_ALIVE:
|
||||
|
@ -272,16 +270,16 @@ void PeerInteractionCommand::receiveMessage() {
|
|||
if(!Piece::isNull(piece) && !RequestSlot::isNull(slot)) {
|
||||
long long int offset =
|
||||
((long long int)message->getIndex())*e->torrentMan->pieceLength+message->getBegin();
|
||||
e->logger->debug("CUID#%d - write block length = %d, offset=%lld",
|
||||
cuid, message->getBlockLength(), offset);
|
||||
logger->debug("CUID#%d - write block length = %d, offset=%lld",
|
||||
cuid, message->getBlockLength(), offset);
|
||||
e->torrentMan->diskAdaptor->writeData(message->getBlock(),
|
||||
message->getBlockLength(),
|
||||
offset);
|
||||
piece.completeBlock(slot.getBlockIndex());
|
||||
sendMessageQueue->deleteRequestSlot(slot);
|
||||
e->torrentMan->updatePiece(piece);
|
||||
e->logger->debug("CUID#%d - setting piece bit index=%d", cuid,
|
||||
slot.getBlockIndex());
|
||||
logger->debug("CUID#%d - setting piece bit index=%d", cuid,
|
||||
slot.getBlockIndex());
|
||||
e->torrentMan->addDeltaDownloadLength(message->getBlockLength());
|
||||
if(piece.pieceComplete()) {
|
||||
if(checkPieceHash(piece)) {
|
||||
|
@ -302,14 +300,14 @@ void PeerInteractionCommand::receiveMessage() {
|
|||
}
|
||||
|
||||
void PeerInteractionCommand::onGotNewPiece() {
|
||||
e->logger->info(MSG_GOT_NEW_PIECE, cuid, piece.getIndex());
|
||||
logger->info(MSG_GOT_NEW_PIECE, cuid, piece.getIndex());
|
||||
e->torrentMan->completePiece(piece);
|
||||
e->torrentMan->advertisePiece(cuid, piece.getIndex());
|
||||
piece = Piece::nullPiece;
|
||||
}
|
||||
|
||||
void PeerInteractionCommand::onGotWrongPiece() {
|
||||
e->logger->error(MSG_GOT_WRONG_PIECE, cuid, piece.getIndex());
|
||||
logger->error(MSG_GOT_WRONG_PIECE, cuid, piece.getIndex());
|
||||
erasePieceOnDisk(piece);
|
||||
piece.clearAllBlock();
|
||||
e->torrentMan->updatePiece(piece);
|
||||
|
@ -336,12 +334,12 @@ Piece PeerInteractionCommand::getNewPieceAndSendInterest() {
|
|||
sendMessageQueue->cancelAllRequest();
|
||||
Piece piece = e->torrentMan->getMissingPiece(peer);
|
||||
if(Piece::isNull(piece)) {
|
||||
e->logger->debug("CUID#%d - try to send not-interested", cuid);
|
||||
logger->debug("CUID#%d - try to send not-interested", cuid);
|
||||
PendingMessage pendingMessage(PeerMessage::NOT_INTERESTED, peerConnection);
|
||||
sendMessageQueue->addPendingMessage(pendingMessage);
|
||||
} else {
|
||||
e->logger->debug("CUID#%d - starting download for piece index=%d", cuid, piece.getIndex());
|
||||
e->logger->debug("CUID#%d - try to send interested", cuid);
|
||||
logger->debug("CUID#%d - starting download for piece index=%d", cuid, piece.getIndex());
|
||||
logger->debug("CUID#%d - try to send interested", cuid);
|
||||
PendingMessage pendingMessage(PeerMessage::INTERESTED, peerConnection);
|
||||
sendMessageQueue->addPendingMessage(pendingMessage);
|
||||
}
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
#include "PeerInteractionCommand.h"
|
||||
|
||||
PeerListenCommand::PeerListenCommand(int cuid, TorrentDownloadEngine* e)
|
||||
:Command(cuid), e(e), socket(NULL) {
|
||||
}
|
||||
:Command(cuid), e(e), socket(NULL) {}
|
||||
|
||||
PeerListenCommand::~PeerListenCommand() {
|
||||
if(socket != NULL) {
|
||||
|
@ -40,12 +39,12 @@ int PeerListenCommand::bindPort(int portRangeStart, int portRangeEnd) {
|
|||
try {
|
||||
socket = new Socket();
|
||||
socket->beginListen(port);
|
||||
e->logger->info("CUID#%d - using port %d for accepting new connections",
|
||||
cuid, port);
|
||||
logger->info("CUID#%d - using port %d for accepting new connections",
|
||||
cuid, port);
|
||||
return port;
|
||||
} catch(Exception* ex) {
|
||||
e->logger->error("CUID#%d - an error occurred while binding port=%d",
|
||||
ex, cuid, port);
|
||||
logger->error("CUID#%d - an error occurred while binding port=%d",
|
||||
ex, cuid, port);
|
||||
delete ex;
|
||||
delete socket;
|
||||
socket = NULL;
|
||||
|
@ -75,14 +74,14 @@ bool PeerListenCommand::execute() {
|
|||
new PeerInteractionCommand(newCuid, peer, e, peerSocket,
|
||||
PeerInteractionCommand::RECEIVER_WAIT_HANDSHAKE);
|
||||
e->commands.push(command);
|
||||
e->logger->debug("CUID#%d - incoming connection, adding new command CUID#%d", cuid, newCuid);
|
||||
logger->debug("CUID#%d - incoming connection, adding new command CUID#%d", cuid, newCuid);
|
||||
} else {
|
||||
delete peer;
|
||||
}
|
||||
}
|
||||
delete peerSocket;
|
||||
} catch(Exception* ex) {
|
||||
e->logger->error("CUID#%d - error in accepting connection", ex, cuid);
|
||||
logger->error("CUID#%d - error in accepting connection", ex, cuid);
|
||||
delete ex;
|
||||
if(peerSocket != NULL) {
|
||||
delete peerSocket;
|
||||
|
|
|
@ -29,7 +29,6 @@ class PeerListenCommand : public Command {
|
|||
private:
|
||||
TorrentDownloadEngine* e;
|
||||
Socket* socket;
|
||||
|
||||
public:
|
||||
PeerListenCommand(int cuid, TorrentDownloadEngine* e);
|
||||
~PeerListenCommand();
|
||||
|
|
|
@ -20,6 +20,19 @@
|
|||
*/
|
||||
/* copyright --> */
|
||||
#include "RequestSlotMan.h"
|
||||
#include "LogFactory.h"
|
||||
|
||||
RequestSlotMan::RequestSlotMan(int cuid,
|
||||
PendingMessages* pendingMessages,
|
||||
PeerConnection* peerConnection,
|
||||
TorrentMan* torrentMan):
|
||||
cuid(cuid),
|
||||
timeout(DEFAULT_TIME_OUT),
|
||||
pendingMessages(pendingMessages),
|
||||
peerConnection(peerConnection),
|
||||
torrentMan(torrentMan) {
|
||||
logger = LogFactory::getInstance();
|
||||
}
|
||||
|
||||
void RequestSlotMan::addRequestSlot(const RequestSlot& requestSlot) {
|
||||
requestSlots.push_back(requestSlot);
|
||||
|
|
|
@ -48,10 +48,7 @@ public:
|
|||
RequestSlotMan(int cuid,
|
||||
PendingMessages* pendingMessages,
|
||||
PeerConnection* peerConnection,
|
||||
TorrentMan* torrentMan,
|
||||
const Logger* logger):cuid(cuid), timeout(DEFAULT_TIME_OUT),
|
||||
pendingMessages(pendingMessages), peerConnection(peerConnection),
|
||||
torrentMan(torrentMan), logger(logger) {}
|
||||
TorrentMan* torrentMan);
|
||||
~RequestSlotMan() {}
|
||||
|
||||
void addRequestSlot(const RequestSlot& requestSlot);
|
||||
|
|
|
@ -21,16 +21,19 @@
|
|||
/* copyright --> */
|
||||
#include "SegmentMan.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include "Util.h"
|
||||
#include "File.h"
|
||||
#include "message.h"
|
||||
#include "prefs.h"
|
||||
#include "LogFactory.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
SegmentMan::SegmentMan():totalSize(0),isSplittable(true),downloadStarted(false),dir(".") {}
|
||||
SegmentMan::SegmentMan():totalSize(0),isSplittable(true),downloadStarted(false),dir(".") {
|
||||
logger = LogFactory::getInstance();
|
||||
}
|
||||
|
||||
SegmentMan::~SegmentMan() {}
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ using namespace std;
|
|||
*/
|
||||
class SegmentMan {
|
||||
private:
|
||||
const Logger* logger;
|
||||
|
||||
void read(FILE* file);
|
||||
FILE* openSegFile(string segFilename, string mode) const;
|
||||
public:
|
||||
|
@ -81,7 +83,6 @@ public:
|
|||
*/
|
||||
string ufilename;
|
||||
|
||||
const Logger* logger;
|
||||
const Option* option;
|
||||
SegmentSplitter* splitter;
|
||||
|
||||
|
|
|
@ -21,6 +21,11 @@
|
|||
/* copyright --> */
|
||||
#include "SegmentSplitter.h"
|
||||
#include "Util.h"
|
||||
#include "LogFactory.h"
|
||||
|
||||
SegmentSplitter::SegmentSplitter() {
|
||||
logger = LogFactory::getInstance();
|
||||
}
|
||||
|
||||
void SegmentSplitter::split(Segment& seg, int cuid, Segment& s) const {
|
||||
long long int nep = (s.ep-(s.sp+s.ds))/2+(s.sp+s.ds);
|
||||
|
|
|
@ -29,11 +29,11 @@
|
|||
class SegmentSplitter {
|
||||
protected:
|
||||
long long int minSegmentSize;
|
||||
const Logger* logger;
|
||||
|
||||
void split(Segment& seg, int cuid, Segment& s) const;
|
||||
public:
|
||||
const Logger* logger;
|
||||
|
||||
SegmentSplitter();
|
||||
virtual ~SegmentSplitter() {}
|
||||
virtual bool splitSegment(Segment& newSegment, int cuid, Segments& segments) = 0;
|
||||
void setMinSegmentSize(long long int size) { minSegmentSize = size; }
|
||||
|
|
|
@ -20,13 +20,14 @@
|
|||
*/
|
||||
/* copyright --> */
|
||||
#include "SendMessageQueue.h"
|
||||
#include "LogFactory.h"
|
||||
|
||||
SendMessageQueue::SendMessageQueue(int cuid, PeerConnection* peerConnection,
|
||||
TorrentMan* torrentMan,
|
||||
const Logger* logger)
|
||||
:cuid(cuid), logger(logger) {
|
||||
TorrentMan* torrentMan)
|
||||
:cuid(cuid) {
|
||||
requestSlotMan = new RequestSlotMan(cuid, &pendingMessages, peerConnection,
|
||||
torrentMan, logger);
|
||||
torrentMan);
|
||||
logger = LogFactory::getInstance();
|
||||
}
|
||||
|
||||
SendMessageQueue::~SendMessageQueue() {
|
||||
|
|
|
@ -33,7 +33,7 @@ private:
|
|||
const Logger* logger;
|
||||
public:
|
||||
SendMessageQueue(int cuid, PeerConnection* peerConnection,
|
||||
TorrentMan* torrentMan, const Logger* logger);
|
||||
TorrentMan* torrentMan);
|
||||
~SendMessageQueue();
|
||||
|
||||
void send();
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "CopyDiskAdaptor.h"
|
||||
#include "DirectDiskAdaptor.h"
|
||||
#include "MultiDiskAdaptor.h"
|
||||
#include "LogFactory.h"
|
||||
#include <errno.h>
|
||||
#include <libgen.h>
|
||||
#include <string.h>
|
||||
|
@ -49,7 +50,9 @@ TorrentMan::TorrentMan():bitfield(NULL),
|
|||
interval(DEFAULT_ANNOUNCE_INTERVAL),
|
||||
minInterval(DEFAULT_ANNOUNCE_MIN_INTERVAL),
|
||||
complete(0), incomplete(0),
|
||||
connections(0), diskAdaptor(NULL) {}
|
||||
connections(0), diskAdaptor(NULL) {
|
||||
logger = LogFactory::getInstance();
|
||||
}
|
||||
|
||||
TorrentMan::~TorrentMan() {
|
||||
if(bitfield != NULL) {
|
||||
|
|
|
@ -73,6 +73,7 @@ private:
|
|||
Haves haves;
|
||||
UsedPieces usedPieces;
|
||||
bool setupComplete;
|
||||
const Logger* logger;
|
||||
|
||||
FILE* openSegFile(string segFilename, string mode) const;
|
||||
void read(FILE* file);
|
||||
|
@ -100,7 +101,6 @@ public:
|
|||
TorrentMan();
|
||||
~TorrentMan();
|
||||
|
||||
const Logger* logger;
|
||||
DiskAdaptor* diskAdaptor;
|
||||
const Option* option;
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ bool TrackerDownloadCommand::executeInternal(Segment seg) {
|
|||
|| te == NULL && len == e->segmentMan->totalSize
|
||||
|| bufSize == 0) {
|
||||
if(te != NULL) te->end();
|
||||
e->logger->info(MSG_DOWNLOAD_COMPLETED, cuid);
|
||||
logger->info(MSG_DOWNLOAD_COMPLETED, cuid);
|
||||
MetaEntry* entry = MetaFileUtil::bdecoding(res, len);
|
||||
e->commands.push(new TrackerUpdateCommand(cuid, req, (TorrentDownloadEngine*)e, entry));
|
||||
return true;
|
||||
|
|
|
@ -31,7 +31,8 @@
|
|||
TrackerUpdateCommand::TrackerUpdateCommand(int cuid, Request* req,
|
||||
TorrentDownloadEngine* e,
|
||||
MetaEntry* trackerResponse)
|
||||
:Command(cuid), req(req), e(e), trackerResponse(trackerResponse) {}
|
||||
:Command(cuid), req(req), e(e), trackerResponse(trackerResponse) {
|
||||
}
|
||||
|
||||
TrackerUpdateCommand::~TrackerUpdateCommand() {
|
||||
delete trackerResponse;
|
||||
|
@ -45,22 +46,22 @@ bool TrackerUpdateCommand::execute() {
|
|||
}
|
||||
Data* warningMessage = (Data*)response->get("warning message");
|
||||
if(warningMessage != NULL) {
|
||||
e->logger->warn(MSG_TRACKER_WARNING_MESSAGE, cuid, warningMessage->toString().c_str());
|
||||
logger->warn(MSG_TRACKER_WARNING_MESSAGE, cuid, warningMessage->toString().c_str());
|
||||
}
|
||||
Data* trackerId = (Data*)response->get("tracker id");
|
||||
if(trackerId != NULL) {
|
||||
e->torrentMan->trackerId = trackerId->toString();
|
||||
e->logger->debug("CUID#%d - Tracker ID:%s", cuid, e->torrentMan->trackerId.c_str());
|
||||
logger->debug("CUID#%d - Tracker ID:%s", cuid, e->torrentMan->trackerId.c_str());
|
||||
}
|
||||
Data* interval = (Data*)response->get("interval");
|
||||
if(interval != NULL) {
|
||||
e->torrentMan->interval = interval->toInt();
|
||||
e->logger->debug("CUID#%d - interval:%d", cuid, e->torrentMan->interval);
|
||||
logger->debug("CUID#%d - interval:%d", cuid, e->torrentMan->interval);
|
||||
}
|
||||
Data* minInterval = (Data*)response->get("min interval");
|
||||
if(minInterval != NULL) {
|
||||
e->torrentMan->minInterval = minInterval->toInt();
|
||||
e->logger->debug("CUID#%d - min interval:%d", cuid, e->torrentMan->minInterval);
|
||||
logger->debug("CUID#%d - min interval:%d", cuid, e->torrentMan->minInterval);
|
||||
}
|
||||
if(e->torrentMan->minInterval > e->torrentMan->interval) {
|
||||
e->torrentMan->minInterval = e->torrentMan->interval;
|
||||
|
@ -68,12 +69,12 @@ bool TrackerUpdateCommand::execute() {
|
|||
Data* complete = (Data*)response->get("complete");
|
||||
if(complete != NULL) {
|
||||
e->torrentMan->complete = complete->toInt();
|
||||
e->logger->debug("CUID#%d - complete:%d", cuid, e->torrentMan->complete);
|
||||
logger->debug("CUID#%d - complete:%d", cuid, e->torrentMan->complete);
|
||||
}
|
||||
Data* incomplete = (Data*)response->get("incomplete");
|
||||
if(incomplete != NULL) {
|
||||
e->torrentMan->incomplete = incomplete->toInt();
|
||||
e->logger->debug("CUID#%d - incomplete:%d", cuid, e->torrentMan->incomplete);
|
||||
logger->debug("CUID#%d - incomplete:%d", cuid, e->torrentMan->incomplete);
|
||||
}
|
||||
Data* peers = (Data*)response->get("peers");
|
||||
if(peers != NULL) {
|
||||
|
@ -90,14 +91,14 @@ bool TrackerUpdateCommand::execute() {
|
|||
Peer* peer = new Peer(ipaddr, port, e->torrentMan->pieceLength,
|
||||
e->torrentMan->getTotalLength());
|
||||
if(e->torrentMan->addPeer(peer)) {
|
||||
e->logger->debug("CUID#%d - adding peer %s:%d", cuid,
|
||||
logger->debug("CUID#%d - adding peer %s:%d", cuid,
|
||||
peer->ipaddr.c_str(), peer->port);
|
||||
} else {
|
||||
delete peer;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
e->logger->info("CUID#%d - no peer list received.", cuid);
|
||||
logger->info("CUID#%d - no peer list received.", cuid);
|
||||
}
|
||||
while(e->torrentMan->isPeerAvailable() &&
|
||||
e->torrentMan->connections < MAX_PEER_UPDATE) {
|
||||
|
@ -106,7 +107,7 @@ bool TrackerUpdateCommand::execute() {
|
|||
peer->cuid = newCuid;
|
||||
PeerInitiateConnectionCommand* command = new PeerInitiateConnectionCommand(newCuid, peer, e);
|
||||
e->commands.push(command);
|
||||
e->logger->debug("CUID#%d - adding new command CUID#%d", cuid, newCuid);
|
||||
logger->debug("CUID#%d - adding new command CUID#%d", cuid, newCuid);
|
||||
}
|
||||
if(req->getTrackerEvent() == Request::STARTED) {
|
||||
req->setTrackerEvent(Request::AUTO);
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
|
||||
TrackerWatcherCommand::TrackerWatcherCommand(int cuid, Request* req,
|
||||
TorrentDownloadEngine* e):
|
||||
Command(cuid), req(req), e(e) {}
|
||||
Command(cuid), req(req), e(e) {
|
||||
}
|
||||
|
||||
TrackerWatcherCommand::~TrackerWatcherCommand() {}
|
||||
|
||||
|
@ -34,8 +35,8 @@ bool TrackerWatcherCommand::execute() {
|
|||
Command* command = new TrackerInitCommand(e->torrentMan->getNewCuid(),
|
||||
req,
|
||||
e);
|
||||
e->logger->info("CUID#%d - creating new tracker request command #%d", cuid,
|
||||
command->getCuid());
|
||||
logger->info("CUID#%d - creating new tracker request command #%d", cuid,
|
||||
command->getCuid());
|
||||
e->commands.push(command);
|
||||
|
||||
SleepCommand* slpCommand = new SleepCommand(cuid, e, this,
|
||||
|
|
20
src/main.cc
20
src/main.cc
|
@ -25,7 +25,7 @@
|
|||
#include "SegmentMan.h"
|
||||
#include "TorrentMan.h"
|
||||
#include "SplitSlowestSegmentSplitter.h"
|
||||
#include "SimpleLogger.h"
|
||||
#include "LogFactory.h"
|
||||
#include "common.h"
|
||||
#include "DefaultDiskWriter.h"
|
||||
#include "Util.h"
|
||||
|
@ -533,14 +533,12 @@ int main(int argc, char* argv[]) {
|
|||
gnutls_global_init();
|
||||
#endif // HAVE_LIBGNUTLS
|
||||
srandom(time(NULL));
|
||||
SimpleLogger* logger;
|
||||
if(stdoutLog) {
|
||||
logger = new SimpleLogger(stdout);
|
||||
LogFactory::setLogFile("/dev/stdout");
|
||||
} else if(logfile.size()) {
|
||||
logger = new SimpleLogger(logfile);
|
||||
} else {
|
||||
logger = new SimpleLogger("/dev/null");
|
||||
LogFactory::setLogFile(logfile);
|
||||
}
|
||||
|
||||
SegmentSplitter* splitter = new SplitSlowestSegmentSplitter();
|
||||
splitter->setMinSegmentSize(op->getAsLLInt(PREF_MIN_SEGMENT_SIZE));
|
||||
|
||||
|
@ -552,15 +550,12 @@ int main(int argc, char* argv[]) {
|
|||
setSignalHander(SIGINT, handler);
|
||||
setSignalHander(SIGTERM, handler);
|
||||
|
||||
splitter->logger = logger;
|
||||
e = new ConsoleDownloadEngine();
|
||||
e->logger = logger;
|
||||
e->option = op;
|
||||
e->diskWriter = new DefaultDiskWriter();
|
||||
e->segmentMan = new SegmentMan();
|
||||
e->segmentMan->dir = dir;
|
||||
e->segmentMan->ufilename = ufilename;
|
||||
e->segmentMan->logger = logger;
|
||||
e->segmentMan->option = op;
|
||||
e->segmentMan->splitter = splitter;
|
||||
|
||||
|
@ -601,16 +596,13 @@ int main(int argc, char* argv[]) {
|
|||
req->isTorrent = true;
|
||||
req->setTrackerEvent(Request::STARTED);
|
||||
te = new TorrentConsoleDownloadEngine();
|
||||
te->logger = logger;
|
||||
te->option = op;
|
||||
te->diskWriter = new DefaultDiskWriter();
|
||||
te->segmentMan = new SegmentMan();
|
||||
te->segmentMan->logger = logger;
|
||||
te->segmentMan->option = op;
|
||||
te->segmentMan->splitter = splitter;
|
||||
te->torrentMan = new TorrentMan();
|
||||
te->torrentMan->setStoreDir(dir);
|
||||
te->torrentMan->logger = logger;
|
||||
te->torrentMan->option = op;
|
||||
string targetTorrentFile = torrentFile.empty() ?
|
||||
downloadedTorrentFile : torrentFile;
|
||||
|
@ -662,11 +654,9 @@ int main(int argc, char* argv[]) {
|
|||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
delete(logger);
|
||||
delete(op);
|
||||
delete(splitter);
|
||||
|
||||
delete(LogFactory::getInstance());
|
||||
#ifdef HAVE_LIBGNUTLS
|
||||
gnutls_global_deinit();
|
||||
#endif // HAVE_LIBGNUTLS
|
||||
|
|
Loading…
Reference in New Issue