comparison mod_smacks/mod_smacks.lua @ 4444:2f5e52d67928

mod_smacks: Do ask for acks while in CSI inactive mode, but less frequent Otherwise the unacked stanza queue just grows forever
author Kim Alvefur <zash@zash.se>
date Tue, 16 Feb 2021 21:33:39 +0100
parents 74da3643c62d
children e13eb0f851c8
comparison
equal deleted inserted replaced
4443:0a56dc6c61af 4444:2f5e52d67928
37 37
38 local resume_timeout = module:get_option_number("smacks_hibernation_time", 600); 38 local resume_timeout = module:get_option_number("smacks_hibernation_time", 600);
39 local s2s_smacks = module:get_option_boolean("smacks_enabled_s2s", false); 39 local s2s_smacks = module:get_option_boolean("smacks_enabled_s2s", false);
40 local s2s_resend = module:get_option_boolean("smacks_s2s_resend", false); 40 local s2s_resend = module:get_option_boolean("smacks_s2s_resend", false);
41 local max_unacked_stanzas = module:get_option_number("smacks_max_unacked_stanzas", 0); 41 local max_unacked_stanzas = module:get_option_number("smacks_max_unacked_stanzas", 0);
42 local max_inactive_unacked_stanzas = module:get_option_number("smacks_max_inactive_unacked_stanzas", 256);
42 local delayed_ack_timeout = module:get_option_number("smacks_max_ack_delay", 30); 43 local delayed_ack_timeout = module:get_option_number("smacks_max_ack_delay", 30);
43 local max_hibernated_sessions = module:get_option_number("smacks_max_hibernated_sessions", 10); 44 local max_hibernated_sessions = module:get_option_number("smacks_max_hibernated_sessions", 10);
44 local max_old_sessions = module:get_option_number("smacks_max_old_sessions", 10); 45 local max_old_sessions = module:get_option_number("smacks_max_old_sessions", 10);
45 local core_process_stanza = prosody.core_process_stanza; 46 local core_process_stanza = prosody.core_process_stanza;
46 local sessionmanager = require"core.sessionmanager"; 47 local sessionmanager = require"core.sessionmanager";
160 161
161 local function request_ack_if_needed(session, force, reason, stanza) 162 local function request_ack_if_needed(session, force, reason, stanza)
162 local queue = session.outgoing_stanza_queue; 163 local queue = session.outgoing_stanza_queue;
163 local expected_h = session.last_acknowledged_stanza + #queue; 164 local expected_h = session.last_acknowledged_stanza + #queue;
164 -- session.log("debug", "*** SMACKS(1) ***: awaiting_ack=%s, hibernating=%s", tostring(session.awaiting_ack), tostring(session.hibernating)); 165 -- session.log("debug", "*** SMACKS(1) ***: awaiting_ack=%s, hibernating=%s", tostring(session.awaiting_ack), tostring(session.hibernating));
165 if session.awaiting_ack == nil and not session.hibernating and session.state ~= "inactive" then 166 if session.awaiting_ack == nil and not session.hibernating then
167 local max_unacked = max_unacked_stanzas;
168 if session.state == "inactive" then
169 max_unacked = max_inactive_unacked_stanzas;
170 end
166 -- this check of last_requested_h prevents ack-loops if missbehaving clients report wrong 171 -- this check of last_requested_h prevents ack-loops if missbehaving clients report wrong
167 -- stanza counts. it is set when an <r> is really sent (e.g. inside timer), preventing any 172 -- stanza counts. it is set when an <r> is really sent (e.g. inside timer), preventing any
168 -- further requests until a higher h-value would be expected. 173 -- further requests until a higher h-value would be expected.
169 -- session.log("debug", "*** SMACKS(2) ***: #queue=%s, max_unacked_stanzas=%s, expected_h=%s, last_requested_h=%s", tostring(#queue), tostring(max_unacked_stanzas), tostring(expected_h), tostring(session.last_requested_h)); 174 -- session.log("debug", "*** SMACKS(2) ***: #queue=%s, max_unacked_stanzas=%s, expected_h=%s, last_requested_h=%s", tostring(#queue), tostring(max_unacked_stanzas), tostring(expected_h), tostring(session.last_requested_h));
170 if (#queue > max_unacked_stanzas and expected_h ~= session.last_requested_h) or force then 175 if (#queue > max_unacked and expected_h ~= session.last_requested_h) or force then
171 session.log("debug", "Queuing <r> (in a moment) from %s - #queue=%d", reason, #queue); 176 session.log("debug", "Queuing <r> (in a moment) from %s - #queue=%d", reason, #queue);
172 session.awaiting_ack = false; 177 session.awaiting_ack = false;
173 session.awaiting_ack_timer = stoppable_timer(1e-06, function () 178 session.awaiting_ack_timer = stoppable_timer(1e-06, function ()
174 -- session.log("debug", "*** SMACKS(3) ***: awaiting_ack=%s, hibernating=%s", tostring(session.awaiting_ack), tostring(session.hibernating)); 179 -- session.log("debug", "*** SMACKS(3) ***: awaiting_ack=%s, hibernating=%s", tostring(session.awaiting_ack), tostring(session.hibernating));
175 -- only request ack if needed and our session is not already hibernated or destroyed 180 -- only request ack if needed and our session is not already hibernated or destroyed