portmanager: Show a friendly error message when initializing SSL fails (thanks MattJ...
[prosody.git] / core / s2smanager.lua
index ea626baa4f7b78c693142adbbec05dd68dfd0ec9..76dde9d27d3b0b81f25ec5b9f13743d4bf2888e0 100644 (file)
@@ -74,7 +74,7 @@ function make_authenticated(session, host)
        else
                return false;
        end
-       session.log("debug", "connection %s->%s is now authenticated for %s", session.from_host or "(unknown)", session.to_host or "(unknown)", host);
+       session.log("debug", "connection %s->%s is now authenticated for %s", session.from_host, session.to_host, host);
        
        mark_connected(session);
        
@@ -87,20 +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");
+       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;
@@ -128,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