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.
This commit is contained in:
hrxi 2019-08-08 17:12:02 +02:00
parent 9a1e9864d6
commit 6494d7a45d
2 changed files with 10 additions and 3 deletions

View File

@ -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<string> tried_transport_methods = new HashSet<string>();
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) {

View File

@ -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();