Software /
code /
prosody-modules
Annotate
mod_s2s_keepalive/mod_s2s_keepalive.lua @ 3764:07a1faa24261
mod_s2s_keepalive: Ping remotes we only have s2sin established from
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 21 Dec 2019 17:47:52 +0100 |
parent | 3723:427879b46061 |
child | 3765:11878130f266 |
rev | line source |
---|---|
1110
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local st = require "util.stanza"; |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local keepalive_servers = module:get_option_set("keepalive_servers"); |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local keepalive_interval = module:get_option_number("keepalive_interval", 60); |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local host = module.host; |
3764
07a1faa24261
mod_s2s_keepalive: Ping remotes we only have s2sin established from
Kim Alvefur <zash@zash.se>
parents:
3723
diff
changeset
|
7 local s2sout = prosody.hosts[host].s2sout; |
1110
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 local function send_pings() |
3764
07a1faa24261
mod_s2s_keepalive: Ping remotes we only have s2sin established from
Kim Alvefur <zash@zash.se>
parents:
3723
diff
changeset
|
10 local ping_hosts = {}; |
07a1faa24261
mod_s2s_keepalive: Ping remotes we only have s2sin established from
Kim Alvefur <zash@zash.se>
parents:
3723
diff
changeset
|
11 |
07a1faa24261
mod_s2s_keepalive: Ping remotes we only have s2sin established from
Kim Alvefur <zash@zash.se>
parents:
3723
diff
changeset
|
12 for remote_domain, session in pairs(s2sout) do |
1110
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 if session.type == "s2sout" -- as opposed to _unauthed |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 and (not(keepalive_servers) or keepalive_servers:contains(remote_domain)) then |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 session.sends2s(st.iq({ to = remote_domain, type = "get", from = host, id = "keepalive" }) |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 :tag("ping", { xmlns = "urn:xmpp:ping" }) |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 ); |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 -- Note: We don't actually check if this comes back. |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 end |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 end |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 for session in pairs(prosody.incoming_s2s) do |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 if session.type == "s2sin" -- as opposed to _unauthed |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 and (not(keepalive_servers) or keepalive_servers:contains(session.from_host)) then |
3764
07a1faa24261
mod_s2s_keepalive: Ping remotes we only have s2sin established from
Kim Alvefur <zash@zash.se>
parents:
3723
diff
changeset
|
25 if not s2sout[session.from_host] then ping_hosts[session.from_host] = true; end |
1264
2db2c03dfb95
mod_s2s_keepalive: Don't send directly on the connection, use sends2s
Kim Alvefur <zash@zash.se>
parents:
1110
diff
changeset
|
26 session.sends2s " "; |
1110
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 -- If the connection is dead, this should make it time out. |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 end |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 end |
3764
07a1faa24261
mod_s2s_keepalive: Ping remotes we only have s2sin established from
Kim Alvefur <zash@zash.se>
parents:
3723
diff
changeset
|
30 |
07a1faa24261
mod_s2s_keepalive: Ping remotes we only have s2sin established from
Kim Alvefur <zash@zash.se>
parents:
3723
diff
changeset
|
31 -- ping remotes we only have s2sin from |
07a1faa24261
mod_s2s_keepalive: Ping remotes we only have s2sin established from
Kim Alvefur <zash@zash.se>
parents:
3723
diff
changeset
|
32 for remote_domain in pairs(ping_hosts) do |
07a1faa24261
mod_s2s_keepalive: Ping remotes we only have s2sin established from
Kim Alvefur <zash@zash.se>
parents:
3723
diff
changeset
|
33 module:send(st.iq({ to = remote_domain, type = "get", from = host, id = "keepalive" }) |
07a1faa24261
mod_s2s_keepalive: Ping remotes we only have s2sin established from
Kim Alvefur <zash@zash.se>
parents:
3723
diff
changeset
|
34 :tag("ping", { xmlns = "urn:xmpp:ping" }) |
07a1faa24261
mod_s2s_keepalive: Ping remotes we only have s2sin established from
Kim Alvefur <zash@zash.se>
parents:
3723
diff
changeset
|
35 ); |
07a1faa24261
mod_s2s_keepalive: Ping remotes we only have s2sin established from
Kim Alvefur <zash@zash.se>
parents:
3723
diff
changeset
|
36 end |
07a1faa24261
mod_s2s_keepalive: Ping remotes we only have s2sin established from
Kim Alvefur <zash@zash.se>
parents:
3723
diff
changeset
|
37 |
1110
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 return keepalive_interval; |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 end |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 |
3723
427879b46061
mod_s2s_keepalive: Remove support for obsolete Prosody 0.8
Kim Alvefur <zash@zash.se>
parents:
1264
diff
changeset
|
41 module:add_timer(keepalive_interval, send_pings); |