浏览代码

2008-12-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Added --max-overall-upload-limit option. This option limits the
	overall upload speed.  Stated in help message that the existing
	--max-upload-limit option limits the upload speed per each
	torrent.  Man page is also updated.
	* doc/aria2c.1.txt
	* src/DefaultBtMessageDispatcher.cc
	* src/DefaultBtMessageDispatcher.h
	* src/OptionHandlerFactory.cc
	* src/PeerInteractionCommand.cc
	* src/option_processing.cc
	* src/prefs.cc
	* src/prefs.h
	* src/usage_text.h
Tatsuhiro Tsujikawa 17 年之前
父节点
当前提交
8c1894720f

+ 16 - 0
ChangeLog

@@ -1,3 +1,19 @@
+2008-12-10  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Added --max-overall-upload-limit option. This option limits the
+	overall upload speed.  Stated in help message that the existing
+	--max-upload-limit option limits the upload speed per each
+	torrent.  Man page is also updated.
+	* doc/aria2c.1.txt
+	* src/DefaultBtMessageDispatcher.cc
+	* src/DefaultBtMessageDispatcher.h
+	* src/OptionHandlerFactory.cc
+	* src/PeerInteractionCommand.cc
+	* src/option_processing.cc
+	* src/prefs.cc
+	* src/prefs.h
+	* src/usage_text.h
+
 2008-12-09  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Use BDE instead of Dictionary/List/Data classes.

+ 21 - 4
doc/aria2c.1

@@ -1,11 +1,11 @@
 .\"     Title: aria2c
 .\"    Author: 
 .\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
-.\"      Date: 12/04/2008
+.\"      Date: 12/10/2008
 .\"    Manual: 
 .\"    Source: 
 .\"
-.TH "ARIA2C" "1" "12/04/2008" "" ""
+.TH "ARIA2C" "1" "12/10/2008" "" ""
 .\" disable hyphenation
 .nh
 .\" disable justification (adjust text to left margin only)
@@ -507,14 +507,31 @@ Set TCP port number for BitTorrent downloads\&. Multiple ports can be specified
 Note
 Make sure that the specified ports are open for incoming TCP traffic\&.
 .PP
+\fB\-\-max\-overall\-upload\-limit\fR=SPEED
+.RS 4
+Set max overall upload speed in bytes/sec\&.
+\fI0\fR
+means unrestricted\&. You can append
+\fIK\fR
+or
+\fIM\fR(1K = 1024, 1M = 1024K)\&. To limit the upload speed per torrent, use
+\fB\-\-max\-upload\-limit\fR
+option\&. If non\-zero value is specified,
+\fB\-\-max\-upload\-limit\fR
+option is ignored\&. Default:
+\fI0\fR
+.RE
+.PP
 \fB\-u\fR, \fB\-\-max\-upload\-limit\fR=SPEED
 .RS 4
-Set max upload speed in bytes per sec\&.
+Set max upload speed per each torrent in bytes/sec\&.
 \fI0\fR
 means unrestricted\&. You can append
 \fIK\fR
 or
-\fIM\fR(1K = 1024, 1M = 1024K)\&. Default:
+\fIM\fR(1K = 1024, 1M = 1024K)\&. To limit the overall upload speed, use
+\fB\-\-max\-overall\-upload\-limit\fR
+option\&. Default:
 \fI0\fR
 .RE
 .PP

+ 17 - 2
doc/aria2c.1.html

@@ -1064,12 +1064,27 @@ writes the piece to the appropriate files.</td>
 </div>
 <div class="vlist"><dl>
 <dt>
+<strong>--max-overall-upload-limit</strong>=SPEED
+</dt>
+<dd>
+<p>
+  Set max overall upload speed in bytes/sec.
+  <em>0</em> means unrestricted.
+  You can append <em>K</em> or <em>M</em>(1K = 1024, 1M = 1024K).
+  To limit the upload speed per torrent, use <strong>--max-upload-limit</strong> option.
+  If non-zero value is specified, <strong>--max-upload-limit</strong> option is ignored.
+  Default: <em>0</em>
+</p>
+</dd>
+<dt>
 <strong>-u</strong>, <strong>--max-upload-limit</strong>=SPEED
 </dt>
 <dd>
 <p>
