Software /
code /
prosody
Comparison
core/s2smanager.lua @ 2281:27441b099984
Merge with tip.
author | Tobias Markmann <tm@ayena.de> |
---|---|
date | Sun, 29 Nov 2009 21:33:37 +0100 |
parent | 2231:288832cdec52 |
child | 2368:4726cd9a6318 |
comparison
equal
deleted
inserted
replaced
2280:0b0fe49e5251 | 2281:27441b099984 |
---|---|
34 | 34 |
35 local log = logger_init("s2smanager"); | 35 local log = logger_init("s2smanager"); |
36 | 36 |
37 local sha256_hash = require "util.hashes".sha256; | 37 local sha256_hash = require "util.hashes".sha256; |
38 | 38 |
39 local dialback_secret = uuid_gen(); | |
40 | |
41 local adns, dns = require "net.adns", require "net.dns"; | 39 local adns, dns = require "net.adns", require "net.dns"; |
42 local config = require "core.configmanager"; | 40 local config = require "core.configmanager"; |
43 local connect_timeout = config.get("*", "core", "s2s_timeout") or 60; | 41 local connect_timeout = config.get("*", "core", "s2s_timeout") or 60; |
44 local dns_timeout = config.get("*", "core", "dns_timeout") or 60; | 42 local dns_timeout = config.get("*", "core", "dns_timeout") or 60; |
45 local max_dns_depth = config.get("*", "core", "dns_max_depth") or 3; | 43 local max_dns_depth = config.get("*", "core", "dns_max_depth") or 3; |
44 local dialback_secret = config.get("*", "core", "dialback_secret") or uuid_gen(); | |
46 | 45 |
47 incoming_s2s = {}; | 46 incoming_s2s = {}; |
48 _G.prosody.incoming_s2s = incoming_s2s; | 47 _G.prosody.incoming_s2s = incoming_s2s; |
49 local incoming_s2s = incoming_s2s; | 48 local incoming_s2s = incoming_s2s; |
50 | 49 |
77 session.sendq = nil; | 76 session.sendq = nil; |
78 end | 77 end |
79 end | 78 end |
80 | 79 |
81 function send_to_host(from_host, to_host, data) | 80 function send_to_host(from_host, to_host, data) |
81 if not hosts[from_host] then | |
82 log("warn", "Attempt to send stanza from %s - a host we don't serve", from_host); | |
83 return false; | |
84 end | |
82 local host = hosts[from_host].s2sout[to_host]; | 85 local host = hosts[from_host].s2sout[to_host]; |
83 if host then | 86 if host then |
84 -- We have a connection to this host already | 87 -- We have a connection to this host already |
85 if host.type == "s2sout_unauthed" and (data.name ~= "db:verify" or not host.dialback_key) and ((not data.xmlns) or data.xmlns == "jabber:client" or data.xmlns == "jabber:server") then | 88 if host.type == "s2sout_unauthed" and (data.name ~= "db:verify" or not host.dialback_key) and ((not data.xmlns) or data.xmlns == "jabber:client" or data.xmlns == "jabber:server") then |
86 (host.log or log)("debug", "trying to send over unauthed s2sout to "..to_host); | 89 (host.log or log)("debug", "trying to send over unauthed s2sout to "..to_host); |
126 getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end; | 129 getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end; |
127 end | 130 end |
128 open_sessions = open_sessions + 1; | 131 open_sessions = open_sessions + 1; |
129 local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); | 132 local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); |
130 session.log = log; | 133 session.log = log; |
131 session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end | 134 session.sends2s = function (t) log("debug", "sending: %s", t.top_tag and t:top_tag() or t:match("^([^>]*>?)")); w(conn, tostring(t)); end |
132 incoming_s2s[session] = true; | 135 incoming_s2s[session] = true; |
133 add_task(connect_timeout, function () | 136 add_task(connect_timeout, function () |
134 if session.conn ~= conn or | 137 if session.conn ~= conn or |
135 session.type == "s2sin" then | 138 session.type == "s2sin" then |
136 return; -- Ok, we're connect[ed|ing] | 139 return; -- Ok, we're connect[ed|ing] |
315 -- Register this outgoing connection so that xmppserver_listener knows about it | 318 -- Register this outgoing connection so that xmppserver_listener knows about it |
316 -- otherwise it will assume it is a new incoming connection | 319 -- otherwise it will assume it is a new incoming connection |
317 cl.register_outgoing(conn, host_session); | 320 cl.register_outgoing(conn, host_session); |
318 | 321 |
319 local w, log = conn.write, host_session.log; | 322 local w, log = conn.write, host_session.log; |
320 host_session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end | 323 host_session.sends2s = function (t) log("debug", "sending: %s", (t.top_tag and t:top_tag()) or t:match("^[^>]*>?")); w(conn, tostring(t)); end |
321 | 324 |
322 conn.write(format([[<stream:stream xmlns='jabber:server' xmlns:db='jabber:server:dialback' xmlns:stream='http://etherx.jabber.org/streams' from='%s' to='%s' version='1.0' xml:lang='en'>]], from_host, to_host)); | 325 conn:write(format([[<stream:stream xmlns='jabber:server' xmlns:db='jabber:server:dialback' xmlns:stream='http://etherx.jabber.org/streams' from='%s' to='%s' version='1.0' xml:lang='en'>]], from_host, to_host)); |
323 log("debug", "Connection attempt in progress..."); | 326 log("debug", "Connection attempt in progress..."); |
324 add_task(connect_timeout, function () | 327 add_task(connect_timeout, function () |
325 if host_session.conn ~= conn or | 328 if host_session.conn ~= conn or |
326 host_session.type == "s2sout" or | 329 host_session.type == "s2sout" or |
327 host_session.connecting then | 330 host_session.connecting then |