portmanager: Show a friendly error message when initializing SSL fails (thanks MattJ...
[prosody.git] / core / s2smanager.lua
index e61aaccbe652c431a9c4722cdef3068479757029..76dde9d27d3b0b81f25ec5b9f13743d4bf2888e0 100644 (file)
@@ -9,41 +9,15 @@
 
 
 local hosts = hosts;
-local core_process_stanza = function(a, b) core_process_stanza(a, b); end
-local format = string.format;
-local t_insert, t_sort = table.insert, table.sort;
-local get_traceback = debug.traceback;
-local tostring, pairs, ipairs, getmetatable, newproxy, type, error, tonumber, setmetatable
-    = tostring, pairs, ipairs, getmetatable, newproxy, type, error, tonumber, setmetatable;
-
-local initialize_filters = require "util.filters".initialize;
-local wrapclient = require "net.server".wrapclient;
-local st = require "stanza";
-local stanza = st.stanza;
-local nameprep = require "util.encodings".stringprep.nameprep;
-local cert_verify_identity = require "util.x509".verify_identity;
-local new_ip = require "util.ip".new_ip;
-local rfc3484_dest = require "util.rfc3484".destination;
+local tostring, pairs, ipairs, getmetatable, newproxy, setmetatable
+    = tostring, pairs, ipairs, getmetatable, newproxy, setmetatable;
 
 local fire_event = prosody.events.fire_event;
-local uuid_gen = require "util.uuid".generate;
-
 local logger_init = require "util.logger".init;
 
 local log = logger_init("s2smanager");
 
-local sha256_hash = require "util.hashes".sha256;
-
-local adns, dns = require "net.adns", require "net.dns";
 local config = require "core.configmanager";
-local dns_timeout = config.get("*", "core", "dns_timeout") or 15;
-local max_dns_depth = config.get("*", "core", "dns_max_depth") or 3;
-local cfg_sources = config.get("*", "core", "s2s_interface")
-       or config.get("*", "core", "interface");
-local sources;
-
---FIXME: s2sout should create its own resolver w/ timeout
-dns.settimeout(dns_timeout);
 
 local prosody = _G.prosody;
 incoming_s2s = {};
@@ -100,7 +74,7 @@ function make_authenticated(session, host)
        else
                return false;
        end
-       session.log("debug", "connection %s->%s is now authenticated", session.from_host or "(unknown)", session.to_host or "(unknown)");
+       session.log("debug", "connection %s->%s is now authenticated for %s", session.from_host, session.to_host, host);
        
        mark_connected(session);
        
@@ -113,23 +87,25 @@ function mark_connected(session)
        
        local from, to = session.from_host, session.to_host;
        
-       session.log("info", session.direction.." s2s connection "..from.."->"..to.." complete");
-       
-       local send_to_host = send_to_host;
-       function session.send(data) return send_to_host(to, from, data); end
-       
+       session.log("info", "%s s2s connection %s->%s complete", session.direction, from, to);
+
        local event_data = { session = session };
        if session.type == "s2sout" then
                prosody.events.fire_event("s2sout-established", event_data);
-               hosts[session.from_host].events.fire_event("s2sout-established", event_data);
+               hosts[from].events.fire_event("s2sout-established", event_data);
        else
+               local host_session = hosts[to];
+               session.send = function(stanza)
+                       host_session.events.fire_event("route/remote", { from_host = to, to_host = from, stanza = stanza });
+               end;
+
                prosody.events.fire_event("s2sin-established", event_data);
-               hosts[session.to_host].events.fire_event("s2sin-established", event_data);
+               hosts[to].events.fire_event("s2sin-established", event_data);
        end
        
        if session.direction == "outgoing" then
                if sendq then
-                       session.log("debug", "sending "..#sendq.." queued stanzas across new outgoing connection to "..session.to_host);
+                       session.log("debug", "sending %d queued stanzas across new outgoing connection to %s", #sendq, session.to_host);
                        for i, data in ipairs(sendq) do
                                send(data[1]);
                                sendq[i] = nil;
@@ -137,6 +113,7 @@ function mark_connected(session)
                        session.sendq = nil;
                end
                
+               session.ip_hosts = nil;
                session.srv_hosts = nil;
        end
 end
@@ -156,7 +133,7 @@ local resting_session = { -- Resting, not dead
 function retire_session(session, reason)
        local log = session.log or log;
        for k in pairs(session) do
-               if k ~= "trace" and k ~= "log" and k ~= "id" then
+               if k ~= "trace" and k ~= "log" and k ~= "id" and k ~= "conn" then
                        session[k] = nil;
                end
        end