# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1661533403 -7200
# Node ID ca4abc6ab2084f3fe4ccb7e5e6a8ebdbd41ae620
# Parent  5a61e1603f4273a5e6b2f77715e3491593313fb8# Parent  7d4a95ba9b6c6ce4491b989c147c71c11e96cf0b
Merge 0.12->trunk

diff -r 5a61e1603f42 -r ca4abc6ab208 plugins/mod_s2s.lua
--- a/plugins/mod_s2s.lua	Fri Aug 26 17:28:06 2022 +0100
+++ b/plugins/mod_s2s.lua	Fri Aug 26 19:03:23 2022 +0200
@@ -460,6 +460,7 @@
 		end
 		if session.type == "s2sin_unauthed" and to and not session.to_host then
 			session.to_host = to;
+			session.host = to;
 		elseif to ~= session.to_host then
 			session:close({ condition = "improper-addressing", text = "New stream 'to' attribute does not match original" });
 			return;
@@ -885,8 +886,7 @@
 function listener.onreadtimeout(conn)
 	local session = sessions[conn];
 	if session then
-		local host = session.host or session.to_host;
-		return (hosts[host] or prosody).events.fire_event("s2s-read-timeout", { session = session });
+		return (hosts[session.host] or prosody).events.fire_event("s2s-read-timeout", { session = session });
 	end
 end