# HG changeset patch # User Kim Alvefur # Date 1399472285 -7200 # Node ID ed2a9c00b5c4f0f3fb0d39c024427e8d2279cba7 # Parent b631c8a8b9e7e150cd3e51e07dba246a36da7b8f mod_smacks: Impose a limit on number of unacked stanzas (Thanks Holger) diff -r b631c8a8b9e7 -r ed2a9c00b5c4 mod_smacks/mod_smacks.lua --- a/mod_smacks/mod_smacks.lua Wed May 07 14:21:33 2014 +0200 +++ b/mod_smacks/mod_smacks.lua Wed May 07 16:18:05 2014 +0200 @@ -19,6 +19,7 @@ local resume_timeout = module:get_option_number("smacks_hibernation_time", 300); local s2s_smacks = module:get_option_boolean("smacks_enabled_s2s", false); +local max_queue_size = module:get_option_number("smacks_max_queue_size", 500); local max_unacked_stanzas = module:get_option_number("smacks_max_unacked_stanzas", 0); local core_process_stanza = prosody.core_process_stanza; local sessionmanager = require"core.sessionmanager"; @@ -90,6 +91,10 @@ cached_stanza = cached_stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()}); end + if max_queue_size > 0 and #queue > max_queue_size then + session.log("warn", "Too many unacked stanzas"); + session:close{ condition = "policy-violation"; text = "Too many unacked stanzas"; }; + end queue[#queue+1] = cached_stanza; session.log("debug", "#queue = %d", #queue); end