mirror of https://github.com/aria2/aria2
				
				
				
			2009-04-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed the bug that removed peer's session upload/download length are counted twice in _cachedTransferStat before it is re-calculated. This affected the calculation of shara ratio, resulting aria2 wrongly determines that specified share ratio is reached. Also fixed the typo in calculateStatFor function name. * src/BtSetup.cc * src/DefaultPeerStorage.cc * src/ShareRatioSeedCriteria.h * test/ShareRatioSeedCriteriaTest.ccpull/1/head
							parent
							
								
									8831819407
								
							
						
					
					
						commit
						becd34bcb9
					
				
							
								
								
									
										12
									
								
								ChangeLog
								
								
								
								
							
							
						
						
									
										12
									
								
								ChangeLog
								
								
								
								
							|  | @ -1,3 +1,15 @@ | |||
| 2009-04-05  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net> | ||||
| 
 | ||||
| 	Fixed the bug that removed peer's session upload/download length | ||||
| 	are counted twice in _cachedTransferStat before it is | ||||
| 	re-calculated.  This affected the calculation of shara ratio, | ||||
| 	resulting aria2 wrongly determines that specified share ratio is | ||||
| 	reached. Also fixed the typo in calculateStatFor function name. | ||||
| 	* src/BtSetup.cc | ||||
| 	* src/DefaultPeerStorage.cc | ||||
| 	* src/ShareRatioSeedCriteria.h | ||||
| 	* test/ShareRatioSeedCriteriaTest.cc | ||||
| 
 | ||||
| 2009-04-01  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net> | ||||
| 
 | ||||
| 	* Release 1.3.0 | ||||
|  |  | |||
|  | @ -57,6 +57,7 @@ | |||
| #include "DHTRegistry.h" | ||||
| #include "BtProgressInfoFile.h" | ||||
| #include "BtAnnounce.h" | ||||
| #include "BtRuntime.h" | ||||
| 
 | ||||
| namespace aria2 { | ||||
| 
 | ||||
|  | @ -136,7 +137,6 @@ void BtSetup::setup(std::deque<Command*>& commands, | |||
| 				    btContext)); | ||||
|       cri->setPieceStorage(pieceStorage); | ||||
|       cri->setPeerStorage(peerStorage); | ||||
|       cri->setBtRuntime(btRuntime); | ||||
| 
 | ||||
|       unionCri->addSeedCriteria(cri); | ||||
|     } | ||||
|  |  | |||
|  | @ -192,7 +192,7 @@ void DefaultPeerStorage::getActivePeers(std::deque<SharedHandle<Peer> >& activeP | |||
|   std::for_each(peers.begin(), peers.end(), CollectActivePeer(activePeers)); | ||||
| } | ||||
| 
 | ||||