-  Set max upload speed in bytes per sec. <em>0</em> means unrestricted.
+  Set max upload speed per each torrent in bytes/sec.
+  <em>0</em> means unrestricted.
   You can append <em>K</em> or <em>M</em>(1K = 1024, 1M = 1024K).
+  To limit the overall upload speed, use <strong>--max-overall-upload-limit</strong> option.
   Default: <em>0</em>
 </p>
 </dd>
@@ -2031,7 +2046,7 @@ files in the program, then also delete it here.</p></div>
 </div>
 <div id="footer">
 <div id="footer-text">
-Last updated 2008-12-04 01:08:46 JST
+Last updated 2008-12-10 23:03:25 JST
 </div>
 </div>
 </body>

+ 11 - 1
doc/aria2c.1.txt

@@ -366,9 +366,19 @@ BitTorrent Specific Options
 [NOTE]
 Make sure that the specified ports are open for incoming TCP traffic.
 
+*--max-overall-upload-limit*=SPEED::
+  Set max overall upload speed in bytes/sec.
+  '0' means unrestricted.
+  You can append 'K' or 'M'(1K = 1024, 1M = 1024K).
+  To limit the upload speed per torrent, use *--max-upload-limit* option.
+  If non-zero value is specified, *--max-upload-limit* option is ignored.
+  Default: '0'
+
 *-u*, *--max-upload-limit*=SPEED::
-  Set max upload speed in bytes per sec. '0' means unrestricted.
+  Set max upload speed per each torrent in bytes/sec.
+  '0' means unrestricted.
   You can append 'K' or 'M'(1K = 1024, 1M = 1024K).
+  To limit the overall upload speed, use *--max-overall-upload-limit* option.
   Default: '0'
 
 *--peer-id-prefix*=PEERI_ID_PREFIX::

+ 33 - 6
src/DefaultBtMessageDispatcher.cc

@@ -52,12 +52,14 @@
 #include "LogFactory.h"
 #include "Logger.h"
 #include "a2functional.h"
+#include "RequestGroupMan.h"
 
 namespace aria2 {
 
 DefaultBtMessageDispatcher::DefaultBtMessageDispatcher():
   cuid(0),
-  maxUploadSpeedLimit(0),
+  _maxOverallSpeedLimit(0),
+  _maxUploadSpeedLimit(0),
   requestTimeout(0),
   logger(LogFactory::getInstance()) {}
 
@@ -79,16 +81,22 @@ void DefaultBtMessageDispatcher::addMessageToQueue(const BtMessages& btMessages)
   }
 }
 
