comparison mod_smacks/mod_smacks.lua @ 3104:626d2c781c66

mod_smacks: send maximum resumption timeout to client
author Jonas Wielicki <jonas@wielicki.name>
date Thu, 07 Jun 2018 13:27:32 +0200
parents e672d1050529
children f703cc6e72df
comparison
equal deleted inserted replaced
3103:5bf79bb3cf7e 3104:626d2c781c66
60 if not key then return nil; end 60 if not key then return nil; end
61 store[key] = value; 61 store[key] = value;
62 end; 62 end;
63 }; 63 };
64 end 64 end
65 65
66 -- use per user limited cache for prosody >= 0.10 66 -- use per user limited cache for prosody >= 0.10
67 local stores = {}; 67 local stores = {};
68 return { 68 return {
69 get = function(user, key) 69 get = function(user, key)
70 if not user then return nil; end 70 if not user then return nil; end
170 end 170 end
171 end 171 end
172 end); 172 end);
173 end 173 end
174 end 174 end
175 175
176 -- Trigger "smacks-ack-delayed"-event if we added new (ackable) stanzas to the outgoing queue 176 -- Trigger "smacks-ack-delayed"-event if we added new (ackable) stanzas to the outgoing queue
177 -- and there isn't already a timer for this event running. 177 -- and there isn't already a timer for this event running.
178 -- If we wouldn't do this, stanzas added to the queue after the first "smacks-ack-delayed"-event 178 -- If we wouldn't do this, stanzas added to the queue after the first "smacks-ack-delayed"-event
179 -- would not trigger this event (again). 179 -- would not trigger this event (again).
180 if #queue > max_unacked_stanzas and session.awaiting_ack and session.delayed_ack_timer == nil then 180 if #queue > max_unacked_stanzas and session.awaiting_ack and session.delayed_ack_timer == nil then
181 session.log("debug", "Calling delayed_ack_function directly (still waiting for ack)"); 181 session.log("debug", "Calling delayed_ack_function directly (still waiting for ack)");
182 delayed_ack_function(session); 182 delayed_ack_function(session);
183 end 183 end
184 184
185 session.last_queue_count = #queue; 185 session.last_queue_count = #queue;
186 end 186 end
187 187
188 local function outgoing_stanza_filter(stanza, session) 188 local function outgoing_stanza_filter(stanza, session)
189 local is_stanza = stanza.attr and not stanza.attr.xmlns and not stanza.name:find":"; 189 local is_stanza = stanza.attr and not stanza.attr.xmlns and not stanza.name:find":";
276 if resume == "true" or resume == "1" then 276 if resume == "true" or resume == "1" then
277 resume_token = uuid_generate(); 277 resume_token = uuid_generate();
278 session_registry.set(session.username, resume_token, session); 278 session_registry.set(session.username, resume_token, session);
279 session.resumption_token = resume_token; 279 session.resumption_token = resume_token;
280 end 280 end
281 (session.sends2s or session.send)(st.stanza("enabled", { xmlns = xmlns_sm, id = resume_token, resume = resume })); 281 (session.sends2s or session.send)(st.stanza("enabled", { xmlns = xmlns_sm, id = resume_token, resume = resume, max = resume_timeout }));
282 return true; 282 return true;
283 end 283 end
284 module:hook_stanza(xmlns_sm2, "enable", function (session, stanza) return handle_enable(session, stanza, xmlns_sm2); end, 100); 284 module:hook_stanza(xmlns_sm2, "enable", function (session, stanza) return handle_enable(session, stanza, xmlns_sm2); end, 100);
285 module:hook_stanza(xmlns_sm3, "enable", function (session, stanza) return handle_enable(session, stanza, xmlns_sm3); end, 100); 285 module:hook_stanza(xmlns_sm3, "enable", function (session, stanza) return handle_enable(session, stanza, xmlns_sm3); end, 100);
286 286