Kaynağa Gözat

2008-12-29 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Fixed the bug that BitTorrent download doesn't finish when
	REJECT message is received before CHOKE message.  The old
	implementation doen't clear the use-bit of the piece when
	recieved REJECT message.
	* src/DefaultBtMessageDispatcher.cc
	* test/DefaultBtMessageDispatcherTest.cc
Tatsuhiro Tsujikawa 17 yıl önce
ebeveyn
işleme
992f82eb5a

+ 9 - 0
ChangeLog

@@ -1,3 +1,12 @@
+2008-12-29  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Fixed the bug that BitTorrent download doesn't finish when REJECT
+	message is received before CHOKE message.  The old implementation
+	doen't clear the use-bit of the piece when recieved REJECT
+	message.
+	* src/DefaultBtMessageDispatcher.cc
+	* test/DefaultBtMessageDispatcherTest.cc
+
 2008-12-25  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	* Release 1.1.1

+ 1 - 0
src/DefaultBtMessageDispatcher.cc

@@ -408,6 +408,7 @@ void DefaultBtMessageDispatcher::removeOutstandingRequest(const RequestSlot& slo
   std::deque<RequestSlot>::iterator i =
     std::lower_bound(requestSlots.begin(), requestSlots.end(), slot);
   if(i != requestSlots.end() && (*i) == slot) {
+    AbortOutstandingRequest(slot.getPiece(), cuid)(*i);
     requestSlots.erase(i);
   }
 }

+ 12 - 3
test/DefaultBtMessageDispatcherTest.cc

@@ -385,16 +385,25 @@ void DefaultBtMessageDispatcherTest::testGetOutstandingRequest() {
 }
 
 void DefaultBtMessageDispatcherTest::testRemoveOutstandingRequest() {
-  RequestSlot slot(1, 1024, 16*1024, 10);
+  SharedHandle<Piece> piece(new Piece(1, 1024*1024));
+  size_t blockIndex = 0;
+  CPPUNIT_ASSERT(piece->getMissingUnusedBlockIndex(blockIndex));
+  uint32_t begin = blockIndex*piece->getBlockLength();
+  size_t length = piece->getBlockLength(blockIndex);
+  RequestSlot slot(piece->getIndex(), begin, length, blockIndex, piece);
   btMessageDispatcher->addOutstandingRequest(slot);
 
-  RequestSlot s2 = btMessageDispatcher->getOutstandingRequest(1, 1024, 16*1024);
+  RequestSlot s2 = btMessageDispatcher->getOutstandingRequest
+    (piece->getIndex(), begin, length);
   CPPUNIT_ASSERT(!RequestSlot::isNull(s2));
+  CPPUNIT_ASSERT(piece->isBlockUsed(blockIndex));
 
   btMessageDispatcher->removeOutstandingRequest(s2);
 
-  RequestSlot s3 = btMessageDispatcher->getOutstandingRequest(1, 1024, 16*1024);
+  RequestSlot s3 = btMessageDispatcher->getOutstandingRequest
+    (piece->getIndex(), begin, length);
   CPPUNIT_ASSERT(RequestSlot::isNull(s3));  
+  CPPUNIT_ASSERT(!piece->isBlockUsed(blockIndex));
 }
 
 } // namespace aria2