Diff

plugins/mod_c2s.lua @ 13504:2159a206684e

mod_c2s,mod_s2s: Advertise idle-seconds per XEP-0478 This is the time after liveness checks are performed via the respective read-timeout event, which by default involves sending a space character but could be overridden e.g. as is done by mod_smacks. Only advertised, unsure what we would do with it.
author Kim Alvefur <zash@zash.se>
date Sat, 03 Aug 2024 16:28:59 +0200
parent 13420:7dc7e2e15b2a
child 13575:750ff9f579e2
line wrap: on
line diff
--- a/plugins/mod_c2s.lua	Fri Jul 12 15:06:42 2024 +0200
+++ b/plugins/mod_c2s.lua	Sat Aug 03 16:28:59 2024 +0200
@@ -30,6 +30,12 @@
 local opt_keepalives = module:get_option_boolean("c2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true));
 local stanza_size_limit = module:get_option_integer("c2s_stanza_size_limit", 1024*256,10000);
 
+local advertised_idle_timeout = 14*60; -- default in all net.server implementations
+local network_settings = module:get_option("network_settings");
+if type(network_settings) == "table" and type(network_settings.read_timeout) == "number" then
+	advertised_idle_timeout = network_settings.read_timeout;
+end
+
 local measure_connections = module:metric("gauge", "connections", "", "Established c2s connections", {"host", "type", "ip_family"});
 
 local sessions = module:shared("sessions");
@@ -130,10 +136,16 @@
 	local features = st.stanza("stream:features");
 	hosts[session.host].events.fire_event("stream-features", { origin = session, features = features, stream = attr });
 	if features.tags[1] or session.full_jid then
-		if stanza_size_limit then
+		if stanza_size_limit or advertised_idle_timeout then
 			features:reset();
-			features:tag("limits", { xmlns = "urn:xmpp:stream-limits:0" })
-				:text_tag("max-bytes", string.format("%d", stanza_size_limit)):up();
+			local limits = features:tag("limits", { xmlns = "urn:xmpp:stream-limits:0" });
+			if stanza_size_limit then
+				limits:text_tag("max-bytes", string.format("%d", stanza_size_limit));
+			end
+			if advertised_idle_timeout then
+				limits:text_tag("idle-seconds", string.format("%d", advertised_idle_timeout));
+			end
+			limits:reset();
 		end
 		send(features);
 	else