diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2007-10-11 16:58:24 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2007-10-11 16:58:24 +0000 |
| commit | 048a2cf59737f761876e81a77e8d064c45c752d7 (patch) | |
| tree | 65c9d5498aafe6a8c8e640ddfcc43c7013504d0d /src/CheckIntegrityEntry.cc | |
| parent | e26bbbb9eee140ba24402fe872a752b42f0077de (diff) | |
2007-10-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Implemented BitTorrent/http/ftp integrated download.
I've rewritten lots of files and now some headers have forward
class declarations to reduce compile time.
The implementation is extremely alpha stage, I recommend to use this
for testing purpose only.
Diffstat (limited to 'src/CheckIntegrityEntry.cc')
| -rw-r--r-- | src/CheckIntegrityEntry.cc | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/src/CheckIntegrityEntry.cc b/src/CheckIntegrityEntry.cc index d4ae1e7c..0377b907 100644 --- a/src/CheckIntegrityEntry.cc +++ b/src/CheckIntegrityEntry.cc @@ -34,33 +34,64 @@ /* copyright --> */ #include "CheckIntegrityEntry.h" #include "DlAbortEx.h" +#include "Command.h" +#include "RequestGroup.h" +#include "IteratableChunkChecksumValidator.h" +#include "DownloadContext.h" +#include "DownloadEngine.h" + +CheckIntegrityEntry::CheckIntegrityEntry(RequestGroup* requestGroup, + Command* nextCommand): + RequestGroupEntry(requestGroup, nextCommand), + _validator(0) +{} + +CheckIntegrityEntry::~CheckIntegrityEntry() {} void CheckIntegrityEntry::validateChunk() { _validator->validateChunk(); } -bool CheckIntegrityEntry::finished() const +int64_t CheckIntegrityEntry::getTotalLength() +{ + if(_validator.isNull()) { + return 0; + } else { + return _validator->getTotalLength(); + } +} + +int64_t CheckIntegrityEntry::getCurrentLength() +{ + if(_validator.isNull()) { + return 0; + } else { + return _validator->getCurrentOffset(); + } +} + +bool CheckIntegrityEntry::finished() { return _validator->finished(); } -int64_t CheckIntegrityEntry::getCurrentLength() const +bool CheckIntegrityEntry::isValidationReady() { - return _validator->getCurrentOffset(); + DownloadContextHandle dctx = _requestGroup->getDownloadContext(); + return dctx->getPieceHashes().size() > 0 && + dctx->getPieceHashes().size() == (uint32_t)dctx->getNumPieces(); } 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(); + new IteratableChunkChecksumValidator(_requestGroup->getDownloadContext(), + _requestGroup->getPieceStorage()); _validator = validator; } + +void CheckIntegrityEntry::updatePieceStorage() +{ + _validator->updatePieceStorage(); +} |
