Merge 0.10->trunk
[prosody.git] / plugins / mod_s2s / mod_s2s.lua
index 480761f4b817ddcf75cf190c41926f903eadbc7a..c1357bf786904f361483391087f4a97dde6abcb3 100644 (file)
@@ -56,6 +56,9 @@ local function bounce_sendq(session, reason)
                        (session.log or log)("error", "Replying to to an s2s error reply, please report this! Traceback: %s", traceback());
                end;
                dummy = true;
+               close = function ()
+                       (session.log or log)("error", "Attempting to close the dummy origin of s2s error replies, please report this! Traceback: %s", traceback());
+               end;
        };
        for i, data in ipairs(sendq) do
                local reply = data[2];
@@ -349,10 +352,16 @@ function stream_callbacks.streamopened(session, attr)
                                hosts[to].events.fire_event("s2s-stream-features", { origin = session, features = features });
                        else
                                (session.log or log)("warn", "No 'to' on stream header from %s means we can't offer any features", from or session.ip or "unknown host");
+                               fire_global_event("s2s-stream-features-legacy", { origin = session, features = features });
                        end
 
-                       log("debug", "Sending stream features: %s", tostring(features));
-                       session.sends2s(features);
+                       if ( session.type == "s2sin" or session.type == "s2sout" ) or features.tags[1] then
+                               log("debug", "Sending stream features: %s", tostring(features));
+                               session.sends2s(features);
+                       else
+                               (session.log or log)("warn", "No features to offer, giving up");
+                               session:close({ condition = "undefined-condition", text = "No features to offer" });
+                       end
                end
        elseif session.direction == "outgoing" then
                session.notopen = nil;
@@ -606,6 +615,11 @@ function listener.onstatus(conn, status)
        end
 end
 
+function listener.ontimeout(conn)
+       -- Called instead of onconnect when the connection times out
+       measure_connections(1);
+end
+
 function listener.ondisconnect(conn, err)
        measure_connections(-1);
        local session = sessions[conn];
@@ -669,7 +683,7 @@ module:hook("server-stopping", function(event)
        for _, session in pairs(sessions) do
                session:close{ condition = "system-shutdown", text = reason };
        end
-end,500);
+end, -200);