comparison mod_s2s_keepalive/mod_s2s_keepalive.lua @ 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 a5930a185806
children 93a980ac1816
comparison
equal deleted inserted replaced
4211:0f26ae2f2a74 4212:593fd9e0a435
59 session.log("info", "Keepalive ping timed out, closing connection"); 59 session.log("info", "Keepalive ping timed out, closing connection");
60 session:close("connection-timeout"); 60 session:close("connection-timeout");
61 end); 61 end);
62 end); 62 end);
63 63
64 module:hook("iq-result/host", function (event) 64 module:hook("iq/host", function (event)
65 local stanza = event.stanza; 65 local stanza = event.stanza;
66 if stanza.attr.type ~= "result" and stanza.attr.type == "error" then
67 return -- not a reply iq stanza
68 end
66 if not (stanza.attr.id and stanza.attr.id:sub(1, #"keepalive:") == "keepalive:") then 69 if not (stanza.attr.id and stanza.attr.id:sub(1, #"keepalive:") == "keepalive:") then
67 return -- not a reply to this module 70 return -- not a reply to this module
68 end 71 end
69 72
70 local origin = event.origin; 73 local origin = event.origin;
74 if origin.dummy then return end -- Probably a sendq bounce
71 if origin.watchdog_keepalive then 75 if origin.watchdog_keepalive then
76 origin.log("debug", "Resetting keepalive watchdog")
72 origin.watchdog_keepalive:reset(); 77 origin.watchdog_keepalive:reset();
73 end 78 end
74 if s2sout[origin.from_host] and s2sout[origin.from_host].watchdog_keepalive then 79 if s2sout[origin.from_host] and s2sout[origin.from_host].watchdog_keepalive then
75 s2sout[origin.from_host].watchdog_keepalive:reset(); 80 s2sout[origin.from_host].watchdog_keepalive:reset();
76 end 81 end
77 return true; 82 return true;
78 end); 83 end);
79
80 module:hook("iq-error/host", function (event)
81 local origin = event.origin;
82 if origin.dummy then return end -- Probably a sendq bounce
83
84 local stanza = event.stanza;
85 if not (stanza.attr.id and stanza.attr.id:sub(1, #"keepalive:") == "keepalive:") then
86 return -- not a reply to this module
87 end
88
89 if origin.type == "s2sin" or origin.type == "s2sout" then
90 -- An error from the remote means connectivity is ok,
91 -- so treat it the same as a result
92 return module:fire_event("iq-result/host", event);
93 end
94 end);
95
96 module:add_timer(keepalive_interval, send_pings);