diff options
author | Kim Alvefur <zash@zash.se> | 2021-12-26 16:26:36 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-12-26 16:26:36 +0100 |
commit | 257f52d826db491f3861a5a7546faf6c940bb629 (patch) | |
tree | 61c8e40501ffae6c7f6877b2920639dea01adda4 /plugins/mod_admin_shell.lua | |
parent | 5a1aa107c36d48a7f9c0b94d3b7b5f94eb1889af (diff) | |
download | prosody-257f52d826db491f3861a5a7546faf6c940bb629.tar.gz prosody-257f52d826db491f3861a5a7546faf6c940bb629.zip |
mod_admin_shell: Print s2s related events while waiting for ping
Gives a better idea of what's taking time.
Diffstat (limited to 'plugins/mod_admin_shell.lua')
-rw-r--r-- | plugins/mod_admin_shell.lua | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/plugins/mod_admin_shell.lua b/plugins/mod_admin_shell.lua index 71597ee9..0b3c12e6 100644 --- a/plugins/mod_admin_shell.lua +++ b/plugins/mod_admin_shell.lua @@ -1387,7 +1387,34 @@ function def_env.xmpp:ping(localhost, remotehost, timeout) local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()} :tag("ping", {xmlns="urn:xmpp:ping"}); local time_start = time.now(); - return module:context(localhost):send_iq(iq, nil, timeout):next(function (pong) + local print = self.session.print; + local function onchange(what) + return function(event) + local s2s_session = event.session; + if (s2s_session.from_host == localhost and s2s_session.to_host == remotehost) + or (s2s_session.to_host == localhost and s2s_session.from_host == remotehost) then + local dir = available_columns.dir.mapper(s2s_session.direction, s2s_session); + print(("Session %s (%s%s%s) %s (%gs)"):format(s2s_session.id, localhost, dir, remotehost, what, + time.now() - time_start)); + end + end + end + local oncreated = onchange("created"); + local onauthenticated = onchange("authenticated"); + local onestablished = onchange("established"); + local ondestroyed = onchange("destroyed"); + module:hook("s2s-created", oncreated, 1); + module:context(localhost):hook("s2s-authenticated", onauthenticated, 1); + module:hook("s2sout-established", onestablished, 1); + module:hook("s2sin-established", onestablished, 1); + module:hook("s2s-destroyed", ondestroyed, 1); + return module:context(localhost):send_iq(iq, nil, timeout):finally(function() + module:unhook("s2s-created", oncreated); + module:context(localhost):unhook("s2s-authenticated", onauthenticated); + module:unhook("s2sout-established", onestablished); + module:unhook("s2sin-established", onestablished); + module:unhook("s2s-destroyed", ondestroyed); + end):next(function(pong) return ("pong from %s in %gs"):format(pong.stanza.attr.from, time.now() - time_start); end); end |