Comparison

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
comparison
equal deleted inserted replaced
3763:f384669a9359 3764:07a1faa24261
2 2
3 local keepalive_servers = module:get_option_set("keepalive_servers"); 3 local keepalive_servers = module:get_option_set("keepalive_servers");
4 local keepalive_interval = module:get_option_number("keepalive_interval", 60); 4 local keepalive_interval = module:get_option_number("keepalive_interval", 60);
5 5
6 local host = module.host; 6 local host = module.host;
7 local s2sout = prosody.hosts[host].s2sout;
7 8
8 local function send_pings() 9 local function send_pings()
9 for remote_domain, session in pairs(hosts[host].s2sout) do 10 local ping_hosts = {};
11
12 for remote_domain, session in pairs(s2sout) do
10 if session.type == "s2sout" -- as opposed to _unauthed 13 if session.type == "s2sout" -- as opposed to _unauthed
11 and (not(keepalive_servers) or keepalive_servers:contains(remote_domain)) then 14 and (not(keepalive_servers) or keepalive_servers:contains(remote_domain)) then
12 session.sends2s(st.iq({ to = remote_domain, type = "get", from = host, id = "keepalive" }) 15 session.sends2s(st.iq({ to = remote_domain, type = "get", from = host, id = "keepalive" })
13 :tag("ping", { xmlns = "urn:xmpp:ping" }) 16 :tag("ping", { xmlns = "urn:xmpp:ping" })
14 ); 17 );
17 end 20 end
18 21
19 for session in pairs(prosody.incoming_s2s) do 22 for session in pairs(prosody.incoming_s2s) do
20 if session.type == "s2sin" -- as opposed to _unauthed 23 if session.type == "s2sin" -- as opposed to _unauthed
21 and (not(keepalive_servers) or keepalive_servers:contains(session.from_host)) then 24 and (not(keepalive_servers) or keepalive_servers:contains(session.from_host)) then
25 if not s2sout[session.from_host] then ping_hosts[session.from_host] = true; end
22 session.sends2s " "; 26 session.sends2s " ";
23 -- If the connection is dead, this should make it time out. 27 -- If the connection is dead, this should make it time out.
24 end 28 end
25 end 29 end
30
31 -- ping remotes we only have s2sin from
32 for remote_domain in pairs(ping_hosts) do
33 module:send(st.iq({ to = remote_domain, type = "get", from = host, id = "keepalive" })
34 :tag("ping", { xmlns = "urn:xmpp:ping" })
35 );
36 end
37
26 return keepalive_interval; 38 return keepalive_interval;
27 end 39 end
28 40
29 module:add_timer(keepalive_interval, send_pings); 41 module:add_timer(keepalive_interval, send_pings);