mirror of https://github.com/aria2/aria2
2008-06-17 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Filled up pieces based on the number of missing blocks, rather than simplay the number of piece * block length. * src/BtRequestFactory.h * src/DefaultBtInteractive.cc * src/DefaultBtInteractive.h * src/DefaultBtRequestFactory.cc * src/DefaultBtRequestFactory.h * src/Piece.cc * src/Piece.h * test/BitfieldManTest.cc * test/DefaultBtRequestFactoryTest.cc * test/MockBtRequestFactory.hpull/1/head
parent
09502fc3db
commit
dfe2f99345
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
||||||
|
2008-06-17 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
Filled up pieces based on the number of missing blocks, rather than
|
||||||
|
simplay the number of piece * block length.
|
||||||
|
* src/BtRequestFactory.h
|
||||||
|
* src/DefaultBtInteractive.cc
|
||||||
|
* src/DefaultBtInteractive.h
|
||||||
|
* src/DefaultBtRequestFactory.cc
|
||||||
|
* src/DefaultBtRequestFactory.h
|
||||||
|
* src/Piece.cc
|
||||||
|
* src/Piece.h
|
||||||
|
* test/BitfieldManTest.cc
|
||||||
|
* test/DefaultBtRequestFactoryTest.cc
|
||||||
|
* test/MockBtRequestFactory.h
|
||||||
|
|
||||||
2008-06-17 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2008-06-17 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Made _epEvents a member variable.
|
Made _epEvents a member variable.
|
||||||
|
|
|
@ -56,6 +56,8 @@ public:
|
||||||
|
|
||||||
virtual size_t countTargetPiece() = 0;
|
virtual size_t countTargetPiece() = 0;
|
||||||
|
|
||||||
|
virtual size_t countMissingBlock() = 0;
|
||||||
|
|
||||||
virtual void removeCompletedPiece() = 0;
|
virtual void removeCompletedPiece() = 0;
|
||||||
|
|
||||||
virtual void doChokedAction() = 0;
|
virtual void doChokedAction() = 0;
|
||||||
|
|
|
@ -288,26 +288,32 @@ void DefaultBtInteractive::decideInterest() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtInteractive::fillPiece(size_t maxPieceNum) {
|
void DefaultBtInteractive::fillPiece(size_t maxMissingBlock) {
|
||||||
if(pieceStorage->hasMissingPiece(peer)) {
|
if(pieceStorage->hasMissingPiece(peer)) {
|
||||||
|
|
||||||
|
size_t numMissingBlock = btRequestFactory->countMissingBlock();
|
||||||
|
|
||||||
if(peer->peerChoking()) {
|
if(peer->peerChoking()) {
|
||||||
if(peer->isFastExtensionEnabled()) {
|
if(peer->isFastExtensionEnabled()) {
|
||||||
while(btRequestFactory->countTargetPiece() < maxPieceNum) {
|
|
||||||
|
while(numMissingBlock < maxMissingBlock) {
|
||||||
PieceHandle piece = pieceStorage->getMissingFastPiece(peer);
|
PieceHandle piece = pieceStorage->getMissingFastPiece(peer);
|
||||||
if(piece.isNull()) {
|
if(piece.isNull()) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
btRequestFactory->addTargetPiece(piece);
|
btRequestFactory->addTargetPiece(piece);
|
||||||
|
numMissingBlock += piece->countMissingBlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while(btRequestFactory->countTargetPiece() < maxPieceNum) {
|
while(numMissingBlock < maxMissingBlock) {
|
||||||
PieceHandle piece = pieceStorage->getMissingPiece(peer);
|
PieceHandle piece = pieceStorage->getMissingPiece(peer);
|
||||||
if(piece.isNull()) {
|
if(piece.isNull()) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
btRequestFactory->addTargetPiece(piece);
|
btRequestFactory->addTargetPiece(piece);
|
||||||
|
numMissingBlock += piece->countMissingBlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,14 +329,7 @@ void DefaultBtInteractive::addRequests() {
|
||||||
} else {
|
} else {
|
||||||
MAX_PENDING_REQUEST = 6;
|
MAX_PENDING_REQUEST = 6;
|
||||||
}
|
}
|
||||||
size_t pieceNum;
|
fillPiece(MAX_PENDING_REQUEST);
|
||||||
if(pieceStorage->isEndGame()) {
|
|
||||||
pieceNum = 1;
|
|
||||||
} else {
|
|
||||||
size_t blocks = DIV_FLOOR(btContext->getPieceLength(), Piece::BLOCK_LENGTH);
|
|
||||||
pieceNum = DIV_FLOOR(MAX_PENDING_REQUEST, blocks);
|
|
||||||
}
|
|
||||||
fillPiece(pieceNum);
|
|
||||||
|
|
||||||
size_t reqNumToCreate =
|
size_t reqNumToCreate =
|
||||||
MAX_PENDING_REQUEST <= dispatcher->countOutstandingRequest() ?
|
MAX_PENDING_REQUEST <= dispatcher->countOutstandingRequest() ?
|
||||||
|
|
|
@ -122,7 +122,7 @@ private:
|
||||||
void checkHave();
|
void checkHave();
|
||||||
void sendKeepAlive();
|
void sendKeepAlive();
|
||||||
void decideInterest();
|
void decideInterest();
|
||||||
void fillPiece(size_t maxPieceNum);
|
void fillPiece(size_t maxMissingBlock);
|
||||||
void addRequests();
|
void addRequests();
|
||||||
void detectMessageFlooding();
|
void detectMessageFlooding();
|
||||||
void checkActiveInteraction();
|
void checkActiveInteraction();
|
||||||
|
|
|
@ -186,6 +186,30 @@ void DefaultBtRequestFactory::createRequestMessagesOnEndGame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CountMissingBlock
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
size_t _numMissingBlock;
|
||||||
|
public:
|
||||||
|
CountMissingBlock():_numMissingBlock(0) {}
|
||||||
|
|
||||||
|
size_t getNumMissingBlock()
|
||||||
|
{
|
||||||
|
return _numMissingBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator()(const SharedHandle<Piece>& piece)
|
||||||
|
{
|
||||||
|
_numMissingBlock += piece->countMissingBlock();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
size_t DefaultBtRequestFactory::countMissingBlock()
|
||||||
|
{
|
||||||
|
return std::for_each(pieces.begin(), pieces.end(),
|
||||||
|
CountMissingBlock()).getNumMissingBlock();
|
||||||
|
}
|
||||||
|
|
||||||
std::deque<SharedHandle<Piece> >& DefaultBtRequestFactory::getTargetPieces()
|
std::deque<SharedHandle<Piece> >& DefaultBtRequestFactory::getTargetPieces()
|
||||||
{
|
{
|
||||||
return pieces;
|
return pieces;
|
||||||
|
|
|
@ -72,6 +72,8 @@ public:
|
||||||
return pieces.size();
|
return pieces.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual size_t countMissingBlock();
|
||||||
|
|
||||||
virtual void removeCompletedPiece();
|
virtual void removeCompletedPiece();
|
||||||
|
|
||||||
virtual void doChokedAction();
|
virtual void doChokedAction();
|
||||||
|
|
|
@ -162,6 +162,11 @@ size_t Piece::countCompleteBlock() const
|
||||||
return bitfield->countBlock()-bitfield->countMissingBlock();
|
return bitfield->countBlock()-bitfield->countMissingBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t Piece::countMissingBlock() const
|
||||||
|
{
|
||||||
|
return bitfield->countMissingBlock();
|
||||||
|
}
|
||||||
|
|
||||||
bool Piece::hasBlock(size_t blockIndex) const
|
bool Piece::hasBlock(size_t blockIndex) const
|
||||||
{
|
{
|
||||||
return bitfield->isBitSet(blockIndex);
|
return bitfield->isBitSet(blockIndex);
|
||||||
|
|
|
@ -95,6 +95,8 @@ public:
|
||||||
|
|
||||||
size_t countCompleteBlock() const;
|
size_t countCompleteBlock() const;
|
||||||
|
|
||||||
|
size_t countMissingBlock() const;
|
||||||
|
|
||||||
bool hasBlock(size_t blockIndex) const;
|
bool hasBlock(size_t blockIndex) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,6 +26,7 @@ class BitfieldManTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testGetMissingIndex_noarg);
|
CPPUNIT_TEST(testGetMissingIndex_noarg);
|
||||||
CPPUNIT_TEST(testGetMissingUnusedIndex_noarg);
|
CPPUNIT_TEST(testGetMissingUnusedIndex_noarg);
|
||||||
CPPUNIT_TEST(testCountFilteredBlock);
|
CPPUNIT_TEST(testCountFilteredBlock);
|
||||||
|
CPPUNIT_TEST(testCountMissingBlock);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
private:
|
||||||
SharedHandle<Randomizer> fixedNumberRandomizer;
|
SharedHandle<Randomizer> fixedNumberRandomizer;
|
||||||
|
@ -59,6 +60,7 @@ public:
|
||||||
void testGetMissingUnusedLength();
|
void testGetMissingUnusedLength();
|
||||||
void testSetBitRange();
|
void testSetBitRange();
|
||||||
void testCountFilteredBlock();
|
void testCountFilteredBlock();
|
||||||
|
void testCountMissingBlock();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -741,4 +743,14 @@ void BitfieldManTest::testCountFilteredBlock()
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)0, bt.countFilteredBlock());
|
CPPUNIT_ASSERT_EQUAL((size_t)0, bt.countFilteredBlock());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BitfieldManTest::testCountMissingBlock()
|
||||||
|
{
|
||||||
|
BitfieldMan bt(1024, 1024*10);
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)10, bt.countMissingBlock());
|
||||||
|
bt.setBit(1);
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)9, bt.countMissingBlock());
|
||||||
|
bt.setAllBit();
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)0, bt.countMissingBlock());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -123,9 +123,18 @@ public:
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtRequestFactoryTest);
|
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtRequestFactoryTest);
|
||||||
|
|
||||||
void DefaultBtRequestFactoryTest::testAddTargetPiece() {
|
void DefaultBtRequestFactoryTest::testAddTargetPiece() {
|
||||||
SharedHandle<Piece> piece(new Piece(0, 16*1024));
|
{
|
||||||
btRequestFactory->addTargetPiece(piece);
|
SharedHandle<Piece> piece(new Piece(0, 16*1024*10));
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)1, btRequestFactory->countTargetPiece());
|
btRequestFactory->addTargetPiece(piece);
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)1, btRequestFactory->countTargetPiece());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SharedHandle<Piece> piece(new Piece(1, 16*1024*9));
|
||||||
|
piece->completeBlock(0);
|
||||||
|
btRequestFactory->addTargetPiece(piece);
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)2, btRequestFactory->countTargetPiece());
|
||||||
|
}
|
||||||
|
CPPUNIT_ASSERT_EQUAL((size_t)18, btRequestFactory->countMissingBlock());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DefaultBtRequestFactoryTest::testRemoveCompletedPiece() {
|
void DefaultBtRequestFactoryTest::testRemoveCompletedPiece() {
|
||||||
|
|
|
@ -17,6 +17,8 @@ public:
|
||||||
|
|
||||||
virtual size_t countTargetPiece() { return 0; }
|
virtual size_t countTargetPiece() { return 0; }
|
||||||
|
|
||||||
|
virtual size_t countMissingBlock() { return 0; }
|
||||||
|
|
||||||
virtual void removeCompletedPiece() {}
|
virtual void removeCompletedPiece() {}
|
||||||
|
|
||||||
virtual void doChokedAction() {}
|
virtual void doChokedAction() {}
|
||||||
|
|
Loading…
Reference in New Issue