mirror of https://github.com/aria2/aria2
To add TrackerUpdateCommand with which replaces
CompactTrackerResponseProcessor: * src/TrackerWatcherCommand.h (req): Removed. * src/TrackerWatcherCommand.cc (execute): Send a request to tracker if the number of peer connections are less than 30. * src/ByteArrayDiskWriter.h (readData): Implemented. * src/SegmentMan.h (diskWriter): New function. * src/SegmentMan.cc (init): Added a call to diskWriter->closeFile() * src/main.cc : Removed #include "CompactTrackerResponseProcessor.h" (main): Use TrackerUpdateCommand. * src/TorrentMan.h (CompactTrackerResponseProcessor): Removed. (req): New variable. (setTrackerResponseProcessor): Removed. (getTrackerResponseProcessor): Removed. (processTrackerResponse): Removed. * src/DownloadEngine.h (diskWriter): Removed. * src/TorrentDownloadEngine.cc (afterEachIteration): Removed a call to torrentMan->processTrackerResponse(). To add Util::expandBuffer: * src/ByteArrayDiskWriter.h (expandBuffer): Removed. * src/ByteArrayDiskWriter.cc (writeData): Use Util::expandBuffer(). * src/Util.h (expandBuffer): New function. To fix the bug that causes segmentation fault when "-l ." is specified in command-line option: * src/SimpleLogger.h (SimpleLogger): Removed "filename" argument. (openFile): New function. (closeFile): New function. * src/SimpleLogger.cc (SimpleLogger): Removed fopen. (~SimpleLogger): Call closeFile(); * src/LogFactory.cc (getInstance): Added a call to slogger->openFile(). * src/main.cc (main): Added a check to see logger is configured properly. To enable HTTP authentication without specifying "--http-auth-scheme" * src/prefs.h (PREF_HTTP_AUTH_ENABLED): New definition. * src/HttpConnection.cc (createRequest): Send Authorization header if PREF_HTTP_AUTH_ENABLED == V_TRUE. * src/main.cc (main): Preset PREF_HTTP_AUTH_SCHEME to V_TRUE If "--http-user" is specified, set PREF_HTTP_AUTH_ENABLED to V_TRUE * src/Peer.cc (shouldChoke): Updated algorithm. * src/message.h (EX_AUTH_FAILED): New definition. (EX_FILE_OPEN): New definition. * src/HttpResponseCommand.cc (checkResponse): Throw DlAbortEx if status == 401. (handleDefaultEncoding): Added a call to diskWriter->initAndOpenFile() if req->isTorrent == true. * src/main.cc (handler): Removed the check to see e->diskWriter != NULL (torrentHandler): Removed the check to see diskAdaptor != NULL. * src/AbstractDiskWriter.cc (openExistingFile): Updated messsage. (createFile): Updated message.pull/1/head
parent
195aff51ba
commit
e199bf8898
63
ChangeLog
63
ChangeLog
|
@ -1,3 +1,66 @@
|
||||||
|
2006-04-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
To add TrackerUpdateCommand with which replaces
|
||||||
|
CompactTrackerResponseProcessor:
|
||||||
|
|
||||||
|
* src/TrackerWatcherCommand.h (req): Removed.
|
||||||
|
* src/TrackerWatcherCommand.cc (execute): Send a request to tracker
|
||||||
|
if the number of peer connections are less than 30.
|
||||||
|
* src/ByteArrayDiskWriter.h (readData): Implemented.
|
||||||
|
* src/SegmentMan.h (diskWriter): New function.
|
||||||
|
* src/SegmentMan.cc (init): Added a call to diskWriter->closeFile()
|
||||||
|
* src/main.cc : Removed #include "CompactTrackerResponseProcessor.h"
|
||||||
|
(main): Use TrackerUpdateCommand.
|
||||||
|
* src/TorrentMan.h (CompactTrackerResponseProcessor): Removed.
|
||||||
|
(req): New variable.
|
||||||
|
(setTrackerResponseProcessor): Removed.
|
||||||
|
(getTrackerResponseProcessor): Removed.
|
||||||
|
(processTrackerResponse): Removed.
|
||||||
|
* src/DownloadEngine.h (diskWriter): Removed.
|
||||||
|
* src/TorrentDownloadEngine.cc (afterEachIteration): Removed a call
|
||||||
|
to torrentMan->processTrackerResponse().
|
||||||
|
|
||||||
|
To add Util::expandBuffer:
|
||||||
|
|
||||||
|
* src/ByteArrayDiskWriter.h (expandBuffer): Removed.
|
||||||
|
* src/ByteArrayDiskWriter.cc (writeData): Use Util::expandBuffer().
|
||||||
|
* src/Util.h (expandBuffer): New function.
|
||||||
|
|
||||||
|
To fix the bug that causes segmentation fault when "-l ." is specified
|
||||||
|
in command-line option:
|
||||||
|
|
||||||
|
* src/SimpleLogger.h (SimpleLogger): Removed "filename" argument.
|
||||||
|
(openFile): New function.
|
||||||
|
(closeFile): New function.
|
||||||
|
* src/SimpleLogger.cc (SimpleLogger): Removed fopen.
|
||||||
|
(~SimpleLogger): Call closeFile();
|
||||||
|
* src/LogFactory.cc (getInstance): Added a call to slogger->openFile().
|
||||||
|
* src/main.cc (main): Added a check to see logger is configured
|
||||||
|
properly.
|
||||||
|
|
||||||
|
To enable HTTP authentication without specifying "--http-auth-scheme"
|
||||||
|
|
||||||
|
* src/prefs.h (PREF_HTTP_AUTH_ENABLED): New definition.
|
||||||
|
* src/HttpConnection.cc (createRequest): Send Authorization header
|
||||||
|
if PREF_HTTP_AUTH_ENABLED == V_TRUE.
|
||||||
|
* src/main.cc (main): Preset PREF_HTTP_AUTH_SCHEME to V_TRUE
|
||||||
|
If "--http-user" is specified, set PREF_HTTP_AUTH_ENABLED to V_TRUE
|
||||||
|
|
||||||
|
* src/Peer.cc (shouldChoke): Updated algorithm.
|
||||||
|
|
||||||
|
* src/message.h (EX_AUTH_FAILED): New definition.
|
||||||
|
(EX_FILE_OPEN): New definition.
|
||||||
|
* src/HttpResponseCommand.cc (checkResponse): Throw DlAbortEx
|
||||||
|
if status == 401.
|
||||||
|
(handleDefaultEncoding): Added a call to diskWriter->initAndOpenFile()
|
||||||
|
if req->isTorrent == true.
|
||||||
|
|
||||||
|
* src/main.cc (handler): Removed the check to see e->diskWriter != NULL
|
||||||
|
(torrentHandler): Removed the check to see diskAdaptor != NULL.
|
||||||
|
|
||||||
|
* src/AbstractDiskWriter.cc (openExistingFile): Updated messsage.
|
||||||
|
(createFile): Updated message.
|
||||||
|
|
||||||
2006-04-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2006-04-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
To add a readout of estimated remaining time to normal HTTP/FTP
|
To add a readout of estimated remaining time to normal HTTP/FTP
|
||||||
|
|
|
@ -20,14 +20,15 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "AbstractDiskWriter.h"
|
#include "AbstractDiskWriter.h"
|
||||||
|
#include "DlAbortEx.h"
|
||||||
|
#include "File.h"
|
||||||
|
#include "Util.h"
|
||||||
|
#include "message.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include "DlAbortEx.h"
|
|
||||||
#include "File.h"
|
|
||||||
#include "Util.h"
|
|
||||||
|
|
||||||
AbstractDiskWriter::AbstractDiskWriter():fd(0) {
|
AbstractDiskWriter::AbstractDiskWriter():fd(0) {
|
||||||
#ifdef ENABLE_SHA1DIGEST
|
#ifdef ENABLE_SHA1DIGEST
|
||||||
|
@ -36,9 +37,7 @@ AbstractDiskWriter::AbstractDiskWriter():fd(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractDiskWriter::~AbstractDiskWriter() {
|
AbstractDiskWriter::~AbstractDiskWriter() {
|
||||||
if(fd >= 0) {
|
closeFile();
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
#ifdef ENABLE_SHA1DIGEST
|
#ifdef ENABLE_SHA1DIGEST
|
||||||
sha1DigestFree(ctx);
|
sha1DigestFree(ctx);
|
||||||
#endif // ENABLE_SHA1DIGEST
|
#endif // ENABLE_SHA1DIGEST
|
||||||
|
@ -63,11 +62,11 @@ void AbstractDiskWriter::closeFile() {
|
||||||
void AbstractDiskWriter::openExistingFile(string filename) {
|
void AbstractDiskWriter::openExistingFile(string filename) {
|
||||||
File f(filename);
|
File f(filename);
|
||||||
if(!f.isFile()) {
|
if(!f.isFile()) {
|
||||||
throw new DlAbortEx(strerror(errno));
|
throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), "file not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if((fd = open(filename.c_str(), O_RDWR, S_IRUSR|S_IWUSR)) < 0) {
|
if((fd = open(filename.c_str(), O_RDWR, S_IRUSR|S_IWUSR)) < 0) {
|
||||||
throw new DlAbortEx(strerror(errno));
|
throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +77,7 @@ void AbstractDiskWriter::createFile(string filename, int addFlags) {
|
||||||
// filename = "index.html";
|
// filename = "index.html";
|
||||||
// }
|
// }
|
||||||
if((fd = open(filename.c_str(), O_CREAT|O_RDWR|O_TRUNC|addFlags, S_IRUSR|S_IWUSR)) < 0) {
|
if((fd = open(filename.c_str(), O_CREAT|O_RDWR|O_TRUNC|addFlags, S_IRUSR|S_IWUSR)) < 0) {
|
||||||
throw new DlAbortEx(strerror(errno));
|
throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "ByteArrayDiskWriter.h"
|
#include "ByteArrayDiskWriter.h"
|
||||||
|
#include "Util.h"
|
||||||
|
|
||||||
ByteArrayDiskWriter::ByteArrayDiskWriter():buf(NULL) {
|
ByteArrayDiskWriter::ByteArrayDiskWriter():buf(NULL) {
|
||||||
}
|
}
|
||||||
|
@ -65,16 +66,23 @@ void ByteArrayDiskWriter::openExistingFile(string filename) {
|
||||||
|
|
||||||
void ByteArrayDiskWriter::writeData(const char* data, int dataLength, long long int position) {
|
void ByteArrayDiskWriter::writeData(const char* data, int dataLength, long long int position) {
|
||||||
if(bufLength+dataLength >= maxBufLength) {
|
if(bufLength+dataLength >= maxBufLength) {
|
||||||
expandBuffer(bufLength+dataLength);
|
maxBufLength = Util::expandBuffer(&buf, bufLength, bufLength+dataLength);
|
||||||
}
|
}
|
||||||
memcpy(buf+bufLength, data, dataLength);
|
memcpy(buf+bufLength, data, dataLength);
|
||||||
bufLength += dataLength;
|
bufLength += dataLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ByteArrayDiskWriter::expandBuffer(int newSize) {
|
int ByteArrayDiskWriter::readData(char* data, int len, long long int position) {
|
||||||
char* newbuf = new char[newSize];
|
if(position >= bufLength) {
|
||||||
memcpy(newbuf, buf, bufLength);
|
return 0;
|
||||||
delete [] buf;
|
|
||||||
buf = newbuf;
|
|
||||||
maxBufLength = newSize;
|
|
||||||
}
|
}
|
||||||
|
int readLength;
|
||||||
|
if(position+len <= bufLength) {
|
||||||
|
readLength = len;
|
||||||
|
} else {
|
||||||
|
readLength = bufLength-position;
|
||||||
|
}
|
||||||
|
memcpy(data, buf+position, readLength);
|
||||||
|
return readLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,12 +32,10 @@ private:
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void clear();
|
void clear();
|
||||||
void expandBuffer(int newSize);
|
|
||||||
public:
|
public:
|
||||||
ByteArrayDiskWriter();
|
ByteArrayDiskWriter();
|
||||||
virtual ~ByteArrayDiskWriter();
|
virtual ~ByteArrayDiskWriter();
|
||||||
|
|
||||||
|
|
||||||
virtual void initAndOpenFile(string filename);
|
virtual void initAndOpenFile(string filename);
|
||||||
|
|
||||||
virtual void openFile(const string& filename);
|
virtual void openFile(const string& filename);
|
||||||
|
@ -48,8 +46,7 @@ public:
|
||||||
|
|
||||||
// position is ignored
|
// position is ignored
|
||||||
virtual void writeData(const char* data, int len, long long int position = 0);
|
virtual void writeData(const char* data, int len, long long int position = 0);
|
||||||
// not implemented yet
|
virtual int readData(char* data, int len, long long int position);
|
||||||
virtual int readData(char* data, int len, long long int position) { return 0; }
|
|
||||||
// not implemented yet
|
// not implemented yet
|
||||||
virtual string sha1Sum(long long int offset, long long int length) { return ""; }
|
virtual string sha1Sum(long long int offset, long long int length) { return ""; }
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ void ConsoleDownloadEngine::calculateStatistics() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleDownloadEngine::onEndOfRun() {
|
void ConsoleDownloadEngine::onEndOfRun() {
|
||||||
diskWriter->closeFile();
|
segmentMan->diskWriter->closeFile();
|
||||||
if(segmentMan->finished()) {
|
if(segmentMan->finished()) {
|
||||||
segmentMan->remove();
|
segmentMan->remove();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -47,10 +47,10 @@ bool DownloadCommand::executeInternal(Segment seg) {
|
||||||
int infbufSize = 4096;
|
int infbufSize = 4096;
|
||||||
char infbuf[infbufSize];
|
char infbuf[infbufSize];
|
||||||
te->inflate(infbuf, infbufSize, buf, bufSize);
|
te->inflate(infbuf, infbufSize, buf, bufSize);
|
||||||
e->diskWriter->writeData(infbuf, infbufSize, seg.sp+seg.ds);
|
e->segmentMan->diskWriter->writeData(infbuf, infbufSize, seg.sp+seg.ds);
|
||||||
seg.ds += infbufSize;
|
seg.ds += infbufSize;
|
||||||
} else {
|
} else {
|
||||||
e->diskWriter->writeData(buf, bufSize, seg.sp+seg.ds);
|
e->segmentMan->diskWriter->writeData(buf, bufSize, seg.sp+seg.ds);
|
||||||
seg.ds += bufSize;
|
seg.ds += bufSize;
|
||||||
}
|
}
|
||||||
// calculate downloading speed
|
// calculate downloading speed
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include "SegmentMan.h"
|
#include "SegmentMan.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "DiskWriter.h"
|
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
@ -57,7 +56,6 @@ public:
|
||||||
bool noWait;
|
bool noWait;
|
||||||
Commands commands;
|
Commands commands;
|
||||||
SegmentMan* segmentMan;
|
SegmentMan* segmentMan;
|
||||||
DiskWriter* diskWriter;
|
|
||||||
const Option* option;
|
const Option* option;
|
||||||
|
|
||||||
DownloadEngine();
|
DownloadEngine();
|
||||||
|
|
|
@ -37,10 +37,10 @@ bool FtpInitiateConnectionCommand::executeInternal(Segment segment) {
|
||||||
bool segFileExists = e->segmentMan->segmentFileExists();
|
bool segFileExists = e->segmentMan->segmentFileExists();
|
||||||
if(segFileExists) {
|
if(segFileExists) {
|
||||||
e->segmentMan->load();
|
e->segmentMan->load();
|
||||||
e->diskWriter->openExistingFile(e->segmentMan->getFilePath());
|
e->segmentMan->diskWriter->openExistingFile(e->segmentMan->getFilePath());
|
||||||
e->segmentMan->downloadStarted = true;
|
e->segmentMan->downloadStarted = true;
|
||||||
} else {
|
} else {
|
||||||
e->diskWriter->initAndOpenFile(e->segmentMan->getFilePath());
|
e->segmentMan->diskWriter->initAndOpenFile(e->segmentMan->getFilePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,11 +83,13 @@ string HttpConnection::createRequest(const Segment& segment) const {
|
||||||
request += "Proxy-Connection: close\r\n";
|
request += "Proxy-Connection: close\r\n";
|
||||||
request += getProxyAuthString();
|
request += getProxyAuthString();
|
||||||
}
|
}
|
||||||
|
if(option->get(PREF_HTTP_AUTH_ENABLED) == V_TRUE) {
|
||||||
if(option->get(PREF_HTTP_AUTH_SCHEME) == V_BASIC) {
|
if(option->get(PREF_HTTP_AUTH_SCHEME) == V_BASIC) {
|
||||||
request += "Authorization: Basic "+
|
request += "Authorization: Basic "+
|
||||||
Base64::encode(option->get(PREF_HTTP_USER)+":"+
|
Base64::encode(option->get(PREF_HTTP_USER)+":"+
|
||||||
option->get(PREF_HTTP_PASSWD))+"\r\n";
|
option->get(PREF_HTTP_PASSWD))+"\r\n";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(req->getPreviousUrl().size()) {
|
if(req->getPreviousUrl().size()) {
|
||||||
request += "Referer: "+req->getPreviousUrl()+"\r\n";
|
request += "Referer: "+req->getPreviousUrl()+"\r\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,10 @@ bool HttpResponseCommand::executeInternal(Segment seg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpResponseCommand::checkResponse(int status, const Segment& segment) {
|
void HttpResponseCommand::checkResponse(int status, const Segment& segment) {
|
||||||
if(!(status < 400 && status >= 300 ||
|
if(status == 401) {
|
||||||
|
throw new DlAbortEx(EX_AUTH_FAILED);
|
||||||
|
}
|
||||||
|
if(!(300 <= status && status < 400 ||
|
||||||
(segment.sp+segment.ds == 0 && status == 200)
|
(segment.sp+segment.ds == 0 && status == 200)
|
||||||
|| (segment.sp+segment.ds > 0 && status == 206))) {
|
|| (segment.sp+segment.ds > 0 && status == 206))) {
|
||||||
throw new DlRetryEx(EX_BAD_STATUS, status);
|
throw new DlRetryEx(EX_BAD_STATUS, status);
|
||||||
|
@ -95,6 +98,7 @@ bool HttpResponseCommand::handleDefaultEncoding(const HttpHeader& headers) {
|
||||||
e->segmentMan->totalSize = size;
|
e->segmentMan->totalSize = size;
|
||||||
e->segmentMan->isSplittable = false;
|
e->segmentMan->isSplittable = false;
|
||||||
e->segmentMan->downloadStarted = true;
|
e->segmentMan->downloadStarted = true;
|
||||||
|
e->segmentMan->diskWriter->initAndOpenFile("/tmp/aria2"+Util::itos(getpid()));
|
||||||
createHttpDownloadCommand();
|
createHttpDownloadCommand();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -109,14 +113,14 @@ bool HttpResponseCommand::handleDefaultEncoding(const HttpHeader& headers) {
|
||||||
e->segmentMan->downloadStarted = true;
|
e->segmentMan->downloadStarted = true;
|
||||||
if(segFileExists) {
|
if(segFileExists) {
|
||||||
e->segmentMan->load();
|
e->segmentMan->load();
|
||||||
e->diskWriter->openExistingFile(e->segmentMan->getFilePath());
|
e->segmentMan->diskWriter->openExistingFile(e->segmentMan->getFilePath());
|
||||||
// send request again to the server with Range header
|
// send request again to the server with Range header
|
||||||
return prepareForRetry(0);
|
return prepareForRetry(0);
|
||||||
} else {
|
} else {
|
||||||
e->segmentMan->totalSize = size;
|
e->segmentMan->totalSize = size;
|
||||||
Segment seg;
|
Segment seg;
|
||||||
e->segmentMan->getSegment(seg, cuid);
|
e->segmentMan->getSegment(seg, cuid);
|
||||||
e->diskWriter->initAndOpenFile(e->segmentMan->getFilePath());
|
e->segmentMan->diskWriter->initAndOpenFile(e->segmentMan->getFilePath());
|
||||||
createHttpDownloadCommand();
|
createHttpDownloadCommand();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +134,7 @@ bool HttpResponseCommand::handleOtherEncoding(string transferEncoding, const Htt
|
||||||
e->segmentMan->totalSize = 0;
|
e->segmentMan->totalSize = 0;
|
||||||
Segment seg;
|
Segment seg;
|
||||||
e->segmentMan->getSegment(seg, cuid);
|
e->segmentMan->getSegment(seg, cuid);
|
||||||
e->diskWriter->initAndOpenFile(e->segmentMan->getFilePath());
|
e->segmentMan->diskWriter->initAndOpenFile(e->segmentMan->getFilePath());
|
||||||
createHttpDownloadCommand(transferEncoding);
|
createHttpDownloadCommand(transferEncoding);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,11 +27,13 @@ Logger* LogFactory::logger = NULL;
|
||||||
|
|
||||||
Logger* LogFactory::getInstance() {
|
Logger* LogFactory::getInstance() {
|
||||||
if(logger == NULL) {
|
if(logger == NULL) {
|
||||||
|
SimpleLogger* slogger = new SimpleLogger();
|
||||||
if(filename.empty()) {
|
if(filename.empty()) {
|
||||||
logger = new SimpleLogger("/dev/null");
|
slogger->openFile("/dev/null");
|
||||||
} else {
|
} else {
|
||||||
logger = new SimpleLogger(filename);
|
slogger->openFile(filename);
|
||||||
}
|
}
|
||||||
|
logger = slogger;
|
||||||
}
|
}
|
||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ SRCS = Socket.cc Socket.h\
|
||||||
MultiDiskAdaptor.cc MultiDiskAdaptor.h\
|
MultiDiskAdaptor.cc MultiDiskAdaptor.h\
|
||||||
FileEntry.h\
|
FileEntry.h\
|
||||||
LogFactory.cc LogFactory.h\
|
LogFactory.cc LogFactory.h\
|
||||||
CompactTrackerResponseProcessor.cc CompactTrackerResponseProcessor.h\
|
TrackerUpdateCommand.cc TrackerUpdateCommand.h\
|
||||||
ByteArrayDiskWriter.cc ByteArrayDiskWriter.h
|
ByteArrayDiskWriter.cc ByteArrayDiskWriter.h
|
||||||
noinst_LIBRARIES = libaria2c.a
|
noinst_LIBRARIES = libaria2c.a
|
||||||
libaria2c_a_SOURCES = $(SRCS)
|
libaria2c_a_SOURCES = $(SRCS)
|
||||||
|
|
|
@ -99,7 +99,7 @@ am__objects_1 = Socket.$(OBJEXT) SocketCore.$(OBJEXT) \
|
||||||
SendMessageQueue.$(OBJEXT) MultiDiskWriter.$(OBJEXT) \
|
SendMessageQueue.$(OBJEXT) MultiDiskWriter.$(OBJEXT) \
|
||||||
DiskAdaptor.$(OBJEXT) CopyDiskAdaptor.$(OBJEXT) \
|
DiskAdaptor.$(OBJEXT) CopyDiskAdaptor.$(OBJEXT) \
|
||||||
DirectDiskAdaptor.$(OBJEXT) MultiDiskAdaptor.$(OBJEXT) \
|
DirectDiskAdaptor.$(OBJEXT) MultiDiskAdaptor.$(OBJEXT) \
|
||||||
LogFactory.$(OBJEXT) CompactTrackerResponseProcessor.$(OBJEXT) \
|
LogFactory.$(OBJEXT) TrackerUpdateCommand.$(OBJEXT) \
|
||||||
ByteArrayDiskWriter.$(OBJEXT)
|
ByteArrayDiskWriter.$(OBJEXT)
|
||||||
am_libaria2c_a_OBJECTS = $(am__objects_1)
|
am_libaria2c_a_OBJECTS = $(am__objects_1)
|
||||||
libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS)
|
libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS)
|
||||||
|
@ -333,7 +333,7 @@ SRCS = Socket.cc Socket.h\
|
||||||
MultiDiskAdaptor.cc MultiDiskAdaptor.h\
|
MultiDiskAdaptor.cc MultiDiskAdaptor.h\
|
||||||
FileEntry.h\
|
FileEntry.h\
|
||||||
LogFactory.cc LogFactory.h\
|
LogFactory.cc LogFactory.h\
|
||||||
CompactTrackerResponseProcessor.cc CompactTrackerResponseProcessor.h\
|
TrackerUpdateCommand.cc TrackerUpdateCommand.h\
|
||||||
ByteArrayDiskWriter.cc ByteArrayDiskWriter.h
|
ByteArrayDiskWriter.cc ByteArrayDiskWriter.h
|
||||||
|
|
||||||
noinst_LIBRARIES = libaria2c.a
|
noinst_LIBRARIES = libaria2c.a
|
||||||
|
@ -426,7 +426,6 @@ distclean-compile:
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldMan.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldMan.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ByteArrayDiskWriter.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ByteArrayDiskWriter.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ChunkedEncoding.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ChunkedEncoding.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CompactTrackerResponseProcessor.Po@am__quote@
|
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConsoleDownloadEngine.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConsoleDownloadEngine.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieBox.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieBox.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CopyDiskAdaptor.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CopyDiskAdaptor.Po@am__quote@
|
||||||
|
@ -488,6 +487,7 @@ distclean-compile:
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TorrentConsoleDownloadEngine.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TorrentConsoleDownloadEngine.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TorrentDownloadEngine.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TorrentDownloadEngine.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TorrentMan.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TorrentMan.Po@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TrackerUpdateCommand.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TrackerWatcherCommand.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TrackerWatcherCommand.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Util.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Util.Po@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
|
||||||
|
|
|
@ -34,10 +34,7 @@ void Peer::updateBitfield(int index, int operation) {
|
||||||
#define THRESHOLD 1024*1024*2
|
#define THRESHOLD 1024*1024*2
|
||||||
|
|
||||||
bool Peer::shouldChoke() const {
|
bool Peer::shouldChoke() const {
|
||||||
if(bitfield->countBlock()*0.7 < bitfield->countMissingBlock()) {
|
if(bitfield->countBlock()*0.95 < bitfield->countMissingBlock()) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(peerDownload <= pieceLength*10) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// we are always optimistic.
|
// we are always optimistic.
|
||||||
|
|
|
@ -217,4 +217,5 @@ void SegmentMan::init() {
|
||||||
isSplittable = false;
|
isSplittable = false;
|
||||||
downloadStarted = false;
|
downloadStarted = false;
|
||||||
segments.clear();
|
segments.clear();
|
||||||
|
diskWriter->closeFile();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "Segment.h"
|
#include "Segment.h"
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "SegmentSplitter.h"
|
#include "SegmentSplitter.h"
|
||||||
|
#include "DiskWriter.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -85,11 +86,13 @@ public:
|
||||||
|
|
||||||
const Option* option;
|
const Option* option;
|
||||||
SegmentSplitter* splitter;
|
SegmentSplitter* splitter;
|
||||||
|
DiskWriter* diskWriter;
|
||||||
|
|
||||||
SegmentMan();
|
SegmentMan();
|
||||||
~SegmentMan();
|
~SegmentMan();
|
||||||
|
|
||||||
// Initializes totalSize, isSplittable, downloadStarted.
|
// Initializes totalSize, isSplittable, downloadStarted.
|
||||||
|
// Clears command queue. Also, closes diskWriter.
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,9 +21,12 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "SimpleLogger.h"
|
#include "SimpleLogger.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include "DlAbortEx.h"
|
||||||
|
#include "message.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#define WRITE_LOG(LEVEL, MSG) \
|
#define WRITE_LOG(LEVEL, MSG) \
|
||||||
va_list ap;\
|
va_list ap;\
|
||||||
|
@ -37,15 +40,24 @@ va_start(ap, EX);\
|
||||||
writeLog(Logger::LEVEL, MSG, ap, EX);\
|
writeLog(Logger::LEVEL, MSG, ap, EX);\
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
SimpleLogger::SimpleLogger(string filename) {
|
SimpleLogger::SimpleLogger():file(NULL) {}
|
||||||
file = fopen(filename.c_str(), "a");
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleLogger::SimpleLogger(FILE* logfile) {
|
SimpleLogger::SimpleLogger(FILE* logfile) {
|
||||||
file = logfile;
|
file = logfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleLogger::~SimpleLogger() {
|
SimpleLogger::~SimpleLogger() {
|
||||||
|
closeFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleLogger::openFile(const string& filename) {
|
||||||
|
file = fopen(filename.c_str(), "a");
|
||||||
|
if(file == NULL) {
|
||||||
|
throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleLogger::closeFile() {
|
||||||
if(file != NULL) {
|
if(file != NULL) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,12 @@ private:
|
||||||
void writeLog(int level, const char* msg, va_list ap, Exception* e = NULL) const;
|
void writeLog(int level, const char* msg, va_list ap, Exception* e = NULL) const;
|
||||||
FILE* file;
|
FILE* file;
|
||||||
public:
|
public:
|
||||||
SimpleLogger(string filename);
|
SimpleLogger();
|
||||||
SimpleLogger(FILE* logfile);
|
SimpleLogger(FILE* logfile);
|
||||||
~SimpleLogger();
|
~SimpleLogger();
|
||||||
|
|
||||||
|
void openFile(const string& filename);
|
||||||
|
void closeFile();
|
||||||
void debug(const char* msg, ...) const;
|
void debug(const char* msg, ...) const;
|
||||||
void debug(const char* msg, Exception* ex, ...) const;
|
void debug(const char* msg, Exception* ex, ...) const;
|
||||||
void info(const char* msg, ...) const;
|
void info(const char* msg, ...) const;
|
||||||
|
|
|
@ -41,5 +41,4 @@ void TorrentDownloadEngine::afterEachIteration() {
|
||||||
filenameFixed = true;
|
filenameFixed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
torrentMan->processTrackerResponse();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -567,10 +567,3 @@ void TorrentMan::onDownloadComplete() {
|
||||||
finishSelectiveDownloadingMode();
|
finishSelectiveDownloadingMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentMan::processTrackerResponse() {
|
|
||||||
if(responseProcessor->isFeeded()) {
|
|
||||||
responseProcessor->execute();
|
|
||||||
responseProcessor->resetTrackerResponse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
#include "DiskAdaptor.h"
|
#include "DiskAdaptor.h"
|
||||||
#include "CompactTrackerResponseProcessor.h"
|
#include "Request.h"
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -75,7 +75,6 @@ private:
|
||||||
UsedPieces usedPieces;
|
UsedPieces usedPieces;
|
||||||
bool setupComplete;
|
bool setupComplete;
|
||||||
const Logger* logger;
|
const Logger* logger;
|
||||||
CompactTrackerResponseProcessor* responseProcessor;
|
|
||||||
|
|
||||||
FILE* openSegFile(string segFilename, string mode) const;
|
FILE* openSegFile(string segFilename, string mode) const;
|
||||||
void read(FILE* file);
|
void read(FILE* file);
|
||||||
|
@ -101,6 +100,8 @@ public:
|
||||||
int connections;
|
int connections;
|
||||||
// The number of tracker request command currently in the command queue.
|
// The number of tracker request command currently in the command queue.
|
||||||
int trackers;
|
int trackers;
|
||||||
|
// tracker request
|
||||||
|
Request* req;
|
||||||
public:
|
public:
|
||||||
TorrentMan();
|
TorrentMan();
|
||||||
~TorrentMan();
|
~TorrentMan();
|
||||||
|
@ -231,15 +232,6 @@ public:
|
||||||
|
|
||||||
void onDownloadComplete();
|
void onDownloadComplete();
|
||||||
|
|
||||||
void setTrackerResponseProcessor(CompactTrackerResponseProcessor* proc) {
|
|
||||||
this->responseProcessor = proc;
|
|
||||||
}
|
|
||||||
CompactTrackerResponseProcessor* getTrackerResponseProcessor() const {
|
|
||||||
return this->responseProcessor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void processTrackerResponse();
|
|
||||||
|
|
||||||
enum FILE_MODE {
|
enum FILE_MODE {
|
||||||
SINGLE,
|
SINGLE,
|
||||||
MULTI
|
MULTI
|
||||||
|
|
|
@ -24,30 +24,30 @@
|
||||||
#include "InitiateConnectionCommandFactory.h"
|
#include "InitiateConnectionCommandFactory.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
TrackerWatcherCommand::TrackerWatcherCommand(int cuid, Request* req,
|
TrackerWatcherCommand::TrackerWatcherCommand(int cuid,
|
||||||
TorrentDownloadEngine* e):
|
TorrentDownloadEngine* e):
|
||||||
Command(cuid), req(req), e(e) {
|
Command(cuid), e(e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackerWatcherCommand::~TrackerWatcherCommand() {}
|
TrackerWatcherCommand::~TrackerWatcherCommand() {}
|
||||||
|
|
||||||
bool TrackerWatcherCommand::execute() {
|
bool TrackerWatcherCommand::execute() {
|
||||||
if(e->torrentMan->trackers == 0) {
|
if(e->torrentMan->trackers == 0 && e->torrentMan->connections < 30) {
|
||||||
req->resetTryCount();
|
e->torrentMan->req->resetTryCount();
|
||||||
|
|
||||||
if(e->torrentMan->downloadComplete()) {
|
if(e->torrentMan->downloadComplete()) {
|
||||||
if(req->getTrackerEvent() == Request::COMPLETED) {
|
if(e->torrentMan->req->getTrackerEvent() == Request::COMPLETED) {
|
||||||
req->setTrackerEvent(Request::AFTER_COMPLETED);
|
e->torrentMan->req->setTrackerEvent(Request::AFTER_COMPLETED);
|
||||||
} else {
|
} else {
|
||||||
if(req->getTrackerEvent() == Request::STARTED) {
|
if(e->torrentMan->req->getTrackerEvent() == Request::STARTED) {
|
||||||
req->setTrackerEvent(Request::AFTER_COMPLETED);
|
e->torrentMan->req->setTrackerEvent(Request::AFTER_COMPLETED);
|
||||||
} else if(req->getTrackerEvent() != Request::AFTER_COMPLETED) {
|
} else if(e->torrentMan->req->getTrackerEvent() != Request::AFTER_COMPLETED) {
|
||||||
req->setTrackerEvent(Request::COMPLETED);
|
e->torrentMan->req->setTrackerEvent(Request::COMPLETED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string event;
|
string event;
|
||||||
switch(req->getTrackerEvent()) {
|
switch(e->torrentMan->req->getTrackerEvent()) {
|
||||||
case Request::STARTED:
|
case Request::STARTED:
|
||||||
event = "started";
|
event = "started";
|
||||||
break;
|
break;
|
||||||
|
@ -74,8 +74,8 @@ bool TrackerWatcherCommand::execute() {
|
||||||
if(!e->torrentMan->trackerId.empty()) {
|
if(!e->torrentMan->trackerId.empty()) {
|
||||||
url += string("&")+"trackerid="+e->torrentMan->trackerId;
|
url += string("&")+"trackerid="+e->torrentMan->trackerId;
|
||||||
}
|
}
|
||||||
req->setUrl(url);
|
e->torrentMan->req->setUrl(url);
|
||||||
Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(e->torrentMan->getNewCuid(), req, e);
|
Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(e->torrentMan->getNewCuid(), e->torrentMan->req, e);
|
||||||
e->commands.push(command);
|
e->commands.push(command);
|
||||||
e->torrentMan->trackers++;
|
e->torrentMan->trackers++;
|
||||||
logger->info("CUID#%d - creating new tracker request command #%d", cuid,
|
logger->info("CUID#%d - creating new tracker request command #%d", cuid,
|
||||||
|
|
|
@ -24,14 +24,12 @@
|
||||||
|
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
#include "TorrentDownloadEngine.h"
|
#include "TorrentDownloadEngine.h"
|
||||||
#include "Request.h"
|
|
||||||
|
|
||||||
class TrackerWatcherCommand : public Command {
|
class TrackerWatcherCommand : public Command {
|
||||||
private:
|
private:
|
||||||
Request* req;
|
|
||||||
TorrentDownloadEngine* e;
|
TorrentDownloadEngine* e;
|
||||||
public:
|
public:
|
||||||
TrackerWatcherCommand(int cuid, Request* req, TorrentDownloadEngine* e);
|
TrackerWatcherCommand(int cuid, TorrentDownloadEngine* e);
|
||||||
~TrackerWatcherCommand();
|
~TrackerWatcherCommand();
|
||||||
|
|
||||||
bool execute();
|
bool execute();
|
||||||
|
|
|
@ -286,3 +286,11 @@ string Util::secfmt(int sec) {
|
||||||
str += itos(sec)+"s";
|
str += itos(sec)+"s";
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Util::expandBuffer(char** pbuf, int curLength, int newLength) {
|
||||||
|
char* newbuf = new char[newLength];
|
||||||
|
memcpy(newbuf, *pbuf, curLength);
|
||||||
|
delete [] *pbuf;
|
||||||
|
*pbuf = newbuf;
|
||||||
|
return newLength;
|
||||||
|
}
|
||||||
|
|
|
@ -71,6 +71,8 @@ public:
|
||||||
static bool isPowerOf(int num, int base);
|
static bool isPowerOf(int num, int base);
|
||||||
|
|
||||||
static string secfmt(int sec);
|
static string secfmt(int sec);
|
||||||
|
|
||||||
|
static int expandBuffer(char** pbuf, int curLength, int newLength);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _D_UTIL_H_
|
#endif // _D_UTIL_H_
|
||||||
|
|
35
src/main.cc
35
src/main.cc
|
@ -34,7 +34,7 @@
|
||||||
#include "PeerListenCommand.h"
|
#include "PeerListenCommand.h"
|
||||||
#include "TorrentAutoSaveCommand.h"
|
#include "TorrentAutoSaveCommand.h"
|
||||||
#include "TrackerWatcherCommand.h"
|
#include "TrackerWatcherCommand.h"
|
||||||
#include "CompactTrackerResponseProcessor.h"
|
#include "TrackerUpdateCommand.h"
|
||||||
#include "ByteArrayDiskWriter.h"
|
#include "ByteArrayDiskWriter.h"
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -91,9 +91,7 @@ void handler(int signal) {
|
||||||
printf(_("\nstopping application...\n"));
|
printf(_("\nstopping application...\n"));
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
e->segmentMan->save();
|
e->segmentMan->save();
|
||||||
if(e->diskWriter != NULL) {
|
e->segmentMan->diskWriter->closeFile();
|
||||||
e->diskWriter->closeFile();
|
|
||||||
}
|
|
||||||
printf(_("done\n"));
|
printf(_("done\n"));
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
@ -101,9 +99,7 @@ void handler(int signal) {
|
||||||
void torrentHandler(int signal) {
|
void torrentHandler(int signal) {
|
||||||
printf(_("\nstopping application...\n"));
|
printf(_("\nstopping application...\n"));
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
if(te->torrentMan->diskAdaptor != NULL) {
|
|
||||||
te->torrentMan->diskAdaptor->closeFile();
|
te->torrentMan->diskAdaptor->closeFile();
|
||||||
}
|
|
||||||
if(te->torrentMan->downloadComplete() && te->isFilenameFixed()) {
|
if(te->torrentMan->downloadComplete() && te->isFilenameFixed()) {
|
||||||
te->torrentMan->remove();
|
te->torrentMan->remove();
|
||||||
//te->torrentMan->deleteTempFile();
|
//te->torrentMan->deleteTempFile();
|
||||||
|
@ -276,6 +272,7 @@ int main(int argc, char* argv[]) {
|
||||||
op->put(PREF_PEER_CONNECTION_TIMEOUT, "60");
|
op->put(PREF_PEER_CONNECTION_TIMEOUT, "60");
|
||||||
op->put(PREF_MIN_SEGMENT_SIZE, "1048576");// 1M
|
op->put(PREF_MIN_SEGMENT_SIZE, "1048576");// 1M
|
||||||
op->put(PREF_MAX_TRIES, "5");
|
op->put(PREF_MAX_TRIES, "5");
|
||||||
|
op->put(PREF_HTTP_AUTH_SCHEME, V_BASIC);
|
||||||
op->put(PREF_HTTP_PROXY_METHOD, V_TUNNEL);
|
op->put(PREF_HTTP_PROXY_METHOD, V_TUNNEL);
|
||||||
op->put(PREF_FTP_USER, "anonymous");
|
op->put(PREF_FTP_USER, "anonymous");
|
||||||
op->put(PREF_FTP_PASSWD, "ARIA2USER@");
|
op->put(PREF_FTP_PASSWD, "ARIA2USER@");
|
||||||
|
@ -346,6 +343,7 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
op->put(PREF_HTTP_USER, optarg);
|
op->put(PREF_HTTP_USER, optarg);
|
||||||
|
op->put(PREF_HTTP_AUTH_ENABLED, V_TRUE);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
op->put(PREF_HTTP_PASSWD, optarg);
|
op->put(PREF_HTTP_PASSWD, optarg);
|
||||||
|
@ -562,6 +560,14 @@ int main(int argc, char* argv[]) {
|
||||||
} else if(logfile.size()) {
|
} else if(logfile.size()) {
|
||||||
LogFactory::setLogFile(logfile);
|
LogFactory::setLogFile(logfile);
|
||||||
}
|
}
|
||||||
|
// make sure logger is configured properly.
|
||||||
|
try {
|
||||||
|
LogFactory::getInstance();
|
||||||
|
} catch(Exception* ex) {
|
||||||
|
cerr << ex->getMsg() << endl;
|
||||||
|
delete ex;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
SegmentSplitter* splitter = new SplitSlowestSegmentSplitter();
|
SegmentSplitter* splitter = new SplitSlowestSegmentSplitter();
|
||||||
splitter->setMinSegmentSize(op->getAsLLInt(PREF_MIN_SEGMENT_SIZE));
|
splitter->setMinSegmentSize(op->getAsLLInt(PREF_MIN_SEGMENT_SIZE));
|
||||||
|
@ -576,8 +582,8 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
e = new ConsoleDownloadEngine();
|
e = new ConsoleDownloadEngine();
|
||||||
e->option = op;
|
e->option = op;
|
||||||
e->diskWriter = new DefaultDiskWriter();
|
|
||||||
e->segmentMan = new SegmentMan();
|
e->segmentMan = new SegmentMan();
|
||||||
|
e->segmentMan->diskWriter = new DefaultDiskWriter();
|
||||||
e->segmentMan->dir = dir;
|
e->segmentMan->dir = dir;
|
||||||
e->segmentMan->ufilename = ufilename;
|
e->segmentMan->ufilename = ufilename;
|
||||||
e->segmentMan->option = op;
|
e->segmentMan->option = op;
|
||||||
|
@ -607,7 +613,7 @@ int main(int argc, char* argv[]) {
|
||||||
requests.clear();
|
requests.clear();
|
||||||
|
|
||||||
delete(e->segmentMan);
|
delete(e->segmentMan);
|
||||||
delete(e->diskWriter);
|
delete(e->segmentMan->diskWriter);
|
||||||
delete(e);
|
delete(e);
|
||||||
}
|
}
|
||||||
if(!torrentFile.empty() || followTorrent && readyToTorrentMode) {
|
if(!torrentFile.empty() || followTorrent && readyToTorrentMode) {
|
||||||
|
@ -622,16 +628,14 @@ int main(int argc, char* argv[]) {
|
||||||
te = new TorrentConsoleDownloadEngine();
|
te = new TorrentConsoleDownloadEngine();
|
||||||
te->option = op;
|
te->option = op;
|
||||||
ByteArrayDiskWriter* byteArrayDiskWriter = new ByteArrayDiskWriter();
|
ByteArrayDiskWriter* byteArrayDiskWriter = new ByteArrayDiskWriter();
|
||||||
te->diskWriter = byteArrayDiskWriter;
|
|
||||||
te->segmentMan = new SegmentMan();
|
te->segmentMan = new SegmentMan();
|
||||||
|
te->segmentMan->diskWriter = byteArrayDiskWriter;
|
||||||
te->segmentMan->option = op;
|
te->segmentMan->option = op;
|
||||||
te->segmentMan->splitter = splitter;
|
te->segmentMan->splitter = splitter;
|
||||||
te->torrentMan = new TorrentMan();
|
te->torrentMan = new TorrentMan();
|
||||||
te->torrentMan->setStoreDir(dir);
|
te->torrentMan->setStoreDir(dir);
|
||||||
te->torrentMan->option = op;
|
te->torrentMan->option = op;
|
||||||
CompactTrackerResponseProcessor* responseProcessor =
|
te->torrentMan->req = req;
|
||||||
new CompactTrackerResponseProcessor(byteArrayDiskWriter, te, req);
|
|
||||||
te->torrentMan->setTrackerResponseProcessor(responseProcessor);
|
|
||||||
string targetTorrentFile = torrentFile.empty() ?
|
string targetTorrentFile = torrentFile.empty() ?
|
||||||
downloadedTorrentFile : torrentFile;
|
downloadedTorrentFile : torrentFile;
|
||||||
if(op->get(PREF_SHOW_FILES) == V_TRUE) {
|
if(op->get(PREF_SHOW_FILES) == V_TRUE) {
|
||||||
|
@ -666,7 +670,9 @@ int main(int argc, char* argv[]) {
|
||||||
te->torrentMan->setPort(port);
|
te->torrentMan->setPort(port);
|
||||||
te->commands.push(listenCommand);
|
te->commands.push(listenCommand);
|
||||||
te->commands.push(new TrackerWatcherCommand(te->torrentMan->getNewCuid(),
|
te->commands.push(new TrackerWatcherCommand(te->torrentMan->getNewCuid(),
|
||||||
req, te));
|
te));
|
||||||
|
te->commands.push(new TrackerUpdateCommand(te->torrentMan->getNewCuid(),
|
||||||
|
te));
|
||||||
te->commands.push(new TorrentAutoSaveCommand(te->torrentMan->getNewCuid(),
|
te->commands.push(new TorrentAutoSaveCommand(te->torrentMan->getNewCuid(),
|
||||||
te,
|
te,
|
||||||
op->getAsInt(PREF_AUTO_SAVE_INTERVAL)));
|
op->getAsInt(PREF_AUTO_SAVE_INTERVAL)));
|
||||||
|
@ -678,10 +684,9 @@ int main(int argc, char* argv[]) {
|
||||||
printDownloadAbortMessage();
|
printDownloadAbortMessage();
|
||||||
}
|
}
|
||||||
delete(req);
|
delete(req);
|
||||||
delete(responseProcessor);
|
|
||||||
delete(te->segmentMan);
|
delete(te->segmentMan);
|
||||||
|
delete(te->segmentMan->diskWriter);
|
||||||
delete(te->torrentMan);
|
delete(te->torrentMan);
|
||||||
delete(te->diskWriter);
|
|
||||||
delete(te);
|
delete(te);
|
||||||
} catch(Exception* ex) {
|
} catch(Exception* ex) {
|
||||||
cerr << ex->getMsg() << endl;
|
cerr << ex->getMsg() << endl;
|
||||||
|
|
|
@ -67,7 +67,11 @@
|
||||||
#define EX_TRANSFER_ENCODING_NOT_SUPPORTED _("Transfer encoding %s is not supported.")
|
#define EX_TRANSFER_ENCODING_NOT_SUPPORTED _("Transfer encoding %s is not supported.")
|
||||||
#define EX_SSL_INIT_FAILURE _("SSL initialization failed.")
|
#define EX_SSL_INIT_FAILURE _("SSL initialization failed.")
|
||||||
#define EX_SIZE_MISMATCH _("Size mismatch %lld != %lld")
|
#define EX_SIZE_MISMATCH _("Size mismatch %lld != %lld")
|
||||||
|
#define EX_AUTH_FAILED "Authorization failed."
|
||||||
#define EX_GOT_EOF _("Got EOF from the server.")
|
#define EX_GOT_EOF _("Got EOF from the server.")
|
||||||
#define EX_EOF_FROM_PEER "Got EOF from peer."
|
#define EX_EOF_FROM_PEER "Got EOF from peer."
|
||||||
#define EX_MULFORMED_META_INFO "Mulformed meta info."
|
#define EX_MULFORMED_META_INFO "Mulformed meta info."
|
||||||
|
|
||||||
|
#define EX_FILE_OPEN "Error occurred while opening <%s>, cause: %s"
|
||||||
|
|
||||||
#endif // _D_MESSAGE_H_
|
#endif // _D_MESSAGE_H_
|
||||||
|
|
|
@ -68,6 +68,8 @@
|
||||||
// values: basic
|
// values: basic
|
||||||
#define PREF_HTTP_AUTH_SCHEME "http_auth_scheme"
|
#define PREF_HTTP_AUTH_SCHEME "http_auth_scheme"
|
||||||
# define V_BASIC "basic"
|
# define V_BASIC "basic"
|
||||||
|
// values: true | false
|
||||||
|
#define PREF_HTTP_AUTH_ENABLED "http_auth_enabled"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP proxy related preferences
|
* HTTP proxy related preferences
|
||||||
|
|
Loading…
Reference in New Issue