summaryrefslogtreecommitdiff
path: root/src/IteratableChunkChecksumValidator.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2015-12-27 18:39:47 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2015-12-27 18:40:08 +0900
commitb1132d6b10cd3791b9529d7031d723fd0e2d8215 (patch)
tree9ce465b42bf09372118335c7c619bb2b41869eaf /src/IteratableChunkChecksumValidator.cc
parent4abad2f64c9ff80144a61c5a9c2bea144852b883 (diff)
make clang-format using clang-format-3.6
Diffstat (limited to 'src/IteratableChunkChecksumValidator.cc')
-rw-r--r--src/IteratableChunkChecksumValidator.cc75
1 files changed, 40 insertions, 35 deletions
diff --git a/src/IteratableChunkChecksumValidator.cc b/src/IteratableChunkChecksumValidator.cc
index cdde1d54..8d1ad8fe 100644
--- a/src/IteratableChunkChecksumValidator.cc
+++ b/src/IteratableChunkChecksumValidator.cc
@@ -54,37 +54,39 @@
namespace aria2 {
-IteratableChunkChecksumValidator::IteratableChunkChecksumValidator
-(const std::shared_ptr<DownloadContext>& dctx,
- const std::shared_ptr<PieceStorage>& pieceStorage)
- : dctx_(dctx),
- pieceStorage_(pieceStorage),
- bitfield_(make_unique<BitfieldMan>(dctx_->getPieceLength(),
- dctx_->getTotalLength())),
- currentIndex_(0)
-{}
+IteratableChunkChecksumValidator::IteratableChunkChecksumValidator(
+ const std::shared_ptr<DownloadContext>& dctx,
+ const std::shared_ptr<PieceStorage>& pieceStorage)
+ : dctx_(dctx),
+ pieceStorage_(pieceStorage),
+ bitfield_(make_unique<BitfieldMan>(dctx_->getPieceLength(),
+ dctx_->getTotalLength())),
+ currentIndex_(0)
+{
+}
IteratableChunkChecksumValidator::~IteratableChunkChecksumValidator() {}
-
void IteratableChunkChecksumValidator::validateChunk()
{
- if(!finished()) {
+ if (!finished()) {
std::string actualChecksum;
try {
actualChecksum = calculateActualChecksum();
- if(actualChecksum == dctx_->getPieceHashes()[currentIndex_]) {
+ if (actualChecksum == dctx_->getPieceHashes()[currentIndex_]) {
bitfield_->setBit(currentIndex_);
- } else {
- A2_LOG_INFO
- (fmt(EX_INVALID_CHUNK_CHECKSUM,
- static_cast<unsigned long>(currentIndex_),
- static_cast<int64_t>(getCurrentOffset()),
- util::toHex(dctx_->getPieceHashes()[currentIndex_]).c_str(),
- util::toHex(actualChecksum).c_str()));
+ }
+ else {
+ A2_LOG_INFO(
+ fmt(EX_INVALID_CHUNK_CHECKSUM,
+ static_cast<unsigned long>(currentIndex_),
+ static_cast<int64_t>(getCurrentOffset()),
+ util::toHex(dctx_->getPieceHashes()[currentIndex_]).c_str(),
+ util::toHex(actualChecksum).c_str()));
bitfield_->unsetBit(currentIndex_);
}
- } catch(RecoverableException& ex) {
+ }
+ catch (RecoverableException& ex) {
A2_LOG_DEBUG_EX(fmt("Caught exception while validating piece index=%lu."
" Some part of file may be missing."
" Continue operation.",
@@ -94,8 +96,9 @@ void IteratableChunkChecksumValidator::validateChunk()
}
++currentIndex_;
- if(finished()) {
- pieceStorage_->setBitfield(bitfield_->getBitfield(), bitfield_->getBitfieldLength());
+ if (finished()) {
+ pieceStorage_->setBitfield(bitfield_->getBitfield(),
+ bitfield_->getBitfieldLength());
}
}
}
@@ -105,9 +108,10 @@ std::string IteratableChunkChecksumValidator::calculateActualChecksum()
int64_t offset = getCurrentOffset();
size_t length;
// When validating last piece
- if(currentIndex_+1 == dctx_->getNumPieces()) {
- length = dctx_->getTotalLength()-offset;
- } else {
+ if (currentIndex_ + 1 == dctx_->getNumPieces()) {
+ length = dctx_->getTotalLength() - offset;
+ }
+ else {
length = dctx_->getPieceLength();
}
return digest(offset, length);
@@ -120,19 +124,19 @@ void IteratableChunkChecksumValidator::init()
currentIndex_ = 0;
}
-std::string IteratableChunkChecksumValidator::digest(int64_t offset, size_t length)
+std::string IteratableChunkChecksumValidator::digest(int64_t offset,
+ size_t length)
{
std::array<unsigned char, 4_k> buf;
ctx_->reset();
- int64_t max = offset+length;
- while(offset < max) {
+ int64_t max = offset + length;
+ while (offset < max) {
size_t r = pieceStorage_->getDiskAdaptor()->readDataDropCache(
buf.data(), std::min(static_cast<int64_t>(buf.size()), max - offset),
offset);
- if(r == 0) {
- throw DL_ABORT_EX
- (fmt(EX_FILE_READ, dctx_->getBasePath().c_str(),
- "data is too short"));
+ if (r == 0) {
+ throw DL_ABORT_EX(
+ fmt(EX_FILE_READ, dctx_->getBasePath().c_str(), "data is too short"));
}
ctx_->update(buf.data(), r);
offset += r;
@@ -142,16 +146,17 @@ std::string IteratableChunkChecksumValidator::digest(int64_t offset, size_t leng
bool IteratableChunkChecksumValidator::finished() const
{
- if(currentIndex_ >= dctx_->getNumPieces()) {
+ if (currentIndex_ >= dctx_->getNumPieces()) {
return true;
- } else {
+ }
+ else {
return false;
}
}
int64_t IteratableChunkChecksumValidator::getCurrentOffset() const
{
- return static_cast<int64_t>(currentIndex_)*dctx_->getPieceLength();
+ return static_cast<int64_t>(currentIndex_) * dctx_->getPieceLength();
}
int64_t IteratableChunkChecksumValidator::getTotalLength() const