소스 검색

Use CUIDCounter instead of BtRuntime::getNewCuid():
* src/ActivePeerConnectionCommand.cc
* src/PeerInteractionCommand.cc
* src/BtRuntime.h
(cuidCounter): Removed.
(getNewCuid): Removed.
* src/DownloadEngineFactory.cc
* src/PeerListenCommand.cc
* src/TrackerUpdateCommand.cc
* src/PeerInitiateConnectionCommand.cc
Use CUIDCounter instead of BtRuntime::getNewCuid():
* src/ActivePeerConnectionCommand.cc
* src/PeerInteractionCommand.cc
* src/BtRuntime.h
(cuidCounter): Removed.
(getNewCuid): Removed.
* src/DownloadEngineFactory.cc
* src/PeerListenCommand.cc
* src/TrackerUpdateCommand.cc
* src/PeerInitiateConnectionCommand.cc

Tatsuhiro Tsujikawa 18 년 전
부모
커밋
ad7078db28
9개의 변경된 파일39개의 추가작업 그리고 30개의 파일을 삭제
  1. 11 0
      ChangeLog
  2. 0 1
      TODO
  3. 2 1
      src/ActivePeerConnectionCommand.cc
  4. 3 6
      src/BtRuntime.h
  5. 9 8
      src/DownloadEngineFactory.cc
  6. 3 3
      src/PeerInitiateConnectionCommand.cc
  7. 3 3
      src/PeerInteractionCommand.cc
  8. 4 4
      src/PeerListenCommand.cc
  9. 4 4
      src/TrackerUpdateCommand.cc

+ 11 - 0
ChangeLog

@@ -2,6 +2,17 @@
 
 	* Added the simultaneous download feature.
 	* src/main.cc: Print "Exception caught: " when exception is caught.
+
+	Use CUIDCounter instead of BtRuntime::getNewCuid():
+	* src/ActivePeerConnectionCommand.cc
+	* src/PeerInteractionCommand.cc
+	* src/BtRuntime.h
+	(cuidCounter): Removed.
+	(getNewCuid): Removed.
+	* src/DownloadEngineFactory.cc
+	* src/PeerListenCommand.cc
+	* src/TrackerUpdateCommand.cc
+	* src/PeerInitiateConnectionCommand.cc
 	
 2007-04-06  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 

+ 0 - 1
TODO

@@ -37,4 +37,3 @@
 * Do not use ufilename in multi-simultaneous download mode.
 * Merge umask patch.
 https://sourceforge.net/tracker/index.php?func=detail&aid=1718641&group_id=159897&atid=813673
-* Use CUIDCounter to generate CUID.

+ 2 - 1
src/ActivePeerConnectionCommand.cc

@@ -34,6 +34,7 @@
 /* copyright --> */
 #include "ActivePeerConnectionCommand.h"
 #include "PeerInitiateConnectionCommand.h"
