/* */ #ifndef _D_CHUNK_CHECKSUM_VALIDATOR_H_ #define _D_CHUNK_CHECKSUM_VALIDATOR_H_ #include "common.h" #include "DiskWriter.h" #include "BitfieldMan.h" #ifdef ENABLE_MESSAGE_DIGEST #include "messageDigest.h" #endif // ENABLE_MESSAGE_DIGEST #include "LogFactory.h" #include "FileAllocationMonitor.h" #include "NullFileAllocationMonitor.h" class ChunkChecksumValidator { #ifdef ENABLE_MESSAGE_DIGEST private: DiskWriterHandle diskWriter; MessageDigestContext::DigestAlgo algo; FileAllocationMonitorHandle fileAllocationMonitor; const Logger* logger; void validateSameLengthChecksum(BitfieldMan* bitfieldMan, int32_t index, const string& expectedChecksum, int32_t thisLength, int32_t checksumLength); void validateDifferentLengthChecksum(BitfieldMan* bitfieldMan, int32_t index, const string& expectedChecksum, int32_t thisLength, int32_t checksumLength); public: ChunkChecksumValidator(): diskWriter(0), algo(DIGEST_ALGO_SHA1), fileAllocationMonitor(new NullFileAllocationMonitor()), logger(LogFactory::getInstance()) {} ~ChunkChecksumValidator() {} void validate(BitfieldMan* bitfieldMan, const Strings& checksums, int32_t checksumLength); void setDiskWriter(const DiskWriterHandle& diskWriter) { this->diskWriter = diskWriter; } void setDigestAlgo(const MessageDigestContext::DigestAlgo& algo) { this->algo = algo; } void setFileAllocationMonitor(const FileAllocationMonitorHandle& monitor) { this->fileAllocationMonitor = monitor; } #endif // ENABLE_MESSAGE_DIGEST }; #endif // _D_CHUNK_CHECKSUM_VALIDATOR_H_