From 6494d7a45dabd180767890a310886146d83ae3be Mon Sep 17 00:00:00 2001 From: hrxi Date: Thu, 8 Aug 2019 17:12:02 +0200 Subject: Fix race condition involving `session-terminate` The Jingle file transfer (XEP-0234) specifies that the receiver of the file transfer is the one to terminate the session. Otherwise, there might be a race condition between the XMPP stream and out-of-band SOCKS5 connections. --- xmpp-vala/src/module/xep/0166_jingle.vala | 12 +++++++++--- xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'xmpp-vala/src/module') diff --git a/xmpp-vala/src/module/xep/0166_jingle.vala b/xmpp-vala/src/module/xep/0166_jingle.vala index f5d112aa..2e38b164 100644 --- a/xmpp-vala/src/module/xep/0166_jingle.vala +++ b/xmpp-vala/src/module/xep/0166_jingle.vala @@ -397,6 +397,8 @@ public class Session { private Connection connection; public IOStream conn { get { return connection; } } + public bool terminate_on_connection_close { get; set; } + // INITIATE_SENT | INITIATE_RECEIVED | CONNECTING Set tried_transport_methods = new HashSet(); TransportParameters? transport = null; @@ -417,6 +419,7 @@ public class Session { this.transport = transport; this.connection = new Connection(this); this.session_terminate_handler = (owned)session_terminate_handler; + this.terminate_on_connection_close = true; } public Session.initiate_received(string sid, TransportType type, TransportParameters? transport, Jid local_full_jid, Jid peer_full_jid, string content_name, owned SessionTerminate session_terminate_handler) { @@ -435,6 +438,7 @@ public class Session { } this.connection = new Connection(this); this.session_terminate_handler = (owned)session_terminate_handler; + this.terminate_on_connection_close = true; } public void handle_iq_set(XmppStream stream, string action, StanzaNode jingle, Iq.Stanza iq) throws IqError { @@ -719,9 +723,11 @@ public class Session { terminate(reason, "transport error: $(error.message)"); } public void on_connection_close() { - StanzaNode reason = new StanzaNode.build("reason", NS_URI) - .put_node(new StanzaNode.build("success", NS_URI)); - terminate(reason, "success"); + if (terminate_on_connection_close) { + StanzaNode reason = new StanzaNode.build("reason", NS_URI) + .put_node(new StanzaNode.build("success", NS_URI)); + terminate(reason, "success"); + } } public void terminate(StanzaNode reason, string? local_reason) { diff --git a/xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala b/xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala index 867a26e3..43c212f5 100644 --- a/xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala +++ b/xmpp-vala/src/module/xep/0234_jingle_file_transfer.vala @@ -45,6 +45,7 @@ public class Module : Jingle.ContentType, XmppStreamModule { Jingle.Session session = stream.get_module(Jingle.Module.IDENTITY) .create_session(stream, Jingle.TransportType.STREAMING, receiver_full_jid, Jingle.Senders.INITIATOR, "a-file-offer", description); // TODO(hrxi): Why "a-file-offer"? + session.terminate_on_connection_close = false; yield session.conn.input_stream.close_async(); -- cgit v1.2.3-70-g09d2