Mercurial > prosody-hg
comparison core/s2smanager.lua @ 1007:c500d4cb7855
core.s2smanager: Buffer data sent before connection
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Mon, 20 Apr 2009 22:14:31 +0100 |
| parents | 9166d7a8c3c0 |
| children | 831c84cbf5fa |
comparison
equal
deleted
inserted
replaced
| 1006:9166d7a8c3c0 | 1007:c500d4cb7855 |
|---|---|
| 139 host_session.log = log; | 139 host_session.log = log; |
| 140 end | 140 end |
| 141 | 141 |
| 142 attempt_connection(host_session); | 142 attempt_connection(host_session); |
| 143 | 143 |
| 144 if not host_session.sends2s then | |
| 145 -- A sends2s which buffers data (until the stream is opened) | |
| 146 -- note that data in this buffer will be sent before the stream is authed | |
| 147 -- and will not be ack'd in any way, successful or otherwise | |
| 148 local buffer; | |
| 149 function host_session.sends2s(data) | |
| 150 if not buffer then | |
| 151 buffer = {}; | |
| 152 host_session.send_buffer = buffer; | |
| 153 end | |
| 154 log("debug", "Buffering data on unconnected s2sout to %s", to_host); | |
| 155 buffer[#buffer+1] = data; | |
| 156 log("debug", "Buffered item %d: %s", #buffer, tostring(data)); | |
| 157 end | |
| 158 | |
| 159 end | |
| 160 | |
| 144 return host_session; | 161 return host_session; |
| 145 end | 162 end |
| 146 | 163 |
| 147 | 164 |
| 148 function attempt_connection(host_session, err) | 165 function attempt_connection(host_session, err) |
| 261 elseif session.direction == "outgoing" then | 278 elseif session.direction == "outgoing" then |
| 262 -- If we are just using the connection for verifying dialback keys, we won't try and auth it | 279 -- If we are just using the connection for verifying dialback keys, we won't try and auth it |
| 263 if not attr.id then error("stream response did not give us a streamid!!!"); end | 280 if not attr.id then error("stream response did not give us a streamid!!!"); end |
| 264 session.streamid = attr.id; | 281 session.streamid = attr.id; |
| 265 | 282 |
| 283 -- Send unauthed buffer | |
| 284 -- (stanzas which are fine to send before dialback) | |
| 285 -- Note that this is *not* the stanza queue (which | |
| 286 -- we can only send if auth succeeds) :) | |
| 287 local send_buffer = session.send_buffer; | |
| 288 if send_buffer and #send_buffer > 0 then | |
| 289 log("debug", "Sending s2s send_buffer now..."); | |
| 290 for i, data in ipairs(send_buffer) do | |
| 291 session.sends2s(tostring(data)); | |
| 292 send_buffer[i] = nil; | |
| 293 end | |
| 294 end | |
| 295 session.send_buffer = nil; | |
| 296 | |
| 266 if not session.dialback_verifying then | 297 if not session.dialback_verifying then |
| 267 initiate_dialback(session); | 298 initiate_dialback(session); |
| 268 else | 299 else |
| 269 mark_connected(session); | 300 mark_connected(session); |
| 270 end | 301 end |
