diff options
author | Matthew Wild <mwild1@gmail.com> | 2009-04-20 22:25:49 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2009-04-20 22:25:49 +0100 |
commit | e1120c6225c8ea63c7367edbfd6a7e471e15c50a (patch) | |
tree | 5675d63e2d6ab93b64f384aa3d4d0b43365e7382 /core/s2smanager.lua | |
parent | dabd9b0b5364630a603daecd3261d45999eff3c7 (diff) | |
parent | 7b9dbf5747ba99cad4730bc6b70639fadc1cdc0a (diff) | |
download | prosody-e1120c6225c8ea63c7367edbfd6a7e471e15c50a.tar.gz prosody-e1120c6225c8ea63c7367edbfd6a7e471e15c50a.zip |
Merge
Diffstat (limited to 'core/s2smanager.lua')
-rw-r--r-- | core/s2smanager.lua | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/core/s2smanager.lua b/core/s2smanager.lua index cf198cf0..a16f8b02 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -105,7 +105,11 @@ function send_to_host(from_host, to_host, data) local host_session = new_outgoing(from_host, to_host); -- Store in buffer host_session.sendq = { {tostring(data), st.reply(data)} }; - if (not host_session.connecting) and (not host_session.conn) then destroy_session(host_session); end + log("debug", "stanza [%s] queued until connection complete", tostring(data.name)); + if (not host_session.connecting) and (not host_session.conn) then + log("warn", "Connection to %s failed already, destroying session...", to_host); + destroy_session(host_session); + end end end @@ -137,6 +141,23 @@ function new_outgoing(from_host, to_host) attempt_connection(host_session); + if not host_session.sends2s then + -- A sends2s which buffers data (until the stream is opened) + -- note that data in this buffer will be sent before the stream is authed + -- and will not be ack'd in any way, successful or otherwise + local buffer; + function host_session.sends2s(data) + if not buffer then + buffer = {}; + host_session.send_buffer = buffer; + end + log("debug", "Buffering data on unconnected s2sout to %s", to_host); + buffer[#buffer+1] = data; + log("debug", "Buffered item %d: %s", #buffer, tostring(data)); + end + + end + return host_session; end @@ -146,6 +167,7 @@ function attempt_connection(host_session, err) local connect_host, connect_port = idna_to_ascii(to_host), 5269; if not err then -- This is our first attempt + log("debug", "First attempt to connect to %s, starting with SRV lookup...", to_host); host_session.connecting = true; local answer = adns.lookup(function (answer) @@ -171,6 +193,7 @@ function attempt_connection(host_session, err) -- Try with SRV, or just the plain hostname if no SRV return try_connect(host_session, connect_host, connect_port); end, "_xmpp-server._tcp."..connect_host..".", "SRV"); + log("debug", "DNS lookup for %s sent, waiting for response before we can connect", to_host); return true; -- Attempt in progress elseif host_session.srv_hosts and #host_session.srv_hosts > host_session.srv_choice then -- Not our first attempt, and we also have SRV host_session.srv_choice = host_session.srv_choice + 1; @@ -185,6 +208,7 @@ function attempt_connection(host_session, err) if not (connect_host and connect_port) then -- Likely we couldn't resolve DNS + log("warn", "Hmm, we're without a host (%s) and port (%s) to connect to for %s, giving up :(", tostring(connect_host), tostring(connect_port), tostring(to_host)); return false; end @@ -256,6 +280,20 @@ function streamopened(session, attr) if not attr.id then error("stream response did not give us a streamid!!!"); end session.streamid = attr.id; + -- Send unauthed buffer + -- (stanzas which are fine to send before dialback) + -- Note that this is *not* the stanza queue (which + -- we can only send if auth succeeds) :) + local send_buffer = session.send_buffer; + if send_buffer and #send_buffer > 0 then + log("debug", "Sending s2s send_buffer now..."); + for i, data in ipairs(send_buffer) do + session.sends2s(tostring(data)); + send_buffer[i] = nil; + end + end + session.send_buffer = nil; + if not session.dialback_verifying then initiate_dialback(session); else @@ -267,6 +305,7 @@ function streamopened(session, attr) end function streamclosed(session) + (session.log or log)("debug", "</stream:stream>"); session.sends2s("</stream:stream>"); session.notopen = true; end |