# HG changeset patch # User Kim Alvefur # Date 1689404981 -7200 # Node ID 6680a1f53353adac2340ad55a182f6de36538494 # Parent c799b460f9f0dfd31889ad88c3e82d68a9f65625 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. diff -r c799b460f9f0 -r 6680a1f53353 mod_muc_limits/README.markdown --- 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. diff -r c799b460f9f0 -r 6680a1f53353 mod_muc_limits/mod_muc_limits.lua --- 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);