diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-02-28 11:48:26 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-02-28 11:48:26 +0000 |
| commit | 0b29a6e2cf4461b20bfdb85d5f5cd635b5ba6b5a (patch) | |
| tree | f63f712ec29cb963b3270e7bcd7cc24870bb7f77 /src | |
| parent | 362cd20bf117b366dd3c72ce5383e243fa4cd0f1 (diff) | |
2009-02-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added --max-overall-download-limit option. Now
--max-upload-limit option is not ignored when
--max-overall-upload-limit option has non-zero value. aria2
checks download(upload) speed in the order:
first checks overall speed limit and if it is not exceeded, then
checks speed limit per download. Thus you can specify both
value. For example, set --max-overall-download-limit=1M and
--max-download-limit=500K to prevent from one download from
eating all overall speed limit.
* src/DefaultBtInteractive.cc
* src/DefaultBtInteractive.h
* src/DefaultBtMessageDispatcher.cc
* src/DefaultBtMessageDispatcher.h
* src/DownloadCommand.cc
* src/DownloadCommand.h
* src/FtpNegotiationCommand.cc
* src/HttpResponseCommand.cc
* src/OptionHandlerFactory.cc
* src/PeerInteractionCommand.cc
* src/RequestGroup.cc
* src/RequestGroup.h
* src/RequestGroupMan.cc
* src/RequestGroupMan.h
* src/prefs.cc
* src/prefs.h
* src/usage_text.h
* test/DefaultBtMessageDispatcherTest.cc
Diffstat (limited to 'src')
| -rw-r--r-- | src/DefaultBtInteractive.cc | 16 | ||||
| -rw-r--r-- | src/DefaultBtInteractive.h | 10 | ||||
| -rw-r--r-- | src/DefaultBtMessageDispatcher.cc | 28 | ||||
| -rw-r--r-- | src/DefaultBtMessageDispatcher.h | 7 | ||||
| -rw-r--r-- | src/DownloadCommand.cc | 6 | ||||
| -rw-r--r-- | src/DownloadCommand.h | 5 | ||||
| -rw-r--r-- | src/FtpNegotiationCommand.cc | 1 | ||||
| -rw-r--r-- | src/HttpResponseCommand.cc | 2 | ||||
| -rw-r--r-- | src/OptionHandlerFactory.cc | 11 | ||||
| -rw-r--r-- | src/PeerInteractionCommand.cc | 19 | ||||
| -rw-r--r-- | src/RequestGroup.cc | 14 | ||||
| -rw-r--r-- | src/RequestGroup.h | 14 | ||||
| -rw-r--r-- | src/RequestGroupMan.cc | 18 | ||||
| -rw-r--r-- | src/RequestGroupMan.h | 14 | ||||
| -rw-r--r-- | src/prefs.cc | 2 | ||||
| -rw-r--r-- | src/prefs.h | 2 | ||||
| -rw-r--r-- | src/usage_text.h | 17 |
17 files changed, 112 insertions, 74 deletions
diff --git a/src/DefaultBtInteractive.cc b/src/DefaultBtInteractive.cc index a32a6c3a..e3f43d2d 100644 --- a/src/DefaultBtInteractive.cc +++ b/src/DefaultBtInteractive.cc @@ -66,6 +66,7 @@ #include "LogFactory.h" #include "StringFormat.h" #include "RequestGroup.h" +#include "RequestGroupMan.h" namespace aria2 { @@ -77,7 +78,6 @@ DefaultBtInteractive::DefaultBtInteractive logger(LogFactory::getInstance()), allowedFastSetSize(10), keepAliveInterval(120), - maxDownloadSpeedLimit(0), _utPexEnabled(false), _dhtEnabled(false), _numReceivedMessage(0) @@ -237,11 +237,9 @@ void DefaultBtInteractive::sendKeepAlive() { size_t DefaultBtInteractive::receiveMessages() { size_t msgcount = 0; for(int i = 0; i < 50; i++) { - if(maxDownloadSpeedLimit > 0) { - TransferStat stat = _btContext->getOwnerRequestGroup()->calculateStat(); - if(maxDownloadSpeedLimit < stat.downloadSpeed) { - break; - } + if(_requestGroupMan->doesOverallDownloadSpeedExceed() || + _btContext->getOwnerRequestGroup()->doesDownloadSpeedExceed()) { + break; } BtMessageHandle message = btMessageReceiver->receiveMessage(); if(message.isNull()) { @@ -544,4 +542,10 @@ void DefaultBtInteractive::setBtMessageFactory this->messageFactory = factory; } +void DefaultBtInteractive::setRequestGroupMan +(const WeakHandle<RequestGroupMan>& rgman) +{ + _requestGroupMan = rgman; +} + } // namespace aria2 diff --git a/src/DefaultBtInteractive.h b/src/DefaultBtInteractive.h index 98f9d2e3..d364404f 100644 --- a/src/DefaultBtInteractive.h +++ b/src/DefaultBtInteractive.h @@ -57,6 +57,7 @@ class PeerConnection; class ExtensionMessageFactory; class DHTNode; class Logger; +class RequestGroupMan; class FloodingStat { private: @@ -123,12 +124,13 @@ private: Time inactiveCheckPoint; Time _pexCheckPoint; time_t keepAliveInterval; - unsigned int maxDownloadSpeedLimit; bool _utPexEnabled; bool _dhtEnabled; size_t _numReceivedMessage; + WeakHandle<RequestGroupMan> _requestGroupMan; + static const time_t FLOODING_CHECK_INTERVAL = 5; void addBitfieldMessageToQueue(); @@ -204,10 +206,6 @@ public: this->keepAliveInterval = keepAliveInterval; } - void setMaxDownloadSpeedLimit(unsigned int maxDownloadSpeedLimit) { - this->maxDownloadSpeedLimit = maxDownloadSpeedLimit; - } - void setUTPexEnabled(bool f) { _utPexEnabled = f; @@ -219,6 +217,8 @@ public: { _dhtEnabled = f; } + + void setRequestGroupMan(const WeakHandle<RequestGroupMan>& rgman); }; typedef SharedHandle<DefaultBtInteractive> DefaultBtInteractiveHandle; diff --git a/src/DefaultBtMessageDispatcher.cc b/src/DefaultBtMessageDispatcher.cc index 81fe64df..a63beeb0 100644 --- a/src/DefaultBtMessageDispatcher.cc +++ b/src/DefaultBtMessageDispatcher.cc @@ -53,13 +53,12 @@ #include "Logger.h" #include "a2functional.h" #include "RequestGroupMan.h" +#include "RequestGroup.h" namespace aria2 { DefaultBtMessageDispatcher::DefaultBtMessageDispatcher(): cuid(0), - _maxOverallSpeedLimit(0), - _maxUploadSpeedLimit(0), requestTimeout(0), logger(LogFactory::getInstance()) {} @@ -87,16 +86,8 @@ void DefaultBtMessageDispatcher::sendMessages() { BtMessageHandle msg = messageQueue.front(); messageQueue.pop_front(); 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())) { + if(_requestGroupMan->doesOverallUploadSpeedExceed() || + btContext->getOwnerRequestGroup()->doesUploadSpeedExceed()) { tempQueue.push_back(msg); continue; } @@ -472,17 +463,4 @@ void DefaultBtMessageDispatcher::setRequestGroupMan _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 f8c07e27..b9721541 100644 --- a/src/DefaultBtMessageDispatcher.h +++ b/src/DefaultBtMessageDispatcher.h @@ -61,8 +61,6 @@ private: WeakHandle<BtMessageFactory> messageFactory; SharedHandle<Peer> peer; WeakHandle<RequestGroupMan> _requestGroupMan; - unsigned int _maxOverallSpeedLimit; - unsigned int _maxUploadSpeedLimit; time_t requestTimeout; Logger* logger; public: @@ -126,14 +124,9 @@ public: this->cuid = cuid; } - void setMaxUploadSpeedLimit(unsigned int maxUploadSpeedLimit); - - void setMaxOverallSpeedLimit(unsigned int maxOverallSpeedLimit); - void setRequestTimeout(time_t requestTimeout) { this->requestTimeout = requestTimeout; } - }; typedef SharedHandle<DefaultBtMessageDispatcher> DefaultBtMessageDispatcherHandle; diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index 19a473ad..b6de9b87 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -57,6 +57,7 @@ #include "prefs.h" #include "StringFormat.h" #include "Decoder.h" +#include "RequestGroupMan.h" #ifdef ENABLE_MESSAGE_DIGEST # include "MessageDigestHelper.h" #endif // ENABLE_MESSAGE_DIGEST @@ -101,9 +102,8 @@ DownloadCommand::~DownloadCommand() { } bool DownloadCommand::executeInternal() { - if(maxDownloadSpeedLimit > 0 && - maxDownloadSpeedLimit < - _requestGroup->calculateStat().getDownloadSpeed()) { + if(e->_requestGroupMan->doesOverallDownloadSpeedExceed() || + _requestGroup->doesDownloadSpeedExceed()) { e->commands.push_back(this); disableReadCheckSocket(); return false; diff --git a/src/DownloadCommand.h b/src/DownloadCommand.h index 87ab9924..05d3b670 100644 --- a/src/DownloadCommand.h +++ b/src/DownloadCommand.h @@ -47,7 +47,6 @@ class MessageDigestContext; class DownloadCommand : public AbstractCommand { private: - unsigned int maxDownloadSpeedLimit; time_t startupIdleTime; unsigned int lowestDownloadSpeedLimit; SharedHandle<PeerStat> peerStat; @@ -86,10 +85,6 @@ public: void setContentEncodingDecoder(const SharedHandle<Decoder>& decoder); - void setMaxDownloadSpeedLimit(unsigned int maxDownloadSpeedLimit) { - this->maxDownloadSpeedLimit = maxDownloadSpeedLimit; - } - void setStartupIdleTime(time_t startupIdleTime) { this->startupIdleTime = startupIdleTime; } diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc index 21a768e0..35fdbe42 100644 --- a/src/FtpNegotiationCommand.cc +++ b/src/FtpNegotiationCommand.cc @@ -96,7 +96,6 @@ bool FtpNegotiationCommand::executeInternal() { } else if(sequence == SEQ_NEGOTIATION_COMPLETED) { FtpDownloadCommand* command = new FtpDownloadCommand(cuid, req, _requestGroup, ftp, e, dataSocket, socket); - command->setMaxDownloadSpeedLimit(e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT)); command->setStartupIdleTime(e->option->getAsInt(PREF_STARTUP_IDLE_TIME)); command->setLowestDownloadSpeedLimit(e->option->getAsInt(PREF_LOWEST_SPEED_LIMIT)); if(!_requestGroup->isSingleHostMultiConnectionEnabled()) { diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index 99117a5d..c40e0049 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -334,8 +334,6 @@ HttpDownloadCommand* HttpResponseCommand::createHttpDownloadCommand HttpDownloadCommand* command = new HttpDownloadCommand(cuid, req, _requestGroup, httpResponse, httpConnection, e, socket); - command->setMaxDownloadSpeedLimit - (e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT)); command->setStartupIdleTime(e->option->getAsInt(PREF_STARTUP_IDLE_TIME)); command->setLowestDownloadSpeedLimit (e->option->getAsInt(PREF_LOWEST_SPEED_LIMIT)); diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index b7c75bb3..9387881c 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -282,6 +282,17 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() handlers.push_back(op); } { + SharedHandle<OptionHandler> op(new UnitNumberOptionHandler + (PREF_MAX_OVERALL_DOWNLOAD_LIMIT, + TEXT_MAX_OVERALL_DOWNLOAD_LIMIT, + "0", + 0)); + op->addTag(TAG_BITTORRENT); + op->addTag(TAG_FTP); + op->addTag(TAG_HTTP); + handlers.push_back(op); + } + { SharedHandle<OptionHandler> op(new BooleanOptionHandler (PREF_NO_CONF, TEXT_NO_CONF, diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc index ad75e6d4..3d27584d 100644 --- a/src/PeerInteractionCommand.cc +++ b/src/PeerInteractionCommand.cc @@ -132,10 +132,6 @@ PeerInteractionCommand::PeerInteractionCommand dispatcher->setBtContext(_btContext); dispatcher->setPieceStorage(pieceStorage); 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); @@ -170,8 +166,7 @@ PeerInteractionCommand::PeerInteractionCommand btInteractive->setExtensionMessageFactory(extensionMessageFactory); btInteractive->setKeepAliveInterval (e->option->getAsInt(PREF_BT_KEEP_ALIVE_INTERVAL)); - btInteractive->setMaxDownloadSpeedLimit - (e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT)); + btInteractive->setRequestGroupMan(e->_requestGroupMan); btInteractive->setBtMessageFactory(factory); if(!_btContext->isPrivate()) { if(e->option->getAsBool(PREF_ENABLE_PEER_EXCHANGE)) { @@ -268,14 +263,10 @@ bool PeerInteractionCommand::executeInternal() { setWriteCheckSocket(socket); } - if(maxDownloadSpeedLimit > 0) { - TransferStat stat = _requestGroup->calculateStat(); - if(maxDownloadSpeedLimit < stat.downloadSpeed) { - disableReadCheckSocket(); - setNoCheck(true); - } else { - setReadCheckSocket(socket); - } + if(e->_requestGroupMan->doesOverallDownloadSpeedExceed() || + _requestGroup->doesDownloadSpeedExceed()) { + disableReadCheckSocket(); + setNoCheck(true); } else { setReadCheckSocket(socket); } diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index d910696e..ceb042d5 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -129,6 +129,8 @@ RequestGroup::RequestGroup(const Option* option, _timeout(option->getAsInt(PREF_TIMEOUT)), _maxTries(option->getAsInt(PREF_MAX_TRIES)), _inMemoryDownload(false), + _maxDownloadSpeedLimit(option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT)), + _maxUploadSpeedLimit(option->getAsInt(PREF_MAX_UPLOAD_LIMIT)), _option(option), _logger(LogFactory::getInstance()) { @@ -1180,4 +1182,16 @@ unsigned int RequestGroup::getMaxTries() const return _maxTries; } +bool RequestGroup::doesDownloadSpeedExceed() +{ + return _maxDownloadSpeedLimit > 0 && + _maxDownloadSpeedLimit < calculateStat().getDownloadSpeed(); +} + +bool RequestGroup::doesUploadSpeedExceed() +{ + return _maxUploadSpeedLimit > 0 && + _maxUploadSpeedLimit < calculateStat().getUploadSpeed(); +} + } // namespace aria2 diff --git a/src/RequestGroup.h b/src/RequestGroup.h index 3c74367d..94a3e581 100644 --- a/src/RequestGroup.h +++ b/src/RequestGroup.h @@ -150,6 +150,10 @@ private: // just sits in memory. bool _inMemoryDownload; + unsigned int _maxDownloadSpeedLimit; + + unsigned int _maxUploadSpeedLimit; + const Option* _option; Logger* _logger; @@ -442,6 +446,16 @@ public: void setMaxTries(unsigned int maxTries); unsigned int getMaxTries() const; + + // Returns true if current download speed exceeds + // _maxDownloadSpeedLimit. Always returns false if + // _maxDownloadSpeedLimit == 0. Otherwise returns false. + bool doesDownloadSpeedExceed(); + + // Returns true if current upload speed exceeds + // _maxUploadSpeedLimit. Always returns false if + // _maxUploadSpeedLimit == 0. Otherwise returns false. + bool doesUploadSpeedExceed(); }; typedef SharedHandle<RequestGroup> RequestGroupHandle; diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index f88e9a50..0541be34 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -74,7 +74,11 @@ RequestGroupMan::RequestGroupMan(const RequestGroups& requestGroups, _maxSimultaneousDownloads(maxSimultaneousDownloads), _gidCounter(0), _option(option), - _serverStatMan(new ServerStatMan()) {} + _serverStatMan(new ServerStatMan()), + _maxOverallDownloadSpeedLimit + (option->getAsInt(PREF_MAX_OVERALL_DOWNLOAD_LIMIT)), + _maxOverallUploadSpeedLimit(option->getAsInt(PREF_MAX_OVERALL_UPLOAD_LIMIT)) +{} bool RequestGroupMan::downloadFinished() { @@ -612,4 +616,16 @@ void RequestGroupMan::removeStaleServerStat(time_t timeout) _serverStatMan->removeStaleServerStat(timeout); } +bool RequestGroupMan::doesOverallDownloadSpeedExceed() +{ + return _maxOverallDownloadSpeedLimit > 0 && + _maxOverallDownloadSpeedLimit < calculateStat().getDownloadSpeed(); +} + +bool RequestGroupMan::doesOverallUploadSpeedExceed() +{ + return _maxOverallUploadSpeedLimit > 0 && + _maxOverallUploadSpeedLimit < calculateStat().getUploadSpeed(); +} + } // namespace aria2 diff --git a/src/RequestGroupMan.h b/src/RequestGroupMan.h index 3f7f5872..07ac17f9 100644 --- a/src/RequestGroupMan.h +++ b/src/RequestGroupMan.h @@ -69,6 +69,10 @@ private: SharedHandle<ServerStatMan> _serverStatMan; + unsigned int _maxOverallDownloadSpeedLimit; + + unsigned int _maxOverallUploadSpeedLimit; + std::string formatDownloadResult(const std::string& status, const SharedHandle<DownloadResult>& downloadResult) const; @@ -170,6 +174,16 @@ public: bool saveServerStat(const std::string& filename) const; void removeStaleServerStat(time_t timeout); + + // Returns true if current download speed exceeds + // _maxOverallDownloadSpeedLimit. Always returns false if + // _maxOverallDownloadSpeedLimit == 0. Otherwise returns false. + bool doesOverallDownloadSpeedExceed(); + + // Returns true if current upload speed exceeds + // _maxOverallUploadSpeedLimit. Always returns false if + // _maxOverallUploadSpeedLimit == 0. Otherwise returns false. + bool doesOverallUploadSpeedExceed(); }; typedef SharedHandle<RequestGroupMan> RequestGroupManHandle; diff --git a/src/prefs.cc b/src/prefs.cc index 8b1a4a2e..765fd801 100644 --- a/src/prefs.cc +++ b/src/prefs.cc @@ -76,6 +76,8 @@ const std::string PREF_LOWEST_SPEED_LIMIT("lowest-speed-limit"); // value: 1*digit const std::string PREF_SEGMENT_SIZE("segment-size"); // value: 1*digit +const std::string PREF_MAX_OVERALL_DOWNLOAD_LIMIT("max-overall-download-limit"); +// value: 1*digit const std::string PREF_MAX_DOWNLOAD_LIMIT("max-download-limit"); // value: 1*digit const std::string PREF_STARTUP_IDLE_TIME("startup-idle-time"); diff --git a/src/prefs.h b/src/prefs.h index eb4b5938..dbaa1f2c 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -101,6 +101,8 @@ extern const std::string PREF_CONTINUE; // value: extern const std::string PREF_NO_NETRC; // value: 1*digit +extern const std::string PREF_MAX_OVERALL_DOWNLOAD_LIMIT; +// value: 1*digit extern const std::string PREF_MAX_DOWNLOADS; // value: string that your file system recognizes as a file name. extern const std::string PREF_INPUT_FILE; diff --git a/src/usage_text.h b/src/usage_text.h index 1270d9f2..92ae0bc0 100644 --- a/src/usage_text.h +++ b/src/usage_text.h @@ -103,10 +103,18 @@ _(" --lowest-speed-limit=SPEED Close connection if download speed is lower tha " 0 means aria2 does not have a lowest speed limit.\n"\ " You can append K or M(1K = 1024, 1M = 1024K).\n"\ " This option does not affect BitTorrent downloads.") -#define TEXT_MAX_DOWNLOAD_LIMIT \ -_(" --max-download-limit=SPEED Set max download speed in bytes per sec.\n"\ +#define TEXT_MAX_OVERALL_DOWNLOAD_LIMIT \ +_(" --max-overall-download-limit=SPEED Set max overall download 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 download speed per download, use\n"\ + " --max-download-limit option.") +#define TEXT_MAX_DOWNLOAD_LIMIT \ +_(" --max-download-limit=SPEED Set max download speed per each download in\n"\ + " bytes/sec. 0 means unrestricted.\n"\ + " You can append K or M(1K = 1024, 1M = 1024K).\n"\ + " To limit the overall download speed, use\n"\ + " --max-overall-download-limit option.") #define TEXT_FILE_ALLOCATION \ _(" --file-allocation=METHOD Specify file allocation method.\n"\ " 'none' doesn't pre-allocate file space. 'prealloc'\n"\ @@ -239,8 +247,7 @@ _(" --max-overall-upload-limit=SPEED Set max overall upload speed in bytes/sec.\ " 0 means unrestricted.\n"\ " 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.") + " --max-upload-limit option.") #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"\ |
