Comparison

core/s2smanager.lua @ 1797:a3b0f21c4e37

Merge with 0.5
author Matthew Wild <mwild1@gmail.com>
date Sun, 20 Sep 2009 15:17:37 +0100
parent 1794:218f720af304
parent 1796:5f7b2f940816
child 1806:c55e06eb53b2
comparison
equal deleted inserted replaced
1795:0e933d6f2c31 1797:a3b0f21c4e37
37 37
38 local dialback_secret = uuid_gen(); 38 local dialback_secret = uuid_gen();
39 39
40 local adns, dns = require "net.adns", require "net.dns"; 40 local adns, dns = require "net.adns", require "net.dns";
41 41
42 local connect_timeout = config.get("*", "core", "s2s_timeout") or 60;
42 local dns_timeout = config.get("*", "core", "dns_timeout") or 60; 43 local dns_timeout = config.get("*", "core", "dns_timeout") or 60;
43 44
44 incoming_s2s = {}; 45 incoming_s2s = {};
45 local incoming_s2s = incoming_s2s; 46 local incoming_s2s = incoming_s2s;
46 47
127 open_sessions = open_sessions + 1; 128 open_sessions = open_sessions + 1;
128 local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); 129 local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$"));
129 session.log = log; 130 session.log = log;
130 session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end 131 session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end
131 incoming_s2s[session] = true; 132 incoming_s2s[session] = true;
133 add_task(connect_timeout, function ()
134 if session.conn ~= conn or
135 session.type == "s2sin" then
136 return; -- Ok, we're connect[ed|ing]
137 end
138 -- Not connected, need to close session and clean up
139 (session.log or log)("warn", "Destroying incomplete session %s->%s due to inactivity",
140 session.from_host or "(unknown)", session.to_host or "(unknown)");
141 session:close("connection-timeout");
142 end);
132 return session; 143 return session;
133 end 144 end
134 145
135 function new_outgoing(from_host, to_host) 146 function new_outgoing(from_host, to_host)
136 local host_session = { to_host = to_host, from_host = from_host, notopen = true, type = "s2sout_unauthed", direction = "outgoing" }; 147 local host_session = { to_host = to_host, from_host = from_host, notopen = true, type = "s2sout_unauthed", direction = "outgoing" };
299 local w = conn.write; 310 local w = conn.write;
300 host_session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end 311 host_session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end
301 312
302 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)); 313 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));
303 log("debug", "Connection attempt in progress..."); 314 log("debug", "Connection attempt in progress...");
315 add_task(connect_timeout, function ()
316 if host_session.conn ~= conn or
317 host_session.type == "s2sout" or
318 host_session.connecting then
319 return; -- Ok, we're connect[ed|ing]
320 end
321 -- Not connected, need to close session and clean up
322 (host_session.log or log)("warn", "Destroying incomplete session %s->%s due to inactivity",
323 host_session.from_host or "(unknown)", host_session.to_host or "(unknown)");
324 host_session:close("connection-timeout");
325 end);
304 return true; 326 return true;
305 end 327 end
306 328
307 function streamopened(session, attr) 329 function streamopened(session, attr)
308 local send = session.sends2s; 330 local send = session.sends2s;