comparison plugins/mod_s2s.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
parents 783706350faa
children 078780f262d5
comparison
equal deleted inserted replaced
13503:8b68e8faab52 13504:2159a206684e
40 local secure_auth = module:get_option_boolean("s2s_secure_auth", false); -- One day... 40 local secure_auth = module:get_option_boolean("s2s_secure_auth", false); -- One day...
41 local secure_domains, insecure_domains = 41 local secure_domains, insecure_domains =
42 module:get_option_set("s2s_secure_domains", {})._items, module:get_option_set("s2s_insecure_domains", {})._items; 42 module:get_option_set("s2s_secure_domains", {})._items, module:get_option_set("s2s_insecure_domains", {})._items;
43 local require_encryption = module:get_option_boolean("s2s_require_encryption", true); 43 local require_encryption = module:get_option_boolean("s2s_require_encryption", true);
44 local stanza_size_limit = module:get_option_integer("s2s_stanza_size_limit", 1024*512, 10000); 44 local stanza_size_limit = module:get_option_integer("s2s_stanza_size_limit", 1024*512, 10000);
45
46 local advertised_idle_timeout = 14*60; -- default in all net.server implementations
47 local network_settings = module:get_option("network_settings");
48 if type(network_settings) == "table" and type(network_settings.read_timeout) == "number" then
49 advertised_idle_timeout = network_settings.read_timeout;
50 end
45 51
46 local measure_connections_inbound = module:metric( 52 local measure_connections_inbound = module:metric(
47 "gauge", "connections_inbound", "", 53 "gauge", "connections_inbound", "",
48 "Established incoming s2s connections", 54 "Established incoming s2s connections",
49 {"host", "type", "ip_family"} 55 {"host", "type", "ip_family"}
256 return nil, "This host has disallow_s2s set"; 262 return nil, "This host has disallow_s2s set";
257 end 263 end
258 module:hook("route/remote", route_to_existing_session, -1); 264 module:hook("route/remote", route_to_existing_session, -1);
259 module:hook("route/remote", route_to_new_session, -10); 265 module:hook("route/remote", route_to_new_session, -10);
260 module:hook("s2sout-stream-features", function (event) 266 module:hook("s2sout-stream-features", function (event)
267 if not (stanza_size_limit or advertised_idle_timeout) then return end
268 local limits = event.features:tag("limits", { xmlns = "urn:xmpp:stream-limits:0" })
261 if stanza_size_limit then 269 if stanza_size_limit then
262 event.features:tag("limits", { xmlns = "urn:xmpp:stream-limits:0" }) 270 limits:text_tag("max-bytes", string.format("%d", stanza_size_limit));
263 :text_tag("max-bytes", string.format("%d", stanza_size_limit)):up(); 271 end
264 end 272 if advertised_idle_timeout then
273 limits:text_tag("idle-seconds", string.format("%d", advertised_idle_timeout));
274 end
275 limits:up();
265 end); 276 end);
266 module:hook_tag("urn:xmpp:bidi", "bidi", function(session, stanza) 277 module:hook_tag("urn:xmpp:bidi", "bidi", function(session, stanza)
267 -- Advertising features on bidi connections where no <stream:features> is sent in the other direction 278 -- Advertising features on bidi connections where no <stream:features> is sent in the other direction
268 local limits = stanza:get_child("limits", "urn:xmpp:stream-limits:0"); 279 local limits = stanza:get_child("limits", "urn:xmpp:stream-limits:0");
269 if limits then 280 if limits then
549 (session.log or log)("warn", "No 'to' on stream header from %s means we can't offer any features", from or session.ip or "unknown host"); 560 (session.log or log)("warn", "No 'to' on stream header from %s means we can't offer any features", from or session.ip or "unknown host");
550 module:fire_event("s2s-stream-features-legacy", { origin = session, features = features }); 561 module:fire_event("s2s-stream-features-legacy", { origin = session, features = features });
551 end 562 end
552 563
553 if ( session.type == "s2sin" or session.type == "s2sout" ) or features.tags[1] then 564 if ( session.type == "s2sin" or session.type == "s2sout" ) or features.tags[1] then
554 if stanza_size_limit then 565 if stanza_size_limit or advertised_idle_timeout then
555 features:reset(); 566 features:reset();
556 features:tag("limits", { xmlns = "urn:xmpp:stream-limits:0" }) 567 local limits = features:tag("limits", { xmlns = "urn:xmpp:stream-limits:0" });
557 :text_tag("max-bytes", string.format("%d", stanza_size_limit)):up(); 568 if stanza_size_limit then
569 limits:text_tag("max-bytes", string.format("%d", stanza_size_limit));
570 end
571 if advertised_idle_timeout then
572 limits:text_tag("idle-seconds", string.format("%d", advertised_idle_timeout));
573 end
574 features:reset();
558 end 575 end
559 576
560 log("debug", "Sending stream features: %s", features); 577 log("debug", "Sending stream features: %s", features);
561 session.sends2s(features); 578 session.sends2s(features);
562 else 579 else