Mercurial > prosody-modules
annotate mod_smacks/mod_smacks.lua @ 3564:35f1dbc943d8
mod_inject_ecaps2: Add a compatibility table.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 24 Apr 2019 11:00:17 +0200 |
parents | 3d4eefdd950a |
children | fb1c8dee2ead |
rev | line source |
---|---|
1670 | 1 -- XEP-0198: Stream Management for Prosody IM |
2 -- | |
3 -- Copyright (C) 2010-2015 Matthew Wild | |
4 -- Copyright (C) 2010 Waqas Hussain | |
5 -- Copyright (C) 2012-2015 Kim Alvefur | |
6 -- Copyright (C) 2012 Thijs Alkemade | |
7 -- Copyright (C) 2014 Florian Zeitz | |
2491
5fbca7de2088
mod_smacks: Send out more ack requests where needed
tmolitor <thilo@eightysoft.de>
parents:
2417
diff
changeset
|
8 -- Copyright (C) 2016-2017 Thilo Molitor |
1670 | 9 -- |
10 -- This project is MIT/X11 licensed. Please see the | |
11 -- COPYING file in the source package for more information. | |
12 -- | |
13 | |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local st = require "util.stanza"; |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
15 local dep = require "util.dependencies"; |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
16 local cache = dep.softreq("util.cache"); -- only available in prosody 0.10+ |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
17 local uuid_generate = require "util.uuid".generate; |
2756 | 18 local jid = require "util.jid"; |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local t_insert, t_remove = table.insert, table.remove; |
220
263858d40ceb
mod_smacks: Fix the logic for handling outgoing stanzas and ack requests
Matthew Wild <mwild1@gmail.com>
parents:
202
diff
changeset
|
21 local math_min = math.min; |
3107
f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
tmolitor <thilo@eightysoft.de>
parents:
3104
diff
changeset
|
22 local math_max = math.max; |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
23 local os_time = os.time; |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 local tonumber, tostring = tonumber, tostring; |
201
bc24f58a0d39
mod_smacks: Use filters for catching incoming stanzas (more reliable and efficient), also add some logic to make compatible with the stream resumption module (coming soon)
Matthew Wild <mwild1@gmail.com>
parents:
200
diff
changeset
|
25 local add_filter = require "util.filters".add_filter; |
257
08fa42e1ab06
mod_smacks: Fixes for monkey-patched sessionmanager.destroy to handle stream resumption, and to fall back to stock destroy() if the session is not smacks-enabled.
Matthew Wild <mwild1@gmail.com>
parents:
256
diff
changeset
|
26 local timer = require "util.timer"; |
593
db2a40cbd6ef
Add a <delay> to stanzas that are queued (and don't have one already), so clients can show them with the original timestamp.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
592
diff
changeset
|
27 local datetime = require "util.datetime"; |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
29 local xmlns_sm2 = "urn:xmpp:sm:2"; |
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
30 local xmlns_sm3 = "urn:xmpp:sm:3"; |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
31 local xmlns_errors = "urn:ietf:params:xml:ns:xmpp-stanzas"; |
593
db2a40cbd6ef
Add a <delay> to stanzas that are queued (and don't have one already), so clients can show them with the original timestamp.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
592
diff
changeset
|
32 local xmlns_delay = "urn:xmpp:delay"; |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
34 local sm2_attr = { xmlns = xmlns_sm2 }; |
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
35 local sm3_attr = { xmlns = xmlns_sm3 }; |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 |
641
06a78cba6499
mod_smacks: get_option+_number
Matthew Wild <mwild1@gmail.com>
parents:
640
diff
changeset
|
37 local resume_timeout = module:get_option_number("smacks_hibernation_time", 300); |
576
44b69c3d5351
mod_smacks: Fix smacks on s2s connections, but disable it by default.
Kim Alvefur <zash@zash.se>
parents:
478
diff
changeset
|
38 local s2s_smacks = module:get_option_boolean("smacks_enabled_s2s", false); |
1881
3683eb95bc1a
mod_smacks: Add experimental resending of unacked messages in s2s queues (disabled by default)
Kim Alvefur <zash@zash.se>
parents:
1733
diff
changeset
|
39 local s2s_resend = module:get_option_boolean("smacks_s2s_resend", false); |
642
842a8a3b0d81
mod_smacks: Make smacks_max_unacked_stanzas configurable
Matthew Wild <mwild1@gmail.com>
parents:
641
diff
changeset
|
40 local max_unacked_stanzas = module:get_option_number("smacks_max_unacked_stanzas", 0); |
2394
4c27ebcf4cbd
mod_smacks: added new event "smacks-ack-delayed" used by mod_cloud_notify and extended the readme file accordingly (also mention mod_smacks_offline and mod_smacks_noerror in readme file)
tmolitor <thilo@eightysoft.de>
parents:
2251
diff
changeset
|
41 local delayed_ack_timeout = module:get_option_number("smacks_max_ack_delay", 60); |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
42 local max_hibernated_sessions = module:get_option_number("smacks_max_hibernated_sessions", 10); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
43 local max_old_sessions = module:get_option_number("smacks_max_old_sessions", 10); |
754
713c6791fbcc
mod_smacks: Import prosody.core_process_stanza()
Kim Alvefur <zash@zash.se>
parents:
642
diff
changeset
|
44 local core_process_stanza = prosody.core_process_stanza; |
757
92c6f84ec446
mod_smacks: Use require to import (thanks a lot, autocomplete)
Kim Alvefur <zash@zash.se>
parents:
756
diff
changeset
|
45 local sessionmanager = require"core.sessionmanager"; |
200
64a573203c20
mod_smacks: Better logic for deciding what is a stanza and what is not, and deciding when to send ack requests
Matthew Wild <mwild1@gmail.com>
parents:
160
diff
changeset
|
46 |
3493
3d4eefdd950a
mod_smacks: Raise error on out-of-range config options (thanks marc0s)
Matthew Wild <mwild1@gmail.com>
parents:
3479
diff
changeset
|
47 assert(max_hibernated_sessions > 0, "smacks_max_hibernated_sessions must be greater than 0"); |
3d4eefdd950a
mod_smacks: Raise error on out-of-range config options (thanks marc0s)
Matthew Wild <mwild1@gmail.com>
parents:
3479
diff
changeset
|
48 assert(max_old_sessions > 0, "smacks_old_sessions must be greater than 0"); |
3d4eefdd950a
mod_smacks: Raise error on out-of-range config options (thanks marc0s)
Matthew Wild <mwild1@gmail.com>
parents:
3479
diff
changeset
|
49 |
640
d87131b29bbd
mod_smacks: Remove dependency on connlisteners (use sessions table shared by mod_c2s directly)
Matthew Wild <mwild1@gmail.com>
parents:
625
diff
changeset
|
50 local c2s_sessions = module:shared("/*/c2s/sessions"); |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
51 |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
52 local function init_session_cache(max_entries, evict_callback) |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
53 -- old prosody version < 0.10 (no limiting at all!) |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
54 if not cache then |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
55 local store = {}; |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
56 return { |
2701 | 57 get = function(user, key) |
58 if not user then return nil; end | |
59 if not key then return nil; end | |
60 return store[key]; | |
61 end; | |
62 set = function(user, key, value) | |
63 if not user then return nil; end | |
64 if not key then return nil; end | |
65 store[key] = value; | |
66 end; | |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
67 }; |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
68 end |
3104
626d2c781c66
mod_smacks: send maximum resumption timeout to client
Jonas Wielicki <jonas@wielicki.name>
parents:
2937
diff
changeset
|
69 |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
70 -- use per user limited cache for prosody >= 0.10 |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
71 local stores = {}; |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
72 return { |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
73 get = function(user, key) |
2701 | 74 if not user then return nil; end |
75 if not key then return nil; end | |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
76 if not stores[user] then |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
77 stores[user] = cache.new(max_entries, evict_callback); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
78 end |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
79 return stores[user]:get(key); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
80 end; |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
81 set = function(user, key, value) |
2701 | 82 if not user then return nil; end |
83 if not key then return nil; end | |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
84 if not stores[user] then stores[user] = cache.new(max_entries, evict_callback); end |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
85 stores[user]:set(key, value); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
86 -- remove empty caches completely |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
87 if not stores[user]:count() then stores[user] = nil; end |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
88 end; |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
89 }; |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
90 end |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
91 local old_session_registry = init_session_cache(max_old_sessions, nil); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
92 local session_registry = init_session_cache(max_hibernated_sessions, function(resumption_token, session) |
2701 | 93 if session.destroyed then return true; end -- destroyed session can always be removed from cache |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
94 session.log("warn", "User has too much hibernated sessions, removing oldest session (token: %s)", resumption_token); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
95 -- store old session's h values on force delete |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
96 -- save only actual h value and username/host (for security) |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
97 old_session_registry.set(session.username, resumption_token, { |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
98 h = session.handled_stanza_count, |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
99 username = session.username, |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
100 host = session.host |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
101 }); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
102 return true; -- allow session to be removed from full cache to make room for new one |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
103 end); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
104 |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
105 local function stoppable_timer(delay, callback) |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
106 local stopped = false; |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
107 return { |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
108 stop = function () stopped = true end; |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
109 module:add_timer(delay, function (t) |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
110 if stopped then return; end |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
111 return callback(t); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
112 end); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
113 }; |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
114 end |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
115 |
2394
4c27ebcf4cbd
mod_smacks: added new event "smacks-ack-delayed" used by mod_cloud_notify and extended the readme file accordingly (also mention mod_smacks_offline and mod_smacks_noerror in readme file)
tmolitor <thilo@eightysoft.de>
parents:
2251
diff
changeset
|
116 local function delayed_ack_function(session) |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
117 -- fire event only if configured to do so and our session is not hibernated or destroyed |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
118 if delayed_ack_timeout > 0 and session.awaiting_ack |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
119 and not session.hibernating and not session.destroyed then |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
120 session.log("debug", "Firing event 'smacks-ack-delayed', queue = %d", |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
121 session.outgoing_stanza_queue and #session.outgoing_stanza_queue or 0); |
2394
4c27ebcf4cbd
mod_smacks: added new event "smacks-ack-delayed" used by mod_cloud_notify and extended the readme file accordingly (also mention mod_smacks_offline and mod_smacks_noerror in readme file)
tmolitor <thilo@eightysoft.de>
parents:
2251
diff
changeset
|
122 module:fire_event("smacks-ack-delayed", {origin = session, queue = session.outgoing_stanza_queue}); |
4c27ebcf4cbd
mod_smacks: added new event "smacks-ack-delayed" used by mod_cloud_notify and extended the readme file accordingly (also mention mod_smacks_offline and mod_smacks_noerror in readme file)
tmolitor <thilo@eightysoft.de>
parents:
2251
diff
changeset
|
123 end |
2494
d300ae5dba87
mod_smacks: Fix some bugs with smacks-ack-delayed event triggering.
tmolitor <thilo@eightysoft.de>
parents:
2491
diff
changeset
|
124 session.delayed_ack_timer = nil; |
2394
4c27ebcf4cbd
mod_smacks: added new event "smacks-ack-delayed" used by mod_cloud_notify and extended the readme file accordingly (also mention mod_smacks_offline and mod_smacks_noerror in readme file)
tmolitor <thilo@eightysoft.de>
parents:
2251
diff
changeset
|
125 end |
4c27ebcf4cbd
mod_smacks: added new event "smacks-ack-delayed" used by mod_cloud_notify and extended the readme file accordingly (also mention mod_smacks_offline and mod_smacks_noerror in readme file)
tmolitor <thilo@eightysoft.de>
parents:
2251
diff
changeset
|
126 |
591
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
127 local function can_do_smacks(session, advertise_only) |
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
128 if session.smacks then return false, "unexpected-request", "Stream management is already enabled"; end |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1325
diff
changeset
|
129 |
591
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
130 local session_type = session.type; |
2417
5e7badecf7fe
mod_smacks: Check if a session is an authenticated c2s session by looking for a username (fix for change in 0.10 9f70d35a1602)
Kim Alvefur <zash@zash.se>
parents:
2394
diff
changeset
|
131 if session.username then |
591
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
132 if not(advertise_only) and not(session.resource) then -- Fail unless we're only advertising sm |
592
f9c73c1249cd
Update smacks to urn:xmpp:sm:3. Fix typo in can_do_smacks.
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
591
diff
changeset
|
133 return false, "unexpected-request", "Client must bind a resource before enabling stream management"; |
591
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
134 end |
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
135 return true; |
595
7693724881b3
Fix a typo in mod_smacks (type -> session_type).
Thijs Alkemade <thijsalkemade@gmail.com>
parents:
594
diff
changeset
|
136 elseif s2s_smacks and (session_type == "s2sin" or session_type == "s2sout") then |
591
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
137 return true; |
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
138 end |
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
139 return false, "service-unavailable", "Stream management is not available for this stream"; |
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
140 end |
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
141 |
263
41f1cac40560
mod_smacks: Fixed to use the correct events API.
Waqas Hussain <waqas20@gmail.com>
parents:
258
diff
changeset
|
142 module:hook("stream-features", |
41f1cac40560
mod_smacks: Fixed to use the correct events API.
Waqas Hussain <waqas20@gmail.com>
parents:
258
diff
changeset
|
143 function (event) |
591
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
144 if can_do_smacks(event.origin, true) then |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
145 event.features:tag("sm", sm2_attr):tag("optional"):up():up(); |
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
146 event.features:tag("sm", sm3_attr):tag("optional"):up():up(); |
589
57ac609444c4
mod_smacks: Only advertise stream features when a stream is authenticated, and doesn't already have smacks enabled
Matthew Wild <mwild1@gmail.com>
parents:
588
diff
changeset
|
147 end |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 end); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 module:hook("s2s-stream-features", |
263
41f1cac40560
mod_smacks: Fixed to use the correct events API.
Waqas Hussain <waqas20@gmail.com>
parents:
258
diff
changeset
|
151 function (event) |
591
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
152 if can_do_smacks(event.origin, true) then |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
153 event.features:tag("sm", sm2_attr):tag("optional"):up():up(); |
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
154 event.features:tag("sm", sm3_attr):tag("optional"):up():up(); |
576
44b69c3d5351
mod_smacks: Fix smacks on s2s connections, but disable it by default.
Kim Alvefur <zash@zash.se>
parents:
478
diff
changeset
|
155 end |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 end); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 |
3478
f6319346e2a3
mod_smacks: improved debug logging
Georg Lukas <georg@op-co.de>
parents:
3477
diff
changeset
|
158 local function request_ack_if_needed(session, force, reason) |
2491
5fbca7de2088
mod_smacks: Send out more ack requests where needed
tmolitor <thilo@eightysoft.de>
parents:
2417
diff
changeset
|
159 local queue = session.outgoing_stanza_queue; |
2727
91cbeb6ad987
mod_smacks: don't send out <r> when already hibernating
tmolitor <thilo@eightysoft.de>
parents:
2713
diff
changeset
|
160 if session.awaiting_ack == nil and not session.hibernating then |
2624
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
161 if (#queue > max_unacked_stanzas and session.last_queue_count ~= #queue) or force then |
3478
f6319346e2a3
mod_smacks: improved debug logging
Georg Lukas <georg@op-co.de>
parents:
3477
diff
changeset
|
162 session.log("debug", "Queuing <r> (in a moment) from %s - #queue=%d", reason, #queue); |
2624
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
163 session.awaiting_ack = false; |
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
164 session.awaiting_ack_timer = stoppable_timer(1e-06, function () |
2727
91cbeb6ad987
mod_smacks: don't send out <r> when already hibernating
tmolitor <thilo@eightysoft.de>
parents:
2713
diff
changeset
|
165 if not session.awaiting_ack and not session.hibernating then |
2624
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
166 session.log("debug", "Sending <r> (inside timer, before send)"); |
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
167 (session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks })) |
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
168 session.log("debug", "Sending <r> (inside timer, after send)"); |
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
169 session.awaiting_ack = true; |
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
170 if not session.delayed_ack_timer then |
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
171 session.delayed_ack_timer = stoppable_timer(delayed_ack_timeout, function() |
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
172 delayed_ack_function(session); |
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
173 end); |
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
174 end |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
175 end |
2624
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
176 end); |
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
177 end |
2491
5fbca7de2088
mod_smacks: Send out more ack requests where needed
tmolitor <thilo@eightysoft.de>
parents:
2417
diff
changeset
|
178 end |
3104
626d2c781c66
mod_smacks: send maximum resumption timeout to client
Jonas Wielicki <jonas@wielicki.name>
parents:
2937
diff
changeset
|
179 |
2713
eea1d5bac451
mod_smacks: Fix delayed_ack event
tmolitor <thilo@eightysoft.de>
parents:
2701
diff
changeset
|
180 -- Trigger "smacks-ack-delayed"-event if we added new (ackable) stanzas to the outgoing queue |
eea1d5bac451
mod_smacks: Fix delayed_ack event
tmolitor <thilo@eightysoft.de>
parents:
2701
diff
changeset
|
181 -- and there isn't already a timer for this event running. |
eea1d5bac451
mod_smacks: Fix delayed_ack event
tmolitor <thilo@eightysoft.de>
parents:
2701
diff
changeset
|
182 -- If we wouldn't do this, stanzas added to the queue after the first "smacks-ack-delayed"-event |
eea1d5bac451
mod_smacks: Fix delayed_ack event
tmolitor <thilo@eightysoft.de>
parents:
2701
diff
changeset
|
183 -- would not trigger this event (again). |
eea1d5bac451
mod_smacks: Fix delayed_ack event
tmolitor <thilo@eightysoft.de>
parents:
2701
diff
changeset
|
184 if #queue > max_unacked_stanzas and session.awaiting_ack and session.delayed_ack_timer == nil then |
eea1d5bac451
mod_smacks: Fix delayed_ack event
tmolitor <thilo@eightysoft.de>
parents:
2701
diff
changeset
|
185 session.log("debug", "Calling delayed_ack_function directly (still waiting for ack)"); |
eea1d5bac451
mod_smacks: Fix delayed_ack event
tmolitor <thilo@eightysoft.de>
parents:
2701
diff
changeset
|
186 delayed_ack_function(session); |
eea1d5bac451
mod_smacks: Fix delayed_ack event
tmolitor <thilo@eightysoft.de>
parents:
2701
diff
changeset
|
187 end |
3104
626d2c781c66
mod_smacks: send maximum resumption timeout to client
Jonas Wielicki <jonas@wielicki.name>
parents:
2937
diff
changeset
|
188 |
2624
c110b6bfe5d1
mod_smacks: Prevent ack loop on misbehaving clients
tmolitor <thilo@eightysoft.de>
parents:
2623
diff
changeset
|
189 session.last_queue_count = #queue; |
2491
5fbca7de2088
mod_smacks: Send out more ack requests where needed
tmolitor <thilo@eightysoft.de>
parents:
2417
diff
changeset
|
190 end |
5fbca7de2088
mod_smacks: Send out more ack requests where needed
tmolitor <thilo@eightysoft.de>
parents:
2417
diff
changeset
|
191 |
1520
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
192 local function outgoing_stanza_filter(stanza, session) |
1597
dc0cf2ba0e1a
mod_smacks: Stanzas don't have a ':' in their name
Kim Alvefur <zash@zash.se>
parents:
1539
diff
changeset
|
193 local is_stanza = stanza.attr and not stanza.attr.xmlns and not stanza.name:find":"; |
1520
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
194 if is_stanza and not stanza._cached then -- Stanza in default stream namespace |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
195 local queue = session.outgoing_stanza_queue; |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
196 local cached_stanza = st.clone(stanza); |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
197 cached_stanza._cached = true; |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
198 |
1599
8e006226e4c5
mod_smacks: Don't attach timestamps to 'iq' stanzas
Kim Alvefur <zash@zash.se>
parents:
1598
diff
changeset
|
199 if cached_stanza and cached_stanza.name ~= "iq" and cached_stanza:get_child("delay", xmlns_delay) == nil then |
2756 | 200 cached_stanza = cached_stanza:tag("delay", { |
201 xmlns = xmlns_delay, | |
202 from = jid.bare(session.full_jid or session.host), | |
203 stamp = datetime.datetime() | |
204 }); | |
1520
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
205 end |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
206 |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
207 queue[#queue+1] = cached_stanza; |
1522
d4a4ed31567e
mod_smacks: Trick session.send() into not returning nil or mod_message will act as if messages were not delivered
Kim Alvefur <zash@zash.se>
parents:
1520
diff
changeset
|
208 if session.hibernating then |
d4a4ed31567e
mod_smacks: Trick session.send() into not returning nil or mod_message will act as if messages were not delivered
Kim Alvefur <zash@zash.se>
parents:
1520
diff
changeset
|
209 session.log("debug", "hibernating, stanza queued"); |
2087
e48dbb640408
mod_smacks: Drop stanzas instead of turning them into the empty string
Kim Alvefur <zash@zash.se>
parents:
1881
diff
changeset
|
210 return nil; |
1522
d4a4ed31567e
mod_smacks: Trick session.send() into not returning nil or mod_message will act as if messages were not delivered
Kim Alvefur <zash@zash.se>
parents:
1520
diff
changeset
|
211 end |
3478
f6319346e2a3
mod_smacks: improved debug logging
Georg Lukas <georg@op-co.de>
parents:
3477
diff
changeset
|
212 request_ack_if_needed(session, false, "outgoing_stanza_filter"); |
1520
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
213 end |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
214 return stanza; |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
215 end |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
216 |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
217 local function count_incoming_stanzas(stanza, session) |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
218 if not stanza.attr.xmlns then |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
219 session.handled_stanza_count = session.handled_stanza_count + 1; |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
220 session.log("debug", "Handled %d incoming stanzas", session.handled_stanza_count); |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
221 end |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
222 return stanza; |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
223 end |
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
224 |
1529
16893646a458
mod_smacks: Move wrap_session() contents into separate direction-specific routines
Kim Alvefur <zash@zash.se>
parents:
1528
diff
changeset
|
225 local function wrap_session_out(session, resume) |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
226 if not resume then |
1528
5ccb3ee2cf72
mod_smacks: Remove variable not used after 2881d532f385
Kim Alvefur <zash@zash.se>
parents:
1527
diff
changeset
|
227 session.outgoing_stanza_queue = {}; |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
228 session.last_acknowledged_stanza = 0; |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
229 end |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1325
diff
changeset
|
230 |
2122
3f788f18cc10
mod_smacks: Adjust filter priorities to avoid conflict with mod_websocket
Kim Alvefur <zash@zash.se>
parents:
2091
diff
changeset
|
231 add_filter(session, "stanzas/out", outgoing_stanza_filter, -999); |
988
c15cea87036f
mod_smacks: Wrap session:close() and make the session not resumable
Kim Alvefur <zash@zash.se>
parents:
987
diff
changeset
|
232 |
c15cea87036f
mod_smacks: Wrap session:close() and make the session not resumable
Kim Alvefur <zash@zash.se>
parents:
987
diff
changeset
|
233 local session_close = session.close; |
c15cea87036f
mod_smacks: Wrap session:close() and make the session not resumable
Kim Alvefur <zash@zash.se>
parents:
987
diff
changeset
|
234 function session.close(...) |
c15cea87036f
mod_smacks: Wrap session:close() and make the session not resumable
Kim Alvefur <zash@zash.se>
parents:
987
diff
changeset
|
235 if session.resumption_token then |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
236 session_registry.set(session.username, session.resumption_token, nil); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
237 old_session_registry.set(session.username, session.resumption_token, nil); |
988
c15cea87036f
mod_smacks: Wrap session:close() and make the session not resumable
Kim Alvefur <zash@zash.se>
parents:
987
diff
changeset
|
238 session.resumption_token = nil; |
c15cea87036f
mod_smacks: Wrap session:close() and make the session not resumable
Kim Alvefur <zash@zash.se>
parents:
987
diff
changeset
|
239 end |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
240 -- send out last ack as per revision 1.5.2 of XEP-0198 |
2623
a65260300708
mod_smacks: Made module more error resistant
tmolitor <thilo@eightysoft.de>
parents:
2608
diff
changeset
|
241 if session.smacks and session.conn then |
2937
e672d1050529
mod_smacks: Ensure stanza count attributes are always strings (thanks Martin)
Matthew Wild <mwild1@gmail.com>
parents:
2756
diff
changeset
|
242 (session.sends2s or session.send)(st.stanza("a", { xmlns = session.smacks, h = string.format("%d", session.handled_stanza_count) })); |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
243 end |
988
c15cea87036f
mod_smacks: Wrap session:close() and make the session not resumable
Kim Alvefur <zash@zash.se>
parents:
987
diff
changeset
|
244 return session_close(...); |
c15cea87036f
mod_smacks: Wrap session:close() and make the session not resumable
Kim Alvefur <zash@zash.se>
parents:
987
diff
changeset
|
245 end |
1529
16893646a458
mod_smacks: Move wrap_session() contents into separate direction-specific routines
Kim Alvefur <zash@zash.se>
parents:
1528
diff
changeset
|
246 return session; |
16893646a458
mod_smacks: Move wrap_session() contents into separate direction-specific routines
Kim Alvefur <zash@zash.se>
parents:
1528
diff
changeset
|
247 end |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1325
diff
changeset
|
248 |
1529
16893646a458
mod_smacks: Move wrap_session() contents into separate direction-specific routines
Kim Alvefur <zash@zash.se>
parents:
1528
diff
changeset
|
249 local function wrap_session_in(session, resume) |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
250 if not resume then |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
251 session.handled_stanza_count = 0; |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
252 end |
2122
3f788f18cc10
mod_smacks: Adjust filter priorities to avoid conflict with mod_websocket
Kim Alvefur <zash@zash.se>
parents:
2091
diff
changeset
|
253 add_filter(session, "stanzas/in", count_incoming_stanzas, 999); |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
254 |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
255 return session; |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
256 end |
201
bc24f58a0d39
mod_smacks: Use filters for catching incoming stanzas (more reliable and efficient), also add some logic to make compatible with the stream resumption module (coming soon)
Matthew Wild <mwild1@gmail.com>
parents:
200
diff
changeset
|
257 |
1529
16893646a458
mod_smacks: Move wrap_session() contents into separate direction-specific routines
Kim Alvefur <zash@zash.se>
parents:
1528
diff
changeset
|
258 local function wrap_session(session, resume) |
16893646a458
mod_smacks: Move wrap_session() contents into separate direction-specific routines
Kim Alvefur <zash@zash.se>
parents:
1528
diff
changeset
|
259 wrap_session_out(session, resume); |
16893646a458
mod_smacks: Move wrap_session() contents into separate direction-specific routines
Kim Alvefur <zash@zash.se>
parents:
1528
diff
changeset
|
260 wrap_session_in(session, resume); |
16893646a458
mod_smacks: Move wrap_session() contents into separate direction-specific routines
Kim Alvefur <zash@zash.se>
parents:
1528
diff
changeset
|
261 return session; |
16893646a458
mod_smacks: Move wrap_session() contents into separate direction-specific routines
Kim Alvefur <zash@zash.se>
parents:
1528
diff
changeset
|
262 end |
16893646a458
mod_smacks: Move wrap_session() contents into separate direction-specific routines
Kim Alvefur <zash@zash.se>
parents:
1528
diff
changeset
|
263 |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
264 function handle_enable(session, stanza, xmlns_sm) |
591
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
265 local ok, err, err_text = can_do_smacks(session); |
36003cae2370
mod_smacks: Consolidate logic for deciding whether to advertise or allow smacks for a given session, and fix an issue with not allowing s2s connections to enable smacks because of not binding a resource... (thanks xnyphs)
Matthew Wild <mwild1@gmail.com>
parents:
590
diff
changeset
|
266 if not ok then |
590
40b707d7a809
mod_smacks: Handle a client trying to <enable> twice, or trying to <enable> before resource binding (thanks Thijs Alkemade)
Matthew Wild <mwild1@gmail.com>
parents:
589
diff
changeset
|
267 session.log("warn", "Failed to enable smacks: %s", err_text); -- TODO: XEP doesn't say we can send error text, should it? |
1527
06ecc5b3ca46
mod_smacks: Send failure correctly on s2s
Kim Alvefur <zash@zash.se>
parents:
1526
diff
changeset
|
268 (session.sends2s or session.send)(st.stanza("failed", { xmlns = xmlns_sm }):tag(err, { xmlns = xmlns_errors})); |
590
40b707d7a809
mod_smacks: Handle a client trying to <enable> twice, or trying to <enable> before resource binding (thanks Thijs Alkemade)
Matthew Wild <mwild1@gmail.com>
parents:
589
diff
changeset
|
269 return true; |
40b707d7a809
mod_smacks: Handle a client trying to <enable> twice, or trying to <enable> before resource binding (thanks Thijs Alkemade)
Matthew Wild <mwild1@gmail.com>
parents:
589
diff
changeset
|
270 end |
40b707d7a809
mod_smacks: Handle a client trying to <enable> twice, or trying to <enable> before resource binding (thanks Thijs Alkemade)
Matthew Wild <mwild1@gmail.com>
parents:
589
diff
changeset
|
271 |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
272 module:log("debug", "Enabling stream management"); |
1520
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
273 session.smacks = xmlns_sm; |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1325
diff
changeset
|
274 |
1520
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
275 wrap_session(session, false); |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1325
diff
changeset
|
276 |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
277 local resume_token; |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
278 local resume = stanza.attr.resume; |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
279 if resume == "true" or resume == "1" then |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
280 resume_token = uuid_generate(); |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
281 session_registry.set(session.username, resume_token, session); |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
282 session.resumption_token = resume_token; |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
283 end |
3110
06e07b483805
mod_smacks: Convert max number into a string before inserting it into a stanza.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3107
diff
changeset
|
284 (session.sends2s or session.send)(st.stanza("enabled", { xmlns = xmlns_sm, id = resume_token, resume = resume, max = tostring(resume_timeout) })); |
576
44b69c3d5351
mod_smacks: Fix smacks on s2s connections, but disable it by default.
Kim Alvefur <zash@zash.se>
parents:
478
diff
changeset
|
285 return true; |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
286 end |
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
287 module:hook_stanza(xmlns_sm2, "enable", function (session, stanza) return handle_enable(session, stanza, xmlns_sm2); end, 100); |
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
288 module:hook_stanza(xmlns_sm3, "enable", function (session, stanza) return handle_enable(session, stanza, xmlns_sm3); end, 100); |
576
44b69c3d5351
mod_smacks: Fix smacks on s2s connections, but disable it by default.
Kim Alvefur <zash@zash.se>
parents:
478
diff
changeset
|
289 |
1530
fb7cd669f41b
mod_smacks: Initiate outgoing smacks on s2s when sending request and incoming when the remote says enabled
Kim Alvefur <zash@zash.se>
parents:
1529
diff
changeset
|
290 module:hook_stanza("http://etherx.jabber.org/streams", "features", |
fb7cd669f41b
mod_smacks: Initiate outgoing smacks on s2s when sending request and incoming when the remote says enabled
Kim Alvefur <zash@zash.se>
parents:
1529
diff
changeset
|
291 function (session, stanza) |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
292 stoppable_timer(1e-6, function () |
1531
7d86fc477993
mod_smacks: Delay initiation of outgoing smacks on s2s until after queued stanzas are sent
Kim Alvefur <zash@zash.se>
parents:
1530
diff
changeset
|
293 if can_do_smacks(session) then |
7d86fc477993
mod_smacks: Delay initiation of outgoing smacks on s2s until after queued stanzas are sent
Kim Alvefur <zash@zash.se>
parents:
1530
diff
changeset
|
294 if stanza:get_child("sm", xmlns_sm3) then |
7d86fc477993
mod_smacks: Delay initiation of outgoing smacks on s2s until after queued stanzas are sent
Kim Alvefur <zash@zash.se>
parents:
1530
diff
changeset
|
295 session.sends2s(st.stanza("enable", sm3_attr)); |
7d86fc477993
mod_smacks: Delay initiation of outgoing smacks on s2s until after queued stanzas are sent
Kim Alvefur <zash@zash.se>
parents:
1530
diff
changeset
|
296 session.smacks = xmlns_sm3; |
7d86fc477993
mod_smacks: Delay initiation of outgoing smacks on s2s until after queued stanzas are sent
Kim Alvefur <zash@zash.se>
parents:
1530
diff
changeset
|
297 elseif stanza:get_child("sm", xmlns_sm2) then |
7d86fc477993
mod_smacks: Delay initiation of outgoing smacks on s2s until after queued stanzas are sent
Kim Alvefur <zash@zash.se>
parents:
1530
diff
changeset
|
298 session.sends2s(st.stanza("enable", sm2_attr)); |
7d86fc477993
mod_smacks: Delay initiation of outgoing smacks on s2s until after queued stanzas are sent
Kim Alvefur <zash@zash.se>
parents:
1530
diff
changeset
|
299 session.smacks = xmlns_sm2; |
7d86fc477993
mod_smacks: Delay initiation of outgoing smacks on s2s until after queued stanzas are sent
Kim Alvefur <zash@zash.se>
parents:
1530
diff
changeset
|
300 else |
7d86fc477993
mod_smacks: Delay initiation of outgoing smacks on s2s until after queued stanzas are sent
Kim Alvefur <zash@zash.se>
parents:
1530
diff
changeset
|
301 return; |
7d86fc477993
mod_smacks: Delay initiation of outgoing smacks on s2s until after queued stanzas are sent
Kim Alvefur <zash@zash.se>
parents:
1530
diff
changeset
|
302 end |
7d86fc477993
mod_smacks: Delay initiation of outgoing smacks on s2s until after queued stanzas are sent
Kim Alvefur <zash@zash.se>
parents:
1530
diff
changeset
|
303 wrap_session_out(session, false); |
1530
fb7cd669f41b
mod_smacks: Initiate outgoing smacks on s2s when sending request and incoming when the remote says enabled
Kim Alvefur <zash@zash.se>
parents:
1529
diff
changeset
|
304 end |
1531
7d86fc477993
mod_smacks: Delay initiation of outgoing smacks on s2s until after queued stanzas are sent
Kim Alvefur <zash@zash.se>
parents:
1530
diff
changeset
|
305 end); |
1530
fb7cd669f41b
mod_smacks: Initiate outgoing smacks on s2s when sending request and incoming when the remote says enabled
Kim Alvefur <zash@zash.se>
parents:
1529
diff
changeset
|
306 end); |
fb7cd669f41b
mod_smacks: Initiate outgoing smacks on s2s when sending request and incoming when the remote says enabled
Kim Alvefur <zash@zash.se>
parents:
1529
diff
changeset
|
307 |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
308 function handle_enabled(session, stanza, xmlns_sm) |
576
44b69c3d5351
mod_smacks: Fix smacks on s2s connections, but disable it by default.
Kim Alvefur <zash@zash.se>
parents:
478
diff
changeset
|
309 module:log("debug", "Enabling stream management"); |
1520
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
310 session.smacks = xmlns_sm; |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1325
diff
changeset
|
311 |
1530
fb7cd669f41b
mod_smacks: Initiate outgoing smacks on s2s when sending request and incoming when the remote says enabled
Kim Alvefur <zash@zash.se>
parents:
1529
diff
changeset
|
312 wrap_session_in(session, false); |
576
44b69c3d5351
mod_smacks: Fix smacks on s2s connections, but disable it by default.
Kim Alvefur <zash@zash.se>
parents:
478
diff
changeset
|
313 |
44b69c3d5351
mod_smacks: Fix smacks on s2s connections, but disable it by default.
Kim Alvefur <zash@zash.se>
parents:
478
diff
changeset
|
314 -- FIXME Resume? |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1325
diff
changeset
|
315 |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
316 return true; |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
317 end |
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
318 module:hook_stanza(xmlns_sm2, "enabled", function (session, stanza) return handle_enabled(session, stanza, xmlns_sm2); end, 100); |
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
319 module:hook_stanza(xmlns_sm3, "enabled", function (session, stanza) return handle_enabled(session, stanza, xmlns_sm3); end, 100); |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
320 |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
321 function handle_r(origin, stanza, xmlns_sm) |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
322 if not origin.smacks then |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
323 module:log("debug", "Received ack request from non-smack-enabled session"); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
324 return; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
325 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
326 module:log("debug", "Received ack request, acking for %d", origin.handled_stanza_count); |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
327 -- Reply with <a> |
2937
e672d1050529
mod_smacks: Ensure stanza count attributes are always strings (thanks Martin)
Matthew Wild <mwild1@gmail.com>
parents:
2756
diff
changeset
|
328 (origin.sends2s or origin.send)(st.stanza("a", { xmlns = xmlns_sm, h = string.format("%d", origin.handled_stanza_count) })); |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
329 return true; |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
330 end |
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
331 module:hook_stanza(xmlns_sm2, "r", function (origin, stanza) return handle_r(origin, stanza, xmlns_sm2); end); |
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
332 module:hook_stanza(xmlns_sm3, "r", function (origin, stanza) return handle_r(origin, stanza, xmlns_sm3); end); |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
333 |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
334 function handle_a(origin, stanza) |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
335 if not origin.smacks then return; end |
200
64a573203c20
mod_smacks: Better logic for deciding what is a stanza and what is not, and deciding when to send ack requests
Matthew Wild <mwild1@gmail.com>
parents:
160
diff
changeset
|
336 origin.awaiting_ack = nil; |
2090
1796a022dd29
mod_smacks: Keep timer object around and stop it when needed (trunk only)
Kim Alvefur <zash@zash.se>
parents:
2089
diff
changeset
|
337 if origin.awaiting_ack_timer then |
1796a022dd29
mod_smacks: Keep timer object around and stop it when needed (trunk only)
Kim Alvefur <zash@zash.se>
parents:
2089
diff
changeset
|
338 origin.awaiting_ack_timer:stop(); |
1796a022dd29
mod_smacks: Keep timer object around and stop it when needed (trunk only)
Kim Alvefur <zash@zash.se>
parents:
2089
diff
changeset
|
339 end |
2394
4c27ebcf4cbd
mod_smacks: added new event "smacks-ack-delayed" used by mod_cloud_notify and extended the readme file accordingly (also mention mod_smacks_offline and mod_smacks_noerror in readme file)
tmolitor <thilo@eightysoft.de>
parents:
2251
diff
changeset
|
340 if origin.delayed_ack_timer then |
4c27ebcf4cbd
mod_smacks: added new event "smacks-ack-delayed" used by mod_cloud_notify and extended the readme file accordingly (also mention mod_smacks_offline and mod_smacks_noerror in readme file)
tmolitor <thilo@eightysoft.de>
parents:
2251
diff
changeset
|
341 origin.delayed_ack_timer:stop(); |
2494
d300ae5dba87
mod_smacks: Fix some bugs with smacks-ack-delayed event triggering.
tmolitor <thilo@eightysoft.de>
parents:
2491
diff
changeset
|
342 origin.delayed_ack_timer = nil; |
2394
4c27ebcf4cbd
mod_smacks: added new event "smacks-ack-delayed" used by mod_cloud_notify and extended the readme file accordingly (also mention mod_smacks_offline and mod_smacks_noerror in readme file)
tmolitor <thilo@eightysoft.de>
parents:
2251
diff
changeset
|
343 end |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
344 -- Remove handled stanzas from outgoing_stanza_queue |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
345 -- origin.log("debug", "ACK: h=%s, last=%s", stanza.attr.h or "", origin.last_acknowledged_stanza or ""); |
1407
b631c8a8b9e7
mod_smacks: Assert that the 'h' attribute is present and a number
Kim Alvefur <zash@zash.se>
parents:
1406
diff
changeset
|
346 local h = tonumber(stanza.attr.h); |
b631c8a8b9e7
mod_smacks: Assert that the 'h' attribute is present and a number
Kim Alvefur <zash@zash.se>
parents:
1406
diff
changeset
|
347 if not h then |
b631c8a8b9e7
mod_smacks: Assert that the 'h' attribute is present and a number
Kim Alvefur <zash@zash.se>
parents:
1406
diff
changeset
|
348 origin:close{ condition = "invalid-xml"; text = "Missing or invalid 'h' attribute"; }; |
3477
1f2381492c9f
mod_smacks: no crash on <a> without @h, fix #1317
Georg Lukas <georg@op-co.de>
parents:
3450
diff
changeset
|
349 return; |
1407
b631c8a8b9e7
mod_smacks: Assert that the 'h' attribute is present and a number
Kim Alvefur <zash@zash.se>
parents:
1406
diff
changeset
|
350 end |
b631c8a8b9e7
mod_smacks: Assert that the 'h' attribute is present and a number
Kim Alvefur <zash@zash.se>
parents:
1406
diff
changeset
|
351 local handled_stanza_count = h-origin.last_acknowledged_stanza; |
220
263858d40ceb
mod_smacks: Fix the logic for handling outgoing stanzas and ack requests
Matthew Wild <mwild1@gmail.com>
parents:
202
diff
changeset
|
352 local queue = origin.outgoing_stanza_queue; |
263858d40ceb
mod_smacks: Fix the logic for handling outgoing stanzas and ack requests
Matthew Wild <mwild1@gmail.com>
parents:
202
diff
changeset
|
353 if handled_stanza_count > #queue then |
1416
7ddb522d9b28
mod_smacks: Fix logging (Thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
1408
diff
changeset
|
354 origin.log("warn", "The client says it handled %d new stanzas, but we only sent %d :)", |
220
263858d40ceb
mod_smacks: Fix the logic for handling outgoing stanzas and ack requests
Matthew Wild <mwild1@gmail.com>
parents:
202
diff
changeset
|
355 handled_stanza_count, #queue); |
1416
7ddb522d9b28
mod_smacks: Fix logging (Thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
1408
diff
changeset
|
356 origin.log("debug", "Client h: %d, our h: %d", tonumber(stanza.attr.h), origin.last_acknowledged_stanza); |
220
263858d40ceb
mod_smacks: Fix the logic for handling outgoing stanzas and ack requests
Matthew Wild <mwild1@gmail.com>
parents:
202
diff
changeset
|
357 for i=1,#queue do |
1416
7ddb522d9b28
mod_smacks: Fix logging (Thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
1408
diff
changeset
|
358 origin.log("debug", "Q item %d: %s", i, tostring(queue[i])); |
220
263858d40ceb
mod_smacks: Fix the logic for handling outgoing stanzas and ack requests
Matthew Wild <mwild1@gmail.com>
parents:
202
diff
changeset
|
359 end |
263858d40ceb
mod_smacks: Fix the logic for handling outgoing stanzas and ack requests
Matthew Wild <mwild1@gmail.com>
parents:
202
diff
changeset
|
360 end |
3450
9b6206f23151
mod_smacks: Fire event on delivery failure/success for each stanza
Matthew Wild <mwild1@gmail.com>
parents:
3218
diff
changeset
|
361 |
220
263858d40ceb
mod_smacks: Fix the logic for handling outgoing stanzas and ack requests
Matthew Wild <mwild1@gmail.com>
parents:
202
diff
changeset
|
362 for i=1,math_min(handled_stanza_count,#queue) do |
3450
9b6206f23151
mod_smacks: Fire event on delivery failure/success for each stanza
Matthew Wild <mwild1@gmail.com>
parents:
3218
diff
changeset
|
363 local handled_stanza = t_remove(origin.outgoing_stanza_queue, 1); |
9b6206f23151
mod_smacks: Fire event on delivery failure/success for each stanza
Matthew Wild <mwild1@gmail.com>
parents:
3218
diff
changeset
|
364 module:fire_event("delivery/success", { session = origin, stanza = handled_stanza }); |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
365 end |
3450
9b6206f23151
mod_smacks: Fire event on delivery failure/success for each stanza
Matthew Wild <mwild1@gmail.com>
parents:
3218
diff
changeset
|
366 |
1406
7d76dd2310ef
mod_smacks: Add more debug logging
Kim Alvefur <zash@zash.se>
parents:
1405
diff
changeset
|
367 origin.log("debug", "#queue = %d", #queue); |
220
263858d40ceb
mod_smacks: Fix the logic for handling outgoing stanzas and ack requests
Matthew Wild <mwild1@gmail.com>
parents:
202
diff
changeset
|
368 origin.last_acknowledged_stanza = origin.last_acknowledged_stanza + handled_stanza_count; |
3478
f6319346e2a3
mod_smacks: improved debug logging
Georg Lukas <georg@op-co.de>
parents:
3477
diff
changeset
|
369 request_ack_if_needed(origin, false, "handle_a") |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
370 return true; |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
371 end |
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
372 module:hook_stanza(xmlns_sm2, "a", handle_a); |
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
373 module:hook_stanza(xmlns_sm3, "a", handle_a); |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
374 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
375 --TODO: Optimise... incoming stanzas should be handled by a per-session |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
376 -- function that has a counter as an upvalue (no table indexing for increments, |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
377 -- and won't slow non-198 sessions). We can also then remove the .handled flag |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
378 -- on stanzas |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
379 |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
380 function handle_unacked_stanzas(session) |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
381 local queue = session.outgoing_stanza_queue; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
382 local error_attr = { type = "cancel" }; |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
383 if #queue > 0 then |
202
d11478ae374e
mod_smacks: Clean outgoing stanza queue correctly on session close
Matthew Wild <mwild1@gmail.com>
parents:
201
diff
changeset
|
384 session.outgoing_stanza_queue = {}; |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
385 for i=1,#queue do |
3450
9b6206f23151
mod_smacks: Fire event on delivery failure/success for each stanza
Matthew Wild <mwild1@gmail.com>
parents:
3218
diff
changeset
|
386 if not module:fire_event("delivery/failure", { session = session, stanza = queue[i] }) then |
9b6206f23151
mod_smacks: Fire event on delivery failure/success for each stanza
Matthew Wild <mwild1@gmail.com>
parents:
3218
diff
changeset
|
387 local reply = st.reply(queue[i]); |
9b6206f23151
mod_smacks: Fire event on delivery failure/success for each stanza
Matthew Wild <mwild1@gmail.com>
parents:
3218
diff
changeset
|
388 if reply.attr.to ~= session.full_jid then |
9b6206f23151
mod_smacks: Fire event on delivery failure/success for each stanza
Matthew Wild <mwild1@gmail.com>
parents:
3218
diff
changeset
|
389 reply.attr.type = "error"; |
9b6206f23151
mod_smacks: Fire event on delivery failure/success for each stanza
Matthew Wild <mwild1@gmail.com>
parents:
3218
diff
changeset
|
390 reply:tag("error", error_attr) |
9b6206f23151
mod_smacks: Fire event on delivery failure/success for each stanza
Matthew Wild <mwild1@gmail.com>
parents:
3218
diff
changeset
|
391 :tag("recipient-unavailable", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}); |
9b6206f23151
mod_smacks: Fire event on delivery failure/success for each stanza
Matthew Wild <mwild1@gmail.com>
parents:
3218
diff
changeset
|
392 core_process_stanza(session, reply); |
9b6206f23151
mod_smacks: Fire event on delivery failure/success for each stanza
Matthew Wild <mwild1@gmail.com>
parents:
3218
diff
changeset
|
393 end |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
394 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
395 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
396 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
397 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
398 |
622
ce39df945de1
mod_smacks: Use pre-resource-unbind (0.9 feature) to fix reloadability and multiple host support
Matthew Wild <mwild1@gmail.com>
parents:
595
diff
changeset
|
399 module:hook("pre-resource-unbind", function (event) |
ce39df945de1
mod_smacks: Use pre-resource-unbind (0.9 feature) to fix reloadability and multiple host support
Matthew Wild <mwild1@gmail.com>
parents:
595
diff
changeset
|
400 local session, err = event.session, event.error; |
1024
d7655e634c30
mod_smacks: Allow resumption if the TCP connection is closed from our end, c15cea87036f ensures distinction from cleanly closed streams (thanks Lance)
Kim Alvefur <zash@zash.se>
parents:
994
diff
changeset
|
401 if session.smacks then |
257
08fa42e1ab06
mod_smacks: Fixes for monkey-patched sessionmanager.destroy to handle stream resumption, and to fall back to stock destroy() if the session is not smacks-enabled.
Matthew Wild <mwild1@gmail.com>
parents:
256
diff
changeset
|
402 if not session.resumption_token then |
08fa42e1ab06
mod_smacks: Fixes for monkey-patched sessionmanager.destroy to handle stream resumption, and to fall back to stock destroy() if the session is not smacks-enabled.
Matthew Wild <mwild1@gmail.com>
parents:
256
diff
changeset
|
403 local queue = session.outgoing_stanza_queue; |
08fa42e1ab06
mod_smacks: Fixes for monkey-patched sessionmanager.destroy to handle stream resumption, and to fall back to stock destroy() if the session is not smacks-enabled.
Matthew Wild <mwild1@gmail.com>
parents:
256
diff
changeset
|
404 if #queue > 0 then |
3150
14b6ad2b773f
mod_smacks: Reduce unacked stanza log message from warn->debug
Matthew Wild <mwild1@gmail.com>
parents:
3110
diff
changeset
|
405 session.log("debug", "Destroying session with %d unacked stanzas", #queue); |
257
08fa42e1ab06
mod_smacks: Fixes for monkey-patched sessionmanager.destroy to handle stream resumption, and to fall back to stock destroy() if the session is not smacks-enabled.
Matthew Wild <mwild1@gmail.com>
parents:
256
diff
changeset
|
406 handle_unacked_stanzas(session); |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
407 end |
257
08fa42e1ab06
mod_smacks: Fixes for monkey-patched sessionmanager.destroy to handle stream resumption, and to fall back to stock destroy() if the session is not smacks-enabled.
Matthew Wild <mwild1@gmail.com>
parents:
256
diff
changeset
|
408 else |
586
f733e7599ed6
mod_smacks: Add logging to hibernation and session destruction (thanks darkrain)
Matthew Wild <mwild1@gmail.com>
parents:
576
diff
changeset
|
409 session.log("debug", "mod_smacks hibernating session for up to %d seconds", resume_timeout); |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
410 local hibernate_time = os_time(); -- Track the time we went into hibernation |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
411 session.hibernating = hibernate_time; |
478
db0f065c4e09
mod_smacks: Don't destroy a session that binds the same resource as a hibernating smacks session (thanks xnyhps for tracking down the problem, though I've used a different fix)
Matthew Wild <mwild1@gmail.com>
parents:
345
diff
changeset
|
412 local resumption_token = session.resumption_token; |
2140
3a94b3cd31e2
mod_smacks: added new events for hibernation start/end
tmolitor <thilo@eightysoft.de>
parents:
2136
diff
changeset
|
413 module:fire_event("smacks-hibernation-start", {origin = session, queue = session.outgoing_stanza_queue}); |
257
08fa42e1ab06
mod_smacks: Fixes for monkey-patched sessionmanager.destroy to handle stream resumption, and to fall back to stock destroy() if the session is not smacks-enabled.
Matthew Wild <mwild1@gmail.com>
parents:
256
diff
changeset
|
414 timer.add_task(resume_timeout, function () |
586
f733e7599ed6
mod_smacks: Add logging to hibernation and session destruction (thanks darkrain)
Matthew Wild <mwild1@gmail.com>
parents:
576
diff
changeset
|
415 session.log("debug", "mod_smacks hibernation timeout reached..."); |
478
db0f065c4e09
mod_smacks: Don't destroy a session that binds the same resource as a hibernating smacks session (thanks xnyhps for tracking down the problem, though I've used a different fix)
Matthew Wild <mwild1@gmail.com>
parents:
345
diff
changeset
|
416 -- We need to check the current resumption token for this resource |
db0f065c4e09
mod_smacks: Don't destroy a session that binds the same resource as a hibernating smacks session (thanks xnyhps for tracking down the problem, though I've used a different fix)
Matthew Wild <mwild1@gmail.com>
parents:
345
diff
changeset
|
417 -- matches the smacks session this timer is for in case it changed |
db0f065c4e09
mod_smacks: Don't destroy a session that binds the same resource as a hibernating smacks session (thanks xnyhps for tracking down the problem, though I've used a different fix)
Matthew Wild <mwild1@gmail.com>
parents:
345
diff
changeset
|
418 -- (for example, the client may have bound a new resource and |
db0f065c4e09
mod_smacks: Don't destroy a session that binds the same resource as a hibernating smacks session (thanks xnyhps for tracking down the problem, though I've used a different fix)
Matthew Wild <mwild1@gmail.com>
parents:
345
diff
changeset
|
419 -- started a new smacks session, or not be using smacks) |
810
464ed063a8f2
mod_smacks: Less table indexing!
Kim Alvefur <zash@zash.se>
parents:
757
diff
changeset
|
420 local curr_session = full_sessions[session.full_jid]; |
1598
043d08448d87
mod_smacks: Remove negation of condition, most likely a leftover from debugging
Kim Alvefur <zash@zash.se>
parents:
1597
diff
changeset
|
421 if session.destroyed then |
987
fabff75bfc3f
mod_smacks: If a hibernating session was destroyed before the timeout, don't destroy it again or say that it was resumed
Kim Alvefur <zash@zash.se>
parents:
925
diff
changeset
|
422 session.log("debug", "The session has already been destroyed"); |
fabff75bfc3f
mod_smacks: If a hibernating session was destroyed before the timeout, don't destroy it again or say that it was resumed
Kim Alvefur <zash@zash.se>
parents:
925
diff
changeset
|
423 elseif curr_session and curr_session.resumption_token == resumption_token |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
424 -- Check the hibernate time still matches what we think it is, |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
425 -- otherwise the session resumed and re-hibernated. |
478
db0f065c4e09
mod_smacks: Don't destroy a session that binds the same resource as a hibernating smacks session (thanks xnyhps for tracking down the problem, though I've used a different fix)
Matthew Wild <mwild1@gmail.com>
parents:
345
diff
changeset
|
426 and session.hibernating == hibernate_time then |
3107
f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
tmolitor <thilo@eightysoft.de>
parents:
3104
diff
changeset
|
427 -- wait longer if the timeout isn't reached because push was enabled for this session |
f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
tmolitor <thilo@eightysoft.de>
parents:
3104
diff
changeset
|
428 -- session.first_hibernated_push is the starting point for hibernation timeouts of those push enabled clients |
f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
tmolitor <thilo@eightysoft.de>
parents:
3104
diff
changeset
|
429 -- wait for an additional resume_timeout seconds if no push occured since hibernation at all |
f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
tmolitor <thilo@eightysoft.de>
parents:
3104
diff
changeset
|
430 local current_time = os_time(); |
f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
tmolitor <thilo@eightysoft.de>
parents:
3104
diff
changeset
|
431 local timeout_start = math_max(session.hibernating, session.first_hibernated_push or session.hibernating); |
f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
tmolitor <thilo@eightysoft.de>
parents:
3104
diff
changeset
|
432 if session.push_identifier ~= nil and not session.first_hibernated_push then |
f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
tmolitor <thilo@eightysoft.de>
parents:
3104
diff
changeset
|
433 session.log("debug", "No push happened since hibernation started, hibernating session for up to %d extra seconds", resume_timeout); |
f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
tmolitor <thilo@eightysoft.de>
parents:
3104
diff
changeset
|
434 return resume_timeout; |
f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
tmolitor <thilo@eightysoft.de>
parents:
3104
diff
changeset
|
435 end |
f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
tmolitor <thilo@eightysoft.de>
parents:
3104
diff
changeset
|
436 if current_time-timeout_start < resume_timeout and session.push_identifier ~= nil then |
f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
tmolitor <thilo@eightysoft.de>
parents:
3104
diff
changeset
|
437 session.log("debug", "A push happened since hibernation started, hibernating session for up to %d extra seconds", current_time-timeout_start); |
f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
tmolitor <thilo@eightysoft.de>
parents:
3104
diff
changeset
|
438 return current_time-timeout_start; -- time left to wait |
f703cc6e72df
mod_smacks: defer timeouts for push enabled clients
tmolitor <thilo@eightysoft.de>
parents:
3104
diff
changeset
|
439 end |
586
f733e7599ed6
mod_smacks: Add logging to hibernation and session destruction (thanks darkrain)
Matthew Wild <mwild1@gmail.com>
parents:
576
diff
changeset
|
440 session.log("debug", "Destroying session for hibernating too long"); |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
441 session_registry.set(session.username, session.resumption_token, nil); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
442 -- save only actual h value and username/host (for security) |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
443 old_session_registry.set(session.username, session.resumption_token, { |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
444 h = session.handled_stanza_count, |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
445 username = session.username, |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
446 host = session.host |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
447 }); |
257
08fa42e1ab06
mod_smacks: Fixes for monkey-patched sessionmanager.destroy to handle stream resumption, and to fall back to stock destroy() if the session is not smacks-enabled.
Matthew Wild <mwild1@gmail.com>
parents:
256
diff
changeset
|
448 session.resumption_token = nil; |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
449 sessionmanager.destroy_session(session); |
586
f733e7599ed6
mod_smacks: Add logging to hibernation and session destruction (thanks darkrain)
Matthew Wild <mwild1@gmail.com>
parents:
576
diff
changeset
|
450 else |
f733e7599ed6
mod_smacks: Add logging to hibernation and session destruction (thanks darkrain)
Matthew Wild <mwild1@gmail.com>
parents:
576
diff
changeset
|
451 session.log("debug", "Session resumed before hibernation timeout, all is well") |
257
08fa42e1ab06
mod_smacks: Fixes for monkey-patched sessionmanager.destroy to handle stream resumption, and to fall back to stock destroy() if the session is not smacks-enabled.
Matthew Wild <mwild1@gmail.com>
parents:
256
diff
changeset
|
452 end |
08fa42e1ab06
mod_smacks: Fixes for monkey-patched sessionmanager.destroy to handle stream resumption, and to fall back to stock destroy() if the session is not smacks-enabled.
Matthew Wild <mwild1@gmail.com>
parents:
256
diff
changeset
|
453 end); |
622
ce39df945de1
mod_smacks: Use pre-resource-unbind (0.9 feature) to fix reloadability and multiple host support
Matthew Wild <mwild1@gmail.com>
parents:
595
diff
changeset
|
454 return true; -- Postpone destruction for now |
160
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
455 end |
9a7671720dec
mod_smacks: XEP-0198 Stream Management acks. Initial commit - very rough, useful mainly for testing at the moment, most certainly contains bugs :)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
456 end |
622
ce39df945de1
mod_smacks: Use pre-resource-unbind (0.9 feature) to fix reloadability and multiple host support
Matthew Wild <mwild1@gmail.com>
parents:
595
diff
changeset
|
457 end); |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
458 |
1732
2f9ee9ed6267
mod_smacks: Handle unacked messages in s2s queues
Kim Alvefur <zash@zash.se>
parents:
1706
diff
changeset
|
459 local function handle_s2s_destroyed(event) |
2f9ee9ed6267
mod_smacks: Handle unacked messages in s2s queues
Kim Alvefur <zash@zash.se>
parents:
1706
diff
changeset
|
460 local session = event.session; |
2f9ee9ed6267
mod_smacks: Handle unacked messages in s2s queues
Kim Alvefur <zash@zash.se>
parents:
1706
diff
changeset
|
461 local queue = session.outgoing_stanza_queue; |
2f9ee9ed6267
mod_smacks: Handle unacked messages in s2s queues
Kim Alvefur <zash@zash.se>
parents:
1706
diff
changeset
|
462 if queue and #queue > 0 then |
2f9ee9ed6267
mod_smacks: Handle unacked messages in s2s queues
Kim Alvefur <zash@zash.se>
parents:
1706
diff
changeset
|
463 session.log("warn", "Destroying session with %d unacked stanzas", #queue); |
1881
3683eb95bc1a
mod_smacks: Add experimental resending of unacked messages in s2s queues (disabled by default)
Kim Alvefur <zash@zash.se>
parents:
1733
diff
changeset
|
464 if s2s_resend then |
3683eb95bc1a
mod_smacks: Add experimental resending of unacked messages in s2s queues (disabled by default)
Kim Alvefur <zash@zash.se>
parents:
1733
diff
changeset
|
465 for i = 1, #queue do |
3683eb95bc1a
mod_smacks: Add experimental resending of unacked messages in s2s queues (disabled by default)
Kim Alvefur <zash@zash.se>
parents:
1733
diff
changeset
|
466 module:send(queue[i]); |
3683eb95bc1a
mod_smacks: Add experimental resending of unacked messages in s2s queues (disabled by default)
Kim Alvefur <zash@zash.se>
parents:
1733
diff
changeset
|
467 end |
3683eb95bc1a
mod_smacks: Add experimental resending of unacked messages in s2s queues (disabled by default)
Kim Alvefur <zash@zash.se>
parents:
1733
diff
changeset
|
468 session.outgoing_stanza_queue = nil; |
3683eb95bc1a
mod_smacks: Add experimental resending of unacked messages in s2s queues (disabled by default)
Kim Alvefur <zash@zash.se>
parents:
1733
diff
changeset
|
469 else |
3683eb95bc1a
mod_smacks: Add experimental resending of unacked messages in s2s queues (disabled by default)
Kim Alvefur <zash@zash.se>
parents:
1733
diff
changeset
|
470 handle_unacked_stanzas(session); |
3683eb95bc1a
mod_smacks: Add experimental resending of unacked messages in s2s queues (disabled by default)
Kim Alvefur <zash@zash.se>
parents:
1733
diff
changeset
|
471 end |
1732
2f9ee9ed6267
mod_smacks: Handle unacked messages in s2s queues
Kim Alvefur <zash@zash.se>
parents:
1706
diff
changeset
|
472 end |
2f9ee9ed6267
mod_smacks: Handle unacked messages in s2s queues
Kim Alvefur <zash@zash.se>
parents:
1706
diff
changeset
|
473 end |
2f9ee9ed6267
mod_smacks: Handle unacked messages in s2s queues
Kim Alvefur <zash@zash.se>
parents:
1706
diff
changeset
|
474 |
2f9ee9ed6267
mod_smacks: Handle unacked messages in s2s queues
Kim Alvefur <zash@zash.se>
parents:
1706
diff
changeset
|
475 module:hook("s2sout-destroyed", handle_s2s_destroyed); |
2f9ee9ed6267
mod_smacks: Handle unacked messages in s2s queues
Kim Alvefur <zash@zash.se>
parents:
1706
diff
changeset
|
476 module:hook("s2sin-destroyed", handle_s2s_destroyed); |
2f9ee9ed6267
mod_smacks: Handle unacked messages in s2s queues
Kim Alvefur <zash@zash.se>
parents:
1706
diff
changeset
|
477 |
3218
67f1d1f22625
mod_smacks: Improve logging on resume so session changes are more easily tracked
Matthew Wild <mwild1@gmail.com>
parents:
3150
diff
changeset
|
478 local function get_session_id(session) |
67f1d1f22625
mod_smacks: Improve logging on resume so session changes are more easily tracked
Matthew Wild <mwild1@gmail.com>
parents:
3150
diff
changeset
|
479 return session.id or (tostring(session):match("[a-f0-9]+$")); |
67f1d1f22625
mod_smacks: Improve logging on resume so session changes are more easily tracked
Matthew Wild <mwild1@gmail.com>
parents:
3150
diff
changeset
|
480 end |
67f1d1f22625
mod_smacks: Improve logging on resume so session changes are more easily tracked
Matthew Wild <mwild1@gmail.com>
parents:
3150
diff
changeset
|
481 |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
482 function handle_resume(session, stanza, xmlns_sm) |
925
720b8268778e
mod_smacks: Don't allow steam resumption onto a stream after resource binding
Kim Alvefur <zash@zash.se>
parents:
908
diff
changeset
|
483 if session.full_jid then |
994
487cd02aada0
mod_smacks: Complain a little louder about clients trying to resume after resource binding
Kim Alvefur <zash@zash.se>
parents:
988
diff
changeset
|
484 session.log("warn", "Tried to resume after resource binding"); |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
485 session.send(st.stanza("failed", { xmlns = xmlns_sm }) |
925
720b8268778e
mod_smacks: Don't allow steam resumption onto a stream after resource binding
Kim Alvefur <zash@zash.se>
parents:
908
diff
changeset
|
486 :tag("unexpected-request", { xmlns = xmlns_errors }) |
720b8268778e
mod_smacks: Don't allow steam resumption onto a stream after resource binding
Kim Alvefur <zash@zash.se>
parents:
908
diff
changeset
|
487 ); |
720b8268778e
mod_smacks: Don't allow steam resumption onto a stream after resource binding
Kim Alvefur <zash@zash.se>
parents:
908
diff
changeset
|
488 return true; |
720b8268778e
mod_smacks: Don't allow steam resumption onto a stream after resource binding
Kim Alvefur <zash@zash.se>
parents:
908
diff
changeset
|
489 end |
720b8268778e
mod_smacks: Don't allow steam resumption onto a stream after resource binding
Kim Alvefur <zash@zash.se>
parents:
908
diff
changeset
|
490 |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
491 local id = stanza.attr.previd; |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
492 local original_session = session_registry.get(session.username, id); |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
493 if not original_session then |
588
8042558336b6
mod_smacks: Log message when client tries to resume unknown session
Matthew Wild <mwild1@gmail.com>
parents:
587
diff
changeset
|
494 session.log("debug", "Tried to resume non-existent session with id %s", id); |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
495 local old_session = old_session_registry.get(session.username, id); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
496 if old_session and session.username == old_session.username |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
497 and session.host == old_session.host |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
498 and old_session.h then |
2937
e672d1050529
mod_smacks: Ensure stanza count attributes are always strings (thanks Martin)
Matthew Wild <mwild1@gmail.com>
parents:
2756
diff
changeset
|
499 session.send(st.stanza("failed", { xmlns = xmlns_sm, h = string.format("%d", old_session.h) }) |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
500 :tag("item-not-found", { xmlns = xmlns_errors }) |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
501 ); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
502 else |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
503 session.send(st.stanza("failed", { xmlns = xmlns_sm }) |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
504 :tag("item-not-found", { xmlns = xmlns_errors }) |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
505 ); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
506 end; |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
507 elseif session.username == original_session.username |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
508 and session.host == original_session.host then |
3218
67f1d1f22625
mod_smacks: Improve logging on resume so session changes are more easily tracked
Matthew Wild <mwild1@gmail.com>
parents:
3150
diff
changeset
|
509 session.log("debug", "mod_smacks resuming existing session %s...", get_session_id(original_session)); |
3478
f6319346e2a3
mod_smacks: improved debug logging
Georg Lukas <georg@op-co.de>
parents:
3477
diff
changeset
|
510 original_session.log("debug", "mod_smacks session resumed from %s...", get_session_id(session)); |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
511 -- TODO: All this should move to sessionmanager (e.g. session:replace(new_session)) |
623
c1f3958695ea
mod_smacks: If a resumed session still has a connection open, close that connection before resuming
Matthew Wild <mwild1@gmail.com>
parents:
622
diff
changeset
|
512 if original_session.conn then |
3218
67f1d1f22625
mod_smacks: Improve logging on resume so session changes are more easily tracked
Matthew Wild <mwild1@gmail.com>
parents:
3150
diff
changeset
|
513 original_session.log("debug", "mod_smacks closing an old connection for this session"); |
623
c1f3958695ea
mod_smacks: If a resumed session still has a connection open, close that connection before resuming
Matthew Wild <mwild1@gmail.com>
parents:
622
diff
changeset
|
514 local conn = original_session.conn; |
640
d87131b29bbd
mod_smacks: Remove dependency on connlisteners (use sessions table shared by mod_c2s directly)
Matthew Wild <mwild1@gmail.com>
parents:
625
diff
changeset
|
515 c2s_sessions[conn] = nil; |
623
c1f3958695ea
mod_smacks: If a resumed session still has a connection open, close that connection before resuming
Matthew Wild <mwild1@gmail.com>
parents:
622
diff
changeset
|
516 conn:close(); |
c1f3958695ea
mod_smacks: If a resumed session still has a connection open, close that connection before resuming
Matthew Wild <mwild1@gmail.com>
parents:
622
diff
changeset
|
517 end |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
518 original_session.ip = session.ip; |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
519 original_session.conn = session.conn; |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
520 original_session.send = session.send; |
2623
a65260300708
mod_smacks: Made module more error resistant
tmolitor <thilo@eightysoft.de>
parents:
2608
diff
changeset
|
521 original_session.close = session.close; |
1637
ad6694f7b13c
mod_smacks: Don't restore filters from original session after resumption, use new filters
Matthew Wild <mwild1@gmail.com>
parents:
1599
diff
changeset
|
522 original_session.filter = session.filter; |
1706
e4867211cddb
mod_smacks: Set session upvalue of filter() to correct session
Kim Alvefur <zash@zash.se>
parents:
1705
diff
changeset
|
523 original_session.filter.session = original_session; |
1705
6fa220a9f36d
mod_smacks: Move set of filters from new session to session being resumed
Kim Alvefur <zash@zash.se>
parents:
1704
diff
changeset
|
524 original_session.filters = session.filters; |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
525 original_session.stream = session.stream; |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
526 original_session.secure = session.secure; |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
527 original_session.hibernating = nil; |
3479
9ef309fb501d
mod_smacks: apply resumed logger and type to new session, fix #1229
Georg Lukas <georg@op-co.de>
parents:
3478
diff
changeset
|
528 session.log = original_session.log; |
9ef309fb501d
mod_smacks: apply resumed logger and type to new session, fix #1229
Georg Lukas <georg@op-co.de>
parents:
3478
diff
changeset
|
529 session.type = original_session.type; |
1520
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
530 wrap_session(original_session, true); |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
531 -- Inform xmppstream of the new session (passed to its callbacks) |
1520
2881d532f385
mod_smacks: Use filters for queuing outgoing stanzas instead of wrapping session.send()
Kim Alvefur <zash@zash.se>
parents:
1518
diff
changeset
|
532 original_session.stream:set_session(original_session); |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
533 -- Similar for connlisteners |
640
d87131b29bbd
mod_smacks: Remove dependency on connlisteners (use sessions table shared by mod_c2s directly)
Matthew Wild <mwild1@gmail.com>
parents:
625
diff
changeset
|
534 c2s_sessions[session.conn] = original_session; |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
535 |
2623
a65260300708
mod_smacks: Made module more error resistant
tmolitor <thilo@eightysoft.de>
parents:
2608
diff
changeset
|
536 original_session.send(st.stanza("resumed", { xmlns = xmlns_sm, |
2937
e672d1050529
mod_smacks: Ensure stanza count attributes are always strings (thanks Martin)
Matthew Wild <mwild1@gmail.com>
parents:
2756
diff
changeset
|
537 h = string.format("%d", original_session.handled_stanza_count), previd = id })); |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1325
diff
changeset
|
538 |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
539 -- Fake an <a> with the h of the <resume/> from the client |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
540 original_session:dispatch_stanza(st.stanza("a", { xmlns = xmlns_sm, |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
541 h = stanza.attr.h })); |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1325
diff
changeset
|
542 |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
543 -- Ok, we need to re-send any stanzas that the client didn't see |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
544 -- ...they are what is now left in the outgoing stanza queue |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
545 local queue = original_session.outgoing_stanza_queue; |
2623
a65260300708
mod_smacks: Made module more error resistant
tmolitor <thilo@eightysoft.de>
parents:
2608
diff
changeset
|
546 original_session.log("debug", "#queue = %d", #queue); |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
547 for i=1,#queue do |
2623
a65260300708
mod_smacks: Made module more error resistant
tmolitor <thilo@eightysoft.de>
parents:
2608
diff
changeset
|
548 original_session.send(queue[i]); |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
549 end |
2623
a65260300708
mod_smacks: Made module more error resistant
tmolitor <thilo@eightysoft.de>
parents:
2608
diff
changeset
|
550 original_session.log("debug", "#queue = %d -- after send", #queue); |
a65260300708
mod_smacks: Made module more error resistant
tmolitor <thilo@eightysoft.de>
parents:
2608
diff
changeset
|
551 function session.send(stanza) |
a65260300708
mod_smacks: Made module more error resistant
tmolitor <thilo@eightysoft.de>
parents:
2608
diff
changeset
|
552 session.log("warn", "Tried to send stanza on old session migrated by smacks resume (maybe there is a bug?): %s", tostring(stanza)); |
a65260300708
mod_smacks: Made module more error resistant
tmolitor <thilo@eightysoft.de>
parents:
2608
diff
changeset
|
553 return false; |
a65260300708
mod_smacks: Made module more error resistant
tmolitor <thilo@eightysoft.de>
parents:
2608
diff
changeset
|
554 end |
2744
f70c02c14161
mod_smacks: Trigger event smacks-hibernation-end after queue resend
tmolitor <thilo@eightysoft.de>
parents:
2727
diff
changeset
|
555 module:fire_event("smacks-hibernation-end", {origin = session, resumed = original_session, queue = queue}); |
3478
f6319346e2a3
mod_smacks: improved debug logging
Georg Lukas <georg@op-co.de>
parents:
3477
diff
changeset
|
556 request_ack_if_needed(original_session, true, "handle_resume"); |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
557 else |
755 | 558 module:log("warn", "Client %s@%s[%s] tried to resume stream for %s@%s[%s]", |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
559 session.username or "?", session.host or "?", session.type, |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
560 original_session.username or "?", original_session.host or "?", original_session.type); |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
561 session.send(st.stanza("failed", { xmlns = xmlns_sm }) |
345
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
562 :tag("not-authorized", { xmlns = xmlns_errors })); |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
563 end |
445178d15b51
mod_smacks: Merge mod_fastreconnect (resumption support), fix a number of bugs, refactor the code and add some more comments to explain process
Matthew Wild <mwild1@gmail.com>
parents:
263
diff
changeset
|
564 return true; |
1298
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
565 end |
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
566 module:hook_stanza(xmlns_sm2, "resume", function (session, stanza) return handle_resume(session, stanza, xmlns_sm2); end); |
659da45a2b4b
mod_smacks: Handle both version 2 and version 3 namespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1293
diff
changeset
|
567 module:hook_stanza(xmlns_sm3, "resume", function (session, stanza) return handle_resume(session, stanza, xmlns_sm3); end); |
1733
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
568 |
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
569 local function handle_read_timeout(event) |
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
570 local session = event.session; |
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
571 if session.smacks then |
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
572 if session.awaiting_ack then |
2090
1796a022dd29
mod_smacks: Keep timer object around and stop it when needed (trunk only)
Kim Alvefur <zash@zash.se>
parents:
2089
diff
changeset
|
573 if session.awaiting_ack_timer then |
1796a022dd29
mod_smacks: Keep timer object around and stop it when needed (trunk only)
Kim Alvefur <zash@zash.se>
parents:
2089
diff
changeset
|
574 session.awaiting_ack_timer:stop(); |
1796a022dd29
mod_smacks: Keep timer object around and stop it when needed (trunk only)
Kim Alvefur <zash@zash.se>
parents:
2089
diff
changeset
|
575 end |
2394
4c27ebcf4cbd
mod_smacks: added new event "smacks-ack-delayed" used by mod_cloud_notify and extended the readme file accordingly (also mention mod_smacks_offline and mod_smacks_noerror in readme file)
tmolitor <thilo@eightysoft.de>
parents:
2251
diff
changeset
|
576 if session.delayed_ack_timer then |
4c27ebcf4cbd
mod_smacks: added new event "smacks-ack-delayed" used by mod_cloud_notify and extended the readme file accordingly (also mention mod_smacks_offline and mod_smacks_noerror in readme file)
tmolitor <thilo@eightysoft.de>
parents:
2251
diff
changeset
|
577 session.delayed_ack_timer:stop(); |
2494
d300ae5dba87
mod_smacks: Fix some bugs with smacks-ack-delayed event triggering.
tmolitor <thilo@eightysoft.de>
parents:
2491
diff
changeset
|
578 session.delayed_ack_timer = nil; |
2394
4c27ebcf4cbd
mod_smacks: added new event "smacks-ack-delayed" used by mod_cloud_notify and extended the readme file accordingly (also mention mod_smacks_offline and mod_smacks_noerror in readme file)
tmolitor <thilo@eightysoft.de>
parents:
2251
diff
changeset
|
579 end |
1733
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
580 return false; -- Kick the session |
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
581 end |
2091
ea95637cf041
mod_smacks: Log when sending <r> from read timeout event (0.10+)
Kim Alvefur <zash@zash.se>
parents:
2090
diff
changeset
|
582 session.log("debug", "Sending <r> (read timeout)"); |
2251
48c3d64a3fc1
mod_smacks: Signal that we're about to send an ack request from read timeout event to prevent a duplicate request from outgoing stanza filter
Kim Alvefur <zash@zash.se>
parents:
2148
diff
changeset
|
583 session.awaiting_ack = false; |
1733
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
584 (session.sends2s or session.send)(st.stanza("r", { xmlns = session.smacks })); |
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
585 session.awaiting_ack = true; |
2596
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
586 if not session.delayed_ack_timer then |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
587 session.delayed_ack_timer = stoppable_timer(delayed_ack_timeout, function() |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
588 delayed_ack_function(session); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
589 end); |
ffb6646b4253
Implement XEP-0198 revision 1.5.2 and limit number of hibernated sessions per user
tmolitor <thilo@eightysoft.de>
parents:
2494
diff
changeset
|
590 end |
1733
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
591 return true; |
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
592 end |
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
593 end |
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
594 |
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
595 module:hook("s2s-read-timeout", handle_read_timeout); |
9abd3dce619a
mod_smacks: Handle the read timeout event (0.10+ only) and send an ack request, close the connection the second time if unanswerd
Kim Alvefur <zash@zash.se>
parents:
1732
diff
changeset
|
596 module:hook("c2s-read-timeout", handle_read_timeout); |