Skip to content

Commit

Permalink
2007-06-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Browse files Browse the repository at this point in the history
	Make download size shown in MB, KB.
	* src/ConsoleDownloadEngine.h (sendStatistics)
	* src/Util.h, srcUtil.cc (abbrevSize): New function.
  • Loading branch information
tatsuhiro-t committed Jun 5, 2007
1 parent 3dd06aa commit 2722c05
Show file tree
Hide file tree
Showing 31 changed files with 592 additions and 147 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2007-06-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Make download size shown in MB, KB.
* src/ConsoleDownloadEngine.h (sendStatistics)
* src/Util.h, srcUtil.cc (abbrevSize): New function.

2007-06-04 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Accept incoming connections if download rate is low.
Expand Down
7 changes: 2 additions & 5 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@
* Add seed mode.

* Rewrite ByteArrayDiskWriter, TrackerUpdateCommand with stringstream
* Make trakcerwatchercommand and trackerUploadCommand poses requestGroup
* Make trakcerwatchercommand and trackerUploadCommand posses requestGroup
* consider life cycle of requestGroup and segmentMan


* Add fancy console read out. like this:
100K/300M(10%)(3cn)(3more) 100KB/s [FileAlloc:35MB/40MB(90%)][Checksum:10MB/20MB(50%)]
* exit status: all downloads have been successful-> EXIT_SUCCESS,
some of downloads have been failed -> EXIT_FAILURE
* Create download command directly when 1connection download.
Consider timeout when file allocation/check integrity is enabled.

40 changes: 20 additions & 20 deletions src/CheckIntegrityCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,40 @@
#include "InitiateConnectionCommandFactory.h"
#include "DlAbortEx.h"
#include "message.h"
#include "DownloadCommand.h"
#include "prefs.h"

void CheckIntegrityCommand::initValidator()
CheckIntegrityCommand::CheckIntegrityCommand(int cuid, RequestGroup* requestGroup, DownloadEngine* e, const CheckIntegrityEntryHandle& entry):
RealtimeCommand(cuid, requestGroup, e),
_entry(entry)
{
_validator = new IteratableChunkChecksumValidator();
_validator->setChunkChecksum(_requestGroup->getChunkChecksum());
_validator->setDiskWriter(_requestGroup->getSegmentMan()->diskWriter);
_validator->setBitfield(_requestGroup->getSegmentMan()->getBitfield());
if(!_validator->canValidate()) {
// insufficient checksums.
throw new DlAbortEx("Insufficient checksums.");
}
_validator->init();
_e->_checkIntegrityMan->addCheckIntegrityEntry(_entry);
}

CheckIntegrityCommand::~CheckIntegrityCommand()
{
_e->_checkIntegrityMan->removeCheckIntegrityEntry(_entry);
}

