Comparison

mod_smacks/mod_smacks.lua @ 576:44b69c3d5351

mod_smacks: Fix smacks on s2s connections, but disable it by default.
author Kim Alvefur <zash@zash.se>
date Tue, 24 Jan 2012 14:56:00 +0100
parent 478:db0f065c4e09
child 586:f733e7599ed6
comparison
equal deleted inserted replaced
575:565d5409c6ca 576:44b69c3d5351
12 local xmlns_errors = "urn:ietf:params:xml:ns:xmpp-stanzas"; 12 local xmlns_errors = "urn:ietf:params:xml:ns:xmpp-stanzas";
13 13
14 local sm_attr = { xmlns = xmlns_sm }; 14 local sm_attr = { xmlns = xmlns_sm };
15 15
16 local resume_timeout = module:get_option("smacks_hibernation_time", 300); 16 local resume_timeout = module:get_option("smacks_hibernation_time", 300);
17 local s2s_smacks = module:get_option_boolean("smacks_enabled_s2s", false);
17 local max_unacked_stanzas = 0; 18 local max_unacked_stanzas = 0;
18 19
19 local session_registry = {}; 20 local session_registry = {};
20 21
21 module:hook("stream-features", 22 module:hook("stream-features",
23 event.features:tag("sm", sm_attr):tag("optional"):up():up(); 24 event.features:tag("sm", sm_attr):tag("optional"):up():up();
24 end); 25 end);
25 26
26 module:hook("s2s-stream-features", 27 module:hook("s2s-stream-features",
27 function (event) 28 function (event)
28 event.features:tag("sm", sm_attr):tag("optional"):up():up(); 29 local origin = event.origin;
30 if s2s_smacks and (origin.type == "s2sin" or origin.type == "s2sout") then
31 event.features:tag("sm", sm_attr):tag("optional"):up():up();
32 end
29 end); 33 end);
30 34
31 module:hook_stanza("http://etherx.jabber.org/streams", "features", 35 module:hook_stanza("http://etherx.jabber.org/streams", "features",
32 function (session, stanza) 36 function (session, stanza)
33 if not session.smacks and stanza:get_child("sm", xmlns_sm) then 37 if s2s_smacks and (session.type == "s2sin" or session.type == "s2sout")
34 session.send(st.stanza("enable", sm_attr)); 38 and not session.smacks and stanza:get_child("sm", xmlns_sm) then
39 session.sends2s(st.stanza("enable", sm_attr));
35 end 40 end
36 end); 41 end);
37 42
38 local function wrap_session(session, resume) 43 local function wrap_session(session, resume)
39 -- Overwrite process_stanza() and send() 44 -- Overwrite process_stanza() and send()
91 if resume == "true" or resume == "1" then 96 if resume == "true" or resume == "1" then
92 resume_token = uuid_generate(); 97 resume_token = uuid_generate();
93 session_registry[resume_token] = session; 98 session_registry[resume_token] = session;
94 session.resumption_token = resume_token; 99 session.resumption_token = resume_token;
95 end 100 end
96 session.send(st.stanza("enabled", { xmlns = xmlns_sm, id = resume_token, resume = resume })); 101 (session.sends2s or session.send)(st.stanza("enabled", { xmlns = xmlns_sm, id = resume_token, resume = resume }));
102 return true;
103 end, 100);
104
105 module:hook_stanza(xmlns_sm, "enabled", function (session, stanza)
106 module:log("debug", "Enabling stream management");
107 session.smacks = true;
108
109 wrap_session(session);
110
111 -- FIXME Resume?
112
97 return true; 113 return true;
98 end, 100); 114 end, 100);
99 115
100 module:hook_stanza(xmlns_sm, "r", function (origin, stanza) 116 module:hook_stanza(xmlns_sm, "r", function (origin, stanza)
101 if not origin.smacks then 117 if not origin.smacks then