Software /
code /
prosody-modules
Comparison
mod_smacks/mod_smacks.lua @ 1408:ed2a9c00b5c4
mod_smacks: Impose a limit on number of unacked stanzas (Thanks Holger)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 07 May 2014 16:18:05 +0200 |
parent | 1407:b631c8a8b9e7 |
child | 1416:7ddb522d9b28 |
comparison
equal
deleted
inserted
replaced
1407:b631c8a8b9e7 | 1408:ed2a9c00b5c4 |
---|---|
17 local sm2_attr = { xmlns = xmlns_sm2 }; | 17 local sm2_attr = { xmlns = xmlns_sm2 }; |
18 local sm3_attr = { xmlns = xmlns_sm3 }; | 18 local sm3_attr = { xmlns = xmlns_sm3 }; |
19 | 19 |
20 local resume_timeout = module:get_option_number("smacks_hibernation_time", 300); | 20 local resume_timeout = module:get_option_number("smacks_hibernation_time", 300); |
21 local s2s_smacks = module:get_option_boolean("smacks_enabled_s2s", false); | 21 local s2s_smacks = module:get_option_boolean("smacks_enabled_s2s", false); |
22 local max_queue_size = module:get_option_number("smacks_max_queue_size", 500); | |
22 local max_unacked_stanzas = module:get_option_number("smacks_max_unacked_stanzas", 0); | 23 local max_unacked_stanzas = module:get_option_number("smacks_max_unacked_stanzas", 0); |
23 local core_process_stanza = prosody.core_process_stanza; | 24 local core_process_stanza = prosody.core_process_stanza; |
24 local sessionmanager = require"core.sessionmanager"; | 25 local sessionmanager = require"core.sessionmanager"; |
25 | 26 |
26 local c2s_sessions = module:shared("/*/c2s/sessions"); | 27 local c2s_sessions = module:shared("/*/c2s/sessions"); |
88 | 89 |
89 if cached_stanza and cached_stanza:get_child("delay", xmlns_delay) == nil then | 90 if cached_stanza and cached_stanza:get_child("delay", xmlns_delay) == nil then |
90 cached_stanza = cached_stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()}); | 91 cached_stanza = cached_stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()}); |
91 end | 92 end |
92 | 93 |
94 if max_queue_size > 0 and #queue > max_queue_size then | |
95 session.log("warn", "Too many unacked stanzas"); | |
96 session:close{ condition = "policy-violation"; text = "Too many unacked stanzas"; }; | |
97 end | |
93 queue[#queue+1] = cached_stanza; | 98 queue[#queue+1] = cached_stanza; |
94 session.log("debug", "#queue = %d", #queue); | 99 session.log("debug", "#queue = %d", #queue); |
95 end | 100 end |
96 if session.hibernating then | 101 if session.hibernating then |
97 session.log("debug", "hibernating, stanza queued") | 102 session.log("debug", "hibernating, stanza queued") |