From f114c890961ef9a0f7666b077b40d22f39b6cdd3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 9 Jun 2010 14:47:13 +0000 Subject: [PATCH] 2010-06-09 Tatsuhiro Tsujikawa Made protected member variable private. Added accessor funcs. * src/ActivePeerConnectionCommand.cc * src/ActivePeerConnectionCommand.h * src/CheckIntegrityDispatcherCommand.cc * src/DHTEntryPointNameResolveCommand.h * src/DHTInteractionCommand.h * src/FileAllocationDispatcherCommand.cc * src/LpdReceiveMessageCommand.h * src/PeerChokeCommand.cc * src/PeerChokeCommand.h * src/PeerListenCommand.cc * src/PeerListenCommand.h * src/SeedCheckCommand.cc * src/SeedCheckCommand.h * src/SequentialDispatcherCommand.h * src/SleepCommand.cc * src/SleepCommand.h * src/TrackerWatcherCommand.cc * src/TrackerWatcherCommand.h --- ChangeLog | 22 +++++++++++++++++++ src/ActivePeerConnectionCommand.cc | 16 +++++++------- src/ActivePeerConnectionCommand.h | 6 +++--- src/CheckIntegrityDispatcherCommand.cc | 4 ++-- src/DHTEntryPointNameResolveCommand.h | 4 ++-- src/DHTInteractionCommand.h | 4 +--- src/FileAllocationDispatcherCommand.cc | 5 +++-- src/LpdReceiveMessageCommand.h | 3 +-- src/PeerChokeCommand.cc | 4 ++-- src/PeerChokeCommand.h | 2 +- src/PeerListenCommand.cc | 30 +++++++++++++------------- src/PeerListenCommand.h | 4 ++-- src/SeedCheckCommand.cc | 22 +++++++++---------- src/SeedCheckCommand.h | 6 +++--- src/SequentialDispatcherCommand.h | 7 +++++- src/SleepCommand.cc | 14 ++++++------ src/SleepCommand.h | 8 +++---- src/TrackerWatcherCommand.cc | 16 +++++++------- src/TrackerWatcherCommand.h | 2 +- 19 files changed, 102 insertions(+), 77 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6ef285c7..0625f0ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2010-06-09 Tatsuhiro Tsujikawa + + Made protected member variable private. Added accessor funcs. + * src/ActivePeerConnectionCommand.cc + * src/ActivePeerConnectionCommand.h + * src/CheckIntegrityDispatcherCommand.cc + * src/DHTEntryPointNameResolveCommand.h + * src/DHTInteractionCommand.h + * src/FileAllocationDispatcherCommand.cc + * src/LpdReceiveMessageCommand.h + * src/PeerChokeCommand.cc + * src/PeerChokeCommand.h + * src/PeerListenCommand.cc + * src/PeerListenCommand.h + * src/SeedCheckCommand.cc + * src/SeedCheckCommand.h + * src/SequentialDispatcherCommand.h + * src/SleepCommand.cc + * src/SleepCommand.h + * src/TrackerWatcherCommand.cc + * src/TrackerWatcherCommand.h + 2010-06-09 Tatsuhiro Tsujikawa Made protected member variable private. Added accessor funcs. diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc index 32996b5d..effdab88 100644 --- a/src/ActivePeerConnectionCommand.cc +++ b/src/ActivePeerConnectionCommand.cc @@ -66,8 +66,8 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand : Command(cuid), _requestGroup(requestGroup), - interval(interval), - e(e), + _interval(interval), + _e(e), _numNewConnection(5) { _requestGroup->increaseNumCommand(); @@ -82,8 +82,8 @@ bool ActivePeerConnectionCommand::execute() { if(_btRuntime->isHalt()) { return true; } - if(checkPoint.difference(global::wallclock) >= interval) { - checkPoint = global::wallclock; + if(_checkPoint.difference(global::wallclock) >= _interval) { + _checkPoint = global::wallclock; TransferStat tstat = _requestGroup->calculateStat(); const unsigned int maxDownloadLimit = _requestGroup->getMaxDownloadSpeedLimit(); @@ -129,7 +129,7 @@ bool ActivePeerConnectionCommand::execute() { } } } - e->addCommand(this); + _e->addCommand(this); return false; } @@ -138,13 +138,13 @@ void ActivePeerConnectionCommand::connectToPeer(const SharedHandle& peer) if(peer.isNull()) { return; } - peer->usedBy(e->newCUID()); + peer->usedBy(_e->newCUID()); PeerInitiateConnectionCommand* command = - new PeerInitiateConnectionCommand(peer->usedBy(), _requestGroup, peer, e, + new PeerInitiateConnectionCommand(peer->usedBy(), _requestGroup, peer, _e, _btRuntime); command->setPeerStorage(_peerStorage); command->setPieceStorage(_pieceStorage); - e->addCommand(command); + _e->addCommand(command); if(getLogger()->info()) { getLogger()->info(MSG_CONNECTING_TO_PEER, util::itos(getCuid()).c_str(), peer->ipaddr.c_str()); diff --git a/src/ActivePeerConnectionCommand.h b/src/ActivePeerConnectionCommand.h index e4d081e4..c4464425 100644 --- a/src/ActivePeerConnectionCommand.h +++ b/src/ActivePeerConnectionCommand.h @@ -57,9 +57,9 @@ private: SharedHandle _peerStorage; SharedHandle _btAnnounce; - time_t interval; // UNIT: sec - DownloadEngine* e; - Timer checkPoint; + time_t _interval; // UNIT: sec + DownloadEngine* _e; + Timer _checkPoint; unsigned int _numNewConnection; // the number of the connection to establish. public: ActivePeerConnectionCommand(cuid_t cuid, diff --git a/src/CheckIntegrityDispatcherCommand.cc b/src/CheckIntegrityDispatcherCommand.cc index 388253e2..bb0b1b16 100644 --- a/src/CheckIntegrityDispatcherCommand.cc +++ b/src/CheckIntegrityDispatcherCommand.cc @@ -56,14 +56,14 @@ CheckIntegrityDispatcherCommand::CheckIntegrityDispatcherCommand Command* CheckIntegrityDispatcherCommand::createCommand (const SharedHandle& entry) { - cuid_t newCUID = _e->newCUID(); + cuid_t newCUID = getDownloadEngine()->newCUID(); if(getLogger()->info()) { getLogger()->info("CUID#%s - Dispatching CheckIntegrityCommand CUID#%s.", util::itos(getCuid()).c_str(), util::itos(newCUID).c_str()); } return new CheckIntegrityCommand - (newCUID, entry->getRequestGroup(), _e, entry); + (newCUID, entry->getRequestGroup(), getDownloadEngine(), entry); } } // namespace aria2 diff --git a/src/DHTEntryPointNameResolveCommand.h b/src/DHTEntryPointNameResolveCommand.h index 0982f9ec..9c0c61a0 100644 --- a/src/DHTEntryPointNameResolveCommand.h +++ b/src/DHTEntryPointNameResolveCommand.h @@ -55,9 +55,9 @@ class AsyncNameResolver; #endif // ENABLE_ASYNC_DNS class DHTEntryPointNameResolveCommand:public Command { -protected: - DownloadEngine* _e; private: + DownloadEngine* _e; + #ifdef ENABLE_ASYNC_DNS SharedHandle _resolver; #endif // ENABLE_ASYNC_DNS diff --git a/src/DHTInteractionCommand.h b/src/DHTInteractionCommand.h index f5a3f049..4afc014a 100644 --- a/src/DHTInteractionCommand.h +++ b/src/DHTInteractionCommand.h @@ -47,14 +47,12 @@ class DownloadEngine; class SocketCore; class DHTInteractionCommand:public Command { -protected: - DownloadEngine* _e; private: + DownloadEngine* _e; SharedHandle _dispatcher; SharedHandle _receiver; SharedHandle _taskQueue; SharedHandle _readCheckSocket; - public: DHTInteractionCommand(cuid_t cuid, DownloadEngine* e); diff --git a/src/FileAllocationDispatcherCommand.cc b/src/FileAllocationDispatcherCommand.cc index cb41f60d..818f3342 100644 --- a/src/FileAllocationDispatcherCommand.cc +++ b/src/FileAllocationDispatcherCommand.cc @@ -53,13 +53,14 @@ FileAllocationDispatcherCommand::FileAllocationDispatcherCommand Command* FileAllocationDispatcherCommand::createCommand (const SharedHandle& entry) { - cuid_t newCUID = _e->newCUID(); + cuid_t newCUID = getDownloadEngine()->newCUID(); if(getLogger()->info()) { getLogger()->info(MSG_FILE_ALLOCATION_DISPATCH, util::itos(newCUID).c_str()); } FileAllocationCommand* command = - new FileAllocationCommand(newCUID, entry->getRequestGroup(), _e, entry); + new FileAllocationCommand(newCUID, entry->getRequestGroup(), + getDownloadEngine(), entry); return command; } diff --git a/src/LpdReceiveMessageCommand.h b/src/LpdReceiveMessageCommand.h index 9cd2dbbb..24fdd388 100644 --- a/src/LpdReceiveMessageCommand.h +++ b/src/LpdReceiveMessageCommand.h @@ -55,9 +55,8 @@ private: LpdReceiveMessageCommand (cuid_t cuid, const SharedHandle& receiver, DownloadEngine* e); -protected: - DownloadEngine* _e; + DownloadEngine* _e; public: virtual ~LpdReceiveMessageCommand(); diff --git a/src/PeerChokeCommand.cc b/src/PeerChokeCommand.cc index 30e3d7dd..fa9b0777 100644 --- a/src/PeerChokeCommand.cc +++ b/src/PeerChokeCommand.cc @@ -47,7 +47,7 @@ namespace aria2 { PeerChokeCommand::PeerChokeCommand(cuid_t cuid, DownloadEngine* e): Command(cuid), - e(e) {} + _e(e) {} PeerChokeCommand::~PeerChokeCommand() {} @@ -58,7 +58,7 @@ bool PeerChokeCommand::execute() { if(_peerStorage->chokeRoundIntervalElapsed()) { _peerStorage->executeChoke(); } - e->addCommand(this); + _e->addCommand(this); return false; } diff --git a/src/PeerChokeCommand.h b/src/PeerChokeCommand.h index ab9f59ec..2a99e1e5 100644 --- a/src/PeerChokeCommand.h +++ b/src/PeerChokeCommand.h @@ -46,7 +46,7 @@ class PeerStorage; class PeerChokeCommand : public Command { private: - DownloadEngine* e; + DownloadEngine* _e; SharedHandle _peerStorage; diff --git a/src/PeerListenCommand.cc b/src/PeerListenCommand.cc index 2d9eacc3..c68b985f 100644 --- a/src/PeerListenCommand.cc +++ b/src/PeerListenCommand.cc @@ -60,7 +60,7 @@ PeerListenCommand* PeerListenCommand::__instance = 0; PeerListenCommand::PeerListenCommand(cuid_t cuid, DownloadEngine* e): Command(cuid), - e(e), + _e(e), _lowestSpeedLimit(20*1024) { ++__numInstance; @@ -73,7 +73,7 @@ PeerListenCommand::~PeerListenCommand() bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq) { - socket.reset(new SocketCore()); + _socket.reset(new SocketCore()); std::vector randPorts = seq.flush(); std::random_shuffle(randPorts.begin(), randPorts.end(), @@ -86,15 +86,15 @@ bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq) } port = (*portItr); try { - socket->bind(port); - socket->beginListen(); - socket->setNonBlockingMode(); + _socket->bind(port); + _socket->beginListen(); + _socket->setNonBlockingMode(); getLogger()->notice("BitTorrent: listening to port %d", port); return true; } catch(RecoverableException& ex) { getLogger()->error(MSG_BIND_FAILURE, ex, util::itos(getCuid()).c_str(), port); - socket->closeConnection(); + _socket->closeConnection(); } } return false; @@ -102,33 +102,33 @@ bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq) uint16_t PeerListenCommand::getPort() const { - if(socket.isNull()) { + if(_socket.isNull()) { return 0; } else { std::pair addr; - socket->getAddrInfo(addr); + _socket->getAddrInfo(addr); return addr.second; } } bool PeerListenCommand::execute() { - if(e->isHaltRequested() || e->getRequestGroupMan()->downloadFinished()) { + if(_e->isHaltRequested() || _e->getRequestGroupMan()->downloadFinished()) { return true; } - for(int i = 0; i < 3 && socket->isReadable(0); ++i) { + for(int i = 0; i < 3 && _socket->isReadable(0); ++i) { SocketHandle peerSocket; try { - peerSocket.reset(socket->acceptConnection()); + peerSocket.reset(_socket->acceptConnection()); std::pair peerInfo; peerSocket->getPeerInfo(peerInfo); peerSocket->setNonBlockingMode(); SharedHandle peer(new Peer(peerInfo.first, peerInfo.second, true)); - cuid_t cuid = e->newCUID(); + cuid_t cuid = _e->newCUID(); Command* command = - new ReceiverMSEHandshakeCommand(cuid, peer, e, peerSocket); - e->addCommand(command); + new ReceiverMSEHandshakeCommand(cuid, peer, _e, peerSocket); + _e->addCommand(command); if(getLogger()->debug()) { getLogger()->debug("Accepted the connection from %s:%u.", peer->ipaddr.c_str(), @@ -140,7 +140,7 @@ bool PeerListenCommand::execute() { getLogger()->debug(MSG_ACCEPT_FAILURE, ex, util::itos(getCuid()).c_str()); } } - e->addCommand(this); + _e->addCommand(this); return false; } diff --git a/src/PeerListenCommand.h b/src/PeerListenCommand.h index f800f7ff..d8b6a2ec 100644 --- a/src/PeerListenCommand.h +++ b/src/PeerListenCommand.h @@ -46,8 +46,8 @@ class SocketCore; class PeerListenCommand : public Command { private: - DownloadEngine* e; - SharedHandle socket; + DownloadEngine* _e; + SharedHandle _socket; unsigned int _lowestSpeedLimit; static unsigned int __numInstance; diff --git a/src/SeedCheckCommand.cc b/src/SeedCheckCommand.cc index 5e3a4528..56853945 100644 --- a/src/SeedCheckCommand.cc +++ b/src/SeedCheckCommand.cc @@ -55,9 +55,9 @@ SeedCheckCommand::SeedCheckCommand const SharedHandle& seedCriteria) :Command(cuid), _requestGroup(requestGroup), - e(e), - seedCriteria(seedCriteria), - checkStarted(false) + _e(e), + _seedCriteria(seedCriteria), + _checkStarted(false) { setStatusRealtime(); _requestGroup->increaseNumCommand(); @@ -72,29 +72,29 @@ bool SeedCheckCommand::execute() { if(_btRuntime->isHalt()) { return true; } - if(!seedCriteria.get()) { + if(!_seedCriteria.get()) { return false; } - if(!checkStarted) { + if(!_checkStarted) { if(_pieceStorage->downloadFinished()) { - checkStarted = true; - seedCriteria->reset(); + _checkStarted = true; + _seedCriteria->reset(); } } - if(checkStarted) { - if(seedCriteria->evaluate()) { + if(_checkStarted) { + if(_seedCriteria->evaluate()) { getLogger()->notice(MSG_SEEDING_END); _btRuntime->setHalt(true); } } - e->addCommand(this); + _e->addCommand(this); return false; } void SeedCheckCommand::setSeedCriteria (const SharedHandle& seedCriteria) { - this->seedCriteria = seedCriteria; + _seedCriteria = seedCriteria; } void SeedCheckCommand::setBtRuntime(const SharedHandle& btRuntime) diff --git a/src/SeedCheckCommand.h b/src/SeedCheckCommand.h index daaa02de..875173ec 100644 --- a/src/SeedCheckCommand.h +++ b/src/SeedCheckCommand.h @@ -50,11 +50,11 @@ class SeedCheckCommand : public Command { private: RequestGroup* _requestGroup; - DownloadEngine* e; + DownloadEngine* _e; SharedHandle _pieceStorage; SharedHandle _btRuntime; - SharedHandle seedCriteria; - bool checkStarted; + SharedHandle _seedCriteria; + bool _checkStarted; public: SeedCheckCommand(cuid_t cuid, RequestGroup* requestGroup, diff --git a/src/SequentialDispatcherCommand.h b/src/SequentialDispatcherCommand.h index 37bdb030..08c76ced 100644 --- a/src/SequentialDispatcherCommand.h +++ b/src/SequentialDispatcherCommand.h @@ -47,10 +47,15 @@ class DownloadEngine; template class SequentialDispatcherCommand : public Command { -protected: +private: SharedHandle > _picker; DownloadEngine* _e; +protected: + DownloadEngine* getDownloadEngine() const + { + return _e; + } public: SequentialDispatcherCommand(cuid_t cuid, const SharedHandle >& picker, diff --git a/src/SleepCommand.cc b/src/SleepCommand.cc index faaba063..c8fd2868 100644 --- a/src/SleepCommand.cc +++ b/src/SleepCommand.cc @@ -47,22 +47,22 @@ namespace aria2 { SleepCommand::SleepCommand(cuid_t cuid, DownloadEngine* e, RequestGroup* requestGroup, Command* nextCommand, time_t wait): - Command(cuid), engine(e), _requestGroup(requestGroup), - nextCommand(nextCommand), wait(wait), checkPoint(global::wallclock) {} + Command(cuid), _engine(e), _requestGroup(requestGroup), + _nextCommand(nextCommand), _wait(wait), _checkPoint(global::wallclock) {} SleepCommand::~SleepCommand() { - delete nextCommand; + delete _nextCommand; } bool SleepCommand::execute() { if(_requestGroup->downloadFinished() || _requestGroup->isHaltRequested()) { return true; - } else if(checkPoint.difference(global::wallclock) >= wait) { - engine->addCommand(nextCommand); - nextCommand = 0; + } else if(_checkPoint.difference(global::wallclock) >= _wait) { + _engine->addCommand(_nextCommand); + _nextCommand = 0; return true; } else { - engine->addCommand(this); + _engine->addCommand(this); return false; } } diff --git a/src/SleepCommand.h b/src/SleepCommand.h index ccf34fe1..cf03dc42 100644 --- a/src/SleepCommand.h +++ b/src/SleepCommand.h @@ -45,11 +45,11 @@ class RequestGroup; class SleepCommand:public Command { private: - DownloadEngine* engine; + DownloadEngine* _engine; RequestGroup* _requestGroup; - Command* nextCommand; - time_t wait; - Timer checkPoint; + Command* _nextCommand; + time_t _wait; + Timer _checkPoint; public: SleepCommand(cuid_t cuid, DownloadEngine* e, RequestGroup* requestGroup, Command* nextCommand, time_t wait); diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc index 38829411..682d0af1 100644 --- a/src/TrackerWatcherCommand.cc +++ b/src/TrackerWatcherCommand.cc @@ -72,7 +72,7 @@ TrackerWatcherCommand::TrackerWatcherCommand (cuid_t cuid, RequestGroup* requestGroup, DownloadEngine* e): Command(cuid), _requestGroup(requestGroup), - e(e) + _e(e) { _requestGroup->increaseNumCommand(); } @@ -91,7 +91,7 @@ bool TrackerWatcherCommand::execute() { return true; } else { _trackerRequestGroup->setForceHaltRequested(true); - e->addCommand(this); + _e->addCommand(this); return false; } } @@ -106,13 +106,13 @@ bool TrackerWatcherCommand::execute() { if(!_trackerRequestGroup.isNull()) { std::vector commands; try { - _trackerRequestGroup->createInitialCommand(commands, e); + _trackerRequestGroup->createInitialCommand(commands, _e); } catch(RecoverableException& ex) { getLogger()->error(EX_EXCEPTION_CAUGHT, ex); std::for_each(commands.begin(), commands.end(), Deleter()); commands.clear(); } - e->addCommand(commands); + _e->addCommand(commands); if(getLogger()->debug()) { getLogger()->debug("added tracker request command"); } @@ -140,7 +140,7 @@ bool TrackerWatcherCommand::execute() { _btAnnounce->resetAnnounce(); } } - e->addCommand(this); + _e->addCommand(this); return false; } @@ -173,13 +173,13 @@ void TrackerWatcherCommand::processTrackerResponse if(peer.isNull()) { break; } - peer->usedBy(e->newCUID()); + peer->usedBy(_e->newCUID()); PeerInitiateConnectionCommand* command = new PeerInitiateConnectionCommand - (peer->usedBy(), _requestGroup, peer, e, _btRuntime); + (peer->usedBy(), _requestGroup, peer, _e, _btRuntime); command->setPeerStorage(_peerStorage); command->setPieceStorage(_pieceStorage); - e->addCommand(command); + _e->addCommand(command); if(getLogger()->debug()) { getLogger()->debug("CUID#%s - Adding new command CUID#%s", util::itos(getCuid()).c_str(), diff --git a/src/TrackerWatcherCommand.h b/src/TrackerWatcherCommand.h index 5c2ec716..9a2db32b 100644 --- a/src/TrackerWatcherCommand.h +++ b/src/TrackerWatcherCommand.h @@ -53,7 +53,7 @@ class TrackerWatcherCommand : public Command private: RequestGroup* _requestGroup; - DownloadEngine* e; + DownloadEngine* _e; SharedHandle _peerStorage;