Mercurial > prosody-modules
comparison mod_smacks/mod_smacks.lua @ 200:64a573203c20
mod_smacks: Better logic for deciding what is a stanza and what is not, and deciding when to send ack requests
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 08 Jul 2010 14:00:05 +0100 |
parents | 9a7671720dec |
children | bc24f58a0d39 |
comparison
equal
deleted
inserted
replaced
199:27b8a7482149 | 200:64a573203c20 |
---|---|
4 local tonumber, tostring = tonumber, tostring; | 4 local tonumber, tostring = tonumber, tostring; |
5 | 5 |
6 local xmlns_sm = "urn:xmpp:sm:2"; | 6 local xmlns_sm = "urn:xmpp:sm:2"; |
7 | 7 |
8 local sm_attr = { xmlns = xmlns_sm }; | 8 local sm_attr = { xmlns = xmlns_sm }; |
9 | |
10 local max_unacked_stanzas = 0; | |
9 | 11 |
10 module:add_event_hook("stream-features", | 12 module:add_event_hook("stream-features", |
11 function (session, features) | 13 function (session, features) |
12 features:tag("sm", sm_attr):tag("optional"):up():up(); | 14 features:tag("sm", sm_attr):tag("optional"):up():up(); |
13 end); | 15 end); |
32 queue_length = queue_length + 1; | 34 queue_length = queue_length + 1; |
33 session.outgoing_stanza_count = queue_length; | 35 session.outgoing_stanza_count = queue_length; |
34 queue[queue_length] = st.reply(stanza); | 36 queue[queue_length] = st.reply(stanza); |
35 end | 37 end |
36 local ok, err = _send(stanza); | 38 local ok, err = _send(stanza); |
37 if ok then | 39 if ok and queue_length > max_unacked_stanzas and not session.awaiting_ack then |
40 session.awaiting_ack = true; | |
38 return _send(st.stanza("r", { xmlns = xmlns_sm })); | 41 return _send(st.stanza("r", { xmlns = xmlns_sm })); |
39 end | 42 end |
40 return ok, err; | 43 return ok, err; |
41 end | 44 end |
42 _send(st.stanza("enabled", sm_attr)); | 45 _send(st.stanza("enabled", sm_attr)); |
54 return true; | 57 return true; |
55 end); | 58 end); |
56 | 59 |
57 module:hook_stanza(xmlns_sm, "a", function (origin, stanza) | 60 module:hook_stanza(xmlns_sm, "a", function (origin, stanza) |
58 if not origin.smacks then return; end | 61 if not origin.smacks then return; end |
59 | 62 origin.awaiting_ack = nil; |
60 -- Remove handled stanzas from outgoing_stanza_queue | 63 -- Remove handled stanzas from outgoing_stanza_queue |
61 local handled_stanza_count = tonumber(stanza.attr.h)+1; | 64 local handled_stanza_count = tonumber(stanza.attr.h)+1; |
62 for i=1,handled_stanza_count do | 65 for i=1,handled_stanza_count do |
63 t_remove(origin.outgoing_stanza_queue, 1); | 66 t_remove(origin.outgoing_stanza_queue, 1); |
64 end | 67 end |