Mercurial > prosody-modules
annotate mod_pinger/mod_pinger.lua @ 2798:e9ca7fd4ad06
mod_auth_dovecot: Support new luasocket unix domain socket API (fixes https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=852250 in Debian Stretch)
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 14 Oct 2017 23:04:02 -0400 |
parents | c971b2cee2cc |
children | 5bf79bb3cf7e |
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; | |
2674
c971b2cee2cc
mod_pinger: Try to solve smacks related issues, see #712
tmolitor <thilo@eightysoft.de>
parents:
2672
diff
changeset
|
18 if session.smacks then |
c971b2cee2cc
mod_pinger: Try to solve smacks related issues, see #712
tmolitor <thilo@eightysoft.de>
parents:
2672
diff
changeset
|
19 if not session.awaiting_ack then |
2671
80b6c63cb559
mod_pinger: Fix hardcoded smacks namespace, fixes #712
tmolitor <thilo@eightysoft.de>
parents:
2034
diff
changeset
|
20 session.send(st.stanza("r", { xmlns = session.smacks })) |
2674
c971b2cee2cc
mod_pinger: Try to solve smacks related issues, see #712
tmolitor <thilo@eightysoft.de>
parents:
2672
diff
changeset
|
21 end |
2671
80b6c63cb559
mod_pinger: Fix hardcoded smacks namespace, fixes #712
tmolitor <thilo@eightysoft.de>
parents:
2034
diff
changeset
|
22 else |
2674
c971b2cee2cc
mod_pinger: Try to solve smacks related issues, see #712
tmolitor <thilo@eightysoft.de>
parents:
2672
diff
changeset
|
23 session.send(st.iq({ type = "get", from = module.host, id = "idle-check" }) |
c971b2cee2cc
mod_pinger: Try to solve smacks related issues, see #712
tmolitor <thilo@eightysoft.de>
parents:
2672
diff
changeset
|
24 :tag("ping", { xmlns = "urn:xmpp:ping" })); |
2671
80b6c63cb559
mod_pinger: Fix hardcoded smacks namespace, fixes #712
tmolitor <thilo@eightysoft.de>
parents:
2034
diff
changeset
|
25 end |
2034 | 26 return ping_timeout; -- Call us again after ping_timeout |
27 else | |
28 module:log("info", "Client %q silent for too long, closing...", session.full_jid); | |
29 session:close("connection-timeout"); | |
30 end | |
31 end | |
32 | |
33 | |
34 function watch_session(session) | |
35 if not session.idle_watchdog | |
36 and not session.requests then -- Don't watch BOSH connections (BOSH already has timeouts) | |
37 session.idle_watchdog = new_watchdog(idle_timeout, check_session); | |
38 session.idle_watchdog.session = session; | |
39 filters.add_filter(session, "bytes/in", update_watchdog); | |
40 end | |
41 end | |
42 | |
43 function unwatch_session(session) | |
44 if session.idle_watchdog then | |
45 session.idle_watchdog:cancel(); | |
46 session.idle_watchdog = nil; | |
47 filters.remove_filter(session, "bytes/in", update_watchdog); | |
48 end | |
49 end | |
50 | |
51 module:hook("resource-bind", function (event) watch_session(event.session); end); | |
52 module:hook("resource-unbind", function (event) unwatch_session(event.session); end); | |
2672
75ab061069aa
mod_pinger: Don't ping when smacks hibernated the session, fixes #712
tmolitor <thilo@eightysoft.de>
parents:
2671
diff
changeset
|
53 |
75ab061069aa
mod_pinger: Don't ping when smacks hibernated the session, fixes #712
tmolitor <thilo@eightysoft.de>
parents:
2671
diff
changeset
|
54 -- handle smacks sessions properly (not pinging in hibernated state) |
75ab061069aa
mod_pinger: Don't ping when smacks hibernated the session, fixes #712
tmolitor <thilo@eightysoft.de>
parents:
2671
diff
changeset
|
55 module:hook("smacks-hibernation-start", function (event) unwatch_session(event.origin); end); |
2674
c971b2cee2cc
mod_pinger: Try to solve smacks related issues, see #712
tmolitor <thilo@eightysoft.de>
parents:
2672
diff
changeset
|
56 module:hook("smacks-hibernation-end", function (event) watch_session(event.resumed); end); |