2010-08-04 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Don't use pre-calculate hash value when end-game mode.  Throw
	exception if bad piece is received.
	* src/BtPieceMessage.cc
	* src/DownloadCommand.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-08-04 14:15:29 +00:00
parent 2176b68116
commit dfdf2d8e56
3 changed files with 18 additions and 2 deletions

View File

@ -1,3 +1,10 @@
2010-08-04 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Don't use pre-calculate hash value when end-game mode. Throw
exception if bad piece is received.
* src/BtPieceMessage.cc
* src/DownloadCommand.cc
2010-08-04 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten ut_pex peer selection.

View File

@ -128,6 +128,7 @@ void BtPieceMessage::doReceivedAction()
onNewPiece(piece);
} else {
onWrongPiece(piece);
throw DL_ABORT_EX("Bad piece hash.");
}
}
} else {
@ -221,7 +222,7 @@ std::string BtPieceMessage::toString() const
bool BtPieceMessage::checkPieceHash(const SharedHandle<Piece>& piece)
{
if(piece->isHashCalculated()) {
if(!getPieceStorage()->isEndGame() && piece->isHashCalculated()) {
if(getLogger()->debug()) {
getLogger()->debug("Hash is available!! index=%lu",
static_cast<unsigned long>(piece->getIndex()));

View File

@ -64,6 +64,9 @@
#ifdef ENABLE_MESSAGE_DIGEST
# include "MessageDigestHelper.h"
#endif // ENABLE_MESSAGE_DIGEST
#ifdef ENABLE_BITTORRENT
# include "bittorrent_helper.h"
#endif // ENABLE_BITTORRENT
namespace aria2 {
@ -241,7 +244,12 @@ bool DownloadCommand::executeInternal() {
const std::string& expectedPieceHash =
getDownloadContext()->getPieceHash(segment->getIndex());
if(pieceHashValidationEnabled_ && !expectedPieceHash.empty()) {
if(segment->isHashCalculated()) {
if(
#ifdef ENABLE_BITTORRENT
(!getPieceStorage()->isEndGame() ||
!getDownloadContext()->hasAttribute(bittorrent::BITTORRENT)) &&
#endif // ENABLE_BITTORRENT
segment->isHashCalculated()) {
if(getLogger()->debug()) {
getLogger()->debug
("Hash is available! index=%lu",