bool CheckIntegrityCommand::executeInternal()
{
_validator->validateChunk();
if(_validator->finished()) {
_entry->validateChunk();
if(_entry->finished()) {
if(_requestGroup->downloadFinished()) {
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED, cuid, _requestGroup->getFilePath().c_str());
return true;
}
if(_requestGroup->needsFileAllocation()) {
FileAllocationEntryHandle entry = new FileAllocationEntry(cuid, _req, _requestGroup);
entry->setNextDownloadCommand(_nextDownloadCommand);
_nextDownloadCommand = 0;
FileAllocationEntryHandle entry = new FileAllocationEntry(cuid, _entry->getCurrentRequest(), _requestGroup, _requestGroup->getExistingFileLength());
entry->setNextDownloadCommand(_entry->popNextDownloadCommand());
_e->_fileAllocationMan->pushFileAllocationEntry(entry);
} else {
if(_nextDownloadCommand) {
_e->commands.push_back(_nextDownloadCommand);
_nextDownloadCommand = 0;
if(_timer.difference() <= _e->option->getAsInt(PREF_DIRECT_DOWNLOAD_TIMEOUT) &&
_entry->getNextDownloadCommand()) {
_e->commands.push_back(_entry->popNextDownloadCommand());
} else {
Commands commands = _requestGroup->createNextCommand(_e);
Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(cuid, _req, _requestGroup, _e);
Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(cuid, _entry->getCurrentRequest(), _requestGroup, _e);
commands.push_front(command);
_e->addCommand(commands);
}
Expand All @@ -91,6 +91,6 @@ bool CheckIntegrityCommand::handleException(Exception* e)
// exception. Fix this.
// The one of the solution is having a copy of bitfield before settting its
// all bit to 1. If exception is thrown, then assign the copy to the bitfield.
_requestGroup->markPieceDone(_validator->getCurrentOffset());
_requestGroup->markPieceDone(_entry->getCurrentLength());
return true;
}
31 changes: 6 additions & 25 deletions src/CheckIntegrityCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,22 @@
#define _D_CHECK_INTEGRITY_COMMAND_H_

#include "RealtimeCommand.h"
#include "Request.h"
#include "IteratableChunkChecksumValidator.h"
#include "DownloadCommand.h"
#include "CheckIntegrityEntry.h"
#include "TimeA2.h"

class CheckIntegrityCommand : public RealtimeCommand {
private:
RequestHandle _req;
IteratableChunkChecksumValidatorHandle _validator;
DownloadCommand* _nextDownloadCommand;
CheckIntegrityEntryHandle _entry;
Time _timer;
public:
CheckIntegrityCommand(int cuid, const RequestHandle& req, RequestGroup* requestGroup, DownloadEngine* e):
RealtimeCommand(cuid, requestGroup, e),
_req(req),
_validator(0),
_nextDownloadCommand(0)
{
++_requestGroup->numConnection;
}
CheckIntegrityCommand(int cuid, RequestGroup* requestGroup, DownloadEngine* e, const CheckIntegrityEntryHandle& entry);

virtual ~CheckIntegrityCommand()
{
--_requestGroup->numConnection;
delete _nextDownloadCommand;
}

void initValidator();
virtual ~CheckIntegrityCommand();

virtual bool executeInternal();

virtual bool handleException(Exception* e);

void setNextDownloadCommand(DownloadCommand* command)
{
_nextDownloadCommand = command;
}
};

#endif // _D_CHECK_INTEGRITY_COMMAND_H_
66 changes: 66 additions & 0 deletions src/CheckIntegrityEntry.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 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.
*/
/* copyright --> */
#include "CheckIntegrityEntry.h"
#include "DlAbortEx.h"

void CheckIntegrityEntry::validateChunk()
{
_validator->validateChunk();
}

bool CheckIntegrityEntry::finished() const
{
return _validator->finished();
}

int64_t CheckIntegrityEntry::getCurrentLength() const
{
return _validator->getCurrentOffset();
}

void CheckIntegrityEntry::initValidator()
{
IteratableChunkChecksumValidatorHandle validator =
new IteratableChunkChecksumValidator();
validator->setChunkChecksum(_requestGroup->getChunkChecksum());
validator->setDiskWriter(_requestGroup->getSegmentMan()->diskWriter);
validator->setBitfield(_requestGroup->getSegmentMan()->getBitfield());
if(!validator->canValidate()) {
// insufficient checksums.
throw new DlAbortEx("Insufficient checksums.");
}
validator->init();
_validator = validator;
}
65 changes: 65 additions & 0 deletions src/CheckIntegrityEntry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 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.
*/
/* copyright --> */
#ifndef _D_CHECK_INTEGRITY_ENTRY_H_
#define _D_CHECK_INTEGRITY_ENTRY_H_

#include "RequestGroupEntry.h"
#include "IteratableChunkChecksumValidator.h"

class CheckIntegrityEntry : public RequestGroupEntry {
private:
IteratableChunkChecksumValidatorHandle _validator;
public:
CheckIntegrityEntry(int cuid,
const RequestHandle& currentRequest,
RequestGroup* requestGroup):
RequestGroupEntry(cuid, currentRequest, requestGroup),
_validator(0)
{}

virtual ~CheckIntegrityEntry() {}

virtual int64_t getCurrentLength() const;

virtual bool finished() const;

void initValidator();

void validateChunk();
};

typedef SharedHandle<CheckIntegrityEntry> CheckIntegrityEntryHandle;
typedef deque<CheckIntegrityEntryHandle> CheckIntegrityEntries;
#endif // _D_CHECK_INTEGRITY_ENTRY_H_
80 changes: 80 additions & 0 deletions src/CheckIntegrityMan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 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.
*/
/* copyright --> */
#ifndef _D_CHECK_INTEGRITY_MAN_H_
#define _D_CHECK_INTEGRITY_MAN_H_

#include "common.h"
#include "CheckIntegrityEntry.h"

class CheckIntegrityMan {
private:
CheckIntegrityEntries _checkIntegrityEntries;
public:
void addCheckIntegrityEntry(const CheckIntegrityEntryHandle& entry)
{
_checkIntegrityEntries.push_back(entry);
}

bool removeCheckIntegrityEntry(const CheckIntegrityEntryHandle& entry)
{
CheckIntegrityEntries::iterator itr = find(_checkIntegrityEntries.begin(),
_checkIntegrityEntries.end(),
entry);
if(itr == _checkIntegrityEntries.end()) {
return false;
} else {
_checkIntegrityEntries.erase(itr);
return true;
}
}

CheckIntegrityEntryHandle getFirstCheckIntegrityEntry() const
{
if(_checkIntegrityEntries.empty()) {
return 0;
} else {
return _checkIntegrityEntries.front();
}
}

int32_t countCheckIntegrityEntry() const
{
return _checkIntegrityEntries.size();
}
};

typedef SharedHandle<CheckIntegrityMan> CheckIntegrityManHandle;

#endif // _D_CHECK_INTEGRITY_MAN_H_
Loading

0 comments on commit 2722c05

Please sign in to comment.