Changeset

5608:6680a1f53353

mod_muc_limits: Reduce cost of multi-line messages, make configurable Typing a 5-line message preceded by a few chat states would have hit the default limit.
author Kim Alvefur <zash@zash.se>
date Sat, 15 Jul 2023 09:09:41 +0200
parents 5607:c799b460f9f0
children 5609:bae2f4830a93
files mod_muc_limits/README.markdown mod_muc_limits/mod_muc_limits.lua
diffstat 2 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_limits/README.markdown	Fri Jul 14 16:20:54 2023 +0200
+++ b/mod_muc_limits/README.markdown	Sat Jul 15 09:09:41 2023 +0200
@@ -35,13 +35,15 @@
 
 You can define (globally or per-MUC component) the following options:
 
-  Name                  Default value   Description
-  --------------------- --------------- --------------------------------------------------
-  muc_event_rate        0.5             The maximum number of events per second.
-  muc_burst_factor      6               Allow temporary bursts of this multiple.
-  muc_max_nick_length   23              The maximum allowed length of user nicknames
-  muc_max_char_count    5664            The maximum allowed number of bytes in a message
-  muc_max_line_count    23              The maximum allowed number of lines in a message
+  Name                        Default value   Description
+  --------------------------- --------------- ----------------------------------------------------------
+  muc_event_rate              0.5             The maximum number of events per second.
+  muc_burst_factor            6               Allow temporary bursts of this multiple.
+  muc_max_nick_length         23              The maximum allowed length of user nicknames
+  muc_max_char_count          5664            The maximum allowed number of bytes in a message
+  muc_max_line_count          23              The maximum allowed number of lines in a message
+  muc_limit_base_cost         1               Base cost of sending a stanza
+  muc_line_count_multiplier   0.1             Additional cost of each newline in the body of a message
 
 For more understanding of how these values are used, see the algorithm
 section below.
--- a/mod_muc_limits/mod_muc_limits.lua	Fri Jul 14 16:20:54 2023 +0200
+++ b/mod_muc_limits/mod_muc_limits.lua	Sat Jul 15 09:09:41 2023 +0200
@@ -15,6 +15,8 @@
 local max_nick_length = module:get_option_number("muc_max_nick_length", 23); -- Default chosen through scientific methods
 local max_line_count = module:get_option_number("muc_max_line_count", 23); -- Default chosen through s/scientific methods/copy and paste/
 local max_char_count = module:get_option_number("muc_max_char_count", 5664); -- Default chosen by multiplying a number by 23
+local base_cost = math.max(module:get_option_number("muc_limit_base_cost", 1), 0);
+local line_multiplier = math.max(module:get_option_number("muc_line_count_multiplier", 0.1), 0);
 
 local join_only = module:get_option_boolean("muc_limit_joins_only", false);
 local dropped_count = 0;
@@ -49,7 +51,7 @@
 		throttle = new_throttle(period*burst, burst);
 		room.throttle = throttle;
 	end
-	local cost = 1;
+	local cost = base_cost;
 	local body = stanza:get_child_text("body");
 	if body then
 		-- TODO calculate a text diagonal cross-section or some mathemagical
@@ -65,7 +67,7 @@
 				:tag("x", { xmlns = xmlns_muc; }));
 			return true;
 		end
-		cost = cost + body_lines;
+		cost = cost + (body_lines * line_multiplier);
 	end
 	if not throttle:poll(cost) then
 		module:log("debug", "Dropping stanza for %s@%s from %s, over rate limit", dest_room, dest_host, from_jid);