+#include "CUIDCounter.h"
 
 bool ActivePeerConnectionCommand::execute() {
   if(btRuntime->isHalt()) {
@@ -59,7 +60,7 @@ void ActivePeerConnectionCommand::connectToPeer(const PeerHandle& peer)
   if(peer.isNull()) {
     return;
   }
-  peer->cuid = btRuntime->getNewCuid();
+  peer->cuid = CUIDCounterSingletonHolder::instance()->newID();
   PeerInitiateConnectionCommand* command =
     new PeerInitiateConnectionCommand(peer->cuid, peer, e, btContext);
   e->commands.push_back(command);

+ 3 - 6
src/BtRuntime.h

@@ -46,14 +46,13 @@ private:
   int port;
   bool halt;
   int connections;
-  int cuidCounter;
 public:
   BtRuntime():
     uploadLengthAtStartup(0),
     port(0),
     halt(false),
-    connections(0),
-    cuidCounter(0) {}
+    connections(0)
+    {}
   ~BtRuntime() {}
 
   long long int getUploadLengthAtStartup() const {
@@ -84,9 +83,7 @@ public:
 
   bool lessThanMinPeer() const { return connections < MIN_PEERS; }
 
-  bool lessThanEqMinPeer() const { return connections <= MIN_PEERS; }
-  
-  int getNewCuid() { return ++cuidCounter; }
+  bool lessThanEqMinPeer() const { return connections <= MIN_PEERS; }  
 };
 
 typedef SharedHandle<BtRuntime> BtRuntimeHandle;

+ 9 - 8
src/DownloadEngineFactory.cc

@@ -173,7 +173,8 @@ DownloadEngineFactory::newTorrentConsoleEngine(const BtContextHandle& btContext,
   }
 
   PeerListenCommand* listenCommand =
-    new PeerListenCommand(btRuntime->getNewCuid(), te, btContext);
+    new PeerListenCommand(CUIDCounterSingletonHolder::instance()->newID(),
+			  te, btContext);
   int port;
   int listenPort = op->getAsInt(PREF_LISTEN_PORT);
   if(listenPort == -1) {
@@ -188,25 +189,25 @@ DownloadEngineFactory::newTorrentConsoleEngine(const BtContextHandle& btContext,
   btRuntime->setListenPort(port);
   te->commands.push_back(listenCommand);
   
-  te->commands.push_back(new TrackerWatcherCommand(btRuntime->getNewCuid(),
+  te->commands.push_back(new TrackerWatcherCommand(CUIDCounterSingletonHolder::instance()->newID(),
 						   te,
 						   btContext));
-  te->commands.push_back(new TrackerUpdateCommand(btRuntime->getNewCuid(),
+  te->commands.push_back(new TrackerUpdateCommand(CUIDCounterSingletonHolder::instance()->newID(),
 						  te,
 						  btContext));
-  te->commands.push_back(new TorrentAutoSaveCommand(btRuntime->getNewCuid(),
+  te->commands.push_back(new TorrentAutoSaveCommand(CUIDCounterSingletonHolder::instance()->newID(),
 						    te,
 						    btContext,
 						    op->getAsInt(PREF_AUTO_SAVE_INTERVAL)));
-  te->commands.push_back(new PeerChokeCommand(btRuntime->getNewCuid(),
+  te->commands.push_back(new PeerChokeCommand(CUIDCounterSingletonHolder::instance()->newID(),
 					      te,
 					      btContext,
 					      10));
-  te->commands.push_back(new HaveEraseCommand(btRuntime->getNewCuid(),
+  te->commands.push_back(new HaveEraseCommand(CUIDCounterSingletonHolder::instance()->newID(),
 					      te,
 					      btContext,
 					      10));
-  te->commands.push_back(new ActivePeerConnectionCommand(btRuntime->getNewCuid(),
+  te->commands.push_back(new ActivePeerConnectionCommand(CUIDCounterSingletonHolder::instance()->newID(),
 							 te,
 							 btContext,
 							 30));
@@ -219,7 +220,7 @@ DownloadEngineFactory::newTorrentConsoleEngine(const BtContextHandle& btContext,
     unionCri->addSeedCriteria(new ShareRatioSeedCriteria(op->getAsDouble(PREF_SEED_RATIO), btContext));
   }
   if(unionCri->getSeedCriterion().size() > 0) {
-    te->commands.push_back(new SeedCheckCommand(btRuntime->getNewCuid(),
+    te->commands.push_back(new SeedCheckCommand(CUIDCounterSingletonHolder::instance()->newID(),
 						te,
 						btContext,
 						unionCri));

+ 3 - 3
src/PeerInitiateConnectionCommand.cc

@@ -38,6 +38,7 @@
 #include "DlAbortEx.h"
 #include "message.h"
 #include "prefs.h"
+#include "CUIDCounter.h"
 
 PeerInitiateConnectionCommand::PeerInitiateConnectionCommand(int cuid,
 							     const PeerHandle& peer,
@@ -68,10 +69,9 @@ bool PeerInitiateConnectionCommand::executeInternal() {
 bool PeerInitiateConnectionCommand::prepareForNextPeer(int wait) {
   if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeer()) {
     PeerHandle peer = peerStorage->getUnusedPeer();
-    int newCuid = btRuntime->getNewCuid();
-    peer->cuid = newCuid;
+    peer->cuid = CUIDCounterSingletonHolder::instance()->newID();
     PeerInitiateConnectionCommand* command =
-      new PeerInitiateConnectionCommand(newCuid,
+      new PeerInitiateConnectionCommand(peer->cuid,
 					peer,
 					e,
 					btContext);

+ 3 - 3
src/PeerInteractionCommand.cc

@@ -46,6 +46,7 @@
 #include "DefaultBtMessageFactory.h"
 #include "DefaultBtInteractive.h"
 #include "PeerConnection.h"
+#include "CUIDCounter.h"
 #include <algorithm>
 
 PeerInteractionCommand::PeerInteractionCommand(int cuid,
@@ -201,10 +202,9 @@ bool PeerInteractionCommand::executeInternal() {
 bool PeerInteractionCommand::prepareForNextPeer(int wait) {
   if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeer()) {
     PeerHandle peer = peerStorage->getUnusedPeer();
-    int newCuid = btRuntime->getNewCuid();
-    peer->cuid = newCuid;
+    peer->cuid = CUIDCounterSingletonHolder::instance()->newID();
     PeerInitiateConnectionCommand* command =
-      new PeerInitiateConnectionCommand(newCuid,
+      new PeerInitiateConnectionCommand(peer->cuid,
 					peer,
 					e,
 					btContext);

+ 4 - 4
src/PeerListenCommand.cc

@@ -35,6 +35,7 @@
 #include "PeerListenCommand.h"
 #include "PeerInteractionCommand.h"
 #include "RecoverableException.h"
+#include "CUIDCounter.h"
 
 PeerListenCommand::PeerListenCommand(int cuid,
 				     TorrentDownloadEngine* e,
@@ -82,15 +83,14 @@ bool PeerListenCommand::execute() {
 					      btContext->getPieceLength(),
 					      btContext->getTotalLength()));
 	if(peerStorage->addIncomingPeer(peer)) {
-	  int newCuid =  btRuntime->getNewCuid();
-	  peer->cuid = newCuid;
+	  peer->cuid = CUIDCounterSingletonHolder::instance()->newID();
 	  PeerInteractionCommand* command =
-	    new PeerInteractionCommand(newCuid, peer, e,
+	    new PeerInteractionCommand(peer->cuid, peer, e,
 				       btContext,
 				       peerSocket,
 				       PeerInteractionCommand::RECEIVER_WAIT_HANDSHAKE);
 	  e->commands.push_back(command);
-	  logger->debug("CUID#%d - incoming connection, adding new command CUID#%d", cuid, newCuid);
+	  logger->debug("CUID#%d - incoming connection, adding new command CUID#%d", cuid, peer->cuid);
 	}
       }
     } catch(RecoverableException* ex) {

+ 4 - 4
src/TrackerUpdateCommand.cc

@@ -39,6 +39,7 @@
 #include "PeerInitiateConnectionCommand.h"
 #include "SleepCommand.h"
 #include "Util.h"
+#include "CUIDCounter.h"
 
 TrackerUpdateCommand::TrackerUpdateCommand(int cuid,
 					   TorrentDownloadEngine* e,
@@ -101,15 +102,14 @@ bool TrackerUpdateCommand::execute() {
       if(peer.isNull()) {
 	break;
       }
-      int newCuid =  btRuntime->getNewCuid();
-      peer->cuid = newCuid;
+      peer->cuid = CUIDCounterSingletonHolder::instance()->newID();
       PeerInitiateConnectionCommand* command =
-	new PeerInitiateConnectionCommand(newCuid,
+	new PeerInitiateConnectionCommand(peer->cuid,
 					  peer,
 					  e,
 					  btContext);
       e->commands.push_back(command);
-      logger->debug("CUID#%d - Adding new command CUID#%d", cuid, newCuid);
+      logger->debug("CUID#%d - Adding new command CUID#%d", cuid, peer->cuid);
     }
     btAnnounce->announceSuccess();
     btAnnounce->resetAnnounce();