Mercurial > prosody-modules
annotate mod_s2s_keepalive/mod_s2s_keepalive.lua @ 3733:9a3d25311fd9
mod_log_json: Use filename from logging config
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 03 Nov 2019 14:33:01 +0100 |
parents | 427879b46061 |
children | 07a1faa24261 |
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; |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local function send_pings() |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 for remote_domain, session in pairs(hosts[host].s2sout) do |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 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
|
11 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
|
12 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
|
13 :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
|
14 ); |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 -- 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
|
16 end |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 end |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 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
|
20 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
|
21 and (not(keepalive_servers) or keepalive_servers:contains(session.from_host)) then |
1264
2db2c03dfb95
mod_s2s_keepalive: Don't send directly on the connection, use sends2s
Kim Alvefur <zash@zash.se>
parents:
1110
diff
changeset
|
22 session.sends2s " "; |
1110
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 -- 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
|
24 end |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 end |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 return keepalive_interval; |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 end |
97e238ce37ce
mod_s2s_keepalive: Initial commit, poke s2s connections with pings and whitespace
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 |
3723
427879b46061
mod_s2s_keepalive: Remove support for obsolete Prosody 0.8
Kim Alvefur <zash@zash.se>
parents:
1264
diff
changeset
|
29 module:add_timer(keepalive_interval, send_pings); |