diff --git a/ChangeLog b/ChangeLog index 492eb9ce..67d8893e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-07-05 Tatsuhiro Tsujikawa + + Committed missing BtStopDownloadCommand.{cc,h} + * src/BtStopDownloadCommand.cc + * src/BtStopDownloadCommand.h + 2009-07-05 Tatsuhiro Tsujikawa Added --bt-stop-timeout=SEC option. This function stops BitTorrent diff --git a/src/BtStopDownloadCommand.cc b/src/BtStopDownloadCommand.cc new file mode 100644 index 00000000..b61f226c --- /dev/null +++ b/src/BtStopDownloadCommand.cc @@ -0,0 +1,82 @@ +/* */ +#include "BtStopDownloadCommand.h" +#include "PieceStorage.h" +#include "PeerStorage.h" +#include "RequestGroup.h" +#include "BtRuntime.h" +#include "Peer.h" +#include "DownloadContext.h" +#include "Logger.h" + +namespace aria2 { + +BtStopDownloadCommand::BtStopDownloadCommand +(int32_t cuid, + RequestGroup* requestGroup, + DownloadEngine* e, + time_t timeout): + TimeBasedCommand(cuid, e, 1), + _requestGroup(requestGroup), + _timeout(timeout) +{} + +void BtStopDownloadCommand::preProcess() +{ + if(_btRuntime->isHalt() || _pieceStorage->downloadFinished()) { + _exit = true; + } + if(_checkPoint.elapsed(_timeout)) { + logger->notice("GID#%d Stop downloading torrent due to" + " --bt-stop-timeout option.", _requestGroup->getGID()); + _requestGroup->setHaltRequested(true); + _exit = true; + } +} + +void BtStopDownloadCommand::process() +{ + if(_requestGroup->calculateStat().getDownloadSpeed() == 0) { + std::deque > activePeers; + _peerStorage->getActivePeers(activePeers); + if(countSeeder(activePeers.begin(), activePeers.end()) != 0) { + _checkPoint.reset(); + } + } else { + _checkPoint.reset(); + } +} + +} // namespace aria2 diff --git a/src/BtStopDownloadCommand.h b/src/BtStopDownloadCommand.h new file mode 100644 index 00000000..c5f7d99b --- /dev/null +++ b/src/BtStopDownloadCommand.h @@ -0,0 +1,92 @@ +/* */ +#ifndef _D_BT_STOP_DOWNLOAD_COMMAND_H_ +#define _D_BT_STOP_DOWNLOAD_COMMAND_H_ + +#include "TimeBasedCommand.h" +#include "SharedHandle.h" + +namespace aria2 { + +class RequestGroup; +class PieceStorage; +class PeerStorage; +class BtRuntime; + +// Stop downloading torrent if in consecutive _timeout seconds, +// download speed is zero and the number of seeder is 0. +class BtStopDownloadCommand:public TimeBasedCommand { +private: + RequestGroup* _requestGroup; + + time_t _timeout; + + Time _checkPoint; + + SharedHandle _btRuntime; + + SharedHandle _peerStorage; + + SharedHandle _pieceStorage; +public: + BtStopDownloadCommand + (int32_t cuid, + RequestGroup* requestGroup, + DownloadEngine* e, + time_t timeout); + + virtual void preProcess(); + + virtual void process(); + + void setBtRuntime(const SharedHandle& btRuntime) + { + _btRuntime = btRuntime; + } + + void setPieceStorage(const SharedHandle& pieceStorage) + { + _pieceStorage = pieceStorage; + } + + void setPeerStorage(const SharedHandle& peerStorage) + { + _peerStorage = peerStorage; + } +}; + +} // namespace aria2 + +#endif // _D_BT_STOP_DOWNLOAD_COMMAND_H_