/* */ #include "ChecksumCommand.h" #include "DlAbortEx.h" #include "message.h" void ChecksumCommand::initValidator() { _validator = new IteratableChecksumValidator(); _validator->setChecksum(_requestGroup->getChecksum()); _validator->setDiskWriter(_requestGroup->getSegmentMan()->diskWriter); _validator->setBitfield(_requestGroup->getSegmentMan()->getBitfield()); if(!_validator->canValidate()) { // insufficient checksums. throw new DlAbortEx("Insufficient checksums."); } _validator->init(); } bool ChecksumCommand::executeInternal() { _validator->validateChunk(); if(_validator->finished()) { if(_requestGroup->downloadFinished()) { logger->notice(MSG_GOOD_CHECKSUM, cuid, _requestGroup->getFilePath().c_str()); return true; } else { logger->error(MSG_BAD_CHECKSUM, cuid, _requestGroup->getFilePath().c_str()); return true; } } else { _e->commands.push_back(this); return false; } } bool ChecksumCommand::handleException(Exception* e) { logger->error("CUID#%d - Exception caught while validating file integrity.", e, cuid); delete e; logger->error(MSG_DOWNLOAD_NOT_COMPLETE, cuid, _requestGroup->getFilePath().c_str()); // TODO We need to set bitfield back to the state when validation begun. // The one of the solution is having a copy of bitfield before settting its // all bit to 1. If exception is thrown, then assign the copy to the bitfield. return true; }