aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-12-31 00:48:38 +0100
committerKim Alvefur <zash@zash.se>2021-12-31 00:48:38 +0100
commitf017e61543ea64999ab9f770e3cc8313bedd1630 (patch)
treedc8d0f868a7a89b5e05a29b1580a4e3150e2df44 /plugins
parent88da8ef1a04a6541e7bd049315279bcbc96ef8a9 (diff)
downloadprosody-f017e61543ea64999ab9f770e3cc8313bedd1630.tar.gz
prosody-f017e61543ea64999ab9f770e3cc8313bedd1630.zip
mod_smacks: Limit "old" session resumption counters
Doing this when creating a whole new session seems reasonable because it is already expensive and this is when it may be adding to the old session store, while a successful resumption should be plus-minus zero.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_smacks.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/plugins/mod_smacks.lua b/plugins/mod_smacks.lua
index c6d33efa..aff898e5 100644
--- a/plugins/mod_smacks.lua
+++ b/plugins/mod_smacks.lua
@@ -52,6 +52,7 @@ local st = require "util.stanza";
local timer = require "util.timer";
local new_id = require "util.id".short;
local watchdog = require "util.watchdog";
+local it = require"util.iterators";
local sessionmanager = require "core.sessionmanager";
local core_process_stanza = prosody.core_process_stanza;
@@ -72,12 +73,14 @@ local s2s_resend = module:get_option_boolean("smacks_s2s_resend", false);
local max_unacked_stanzas = module:get_option_number("smacks_max_unacked_stanzas", 0);
local max_inactive_unacked_stanzas = module:get_option_number("smacks_max_inactive_unacked_stanzas", 256);
local delayed_ack_timeout = module:get_option_number("smacks_max_ack_delay", 30);
+local max_old_sessions = module:get_option_number("smacks_max_old_sessions", 10);
local c2s_sessions = module:shared("/*/c2s/sessions");
local local_sessions = prosody.hosts[module.host].sessions;
local function format_h(h) if h then return string.format("%d", h) end end
+local all_old_sessions = module:open_store("smacks_h");
local old_session_registry = module:open_store("smacks_h", "map");
local session_registry = module:shared "/*/smacks/resumption-tokens"; -- > user@host/resumption-token --> resource
@@ -281,6 +284,22 @@ function handle_enable(session, stanza, xmlns_sm)
return true;
end
+ if session.username then
+ local old_sessions, err = all_old_sessions:get(session.username);
+ module:log("debug", "Old sessions: %q", old_sessions)
+ if old_sessions then
+ local keep, count = {}, 0;
+ for token, info in it.sorted_pairs(old_sessions, function(a, b)
+ return (old_sessions[a].t or 0) > (old_sessions[b].t or 0);
+ end) do
+ count = count + 1;
+ if count > max_old_sessions then break end
+ keep[token] = info;
+ end
+ all_old_sessions:set(session.username, keep);
+ end
+ end
+
module:log("debug", "Enabling stream management");
session.smacks = xmlns_sm;