diff --git a/ChangeLog b/ChangeLog index e3c89cf4..e15ce2bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-11-22 Tatsuhiro Tsujikawa + + Don't inject validator into BtMessage in metadataGetMode because + most of the checks depends on the total length of download but it + is unknown. Delegate metadataGetMode to BtMessage. + * src/DefaultBtMessageFactory.cc + * src/DefaultBtMessageFactory.h + 2009-11-22 Tatsuhiro Tsujikawa Added setEndGamePieceNum() pure virtual function to PieceStorage. diff --git a/src/DefaultBtMessageFactory.cc b/src/DefaultBtMessageFactory.cc index 4d0e6bbf..51be6c1f 100644 --- a/src/DefaultBtMessageFactory.cc +++ b/src/DefaultBtMessageFactory.cc @@ -71,7 +71,8 @@ namespace aria2 { DefaultBtMessageFactory::DefaultBtMessageFactory():cuid(0), - _dhtEnabled(false) + _dhtEnabled(false), + _metadataGetMode(false) {} DefaultBtMessageFactory::~DefaultBtMessageFactory() {} @@ -111,51 +112,61 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL case BtHaveMessage::ID: msg = BtHaveMessage::create(data, dataLength); { - SharedHandle v - (new IndexBtMessageValidator(static_cast(msg.get()), - _downloadContext->getNumPieces())); - msg->setBtMessageValidator(v); + if(!_metadataGetMode) { + SharedHandle v + (new IndexBtMessageValidator(static_cast(msg.get()), + _downloadContext->getNumPieces())); + msg->setBtMessageValidator(v); + } } break; case BtBitfieldMessage::ID: msg = BtBitfieldMessage::create(data, dataLength); { - SharedHandle v - (new BtBitfieldMessageValidator - (static_cast(msg.get()), - _downloadContext->getNumPieces())); - msg->setBtMessageValidator(v); + if(!_metadataGetMode) { + SharedHandle v + (new BtBitfieldMessageValidator + (static_cast(msg.get()), + _downloadContext->getNumPieces())); + msg->setBtMessageValidator(v); + } } break; case BtRequestMessage::ID: { BtRequestMessageHandle temp = BtRequestMessage::create(data, dataLength); - SharedHandle validator - (new RangeBtMessageValidator - (temp.get(), - _downloadContext->getNumPieces(), - _pieceStorage->getPieceLength(temp->getIndex()))); - temp->setBtMessageValidator(validator); + if(!_metadataGetMode) { + SharedHandle validator + (new RangeBtMessageValidator + (temp.get(), + _downloadContext->getNumPieces(), + _pieceStorage->getPieceLength(temp->getIndex()))); + temp->setBtMessageValidator(validator); + } msg = temp; break; } case BtCancelMessage::ID: { BtCancelMessageHandle temp = BtCancelMessage::create(data, dataLength); - SharedHandle validator - (new RangeBtMessageValidator - (temp.get(), - _downloadContext->getNumPieces(), - _pieceStorage->getPieceLength(temp->getIndex()))); - temp->setBtMessageValidator(validator); + if(!_metadataGetMode) { + SharedHandle validator + (new RangeBtMessageValidator + (temp.get(), + _downloadContext->getNumPieces(), + _pieceStorage->getPieceLength(temp->getIndex()))); + temp->setBtMessageValidator(validator); + } msg = temp; break; } case BtPieceMessage::ID: { BtPieceMessageHandle temp = BtPieceMessage::create(data, dataLength); - BtMessageValidatorHandle validator - (new BtPieceMessageValidator(temp.get(), - _downloadContext->getNumPieces(), - _pieceStorage->getPieceLength(temp->getIndex()))); - temp->setBtMessageValidator(validator); + if(!_metadataGetMode) { + BtMessageValidatorHandle validator + (new BtPieceMessageValidator(temp.get(), + _downloadContext->getNumPieces(), + _pieceStorage->getPieceLength(temp->getIndex()))); + temp->setBtMessageValidator(validator); + } temp->setDownloadContext(_downloadContext); msg = temp; break; @@ -168,30 +179,36 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL break; case BtRejectMessage::ID: { BtRejectMessageHandle temp = BtRejectMessage::create(data, dataLength); - SharedHandle validator - (new RangeBtMessageValidator - (temp.get(), - _downloadContext->getNumPieces(), - _pieceStorage->getPieceLength(temp->getIndex()))); - temp->setBtMessageValidator(validator); + if(!_metadataGetMode) { + SharedHandle validator + (new RangeBtMessageValidator + (temp.get(), + _downloadContext->getNumPieces(), + _pieceStorage->getPieceLength(temp->getIndex()))); + temp->setBtMessageValidator(validator); + } msg = temp; break; } case BtSuggestPieceMessage::ID: { BtSuggestPieceMessageHandle temp = BtSuggestPieceMessage::create(data, dataLength); - SharedHandle validator - (new IndexBtMessageValidator(temp.get(), - _downloadContext->getNumPieces())); - temp->setBtMessageValidator(validator); + if(!_metadataGetMode) { + SharedHandle validator + (new IndexBtMessageValidator(temp.get(), + _downloadContext->getNumPieces())); + temp->setBtMessageValidator(validator); + } msg = temp; break; } case BtAllowedFastMessage::ID: { BtAllowedFastMessageHandle temp = BtAllowedFastMessage::create(data, dataLength); - SharedHandle validator - (new IndexBtMessageValidator(temp.get(), - _downloadContext->getNumPieces())); - temp->setBtMessageValidator(validator); + if(!_metadataGetMode) { + SharedHandle validator + (new IndexBtMessageValidator(temp.get(), + _downloadContext->getNumPieces())); + temp->setBtMessageValidator(validator); + } msg = temp; break; } @@ -229,6 +246,9 @@ void DefaultBtMessageFactory::setCommonProperty(const AbstractBtMessageHandle& m msg->setBtRequestFactory(requestFactory); msg->setBtMessageFactory(WeakHandle(this)); msg->setPeerConnection(peerConnection); + if(_metadataGetMode) { + msg->enableMetadataGetMode(); + } } SharedHandle diff --git a/src/DefaultBtMessageFactory.h b/src/DefaultBtMessageFactory.h index 7b289946..411767af 100644 --- a/src/DefaultBtMessageFactory.h +++ b/src/DefaultBtMessageFactory.h @@ -79,6 +79,8 @@ private: WeakHandle _taskFactory; + bool _metadataGetMode; + void setCommonProperty(const SharedHandle& msg); public: DefaultBtMessageFactory(); @@ -164,6 +166,11 @@ public: void setTaskQueue(const WeakHandle& taskQueue); void setTaskFactory(const WeakHandle& taskFactory); + + void enableMetadataGetMode() + { + _metadataGetMode = true; + } }; typedef SharedHandle DefaultBtMessageFactoryHandle;