Changeset

4212:593fd9e0a435

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.
author Kim Alvefur <zash@zash.se>
date Fri, 16 Oct 2020 13:18:11 +0200
parents 4211:0f26ae2f2a74
children 4213:93a980ac1816
files mod_s2s_keepalive/mod_s2s_keepalive.lua
diffstat 1 files changed, 6 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- 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);