Parcourir la source

To fix the bug that causes the number of bytes uploaded is not
saved
to .aria2 file:

* src/DefaultPeerStorage.h
(removedPeerSessionDownloadLength): New variable.
(removedPeerSessionUploadLength): New variable.
* src/DefaultPeerStorage.cc
(DefaultPieceStorage): Added
removedPeerSessionDownloadLength(0),
removedPeerSessionUploadLength(0).
(calculateStat): Calculate the number of bytes
downloaded(uploaded)
through all peers, and then add
removedPeerSessionDownloadLength(
removedPeerSessionUploadLength) to it.
(deleteUnusedPeer): Add the number of bytes downloaded(uploaded)
from
(to) the peer to removedPeerSessionDownloadLength
(removedPeerSessionUploadLength).

Tatsuhiro Tsujikawa il y a 19 ans
Parent
commit
b14e4a5ac1
4 fichiers modifiés avec 35 ajouts et 1 suppressions
  1. 21 0
      ChangeLog
  2. 11 1
      src/DefaultPeerStorage.cc
  3. 2 0
      src/DefaultPeerStorage.h
  4. 1 0
      src/PeerAbstractCommand.cc

+ 21 - 0
ChangeLog

@@ -34,6 +34,27 @@
 	(setGlobalSignalHandler): New function.
 	* src/UrlRequestInfo.cc:
 	setSignalHander -> Util::setGlobalSignalHandler
+
+	Reset peer status in order to exit gracefully:
+
+	* src/PeerAbstractCommand.cc
+	(execute): Call peer->resetStatus() when btRuntime->isHalt() is true.
+
+	To fix the bug that causes the number of bytes uploaded is not saved
+	to .aria2 file:
+
+	* src/DefaultPeerStorage.h
+	(removedPeerSessionDownloadLength): New variable.
+	(removedPeerSessionUploadLength): New variable.
+	* src/DefaultPeerStorage.cc
+	(DefaultPieceStorage): Added removedPeerSessionDownloadLength(0),
+	removedPeerSessionUploadLength(0).
+	(calculateStat): Calculate the number of bytes downloaded(uploaded)
+	through all peers, and then add removedPeerSessionDownloadLength(
+	removedPeerSessionUploadLength) to it.
+	(deleteUnusedPeer): Add the number of bytes downloaded(uploaded) from
+	 (to) the peer to removedPeerSessionDownloadLength
+	 (removedPeerSessionUploadLength).
 	
 2006-11-09  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 

+ 11 - 1
src/DefaultPeerStorage.cc

@@ -44,7 +44,9 @@ DefaultPeerStorage::DefaultPeerStorage(BtContextHandle btContext,
   option(option),
   maxPeerListSize(MAX_PEER_LIST_SIZE),
   peerEntryIdCounter(0),
-  btRuntime(BT_RUNTIME(btContext))
+  btRuntime(BT_RUNTIME(btContext)),
+  removedPeerSessionDownloadLength(0),
+  removedPeerSessionUploadLength(0)
 {
   logger = LogFactory::getInstance();
 }
@@ -154,9 +156,14 @@ TransferStat DefaultPeerStorage::calculateStat() {
     PeerHandle& peer = *itr;
     stat.downloadSpeed += peer->calculateDownloadSpeed();
     stat.uploadSpeed += peer->calculateUploadSpeed();
+  }
+  for(Peers::iterator itr = peers.begin(); itr != peers.end(); itr++) {
+    PeerHandle& peer = *itr;
     stat.sessionDownloadLength += peer->getSessionDownloadLength();
     stat.sessionUploadLength += peer->getSessionUploadLength();
   }
+  stat.sessionDownloadLength += removedPeerSessionDownloadLength;
+  stat.sessionUploadLength += removedPeerSessionUploadLength;
   return stat;
 }
 
@@ -165,6 +172,9 @@ void DefaultPeerStorage::deleteUnusedPeer(int delSize) {
       itr != peers.end() && delSize > 0;) {
     const PeerHandle& p = *itr;
     if(p->cuid == 0) {
+      // Update removedPeerSession******Length
+      removedPeerSessionDownloadLength += p->getSessionDownloadLength();
+      removedPeerSessionUploadLength += p->getSessionUploadLength();
       itr = peers.erase(itr);
       delSize--;
     } else {

+ 2 - 0
src/DefaultPeerStorage.h

@@ -53,6 +53,8 @@ private:
   int peerEntryIdCounter;
   Logger* logger;
   BtRuntimeHandle btRuntime;
+  long long int removedPeerSessionDownloadLength;
+  long long int removedPeerSessionUploadLength;
 public:
   DefaultPeerStorage(BtContextHandle btContext, const Option* option);
   virtual ~DefaultPeerStorage();

+ 1 - 0
src/PeerAbstractCommand.cc

@@ -60,6 +60,7 @@ PeerAbstractCommand::~PeerAbstractCommand() {
 
 bool PeerAbstractCommand::execute() {
   if(btRuntime->isHalt()) {
+    peer->resetStatus();
     return true;
   }
   try {