Mercurial > prosody-hg
comparison core/s2smanager.lua @ 1796:5f7b2f940816
s2smanager: Timeout unauthed s2s connections
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 20 Sep 2009 15:16:25 +0100 |
| parents | 1fc6c2822e6b |
| children | a3b0f21c4e37 7e41ad68fe3c |
comparison
equal
deleted
inserted
replaced
| 1793:1fc6c2822e6b | 1796:5f7b2f940816 |
|---|---|
| 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 |
| 126 end | 127 end |
| 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.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end | 130 session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end |
| 130 incoming_s2s[session] = true; | 131 incoming_s2s[session] = true; |
| 132 add_task(connect_timeout, function () | |
| 133 if session.conn ~= conn or | |
| 134 session.type == "s2sin" then | |
| 135 return; -- Ok, we're connect[ed|ing] | |
| 136 end | |
| 137 -- Not connected, need to close session and clean up | |
| 138 (session.log or log)("warn", "Destroying incomplete session %s->%s due to inactivity", | |
| 139 session.from_host or "(unknown)", session.to_host or "(unknown)"); | |
| 140 session:close("connection-timeout"); | |
| 141 end); | |
| 131 return session; | 142 return session; |
| 132 end | 143 end |
| 133 | 144 |
| 134 function new_outgoing(from_host, to_host) | 145 function new_outgoing(from_host, to_host) |
| 135 local host_session = { to_host = to_host, from_host = from_host, notopen = true, type = "s2sout_unauthed", direction = "outgoing" }; | 146 local host_session = { to_host = to_host, from_host = from_host, notopen = true, type = "s2sout_unauthed", direction = "outgoing" }; |
| 298 local w = conn.write; | 309 local w = conn.write; |
| 299 host_session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end | 310 host_session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end |
| 300 | 311 |
| 301 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)); | 312 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)); |
| 302 log("debug", "Connection attempt in progress..."); | 313 log("debug", "Connection attempt in progress..."); |
| 314 add_task(connect_timeout, function () | |
| 315 if host_session.conn ~= conn or | |
| 316 host_session.type == "s2sout" or | |
| 317 host_session.connecting then | |
| 318 return; -- Ok, we're connect[ed|ing] | |
| 319 end | |
| 320 -- Not connected, need to close session and clean up | |
| 321 (host_session.log or log)("warn", "Destroying incomplete session %s->%s due to inactivity", | |
| 322 host_session.from_host or "(unknown)", host_session.to_host or "(unknown)"); | |
| 323 host_session:close("connection-timeout"); | |
| 324 end); | |
| 303 return true; | 325 return true; |
| 304 end | 326 end |
| 305 | 327 |
| 306 function streamopened(session, attr) | 328 function streamopened(session, attr) |
| 307 local send = session.sends2s; | 329 local send = session.sends2s; |
