diff --git a/ChangeLog b/ChangeLog index 88487228..40733090 100644 --- a/ChangeLog +++ b/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 diff --git a/TODO b/TODO index bbc22999..cc222e7f 100644 --- a/TODO +++ b/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. \ No newline at end of file diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc index 8a24a1e2..ff8b5d11 100644 --- a/src/ActivePeerConnectionCommand.cc +++ b/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); diff --git a/src/BtRuntime.h b/src/BtRuntime.h index 911fa6d3..7c2313e7 100644 --- a/src/BtRuntime.h +++ b/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 BtRuntimeHandle; diff --git a/src/DownloadEngineFactory.cc b/src/DownloadEngineFactory.cc index d447dc90..31f9d0bc 100644 --- a/src/DownloadEngineFactory.cc +++ b/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)); diff --git a/src/PeerInitiateConnectionCommand.cc b/src/PeerInitiateConnectionCommand.cc index 399cfb1e..8ada7e3f 100644 --- a/src/PeerInitiateConnectionCommand.cc +++ b/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); diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc index 87a3bf52..d1476cd4 100644 --- a/src/PeerInteractionCommand.cc +++ b/src/PeerInteractionCommand.cc @@ -46,6 +46,7 @@ #include "DefaultBtMessageFactory.h" #include "DefaultBtInteractive.h" #include "PeerConnection.h" +#include "CUIDCounter.h" #include 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); diff --git a/src/PeerListenCommand.cc b/src/PeerListenCommand.cc index c2610455..f544e9f3 100644 --- a/src/PeerListenCommand.cc +++ b/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) { diff --git a/src/TrackerUpdateCommand.cc b/src/TrackerUpdateCommand.cc index 53796e76..24f57d71 100644 --- a/src/TrackerUpdateCommand.cc +++ b/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();