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

@ -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>

1
TODO
View File

@ -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.

View File

@ -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);

View File

@ -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;

View File

@ -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));

View File

@ -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);

View File

@ -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);

View File

@ -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) {

View File

@ -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();