Software /
code /
prosody-modules
Comparison
mod_smacks/mod_smacks.lua @ 3107:f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
author | tmolitor <thilo@eightysoft.de> |
---|---|
date | Fri, 08 Jun 2018 17:38:24 +0200 |
parent | 3104:626d2c781c66 |
child | 3110:06e07b483805 |
comparison
equal
deleted
inserted
replaced
3106:1fe7da46e915 | 3107:f703cc6e72df |
---|---|
17 local uuid_generate = require "util.uuid".generate; | 17 local uuid_generate = require "util.uuid".generate; |
18 local jid = require "util.jid"; | 18 local jid = require "util.jid"; |
19 | 19 |
20 local t_insert, t_remove = table.insert, table.remove; | 20 local t_insert, t_remove = table.insert, table.remove; |
21 local math_min = math.min; | 21 local math_min = math.min; |
22 local math_max = math.max; | |
22 local os_time = os.time; | 23 local os_time = os.time; |
23 local tonumber, tostring = tonumber, tostring; | 24 local tonumber, tostring = tonumber, tostring; |
24 local add_filter = require "util.filters".add_filter; | 25 local add_filter = require "util.filters".add_filter; |
25 local timer = require "util.timer"; | 26 local timer = require "util.timer"; |
26 local datetime = require "util.datetime"; | 27 local datetime = require "util.datetime"; |
413 session.log("debug", "The session has already been destroyed"); | 414 session.log("debug", "The session has already been destroyed"); |
414 elseif curr_session and curr_session.resumption_token == resumption_token | 415 elseif curr_session and curr_session.resumption_token == resumption_token |
415 -- Check the hibernate time still matches what we think it is, | 416 -- Check the hibernate time still matches what we think it is, |
416 -- otherwise the session resumed and re-hibernated. | 417 -- otherwise the session resumed and re-hibernated. |
417 and session.hibernating == hibernate_time then | 418 and session.hibernating == hibernate_time then |
419 -- wait longer if the timeout isn't reached because push was enabled for this session | |
420 -- session.first_hibernated_push is the starting point for hibernation timeouts of those push enabled clients | |
421 -- wait for an additional resume_timeout seconds if no push occured since hibernation at all | |
422 local current_time = os_time(); | |
423 local timeout_start = math_max(session.hibernating, session.first_hibernated_push or session.hibernating); | |
424 if session.push_identifier ~= nil and not session.first_hibernated_push then | |
425 session.log("debug", "No push happened since hibernation started, hibernating session for up to %d extra seconds", resume_timeout); | |
426 return resume_timeout; | |
427 end | |
428 if current_time-timeout_start < resume_timeout and session.push_identifier ~= nil then | |
429 session.log("debug", "A push happened since hibernation started, hibernating session for up to %d extra seconds", current_time-timeout_start); | |
430 return current_time-timeout_start; -- time left to wait | |
431 end | |
418 session.log("debug", "Destroying session for hibernating too long"); | 432 session.log("debug", "Destroying session for hibernating too long"); |
419 session_registry.set(session.username, session.resumption_token, nil); | 433 session_registry.set(session.username, session.resumption_token, nil); |
420 -- save only actual h value and username/host (for security) | 434 -- save only actual h value and username/host (for security) |
421 old_session_registry.set(session.username, session.resumption_token, { | 435 old_session_registry.set(session.username, session.resumption_token, { |
422 h = session.handled_stanza_count, | 436 h = session.handled_stanza_count, |