2009-11-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

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
pull/1/head
Tatsuhiro Tsujikawa 2009-11-22 14:52:17 +00:00
parent 03b281f604
commit c1f9032441
3 changed files with 76 additions and 41 deletions

View File

@ -1,3 +1,11 @@
2009-11-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
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 <t-tujikawa@users.sourceforge.net> 2009-11-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added setEndGamePieceNum() pure virtual function to PieceStorage. Added setEndGamePieceNum() pure virtual function to PieceStorage.

View File

@ -71,7 +71,8 @@
namespace aria2 { namespace aria2 {
DefaultBtMessageFactory::DefaultBtMessageFactory():cuid(0), DefaultBtMessageFactory::DefaultBtMessageFactory():cuid(0),
_dhtEnabled(false) _dhtEnabled(false),
_metadataGetMode(false)
{} {}
DefaultBtMessageFactory::~DefaultBtMessageFactory() {} DefaultBtMessageFactory::~DefaultBtMessageFactory() {}
@ -111,51 +112,61 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL
case BtHaveMessage::ID: case BtHaveMessage::ID:
msg = BtHaveMessage::create(data, dataLength); msg = BtHaveMessage::create(data, dataLength);
{ {
SharedHandle<BtMessageValidator> v if(!_metadataGetMode) {
(new IndexBtMessageValidator(static_cast<BtHaveMessage*>(msg.get()), SharedHandle<BtMessageValidator> v
_downloadContext->getNumPieces())); (new IndexBtMessageValidator(static_cast<BtHaveMessage*>(msg.get()),
msg->setBtMessageValidator(v); _downloadContext->getNumPieces()));
msg->setBtMessageValidator(v);
}
} }
break; break;
case BtBitfieldMessage::ID: case BtBitfieldMessage::ID:
msg = BtBitfieldMessage::create(data, dataLength); msg = BtBitfieldMessage::create(data, dataLength);
{ {
SharedHandle<BtMessageValidator> v if(!_metadataGetMode) {
(new BtBitfieldMessageValidator SharedHandle<BtMessageValidator> v
(static_cast<BtBitfieldMessage*>(msg.get()), (new BtBitfieldMessageValidator
_downloadContext->getNumPieces())); (static_cast<BtBitfieldMessage*>(msg.get()),
msg->setBtMessageValidator(v); _downloadContext->getNumPieces()));
msg->setBtMessageValidator(v);
}
} }
break; break;
case BtRequestMessage::ID: { case BtRequestMessage::ID: {
BtRequestMessageHandle temp = BtRequestMessage::create(data, dataLength); BtRequestMessageHandle temp = BtRequestMessage::create(data, dataLength);
SharedHandle<BtMessageValidator> validator if(!_metadataGetMode) {
(new RangeBtMessageValidator SharedHandle<BtMessageValidator> validator
(temp.get(), (new RangeBtMessageValidator
_downloadContext->getNumPieces(), (temp.get(),
_pieceStorage->getPieceLength(temp->getIndex()))); _downloadContext->getNumPieces(),
temp->setBtMessageValidator(validator); _pieceStorage->getPieceLength(temp->getIndex())));
temp->setBtMessageValidator(validator);
}
msg = temp; msg = temp;
break; break;
} }
case BtCancelMessage::ID: { case BtCancelMessage::ID: {
BtCancelMessageHandle temp = BtCancelMessage::create(data, dataLength); BtCancelMessageHandle temp = BtCancelMessage::create(data, dataLength);
SharedHandle<BtMessageValidator> validator if(!_metadataGetMode) {
(new RangeBtMessageValidator SharedHandle<BtMessageValidator> validator
(temp.get(), (new RangeBtMessageValidator
_downloadContext->getNumPieces(), (temp.get(),
_pieceStorage->getPieceLength(temp->getIndex()))); _downloadContext->getNumPieces(),
temp->setBtMessageValidator(validator); _pieceStorage->getPieceLength(temp->getIndex())));
temp->setBtMessageValidator(validator);
}
msg = temp; msg = temp;
break; break;
} }
case BtPieceMessage::ID: { case BtPieceMessage::ID: {
BtPieceMessageHandle temp = BtPieceMessage::create(data, dataLength); BtPieceMessageHandle temp = BtPieceMessage::create(data, dataLength);
BtMessageValidatorHandle validator if(!_metadataGetMode) {
(new BtPieceMessageValidator(temp.get(), BtMessageValidatorHandle validator
_downloadContext->getNumPieces(), (new BtPieceMessageValidator(temp.get(),
_pieceStorage->getPieceLength(temp->getIndex()))); _downloadContext->getNumPieces(),
temp->setBtMessageValidator(validator); _pieceStorage->getPieceLength(temp->getIndex())));
temp->setBtMessageValidator(validator);
}
temp->setDownloadContext(_downloadContext); temp->setDownloadContext(_downloadContext);
msg = temp; msg = temp;
break; break;
@ -168,30 +179,36 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL
break; break;
case BtRejectMessage::ID: { case BtRejectMessage::ID: {
BtRejectMessageHandle temp = BtRejectMessage::create(data, dataLength); BtRejectMessageHandle temp = BtRejectMessage::create(data, dataLength);
SharedHandle<BtMessageValidator> validator if(!_metadataGetMode) {
(new RangeBtMessageValidator SharedHandle<BtMessageValidator> validator
(temp.get(), (new RangeBtMessageValidator
_downloadContext->getNumPieces(), (temp.get(),
_pieceStorage->getPieceLength(temp->getIndex()))); _downloadContext->getNumPieces(),
temp->setBtMessageValidator(validator); _pieceStorage->getPieceLength(temp->getIndex())));
temp->setBtMessageValidator(validator);
}
msg = temp; msg = temp;
break; break;
} }
case BtSuggestPieceMessage::ID: { case BtSuggestPieceMessage::ID: {
BtSuggestPieceMessageHandle temp = BtSuggestPieceMessage::create(data, dataLength); BtSuggestPieceMessageHandle temp = BtSuggestPieceMessage::create(data, dataLength);
SharedHandle<BtMessageValidator> validator if(!_metadataGetMode) {
(new IndexBtMessageValidator(temp.get(), SharedHandle<BtMessageValidator> validator
_downloadContext->getNumPieces())); (new IndexBtMessageValidator(temp.get(),
temp->setBtMessageValidator(validator); _downloadContext->getNumPieces()));
temp->setBtMessageValidator(validator);
}
msg = temp; msg = temp;
break; break;
} }
case BtAllowedFastMessage::ID: { case BtAllowedFastMessage::ID: {
BtAllowedFastMessageHandle temp = BtAllowedFastMessage::create(data, dataLength); BtAllowedFastMessageHandle temp = BtAllowedFastMessage::create(data, dataLength);
SharedHandle<BtMessageValidator> validator if(!_metadataGetMode) {
(new IndexBtMessageValidator(temp.get(), SharedHandle<BtMessageValidator> validator
_downloadContext->getNumPieces())); (new IndexBtMessageValidator(temp.get(),
temp->setBtMessageValidator(validator); _downloadContext->getNumPieces()));
temp->setBtMessageValidator(validator);
}
msg = temp; msg = temp;
break; break;
} }
@ -229,6 +246,9 @@ void DefaultBtMessageFactory::setCommonProperty(const AbstractBtMessageHandle& m
msg->setBtRequestFactory(requestFactory); msg->setBtRequestFactory(requestFactory);
msg->setBtMessageFactory(WeakHandle<BtMessageFactory>(this)); msg->setBtMessageFactory(WeakHandle<BtMessageFactory>(this));
msg->setPeerConnection(peerConnection); msg->setPeerConnection(peerConnection);
if(_metadataGetMode) {
msg->enableMetadataGetMode();
}
} }
SharedHandle<BtHandshakeMessage> SharedHandle<BtHandshakeMessage>

View File

@ -79,6 +79,8 @@ private:
WeakHandle<DHTTaskFactory> _taskFactory; WeakHandle<DHTTaskFactory> _taskFactory;
bool _metadataGetMode;
void setCommonProperty(const SharedHandle<AbstractBtMessage>& msg); void setCommonProperty(const SharedHandle<AbstractBtMessage>& msg);
public: public:
DefaultBtMessageFactory(); DefaultBtMessageFactory();
@ -164,6 +166,11 @@ public:
void setTaskQueue(const WeakHandle<DHTTaskQueue>& taskQueue); void setTaskQueue(const WeakHandle<DHTTaskQueue>& taskQueue);
void setTaskFactory(const WeakHandle<DHTTaskFactory>& taskFactory); void setTaskFactory(const WeakHandle<DHTTaskFactory>& taskFactory);
void enableMetadataGetMode()
{
_metadataGetMode = true;
}
}; };
typedef SharedHandle<DefaultBtMessageFactory> DefaultBtMessageFactoryHandle; typedef SharedHandle<DefaultBtMessageFactory> DefaultBtMessageFactoryHandle;