Browse Source

2008-05-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Call subtractPieceStats from ~PeerInteractionCommand only when 
the
	peer has at least one completed piece.
	* src/Peer.cc
	* src/Peer.h
	* src/PeerInteractionCommand.cc
	* src/PeerSessionResource.cc
	* src/PeerSessionResource.h
Tatsuhiro Tsujikawa 17 năm trước cách đây
mục cha
commit
7bbd9cec3b

+ 10 - 0
ChangeLog

@@ -1,3 +1,13 @@
+2008-05-16  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Call subtractPieceStats from ~PeerInteractionCommand only when the
+	peer has at least one completed piece.
+	* src/Peer.cc
+	* src/Peer.h
+	* src/PeerInteractionCommand.cc
+	* src/PeerSessionResource.cc
+	* src/PeerSessionResource.h
+
 2008-05-16  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 2008-05-16  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 
 	Removed unnecessary sorting
 	Removed unnecessary sorting

+ 6 - 0
src/Peer.cc

@@ -454,4 +454,10 @@ const Time& Peer::getLastAmUnchoking() const
   return _res->getLastAmUnchoking();
   return _res->getLastAmUnchoking();
 }
 }
 
 
+uint64_t Peer::getCompletedLength() const
+{
+  assert(_res);
+  return _res->getCompletedLength();
+}
+
 } // namespace aria2
 } // namespace aria2

+ 2 - 0
src/Peer.h

@@ -235,6 +235,8 @@ public:
   const Time& getLastDownloadUpdate() const;
   const Time& getLastDownloadUpdate() const;
 
 
   const Time& getLastAmUnchoking() const;
   const Time& getLastAmUnchoking() const;
+
+  uint64_t getCompletedLength() const;
 };
 };
 
 
 typedef SharedHandle<Peer> PeerHandle;
 typedef SharedHandle<Peer> PeerHandle;

+ 4 - 2
src/PeerInteractionCommand.cc

@@ -170,8 +170,10 @@ PeerInteractionCommand::PeerInteractionCommand(int32_t cuid,
 }
 }
 
 
 PeerInteractionCommand::~PeerInteractionCommand() {
 PeerInteractionCommand::~PeerInteractionCommand() {
-  pieceStorage->subtractPieceStats(peer->getBitfield(),
-				   peer->getBitfieldLength());
+  if(peer->getCompletedLength() > 0) {
+    pieceStorage->subtractPieceStats(peer->getBitfield(),
+				     peer->getBitfieldLength());
+  }
   peer->releaseSessionResource();
   peer->releaseSessionResource();
   PEER_OBJECT_CLUSTER(btContext)->unregisterHandle(peer->getID());
   PEER_OBJECT_CLUSTER(btContext)->unregisterHandle(peer->getID());
 					
 					

+ 5 - 0
src/PeerSessionResource.cc

@@ -337,4 +337,9 @@ const Time& PeerSessionResource::getLastAmUnchoking() const
   return _lastAmUnchoking;
   return _lastAmUnchoking;
 }
 }
 
 
+uint64_t PeerSessionResource::getCompletedLength() const
+{
+  return _bitfieldMan->getCompletedLength();
+}
+
 } // namespace aria2
 } // namespace aria2

+ 2 - 0
src/PeerSessionResource.h

@@ -185,6 +185,8 @@ public:
   const Time& getLastDownloadUpdate() const;
   const Time& getLastDownloadUpdate() const;
 
 
   const Time& getLastAmUnchoking() const;
   const Time& getLastAmUnchoking() const;
+
+  uint64_t getCompletedLength() const;
 };
 };
 
 
 } // namespace aria2
 } // namespace aria2