2006-04-16 14:42:26 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-04-16 14:42:26 +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
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-09-21 15:31:24 +00:00
|
|
|
*
|
|
|
|
* 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-04-16 14:42:26 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "MultiDiskAdaptor.h"
|
2008-11-08 08:36:40 +00:00
|
|
|
|
|
|
|
#include <cassert>
|
2009-02-11 07:41:15 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <map>
|
2008-11-08 08:36:40 +00:00
|
|
|
|
2007-01-08 00:13:25 +00:00
|
|
|
#include "DefaultDiskWriter.h"
|
|
|
|
#include "message.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "FileEntry.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "MultiFileAllocationIterator.h"
|
|
|
|
#include "DefaultDiskWriterFactory.h"
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
#include "DlAbortEx.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "File.h"
|
2008-04-27 02:22:14 +00:00
|
|
|
#include "StringFormat.h"
|
2008-06-08 10:47:00 +00:00
|
|
|
#include "Logger.h"
|
|
|
|
#include "SimpleRandomizer.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
DiskWriterEntry::DiskWriterEntry(const SharedHandle<FileEntry>& fileEntry):
|
2010-06-21 13:51:56 +00:00
|
|
|
fileEntry_(fileEntry), open_(false), directIO_(false),
|
|
|
|
needsFileAllocation_(false) {}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2009-03-09 15:10:26 +00:00
|
|
|
const std::string& DiskWriterEntry::getFilePath() const
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return fileEntry_->getPath();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2009-03-09 15:10:26 +00:00
|
|
|
void DiskWriterEntry::initAndOpenFile()
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(!diskWriter_.isNull()) {
|
|
|
|
diskWriter_->initAndOpenFile(fileEntry_->getLength());
|
|
|
|
if(directIO_) {
|
|
|
|
diskWriter_->enableDirectIO();
|
2008-09-07 11:37:15 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
open_ = true;
|
2008-06-08 10:47:00 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2009-03-09 15:10:26 +00:00
|
|
|
void DiskWriterEntry::openFile()
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(!diskWriter_.isNull()) {
|
|
|
|
diskWriter_->openFile(fileEntry_->getLength());
|
|
|
|
if(directIO_) {
|
|
|
|
diskWriter_->enableDirectIO();
|
2008-09-07 11:37:15 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
open_ = true;
|
2008-06-08 10:47:00 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2009-03-09 15:10:26 +00:00
|
|
|
void DiskWriterEntry::openExistingFile()
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(!diskWriter_.isNull()) {
|
|
|
|
diskWriter_->openExistingFile(fileEntry_->getLength());
|
|
|
|
if(directIO_) {
|
|
|
|
diskWriter_->enableDirectIO();
|
2008-09-07 11:37:15 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
open_ = true;
|
2008-06-08 10:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void DiskWriterEntry::closeFile()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(open_) {
|
|
|
|
diskWriter_->closeFile();
|
|
|
|
open_ = false;
|
2008-06-08 10:47:00 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2009-03-09 15:10:26 +00:00
|
|
|
bool DiskWriterEntry::fileExists()
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return fileEntry_->exists();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
uint64_t DiskWriterEntry::size() const
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2009-05-04 07:50:38 +00:00
|
|
|
return File(getFilePath()).size();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DiskWriterEntry::setDiskWriter(const SharedHandle<DiskWriter>& diskWriter)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
diskWriter_ = diskWriter;
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DiskWriterEntry::operator<(const DiskWriterEntry& entry) const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return fileEntry_ < entry.fileEntry_;
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-06-08 10:47:00 +00:00
|
|
|
void DiskWriterEntry::enableDirectIO()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(open_) {
|
|
|
|
diskWriter_->enableDirectIO();
|
2008-06-08 10:47:00 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
directIO_ = true;
|
2008-06-08 10:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DiskWriterEntry::disableDirectIO()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(open_) {
|
|
|
|
diskWriter_->disableDirectIO();
|
2008-06-08 10:47:00 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
directIO_ = false;
|
2008-06-08 10:47:00 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
MultiDiskAdaptor::MultiDiskAdaptor():
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceLength_(0),
|
|
|
|
maxOpenFiles_(DEFAULT_MAX_OPEN_FILES),
|
|
|
|
directIOAllowed_(false),
|
|
|
|
readOnly_(false) {}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-06-15 16:19:06 +00:00
|
|
|
static SharedHandle<DiskWriterEntry> createDiskWriterEntry
|
|
|
|
(const SharedHandle<FileEntry>& fileEntry,
|
2008-09-07 11:37:15 +00:00
|
|
|
bool needsFileAllocation)
|
2008-06-15 16:19:06 +00:00
|
|
|
{
|
|
|
|
SharedHandle<DiskWriterEntry> entry(new DiskWriterEntry(fileEntry));
|
2008-09-07 11:37:15 +00:00
|
|
|
entry->needsFileAllocation(needsFileAllocation);
|
2008-06-15 16:19:06 +00:00
|
|
|
return entry;
|
2010-06-11 12:49:14 +00:00
|
|
|
}
|
2008-06-15 16:19:06 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
void MultiDiskAdaptor::resetDiskWriterEntries()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
diskWriterEntries_.clear();
|
2008-06-15 16:19:06 +00:00
|
|
|
|
2010-06-11 12:49:14 +00:00
|
|
|
if(getFileEntries().empty()) {
|
2008-06-15 16:19:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-28 10:37:15 +00:00
|
|
|
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
2010-06-11 12:49:14 +00:00
|
|
|
getFileEntries().begin(), eoi = getFileEntries().end(); i != eoi; ++i) {
|
2010-06-21 13:51:56 +00:00
|
|
|
diskWriterEntries_.push_back
|
2008-09-07 11:37:15 +00:00
|
|
|
(createDiskWriterEntry(*i, (*i)->isRequested()));
|
|
|
|
}
|
2009-02-11 07:41:15 +00:00
|
|
|
std::map<std::string, bool> dwreq;
|
2010-06-21 13:51:56 +00:00
|
|
|
// TODO Currently, pieceLength_ == 0 is used for unit testing only.
|
|
|
|
if(pieceLength_ > 0) {
|
2010-02-28 16:04:52 +00:00
|
|
|
std::vector<SharedHandle<DiskWriterEntry> >::const_iterator done =
|
2010-06-21 13:51:56 +00:00
|
|
|
diskWriterEntries_.begin();
|
2010-02-28 16:04:52 +00:00
|
|
|
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator itr =
|
2010-06-21 13:51:56 +00:00
|
|
|
diskWriterEntries_.begin(), eoi = diskWriterEntries_.end();
|
2010-02-28 16:04:52 +00:00
|
|
|
itr != eoi;) {
|
2009-02-11 07:41:15 +00:00
|
|
|
const SharedHandle<FileEntry>& fileEntry = (*itr)->getFileEntry();
|
|
|
|
|
|
|
|
if(!fileEntry->isRequested()) {
|
2010-01-05 16:01:46 +00:00
|
|
|
++itr;
|
|
|
|
continue;
|
2008-06-15 16:19:06 +00:00
|
|
|
}
|
2008-09-07 11:37:15 +00:00
|
|
|
off_t pieceStartOffset =
|
2010-06-21 13:51:56 +00:00
|
|
|
(fileEntry->getOffset()/pieceLength_)*pieceLength_;
|
|
|
|
if(itr != diskWriterEntries_.begin()) {
|
2010-02-28 16:04:52 +00:00
|
|
|
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
2010-01-05 16:01:46 +00:00
|
|
|
itr-1; true; --i) {
|
|
|
|
const SharedHandle<FileEntry>& fileEntry = (*i)->getFileEntry();
|
|
|
|
if(pieceStartOffset <= fileEntry->getOffset() ||
|
|
|
|
(uint64_t)pieceStartOffset <
|
|
|
|
fileEntry->getOffset()+fileEntry->getLength()) {
|
|
|
|
(*i)->needsFileAllocation(true);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(i == done) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-06-15 16:19:06 +00:00
|
|
|
}
|
|
|
|
|
2009-02-11 07:41:15 +00:00
|
|
|
if(fileEntry->getLength() > 0) {
|
2010-01-05 16:01:46 +00:00
|
|
|
off_t lastPieceStartOffset =
|
2010-06-11 12:49:14 +00:00
|
|
|
(fileEntry->getOffset()+fileEntry->getLength()-1)/
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceLength_*pieceLength_;
|
2010-06-11 12:49:14 +00:00
|
|
|
if(getLogger()->debug()) {
|
|
|
|
getLogger()->debug("Checking adjacent backward file to %s"
|
2010-06-21 13:51:56 +00:00
|
|
|
" whose lastPieceStartOffset+pieceLength_=%lld",
|
2010-06-11 12:49:14 +00:00
|
|
|
fileEntry->getPath().c_str(),
|
2010-06-21 13:51:56 +00:00
|
|
|
lastPieceStartOffset+pieceLength_);
|
2010-02-09 12:20:20 +00:00
|
|
|
}
|
2010-01-05 16:01:46 +00:00
|
|
|
++itr;
|
|
|
|
// adjacent backward files are not needed to be allocated. They
|
|
|
|
// just requre DiskWriter
|
2010-02-28 16:04:52 +00:00
|
|
|
for(; itr != eoi &&
|
2010-01-05 16:01:46 +00:00
|
|
|
(!(*itr)->getFileEntry()->isRequested() ||
|
|
|
|
(*itr)->getFileEntry()->getLength() == 0); ++itr) {
|
2010-06-11 12:49:14 +00:00
|
|
|
if(getLogger()->debug()) {
|
|
|
|
getLogger()->debug("file=%s, offset=%lld",
|
|
|
|
(*itr)->getFileEntry()->getPath().c_str(),
|
|
|
|
(*itr)->getFileEntry()->getOffset());
|
2010-02-09 12:20:20 +00:00
|
|
|
}
|
2010-01-05 16:01:46 +00:00
|
|
|
if((*itr)->getFileEntry()->getOffset() <
|
2010-06-21 13:51:56 +00:00
|
|
|
static_cast<off_t>(lastPieceStartOffset+pieceLength_)) {
|
2010-06-11 12:49:14 +00:00
|
|
|
if(getLogger()->debug()) {
|
|
|
|
getLogger()->debug("%s needs diskwriter",
|
|
|
|
(*itr)->getFileEntry()->getPath().c_str());
|
2010-02-09 12:20:20 +00:00
|
|
|
}
|
2010-01-05 16:01:46 +00:00
|
|
|
dwreq[(*itr)->getFileEntry()->getPath()] = true;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done = itr-1;
|
2009-02-11 07:41:15 +00:00
|
|
|
} else {
|
2010-01-05 16:01:46 +00:00
|
|
|
done = itr;
|
|
|
|
++itr;
|
2008-06-15 16:19:06 +00:00
|
|
|
}
|
2007-01-08 00:13:25 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-07 11:37:15 +00:00
|
|
|
DefaultDiskWriterFactory dwFactory;
|
2010-02-28 16:04:52 +00:00
|
|
|
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
2010-06-21 13:51:56 +00:00
|
|
|
diskWriterEntries_.begin(), eoi = diskWriterEntries_.end();
|
2010-02-28 16:04:52 +00:00
|
|
|
i != eoi; ++i) {
|
2009-02-11 07:41:15 +00:00
|
|
|
if((*i)->needsFileAllocation() ||
|
|
|
|
dwreq.find((*i)->getFileEntry()->getPath()) != dwreq.end() ||
|
2009-03-09 15:10:26 +00:00
|
|
|
(*i)->fileExists()) {
|
2010-06-11 12:49:14 +00:00
|
|
|
if(getLogger()->debug()) {
|
|
|
|
getLogger()->debug("Creating DiskWriter for filename=%s",
|
|
|
|
(*i)->getFilePath().c_str());
|
2010-02-09 12:20:20 +00:00
|
|
|
}
|
2009-05-04 07:50:38 +00:00
|
|
|
(*i)->setDiskWriter(dwFactory.newDiskWriter((*i)->getFilePath()));
|
2010-06-21 13:51:56 +00:00
|
|
|
if(directIOAllowed_) {
|
2010-01-05 16:01:46 +00:00
|
|
|
(*i)->getDiskWriter()->allowDirectIO();
|
2009-05-04 08:11:40 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(readOnly_) {
|
2010-01-05 16:01:46 +00:00
|
|
|
(*i)->getDiskWriter()->enableReadOnly();
|
2009-02-23 13:27:08 +00:00
|
|
|
}
|
2008-09-07 11:37:15 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-16 14:42:26 +00:00
|
|
|
}
|
|
|
|
|
2009-03-09 15:10:26 +00:00
|
|
|
void MultiDiskAdaptor::mkdir() const
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2009-06-28 10:37:15 +00:00
|
|
|
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
2010-06-21 13:51:56 +00:00
|
|
|
diskWriterEntries_.begin(), eoi = diskWriterEntries_.end();
|
2010-02-28 16:04:52 +00:00
|
|
|
i != eoi; ++i) {
|
2009-03-09 15:10:26 +00:00
|
|
|
(*i)->getFileEntry()->setupDir();
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-08 10:47:00 +00:00
|
|
|
void MultiDiskAdaptor::openIfNot
|
2009-03-09 15:10:26 +00:00
|
|
|
(const SharedHandle<DiskWriterEntry>& entry, void (DiskWriterEntry::*open)())
|
2008-06-08 10:47:00 +00:00
|
|
|
{
|
|
|
|
if(!entry->isOpen()) {
|
2010-06-11 12:49:14 +00:00
|
|
|
// getLogger()->debug("DiskWriterEntry: Cache MISS. offset=%s",
|
2010-01-05 16:01:46 +00:00
|
|
|
// util::itos(entry->getFileEntry()->getOffset()).c_str());
|
2008-06-08 10:47:00 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
size_t numOpened = openedDiskWriterEntries_.size();
|
2009-03-09 15:10:26 +00:00
|
|
|
(entry.get()->*open)();
|
2010-06-21 13:51:56 +00:00
|
|
|
if(numOpened >= maxOpenFiles_) {
|
2008-06-08 10:47:00 +00:00
|
|
|
// Cache is full.
|
|
|
|
// Choose one DiskWriterEntry randomly and close it.
|
2010-06-11 12:49:14 +00:00
|
|
|
size_t index =
|
|
|
|
SimpleRandomizer::getInstance()->getRandomNumber(numOpened);
|
2009-06-28 10:37:15 +00:00
|
|
|
std::vector<SharedHandle<DiskWriterEntry> >::iterator i =
|
2010-06-21 13:51:56 +00:00
|
|
|
openedDiskWriterEntries_.begin();
|
2008-06-08 10:47:00 +00:00
|
|
|
std::advance(i, index);
|
|
|
|
(*i)->closeFile();
|
|
|
|
(*i) = entry;
|
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
openedDiskWriterEntries_.push_back(entry);
|
2008-06-08 10:47:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-06-11 12:49:14 +00:00
|
|
|
// getLogger()->debug("DiskWriterEntry: Cache HIT. offset=%s",
|
2010-01-05 16:01:46 +00:00
|
|
|
// util::itos(entry->getFileEntry()->getOffset()).c_str());
|
2008-06-08 10:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
void MultiDiskAdaptor::openFile()
|
|
|
|
{
|
2007-01-08 00:13:25 +00:00
|
|
|
resetDiskWriterEntries();
|
2009-03-09 15:10:26 +00:00
|
|
|
mkdir();
|
2008-11-08 08:36:40 +00:00
|
|
|
// Call DiskWriterEntry::openFile to make sure that zero-length files are
|
|
|
|
// created.
|
2010-06-21 13:51:56 +00:00
|
|
|
for(DiskWriterEntries::const_iterator itr = diskWriterEntries_.begin(),
|
|
|
|
eoi = diskWriterEntries_.end(); itr != eoi; ++itr) {
|
2009-03-09 15:10:26 +00:00
|
|
|
openIfNot(*itr, &DiskWriterEntry::openFile);
|
2008-11-08 08:36:40 +00:00
|
|
|
}
|
2006-04-16 14:42:26 +00:00
|
|
|
}
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
void MultiDiskAdaptor::initAndOpenFile()
|
|
|
|
{
|
2007-01-08 00:13:25 +00:00
|
|
|
resetDiskWriterEntries();
|
2009-03-09 15:10:26 +00:00
|
|
|
mkdir();
|
2008-06-08 10:47:00 +00:00
|
|
|
// Call DiskWriterEntry::initAndOpenFile to make files truncated.
|
2010-06-21 13:51:56 +00:00
|
|
|
for(DiskWriterEntries::const_iterator itr = diskWriterEntries_.begin(),
|
|
|
|
eoi = diskWriterEntries_.end(); itr != eoi; ++itr) {
|
2009-03-09 15:10:26 +00:00
|
|
|
openIfNot(*itr, &DiskWriterEntry::initAndOpenFile);
|
2007-01-08 00:13:25 +00:00
|
|
|
}
|
2006-04-16 14:42:26 +00:00
|
|
|
}
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
void MultiDiskAdaptor::openExistingFile()
|
|
|
|
{
|
2007-01-08 00:13:25 +00:00
|
|
|
resetDiskWriterEntries();
|
2008-06-08 10:47:00 +00:00
|
|
|
// Not need to call openIfNot here.
|
2007-01-08 00:13:25 +00:00
|
|
|
}
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
void MultiDiskAdaptor::closeFile()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
std::for_each(diskWriterEntries_.begin(), diskWriterEntries_.end(),
|
2010-06-11 12:49:14 +00:00
|
|
|
mem_fun_sh(&DiskWriterEntry::closeFile));
|
2006-04-16 14:42:26 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 01:13:22 +00:00
|
|
|
static bool isInRange(const DiskWriterEntryHandle entry, off_t offset)
|
2007-01-08 00:13:25 +00:00
|
|
|
{
|
2007-01-11 16:32:31 +00:00
|
|
|
return entry->getFileEntry()->getOffset() <= offset &&
|
2010-06-11 12:49:14 +00:00
|
|
|
(uint64_t)offset <
|
|
|
|
entry->getFileEntry()->getOffset()+entry->getFileEntry()->getLength();
|
2007-01-08 00:13:25 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 01:13:22 +00:00
|
|
|
static size_t calculateLength(const DiskWriterEntryHandle entry,
|
2010-01-05 16:01:46 +00:00
|
|
|
off_t fileOffset, size_t rem)
|
2007-01-08 00:13:25 +00:00
|
|
|
{
|
2008-03-09 12:24:01 +00:00
|
|
|
size_t length;
|
|
|
|
if(entry->getFileEntry()->getLength() < (uint64_t)fileOffset+rem) {
|
2007-01-11 16:32:31 +00:00
|
|
|
length = entry->getFileEntry()->getLength()-fileOffset;
|
2007-01-08 00:13:25 +00:00
|
|
|
} else {
|
|
|
|
length = rem;
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2008-05-11 01:13:22 +00:00
|
|
|
class OffsetCompare {
|
|
|
|
public:
|
|
|
|
bool operator()(off_t offset, const SharedHandle<DiskWriterEntry>& dwe)
|
|
|
|
{
|
|
|
|
return offset < dwe->getFileEntry()->getOffset();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static DiskWriterEntries::const_iterator
|
2010-06-11 12:49:14 +00:00
|
|
|
findFirstDiskWriterEntry
|
|
|
|
(const DiskWriterEntries& diskWriterEntries, off_t offset)
|
2008-05-11 01:13:22 +00:00
|
|
|
{
|
|
|
|
DiskWriterEntries::const_iterator first =
|
|
|
|
std::upper_bound(diskWriterEntries.begin(), diskWriterEntries.end(),
|
2010-01-05 16:01:46 +00:00
|
|
|
offset, OffsetCompare());
|
2008-05-11 01:13:22 +00:00
|
|
|
|
|
|
|
--first;
|
|
|
|
|
|
|
|
// In case when offset is out-of-range
|
|
|
|
if(!isInRange(*first, offset)) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX
|
2008-05-11 01:13:22 +00:00
|
|
|
(StringFormat(EX_FILE_OFFSET_OUT_OF_RANGE,
|
2010-01-05 16:01:46 +00:00
|
|
|
util::itos(offset, true).c_str()).str());
|
2008-05-11 01:13:22 +00:00
|
|
|
}
|
|
|
|
return first;
|
|
|
|
}
|
|
|
|
|
2008-10-21 15:34:56 +00:00
|
|
|
static void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e,
|
2010-01-05 16:01:46 +00:00
|
|
|
off_t offset)
|
2008-10-21 15:34:56 +00:00
|
|
|
{
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX
|
2008-10-21 15:34:56 +00:00
|
|
|
(StringFormat("DiskWriter for offset=%s, filename=%s is not opened.",
|
2010-01-05 16:01:46 +00:00
|
|
|
util::itos(offset).c_str(),
|
|
|
|
e->getFilePath().c_str()).str());
|
2008-10-21 15:34:56 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 01:13:22 +00:00
|
|
|
void MultiDiskAdaptor::writeData(const unsigned char* data, size_t len,
|
2010-01-05 16:01:46 +00:00
|
|
|
off_t offset)
|
2008-05-11 01:13:22 +00:00
|
|
|
{
|
2010-06-11 12:49:14 +00:00
|
|
|
DiskWriterEntries::const_iterator first =
|
2010-06-21 13:51:56 +00:00
|
|
|
findFirstDiskWriterEntry(diskWriterEntries_, offset);
|
2008-05-11 01:13:22 +00:00
|
|
|
|
|
|
|
size_t rem = len;
|
|
|
|
off_t fileOffset = offset-(*first)->getFileEntry()->getOffset();
|
2010-02-28 16:04:52 +00:00
|
|
|
for(DiskWriterEntries::const_iterator i = first,
|
2010-06-21 13:51:56 +00:00
|
|
|
eoi = diskWriterEntries_.end(); i != eoi; ++i) {
|
2008-05-11 01:13:22 +00:00
|
|
|
size_t writeLength = calculateLength(*i, fileOffset, rem);
|
2008-06-08 10:47:00 +00:00
|
|
|
|
2009-03-09 15:10:26 +00:00
|
|
|
openIfNot(*i, &DiskWriterEntry::openFile);
|
2008-06-08 10:47:00 +00:00
|
|
|
|
2008-10-21 15:34:56 +00:00
|
|
|
if(!(*i)->isOpen()) {
|
2009-03-09 15:10:26 +00:00
|
|
|
throwOnDiskWriterNotOpened(*i, offset+(len-rem));
|
2008-10-21 15:34:56 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 01:13:22 +00:00
|
|
|
(*i)->getDiskWriter()->writeData(data+(len-rem), writeLength, fileOffset);
|
|
|
|
rem -= writeLength;
|
|
|
|
fileOffset = 0;
|
|
|
|
if(rem == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-11 12:49:14 +00:00
|
|
|
ssize_t MultiDiskAdaptor::readData
|
|
|
|
(unsigned char* data, size_t len, off_t offset)
|
2007-01-08 00:13:25 +00:00
|
|
|
{
|
2010-02-28 16:04:52 +00:00
|
|
|
DiskWriterEntries::const_iterator first =
|
2010-06-21 13:51:56 +00:00
|
|
|
findFirstDiskWriterEntry(diskWriterEntries_, offset);
|
2008-05-11 01:13:22 +00:00
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
size_t rem = len;
|
|
|
|
size_t totalReadLength = 0;
|
2008-05-11 01:13:22 +00:00
|
|
|
off_t fileOffset = offset-(*first)->getFileEntry()->getOffset();
|
2010-02-28 16:04:52 +00:00
|
|
|
for(DiskWriterEntries::const_iterator i = first,
|
2010-06-21 13:51:56 +00:00
|
|
|
eoi = diskWriterEntries_.end(); i != eoi; ++i) {
|
2008-05-11 01:13:22 +00:00
|
|
|
size_t readLength = calculateLength(*i, fileOffset, rem);
|
2008-06-08 10:47:00 +00:00
|
|
|
|
2009-03-09 15:10:26 +00:00
|
|
|
openIfNot(*i, &DiskWriterEntry::openFile);
|
2008-06-08 10:47:00 +00:00
|
|
|
|
2008-10-21 15:34:56 +00:00
|
|
|
if(!(*i)->isOpen()) {
|
2009-03-09 15:10:26 +00:00
|
|
|
throwOnDiskWriterNotOpened(*i, offset+(len-rem));
|
2008-10-21 15:34:56 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 01:13:22 +00:00
|
|
|
totalReadLength +=
|
|
|
|
(*i)->getDiskWriter()->readData(data+(len-rem), readLength, fileOffset);
|
|
|
|
rem -= readLength;
|
|
|
|
fileOffset = 0;
|
|
|
|
if(rem == 0) {
|
|
|
|
break;
|
2007-01-08 00:13:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return totalReadLength;
|
|
|
|
}
|
|
|
|
|
2007-01-11 16:32:31 +00:00
|
|
|
bool MultiDiskAdaptor::fileExists()
|
|
|
|
{
|
2010-06-11 12:49:14 +00:00
|
|
|
return std::find_if(getFileEntries().begin(), getFileEntries().end(),
|
|
|
|
mem_fun_sh(&FileEntry::exists)) !=
|
|
|
|
getFileEntries().end();
|
2007-01-11 16:32:31 +00:00
|
|
|
}
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
|
2008-09-07 08:29:09 +00:00
|
|
|
uint64_t MultiDiskAdaptor::size()
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
{
|
2008-03-09 12:24:01 +00:00
|
|
|
uint64_t size = 0;
|
2010-02-28 16:04:52 +00:00
|
|
|
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
2010-06-11 12:49:14 +00:00
|
|
|
getFileEntries().begin(), eoi = getFileEntries().end(); i != eoi; ++i) {
|
2009-06-28 10:37:15 +00:00
|
|
|
size += File((*i)->getPath()).size();
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
FileAllocationIteratorHandle MultiDiskAdaptor::fileAllocationIterator()
|
|
|
|
{
|
2010-06-11 12:49:14 +00:00
|
|
|
return SharedHandle<FileAllocationIterator>
|
|
|
|
(new MultiFileAllocationIterator(this));
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
2007-11-28 14:22:28 +00:00
|
|
|
|
|
|
|
void MultiDiskAdaptor::enableDirectIO()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
std::for_each(diskWriterEntries_.begin(), diskWriterEntries_.end(),
|
2010-06-11 12:49:14 +00:00
|
|
|
mem_fun_sh(&DiskWriterEntry::enableDirectIO));
|
2007-11-28 14:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultiDiskAdaptor::disableDirectIO()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
std::for_each(diskWriterEntries_.begin(), diskWriterEntries_.end(),
|
2010-06-11 12:49:14 +00:00
|
|
|
mem_fun_sh(&DiskWriterEntry::disableDirectIO));
|
2007-11-28 14:22:28 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2009-02-23 13:27:08 +00:00
|
|
|
void MultiDiskAdaptor::enableReadOnly()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
readOnly_ = true;
|
2009-02-23 13:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MultiDiskAdaptor::disableReadOnly()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
readOnly_ = false;
|
2009-02-23 13:27:08 +00:00
|
|
|
}
|
|
|
|
|
2008-08-26 12:39:07 +00:00
|
|
|
void MultiDiskAdaptor::cutTrailingGarbage()
|
|
|
|
{
|
2009-06-28 10:37:15 +00:00
|
|
|
for(std::vector<SharedHandle<DiskWriterEntry> >::const_iterator i =
|
2010-06-21 13:51:56 +00:00
|
|
|
diskWriterEntries_.begin(), eoi = diskWriterEntries_.end();
|
2010-02-28 16:04:52 +00:00
|
|
|
i != eoi; ++i) {
|
2008-08-26 12:39:07 +00:00
|
|
|
uint64_t length = (*i)->getFileEntry()->getLength();
|
2009-03-09 15:10:26 +00:00
|
|
|
if(File((*i)->getFilePath()).size() > length) {
|
2008-08-26 12:39:07 +00:00
|
|
|
// We need open file before calling DiskWriter::truncate(uint64_t)
|
2009-03-09 15:10:26 +00:00
|
|
|
openIfNot(*i, &DiskWriterEntry::openFile);
|
2008-08-26 12:39:07 +00:00
|
|
|
(*i)->getDiskWriter()->truncate(length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-08 12:34:36 +00:00
|
|
|
void MultiDiskAdaptor::setMaxOpenFiles(size_t maxOpenFiles)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
maxOpenFiles_ = maxOpenFiles;
|
2008-06-08 12:34:36 +00:00
|
|
|
}
|
|
|
|
|
2008-09-07 14:38:26 +00:00
|
|
|
size_t MultiDiskAdaptor::utime(const Time& actime, const Time& modtime)
|
|
|
|
{
|
|
|
|
size_t numOK = 0;
|
2009-06-28 10:37:15 +00:00
|
|
|
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
2010-06-11 12:49:14 +00:00
|
|
|
getFileEntries().begin(), eoi = getFileEntries().end(); i != eoi; ++i) {
|
2008-09-07 14:38:26 +00:00
|
|
|
if((*i)->isRequested()) {
|
2009-03-09 15:10:26 +00:00
|
|
|
File f((*i)->getPath());
|
2008-09-07 14:38:26 +00:00
|
|
|
if(f.isFile() && f.utime(actime, modtime)) {
|
2010-01-05 16:01:46 +00:00
|
|
|
++numOK;
|
2008-09-07 14:38:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return numOK;
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|