mirror of https://github.com/aria2/aria2
2010-06-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
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.hpull/1/head
parent
d4dfb6c4a8
commit
f114c89096
22
ChangeLog
22
ChangeLog
|
@ -1,3 +1,25 @@
|
||||||
|
2010-06-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
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 <t-tujikawa@users.sourceforge.net>
|
2010-06-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Made protected member variable private. Added accessor funcs.
|
Made protected member variable private. Added accessor funcs.
|
||||||
|
|
|
@ -66,8 +66,8 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand
|
||||||
:
|
:
|
||||||
Command(cuid),
|
Command(cuid),
|
||||||
_requestGroup(requestGroup),
|
_requestGroup(requestGroup),
|
||||||
interval(interval),
|
_interval(interval),
|
||||||
e(e),
|
_e(e),
|
||||||
_numNewConnection(5)
|
_numNewConnection(5)
|
||||||
{
|
{
|
||||||
_requestGroup->increaseNumCommand();
|
_requestGroup->increaseNumCommand();
|
||||||
|
@ -82,8 +82,8 @@ bool ActivePeerConnectionCommand::execute() {
|
||||||
if(_btRuntime->isHalt()) {
|
if(_btRuntime->isHalt()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(checkPoint.difference(global::wallclock) >= interval) {
|
if(_checkPoint.difference(global::wallclock) >= _interval) {
|
||||||
checkPoint = global::wallclock;
|
_checkPoint = global::wallclock;
|
||||||
TransferStat tstat = _requestGroup->calculateStat();
|
TransferStat tstat = _requestGroup->calculateStat();
|
||||||
const unsigned int maxDownloadLimit =
|
const unsigned int maxDownloadLimit =
|
||||||
_requestGroup->getMaxDownloadSpeedLimit();
|
_requestGroup->getMaxDownloadSpeedLimit();
|
||||||
|
@ -129,7 +129,7 @@ bool ActivePeerConnectionCommand::execute() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e->addCommand(this);
|
_e->addCommand(this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,13 +138,13 @@ void ActivePeerConnectionCommand::connectToPeer(const SharedHandle<Peer>& peer)
|
||||||
if(peer.isNull()) {
|
if(peer.isNull()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
peer->usedBy(e->newCUID());
|
peer->usedBy(_e->newCUID());
|
||||||
PeerInitiateConnectionCommand* command =
|
PeerInitiateConnectionCommand* command =
|
||||||
new PeerInitiateConnectionCommand(peer->usedBy(), _requestGroup, peer, e,
|
new PeerInitiateConnectionCommand(peer->usedBy(), _requestGroup, peer, _e,
|
||||||
_btRuntime);
|
_btRuntime);
|
||||||
command->setPeerStorage(_peerStorage);
|
command->setPeerStorage(_peerStorage);
|
||||||
command->setPieceStorage(_pieceStorage);
|
command->setPieceStorage(_pieceStorage);
|
||||||
e->addCommand(command);
|
_e->addCommand(command);
|
||||||
if(getLogger()->info()) {
|
if(getLogger()->info()) {
|
||||||
getLogger()->info(MSG_CONNECTING_TO_PEER,
|
getLogger()->info(MSG_CONNECTING_TO_PEER,
|
||||||
util::itos(getCuid()).c_str(), peer->ipaddr.c_str());
|
util::itos(getCuid()).c_str(), peer->ipaddr.c_str());
|
||||||
|
|
|
@ -57,9 +57,9 @@ private:
|
||||||
SharedHandle<PeerStorage> _peerStorage;
|
SharedHandle<PeerStorage> _peerStorage;
|
||||||
SharedHandle<BtAnnounce> _btAnnounce;
|
SharedHandle<BtAnnounce> _btAnnounce;
|
||||||
|
|
||||||
time_t interval; // UNIT: sec
|
time_t _interval; // UNIT: sec
|
||||||
DownloadEngine* e;
|
DownloadEngine* _e;
|
||||||
Timer checkPoint;
|
Timer _checkPoint;
|
||||||
unsigned int _numNewConnection; // the number of the connection to establish.
|
unsigned int _numNewConnection; // the number of the connection to establish.
|
||||||
public:
|
public:
|
||||||
ActivePeerConnectionCommand(cuid_t cuid,
|
ActivePeerConnectionCommand(cuid_t cuid,
|
||||||
|
|
|
@ -56,14 +56,14 @@ CheckIntegrityDispatcherCommand::CheckIntegrityDispatcherCommand
|
||||||
Command* CheckIntegrityDispatcherCommand::createCommand
|
Command* CheckIntegrityDispatcherCommand::createCommand
|
||||||
(const SharedHandle<CheckIntegrityEntry>& entry)
|
(const SharedHandle<CheckIntegrityEntry>& entry)
|
||||||
{
|
{
|
||||||
cuid_t newCUID = _e->newCUID();
|
cuid_t newCUID = getDownloadEngine()->newCUID();
|
||||||
if(getLogger()->info()) {
|
if(getLogger()->info()) {
|
||||||
getLogger()->info("CUID#%s - Dispatching CheckIntegrityCommand CUID#%s.",
|
getLogger()->info("CUID#%s - Dispatching CheckIntegrityCommand CUID#%s.",
|
||||||
util::itos(getCuid()).c_str(),
|
util::itos(getCuid()).c_str(),
|
||||||
util::itos(newCUID).c_str());
|
util::itos(newCUID).c_str());
|
||||||
}
|
}
|
||||||
return new CheckIntegrityCommand
|
return new CheckIntegrityCommand
|
||||||
(newCUID, entry->getRequestGroup(), _e, entry);
|
(newCUID, entry->getRequestGroup(), getDownloadEngine(), entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -55,9 +55,9 @@ class AsyncNameResolver;
|
||||||
#endif // ENABLE_ASYNC_DNS
|
#endif // ENABLE_ASYNC_DNS
|
||||||
|
|
||||||
class DHTEntryPointNameResolveCommand:public Command {
|
class DHTEntryPointNameResolveCommand:public Command {
|
||||||
protected:
|
|
||||||
DownloadEngine* _e;
|
|
||||||
private:
|
private:
|
||||||
|
DownloadEngine* _e;
|
||||||
|
|
||||||
#ifdef ENABLE_ASYNC_DNS
|
#ifdef ENABLE_ASYNC_DNS
|
||||||
SharedHandle<AsyncNameResolver> _resolver;
|
SharedHandle<AsyncNameResolver> _resolver;
|
||||||
#endif // ENABLE_ASYNC_DNS
|
#endif // ENABLE_ASYNC_DNS
|
||||||
|
|
|
@ -47,14 +47,12 @@ class DownloadEngine;
|
||||||
class SocketCore;
|
class SocketCore;
|
||||||
|
|
||||||
class DHTInteractionCommand:public Command {
|
class DHTInteractionCommand:public Command {
|
||||||
protected:
|
|
||||||
DownloadEngine* _e;
|
|
||||||
private:
|
private:
|
||||||
|
DownloadEngine* _e;
|
||||||
SharedHandle<DHTMessageDispatcher> _dispatcher;
|
SharedHandle<DHTMessageDispatcher> _dispatcher;
|
||||||
SharedHandle<DHTMessageReceiver> _receiver;
|
SharedHandle<DHTMessageReceiver> _receiver;
|
||||||
SharedHandle<DHTTaskQueue> _taskQueue;
|
SharedHandle<DHTTaskQueue> _taskQueue;
|
||||||
SharedHandle<SocketCore> _readCheckSocket;
|
SharedHandle<SocketCore> _readCheckSocket;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DHTInteractionCommand(cuid_t cuid, DownloadEngine* e);
|
DHTInteractionCommand(cuid_t cuid, DownloadEngine* e);
|
||||||
|
|
||||||
|
|
|
@ -53,13 +53,14 @@ FileAllocationDispatcherCommand::FileAllocationDispatcherCommand
|
||||||
Command* FileAllocationDispatcherCommand::createCommand
|
Command* FileAllocationDispatcherCommand::createCommand
|
||||||
(const SharedHandle<FileAllocationEntry>& entry)
|
(const SharedHandle<FileAllocationEntry>& entry)
|
||||||
{
|
{
|
||||||
cuid_t newCUID = _e->newCUID();
|
cuid_t newCUID = getDownloadEngine()->newCUID();
|
||||||
if(getLogger()->info()) {
|
if(getLogger()->info()) {
|
||||||
getLogger()->info(MSG_FILE_ALLOCATION_DISPATCH,
|
getLogger()->info(MSG_FILE_ALLOCATION_DISPATCH,
|
||||||
util::itos(newCUID).c_str());
|
util::itos(newCUID).c_str());
|
||||||
}
|
}
|
||||||
FileAllocationCommand* command =
|
FileAllocationCommand* command =
|
||||||
new FileAllocationCommand(newCUID, entry->getRequestGroup(), _e, entry);
|
new FileAllocationCommand(newCUID, entry->getRequestGroup(),
|
||||||
|
getDownloadEngine(), entry);
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,9 +55,8 @@ private:
|
||||||
LpdReceiveMessageCommand
|
LpdReceiveMessageCommand
|
||||||
(cuid_t cuid, const SharedHandle<LpdMessageReceiver>& receiver,
|
(cuid_t cuid, const SharedHandle<LpdMessageReceiver>& receiver,
|
||||||
DownloadEngine* e);
|
DownloadEngine* e);
|
||||||
protected:
|
|
||||||
DownloadEngine* _e;
|
|
||||||
|
|
||||||
|
DownloadEngine* _e;
|
||||||
public:
|
public:
|
||||||
virtual ~LpdReceiveMessageCommand();
|
virtual ~LpdReceiveMessageCommand();
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace aria2 {
|
||||||
PeerChokeCommand::PeerChokeCommand(cuid_t cuid,
|
PeerChokeCommand::PeerChokeCommand(cuid_t cuid,
|
||||||
DownloadEngine* e):
|
DownloadEngine* e):
|
||||||
Command(cuid),
|
Command(cuid),
|
||||||
e(e) {}
|
_e(e) {}
|
||||||
|
|
||||||
PeerChokeCommand::~PeerChokeCommand() {}
|
PeerChokeCommand::~PeerChokeCommand() {}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ bool PeerChokeCommand::execute() {
|
||||||
if(_peerStorage->chokeRoundIntervalElapsed()) {
|
if(_peerStorage->chokeRoundIntervalElapsed()) {
|
||||||
_peerStorage->executeChoke();
|
_peerStorage->executeChoke();
|
||||||
}
|
}
|
||||||
e->addCommand(this);
|
_e->addCommand(this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ class PeerStorage;
|
||||||
|
|
||||||
class PeerChokeCommand : public Command {
|
class PeerChokeCommand : public Command {
|
||||||
private:
|
private:
|
||||||
DownloadEngine* e;
|
DownloadEngine* _e;
|
||||||
|
|
||||||
SharedHandle<PeerStorage> _peerStorage;
|
SharedHandle<PeerStorage> _peerStorage;
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ PeerListenCommand* PeerListenCommand::__instance = 0;
|
||||||
|
|
||||||
PeerListenCommand::PeerListenCommand(cuid_t cuid, DownloadEngine* e):
|
PeerListenCommand::PeerListenCommand(cuid_t cuid, DownloadEngine* e):
|
||||||
Command(cuid),
|
Command(cuid),
|
||||||
e(e),
|
_e(e),
|
||||||
_lowestSpeedLimit(20*1024)
|
_lowestSpeedLimit(20*1024)
|
||||||
{
|
{
|
||||||
++__numInstance;
|
++__numInstance;
|
||||||
|
@ -73,7 +73,7 @@ PeerListenCommand::~PeerListenCommand()
|
||||||
|
|
||||||
bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq)
|
bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq)
|
||||||
{
|
{
|
||||||
socket.reset(new SocketCore());
|
_socket.reset(new SocketCore());
|
||||||
|
|
||||||
std::vector<int32_t> randPorts = seq.flush();
|
std::vector<int32_t> randPorts = seq.flush();
|
||||||
std::random_shuffle(randPorts.begin(), randPorts.end(),
|
std::random_shuffle(randPorts.begin(), randPorts.end(),
|
||||||
|
@ -86,15 +86,15 @@ bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq)
|
||||||
}
|
}
|
||||||
port = (*portItr);
|
port = (*portItr);
|
||||||
try {
|
try {
|
||||||
socket->bind(port);
|
_socket->bind(port);
|
||||||
socket->beginListen();
|
_socket->beginListen();
|
||||||
socket->setNonBlockingMode();
|
_socket->setNonBlockingMode();
|
||||||
getLogger()->notice("BitTorrent: listening to port %d", port);
|
getLogger()->notice("BitTorrent: listening to port %d", port);
|
||||||
return true;
|
return true;
|
||||||
} catch(RecoverableException& ex) {
|
} catch(RecoverableException& ex) {
|
||||||
getLogger()->error(MSG_BIND_FAILURE, ex,
|
getLogger()->error(MSG_BIND_FAILURE, ex,
|
||||||
util::itos(getCuid()).c_str(), port);
|
util::itos(getCuid()).c_str(), port);
|
||||||
socket->closeConnection();
|
_socket->closeConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -102,33 +102,33 @@ bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq)
|
||||||
|
|
||||||
uint16_t PeerListenCommand::getPort() const
|
uint16_t PeerListenCommand::getPort() const
|
||||||
{
|
{
|
||||||
if(socket.isNull()) {
|
if(_socket.isNull()) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
std::pair<std::string, uint16_t> addr;
|
std::pair<std::string, uint16_t> addr;
|
||||||
socket->getAddrInfo(addr);
|
_socket->getAddrInfo(addr);
|
||||||
return addr.second;
|
return addr.second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerListenCommand::execute() {
|
bool PeerListenCommand::execute() {
|
||||||
if(e->isHaltRequested() || e->getRequestGroupMan()->downloadFinished()) {
|
if(_e->isHaltRequested() || _e->getRequestGroupMan()->downloadFinished()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for(int i = 0; i < 3 && socket->isReadable(0); ++i) {
|
for(int i = 0; i < 3 && _socket->isReadable(0); ++i) {
|
||||||
SocketHandle peerSocket;
|
SocketHandle peerSocket;
|
||||||
try {
|
try {
|
||||||
peerSocket.reset(socket->acceptConnection());
|
peerSocket.reset(_socket->acceptConnection());
|
||||||
std::pair<std::string, uint16_t> peerInfo;
|
std::pair<std::string, uint16_t> peerInfo;
|
||||||
peerSocket->getPeerInfo(peerInfo);
|
peerSocket->getPeerInfo(peerInfo);
|
||||||
|
|
||||||
peerSocket->setNonBlockingMode();
|
peerSocket->setNonBlockingMode();
|
||||||
|
|
||||||
SharedHandle<Peer> peer(new Peer(peerInfo.first, peerInfo.second, true));
|
SharedHandle<Peer> peer(new Peer(peerInfo.first, peerInfo.second, true));
|
||||||
cuid_t cuid = e->newCUID();
|
cuid_t cuid = _e->newCUID();
|
||||||
Command* command =
|
Command* command =
|
||||||
new ReceiverMSEHandshakeCommand(cuid, peer, e, peerSocket);
|
new ReceiverMSEHandshakeCommand(cuid, peer, _e, peerSocket);
|
||||||
e->addCommand(command);
|
_e->addCommand(command);
|
||||||
if(getLogger()->debug()) {
|
if(getLogger()->debug()) {
|
||||||
getLogger()->debug("Accepted the connection from %s:%u.",
|
getLogger()->debug("Accepted the connection from %s:%u.",
|
||||||
peer->ipaddr.c_str(),
|
peer->ipaddr.c_str(),
|
||||||
|
@ -140,7 +140,7 @@ bool PeerListenCommand::execute() {
|
||||||
getLogger()->debug(MSG_ACCEPT_FAILURE, ex, util::itos(getCuid()).c_str());
|
getLogger()->debug(MSG_ACCEPT_FAILURE, ex, util::itos(getCuid()).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e->addCommand(this);
|
_e->addCommand(this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,8 @@ class SocketCore;
|
||||||
|
|
||||||
class PeerListenCommand : public Command {
|
class PeerListenCommand : public Command {
|
||||||
private:
|
private:
|
||||||
DownloadEngine* e;
|
DownloadEngine* _e;
|
||||||
SharedHandle<SocketCore> socket;
|
SharedHandle<SocketCore> _socket;
|
||||||
unsigned int _lowestSpeedLimit;
|
unsigned int _lowestSpeedLimit;
|
||||||
|
|
||||||
static unsigned int __numInstance;
|
static unsigned int __numInstance;
|
||||||
|
|
|
@ -55,9 +55,9 @@ SeedCheckCommand::SeedCheckCommand
|
||||||
const SharedHandle<SeedCriteria>& seedCriteria)
|
const SharedHandle<SeedCriteria>& seedCriteria)
|
||||||
:Command(cuid),
|
:Command(cuid),
|
||||||
_requestGroup(requestGroup),
|
_requestGroup(requestGroup),
|
||||||
e(e),
|
_e(e),
|
||||||
seedCriteria(seedCriteria),
|
_seedCriteria(seedCriteria),
|
||||||
checkStarted(false)
|
_checkStarted(false)
|
||||||
{
|
{
|
||||||
setStatusRealtime();
|
setStatusRealtime();
|
||||||
_requestGroup->increaseNumCommand();
|
_requestGroup->increaseNumCommand();
|
||||||
|
@ -72,29 +72,29 @@ bool SeedCheckCommand::execute() {
|
||||||
if(_btRuntime->isHalt()) {
|
if(_btRuntime->isHalt()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(!seedCriteria.get()) {
|
if(!_seedCriteria.get()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!checkStarted) {
|
if(!_checkStarted) {
|
||||||
if(_pieceStorage->downloadFinished()) {
|
if(_pieceStorage->downloadFinished()) {
|
||||||
checkStarted = true;
|
_checkStarted = true;
|
||||||
seedCriteria->reset();
|
_seedCriteria->reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(checkStarted) {
|
if(_checkStarted) {
|
||||||
if(seedCriteria->evaluate()) {
|
if(_seedCriteria->evaluate()) {
|
||||||
getLogger()->notice(MSG_SEEDING_END);
|
getLogger()->notice(MSG_SEEDING_END);
|
||||||
_btRuntime->setHalt(true);
|
_btRuntime->setHalt(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e->addCommand(this);
|
_e->addCommand(this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SeedCheckCommand::setSeedCriteria
|
void SeedCheckCommand::setSeedCriteria
|
||||||
(const SharedHandle<SeedCriteria>& seedCriteria)
|
(const SharedHandle<SeedCriteria>& seedCriteria)
|
||||||
{
|
{
|
||||||
this->seedCriteria = seedCriteria;
|
_seedCriteria = seedCriteria;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SeedCheckCommand::setBtRuntime(const SharedHandle<BtRuntime>& btRuntime)
|
void SeedCheckCommand::setBtRuntime(const SharedHandle<BtRuntime>& btRuntime)
|
||||||
|
|
|
@ -50,11 +50,11 @@ class SeedCheckCommand : public Command
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
RequestGroup* _requestGroup;
|
RequestGroup* _requestGroup;
|
||||||
DownloadEngine* e;
|
DownloadEngine* _e;
|
||||||
SharedHandle<PieceStorage> _pieceStorage;
|
SharedHandle<PieceStorage> _pieceStorage;
|
||||||
SharedHandle<BtRuntime> _btRuntime;
|
SharedHandle<BtRuntime> _btRuntime;
|
||||||
SharedHandle<SeedCriteria> seedCriteria;
|
SharedHandle<SeedCriteria> _seedCriteria;
|
||||||
bool checkStarted;
|
bool _checkStarted;
|
||||||
public:
|
public:
|
||||||
SeedCheckCommand(cuid_t cuid,
|
SeedCheckCommand(cuid_t cuid,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
|
|
|
@ -47,10 +47,15 @@ class DownloadEngine;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class SequentialDispatcherCommand : public Command {
|
class SequentialDispatcherCommand : public Command {
|
||||||
protected:
|
private:
|
||||||
SharedHandle<SequentialPicker<T> > _picker;
|
SharedHandle<SequentialPicker<T> > _picker;
|
||||||
|
|
||||||
DownloadEngine* _e;
|
DownloadEngine* _e;
|
||||||
|
protected:
|
||||||
|
DownloadEngine* getDownloadEngine() const
|
||||||
|
{
|
||||||
|
return _e;
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
SequentialDispatcherCommand(cuid_t cuid,
|
SequentialDispatcherCommand(cuid_t cuid,
|
||||||
const SharedHandle<SequentialPicker<T> >& picker,
|
const SharedHandle<SequentialPicker<T> >& picker,
|
||||||
|
|
|
@ -47,22 +47,22 @@ namespace aria2 {
|
||||||
SleepCommand::SleepCommand(cuid_t cuid, DownloadEngine* e,
|
SleepCommand::SleepCommand(cuid_t cuid, DownloadEngine* e,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
Command* nextCommand, time_t wait):
|
Command* nextCommand, time_t wait):
|
||||||
Command(cuid), engine(e), _requestGroup(requestGroup),
|
Command(cuid), _engine(e), _requestGroup(requestGroup),
|
||||||
nextCommand(nextCommand), wait(wait), checkPoint(global::wallclock) {}
|
_nextCommand(nextCommand), _wait(wait), _checkPoint(global::wallclock) {}
|
||||||
|
|
||||||
SleepCommand::~SleepCommand() {
|
SleepCommand::~SleepCommand() {
|
||||||
delete nextCommand;
|
delete _nextCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SleepCommand::execute() {
|
bool SleepCommand::execute() {
|
||||||
if(_requestGroup->downloadFinished() || _requestGroup->isHaltRequested()) {
|
if(_requestGroup->downloadFinished() || _requestGroup->isHaltRequested()) {
|
||||||
return true;
|
return true;
|
||||||
} else if(checkPoint.difference(global::wallclock) >= wait) {
|
} else if(_checkPoint.difference(global::wallclock) >= _wait) {
|
||||||
engine->addCommand(nextCommand);
|
_engine->addCommand(_nextCommand);
|
||||||
nextCommand = 0;
|
_nextCommand = 0;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
engine->addCommand(this);
|
_engine->addCommand(this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,11 +45,11 @@ class RequestGroup;
|
||||||
|
|
||||||
class SleepCommand:public Command {
|
class SleepCommand:public Command {
|
||||||
private:
|
private:
|
||||||
DownloadEngine* engine;
|
DownloadEngine* _engine;
|
||||||
RequestGroup* _requestGroup;
|
RequestGroup* _requestGroup;
|
||||||
Command* nextCommand;
|
Command* _nextCommand;
|
||||||
time_t wait;
|
time_t _wait;
|
||||||
Timer checkPoint;
|
Timer _checkPoint;
|
||||||
public:
|
public:
|
||||||
SleepCommand(cuid_t cuid, DownloadEngine* e, RequestGroup* requestGroup,
|
SleepCommand(cuid_t cuid, DownloadEngine* e, RequestGroup* requestGroup,
|
||||||
Command* nextCommand, time_t wait);
|
Command* nextCommand, time_t wait);
|
||||||
|
|
|
@ -72,7 +72,7 @@ TrackerWatcherCommand::TrackerWatcherCommand
|
||||||
(cuid_t cuid, RequestGroup* requestGroup, DownloadEngine* e):
|
(cuid_t cuid, RequestGroup* requestGroup, DownloadEngine* e):
|
||||||
Command(cuid),
|
Command(cuid),
|
||||||
_requestGroup(requestGroup),
|
_requestGroup(requestGroup),
|
||||||
e(e)
|
_e(e)
|
||||||
{
|
{
|
||||||
_requestGroup->increaseNumCommand();
|
_requestGroup->increaseNumCommand();
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ bool TrackerWatcherCommand::execute() {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
_trackerRequestGroup->setForceHaltRequested(true);
|
_trackerRequestGroup->setForceHaltRequested(true);
|
||||||
e->addCommand(this);
|
_e->addCommand(this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,13 +106,13 @@ bool TrackerWatcherCommand::execute() {
|
||||||
if(!_trackerRequestGroup.isNull()) {
|
if(!_trackerRequestGroup.isNull()) {
|
||||||
std::vector<Command*> commands;
|
std::vector<Command*> commands;
|
||||||
try {
|
try {
|
||||||
_trackerRequestGroup->createInitialCommand(commands, e);
|
_trackerRequestGroup->createInitialCommand(commands, _e);
|
||||||
} catch(RecoverableException& ex) {
|
} catch(RecoverableException& ex) {
|
||||||
getLogger()->error(EX_EXCEPTION_CAUGHT, ex);
|
getLogger()->error(EX_EXCEPTION_CAUGHT, ex);
|
||||||
std::for_each(commands.begin(), commands.end(), Deleter());
|
std::for_each(commands.begin(), commands.end(), Deleter());
|
||||||
commands.clear();
|
commands.clear();
|
||||||
}
|
}
|
||||||
e->addCommand(commands);
|
_e->addCommand(commands);
|
||||||
if(getLogger()->debug()) {
|
if(getLogger()->debug()) {
|
||||||
getLogger()->debug("added tracker request command");
|
getLogger()->debug("added tracker request command");
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ bool TrackerWatcherCommand::execute() {
|
||||||
_btAnnounce->resetAnnounce();
|
_btAnnounce->resetAnnounce();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e->addCommand(this);
|
_e->addCommand(this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,13 +173,13 @@ void TrackerWatcherCommand::processTrackerResponse
|
||||||
if(peer.isNull()) {
|
if(peer.isNull()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
peer->usedBy(e->newCUID());
|
peer->usedBy(_e->newCUID());
|
||||||
PeerInitiateConnectionCommand* command =
|
PeerInitiateConnectionCommand* command =
|
||||||
new PeerInitiateConnectionCommand
|
new PeerInitiateConnectionCommand
|
||||||
(peer->usedBy(), _requestGroup, peer, e, _btRuntime);
|
(peer->usedBy(), _requestGroup, peer, _e, _btRuntime);
|
||||||
command->setPeerStorage(_peerStorage);
|
command->setPeerStorage(_peerStorage);
|
||||||
command->setPieceStorage(_pieceStorage);
|
command->setPieceStorage(_pieceStorage);
|
||||||
e->addCommand(command);
|
_e->addCommand(command);
|
||||||
if(getLogger()->debug()) {
|
if(getLogger()->debug()) {
|
||||||
getLogger()->debug("CUID#%s - Adding new command CUID#%s",
|
getLogger()->debug("CUID#%s - Adding new command CUID#%s",
|
||||||
util::itos(getCuid()).c_str(),
|
util::itos(getCuid()).c_str(),
|
||||||
|
|
|
@ -53,7 +53,7 @@ class TrackerWatcherCommand : public Command
|
||||||
private:
|
private:
|
||||||
RequestGroup* _requestGroup;
|
RequestGroup* _requestGroup;
|
||||||
|
|
||||||
DownloadEngine* e;
|
DownloadEngine* _e;
|
||||||
|
|
||||||
SharedHandle<PeerStorage> _peerStorage;
|
SharedHandle<PeerStorage> _peerStorage;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue