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
pull/1/head
Tatsuhiro Tsujikawa 2007-05-20 15:22:50 +00:00
parent f3995b1f7e
commit ad7078db28
9 changed files with 39 additions and 30 deletions

View File

@ -3,6 +3,17 @@
* Added the simultaneous download feature. * Added the simultaneous download feature.
* src/main.cc: Print "Exception caught: " when exception is caught. * 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> 2007-04-06 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/PeerAbstractCommand.cc * src/PeerAbstractCommand.cc

1
TODO
View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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