Software /
code /
prosody
Comparison
plugins/mod_admin_telnet.lua @ 10310:b03065cd033a
mod_admin_telnet: xmpp:ping: Log ping time
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 06 Oct 2019 19:35:35 +0200 |
parent | 10292:8fb546e40756 |
child | 10383:496248e48a1d |
comparison
equal
deleted
inserted
replaced
10309:2a31571efce0 | 10310:b03065cd033a |
---|---|
31 local envload = require "util.envload".envload; | 31 local envload = require "util.envload".envload; |
32 local envloadfile = require "util.envload".envloadfile; | 32 local envloadfile = require "util.envload".envloadfile; |
33 local has_pposix, pposix = pcall(require, "util.pposix"); | 33 local has_pposix, pposix = pcall(require, "util.pposix"); |
34 local async = require "util.async"; | 34 local async = require "util.async"; |
35 local serialize = require "util.serialization".new({ fatal = false, unquoted = true}); | 35 local serialize = require "util.serialization".new({ fatal = false, unquoted = true}); |
36 local time = require "util.time"; | |
36 | 37 |
37 local commands = module:shared("commands") | 38 local commands = module:shared("commands") |
38 local def_env = module:shared("env"); | 39 local def_env = module:shared("env"); |
39 local default_env_mt = { __index = def_env }; | 40 local default_env_mt = { __index = def_env }; |
40 | 41 |
1146 elseif prosody.hosts[remotehost] then | 1147 elseif prosody.hosts[remotehost] then |
1147 return nil, "Both hosts are local"; | 1148 return nil, "Both hosts are local"; |
1148 end | 1149 end |
1149 local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()} | 1150 local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()} |
1150 :tag("ping", {xmlns="urn:xmpp:ping"}); | 1151 :tag("ping", {xmlns="urn:xmpp:ping"}); |
1152 local time_start = time.now(); | |
1151 local ret, err = async.wait(module:context(localhost):send_iq(iq, nil, timeout)); | 1153 local ret, err = async.wait(module:context(localhost):send_iq(iq, nil, timeout)); |
1152 if ret then | 1154 if ret then |
1153 return true, "pong from " .. ret.stanza.attr.from; | 1155 return true, ("pong from %s in %gs"):format(ret.stanza.attr.from, time.now() - time_start); |
1154 else | 1156 else |
1155 return false, tostring(err); | 1157 return false, tostring(err); |
1156 end | 1158 end |
1157 end | 1159 end |
1158 | 1160 |