diff options
author | Kim Alvefur <zash@zash.se> | 2020-05-07 21:55:29 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2020-05-07 21:55:29 +0200 |
commit | 5593dc204fa3637aadc1e97bef7b17d4dc3c696b (patch) | |
tree | 711efcbe684475d4208f85a9562a58ce758a9eec /plugins | |
parent | 0de207dbbd153fe2d254c2b33a3417cd3d4a3ace (diff) | |
download | prosody-5593dc204fa3637aadc1e97bef7b17d4dc3c696b.tar.gz prosody-5593dc204fa3637aadc1e97bef7b17d4dc3c696b.zip |
mod_csi_simple: Refactor to allow logging reason for buffer flush
Same style as mod_mam and mod_carbons allows easy comparison.
BC: Log format changes
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/mod_csi_simple.lua | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua index 05650957..7b8b3741 100644 --- a/plugins/mod_csi_simple.lua +++ b/plugins/mod_csi_simple.lua @@ -15,8 +15,7 @@ local queue_size = module:get_option_number("csi_queue_size", 256); local important_payloads = module:get_option_set("csi_important_payloads", { }); -module:hook("csi-is-stanza-important", function (event) - local stanza = event.stanza; +function is_important(stanza) --> boolean, reason: string if not st.is_stanza(stanza) then -- whitespace pings etc return true; @@ -69,8 +68,23 @@ module:hook("csi-is-stanza-important", function (event) elseif st_name == "iq" then return true; end +end + +module:hook("csi-is-stanza-important", function (event) + local important, why = is_important(event.stanza); + event.reason = why; + return important; end, -1); +local function should_flush(stanza, session, ctr) --> boolean, reason: string + if ctr >= queue_size then + return true, "queue size limit reached"; + end + local event = { stanza = stanza, session = session }; + local ret = module:fire_event("csi-is-stanza-important", event) + return ret, event.reason; +end + local function with_timestamp(stanza, from) if st.is_stanza(stanza) and stanza.attr.xmlns == nil and stanza.name ~= "iq" then stanza = st.clone(stanza); @@ -81,11 +95,9 @@ end local function manage_buffer(stanza, session) local ctr = session.csi_counter or 0; - if ctr >= queue_size then - session.log("debug", "Queue size limit hit, flushing buffer (queue size is %d)", session.csi_counter); - session.conn:resume_writes(); - elseif module:fire_event("csi-is-stanza-important", { stanza = stanza, session = session }) then - session.log("debug", "Important stanza, flushing buffer (queue size is %d)", session.csi_counter); + local flush, why = should_flush(stanza, session, ctr); + if flush then + session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter); session.conn:resume_writes(); else stanza = with_timestamp(stanza, jid.join(session.username, session.host)) |