2010-06-23 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Request ut_metadata in end-game mode(in other words, more
	aggresively)
	* src/HandshakeExtensionMessage.cc
	* src/Peer.cc
	* src/Peer.h
	* src/PeerSessionResource.cc
	* src/PeerSessionResource.h
	* src/UTMetadataRequestFactory.cc
	* test/UTMetadataRequestFactoryTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-06-23 11:55:23 +00:00
parent 3e98f05533
commit 4736e77acf
8 changed files with 58 additions and 22 deletions

View File

@ -1,3 +1,15 @@
2010-06-23 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Request ut_metadata in end-game mode(in other words, more
aggresively)
* src/HandshakeExtensionMessage.cc
* src/Peer.cc
* src/Peer.h
* src/PeerSessionResource.cc
* src/PeerSessionResource.h
* src/UTMetadataRequestFactory.cc
* test/UTMetadataRequestFactoryTest.cc
2010-06-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added missing parameter to log message.

View File

@ -123,6 +123,11 @@ void HandshakeExtensionMessage::doReceivedAction()
if(metadataSize_ != attrs->metadataSize) {
throw DL_ABORT_EX("Wrong metadata_size. Which one is correct!?");
}
if(!peer_->isSeeder()) {
peer_->reconfigureSessionResource(dctx_->getPieceLength(),
dctx_->getTotalLength());
peer_->setAllBitfield();
}
} else {
attrs->metadataSize = metadataSize_;
dctx_->getFirstFileEntry()->setLength(metadataSize_);
@ -131,7 +136,9 @@ void HandshakeExtensionMessage::doReceivedAction()
SharedHandle<PieceStorage> pieceStorage =
dctx_->getOwnerRequestGroup()->getPieceStorage();
pieceStorage->setEndGamePieceNum(0);
peer_->reconfigureSessionResource(dctx_->getPieceLength(),
dctx_->getTotalLength());
peer_->setAllBitfield();
}
} else if(attrs->metadata.empty()) {
throw DL_ABORT_EX("Peer didn't provide metadata_size."

View File

@ -80,6 +80,12 @@ void Peer::allocateSessionResource(size_t pieceLength, uint64_t totalLength)
res_->getPeerStat().downloadStart();
}
void Peer::reconfigureSessionResource(size_t pieceLength, uint64_t totalLength)
{
assert(res_);
res_->reconfigure(pieceLength, totalLength);
}
void Peer::releaseSessionResource()
{
delete res_;

View File

@ -159,6 +159,8 @@ public:
void allocateSessionResource(size_t pieceLength, uint64_t totalLength);
void reconfigureSessionResource(size_t pieceLength, uint64_t totalLength);
void releaseSessionResource();
const Timer& getFirstContactTime() const

View File

@ -273,4 +273,10 @@ size_t PeerSessionResource::countOutstandingUpload() const
return dispatcher_->countOutstandingUpload();
}
void PeerSessionResource::reconfigure(size_t pieceLength, uint64_t totalLenth)
{
delete bitfieldMan_;
bitfieldMan_ = new BitfieldMan(pieceLength, totalLenth);
}
} // namespace aria2

View File

@ -155,6 +155,8 @@ public:
size_t getBitfieldLength() const;
void reconfigure(size_t index, uint64_t totalLength);
bool hasPiece(size_t index) const;
void markSeeder();

View File

@ -52,26 +52,23 @@ void UTMetadataRequestFactory::create
(std::vector<SharedHandle<BtMessage> >& msgs, size_t num,
const SharedHandle<PieceStorage>& pieceStorage)
{
for(size_t index = 0, numPieces = dctx_->getNumPieces();
index < numPieces && num; ++index) {
SharedHandle<Piece> p = pieceStorage->getMissingPiece(index);
while(num) {
SharedHandle<Piece> p = pieceStorage->getMissingPiece(peer_);
if(p.isNull()) {
if(logger_->debug()) {
logger_->debug
("ut_metadata piece %lu is used or already acquired.",
static_cast<unsigned long>(index));
logger_->debug("No ut_metadata piece is available to download.");
}
continue;
break;
}
--num;
if(logger_->debug()) {
logger_->debug("Creating ut_metadata request index=%lu",
static_cast<unsigned long>(index));
static_cast<unsigned long>(p->getIndex()));
}
SharedHandle<UTMetadataRequestExtensionMessage> m
(new UTMetadataRequestExtensionMessage
(peer_->getExtensionMessageID("ut_metadata")));
m->setIndex(index);
m->setIndex(p->getIndex());
m->setDownloadContext(dctx_);
m->setBtMessageDispatcher(dispatcher_);
m->setBtMessageFactory(messageFactory_);
@ -79,7 +76,7 @@ void UTMetadataRequestFactory::create
SharedHandle<BtMessage> msg = messageFactory_->createBtExtendedMessage(m);
msgs.push_back(msg);
tracker_->add(index);
tracker_->add(p->getIndex());
}
}

View File

@ -1,6 +1,7 @@
#include "UTMetadataRequestFactory.h"
#include <vector>
#include <deque>
#include <cppunit/extensions/HelperMacros.h>
@ -25,14 +26,17 @@ public:
class MockPieceStorage2:public MockPieceStorage {
public:
std::set<size_t> missingIndexes;
std::deque<size_t> missingIndexes;
virtual SharedHandle<Piece> getMissingPiece(size_t index)
virtual SharedHandle<Piece> getMissingPiece
(const SharedHandle<Peer>& peer)
{
if(missingIndexes.find(index) != missingIndexes.end()) {
return SharedHandle<Piece>(new Piece(index, 0));
} else {
if(missingIndexes.empty()) {
return SharedHandle<Piece>();
} else {
size_t index = missingIndexes.front();
missingIndexes.pop_front();
return SharedHandle<Piece>(new Piece(index, 0));
}
}
};
@ -48,8 +52,8 @@ void UTMetadataRequestFactoryTest::testCreate()
(new DownloadContext(METADATA_PIECE_SIZE, METADATA_PIECE_SIZE*2));
factory.setDownloadContext(dctx);
SharedHandle<MockPieceStorage2> ps(new MockPieceStorage2());
ps->missingIndexes.insert(0);
ps->missingIndexes.insert(1);
ps->missingIndexes.push_back(0);
ps->missingIndexes.push_back(1);
SharedHandle<WrapExtBtMessageFactory> messageFactory
(new WrapExtBtMessageFactory());
factory.setBtMessageFactory(messageFactory);
@ -65,11 +69,11 @@ void UTMetadataRequestFactoryTest::testCreate()
factory.create(msgs, 1, ps);
CPPUNIT_ASSERT_EQUAL((size_t)1, msgs.size());
msgs.clear();
ps->missingIndexes.clear();
factory.create(msgs, 1, ps);
CPPUNIT_ASSERT_EQUAL((size_t)0, msgs.size());
CPPUNIT_ASSERT_EQUAL((size_t)2, msgs.size());
factory.create(msgs, 1, ps);
CPPUNIT_ASSERT_EQUAL((size_t)2, msgs.size());
}
} // namespace aria2