Software /
code /
prosody
Comparison
plugins/mod_admin_shell.lua @ 12122:50795249b7be
mod_admin_shell: Print s2s related events while waiting for ping
Gives a better idea of what's taking time.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 26 Dec 2021 16:26:36 +0100 |
parent | 12056:e62025f949f9 |
child | 12126:0d8e6646ce42 |
comparison
equal
deleted
inserted
replaced
12121:2162e86029b6 | 12122:50795249b7be |
---|---|
1385 return nil, "Both hosts are local"; | 1385 return nil, "Both hosts are local"; |
1386 end | 1386 end |
1387 local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()} | 1387 local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()} |
1388 :tag("ping", {xmlns="urn:xmpp:ping"}); | 1388 :tag("ping", {xmlns="urn:xmpp:ping"}); |
1389 local time_start = time.now(); | 1389 local time_start = time.now(); |
1390 return module:context(localhost):send_iq(iq, nil, timeout):next(function (pong) | 1390 local print = self.session.print; |
1391 local function onchange(what) | |
1392 return function(event) | |
1393 local s2s_session = event.session; | |
1394 if (s2s_session.from_host == localhost and s2s_session.to_host == remotehost) | |
1395 or (s2s_session.to_host == localhost and s2s_session.from_host == remotehost) then | |
1396 local dir = available_columns.dir.mapper(s2s_session.direction, s2s_session); | |
1397 print(("Session %s (%s%s%s) %s (%gs)"):format(s2s_session.id, localhost, dir, remotehost, what, | |
1398 time.now() - time_start)); | |
1399 end | |
1400 end | |
1401 end | |
1402 local oncreated = onchange("created"); | |
1403 local onauthenticated = onchange("authenticated"); | |
1404 local onestablished = onchange("established"); | |
1405 local ondestroyed = onchange("destroyed"); | |
1406 module:hook("s2s-created", oncreated, 1); | |
1407 module:context(localhost):hook("s2s-authenticated", onauthenticated, 1); | |
1408 module:hook("s2sout-established", onestablished, 1); | |
1409 module:hook("s2sin-established", onestablished, 1); | |
1410 module:hook("s2s-destroyed", ondestroyed, 1); | |
1411 return module:context(localhost):send_iq(iq, nil, timeout):finally(function() | |
1412 module:unhook("s2s-created", oncreated); | |
1413 module:context(localhost):unhook("s2s-authenticated", onauthenticated); | |
1414 module:unhook("s2sout-established", onestablished); | |
1415 module:unhook("s2sin-established", onestablished); | |
1416 module:unhook("s2s-destroyed", ondestroyed); | |
1417 end):next(function(pong) | |
1391 return ("pong from %s in %gs"):format(pong.stanza.attr.from, time.now() - time_start); | 1418 return ("pong from %s in %gs"):format(pong.stanza.attr.from, time.now() - time_start); |
1392 end); | 1419 end); |
1393 end | 1420 end |
1394 | 1421 |
1395 def_env.dns = {}; | 1422 def_env.dns = {}; |