| static TransferStat caluclateStatFor(const SharedHandle<Peer>& peer) | ||||
| static TransferStat calculateStatFor(const SharedHandle<Peer>& peer) | ||||
| { | ||||
|   struct timeval now; | ||||
|   gettimeofday(&now, 0); | ||||
|  | @ -223,7 +223,7 @@ TransferStat DefaultPeerStorage::calculateStat() | |||
|       s.sessionDownloadLength = (*i)->getSessionDownloadLength(); | ||||
|       s.sessionUploadLength = (*i)->getSessionUploadLength(); | ||||
| 
 | ||||
|       _peerTransferStatMap[(*i)->getID()] = caluclateStatFor(*i); | ||||
|       _peerTransferStatMap[(*i)->getID()] = calculateStatFor(*i); | ||||
|       stat += s; | ||||
|     } | ||||
|     _cachedTransferStat = stat; | ||||
|  | @ -240,8 +240,8 @@ TransferStat DefaultPeerStorage::calculateStat() | |||
| void DefaultPeerStorage::updateTransferStatFor(const SharedHandle<Peer>& peer) | ||||
| { | ||||
|   logger->debug("Updating TransferStat for peer %s", peer->getID().c_str()); | ||||
|   _cachedTransferStat = _cachedTransferStat-_peerTransferStatMap[peer->getID()]; | ||||
|   TransferStat s = caluclateStatFor(peer); | ||||
|   _cachedTransferStat -= _peerTransferStatMap[peer->getID()]; | ||||
|   TransferStat s = calculateStatFor(peer); | ||||
|   _cachedTransferStat += s; | ||||
|   _peerTransferStatMap[peer->getID()] = s; | ||||
| } | ||||
|  | @ -266,8 +266,11 @@ void DefaultPeerStorage::onErasingPeer(const SharedHandle<Peer>& peer) {} | |||
| void DefaultPeerStorage::onReturningPeer(const SharedHandle<Peer>& peer) | ||||
| { | ||||
|   if(peer->isActive()) { | ||||
|     removedPeerSessionDownloadLength += peer->getSessionDownloadLength(); | ||||
|     removedPeerSessionUploadLength += peer->getSessionUploadLength(); | ||||
|     TransferStat removedStat(calculateStatFor(peer)); | ||||
|     removedPeerSessionDownloadLength += removedStat.getSessionDownloadLength(); | ||||
|     removedPeerSessionUploadLength += removedStat.getSessionUploadLength(); | ||||
|     _cachedTransferStat -= removedStat; | ||||
| 
 | ||||
|     // Execute choking algorithm if unchoked and interested peer is
 | ||||
|     // disconnected.
 | ||||
|     if(!peer->amChoking() && peer->peerInterested()) { | ||||
|  |  | |||
|  | @ -39,7 +39,6 @@ | |||
| #include "BtContext.h" | ||||
| #include "PeerStorage.h" | ||||
| #include "PieceStorage.h" | ||||
| #include "BtRuntime.h" | ||||
| 
 | ||||
| namespace aria2 { | ||||
| 
 | ||||
|  | @ -49,7 +48,6 @@ private: | |||
|   SharedHandle<BtContext> btContext; | ||||
|   SharedHandle<PeerStorage> _peerStorage; | ||||
|   SharedHandle<PieceStorage> _pieceStorage; | ||||
|   SharedHandle<BtRuntime> _btRuntime; | ||||
| public: | ||||
|   ShareRatioSeedCriteria(double ratio, const SharedHandle<BtContext>& btContext) | ||||
|     :ratio(ratio), | ||||
|  | @ -64,10 +62,9 @@ public: | |||
|       return false; | ||||
|     } | ||||
|     TransferStat stat = _peerStorage->calculateStat(); | ||||
|     uint64_t allTimeUploadLength = | ||||
|       _btRuntime->getUploadLengthAtStartup()+stat.getSessionUploadLength(); | ||||
|     return ratio <= | ||||
|       ((double)allTimeUploadLength)/_pieceStorage->getCompletedLength(); | ||||
|       (double)stat.getAllTimeUploadLength()/ | ||||
|        _pieceStorage->getCompletedLength(); | ||||
|   } | ||||
| 
 | ||||
|   void setRatio(double ratio) { | ||||
|  | @ -87,11 +84,6 @@ public: | |||
|   { | ||||
|     _pieceStorage = pieceStorage; | ||||
|   } | ||||
| 
 | ||||
|   void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime) | ||||
|   { | ||||
|     _btRuntime = btRuntime; | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| } // namespace aria2
 | ||||
|  |  | |||
|  | @ -30,13 +30,9 @@ void ShareRatioSeedCriteriaTest::testEvaluate() { | |||
|   btContext->setTotalLength(1000000); | ||||
|   btContext->setInfoHash((const unsigned char*)infoHash.c_str()); | ||||
|    | ||||
|   SharedHandle<BtRuntime> btRuntime(new BtRuntime()); | ||||
|   btRuntime->setUploadLengthAtStartup(500000); | ||||
|    | ||||
|   SharedHandle<MockPeerStorage> peerStorage(new MockPeerStorage()); | ||||
|   TransferStat stat; | ||||
|   stat.setSessionDownloadLength(1000000); | ||||
|   stat.setSessionUploadLength(500000); | ||||
|   stat.setAllTimeUploadLength(1000000); | ||||
|   peerStorage->setStat(stat); | ||||
| 
 | ||||
|   SharedHandle<MockPieceStorage> pieceStorage(new MockPieceStorage()); | ||||
|  | @ -45,7 +41,6 @@ void ShareRatioSeedCriteriaTest::testEvaluate() { | |||
|   ShareRatioSeedCriteria cri(1.0, btContext); | ||||
|   cri.setPeerStorage(peerStorage); | ||||
|   cri.setPieceStorage(pieceStorage); | ||||
|   cri.setBtRuntime(btRuntime); | ||||
| 
 | ||||
|   CPPUNIT_ASSERT(cri.evaluate()); | ||||
|    | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Tatsuhiro Tsujikawa
						Tatsuhiro Tsujikawa