2006-02-17 13:35:04 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-02-17 13:35:04 +00:00
|
|
|
*
|
|
|
|
* 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
|
2006-09-21 15:31:24 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
2006-02-17 13:35:04 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "DownloadEngine.h"
|
2008-05-08 11:18:36 +00:00
|
|
|
#ifdef ENABLE_ASYNC_DNS
|
|
|
|
#include "AsyncNameResolver.h"
|
|
|
|
#endif // ENABLE_ASYNC_DNS
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "StatCalc.h"
|
|
|
|
#include "RequestGroup.h"
|
|
|
|
#include "RequestGroupMan.h"
|
|
|
|
#include "FileAllocationMan.h"
|
|
|
|
#include "CheckIntegrityMan.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "DownloadResult.h"
|
|
|
|
#include "StatCalc.h"
|
2006-04-17 16:17:20 +00:00
|
|
|
#include "LogFactory.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Logger.h"
|
2006-08-07 16:28:41 +00:00
|
|
|
#include "TimeA2.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "a2time.h"
|
|
|
|
#include "Socket.h"
|
2008-04-22 08:52:47 +00:00
|
|
|
#include "Util.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include <signal.h>
|
2008-02-08 15:53:45 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace aria2 {
|
2006-02-17 13:35:04 +00:00
|
|
|
|
2007-12-07 13:33:59 +00:00
|
|
|
// 0 ... running
|
|
|
|
// 1 ... stop signal detected
|
|
|
|
// 2 ... stop signal processed by DownloadEngine
|
|
|
|
// 3 ... 2nd stop signal(force shutdown) detected
|
|
|
|
// 4 ... 2nd stop signal processed by DownloadEngine
|
|
|
|
volatile sig_atomic_t globalHaltRequested = 0;
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
SocketEntry::SocketEntry(const SocketHandle& socket,
|
|
|
|
Command* command,
|
|
|
|
TYPE type):
|
|
|
|
socket(socket), command(command), type(type) {}
|
|
|
|
|
|
|
|
bool SocketEntry::operator==(const SocketEntry& entry)
|
|
|
|
{
|
|
|
|
return socket == entry.socket &&
|
|
|
|
command == entry.command &&
|
|
|
|
type == entry.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ENABLE_ASYNC_DNS
|
2008-05-08 11:18:36 +00:00
|
|
|
AsyncNameResolverEntry::AsyncNameResolverEntry
|
|
|
|
(const SharedHandle<AsyncNameResolver>& nameResolver,
|
|
|
|
Command* command):
|
2007-10-11 16:58:24 +00:00
|
|
|
nameResolver(nameResolver), command(command) {}
|
|
|
|
|
2008-05-08 11:18:36 +00:00
|
|
|
bool AsyncNameResolverEntry::operator==(const AsyncNameResolverEntry& entry)
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
|
|
|
return nameResolver == entry.nameResolver &&
|
|
|
|
command == entry.command;
|
|
|
|
}
|
|
|
|
#endif // ENABLE_ASYNC_DNS
|
2006-02-17 13:35:04 +00:00
|
|
|
|
2007-05-20 13:51:52 +00:00
|
|
|
DownloadEngine::DownloadEngine():logger(LogFactory::getInstance()),
|
2007-10-11 16:58:24 +00:00
|
|
|
_haltRequested(false),
|
2008-04-20 05:42:15 +00:00
|
|
|
_noWait(false)
|
2007-07-04 16:04:57 +00:00
|
|
|
{}
|
2006-02-17 13:35:04 +00:00
|
|
|
|
|
|
|
DownloadEngine::~DownloadEngine() {
|
2006-08-07 16:05:00 +00:00
|
|
|
cleanQueue();
|
2006-05-09 15:54:14 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
class Deleter {
|
|
|
|
public:
|
|
|
|
template<class T>
|
|
|
|
void operator()(T* ptr) {
|
|
|
|
delete ptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-05-09 15:54:14 +00:00
|
|
|
void DownloadEngine::cleanQueue() {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::for_each(commands.begin(), commands.end(), Deleter());
|
2006-05-09 15:54:14 +00:00
|
|
|
commands.clear();
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 05:42:15 +00:00
|
|
|
static void executeCommand(std::deque<Command*>& commands,
|
|
|
|
Command::STATUS statusFilter)
|
2007-03-16 14:21:29 +00:00
|
|
|
{
|
2008-03-09 12:24:01 +00:00
|
|
|
size_t max = commands.size();
|
|
|
|
for(size_t i = 0; i < max; i++) {
|
2007-03-16 14:21:29 +00:00
|
|
|
Command* com = commands.front();
|
|
|
|
commands.pop_front();
|
|
|
|
if(com->statusMatch(statusFilter)) {
|
|
|
|
if(com->execute()) {
|
|
|
|
delete com;
|
|
|
|
} else {
|
2007-05-20 13:51:52 +00:00
|
|
|
com->transitStatus();
|
2007-03-16 14:21:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
commands.push_back(com);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-17 13:35:04 +00:00
|
|
|
void DownloadEngine::run() {
|
2006-06-12 16:55:08 +00:00
|
|
|
Time cp;
|
2006-08-11 12:29:55 +00:00
|
|
|
cp.setTimeInSec(0);
|
2008-04-23 10:03:52 +00:00
|
|
|
while(!commands.empty() || !_routineCommands.empty()) {
|
2006-06-12 16:55:08 +00:00
|
|
|
if(cp.elapsed(1)) {
|
|
|
|
cp.reset();
|
2008-04-20 05:42:15 +00:00
|
|
|
executeCommand(commands, Command::STATUS_ALL);
|
2006-05-24 15:18:58 +00:00
|
|
|
} else {
|
2008-04-20 05:42:15 +00:00
|
|
|
executeCommand(commands, Command::STATUS_ACTIVE);
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
2008-04-20 05:42:15 +00:00
|
|
|
executeCommand(_routineCommands, Command::STATUS_ALL);
|
2006-03-24 11:59:18 +00:00
|
|
|
afterEachIteration();
|
2007-05-20 13:51:52 +00:00
|
|
|
if(!commands.empty()) {
|
2007-03-16 14:21:29 +00:00
|
|
|
waitData();
|
2006-02-21 12:27:17 +00:00
|
|
|
}
|
2008-04-20 05:42:15 +00:00
|
|
|
_noWait = false;
|
2006-03-02 02:54:49 +00:00
|
|
|
calculateStatistics();
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
onEndOfRun();
|
2006-03-02 02:54:49 +00:00
|
|
|
}
|
|
|
|
|
2006-03-21 14:12:51 +00:00
|
|
|
void DownloadEngine::shortSleep() const {
|
|
|
|
struct timeval tv;
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 1000;
|
|
|
|
fd_set rfds;
|
|
|
|
FD_ZERO(&rfds);
|
|
|
|
select(0, &rfds, NULL, NULL, &tv);
|
2006-03-02 02:54:49 +00:00
|
|
|
}
|
2006-02-17 13:35:04 +00:00
|
|
|
|
2007-03-16 14:21:29 +00:00
|
|
|
void DownloadEngine::waitData() {
|
2006-02-17 13:35:04 +00:00
|
|
|
fd_set rfds;
|
|
|
|
fd_set wfds;
|
2006-08-07 16:05:00 +00:00
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
memcpy(&rfds, &rfdset, sizeof(fd_set));
|
|
|
|
memcpy(&wfds, &wfdset, sizeof(fd_set));
|
|
|
|
|
2008-03-05 10:35:39 +00:00
|
|
|
#ifdef ENABLE_ASYNC_DNS
|
2008-05-08 11:18:36 +00:00
|
|
|
for(AsyncNameResolverEntries::iterator itr = nameResolverEntries.begin();
|
2008-03-05 10:35:39 +00:00
|
|
|
itr != nameResolverEntries.end(); ++itr) {
|
2008-05-08 11:18:36 +00:00
|
|
|
AsyncNameResolverEntry& entry = *itr;
|
2008-03-09 12:24:01 +00:00
|
|
|
int fd = entry.nameResolver->getFds(&rfds, &wfds);
|
2008-03-05 10:35:39 +00:00
|
|
|
// TODO force error if fd == 0
|
|
|
|
if(fdmax < fd) {
|
|
|
|
fdmax = fd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // ENABLE_ASYNC_DNS
|
|
|
|
|
2008-04-20 05:42:15 +00:00
|
|
|
tv.tv_sec = _noWait ? 0 : 1;
|
2006-08-07 16:05:00 +00:00
|
|
|
tv.tv_usec = 0;
|
2008-03-09 12:24:01 +00:00
|
|
|
int retval = select(fdmax+1, &rfds, &wfds, NULL, &tv);
|
2006-05-24 15:18:58 +00:00
|
|
|
if(retval > 0) {
|
2007-01-23 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To add chunk checksum validation:
* src/MetalinkEntry.h
(MetalinkChunkChecksum.h): New include.
(chunkChecksum): New variable.
* src/Request.h
(method): New variable.
(setMethod): New function.
(getMethod): New function.
(METHOD_GET): New static constant.
(METHOD_HEAD): New static constant.
* src/Xml2MetalinkProcessor.h
(getPieceHash): New function.
* src/PieceStorage.h
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/FileAllocator.h
(NullFileAllocationMonitor.h): New include.
(FileAllocator): Initialize fileAllocationMonitor with new
NullFileAllocationMonitor().
* src/MultiDiskAdaptor.h
(messageDigest.h): Remove include.
(ctx): Removed.
(hashUpdate): Added ctx.
(MultiDiskAdaptor): Removed ctx.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/UrlRequestInfo.h
(HeadResult): New class.
(digestAlgo): New variable.
(chunkChecksumLength): New variable.
(chunkChecksums): New variable.
(getHeadResult): New function.
(UrlRequestInfo): Added digestAlgo, chunkChecksumLength.
(setDigestAlgo): New function.
(setChunkChecksumLength): New function.
(setChunkChecksums): New function.
* src/DefaultPieceStorage.cc
(DiskAdaptorWriter.h): New include.
(ChunkChecksumValidator.h): New include.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/DefaultBtContext.h
(getPieceHashes): New function.
* src/TorrentRequestInfo.cc
(execute): Try to validate chunk checksum if file already exists
and
.aria2 file doesn't there and user allows aria2 to overwrite it.
* src/messageDigest.h
(~MessageDigestContext): Added digestFree().
* src/MetalinkRequestInfo.cc
(execute): Set digestAlgo, chunkChecksum, chunkChecksums to
reqInfo.
* src/DiskAdaptor.h
(messageDigest.h): New include.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/DownloadCommand.h
(PeerStat.h): New include.
(maxDownloadSpeedLimit): New variable.
(startupIdleTime): New variable.
(lowestDownloadSpeedLimit): New variable.
(peerStat): New variable.
(setMaxDownloadSpeedLimit): New function.
(setStartupIdleTime): New function.
(setLowestDownloadSPeedLimit): New function.
* src/BtContext.h
(getPieceHashes): New function.
* src/main.cc
(main): Set PREF_REALTIME_CHUNK_CHECKSUM and
PREF_CHECK_INTEGRITY
option to true for testing purpose.
* src/BtPieceMessage.cc
(checkPieceHash): Use messageDigest
* src/DownloadEngine.cc
(SetDescriptor): Removed.
(AccumulateActiveCommand): Removed.
(waitData): Rewritten.
(updateFdSet): Rewritten.
* src/MultiDiskAdaptor.cc
(hashUpdate): Added ctx.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/BitfieldMan.h
(isBitRangeSet): New function.
(unsetBitRange): New function.
* src/ByteArrayDiskWriter.h
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/ConsoleDownloadEngine.cc
(calculateStatistics): If nspeed < 0 then set nspeed to 0.
* src/DiskWriter.h
(messageDigest.h): New include.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/ChunkChecksumValidator.h: New class.
* src/DiskAdaptorWriter.h: New class.
* src/prefs.h
(PREF_REALTIME_CHUNK_CHECKSUM): New definition.
(PREF_CHECK_INTEGRITY): New definition.
* src/HttpResponseCommand.cc
(handleDefaultEncoding): Added method "HEAD" handling.
Removed the call to
e->segmentMan->shouldCancelDownloadForSafety().
(handleOtherEncoding):
Added the call to
e->segmentMan->shouldCancelDownloadForSafety().
(createHttpDownloadCommand): Set maxDownloadSpeedLimit,
startupIdleTime, lowestDownloadSpeedLimit to command.
* src/SegmentMan.h
(getSegmentEntryByIndex): New function.
(getSegmentEntryByCuid): New function.
(getSegmentEntryIteratorByCuid): New function.
(diskWriter): DiskWriter -> DiskWriterHandle
(pieceHashes): New variable.
(chunkHashLength): New variable.
(digestAlgo): New variable.
(FindPeerStat): Removed.
(getPeerStat): Rewritten.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
(tryChunkChecksumValidation): New function.
(isChunkChecksumValidationReady): New function.
* src/BitfieldMan.cc
(BitfieldMan): Initialized bitfieldLength, blocks to 0.
(BitfieldMan): Initialized blockLength, totalLength,
bitfieldLength,
blocks to 0.
(isBitRangeSet): New function.
(unsetBitRange): New function.
* src/FtpNegotiateCommand.cc
(executeInternal): Set maxDownloadSpeedLimit,
startupIdleTime, lowestDownloadSpeedLimit to command.
(recvSize): Added method "HEAD" handling.
Removed the call to
e->segmentMan->shouldCancelDownloadForSafety().
* src/AbstractSingleDiskAdaptor.cc
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/AbstractSingleDiskAdaptor.h
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/Util.h
(indexRange): New function.
* src/MetalinkEntry.cc
(MetalinkEntry): Initialized chunkChecksum to 0.
* src/ShaVisitor.cc
(~ShaVisitor): Removed the call to ctx.digestFree().
* src/SegmentMan.cc
(ChunkChecksumValidator.h): New include.
(SegmentMan): Initialized chunkHashLength to 0. Initialized
digestAlgo
to DIGEST_ALGO_SHA1.
(~SegmentMan): Removed diskWriter.
(FindSegmentEntryByIndex): Removed.
(FindSegmentEntryByCuid): Removed.
(checkoutSegment): Rewritten.
(findSlowerSegmentEntry): Rewritten.
(getSegment): Rewritten.
(updateSegment): Rewritten.
(completeSegment): Rewritten.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
(isChunkChecksumValidationReady): New function.
(tryChunkChecksumValidation): New function.
* src/Xml2MetalinkProcessor.cc
(getEntry): Get size and set it to entry.
Get chunk checksum and set it to entry.
(getPieceHash): New function.
* src/Util.cc
(sha1Sum): Removed ctx.digestFree()
(fileChecksum): Removed ctx.digestFree()
(indexRange): New function.
* src/Request.cc
(METHOD_GET): New variable.
(METHOD_HEAD): New variable.
(Request): Added method.
* src/UrlRequestInfo.cc
(FatalException.h): New include.
(message.h): New include.
(operator<<): Added operator<< for class HeadResult.
(getHeadResult): New function.
(execute): Get filename and size in separate download engine.
* src/ChunkChecksumValidator.cc: New class.
* src/DownloadCommand.cc:
(DownloadCommand): Added peerStat.
(executeInternal): Use maxDownloadSpeedLimit member instead of
getting
the value from Option.
The buffer size is now 16KB.
Use peerStat member instead of getting it from SegmentMan.
Use startupIdleTime member instead of gettingit from Option.
Added chunk checksum validation.
* src/AbstractDiskWriter.cc
(AbstractDiskWriter): Removed ctx.
(~AbstractDiskWriter): Removed ctx.digestFree()
(writeDataInternal): Returns the return value of write.
(readDataInternal): Returns the return value of read.
(sha1Sum): Renamed as messageDigest
(messageDigest): New function.
* src/AbstractDiwkWriter.h
(messageDigest.h): Removed include.
(ctx): Removed.
(sha1Sum): Renamed as messageDigest
(messageDigest): New function.
* src/DefaultPieceStorage.h
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/NullFileAllocationMonitor.h: New class.
2007-01-24 15:55:34 +00:00
|
|
|
for(SocketEntries::iterator itr = socketEntries.begin();
|
|
|
|
itr != socketEntries.end(); ++itr) {
|
|
|
|
SocketEntry& entry = *itr;
|
|
|
|
if(FD_ISSET(entry.socket->getSockfd(), &rfds) ||
|
|
|
|
FD_ISSET(entry.socket->getSockfd(), &wfds)) {
|
2007-03-16 14:21:29 +00:00
|
|
|
entry.command->setStatusActive();
|
2007-01-23 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To add chunk checksum validation:
* src/MetalinkEntry.h
(MetalinkChunkChecksum.h): New include.
(chunkChecksum): New variable.
* src/Request.h
(method): New variable.
(setMethod): New function.
(getMethod): New function.
(METHOD_GET): New static constant.
(METHOD_HEAD): New static constant.
* src/Xml2MetalinkProcessor.h
(getPieceHash): New function.
* src/PieceStorage.h
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/FileAllocator.h
(NullFileAllocationMonitor.h): New include.
(FileAllocator): Initialize fileAllocationMonitor with new
NullFileAllocationMonitor().
* src/MultiDiskAdaptor.h
(messageDigest.h): Remove include.
(ctx): Removed.
(hashUpdate): Added ctx.
(MultiDiskAdaptor): Removed ctx.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/UrlRequestInfo.h
(HeadResult): New class.
(digestAlgo): New variable.
(chunkChecksumLength): New variable.
(chunkChecksums): New variable.
(getHeadResult): New function.
(UrlRequestInfo): Added digestAlgo, chunkChecksumLength.
(setDigestAlgo): New function.
(setChunkChecksumLength): New function.
(setChunkChecksums): New function.
* src/DefaultPieceStorage.cc
(DiskAdaptorWriter.h): New include.
(ChunkChecksumValidator.h): New include.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/DefaultBtContext.h
(getPieceHashes): New function.
* src/TorrentRequestInfo.cc
(execute): Try to validate chunk checksum if file already exists
and
.aria2 file doesn't there and user allows aria2 to overwrite it.
* src/messageDigest.h
(~MessageDigestContext): Added digestFree().
* src/MetalinkRequestInfo.cc
(execute): Set digestAlgo, chunkChecksum, chunkChecksums to
reqInfo.
* src/DiskAdaptor.h
(messageDigest.h): New include.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/DownloadCommand.h
(PeerStat.h): New include.
(maxDownloadSpeedLimit): New variable.
(startupIdleTime): New variable.
(lowestDownloadSpeedLimit): New variable.
(peerStat): New variable.
(setMaxDownloadSpeedLimit): New function.
(setStartupIdleTime): New function.
(setLowestDownloadSPeedLimit): New function.
* src/BtContext.h
(getPieceHashes): New function.
* src/main.cc
(main): Set PREF_REALTIME_CHUNK_CHECKSUM and
PREF_CHECK_INTEGRITY
option to true for testing purpose.
* src/BtPieceMessage.cc
(checkPieceHash): Use messageDigest
* src/DownloadEngine.cc
(SetDescriptor): Removed.
(AccumulateActiveCommand): Removed.
(waitData): Rewritten.
(updateFdSet): Rewritten.
* src/MultiDiskAdaptor.cc
(hashUpdate): Added ctx.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/BitfieldMan.h
(isBitRangeSet): New function.
(unsetBitRange): New function.
* src/ByteArrayDiskWriter.h
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/ConsoleDownloadEngine.cc
(calculateStatistics): If nspeed < 0 then set nspeed to 0.
* src/DiskWriter.h
(messageDigest.h): New include.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/ChunkChecksumValidator.h: New class.
* src/DiskAdaptorWriter.h: New class.
* src/prefs.h
(PREF_REALTIME_CHUNK_CHECKSUM): New definition.
(PREF_CHECK_INTEGRITY): New definition.
* src/HttpResponseCommand.cc
(handleDefaultEncoding): Added method "HEAD" handling.
Removed the call to
e->segmentMan->shouldCancelDownloadForSafety().
(handleOtherEncoding):
Added the call to
e->segmentMan->shouldCancelDownloadForSafety().
(createHttpDownloadCommand): Set maxDownloadSpeedLimit,
startupIdleTime, lowestDownloadSpeedLimit to command.
* src/SegmentMan.h
(getSegmentEntryByIndex): New function.
(getSegmentEntryByCuid): New function.
(getSegmentEntryIteratorByCuid): New function.
(diskWriter): DiskWriter -> DiskWriterHandle
(pieceHashes): New variable.
(chunkHashLength): New variable.
(digestAlgo): New variable.
(FindPeerStat): Removed.
(getPeerStat): Rewritten.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
(tryChunkChecksumValidation): New function.
(isChunkChecksumValidationReady): New function.
* src/BitfieldMan.cc
(BitfieldMan): Initialized bitfieldLength, blocks to 0.
(BitfieldMan): Initialized blockLength, totalLength,
bitfieldLength,
blocks to 0.
(isBitRangeSet): New function.
(unsetBitRange): New function.
* src/FtpNegotiateCommand.cc
(executeInternal): Set maxDownloadSpeedLimit,
startupIdleTime, lowestDownloadSpeedLimit to command.
(recvSize): Added method "HEAD" handling.
Removed the call to
e->segmentMan->shouldCancelDownloadForSafety().
* src/AbstractSingleDiskAdaptor.cc
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/AbstractSingleDiskAdaptor.h
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/Util.h
(indexRange): New function.
* src/MetalinkEntry.cc
(MetalinkEntry): Initialized chunkChecksum to 0.
* src/ShaVisitor.cc
(~ShaVisitor): Removed the call to ctx.digestFree().
* src/SegmentMan.cc
(ChunkChecksumValidator.h): New include.
(SegmentMan): Initialized chunkHashLength to 0. Initialized
digestAlgo
to DIGEST_ALGO_SHA1.
(~SegmentMan): Removed diskWriter.
(FindSegmentEntryByIndex): Removed.
(FindSegmentEntryByCuid): Removed.
(checkoutSegment): Rewritten.
(findSlowerSegmentEntry): Rewritten.
(getSegment): Rewritten.
(updateSegment): Rewritten.
(completeSegment): Rewritten.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
(isChunkChecksumValidationReady): New function.
(tryChunkChecksumValidation): New function.
* src/Xml2MetalinkProcessor.cc
(getEntry): Get size and set it to entry.
Get chunk checksum and set it to entry.
(getPieceHash): New function.
* src/Util.cc
(sha1Sum): Removed ctx.digestFree()
(fileChecksum): Removed ctx.digestFree()
(indexRange): New function.
* src/Request.cc
(METHOD_GET): New variable.
(METHOD_HEAD): New variable.
(Request): Added method.
* src/UrlRequestInfo.cc
(FatalException.h): New include.
(message.h): New include.
(operator<<): Added operator<< for class HeadResult.
(getHeadResult): New function.
(execute): Get filename and size in separate download engine.
* src/ChunkChecksumValidator.cc: New class.
* src/DownloadCommand.cc:
(DownloadCommand): Added peerStat.
(executeInternal): Use maxDownloadSpeedLimit member instead of
getting
the value from Option.
The buffer size is now 16KB.
Use peerStat member instead of getting it from SegmentMan.
Use startupIdleTime member instead of gettingit from Option.
Added chunk checksum validation.
* src/AbstractDiskWriter.cc
(AbstractDiskWriter): Removed ctx.
(~AbstractDiskWriter): Removed ctx.digestFree()
(writeDataInternal): Returns the return value of write.
(readDataInternal): Returns the return value of read.
(sha1Sum): Renamed as messageDigest
(messageDigest): New function.
* src/AbstractDiwkWriter.h
(messageDigest.h): Removed include.
(ctx): Removed.
(sha1Sum): Renamed as messageDigest
(messageDigest): New function.
* src/DefaultPieceStorage.h
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/NullFileAllocationMonitor.h: New class.
2007-01-24 15:55:34 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-05 10:35:39 +00:00
|
|
|
}
|
2006-08-21 13:18:51 +00:00
|
|
|
#ifdef ENABLE_ASYNC_DNS
|
2008-05-08 11:18:36 +00:00
|
|
|
for(AsyncNameResolverEntries::iterator itr = nameResolverEntries.begin();
|
2008-03-05 10:35:39 +00:00
|
|
|
itr != nameResolverEntries.end(); ++itr) {
|
2008-05-08 11:18:36 +00:00
|
|
|
AsyncNameResolverEntry& entry = *itr;
|
2008-03-05 10:35:39 +00:00
|
|
|
entry.nameResolver->process(&rfds, &wfds);
|
|
|
|
switch(entry.nameResolver->getStatus()) {
|
2008-05-08 11:18:36 +00:00
|
|
|
case AsyncNameResolver::STATUS_SUCCESS:
|
|
|
|
case AsyncNameResolver::STATUS_ERROR:
|
2008-03-05 10:35:39 +00:00
|
|
|
entry.command->setStatusActive();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2007-01-23 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To add chunk checksum validation:
* src/MetalinkEntry.h
(MetalinkChunkChecksum.h): New include.
(chunkChecksum): New variable.
* src/Request.h
(method): New variable.
(setMethod): New function.
(getMethod): New function.
(METHOD_GET): New static constant.
(METHOD_HEAD): New static constant.
* src/Xml2MetalinkProcessor.h
(getPieceHash): New function.
* src/PieceStorage.h
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/FileAllocator.h
(NullFileAllocationMonitor.h): New include.
(FileAllocator): Initialize fileAllocationMonitor with new
NullFileAllocationMonitor().
* src/MultiDiskAdaptor.h
(messageDigest.h): Remove include.
(ctx): Removed.
(hashUpdate): Added ctx.
(MultiDiskAdaptor): Removed ctx.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/UrlRequestInfo.h
(HeadResult): New class.
(digestAlgo): New variable.
(chunkChecksumLength): New variable.
(chunkChecksums): New variable.
(getHeadResult): New function.
(UrlRequestInfo): Added digestAlgo, chunkChecksumLength.
(setDigestAlgo): New function.
(setChunkChecksumLength): New function.
(setChunkChecksums): New function.
* src/DefaultPieceStorage.cc
(DiskAdaptorWriter.h): New include.
(ChunkChecksumValidator.h): New include.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/DefaultBtContext.h
(getPieceHashes): New function.
* src/TorrentRequestInfo.cc
(execute): Try to validate chunk checksum if file already exists
and
.aria2 file doesn't there and user allows aria2 to overwrite it.
* src/messageDigest.h
(~MessageDigestContext): Added digestFree().
* src/MetalinkRequestInfo.cc
(execute): Set digestAlgo, chunkChecksum, chunkChecksums to
reqInfo.
* src/DiskAdaptor.h
(messageDigest.h): New include.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/DownloadCommand.h
(PeerStat.h): New include.
(maxDownloadSpeedLimit): New variable.
(startupIdleTime): New variable.
(lowestDownloadSpeedLimit): New variable.
(peerStat): New variable.
(setMaxDownloadSpeedLimit): New function.
(setStartupIdleTime): New function.
(setLowestDownloadSPeedLimit): New function.
* src/BtContext.h
(getPieceHashes): New function.
* src/main.cc
(main): Set PREF_REALTIME_CHUNK_CHECKSUM and
PREF_CHECK_INTEGRITY
option to true for testing purpose.
* src/BtPieceMessage.cc
(checkPieceHash): Use messageDigest
* src/DownloadEngine.cc
(SetDescriptor): Removed.
(AccumulateActiveCommand): Removed.
(waitData): Rewritten.
(updateFdSet): Rewritten.
* src/MultiDiskAdaptor.cc
(hashUpdate): Added ctx.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/BitfieldMan.h
(isBitRangeSet): New function.
(unsetBitRange): New function.
* src/ByteArrayDiskWriter.h
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/ConsoleDownloadEngine.cc
(calculateStatistics): If nspeed < 0 then set nspeed to 0.
* src/DiskWriter.h
(messageDigest.h): New include.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/ChunkChecksumValidator.h: New class.
* src/DiskAdaptorWriter.h: New class.
* src/prefs.h
(PREF_REALTIME_CHUNK_CHECKSUM): New definition.
(PREF_CHECK_INTEGRITY): New definition.
* src/HttpResponseCommand.cc
(handleDefaultEncoding): Added method "HEAD" handling.
Removed the call to
e->segmentMan->shouldCancelDownloadForSafety().
(handleOtherEncoding):
Added the call to
e->segmentMan->shouldCancelDownloadForSafety().
(createHttpDownloadCommand): Set maxDownloadSpeedLimit,
startupIdleTime, lowestDownloadSpeedLimit to command.
* src/SegmentMan.h
(getSegmentEntryByIndex): New function.
(getSegmentEntryByCuid): New function.
(getSegmentEntryIteratorByCuid): New function.
(diskWriter): DiskWriter -> DiskWriterHandle
(pieceHashes): New variable.
(chunkHashLength): New variable.
(digestAlgo): New variable.
(FindPeerStat): Removed.
(getPeerStat): Rewritten.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
(tryChunkChecksumValidation): New function.
(isChunkChecksumValidationReady): New function.
* src/BitfieldMan.cc
(BitfieldMan): Initialized bitfieldLength, blocks to 0.
(BitfieldMan): Initialized blockLength, totalLength,
bitfieldLength,
blocks to 0.
(isBitRangeSet): New function.
(unsetBitRange): New function.
* src/FtpNegotiateCommand.cc
(executeInternal): Set maxDownloadSpeedLimit,
startupIdleTime, lowestDownloadSpeedLimit to command.
(recvSize): Added method "HEAD" handling.
Removed the call to
e->segmentMan->shouldCancelDownloadForSafety().
* src/AbstractSingleDiskAdaptor.cc
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/AbstractSingleDiskAdaptor.h
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/Util.h
(indexRange): New function.
* src/MetalinkEntry.cc
(MetalinkEntry): Initialized chunkChecksum to 0.
* src/ShaVisitor.cc
(~ShaVisitor): Removed the call to ctx.digestFree().
* src/SegmentMan.cc
(ChunkChecksumValidator.h): New include.
(SegmentMan): Initialized chunkHashLength to 0. Initialized
digestAlgo
to DIGEST_ALGO_SHA1.
(~SegmentMan): Removed diskWriter.
(FindSegmentEntryByIndex): Removed.
(FindSegmentEntryByCuid): Removed.
(checkoutSegment): Rewritten.
(findSlowerSegmentEntry): Rewritten.
(getSegment): Rewritten.
(updateSegment): Rewritten.
(completeSegment): Rewritten.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
(isChunkChecksumValidationReady): New function.
(tryChunkChecksumValidation): New function.
* src/Xml2MetalinkProcessor.cc
(getEntry): Get size and set it to entry.
Get chunk checksum and set it to entry.
(getPieceHash): New function.
* src/Util.cc
(sha1Sum): Removed ctx.digestFree()
(fileChecksum): Removed ctx.digestFree()
(indexRange): New function.
* src/Request.cc
(METHOD_GET): New variable.
(METHOD_HEAD): New variable.
(Request): Added method.
* src/UrlRequestInfo.cc
(FatalException.h): New include.
(message.h): New include.
(operator<<): Added operator<< for class HeadResult.
(getHeadResult): New function.
(execute): Get filename and size in separate download engine.
* src/ChunkChecksumValidator.cc: New class.
* src/DownloadCommand.cc:
(DownloadCommand): Added peerStat.
(executeInternal): Use maxDownloadSpeedLimit member instead of
getting
the value from Option.
The buffer size is now 16KB.
Use peerStat member instead of getting it from SegmentMan.
Use startupIdleTime member instead of gettingit from Option.
Added chunk checksum validation.
* src/AbstractDiskWriter.cc
(AbstractDiskWriter): Removed ctx.
(~AbstractDiskWriter): Removed ctx.digestFree()
(writeDataInternal): Returns the return value of write.
(readDataInternal): Returns the return value of read.
(sha1Sum): Renamed as messageDigest
(messageDigest): New function.
* src/AbstractDiwkWriter.h
(messageDigest.h): Removed include.
(ctx): Removed.
(sha1Sum): Renamed as messageDigest
(messageDigest): New function.
* src/DefaultPieceStorage.h
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/NullFileAllocationMonitor.h: New class.
2007-01-24 15:55:34 +00:00
|
|
|
}
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
2008-03-05 10:35:39 +00:00
|
|
|
#endif // ENABLE_ASYNC_DNS
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
|
|
|
|
2006-07-28 14:06:47 +00:00
|
|
|
void DownloadEngine::updateFdSet() {
|
|
|
|
fdmax = 0;
|
|
|
|
FD_ZERO(&rfdset);
|
|
|
|
FD_ZERO(&wfdset);
|
2007-01-23 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To add chunk checksum validation:
* src/MetalinkEntry.h
(MetalinkChunkChecksum.h): New include.
(chunkChecksum): New variable.
* src/Request.h
(method): New variable.
(setMethod): New function.
(getMethod): New function.
(METHOD_GET): New static constant.
(METHOD_HEAD): New static constant.
* src/Xml2MetalinkProcessor.h
(getPieceHash): New function.
* src/PieceStorage.h
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/FileAllocator.h
(NullFileAllocationMonitor.h): New include.
(FileAllocator): Initialize fileAllocationMonitor with new
NullFileAllocationMonitor().
* src/MultiDiskAdaptor.h
(messageDigest.h): Remove include.
(ctx): Removed.
(hashUpdate): Added ctx.
(MultiDiskAdaptor): Removed ctx.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/UrlRequestInfo.h
(HeadResult): New class.
(digestAlgo): New variable.
(chunkChecksumLength): New variable.
(chunkChecksums): New variable.
(getHeadResult): New function.
(UrlRequestInfo): Added digestAlgo, chunkChecksumLength.
(setDigestAlgo): New function.
(setChunkChecksumLength): New function.
(setChunkChecksums): New function.
* src/DefaultPieceStorage.cc
(DiskAdaptorWriter.h): New include.
(ChunkChecksumValidator.h): New include.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/DefaultBtContext.h
(getPieceHashes): New function.
* src/TorrentRequestInfo.cc
(execute): Try to validate chunk checksum if file already exists
and
.aria2 file doesn't there and user allows aria2 to overwrite it.
* src/messageDigest.h
(~MessageDigestContext): Added digestFree().
* src/MetalinkRequestInfo.cc
(execute): Set digestAlgo, chunkChecksum, chunkChecksums to
reqInfo.
* src/DiskAdaptor.h
(messageDigest.h): New include.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/DownloadCommand.h
(PeerStat.h): New include.
(maxDownloadSpeedLimit): New variable.
(startupIdleTime): New variable.
(lowestDownloadSpeedLimit): New variable.
(peerStat): New variable.
(setMaxDownloadSpeedLimit): New function.
(setStartupIdleTime): New function.
(setLowestDownloadSPeedLimit): New function.
* src/BtContext.h
(getPieceHashes): New function.
* src/main.cc
(main): Set PREF_REALTIME_CHUNK_CHECKSUM and
PREF_CHECK_INTEGRITY
option to true for testing purpose.
* src/BtPieceMessage.cc
(checkPieceHash): Use messageDigest
* src/DownloadEngine.cc
(SetDescriptor): Removed.
(AccumulateActiveCommand): Removed.
(waitData): Rewritten.
(updateFdSet): Rewritten.
* src/MultiDiskAdaptor.cc
(hashUpdate): Added ctx.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/BitfieldMan.h
(isBitRangeSet): New function.
(unsetBitRange): New function.
* src/ByteArrayDiskWriter.h
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/ConsoleDownloadEngine.cc
(calculateStatistics): If nspeed < 0 then set nspeed to 0.
* src/DiskWriter.h
(messageDigest.h): New include.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/ChunkChecksumValidator.h: New class.
* src/DiskAdaptorWriter.h: New class.
* src/prefs.h
(PREF_REALTIME_CHUNK_CHECKSUM): New definition.
(PREF_CHECK_INTEGRITY): New definition.
* src/HttpResponseCommand.cc
(handleDefaultEncoding): Added method "HEAD" handling.
Removed the call to
e->segmentMan->shouldCancelDownloadForSafety().
(handleOtherEncoding):
Added the call to
e->segmentMan->shouldCancelDownloadForSafety().
(createHttpDownloadCommand): Set maxDownloadSpeedLimit,
startupIdleTime, lowestDownloadSpeedLimit to command.
* src/SegmentMan.h
(getSegmentEntryByIndex): New function.
(getSegmentEntryByCuid): New function.
(getSegmentEntryIteratorByCuid): New function.
(diskWriter): DiskWriter -> DiskWriterHandle
(pieceHashes): New variable.
(chunkHashLength): New variable.
(digestAlgo): New variable.
(FindPeerStat): Removed.
(getPeerStat): Rewritten.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
(tryChunkChecksumValidation): New function.
(isChunkChecksumValidationReady): New function.
* src/BitfieldMan.cc
(BitfieldMan): Initialized bitfieldLength, blocks to 0.
(BitfieldMan): Initialized blockLength, totalLength,
bitfieldLength,
blocks to 0.
(isBitRangeSet): New function.
(unsetBitRange): New function.
* src/FtpNegotiateCommand.cc
(executeInternal): Set maxDownloadSpeedLimit,
startupIdleTime, lowestDownloadSpeedLimit to command.
(recvSize): Added method "HEAD" handling.
Removed the call to
e->segmentMan->shouldCancelDownloadForSafety().
* src/AbstractSingleDiskAdaptor.cc
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/AbstractSingleDiskAdaptor.h
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/Util.h
(indexRange): New function.
* src/MetalinkEntry.cc
(MetalinkEntry): Initialized chunkChecksum to 0.
* src/ShaVisitor.cc
(~ShaVisitor): Removed the call to ctx.digestFree().
* src/SegmentMan.cc
(ChunkChecksumValidator.h): New include.
(SegmentMan): Initialized chunkHashLength to 0. Initialized
digestAlgo
to DIGEST_ALGO_SHA1.
(~SegmentMan): Removed diskWriter.
(FindSegmentEntryByIndex): Removed.
(FindSegmentEntryByCuid): Removed.
(checkoutSegment): Rewritten.
(findSlowerSegmentEntry): Rewritten.
(getSegment): Rewritten.
(updateSegment): Rewritten.
(completeSegment): Rewritten.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
(isChunkChecksumValidationReady): New function.
(tryChunkChecksumValidation): New function.
* src/Xml2MetalinkProcessor.cc
(getEntry): Get size and set it to entry.
Get chunk checksum and set it to entry.
(getPieceHash): New function.
* src/Util.cc
(sha1Sum): Removed ctx.digestFree()
(fileChecksum): Removed ctx.digestFree()
(indexRange): New function.
* src/Request.cc
(METHOD_GET): New variable.
(METHOD_HEAD): New variable.
(Request): Added method.
* src/UrlRequestInfo.cc
(FatalException.h): New include.
(message.h): New include.
(operator<<): Added operator<< for class HeadResult.
(getHeadResult): New function.
(execute): Get filename and size in separate download engine.
* src/ChunkChecksumValidator.cc: New class.
* src/DownloadCommand.cc:
(DownloadCommand): Added peerStat.
(executeInternal): Use maxDownloadSpeedLimit member instead of
getting
the value from Option.
The buffer size is now 16KB.
Use peerStat member instead of getting it from SegmentMan.
Use startupIdleTime member instead of gettingit from Option.
Added chunk checksum validation.
* src/AbstractDiskWriter.cc
(AbstractDiskWriter): Removed ctx.
(~AbstractDiskWriter): Removed ctx.digestFree()
(writeDataInternal): Returns the return value of write.
(readDataInternal): Returns the return value of read.
(sha1Sum): Renamed as messageDigest
(messageDigest): New function.
* src/AbstractDiwkWriter.h
(messageDigest.h): Removed include.
(ctx): Removed.
(sha1Sum): Renamed as messageDigest
(messageDigest): New function.
* src/DefaultPieceStorage.h
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/NullFileAllocationMonitor.h: New class.
2007-01-24 15:55:34 +00:00
|
|
|
for(SocketEntries::iterator itr = socketEntries.begin();
|
|
|
|
itr != socketEntries.end(); ++itr) {
|
|
|
|
SocketEntry& entry = *itr;
|
2008-03-09 12:24:01 +00:00
|
|
|
int fd = entry.socket->getSockfd();
|
2007-01-23 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To add chunk checksum validation:
* src/MetalinkEntry.h
(MetalinkChunkChecksum.h): New include.
(chunkChecksum): New variable.
* src/Request.h
(method): New variable.
(setMethod): New function.
(getMethod): New function.
(METHOD_GET): New static constant.
(METHOD_HEAD): New static constant.
* src/Xml2MetalinkProcessor.h
(getPieceHash): New function.
* src/PieceStorage.h
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/FileAllocator.h
(NullFileAllocationMonitor.h): New include.
(FileAllocator): Initialize fileAllocationMonitor with new
NullFileAllocationMonitor().
* src/MultiDiskAdaptor.h
(messageDigest.h): Remove include.
(ctx): Removed.
(hashUpdate): Added ctx.
(MultiDiskAdaptor): Removed ctx.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/UrlRequestInfo.h
(HeadResult): New class.
(digestAlgo): New variable.
(chunkChecksumLength): New variable.
(chunkChecksums): New variable.
(getHeadResult): New function.
(UrlRequestInfo): Added digestAlgo, chunkChecksumLength.
(setDigestAlgo): New function.
(setChunkChecksumLength): New function.
(setChunkChecksums): New function.
* src/DefaultPieceStorage.cc
(DiskAdaptorWriter.h): New include.
(ChunkChecksumValidator.h): New include.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/DefaultBtContext.h
(getPieceHashes): New function.
* src/TorrentRequestInfo.cc
(execute): Try to validate chunk checksum if file already exists
and
.aria2 file doesn't there and user allows aria2 to overwrite it.
* src/messageDigest.h
(~MessageDigestContext): Added digestFree().
* src/MetalinkRequestInfo.cc
(execute): Set digestAlgo, chunkChecksum, chunkChecksums to
reqInfo.
* src/DiskAdaptor.h
(messageDigest.h): New include.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/DownloadCommand.h
(PeerStat.h): New include.
(maxDownloadSpeedLimit): New variable.
(startupIdleTime): New variable.
(lowestDownloadSpeedLimit): New variable.
(peerStat): New variable.
(setMaxDownloadSpeedLimit): New function.
(setStartupIdleTime): New function.
(setLowestDownloadSPeedLimit): New function.
* src/BtContext.h
(getPieceHashes): New function.
* src/main.cc
(main): Set PREF_REALTIME_CHUNK_CHECKSUM and
PREF_CHECK_INTEGRITY
option to true for testing purpose.
* src/BtPieceMessage.cc
(checkPieceHash): Use messageDigest
* src/DownloadEngine.cc
(SetDescriptor): Removed.
(AccumulateActiveCommand): Removed.
(waitData): Rewritten.
(updateFdSet): Rewritten.
* src/MultiDiskAdaptor.cc
(hashUpdate): Added ctx.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/BitfieldMan.h
(isBitRangeSet): New function.
(unsetBitRange): New function.
* src/ByteArrayDiskWriter.h
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/ConsoleDownloadEngine.cc
(calculateStatistics): If nspeed < 0 then set nspeed to 0.
* src/DiskWriter.h
(messageDigest.h): New include.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/ChunkChecksumValidator.h: New class.
* src/DiskAdaptorWriter.h: New class.
* src/prefs.h
(PREF_REALTIME_CHUNK_CHECKSUM): New definition.
(PREF_CHECK_INTEGRITY): New definition.
* src/HttpResponseCommand.cc
(handleDefaultEncoding): Added method "HEAD" handling.
Removed the call to
e->segmentMan->shouldCancelDownloadForSafety().
(handleOtherEncoding):
Added the call to
e->segmentMan->shouldCancelDownloadForSafety().
(createHttpDownloadCommand): Set maxDownloadSpeedLimit,
startupIdleTime, lowestDownloadSpeedLimit to command.
* src/SegmentMan.h
(getSegmentEntryByIndex): New function.
(getSegmentEntryByCuid): New function.
(getSegmentEntryIteratorByCuid): New function.
(diskWriter): DiskWriter -> DiskWriterHandle
(pieceHashes): New variable.
(chunkHashLength): New variable.
(digestAlgo): New variable.
(FindPeerStat): Removed.
(getPeerStat): Rewritten.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
(tryChunkChecksumValidation): New function.
(isChunkChecksumValidationReady): New function.
* src/BitfieldMan.cc
(BitfieldMan): Initialized bitfieldLength, blocks to 0.
(BitfieldMan): Initialized blockLength, totalLength,
bitfieldLength,
blocks to 0.
(isBitRangeSet): New function.
(unsetBitRange): New function.
* src/FtpNegotiateCommand.cc
(executeInternal): Set maxDownloadSpeedLimit,
startupIdleTime, lowestDownloadSpeedLimit to command.
(recvSize): Added method "HEAD" handling.
Removed the call to
e->segmentMan->shouldCancelDownloadForSafety().
* src/AbstractSingleDiskAdaptor.cc
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/AbstractSingleDiskAdaptor.h
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/Util.h
(indexRange): New function.
* src/MetalinkEntry.cc
(MetalinkEntry): Initialized chunkChecksum to 0.
* src/ShaVisitor.cc
(~ShaVisitor): Removed the call to ctx.digestFree().
* src/SegmentMan.cc
(ChunkChecksumValidator.h): New include.
(SegmentMan): Initialized chunkHashLength to 0. Initialized
digestAlgo
to DIGEST_ALGO_SHA1.
(~SegmentMan): Removed diskWriter.
(FindSegmentEntryByIndex): Removed.
(FindSegmentEntryByCuid): Removed.
(checkoutSegment): Rewritten.
(findSlowerSegmentEntry): Rewritten.
(getSegment): Rewritten.
(updateSegment): Rewritten.
(completeSegment): Rewritten.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
(isChunkChecksumValidationReady): New function.
(tryChunkChecksumValidation): New function.
* src/Xml2MetalinkProcessor.cc
(getEntry): Get size and set it to entry.
Get chunk checksum and set it to entry.
(getPieceHash): New function.
* src/Util.cc
(sha1Sum): Removed ctx.digestFree()
(fileChecksum): Removed ctx.digestFree()
(indexRange): New function.
* src/Request.cc
(METHOD_GET): New variable.
(METHOD_HEAD): New variable.
(Request): Added method.
* src/UrlRequestInfo.cc
(FatalException.h): New include.
(message.h): New include.
(operator<<): Added operator<< for class HeadResult.
(getHeadResult): New function.
(execute): Get filename and size in separate download engine.
* src/ChunkChecksumValidator.cc: New class.
* src/DownloadCommand.cc:
(DownloadCommand): Added peerStat.
(executeInternal): Use maxDownloadSpeedLimit member instead of
getting
the value from Option.
The buffer size is now 16KB.
Use peerStat member instead of getting it from SegmentMan.
Use startupIdleTime member instead of gettingit from Option.
Added chunk checksum validation.
* src/AbstractDiskWriter.cc
(AbstractDiskWriter): Removed ctx.
(~AbstractDiskWriter): Removed ctx.digestFree()
(writeDataInternal): Returns the return value of write.
(readDataInternal): Returns the return value of read.
(sha1Sum): Renamed as messageDigest
(messageDigest): New function.
* src/AbstractDiwkWriter.h
(messageDigest.h): Removed include.
(ctx): Removed.
(sha1Sum): Renamed as messageDigest
(messageDigest): New function.
* src/DefaultPieceStorage.h
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/NullFileAllocationMonitor.h: New class.
2007-01-24 15:55:34 +00:00
|
|
|
switch(entry.type) {
|
|
|
|
case SocketEntry::TYPE_RD:
|
|
|
|
FD_SET(fd, &rfdset);
|
|
|
|
break;
|
|
|
|
case SocketEntry::TYPE_WR:
|
|
|
|
FD_SET(fd, &wfdset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(fdmax < fd) {
|
|
|
|
fdmax = fd;
|
|
|
|
}
|
|
|
|
}
|
2006-07-28 14:06:47 +00:00
|
|
|
}
|
|
|
|
|
2006-08-07 16:05:00 +00:00
|
|
|
bool DownloadEngine::addSocket(const SocketEntry& entry) {
|
|
|
|
SocketEntries::iterator itr =
|
2008-02-08 15:53:45 +00:00
|
|
|
std::find(socketEntries.begin(), socketEntries.end(), entry);
|
2006-08-07 16:05:00 +00:00
|
|
|
if(itr == socketEntries.end()) {
|
|
|
|
socketEntries.push_back(entry);
|
2006-07-28 14:06:47 +00:00
|
|
|
updateFdSet();
|
2006-02-17 13:35:04 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-07 16:05:00 +00:00
|
|
|
bool DownloadEngine::deleteSocket(const SocketEntry& entry) {
|
|
|
|
SocketEntries::iterator itr =
|
2008-02-08 15:53:45 +00:00
|
|
|
std::find(socketEntries.begin(), socketEntries.end(), entry);
|
2006-08-07 16:05:00 +00:00
|
|
|
if(itr == socketEntries.end()) {
|
2006-02-17 13:35:04 +00:00
|
|
|
return false;
|
2006-07-19 17:07:45 +00:00
|
|
|
} else {
|
2006-08-07 16:05:00 +00:00
|
|
|
socketEntries.erase(itr);
|
2006-07-28 14:06:47 +00:00
|
|
|
updateFdSet();
|
2006-07-19 17:07:45 +00:00
|
|
|
return true;
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-19 17:07:45 +00:00
|
|
|
bool DownloadEngine::addSocketForReadCheck(const SocketHandle& socket,
|
2006-08-14 15:03:38 +00:00
|
|
|
Command* command) {
|
|
|
|
SocketEntry entry(socket, command, SocketEntry::TYPE_RD);
|
2006-08-07 16:05:00 +00:00
|
|
|
return addSocket(entry);
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
|
|
|
|
2006-07-19 17:07:45 +00:00
|
|
|
bool DownloadEngine::deleteSocketForReadCheck(const SocketHandle& socket,
|
2006-08-14 15:03:38 +00:00
|
|
|
Command* command) {
|
|
|
|
SocketEntry entry(socket, command, SocketEntry::TYPE_RD);
|
2006-08-07 16:05:00 +00:00
|
|
|
return deleteSocket(entry);
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
|
|
|
|
2006-07-19 17:07:45 +00:00
|
|
|
bool DownloadEngine::addSocketForWriteCheck(const SocketHandle& socket,
|
2006-08-14 15:03:38 +00:00
|
|
|
Command* command) {
|
|
|
|
SocketEntry entry(socket, command, SocketEntry::TYPE_WR);
|
2006-08-07 16:05:00 +00:00
|
|
|
return addSocket(entry);
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
|
|
|
|
2006-07-19 17:07:45 +00:00
|
|
|
bool DownloadEngine::deleteSocketForWriteCheck(const SocketHandle& socket,
|
2006-08-14 15:03:38 +00:00
|
|
|
Command* command) {
|
|
|
|
SocketEntry entry(socket, command, SocketEntry::TYPE_WR);
|
2006-08-07 16:05:00 +00:00
|
|
|
return deleteSocket(entry);
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
2006-08-11 12:29:55 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
void DownloadEngine::calculateStatistics()
|
|
|
|
{
|
|
|
|
if(!_statCalc.isNull()) {
|
|
|
|
_statCalc->calculateStat(_requestGroupMan, _fileAllocationMan, _checkIntegrityMan);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadEngine::onEndOfRun()
|
|
|
|
{
|
|
|
|
_requestGroupMan->closeFile();
|
|
|
|
_requestGroupMan->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadEngine::afterEachIteration()
|
|
|
|
{
|
2007-12-07 13:33:59 +00:00
|
|
|
if(globalHaltRequested == 1) {
|
|
|
|
logger->notice(_("Shutdown sequence commencing... Press Ctrl-C again for emergency shutdown."));
|
2008-02-11 05:07:08 +00:00
|
|
|
requestHalt();
|
2007-12-07 13:33:59 +00:00
|
|
|
globalHaltRequested = 2;
|
|
|
|
} else if(globalHaltRequested == 3) {
|
|
|
|
logger->notice(_("Emergency shutdown sequence commencing..."));
|
|
|
|
_requestGroupMan->forceHalt();
|
|
|
|
globalHaltRequested = 4;
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-11 05:07:08 +00:00
|
|
|
void DownloadEngine::requestHalt()
|
|
|
|
{
|
|
|
|
_haltRequested = true;
|
|
|
|
_requestGroupMan->halt();
|
|
|
|
}
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
void DownloadEngine::fillCommand()
|
|
|
|
{
|
|
|
|
addCommand(_requestGroupMan->getInitialCommands(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadEngine::setStatCalc(const StatCalcHandle& statCalc)
|
|
|
|
{
|
|
|
|
_statCalc = statCalc;
|
|
|
|
}
|
|
|
|
|
2007-11-24 11:32:22 +00:00
|
|
|
void DownloadEngine::addCommand(const Commands& commands)
|
|
|
|
{
|
|
|
|
this->commands.insert(this->commands.end(), commands.begin(), commands.end());
|
|
|
|
}
|
|
|
|
|
2006-08-21 13:18:51 +00:00
|
|
|
#ifdef ENABLE_ASYNC_DNS
|
2008-05-08 11:18:36 +00:00
|
|
|
bool DownloadEngine::addNameResolverCheck
|
|
|
|
(const SharedHandle<AsyncNameResolver>& resolver,
|
|
|
|
Command* command)
|
|
|
|
{
|
|
|
|
AsyncNameResolverEntry entry(resolver, command);
|
|
|
|
AsyncNameResolverEntries::iterator itr =
|
|
|
|
std::find(nameResolverEntries.begin(), nameResolverEntries.end(), entry);
|
2006-08-11 12:29:55 +00:00
|
|
|
if(itr == nameResolverEntries.end()) {
|
|
|
|
nameResolverEntries.push_back(entry);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-08 11:18:36 +00:00
|
|
|
bool DownloadEngine::deleteNameResolverCheck
|
|
|
|
(const SharedHandle<AsyncNameResolver>& resolver,
|
|
|
|
Command* command)
|
|
|
|
{
|
|
|
|
AsyncNameResolverEntry entry(resolver, command);
|
|
|
|
AsyncNameResolverEntries::iterator itr =
|
|
|
|
std::find(nameResolverEntries.begin(), nameResolverEntries.end(), entry);
|
2006-08-11 12:29:55 +00:00
|
|
|
if(itr == nameResolverEntries.end()) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
nameResolverEntries.erase(itr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2006-08-21 13:18:51 +00:00
|
|
|
#endif // ENABLE_ASYNC_DNS
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-04-20 05:42:15 +00:00
|
|
|
void DownloadEngine::setNoWait(bool b)
|
|
|
|
{
|
|
|
|
_noWait = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadEngine::addRoutineCommand(Command* command)
|
|
|
|
{
|
|
|
|
_routineCommands.push_back(command);
|
|
|
|
}
|
|
|
|
|
2008-04-22 08:52:47 +00:00
|
|
|
void DownloadEngine::poolSocket(const std::string& ipaddr, uint16_t port,
|
2008-05-08 13:18:25 +00:00
|
|
|
const SharedHandle<SocketCore>& sock,
|
|
|
|
time_t timeout)
|
2008-04-22 08:52:47 +00:00
|
|
|
{
|
|
|
|
std::string addr = ipaddr+":"+Util::uitos(port);
|
|
|
|
logger->info("Pool socket for %s", addr.c_str());
|
2008-05-08 13:18:25 +00:00
|
|
|
|
|
|
|
SocketPoolEntry e(sock, timeout);
|
|
|
|
std::multimap<std::string, SocketPoolEntry>::value_type p(addr, e);
|
|
|
|
_socketPool.insert(p);
|
2008-04-22 08:52:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SharedHandle<SocketCore>
|
|
|
|
DownloadEngine::popPooledSocket(const std::string& ipaddr, uint16_t port)
|
|
|
|
{
|
2008-05-08 13:18:25 +00:00
|
|
|
SharedHandle<SocketCore> s;
|
2008-04-22 08:52:47 +00:00
|
|
|
std::string addr = ipaddr+":"+Util::uitos(port);
|
2008-05-08 13:18:25 +00:00
|
|
|
|
|
|
|
std::multimap<std::string, SocketPoolEntry>::iterator first = _socketPool.find(addr);
|
|
|
|
|
|
|
|
for(std::multimap<std::string, SocketPoolEntry>::iterator i = first;
|
|
|
|
i != _socketPool.end() && (*i).first == addr; ++i) {
|
|
|
|
const SocketPoolEntry& e = (*i).second;
|
|
|
|
if(!e.isTimeout()) {
|
|
|
|
logger->info("Reuse socket for %s", addr.c_str());
|
|
|
|
s = e.getSocket();
|
|
|
|
_socketPool.erase(first, ++i);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-22 08:52:47 +00:00
|
|
|
}
|
2008-05-08 13:18:25 +00:00
|
|
|
return s;
|
2008-04-22 08:52:47 +00:00
|
|
|
}
|
|
|
|
|
2008-05-08 11:18:36 +00:00
|
|
|
SharedHandle<SocketCore>
|
|
|
|
DownloadEngine::popPooledSocket
|
|
|
|
(const std::deque<std::string>& ipaddrs, uint16_t port)
|
|
|
|
{
|
|
|
|
for(std::deque<std::string>::const_iterator i = ipaddrs.begin();
|
|
|
|
i != ipaddrs.end(); ++i) {
|
|
|
|
SharedHandle<SocketCore> s = popPooledSocket(*i, port);
|
|
|
|
if(!s.isNull()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SharedHandle<SocketCore>();
|
|
|
|
}
|
|
|
|
|
2008-05-08 13:18:25 +00:00
|
|
|
DownloadEngine::SocketPoolEntry::SocketPoolEntry
|
|
|
|
(const SharedHandle<SocketCore>& socket,
|
|
|
|
time_t timeout):
|
|
|
|
_socket(socket),
|
|
|
|
_timeout(timeout) {}
|
|
|
|
|
|
|
|
DownloadEngine::SocketPoolEntry::~SocketPoolEntry() {}
|
|
|
|
|
|
|
|
bool DownloadEngine::SocketPoolEntry::isTimeout() const
|
|
|
|
{
|
|
|
|
return _registeredTime.elapsed(_timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedHandle<SocketCore> DownloadEngine::SocketPoolEntry::getSocket() const
|
|
|
|
{
|
|
|
|
return _socket;
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|