Software /
code /
prosody-modules
Changeset
893:602e4c509095
mod_bidi: Close conflicting outgoing sessions when bidi is initiated, not requested.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 12 Jan 2013 02:36:30 +0100 |
parents | 892:148865199003 |
children | 894:d066987e00b7 |
files | mod_bidi/mod_bidi.lua |
diffstat | 1 files changed, 8 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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