# HG changeset patch # User Kim Alvefur # Date 1357954590 -3600 # Node ID 602e4c5090950a6eebc292bd42117b4772ddd017 # Parent 14886519900328c379172119318d43a191629c6f mod_bidi: Close conflicting outgoing sessions when bidi is initiated, not requested. diff -r 148865199003 -r 602e4c509095 mod_bidi/mod_bidi.lua --- a/mod_bidi/mod_bidi.lua Fri Jan 11 01:08:31 2013 +0100 +++ b/mod_bidi/mod_bidi.lua Sat Jan 12 02:36:30 2013 +0100 @@ -28,10 +28,16 @@ local function new_bidi(origin) local bidi_session, remote_host; origin.log("debug", "Creating bidirectional session wrapper"); - if origin.direction == "incoming" then + if origin.direction == "incoming" then -- then we create an "outgoing" bidirectional session + local conflicting_session = hosts[origin.to_host].s2sout[origin.from_host] + if conflicting_session then + conflicting_session.log("warn", "We already have an outgoing connection to %s, closing it...", origin.from_host); + conflicting_session:close{ condition = "conflict", text = "Replaced by bidirectional stream" } + s2smanager.destroy_session(conflicting_session); + end remote_host = origin.from_host; bidi_session = s2smanager.new_outgoing(origin.to_host, origin.from_host) - else -- outgoing + else -- outgoing -- then we create an "incoming" bidirectional session remote_host = origin.to_host; bidi_session = s2smanager.new_incoming(origin.conn) bidi_session.to_host = origin.from_host; @@ -75,12 +81,6 @@ local origin = event.session or event.origin; if not origin.is_bidi and not origin.bidi_session then module:log("debug", "%s requested bidirectional stream", origin.from_host); - if hosts[module.host].s2sout[origin.from_host] then - local conflicting_session = hosts[module.host].s2sout[origin.from_host] - conflicting_session.log("warn", "We already have an outgoing connection to %s, closing it...", origin.from_host); - conflicting_session:close{ condition = "conflict", text = "Replaced by bidirectional stream" } - s2smanager.destroy_session(conflicting_session); - end origin.do_bidi = true; return true; end