Software /
code /
prosody-modules
Comparison
mod_smacks/mod_smacks.lua @ 640:d87131b29bbd
mod_smacks: Remove dependency on connlisteners (use sessions table shared by mod_c2s directly)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 28 Apr 2012 18:16:47 +0100 |
parent | 625:2c07bcf56a36 |
child | 641:06a78cba6499 |
comparison
equal
deleted
inserted
replaced
639:d4f3754c4286 | 640:d87131b29bbd |
---|---|
6 local os_time = os.time; | 6 local os_time = os.time; |
7 local tonumber, tostring = tonumber, tostring; | 7 local tonumber, tostring = tonumber, tostring; |
8 local add_filter = require "util.filters".add_filter; | 8 local add_filter = require "util.filters".add_filter; |
9 local timer = require "util.timer"; | 9 local timer = require "util.timer"; |
10 local datetime = require "util.datetime"; | 10 local datetime = require "util.datetime"; |
11 local connlisteners = require "net.connlisteners"; | |
12 | 11 |
13 local xmlns_sm = "urn:xmpp:sm:2"; | 12 local xmlns_sm = "urn:xmpp:sm:2"; |
14 local xmlns_errors = "urn:ietf:params:xml:ns:xmpp-stanzas"; | 13 local xmlns_errors = "urn:ietf:params:xml:ns:xmpp-stanzas"; |
15 local xmlns_delay = "urn:xmpp:delay"; | 14 local xmlns_delay = "urn:xmpp:delay"; |
16 | 15 |
18 | 17 |
19 local resume_timeout = module:get_option("smacks_hibernation_time", 300); | 18 local resume_timeout = module:get_option("smacks_hibernation_time", 300); |
20 local s2s_smacks = module:get_option_boolean("smacks_enabled_s2s", false); | 19 local s2s_smacks = module:get_option_boolean("smacks_enabled_s2s", false); |
21 local max_unacked_stanzas = 0; | 20 local max_unacked_stanzas = 0; |
22 | 21 |
22 local c2s_sessions = module:shared("/*/c2s/sessions"); | |
23 local session_registry = {}; | 23 local session_registry = {}; |
24 | 24 |
25 local function can_do_smacks(session, advertise_only) | 25 local function can_do_smacks(session, advertise_only) |
26 if session.smacks then return false, "unexpected-request", "Stream management is already enabled"; end | 26 if session.smacks then return false, "unexpected-request", "Stream management is already enabled"; end |
27 | 27 |
254 session.log("debug", "mod_smacks resuming existing session..."); | 254 session.log("debug", "mod_smacks resuming existing session..."); |
255 -- TODO: All this should move to sessionmanager (e.g. session:replace(new_session)) | 255 -- TODO: All this should move to sessionmanager (e.g. session:replace(new_session)) |
256 if original_session.conn then | 256 if original_session.conn then |
257 session.log("debug", "mod_smacks closing an old connection for this session"); | 257 session.log("debug", "mod_smacks closing an old connection for this session"); |
258 local conn = original_session.conn; | 258 local conn = original_session.conn; |
259 connlisteners.get("xmppclient").associate_session(conn, nil); | 259 c2s_sessions[conn] = nil; |
260 conn:close(); | 260 conn:close(); |
261 end | 261 end |
262 original_session.ip = session.ip; | 262 original_session.ip = session.ip; |
263 original_session.conn = session.conn; | 263 original_session.conn = session.conn; |
264 original_session.send = session.send; | 264 original_session.send = session.send; |
279 end | 279 end |
280 wrap_session(original_session, true); | 280 wrap_session(original_session, true); |
281 -- Inform xmppstream of the new session (passed to its callbacks) | 281 -- Inform xmppstream of the new session (passed to its callbacks) |
282 stream:set_session(original_session); | 282 stream:set_session(original_session); |
283 -- Similar for connlisteners | 283 -- Similar for connlisteners |
284 connlisteners.get("xmppclient").associate_session(session.conn, original_session); | 284 c2s_sessions[session.conn] = original_session; |
285 | 285 |
286 session.send(st.stanza("resumed", { xmlns = xmlns_sm, | 286 session.send(st.stanza("resumed", { xmlns = xmlns_sm, |
287 h = original_session.handled_stanza_count, previd = id })); | 287 h = original_session.handled_stanza_count, previd = id })); |
288 | 288 |
289 -- Fake an <a> with the h of the <resume/> from the client | 289 -- Fake an <a> with the h of the <resume/> from the client |