mirror of
https://github.com/meganz/MEGAcmd
synced 2025-08-22 18:07:09 +00:00
vitaminate speedlimit with support for setting max connections
This commit is contained in:
parent
f359a9c31a
commit
1de28fca33
@ -214,7 +214,7 @@ Verbosity: You can increase the amount of information given by any command by pa
|
|||||||
* [`mv`](contrib/docs/commands/mv.md)`srcremotepath [--use-pcre] [srcremotepath2 srcremotepath3 ..] dstremotepath` Moves file(s)/folder(s) into a new location (all remotes)
|
* [`mv`](contrib/docs/commands/mv.md)`srcremotepath [--use-pcre] [srcremotepath2 srcremotepath3 ..] dstremotepath` Moves file(s)/folder(s) into a new location (all remotes)
|
||||||
* [`rm`](contrib/docs/commands/rm.md)`[-r] [-f] [--use-pcre] remotepath` Deletes a remote file/folder
|
* [`rm`](contrib/docs/commands/rm.md)`[-r] [-f] [--use-pcre] remotepath` Deletes a remote file/folder
|
||||||
* [`transfers`](contrib/docs/commands/transfers.md)`[-c TAG|-a] | [-r TAG|-a] | [-p TAG|-a] [--only-downloads | --only-uploads] [SHOWOPTIONS]` List or operate with transfers
|
* [`transfers`](contrib/docs/commands/transfers.md)`[-c TAG|-a] | [-r TAG|-a] | [-p TAG|-a] [--only-downloads | --only-uploads] [SHOWOPTIONS]` List or operate with transfers
|
||||||
* [`speedlimit`](contrib/docs/commands/speedlimit.md)`[-u|-d] [-h] [NEWLIMIT]` Displays/modifies upload/download rate limits
|
* [`speedlimit`](contrib/docs/commands/speedlimit.md)`[-u|-d|--upload-connections|--download-connections] [-h] [NEWLIMIT]` Displays/modifies upload/download rate limits
|
||||||
* [`sync`](contrib/docs/commands/sync.md)`[localpath dstremotepath| [-dpe] [ID|localpath]` Controls synchronizations.
|
* [`sync`](contrib/docs/commands/sync.md)`[localpath dstremotepath| [-dpe] [ID|localpath]` Controls synchronizations.
|
||||||
* [`sync-issues`](contrib/docs/commands/sync-issues.md)`[[--detail (ID|--all)] [--limit=rowcount] [--disable-path-collapse]] | [--enable-warning|--disable-warning]` Show all issues with current syncs
|
* [`sync-issues`](contrib/docs/commands/sync-issues.md)`[[--detail (ID|--all)] [--limit=rowcount] [--disable-path-collapse]] | [--enable-warning|--disable-warning]` Show all issues with current syncs
|
||||||
* [`sync-ignore`](contrib/docs/commands/sync-ignore.md)`[--show|[--add|--add-exclusion|--remove|--remove-exclusion] filter1 filter2 ...] (ID|localpath|DEFAULT)` Manages ignore filters for syncs
|
* [`sync-ignore`](contrib/docs/commands/sync-ignore.md)`[--show|[--add|--add-exclusion|--remove|--remove-exclusion] filter1 filter2 ...] (ID|localpath|DEFAULT)` Manages ignore filters for syncs
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
### speedlimit
|
### speedlimit
|
||||||
Displays/modifies upload/download rate limits
|
Displays/modifies upload/download rate limits
|
||||||
|
|
||||||
Usage: `speedlimit [-u|-d] [-h] [NEWLIMIT]`
|
Usage: `speedlimit [-u|-d|--upload-connections|--download-connections] [-h] [NEWLIMIT]`
|
||||||
<pre>
|
<pre>
|
||||||
NEWLIMIT establish the new limit in size per second (0 = no limit)
|
NEWLIMIT establish the new limit in size per second (0 = no limit)
|
||||||
NEWLIMIT may include (B)ytes, (K)ilobytes, (M)egabytes, (G)igabytes & (T)erabytes.
|
NEWLIMIT may include (B)ytes, (K)ilobytes, (M)egabytes, (G)igabytes & (T)erabytes.
|
||||||
Examples: "1m12k3B" "3M". If no units are given, bytes are assumed
|
Examples: "1m12k3B" "3M". If no units are given, bytes are assumed
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-d Download speed limit
|
-d Download speed limit
|
||||||
-u Upload speed limit
|
-u Upload speed limit
|
||||||
-h Human readable
|
--upload-connections Max number of connections for an upload transfer
|
||||||
|
--download-connections Max number of connections for a download transfer
|
||||||
|
-h Human readable
|
||||||
|
|
||||||
Notice: this limit will be saved for the next time you execute MEGAcmd server. They will be removed if you logout.
|
Notice: these limits will be saved for the next time you execute MEGAcmd server. They will be removed if you logout.
|
||||||
</pre>
|
</pre>
|
||||||
|
@ -514,6 +514,8 @@ void insertValidParamsPerCommand(set<string> *validParams, string thecommand, se
|
|||||||
validParams->insert("u");
|
validParams->insert("u");
|
||||||
validParams->insert("d");
|
validParams->insert("d");
|
||||||
validParams->insert("h");
|
validParams->insert("h");
|
||||||
|
validParams->insert("upload-connections");
|
||||||
|
validParams->insert("download-connections");
|
||||||
}
|
}
|
||||||
else if ("whoami" == thecommand)
|
else if ("whoami" == thecommand)
|
||||||
{
|
{
|
||||||
@ -1856,7 +1858,7 @@ const char * getUsageStr(const char *command, const HelpFlags& flags)
|
|||||||
}
|
}
|
||||||
if (!strcmp(command, "speedlimit"))
|
if (!strcmp(command, "speedlimit"))
|
||||||
{
|
{
|
||||||
return "speedlimit [-u|-d] [-h] [NEWLIMIT]";
|
return "speedlimit [-u|-d|--upload-connections|--download-connections] [-h] [NEWLIMIT]";
|
||||||
}
|
}
|
||||||
if (!strcmp(command, "killsession"))
|
if (!strcmp(command, "killsession"))
|
||||||
{
|
{
|
||||||
@ -2964,11 +2966,13 @@ string getHelpStr(const char *command, const HelpFlags& flags = {})
|
|||||||
os << " Examples: \"1m12k3B\" \"3M\". If no units are given, bytes are assumed" << endl;
|
os << " Examples: \"1m12k3B\" \"3M\". If no units are given, bytes are assumed" << endl;
|
||||||
os << endl;
|
os << endl;
|
||||||
os << "Options:" << endl;
|
os << "Options:" << endl;
|
||||||
os << " -d" << "\t" << "Download speed limit" << endl;
|
os << " -d " << "Download speed limit" << endl;
|
||||||
os << " -u" << "\t" << "Upload speed limit" << endl;
|
os << " -u " << "Upload speed limit" << endl;
|
||||||
os << " -h" << "\t" << "Human readable" << endl;
|
os << " --upload-connections " << "Max number of connections for an upload transfer" << endl;
|
||||||
|
os << " --download-connections " << "Max number of connections for a download transfer" << endl;
|
||||||
|
os << " -h " << "Human readable" << endl;
|
||||||
os << endl;
|
os << endl;
|
||||||
os << "Notice: this limit will be saved for the next time you execute MEGAcmd server. They will be removed if you logout." << endl;
|
os << "Notice: these limits will be saved for the next time you execute MEGAcmd server. They will be removed if you logout." << endl;
|
||||||
}
|
}
|
||||||
else if (!strcmp(command, "killsession"))
|
else if (!strcmp(command, "killsession"))
|
||||||
{
|
{
|
||||||
|
@ -276,6 +276,12 @@ bool onlyZeroOrOneOf(Bools... args)
|
|||||||
return (args + ...) <= 1;
|
return (args + ...) <= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename... Bools>
|
||||||
|
bool onlyZeroOf(Bools... args)
|
||||||
|
{
|
||||||
|
return (args + ...) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
void printPercentageLineCerr(const char *title, long long completed, long long total, float percentDowloaded, bool cleanLineAfter = true);
|
void printPercentageLineCerr(const char *title, long long completed, long long total, float percentDowloaded, bool cleanLineAfter = true);
|
||||||
|
|
||||||
|
|
||||||
|
@ -2640,6 +2640,19 @@ int MegaCmdExecuter::actUponLogin(SynchronousRequestListener *srl, int timeout)
|
|||||||
long long maxspeedupload = ConfigurationManager::getConfigurationValue("maxspeedupload", -1);
|
long long maxspeedupload = ConfigurationManager::getConfigurationValue("maxspeedupload", -1);
|
||||||
if (maxspeedupload != -1) api->setMaxUploadSpeed(maxspeedupload);
|
if (maxspeedupload != -1) api->setMaxUploadSpeed(maxspeedupload);
|
||||||
|
|
||||||
|
for (bool up :{true, false})
|
||||||
|
{
|
||||||
|
auto megaCmdListener = std::make_unique<MegaCmdListener>(nullptr);
|
||||||
|
auto value = ConfigurationManager::getConfigurationValue(up ? "maxuploadconnections" : "maxdownloadconnections", -1);
|
||||||
|
api->setMaxConnections(up ? 1 : 0, value, megaCmdListener.get());
|
||||||
|
megaCmdListener->wait();
|
||||||
|
if (megaCmdListener->getError()->getErrorCode() != MegaError::API_OK)
|
||||||
|
{
|
||||||
|
LOG_err << "Failed to change max " << (up ? "upload" : "download") << " connections: "
|
||||||
|
<< megaCmdListener->getError()->getErrorString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
api->useHttpsOnly(ConfigurationManager::getConfigurationValue("https", false));
|
api->useHttpsOnly(ConfigurationManager::getConfigurationValue("https", false));
|
||||||
api->disableGfxFeatures(!ConfigurationManager::getConfigurationValue("graphics", true));
|
api->disableGfxFeatures(!ConfigurationManager::getConfigurationValue("graphics", true));
|
||||||
|
|
||||||
@ -9187,59 +9200,107 @@ void MegaCmdExecuter::executecommand(vector<string> words, map<string, int> *clf
|
|||||||
}
|
}
|
||||||
else if (words[0] == "speedlimit")
|
else if (words[0] == "speedlimit")
|
||||||
{
|
{
|
||||||
if (words.size() > 2)
|
bool uploadSpeed = getFlag(clflags, "u");
|
||||||
|
bool downloadSpeed = getFlag(clflags, "d");
|
||||||
|
bool uploadCons = getFlag(clflags, "upload-connections");
|
||||||
|
bool downloadCons = getFlag(clflags, "download-connections");
|
||||||
|
|
||||||
|
bool moreThanOne = !onlyZeroOrOneOf(uploadSpeed, downloadSpeed, uploadCons, downloadCons);
|
||||||
|
bool noParam = onlyZeroOf(uploadSpeed, downloadSpeed, uploadCons, downloadCons);
|
||||||
|
bool hr = getFlag(clflags,"h");
|
||||||
|
|
||||||
|
if (words.size() > 2 || moreThanOne)
|
||||||
{
|
{
|
||||||
setCurrentThreadOutCode(MCMD_EARGS);
|
setCurrentThreadOutCode(MCMD_EARGS);
|
||||||
LOG_err << " " << getUsageStr("speedlimit");
|
LOG_err << " " << getUsageStr("speedlimit");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (words.size() > 1)
|
if (words.size() > 1) // setting
|
||||||
{
|
{
|
||||||
long long maxspeed = textToSize(words[1].c_str());
|
long long value = textToSize(words[1].c_str());
|
||||||
if (maxspeed == -1)
|
if (value == -1)
|
||||||
{
|
{
|
||||||
string s = words[1] + "B";
|
string s = words[1] + "B";
|
||||||
maxspeed = textToSize(s.c_str());
|
value = textToSize(s.c_str());
|
||||||
}
|
}
|
||||||
if (!getFlag(clflags, "u") && !getFlag(clflags, "d"))
|
if (noParam)
|
||||||
{
|
{
|
||||||
api->setMaxDownloadSpeed(maxspeed);
|
api->setMaxDownloadSpeed(value);
|
||||||
api->setMaxUploadSpeed(maxspeed);
|
api->setMaxUploadSpeed(value);
|
||||||
ConfigurationManager::savePropertyValue("maxspeedupload", maxspeed);
|
ConfigurationManager::savePropertyValue("maxspeedupload", value);
|
||||||
ConfigurationManager::savePropertyValue("maxspeeddownload", maxspeed);
|
ConfigurationManager::savePropertyValue("maxspeeddownload", value);
|
||||||
}
|
}
|
||||||
else if (getFlag(clflags, "u"))
|
else if (uploadSpeed)
|
||||||
{
|
{
|
||||||
api->setMaxUploadSpeed(maxspeed);
|
api->setMaxUploadSpeed(value);
|
||||||
ConfigurationManager::savePropertyValue("maxspeedupload", maxspeed);
|
ConfigurationManager::savePropertyValue("maxspeedupload", value);
|
||||||
}
|
}
|
||||||
else if (getFlag(clflags, "d"))
|
else if (downloadSpeed)
|
||||||
{
|
{
|
||||||
api->setMaxDownloadSpeed(maxspeed);
|
api->setMaxDownloadSpeed(value);
|
||||||
ConfigurationManager::savePropertyValue("maxspeeddownload", maxspeed);
|
ConfigurationManager::savePropertyValue("maxspeeddownload", value);
|
||||||
|
}
|
||||||
|
else if (uploadCons || downloadCons)
|
||||||
|
{
|
||||||
|
auto megaCmdListener = std::make_unique<MegaCmdListener>(nullptr);
|
||||||
|
api->setMaxConnections(uploadCons ? 1 : 0, value, megaCmdListener.get());
|
||||||
|
if (!checkNoErrors(megaCmdListener.get(), uploadCons ? "change max upload connections" : "change max download connections"))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigurationManager::savePropertyValue(uploadCons ? "maxuploadconnections" : "maxdownloadconnections", value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hr = getFlag(clflags,"h");
|
// listing:
|
||||||
|
if (noParam)
|
||||||
if (!getFlag(clflags, "u") && !getFlag(clflags, "d"))
|
|
||||||
{
|
{
|
||||||
long long us = api->getMaxUploadSpeed();
|
long long us = api->getMaxUploadSpeed();
|
||||||
long long ds = api->getMaxDownloadSpeed();
|
long long ds = api->getMaxDownloadSpeed();
|
||||||
OUTSTREAM << "Upload speed limit = " << (us?sizeToText(us,false,hr):"unlimited") << ((us && hr)?"/s":(us?" B/s":"")) << endl;
|
OUTSTREAM << "Upload speed limit = " << (us?sizeToText(us,false,hr):"unlimited") << ((us && hr)?"/s":(us?" B/s":"")) << endl;
|
||||||
OUTSTREAM << "Download speed limit = " << (ds?sizeToText(ds,false,hr):"unlimited") << ((ds && hr)?"/s":(us?" B/s":"")) << endl;
|
OUTSTREAM << "Download speed limit = " << (ds?sizeToText(ds,false,hr):"unlimited") << ((ds && hr)?"/s":(us?" B/s":"")) << endl;
|
||||||
|
auto upConns = ConfigurationManager::getConfigurationValue("maxuploadconnections", -1);
|
||||||
|
auto downConns = ConfigurationManager::getConfigurationValue("maxdownloadconnections", -1);
|
||||||
|
if (upConns != -1)
|
||||||
|
{
|
||||||
|
OUTSTREAM << "Upload max connections = " << upConns << std::endl;
|
||||||
|
}
|
||||||
|
if (downConns != -1)
|
||||||
|
{
|
||||||
|
OUTSTREAM << "Download max connections = " << downConns << std::endl;;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (getFlag(clflags, "u"))
|
else if (uploadSpeed)
|
||||||
{
|
{
|
||||||
long long us = api->getMaxUploadSpeed();
|
long long us = api->getMaxUploadSpeed();
|
||||||
OUTSTREAM << "Upload speed limit = " << (us?sizeToText(us,false,hr):"unlimited") << ((us && hr)?"/s":(us?" B/s":"")) << endl;
|
OUTSTREAM << "Upload speed limit = " << (us?sizeToText(us,false,hr):"unlimited") << ((us && hr)?"/s":(us?" B/s":"")) << endl;
|
||||||
}
|
}
|
||||||
else if (getFlag(clflags, "d"))
|
else if (downloadSpeed)
|
||||||
{
|
{
|
||||||
long long ds = api->getMaxDownloadSpeed();
|
long long ds = api->getMaxDownloadSpeed();
|
||||||
OUTSTREAM << "Download speed limit = " << (ds?sizeToText(ds,false,hr):"unlimited") << ((ds && hr)?"/s":(ds?" B/s":"")) << endl;
|
OUTSTREAM << "Download speed limit = " << (ds?sizeToText(ds,false,hr):"unlimited") << ((ds && hr)?"/s":(ds?" B/s":"")) << endl;
|
||||||
}
|
}
|
||||||
|
else if (uploadCons || downloadCons)
|
||||||
|
{
|
||||||
|
if (uploadCons)
|
||||||
|
{
|
||||||
|
auto upConns = ConfigurationManager::getConfigurationValue("maxuploadconnections", -1);
|
||||||
|
if (upConns != -1)
|
||||||
|
{
|
||||||
|
OUTSTREAM << "Upload max connections = " << upConns << std::endl;;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto downConns = ConfigurationManager::getConfigurationValue("maxdownloadconnections", -1);
|
||||||
|
|
||||||
|
if (downConns != -1)
|
||||||
|
{
|
||||||
|
OUTSTREAM << "Download max connections = " << downConns << std::endl;;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (words[0] == "invite")
|
else if (words[0] == "invite")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user