Disable the throttle limit if negative
Also, invalid values result in -1 being set
This commit is contained in:
+1
-1
@@ -691,7 +691,7 @@ On a server JID (e.g on the JID chat.freenode.org@biboumi.example.com)
|
|||||||
are throttled, only one command per second is sent to the server.
|
are throttled, only one command per second is sent to the server.
|
||||||
The default is 10. You can lower this value if you are ever kicked
|
The default is 10. You can lower this value if you are ever kicked
|
||||||
for excess flood. If the value is 0, all messages are throttled. To
|
for excess flood. If the value is 0, all messages are throttled. To
|
||||||
disable this feature, just set a high value, like 999.
|
disable this feature, set it to a negative number, or an empty string.
|
||||||
|
|
||||||
- get-irc-connection-info: Returns some information about the IRC server,
|
- get-irc-connection-info: Returns some information about the IRC server,
|
||||||
for the executing user. It lets the user know if they are connected to
|
for the executing user. It lets the user know if they are connected to
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ class Database
|
|||||||
|
|
||||||
struct Address: Column<std::string> { static constexpr auto name = "address_"; };
|
struct Address: Column<std::string> { static constexpr auto name = "address_"; };
|
||||||
|
|
||||||
struct ThrottleLimit: Column<unsigned long int> { static constexpr auto name = "throttlelimit_";
|
struct ThrottleLimit: Column<long int> { static constexpr auto name = "throttlelimit_";
|
||||||
ThrottleLimit(): Column<unsigned long int>(10) {} };
|
ThrottleLimit(): Column<long int>(10) {} };
|
||||||
|
|
||||||
using MucLogLineTable = Table<Id, Uuid, Owner, IrcChanName, IrcServerName, Date, Body, Nick>;
|
using MucLogLineTable = Table<Id, Uuid, Owner, IrcChanName, IrcServerName, Date, Body, Nick>;
|
||||||
using MucLogLine = MucLogLineTable::RowType;
|
using MucLogLine = MucLogLineTable::RowType;
|
||||||
|
|||||||
@@ -1291,7 +1291,7 @@ bool IrcClient::abort_on_invalid_cert() const
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::size_t IrcClient::get_throttle_limit() const
|
long int IrcClient::get_throttle_limit() const
|
||||||
{
|
{
|
||||||
#ifdef USE_DATABASE
|
#ifdef USE_DATABASE
|
||||||
return Database::get_irc_server_options(this->bridge.get_bare_jid(), this->hostname).col<Database::ThrottleLimit>();
|
return Database::get_irc_server_options(this->bridge.get_bare_jid(), this->hostname).col<Database::ThrottleLimit>();
|
||||||
|
|||||||
@@ -402,7 +402,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
Resolver dns_resolver;
|
Resolver dns_resolver;
|
||||||
TokensBucket tokens_bucket;
|
TokensBucket tokens_bucket;
|
||||||
std::size_t get_throttle_limit() const;
|
long int get_throttle_limit() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
class TokensBucket
|
class TokensBucket
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TokensBucket(std::size_t max_size, std::chrono::milliseconds fill_duration, std::function<bool()> callback, std::string name):
|
TokensBucket(long int max_size, std::chrono::milliseconds fill_duration, std::function<bool()> callback, std::string name):
|
||||||
limit(max_size),
|
limit(max_size),
|
||||||
tokens(limit),
|
tokens(limit),
|
||||||
callback(std::move(callback))
|
callback(std::move(callback))
|
||||||
@@ -29,6 +29,8 @@ public:
|
|||||||
|
|
||||||
bool use_token()
|
bool use_token()
|
||||||
{
|
{
|
||||||
|
if (this->limit < 0)
|
||||||
|
return true;
|
||||||
if (this->tokens > 0)
|
if (this->tokens > 0)
|
||||||
{
|
{
|
||||||
this->tokens--;
|
this->tokens--;
|
||||||
@@ -38,19 +40,21 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_limit(std::size_t limit)
|
void set_limit(long int limit)
|
||||||
{
|
{
|
||||||
this->limit = limit;
|
this->limit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::size_t limit;
|
long int limit;
|
||||||
std::size_t tokens;
|
std::size_t tokens;
|
||||||
std::function<bool()> callback;
|
std::function<bool()> callback;
|
||||||
|
|
||||||
void add_token()
|
void add_token()
|
||||||
{
|
{
|
||||||
if (this->callback() && this->tokens != limit)
|
if (this->limit < 0)
|
||||||
|
return;
|
||||||
|
if (this->callback() && this->tokens != static_cast<decltype(this->tokens)>(this->limit))
|
||||||
this->tokens++;
|
this->tokens++;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -494,7 +494,11 @@ void ConfigureIrcServerStep2(XmppComponent& xmpp_component, AdhocSession& sessio
|
|||||||
|
|
||||||
else if (field->get_tag("var") == "throttle_limit" && value)
|
else if (field->get_tag("var") == "throttle_limit" && value)
|
||||||
{
|
{
|
||||||
options.col<Database::ThrottleLimit>() = std::stoul(value->get_inner());
|
try {
|
||||||
|
options.col<Database::ThrottleLimit>() = std::stol(value->get_inner());
|
||||||
|
} catch (const std::logic_error&) {
|
||||||
|
options.col<Database::ThrottleLimit>() = -1;
|
||||||
|
}
|
||||||
Bridge* bridge = biboumi_component.find_user_bridge(session.get_owner_jid());
|
Bridge* bridge = biboumi_component.find_user_bridge(session.get_owner_jid());
|
||||||
if (bridge)
|
if (bridge)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2973,6 +2973,7 @@ if __name__ == '__main__':
|
|||||||
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-multi'][@var='tls_ports']/dataform:value[text()='6697']",
|
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-multi'][@var='tls_ports']/dataform:value[text()='6697']",
|
||||||
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='boolean'][@var='verify_cert']/dataform:value[text()='true']",
|
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='boolean'][@var='verify_cert']/dataform:value[text()='true']",
|
||||||
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='fingerprint']",
|
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='fingerprint']",
|
||||||
|
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='throttle_limit']",
|
||||||
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-private'][@var='pass']",
|
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-private'][@var='pass']",
|
||||||
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-multi'][@var='after_connect_commands']",
|
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-multi'][@var='after_connect_commands']",
|
||||||
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='nick']",
|
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='nick']",
|
||||||
@@ -2995,6 +2996,7 @@ if __name__ == '__main__':
|
|||||||
"<field var='after_connect_commands'><value>first command</value><value>second command</value></field>"
|
"<field var='after_connect_commands'><value>first command</value><value>second command</value></field>"
|
||||||
"<field var='nick'><value>my_nickname</value></field>"
|
"<field var='nick'><value>my_nickname</value></field>"
|
||||||
"<field var='username'><value>username</value></field>"
|
"<field var='username'><value>username</value></field>"
|
||||||
|
"<field var='throttle_limit'><value>42</value></field>"
|
||||||
"<field var='realname'><value>realname</value></field>"
|
"<field var='realname'><value>realname</value></field>"
|
||||||
"<field var='encoding_out'><value>UTF-8</value></field>"
|
"<field var='encoding_out'><value>UTF-8</value></field>"
|
||||||
"<field var='encoding_in'><value>latin-1</value></field>"
|
"<field var='encoding_in'><value>latin-1</value></field>"
|
||||||
@@ -3016,6 +3018,7 @@ if __name__ == '__main__':
|
|||||||
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-multi'][@var='after_connect_commands']/dataform:value[text()='second command']",
|
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-multi'][@var='after_connect_commands']/dataform:value[text()='second command']",
|
||||||
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='username']/dataform:value[text()='username']",
|
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='username']/dataform:value[text()='username']",
|
||||||
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='realname']/dataform:value[text()='realname']",
|
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='realname']/dataform:value[text()='realname']",
|
||||||
|
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='throttle_limit']/dataform:value[text()='42']",
|
||||||
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='encoding_in']/dataform:value[text()='latin-1']",
|
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='encoding_in']/dataform:value[text()='latin-1']",
|
||||||
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='encoding_out']/dataform:value[text()='UTF-8']",
|
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='encoding_out']/dataform:value[text()='UTF-8']",
|
||||||
"/iq/commands:command/commands:actions/commands:next",
|
"/iq/commands:command/commands:actions/commands:next",
|
||||||
@@ -3037,6 +3040,7 @@ if __name__ == '__main__':
|
|||||||
"<field var='after_connect_commands'></field>"
|
"<field var='after_connect_commands'></field>"
|
||||||
"<field var='username'><value></value></field>"
|
"<field var='username'><value></value></field>"
|
||||||
"<field var='realname'><value></value></field>"
|
"<field var='realname'><value></value></field>"
|
||||||
|
"<field var='throttle_limit'><value></value></field>"
|
||||||
"<field var='encoding_out'><value></value></field>"
|
"<field var='encoding_out'><value></value></field>"
|
||||||
"<field var='encoding_in'><value></value></field>"
|
"<field var='encoding_in'><value></value></field>"
|
||||||
"</x></command></iq>"),
|
"</x></command></iq>"),
|
||||||
@@ -3054,6 +3058,7 @@ if __name__ == '__main__':
|
|||||||
"!/iq/commands:command/dataform:x[@type='form']/dataform:field[@var='encoding_in']/dataform:value",
|
"!/iq/commands:command/dataform:x[@type='form']/dataform:field[@var='encoding_in']/dataform:value",
|
||||||
"!/iq/commands:command/dataform:x[@type='form']/dataform:field[@var='encoding_out']/dataform:value",
|
"!/iq/commands:command/dataform:x[@type='form']/dataform:field[@var='encoding_out']/dataform:value",
|
||||||
"/iq/commands:command/commands:actions/commands:next",
|
"/iq/commands:command/commands:actions/commands:next",
|
||||||
|
"/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='throttle_limit']/dataform:value[text()='-1']", # An invalid value sets this field to -1, aka disabled
|
||||||
),
|
),
|
||||||
after = partial(save_value, "sessionid", partial(extract_attribute, "/iq[@type='result']/commands:command[@node='configure']", "sessionid"))
|
after = partial(save_value, "sessionid", partial(extract_attribute, "/iq[@type='result']/commands:command[@node='configure']", "sessionid"))
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user