Mercurial > prosody-modules
comparison mod_smacks/mod_smacks.lua @ 2098:1124758cac7f
Merge
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 16 Mar 2016 12:55:47 +0000 |
parents | ea95637cf041 |
children | 3f788f18cc10 |
comparison
equal
deleted
inserted
replaced
2097:4454f124465a | 2098:1124758cac7f |
---|---|
83 | 83 |
84 queue[#queue+1] = cached_stanza; | 84 queue[#queue+1] = cached_stanza; |
85 session.log("debug", "#queue = %d", #queue); | 85 session.log("debug", "#queue = %d", #queue); |
86 if session.hibernating then | 86 if session.hibernating then |
87 session.log("debug", "hibernating, stanza queued"); | 87 session.log("debug", "hibernating, stanza queued"); |
88 return ""; -- Hack to make session.send() not return nil | 88 return nil; |
89 end | 89 end |
90 if #queue > max_unacked_stanzas and not session.awaiting_ack then | 90 if #queue > max_unacked_stanzas and not session.awaiting_ack then |
91 session.awaiting_ack = true; | 91 session.log("debug", "Queuing <r> (in a moment)"); |
92 return tostring(stanza)..tostring(st.stanza("r", { xmlns = session.smacks })); | 92 session.awaiting_ack_timer = module:add_timer(1e-06, function () |
93 if not session.awaiting_ack then | |
94 session.awaiting_ack = true; | |
95 session.log("debug", "Sending <r> (after send)"); | |
96 (session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks })) | |
97 end | |
98 end); | |
93 end | 99 end |
94 end | 100 end |
95 return stanza; | 101 return stanza; |
96 end | 102 end |
97 | 103 |
163 module:hook_stanza(xmlns_sm2, "enable", function (session, stanza) return handle_enable(session, stanza, xmlns_sm2); end, 100); | 169 module:hook_stanza(xmlns_sm2, "enable", function (session, stanza) return handle_enable(session, stanza, xmlns_sm2); end, 100); |
164 module:hook_stanza(xmlns_sm3, "enable", function (session, stanza) return handle_enable(session, stanza, xmlns_sm3); end, 100); | 170 module:hook_stanza(xmlns_sm3, "enable", function (session, stanza) return handle_enable(session, stanza, xmlns_sm3); end, 100); |
165 | 171 |
166 module:hook_stanza("http://etherx.jabber.org/streams", "features", | 172 module:hook_stanza("http://etherx.jabber.org/streams", "features", |
167 function (session, stanza) | 173 function (session, stanza) |
168 module:add_timer(0, function () | 174 module:add_timer(1e-6, function () |
169 if can_do_smacks(session) then | 175 if can_do_smacks(session) then |
170 if stanza:get_child("sm", xmlns_sm3) then | 176 if stanza:get_child("sm", xmlns_sm3) then |
171 session.sends2s(st.stanza("enable", sm3_attr)); | 177 session.sends2s(st.stanza("enable", sm3_attr)); |
172 session.smacks = xmlns_sm3; | 178 session.smacks = xmlns_sm3; |
173 elseif stanza:get_child("sm", xmlns_sm2) then | 179 elseif stanza:get_child("sm", xmlns_sm2) then |
208 module:hook_stanza(xmlns_sm3, "r", function (origin, stanza) return handle_r(origin, stanza, xmlns_sm3); end); | 214 module:hook_stanza(xmlns_sm3, "r", function (origin, stanza) return handle_r(origin, stanza, xmlns_sm3); end); |
209 | 215 |
210 function handle_a(origin, stanza) | 216 function handle_a(origin, stanza) |
211 if not origin.smacks then return; end | 217 if not origin.smacks then return; end |
212 origin.awaiting_ack = nil; | 218 origin.awaiting_ack = nil; |
219 if origin.awaiting_ack_timer then | |
220 origin.awaiting_ack_timer:stop(); | |
221 end | |
213 -- Remove handled stanzas from outgoing_stanza_queue | 222 -- Remove handled stanzas from outgoing_stanza_queue |
214 --log("debug", "ACK: h=%s, last=%s", stanza.attr.h or "", origin.last_acknowledged_stanza or ""); | 223 --log("debug", "ACK: h=%s, last=%s", stanza.attr.h or "", origin.last_acknowledged_stanza or ""); |
215 local h = tonumber(stanza.attr.h); | 224 local h = tonumber(stanza.attr.h); |
216 if not h then | 225 if not h then |
217 origin:close{ condition = "invalid-xml"; text = "Missing or invalid 'h' attribute"; }; | 226 origin:close{ condition = "invalid-xml"; text = "Missing or invalid 'h' attribute"; }; |
388 | 397 |
389 local function handle_read_timeout(event) | 398 local function handle_read_timeout(event) |
390 local session = event.session; | 399 local session = event.session; |
391 if session.smacks then | 400 if session.smacks then |
392 if session.awaiting_ack then | 401 if session.awaiting_ack then |
402 if session.awaiting_ack_timer then | |
403 session.awaiting_ack_timer:stop(); | |
404 end | |
393 return false; -- Kick the session | 405 return false; -- Kick the session |
394 end | 406 end |
407 session.log("debug", "Sending <r> (read timeout)"); | |
395 (session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks })); | 408 (session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks })); |
396 session.awaiting_ack = true; | 409 session.awaiting_ack = true; |
397 return true; | 410 return true; |
398 end | 411 end |
399 end | 412 end |