# HG changeset patch # User Kim Alvefur # Date 1602847091 -7200 # Node ID 593fd9e0a435d76f55e4683b4e3ea74469740540 # Parent 0f26ae2f2a74915e91a56ce572bbafb8e5afb37e mod_s2s_keepalive: Fix response handler (thanks Ge0rG) So there are no 'iq-{result,error}/host' events, mod_iq only fires events for result stanzas that include the full 'id' attr. This fixes it by hooking the stanza router event. diff -r 0f26ae2f2a74 -r 593fd9e0a435 mod_s2s_keepalive/mod_s2s_keepalive.lua --- a/mod_s2s_keepalive/mod_s2s_keepalive.lua Fri Oct 16 11:06:25 2020 +0100 +++ b/mod_s2s_keepalive/mod_s2s_keepalive.lua Fri Oct 16 13:18:11 2020 +0200 @@ -61,14 +61,19 @@ end); end); -module:hook("iq-result/host", function (event) +module:hook("iq/host", function (event) local stanza = event.stanza; + if stanza.attr.type ~= "result" and stanza.attr.type == "error" then + return -- not a reply iq stanza + end if not (stanza.attr.id and stanza.attr.id:sub(1, #"keepalive:") == "keepalive:") then return -- not a reply to this module end local origin = event.origin; + if origin.dummy then return end -- Probably a sendq bounce if origin.watchdog_keepalive then + origin.log("debug", "Resetting keepalive watchdog") origin.watchdog_keepalive:reset(); end if s2sout[origin.from_host] and s2sout[origin.from_host].watchdog_keepalive then @@ -76,21 +81,3 @@ end return true; end); - -module:hook("iq-error/host", function (event) - local origin = event.origin; - if origin.dummy then return end -- Probably a sendq bounce - - local stanza = event.stanza; - if not (stanza.attr.id and stanza.attr.id:sub(1, #"keepalive:") == "keepalive:") then - return -- not a reply to this module - end - - if origin.type == "s2sin" or origin.type == "s2sout" then - -- An error from the remote means connectivity is ok, - -- so treat it the same as a result - return module:fire_event("iq-result/host", event); - end -end); - -module:add_timer(keepalive_interval, send_pings);