Mercurial > prosody-hg
diff plugins/mod_s2s.lua @ 14138:c1469296190d
Merge 13.0->trunk
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 17 Apr 2026 14:35:32 +0100 |
| parents | b5eeb6730721 1e005ba71f0d |
| children | 5aacae4b2ccf |
line wrap: on
line diff
--- a/plugins/mod_s2s.lua Thu Apr 02 20:54:46 2026 +0100 +++ b/plugins/mod_s2s.lua Fri Apr 17 14:35:32 2026 +0100 @@ -41,7 +41,9 @@ local secure_domains, insecure_domains = module:get_option_set("s2s_secure_domains", {})._items, module:get_option_set("s2s_insecure_domains", {})._items; local require_encryption = module:get_option_boolean("s2s_require_encryption", true); -local stanza_size_limit = module:get_option_integer("s2s_stanza_size_limit", 1024*512, 10000); +local unauthed_stanza_size_limit = module:get_option_integer("s2s_unauthed_stanza_size_limit", 10000, 1000); +local authed_stanza_size_limit = module:get_option_integer("s2s_stanza_size_limit", 1024*512, 10000); +local max_child_elements = module:get_option_integer("s2s_max_child_elements", 25000, 0); local sendq_size = module:get_option_integer("s2s_send_queue_size", 1024*32, 1); local block_retries = module:get_option_boolean("s2s_block_immediate_retries", false); @@ -247,6 +249,8 @@ end host_session.version = 1; + host_session.stanza_size_limit = unauthed_stanza_size_limit; + -- Store in buffer host_session.bounce_sendq = bounce_sendq; host_session.sendq = queue.new(sendq_size); @@ -291,10 +295,11 @@ module:hook("route/remote", route_to_existing_session, -1); module:hook("route/remote", route_to_new_session, -10); module:hook("s2sout-stream-features", function (event) - if not (stanza_size_limit or advertised_idle_timeout) then return end + local session = event.origin; + if not (session.stanza_size_limit or advertised_idle_timeout) then return end local limits = event.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)); + if session.stanza_size_limit then + limits:text_tag("max-bytes", string.format("%d", session.stanza_size_limit)); end if advertised_idle_timeout then limits:text_tag("idle-seconds", string.format("%d", advertised_idle_timeout)); @@ -436,6 +441,9 @@ return false; end + session.stanza_size_limit = authed_stanza_size_limit; + session.stream:set_stanza_size_limit(session.stanza_size_limit); + if session.incoming and host then if not session.hosts[host] then session.hosts[host] = {}; end session.hosts[host].authed = true; @@ -594,11 +602,11 @@ end if ( session.type == "s2sin" or session.type == "s2sout" ) or features.tags[1] then - if stanza_size_limit or advertised_idle_timeout then + if session.stanza_size_limit or advertised_idle_timeout then features:reset(); 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)); + if session.stanza_size_limit then + limits:text_tag("max-bytes", string.format("%d", session.stanza_size_limit)); end if advertised_idle_timeout then limits:text_tag("idle-seconds", string.format("%d", advertised_idle_timeout)); @@ -815,7 +823,9 @@ -- Session initialization logic shared by incoming and outgoing local function initialize_session(session) - local stream = new_xmpp_stream(session, stream_callbacks, stanza_size_limit); + local stream = new_xmpp_stream(session, stream_callbacks, session.stanza_size_limit, { + max_elements = max_child_elements; + }); session.thread = runner(function (item) if st.is_stanza(item) then @@ -933,7 +943,7 @@ module:fire_event("s2sout-connected", { session = session }) session:open_stream(session.from_host, session.to_host); end - module:fire_event("s2s-connected", { session = session }) + module:fire_event("s2s-connected", { session = session, conn = conn }) session.ip = conn:ip(); end
