mirror of https://github.com/aria2/aria2
2007-12-06 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed the bug: aria2 doesn't utilize fast set index offered by peer. * src/Peer.{h, cc} * src/DefaultPieceStorage.cc * test/DefaultPieceStorageTest.ccpull/1/head
parent
2850c16f8a
commit
30739b0763
|
@ -1,3 +1,10 @@
|
|||
2007-12-06 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Fixed the bug: aria2 doesn't utilize fast set index offered by peer.
|
||||
* src/Peer.{h, cc}
|
||||
* src/DefaultPieceStorage.cc
|
||||
* test/DefaultPieceStorageTest.cc
|
||||
|
||||
2007-12-06 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Rewritten direct I/O support routine
|
||||
|
|
|
@ -166,11 +166,11 @@ PieceHandle DefaultPieceStorage::getMissingPiece(const PeerHandle& peer)
|
|||
int32_t DefaultPieceStorage::getMissingFastPieceIndex(const PeerHandle& peer)
|
||||
{
|
||||
int32_t index = -1;
|
||||
if(peer->isFastExtensionEnabled() && peer->countFastSet() > 0) {
|
||||
if(peer->isFastExtensionEnabled() && peer->countPeerAllowedIndexSet() > 0) {
|
||||
BitfieldMan tempBitfield(bitfieldMan->getBlockLength(),
|
||||
bitfieldMan->getTotalLength());
|
||||
for(Integers::const_iterator itr = peer->getFastSet().begin();
|
||||
itr != peer->getFastSet().end(); itr++) {
|
||||
for(Integers::const_iterator itr = peer->getPeerAllowedIndexSet().begin();
|
||||
itr != peer->getPeerAllowedIndexSet().end(); itr++) {
|
||||
if(!bitfieldMan->isBitSet(index) && peer->hasPiece(*itr)) {
|
||||
tempBitfield.setBit(*itr);
|
||||
}
|
||||
|
|
11
src/Peer.cc
11
src/Peer.cc
|
@ -114,22 +114,11 @@ void Peer::resetStatus() {
|
|||
snubbing = false;
|
||||
fastExtensionEnabled = false;
|
||||
latency = DEFAULT_LATENCY;
|
||||
fastSet.clear();
|
||||
peerAllowedIndexSet.clear();
|
||||
amAllowedIndexSet.clear();
|
||||
peerStat.reset();
|
||||
}
|
||||
|
||||
bool Peer::isInFastSet(int32_t index) const {
|
||||
return find(fastSet.begin(), fastSet.end(), index) != fastSet.end();
|
||||
}
|
||||
|
||||
void Peer::addFastSetIndex(int32_t index) {
|
||||
if(!isInFastSet(index)) {
|
||||
fastSet.push_back(index);
|
||||
}
|
||||
}
|
||||
|
||||
bool Peer::isInPeerAllowedIndexSet(int32_t index) const {
|
||||
return find(peerAllowedIndexSet.begin(), peerAllowedIndexSet.end(),
|
||||
index) != peerAllowedIndexSet.end();
|
||||
|
|
17
src/Peer.h
17
src/Peer.h
|
@ -63,8 +63,6 @@ private:
|
|||
unsigned char peerId[PEER_ID_LENGTH];
|
||||
BitfieldMan* bitfield;
|
||||
bool fastExtensionEnabled;
|
||||
// allowed fast indexes that peer has sent by Allowed Fast message
|
||||
Integers fastSet;
|
||||
// fast index set which a peer has sent to localhost.
|
||||
Integers peerAllowedIndexSet;
|
||||
// fast index set which localhost has sent to a peer.
|
||||
|
@ -179,14 +177,19 @@ public:
|
|||
}
|
||||
bool isFastExtensionEnabled() const { return fastExtensionEnabled; }
|
||||
|
||||
void addFastSetIndex(int32_t index);
|
||||
const Integers& getFastSet() const { return fastSet; }
|
||||
bool isInFastSet(int32_t index) const;
|
||||
int32_t countFastSet() const { return fastSet.size(); }
|
||||
|
||||
void addPeerAllowedIndex(int32_t index);
|
||||
bool isInPeerAllowedIndexSet(int32_t index) const;
|
||||
|
||||
int32_t countPeerAllowedIndexSet() const
|
||||
{
|
||||
return peerAllowedIndexSet.size();
|
||||
}
|
||||
|
||||
const Integers& getPeerAllowedIndexSet() const
|
||||
{
|
||||
return peerAllowedIndexSet;
|
||||
}
|
||||
|
||||
void addAmAllowedIndex(int32_t index);
|
||||
bool isInAmAllowedIndexSet(int32_t index) const;
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ void DefaultPieceStorageTest::testGetMissingFastPiece() {
|
|||
|
||||
peer->setAllBitfield();
|
||||
peer->setFastExtensionEnabled(true);
|
||||
peer->addFastSetIndex(2);
|
||||
peer->addPeerAllowedIndex(2);
|
||||
|
||||
PieceHandle piece = pss.getMissingFastPiece(peer);
|
||||
CPPUNIT_ASSERT_EQUAL(string("piece: index=2, length=128"),
|
||||
|
|
Loading…
Reference in New Issue