diff --git a/ChangeLog b/ChangeLog index 2c66702a..4aa78f2a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2008-12-10 Tatsuhiro Tsujikawa + + 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 Use BDE instead of Dictionary/List/Data classes. diff --git a/doc/aria2c.1 b/doc/aria2c.1 index 6163e528..b7d8eba6 100644 --- a/doc/aria2c.1 +++ b/doc/aria2c.1 @@ -1,11 +1,11 @@ .\" Title: aria2c .\" Author: .\" Generator: DocBook XSL Stylesheets v1.73.2 -.\" 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\-u\fR, \fB\-\-max\-upload\-limit\fR=SPEED +\fB\-\-max\-overall\-upload\-limit\fR=SPEED .RS 4 -Set max upload speed in bytes per sec\&. +Set max overall upload speed 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 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 per each torrent in bytes/sec\&. +\fI0\fR +means unrestricted\&. You can append +\fIK\fR +or +\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 diff --git a/doc/aria2c.1.html b/doc/aria2c.1.html index 22b0cd21..20791838 100644 --- a/doc/aria2c.1.html +++ b/doc/aria2c.1.html @@ -1064,12 +1064,27 @@ writes the piece to the appropriate files.
+--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

@@ -2031,7 +2046,7 @@ files in the program, then also delete it here.

diff --git a/doc/aria2c.1.txt b/doc/aria2c.1.txt index 5e71d241..0924fb8d 100644 --- a/doc/aria2c.1.txt +++ b/doc/aria2c.1.txt @@ -366,9 +366,19 @@ BitTorrent Specific Options [NOTE] Make sure that the specified ports are open for incoming TCP traffic. -*-u*, *--max-upload-limit*=SPEED:: - Set max upload speed in bytes per sec. '0' means unrestricted. +*--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 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:: diff --git a/src/DefaultBtMessageDispatcher.cc b/src/DefaultBtMessageDispatcher.cc index 07d54722..53eccae5 100644 --- a/src/DefaultBtMessageDispatcher.cc +++ b/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 WeakHandlemessageFactory = factory; } +void DefaultBtMessageDispatcher::setRequestGroupMan +(const WeakHandle& rgman) +{ + _requestGroupMan = rgman; +} + +void DefaultBtMessageDispatcher::setMaxUploadSpeedLimit +(unsigned int maxUploadSpeedLimit) +{ + _maxUploadSpeedLimit = maxUploadSpeedLimit; +} + +void DefaultBtMessageDispatcher::setMaxOverallSpeedLimit +(unsigned int maxOverallSpeedLimit) +{ + _maxOverallSpeedLimit = maxOverallSpeedLimit; +} + + } // namespace aria2 diff --git a/src/DefaultBtMessageDispatcher.h b/src/DefaultBtMessageDispatcher.h index 678bfa5f..f8c07e27 100644 --- a/src/DefaultBtMessageDispatcher.h +++ b/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; WeakHandle messageFactory; SharedHandle peer; - unsigned int maxUploadSpeedLimit; + WeakHandle _requestGroupMan; + unsigned int _maxOverallSpeedLimit; + unsigned int _maxUploadSpeedLimit; time_t requestTimeout; Logger* logger; public: @@ -117,13 +120,15 @@ public: void setBtMessageFactory(const WeakHandle& factory); + void setRequestGroupMan(const WeakHandle& 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; diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index be7fa90f..563ecf23 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -824,6 +824,16 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() op->addTag(TAG_BITTORRENT); handlers.push_back(op); } + { + SharedHandle 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 op(new UnitNumberOptionHandler (PREF_MAX_UPLOAD_LIMIT, diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc index 186a2960..ad75e6d4 100644 --- a/src/PeerInteractionCommand.cc +++ b/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); diff --git a/src/option_processing.cc b/src/option_processing.cc index 523658a3..e0102d84 100644 --- a/src/option_processing.cc +++ b/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; diff --git a/src/prefs.cc b/src/prefs.cc index 64fbd58c..8a677259 100644 --- a/src/prefs.cc +++ b/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"); diff --git a/src/prefs.h b/src/prefs.h index befa838b..0328a656 100644 --- a/src/prefs.h +++ b/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; diff --git a/src/usage_text.h b/src/usage_text.h index a2ed0c2c..c7c6e457 100644 --- a/src/usage_text.h +++ b/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.")