mod_s2s: Factor out procedure for newly encrypted sessions
authorKim Alvefur <zash@zash.se>
Tue, 10 Aug 2021 20:51:31 +0200
changeset 11776 e2155e2703dd
parent 11775 4c0802b52673
child 11777 c5f2b63cf6ff
mod_s2s: Factor out procedure for newly encrypted sessions Goal is to call this if the connection is using Direct TLS, either via multiplexing or a future Direct TLS S2S port.
plugins/mod_s2s.lua
--- a/plugins/mod_s2s.lua	Mon Jun 21 22:50:23 2021 +0200
+++ b/plugins/mod_s2s.lua	Tue Aug 10 20:51:31 2021 +0200
@@ -379,6 +379,21 @@
 
 --- XMPP stream event handlers
 
+local function session_secure(session)
+	session.secure = true;
+	session.encrypted = true;
+
+	local sock = session.conn:socket();
+	local info = sock.info and sock:info();
+	if type(info) == "table" then
+		(session.log or log)("info", "Stream encrypted (%s with %s)", info.protocol, info.cipher);
+		session.compressed = info.compression;
+		m_tls_params:with_labels(info.protocol, info.cipher):add(1)
+	else
+		(session.log or log)("info", "Stream encrypted");
+	end
+end
+
 local stream_callbacks = { default_ns = "jabber:server" };
 
 function stream_callbacks.handlestanza(session, stanza)
@@ -399,18 +414,7 @@
 
 	-- TODO: Rename session.secure to session.encrypted
 	if session.secure == false then
-		session.secure = true;
-		session.encrypted = true;
-
-		local sock = session.conn:socket();
-		local info = sock.info and sock:info();
-		if type(info) == "table" then
-			(session.log or log)("info", "Stream encrypted (%s with %s)", info.protocol, info.cipher);
-			session.compressed = info.compression;
-			m_tls_params:with_labels(info.protocol, info.cipher):add(1)
-		else
-			(session.log or log)("info", "Stream encrypted");
-		end
+		session_secure(session);
 	end
 
 	if session.direction == "incoming" then