Mercurial > prosody-modules
annotate mod_pinger/mod_pinger.lua @ 2671:80b6c63cb559
mod_pinger: Fix hardcoded smacks namespace, fixes #712
author | tmolitor <thilo@eightysoft.de> |
---|---|
date | Thu, 06 Apr 2017 02:31:16 +0200 |
parents | 256a5e3591db |
children | 75ab061069aa |
rev | line source |
---|---|
2034 | 1 local new_watchdog = require "util.watchdog".new; |
2 local filters = require "util.filters"; | |
3 local st = require "util.stanza"; | |
4 | |
5 local idle_timeout = module:get_option_number("c2s_idle_timeout", 300); | |
6 local ping_timeout = module:get_option_number("c2s_ping_timeout", 30); | |
7 | |
8 function update_watchdog(data, session) | |
9 session.idle_watchdog:reset(); | |
10 session.idle_pinged = nil; | |
11 return data; | |
12 end | |
13 | |
14 function check_session(watchdog) | |
15 local session = watchdog.session; | |
16 if not session.idle_pinged then | |
17 session.idle_pinged = true; | |
2671
80b6c63cb559
mod_pinger: Fix hardcoded smacks namespace, fixes #712
tmolitor <thilo@eightysoft.de>
parents:
2034
diff
changeset
|
18 if session.smacks and not session.awaiting_ack then |
80b6c63cb559
mod_pinger: Fix hardcoded smacks namespace, fixes #712
tmolitor <thilo@eightysoft.de>
parents:
2034
diff
changeset
|
19 session.send(st.stanza("r", { xmlns = session.smacks })) |
80b6c63cb559
mod_pinger: Fix hardcoded smacks namespace, fixes #712
tmolitor <thilo@eightysoft.de>
parents:
2034
diff
changeset
|
20 else |
80b6c63cb559
mod_pinger: Fix hardcoded smacks namespace, fixes #712
tmolitor <thilo@eightysoft.de>
parents:
2034
diff
changeset
|
21 session.send(st.iq({ type = "get", from = module.host, id = "idle-check" }) |
80b6c63cb559
mod_pinger: Fix hardcoded smacks namespace, fixes #712
tmolitor <thilo@eightysoft.de>
parents:
2034
diff
changeset
|
22 :tag("ping", { xmlns = "urn:xmpp:ping" })); |
80b6c63cb559
mod_pinger: Fix hardcoded smacks namespace, fixes #712
tmolitor <thilo@eightysoft.de>
parents:
2034
diff
changeset
|
23 end |
2034 | 24 return ping_timeout; -- Call us again after ping_timeout |
25 else | |
26 module:log("info", "Client %q silent for too long, closing...", session.full_jid); | |
27 session:close("connection-timeout"); | |
28 end | |
29 end | |
30 | |
31 | |
32 function watch_session(session) | |
33 if not session.idle_watchdog | |
34 and not session.requests then -- Don't watch BOSH connections (BOSH already has timeouts) | |
35 session.idle_watchdog = new_watchdog(idle_timeout, check_session); | |
36 session.idle_watchdog.session = session; | |
37 filters.add_filter(session, "bytes/in", update_watchdog); | |
38 end | |
39 end | |
40 | |
41 function unwatch_session(session) | |
42 if session.idle_watchdog then | |
43 session.idle_watchdog:cancel(); | |
44 session.idle_watchdog = nil; | |
45 filters.remove_filter(session, "bytes/in", update_watchdog); | |
46 end | |
47 end | |
48 | |
49 module:hook("resource-bind", function (event) watch_session(event.session); end); | |
50 module:hook("resource-unbind", function (event) unwatch_session(event.session); end); |