diff --git a/ChangeLog b/ChangeLog index 939d90f5..492eb9ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2009-07-05 Tatsuhiro Tsujikawa + + Added --bt-stop-timeout=SEC option. This function stops BitTorrent + download if the download speed is 0 and the number of seeder is 0 + in consecutive SEC seconds. By default, this function is disabled. + * src/BtSetup.cc + * src/Makefile.am + * src/OptionHandlerFactory.cc + * src/prefs.cc + * src/prefs.h + * src/usage_text.h + 2009-07-05 Tatsuhiro Tsujikawa Removed the call to DiskAdaptor::onDownloadComplete() from diff --git a/src/BtSetup.cc b/src/BtSetup.cc index ea339780..2f242548 100644 --- a/src/BtSetup.cc +++ b/src/BtSetup.cc @@ -59,6 +59,7 @@ #include "BtAnnounce.h" #include "BtRuntime.h" #include "bittorrent_helper.h" +#include "BtStopDownloadCommand.h" namespace aria2 { @@ -158,7 +159,15 @@ void BtSetup::setup(std::deque& commands, delete listenCommand; } } - + time_t btStopTimeout = option->getAsInt(PREF_BT_STOP_TIMEOUT); + if(btStopTimeout > 0) { + BtStopDownloadCommand* stopDownloadCommand = + new BtStopDownloadCommand(e->newCUID(), requestGroup, e, btStopTimeout); + stopDownloadCommand->setBtRuntime(btRuntime); + stopDownloadCommand->setPieceStorage(pieceStorage); + stopDownloadCommand->setPeerStorage(peerStorage); + commands.push_back(stopDownloadCommand); + } btRuntime->setReady(true); } diff --git a/src/Makefile.am b/src/Makefile.am index a0ad4423..993e9331 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -434,7 +434,8 @@ SRCS += PeerMessageUtil.cc PeerMessageUtil.h\ IndexBtMessageValidator.h\ ExtensionMessageRegistry.h\ bencode.cc bencode.h\ - bittorrent_helper.cc bittorrent_helper.h + bittorrent_helper.cc bittorrent_helper.h\ + BtStopDownloadCommand.cc BtStopDownloadCommand.h endif # ENABLE_BITTORRENT if ENABLE_METALINK diff --git a/src/Makefile.in b/src/Makefile.in index 60f7cb27..00806a3a 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -230,7 +230,8 @@ bin_PROGRAMS = aria2c$(EXEEXT) @ENABLE_BITTORRENT_TRUE@ IndexBtMessageValidator.h\ @ENABLE_BITTORRENT_TRUE@ ExtensionMessageRegistry.h\ @ENABLE_BITTORRENT_TRUE@ bencode.cc bencode.h\ -@ENABLE_BITTORRENT_TRUE@ bittorrent_helper.cc bittorrent_helper.h +@ENABLE_BITTORRENT_TRUE@ bittorrent_helper.cc bittorrent_helper.h\ +@ENABLE_BITTORRENT_TRUE@ BtStopDownloadCommand.cc BtStopDownloadCommand.h @ENABLE_METALINK_TRUE@am__append_14 = Metalinker.cc Metalinker.h\ @ENABLE_METALINK_TRUE@ MetalinkEntry.cc MetalinkEntry.h\ @@ -562,7 +563,8 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \ ZeroBtMessage.h RangeBtMessageValidator.h \ IndexBtMessageValidator.h ExtensionMessageRegistry.h \ bencode.cc bencode.h bittorrent_helper.cc bittorrent_helper.h \ - Metalinker.cc Metalinker.h MetalinkEntry.cc MetalinkEntry.h \ + BtStopDownloadCommand.cc BtStopDownloadCommand.h Metalinker.cc \ + Metalinker.h MetalinkEntry.cc MetalinkEntry.h \ MetalinkResource.cc MetalinkResource.h MetalinkProcessor.h \ MetalinkParserController.cc MetalinkParserController.h \ MetalinkParserStateMachine.cc MetalinkParserStateMachine.h \ @@ -731,7 +733,8 @@ am__objects_6 = @ENABLE_BITTORRENT_TRUE@ IndexBtMessage.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ ZeroBtMessage.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ bencode.$(OBJEXT) \ -@ENABLE_BITTORRENT_TRUE@ bittorrent_helper.$(OBJEXT) +@ENABLE_BITTORRENT_TRUE@ bittorrent_helper.$(OBJEXT) \ +@ENABLE_BITTORRENT_TRUE@ BtStopDownloadCommand.$(OBJEXT) @ENABLE_METALINK_TRUE@am__objects_14 = Metalinker.$(OBJEXT) \ @ENABLE_METALINK_TRUE@ MetalinkEntry.$(OBJEXT) \ @ENABLE_METALINK_TRUE@ MetalinkResource.$(OBJEXT) \ @@ -1320,6 +1323,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtRequestMessage.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtSeederStateChoke.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtSetup.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtStopDownloadCommand.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtSuggestPieceMessage.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtUnchokeMessage.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ByteArrayDiskWriter.Po@am__quote@ diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index 21e6acbd..7f076e76 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -988,6 +988,15 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() op->addTag(TAG_BITTORRENT); handlers.push_back(op); } + { + SharedHandle op(new NumberOptionHandler + (PREF_BT_STOP_TIMEOUT, + TEXT_BT_STOP_TIMEOUT, + "0", + 0)); + op->addTag(TAG_BITTORRENT); + handlers.push_back(op); + } { SharedHandle op(new NumberOptionHandler (PREF_BT_TIMEOUT, diff --git a/src/prefs.cc b/src/prefs.cc index 08a985c0..6d732985 100644 --- a/src/prefs.cc +++ b/src/prefs.cc @@ -303,6 +303,8 @@ const std::string PREF_BT_EXTERNAL_IP("bt-external-ip"); const std::string PREF_INDEX_OUT("index-out"); // values: 1*digit const std::string PREF_BT_TRACKER_INTERVAL("bt-tracker-interval"); +// values: 1*digit +const std::string PREF_BT_STOP_TIMEOUT("bt-stop-timeout"); /** * Metalink related preferences diff --git a/src/prefs.h b/src/prefs.h index 73f0846a..17c70727 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -307,6 +307,8 @@ extern const std::string PREF_BT_EXTERNAL_IP; extern const std::string PREF_INDEX_OUT; // values: 1*digit extern const std::string PREF_BT_TRACKER_INTERVAL; +// values: 1*digit +extern const std::string PREF_BT_STOP_TIMEOUT; /** * Metalink related preferences diff --git a/src/usage_text.h b/src/usage_text.h index 4b0eb6d9..399144c1 100644 --- a/src/usage_text.h +++ b/src/usage_text.h @@ -558,3 +558,7 @@ _(" --on-download-stop=COMMAND Set the command to be executed when download\n" " option is not executed.\n"\ " See --on-download-start option for the\n"\ " requirement of COMMAND.") +#define TEXT_BT_STOP_TIMEOUT \ +_(" --bt-stop-timteout=SEC Stop BitTorrent download if download speed is 0\n"\ + " and the number of seeder is 0 in consecutive NUM\n"\ + " seconds. If 0 is given, this feature is disabled.")