Consistent naming scheme for hash type and digest for Piece.

pull/1/head
Tatsuhiro Tsujikawa 2011-07-27 22:50:10 +09:00
parent 03f0774482
commit 02292feaba
5 changed files with 10 additions and 10 deletions

View File

@ -390,7 +390,7 @@ void DefaultBtProgressInfoFile::load()
#ifdef ENABLE_MESSAGE_DIGEST
piece->setHashAlgo(dctx_->getPieceHashType());
piece->setHashType(dctx_->getPieceHashType());
#endif // ENABLE_MESSAGE_DIGEST

View File

@ -106,7 +106,7 @@ SharedHandle<Piece> DefaultPieceStorage::checkOutPiece
piece.reset(new Piece(index, bitfieldMan_->getBlockLength(index)));
#ifdef ENABLE_MESSAGE_DIGEST
piece->setHashAlgo(downloadContext_->getPieceHashType());
piece->setHashType(downloadContext_->getPieceHashType());
#endif // ENABLE_MESSAGE_DIGEST
@ -735,7 +735,7 @@ void DefaultPieceStorage::markPiecesDone(uint64_t length)
#ifdef ENABLE_MESSAGE_DIGEST
p->setHashAlgo(downloadContext_->getPieceHashType());
p->setHashType(downloadContext_->getPieceHashType());
#endif // ENABLE_MESSAGE_DIGEST

View File

@ -190,20 +190,20 @@ size_t Piece::getCompletedLength()
#ifdef ENABLE_MESSAGE_DIGEST
void Piece::setHashAlgo(const std::string& algo)
void Piece::setHashType(const std::string& hashType)
{
hashAlgo_ = algo;
hashType_ = hashType;
}
bool Piece::updateHash
(uint32_t begin, const unsigned char* data, size_t dataLength)
{
if(hashAlgo_.empty()) {
if(hashType_.empty()) {
return false;
}
if(begin == nextBegin_ && nextBegin_+dataLength <= length_) {
if(!mdctx_) {
mdctx_ = MessageDigest::create(hashAlgo_);
mdctx_ = MessageDigest::create(hashType_);
}
mdctx_->update(data, dataLength);
nextBegin_ += dataLength;

View File

@ -66,7 +66,7 @@ private:
size_t nextBegin_;
std::string hashAlgo_;
std::string hashType_;
SharedHandle<MessageDigest> mdctx_;
@ -155,7 +155,7 @@ public:
#ifdef ENABLE_MESSAGE_DIGEST
void setHashAlgo(const std::string& algo);
void setHashType(const std::string& hashType);
// Updates hash value. This function compares begin and private variable
// nextBegin_ and only when they are equal, hash is updated eating data and

View File

@ -65,7 +65,7 @@ void PieceTest::testGetCompletedLength()
void PieceTest::testUpdateHash()
{
Piece p(0, 16, 2*1024*1024);
p.setHashAlgo("sha-1");
p.setHashType("sha-1");
std::string spam("SPAM!");
CPPUNIT_ASSERT(p.updateHash