# HG changeset patch # User Matthew Wild # Date 1253456257 -3600 # Node ID a3b0f21c4e373ea328313b205d9afea516fef80f # Parent 0e933d6f2c31989986e99b052d916d6329631d3b# Parent 5f7b2f940816e0028d144cb014971afddf884be8 Merge with 0.5 diff -r 0e933d6f2c31 -r a3b0f21c4e37 core/s2smanager.lua --- a/core/s2smanager.lua Sun Sep 20 03:20:38 2009 +0100 +++ b/core/s2smanager.lua Sun Sep 20 15:17:37 2009 +0100 @@ -39,6 +39,7 @@ local adns, dns = require "net.adns", require "net.dns"; +local connect_timeout = config.get("*", "core", "s2s_timeout") or 60; local dns_timeout = config.get("*", "core", "dns_timeout") or 60; incoming_s2s = {}; @@ -129,6 +130,16 @@ session.log = log; session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end incoming_s2s[session] = true; + add_task(connect_timeout, function () + if session.conn ~= conn or + session.type == "s2sin" then + return; -- Ok, we're connect[ed|ing] + end + -- Not connected, need to close session and clean up + (session.log or log)("warn", "Destroying incomplete session %s->%s due to inactivity", + session.from_host or "(unknown)", session.to_host or "(unknown)"); + session:close("connection-timeout"); + end); return session; end @@ -301,6 +312,17 @@ conn.write(format([[]], from_host, to_host)); log("debug", "Connection attempt in progress..."); + add_task(connect_timeout, function () + if host_session.conn ~= conn or + host_session.type == "s2sout" or + host_session.connecting then + return; -- Ok, we're connect[ed|ing] + end + -- Not connected, need to close session and clean up + (host_session.log or log)("warn", "Destroying incomplete session %s->%s due to inactivity", + host_session.from_host or "(unknown)", host_session.to_host or "(unknown)"); + host_session:close("connection-timeout"); + end); return true; end