Software /
code /
prosody
Comparison
plugins/s2s/mod_s2s.lua @ 4573:09255a10fdfa
Merge Zash with Florob and Maranda
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 24 Feb 2012 16:23:46 +0000 |
parent | 4561:429a007f70e8 |
parent | 4572:aba47e6dff43 |
child | 4575:e0c4ac7749a6 |
comparison
equal
deleted
inserted
replaced
4564:a11b4cbac3c5 | 4573:09255a10fdfa |
---|---|
12 local xpcall, traceback = xpcall, debug.traceback; | 12 local xpcall, traceback = xpcall, debug.traceback; |
13 | 13 |
14 local add_task = require "util.timer".add_task; | 14 local add_task = require "util.timer".add_task; |
15 local st = require "util.stanza"; | 15 local st = require "util.stanza"; |
16 local initialize_filters = require "util.filters".initialize; | 16 local initialize_filters = require "util.filters".initialize; |
17 local nameprep = require "util.encodings".stringprep.nameprep; | |
17 local new_xmpp_stream = require "util.xmppstream".new; | 18 local new_xmpp_stream = require "util.xmppstream".new; |
18 local s2s_new_incoming = require "core.s2smanager".new_incoming; | 19 local s2s_new_incoming = require "core.s2smanager".new_incoming; |
19 local s2s_new_outgoing = require "core.s2smanager".new_outgoing; | 20 local s2s_new_outgoing = require "core.s2smanager".new_outgoing; |
20 local s2s_destroy_session = require "core.s2smanager".destroy_session; | 21 local s2s_destroy_session = require "core.s2smanager".destroy_session; |
21 local nameprep = require "util.encodings".stringprep.nameprep; | |
22 local uuid_gen = require "util.uuid".generate; | 22 local uuid_gen = require "util.uuid".generate; |
23 local cert_verify_identity = require "util.x509".verify_identity; | 23 local cert_verify_identity = require "util.x509".verify_identity; |
24 | 24 |
25 local s2sout = module:require("s2sout"); | 25 local s2sout = module:require("s2sout"); |
26 | 26 |
90 host.log("debug", "stanza sent over "..host.type); | 90 host.log("debug", "stanza sent over "..host.type); |
91 end | 91 end |
92 else | 92 else |
93 log("debug", "opening a new outgoing connection for this stanza"); | 93 log("debug", "opening a new outgoing connection for this stanza"); |
94 local host_session = s2s_new_outgoing(from_host, to_host); | 94 local host_session = s2s_new_outgoing(from_host, to_host); |
95 s2sout.initiate_connection(host_session); | |
96 | 95 |
97 -- Store in buffer | 96 -- Store in buffer |
98 host_session.bounce_sendq = bounce_sendq; | 97 host_session.bounce_sendq = bounce_sendq; |
99 host_session.sendq = { {tostring(stanza), stanza.attr.type ~= "error" and stanza.attr.type ~= "result" and st.reply(stanza)} }; | 98 host_session.sendq = { {tostring(stanza), stanza.attr.type ~= "error" and stanza.attr.type ~= "result" and st.reply(stanza)} }; |
100 log("debug", "stanza [%s] queued until connection complete", tostring(stanza.name)); | 99 log("debug", "stanza [%s] queued until connection complete", tostring(stanza.name)); |
100 s2sout.initiate_connection(host_session); | |
101 if (not host_session.connecting) and (not host_session.conn) then | 101 if (not host_session.connecting) and (not host_session.conn) then |
102 log("warn", "Connection to %s failed already, destroying session...", to_host); | 102 log("warn", "Connection to %s failed already, destroying session...", to_host); |
103 if not s2s_destroy_session(host_session, "Connection failed") then | 103 if not s2s_destroy_session(host_session, "Connection failed") then |
104 -- Already destroyed, we need to bounce our stanza | 104 -- Already destroyed, we need to bounce our stanza |
105 host_session:bounce_sendq(host_session.destruction_reason); | 105 host_session:bounce_sendq(host_session.destruction_reason); |
106 end | 106 end |
107 return false; | 107 return false; |
108 end | 108 end |
109 s2sout.initiate_connection(host_session); | |
110 end | 109 end |
111 return true; | 110 return true; |
112 end | 111 end |
113 | 112 |
114 module:hook("route/remote", function (event) | 113 module:hook("route/remote", function (event) |
190 end | 189 end |
191 end | 190 end |
192 | 191 |
193 if session.secure and not session.cert_chain_status then check_cert_status(session); end | 192 if session.secure and not session.cert_chain_status then check_cert_status(session); end |
194 | 193 |
195 function session.send(data) | |
196 return send_to_host(session.to_host, session.from_host, data); | |
197 end | |
198 send("<?xml version='1.0'?>"); | 194 send("<?xml version='1.0'?>"); |
199 send(st.stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', | 195 send(st.stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', |
200 ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host, to=session.from_host, version=(session.version > 0 and "1.0" or nil) }):top_tag()); | 196 ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host, to=session.from_host, version=(session.version > 0 and "1.0" or nil) }):top_tag()); |
201 if session.version >= 1.0 then | 197 if session.version >= 1.0 then |
202 local features = st.stanza("stream:features"); | 198 local features = st.stanza("stream:features"); |
240 s2s_mark_connected(session); | 236 s2s_mark_connected(session); |
241 end | 237 end |
242 end | 238 end |
243 end | 239 end |
244 session.notopen = nil; | 240 session.notopen = nil; |
241 session.send = function(stanza) send_to_host(session.to_host, session.from_host, stanza); end; | |
245 end | 242 end |
246 | 243 |
247 function stream_callbacks.streamclosed(session) | 244 function stream_callbacks.streamclosed(session) |
248 (session.log or log)("debug", "Received </stream:stream>"); | 245 (session.log or log)("debug", "Received </stream:stream>"); |
249 session:close(); | 246 session:close(); |
250 end | 247 end |
251 | 248 |
252 function stream_callbacks.streamdisconnected(session, err) | 249 function stream_callbacks.streamdisconnected(session, err) |
253 if err and err ~= "closed" then | 250 if err and err ~= "stream closed" then |
254 (session.log or log)("debug", "s2s connection attempt failed: %s", err); | 251 (session.log or log)("debug", "s2s connection attempt failed: %s", err); |
255 if s2sout.attempt_connection(session, err) then | 252 if s2sout.attempt_connection(session, err) then |
256 (session.log or log)("debug", "...so we're going to try another target"); | 253 (session.log or log)("debug", "...so we're going to try another target"); |
257 return true; -- Session lives for now | 254 return true; -- Session lives for now |
258 end | 255 end |
259 end | 256 end |
260 (session.log or log)("info", "s2s disconnected: %s->%s (%s)", tostring(session.from_host), tostring(session.to_host), tostring(err or "closed")); | 257 (session.log or log)("info", "s2s disconnected: %s->%s (%s)", tostring(session.from_host), tostring(session.to_host), tostring(err or "closed")); |
261 sessions[session.conn] = nil; | 258 if session.con then sessions[session.conn] = nil; else (session.log or log)("debug", "stale session's connection already closed"); end |
262 s2s_destroy_session(session, err); | 259 s2s_destroy_session(session, err); |
263 end | 260 end |
264 | 261 |
265 function stream_callbacks.error(session, error, data) | 262 function stream_callbacks.error(session, error, data) |
266 if error == "no-stream" then | 263 if error == "no-stream" then |