X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=core%2Fs2smanager.lua;h=c374b72ac1951d39700b6acdce027bc3f2692213;hb=461768c541104235a93e8f9179929cedca1235f9;hp=e11b305a02244df1e96b3d013fd76645ef8fbfe0;hpb=f026088c8b10eaf746e8ccf802136e157f0dcc48;p=prosody.git diff --git a/core/s2smanager.lua b/core/s2smanager.lua index e11b305a..c374b72a 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -27,6 +27,7 @@ local st = require "stanza"; local stanza = st.stanza; local nameprep = require "util.encodings".stringprep.nameprep; +local fire_event = require "core.eventmanager".fire_event; local uuid_gen = require "util.uuid".generate; local logger_init = require "util.logger".init; @@ -128,6 +129,7 @@ function new_incoming(conn) end open_sessions = open_sessions + 1; local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); + session.log = log; session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end incoming_s2s[session] = true; add_task(connect_timeout, function () @@ -144,7 +146,9 @@ function new_incoming(conn) end function new_outgoing(from_host, to_host) - local host_session = { to_host = to_host, from_host = from_host, notopen = true, type = "s2sout_unauthed", direction = "outgoing" }; + local host_session = { to_host = to_host, from_host = from_host, host = from_host, + notopen = true, type = "s2sout_unauthed", direction = "outgoing" }; + hosts[from_host].s2sout[to_host] = host_session; local log; @@ -333,7 +337,7 @@ function streamopened(session, attr) local send = session.sends2s; -- TODO: #29: SASL/TLS on s2s streams - session.version = 0; --tonumber(attr.version) or 0; + session.version = tonumber(attr.version) or 0; if session.version >= 1.0 and not (attr.to and attr.from) then log("warn", (session.to_host or "(unknown)").." failed to specify 'to' or 'from' hostname as per RFC"); @@ -355,8 +359,11 @@ function streamopened(session, attr) return; end if session.version >= 1.0 then - send(st.stanza("stream:features") - :tag("dialback", { xmlns='urn:xmpp:features:dialback' }):tag("optional"):up():up()); + local features = st.stanza("stream:features"); + fire_event("s2s-stream-features", session, features); + + log("debug", "Sending stream features: %s", tostring(features)); + send(features); end elseif session.direction == "outgoing" then -- If we are just using the connection for verifying dialback keys, we won't try and auth it @@ -377,10 +384,14 @@ function streamopened(session, attr) end session.send_buffer = nil; - if not session.dialback_verifying then - initiate_dialback(session); - else - mark_connected(session); + -- If server is pre-1.0, don't wait for features, just do dialback + if session.version < 1.0 then + if not session.dialback_verifying then + log("debug", "Initiating dialback..."); + initiate_dialback(session); + else + mark_connected(session); + end end end @@ -430,6 +441,7 @@ function make_authenticated(session, host) return true; end +-- Stream is authorised, and ready for normal stanzas function mark_connected(session) local sendq, send = session.sendq, session.sends2s;