-
 void DefaultBtMessageDispatcher::sendMessages() {
   BtMessages tempQueue;
   while(!messageQueue.empty()) {
     BtMessageHandle msg = messageQueue.front();
     messageQueue.pop_front();
-    if(maxUploadSpeedLimit > 0 &&
-       msg->isUploading() && !msg->isSendingInProgress()) {
-      TransferStat stat = _peerStorage->calculateStat();
-      if(maxUploadSpeedLimit < stat.getUploadSpeed()) {
+    if(msg->isUploading() && !msg->isSendingInProgress()) {
+      if(// See whether upload speed is exceeding overall limit.
+	 (_maxOverallSpeedLimit > 0 &&
+	  _maxOverallSpeedLimit <
+	  _requestGroupMan->calculateStat().getUploadSpeed()) ||
+	 // See whether uplaod speed is exceeding upload limit for each torrent.
+	 // _maxUploadLimit is ignored when _maxOverallSpeedLimit is specified.
+	 (_maxOverallSpeedLimit == 0 &&
+	  _maxUploadSpeedLimit > 0 &&
+	  _maxUploadSpeedLimit <
+	  _peerStorage->calculateStat().getUploadSpeed())) {
 	tempQueue.push_back(msg);
 	continue;
       }
@@ -457,4 +465,23 @@ void DefaultBtMessageDispatcher::setBtMessageFactory(const WeakHandle<BtMessageF
   this->messageFactory = factory;
 }
 
+void DefaultBtMessageDispatcher::setRequestGroupMan
+(const WeakHandle<RequestGroupMan>& rgman)
+{
+  _requestGroupMan = rgman;
+}
+
+void DefaultBtMessageDispatcher::setMaxUploadSpeedLimit
+(unsigned int maxUploadSpeedLimit)
+{
+  _maxUploadSpeedLimit = maxUploadSpeedLimit;
+}
+
+void DefaultBtMessageDispatcher::setMaxOverallSpeedLimit
+(unsigned int maxOverallSpeedLimit)
+{
+  _maxOverallSpeedLimit = maxOverallSpeedLimit;
+}
+
+
 } // namespace aria2

+ 9 - 4
src/DefaultBtMessageDispatcher.h

@@ -48,6 +48,7 @@ class BtMessageFactory;
 class Peer;
 class Piece;
 class Logger;
+class RequestGroupMan;
 
 class DefaultBtMessageDispatcher : public BtMessageDispatcher {
 private:
@@ -59,7 +60,9 @@ private:
   SharedHandle<PieceStorage> _pieceStorage;
   WeakHandle<BtMessageFactory> messageFactory;
   SharedHandle<Peer> peer;
-  unsigned int maxUploadSpeedLimit;
+  WeakHandle<RequestGroupMan> _requestGroupMan;
+  unsigned int _maxOverallSpeedLimit;
+  unsigned int _maxUploadSpeedLimit;
   time_t requestTimeout;
   Logger* logger;
 public:
@@ -117,13 +120,15 @@ public:
 
   void setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory);
 
+  void setRequestGroupMan(const WeakHandle<RequestGroupMan>& rgman);
+
   void setCuid(int32_t cuid) {
     this->cuid = cuid;
   }
 
-  void setMaxUploadSpeedLimit(unsigned int maxUploadSpeedLimit) {
-    this->maxUploadSpeedLimit = maxUploadSpeedLimit;
-  }
+  void setMaxUploadSpeedLimit(unsigned int maxUploadSpeedLimit);
+
+  void setMaxOverallSpeedLimit(unsigned int maxOverallSpeedLimit);
 
   void setRequestTimeout(time_t requestTimeout) {
     this->requestTimeout = requestTimeout;

+ 10 - 0
src/OptionHandlerFactory.cc

@@ -824,6 +824,16 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
     op->addTag(TAG_BITTORRENT);
     handlers.push_back(op);
   }
+  {
+    SharedHandle<OptionHandler> op(new UnitNumberOptionHandler
+				   (PREF_MAX_OVERALL_UPLOAD_LIMIT,
+				    TEXT_MAX_OVERALL_UPLOAD_LIMIT,
+				    "0",
+				    0));
+    op->addTag(TAG_BASIC);
+    op->addTag(TAG_BITTORRENT);
+    handlers.push_back(op);
+  }
   {
     SharedHandle<OptionHandler> op(new UnitNumberOptionHandler
 				   (PREF_MAX_UPLOAD_LIMIT,

+ 4 - 0
src/PeerInteractionCommand.cc

@@ -68,6 +68,7 @@
 #include "BtAnnounce.h"
 #include "BtProgressInfoFile.h"
 #include "DefaultExtensionMessageFactory.h"
+#include "RequestGroupMan.h"
 
 namespace aria2 {
 
@@ -133,8 +134,11 @@ PeerInteractionCommand::PeerInteractionCommand
   dispatcher->setPeerStorage(peerStorage);
   dispatcher->setMaxUploadSpeedLimit
     (e->option->getAsInt(PREF_MAX_UPLOAD_LIMIT));
+  dispatcher->setMaxOverallSpeedLimit
+    (e->option->getAsInt(PREF_MAX_OVERALL_UPLOAD_LIMIT));
   dispatcher->setRequestTimeout(e->option->getAsInt(PREF_BT_REQUEST_TIMEOUT));
   dispatcher->setBtMessageFactory(factory);
+  dispatcher->setRequestGroupMan(e->_requestGroupMan);
 
   DefaultBtMessageReceiverHandle receiver(new DefaultBtMessageReceiver());
   receiver->setCuid(cuid);

+ 4 - 0
src/option_processing.cc

@@ -214,6 +214,7 @@ Option* option_processing(int argc, char* const argv[])
       { PREF_BT_MAX_OPEN_FILES.c_str(), required_argument, &lopt, 33 },
       { PREF_BT_SEED_UNVERIFIED.c_str(), optional_argument, &lopt, 34 },
       { PREF_DHT_FILE_PATH.c_str(), required_argument, &lopt, 35 },
+      { PREF_MAX_OVERALL_UPLOAD_LIMIT.c_str(), required_argument, &lopt, 36 },
 #endif // ENABLE_BITTORRENT
 #ifdef ENABLE_METALINK
       { PREF_METALINK_FILE.c_str(), required_argument, NULL, 'M' },
@@ -338,6 +339,9 @@ Option* option_processing(int argc, char* const argv[])
       case 35:
 	cmdstream << PREF_DHT_FILE_PATH << "=" << optarg << "\n";
 	break;
+      case 36:
+	cmdstream << PREF_MAX_OVERALL_UPLOAD_LIMIT << "=" << optarg << "\n";
+	break;
       case 100:
 	cmdstream << PREF_METALINK_VERSION << "=" << optarg << "\n";
 	break;

+ 2 - 0
src/prefs.cc

@@ -217,6 +217,8 @@ const std::string PREF_SHOW_FILES("show-files");
 // values: true | false
 const std::string PREF_DIRECT_FILE_MAPPING("direct-file-mapping");
 // values: 1*digit
+const std::string PREF_MAX_OVERALL_UPLOAD_LIMIT("max-overall-upload-limit");
+// values: 1*digit
 const std::string PREF_MAX_UPLOAD_LIMIT("max-upload-limit");
 // values: a string that your file system recognizes as a file name.
 const std::string PREF_TORRENT_FILE("torrent-file");

+ 2 - 0
src/prefs.h

@@ -221,6 +221,8 @@ extern const std::string PREF_SHOW_FILES;
 // values: true | false
 extern const std::string PREF_DIRECT_FILE_MAPPING;
 // values: 1*digit
+extern const std::string PREF_MAX_OVERALL_UPLOAD_LIMIT;
+// values: 1*digit
 extern const std::string PREF_MAX_UPLOAD_LIMIT;
 // values: a string that your file system recognizes as a file name.
 extern const std::string PREF_TORRENT_FILE;

+ 12 - 3
src/usage_text.h

@@ -227,10 +227,19 @@ _(" --listen-port=PORT...        Set TCP port number for BitTorrent downloads.\n
   "                              for example: \"6881,6885\". You can also use '-'\n"\
   "                              to specify a range: \"6881-6999\". ',' and '-' can\n"\
   "                              be used together.")
-#define TEXT_MAX_UPLOAD_LIMIT \
-_(" -u, --max-upload-limit=SPEED Set max upload speed in bytes per sec.\n"\
+#define TEXT_MAX_OVERALL_UPLOAD_LIMIT \
+_(" --max-overall-upload-limit=SPEED Set max overall upload speed in bytes/sec.\n"\
   "                              0 means unrestricted.\n"\
-  "                              You can append K or M(1K = 1024, 1M = 1024K).")
+  "                              You can append K or M(1K = 1024, 1M = 1024K).\n"\
+  "                              To limit the upload speed per torrent, use\n"\
+  "                              --max-upload-limit option. If non-zero value is\n"\
+  "                              specified, --max-upload-limit option is ignored.")
+#define TEXT_MAX_UPLOAD_LIMIT \
+_(" -u, --max-upload-limit=SPEED Set max upload speed per each torrent in\n"\
+  "                              bytes/sec. 0 means unrestricted.\n"\
+  "                              You can append K or M(1K = 1024, 1M = 1024K).\n"\
+  "                              To limit the overall upload speed, use\n"\
+  "                              --max-overall-upload-limit option.")
 #define TEXT_SEED_TIME \
 _(" --seed-time=MINUTES          Specify seeding time in minutes. Also see the\n"\
   "                              --seed-ratio option.")