From 84fbbbc29954811faf8a97e796d36e0f93ae8393 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 17 Dec 2015 22:37:58 +0100 Subject: [PATCH] plugins XEP-0065, XEP-0260: fixed session creation order: session is created earlied, and file object associated in a second time if needed --- src/plugins/plugin_xep_0065.py | 14 ++++++++++++-- src/plugins/plugin_xep_0260.py | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/plugins/plugin_xep_0065.py b/src/plugins/plugin_xep_0065.py index 97621fa8..12fc989e 100755 --- a/src/plugins/plugin_xep_0065.py +++ b/src/plugins/plugin_xep_0065.py @@ -1148,7 +1148,8 @@ class XEP_0065(object): """Create a session_data associated to hash @param session_hash(str): hash of the session - @param file_obj(file): file-like object + @param file_obj(file, None): file-like object + None if it will be filled later @param profile: %(doc_profile)s return (dict): session data """ @@ -1157,10 +1158,13 @@ class XEP_0065(object): session_d = defer.Deferred() session_d.addBoth(self.killSession, session_hash, None, client) session_data = client._s5b_sessions[session_hash] = { - "file": file_obj, DEFER_KEY: session_d, TIMER_KEY: reactor.callLater(TIMEOUT, self._timeOut, session_hash, client), } + + if file_obj is not None: + session_data['file'] = file_obj + if session_hash in self.hash_profiles_map: # The only case when 2 profiles want to register the same hash # is when they are on the same instance @@ -1181,6 +1185,12 @@ class XEP_0065(object): return session_data + def associateFileObj(self, session_hash, file_obj, profile): + """Associate a file obj with a session""" + session_data = self.getSession(session_hash, profile) + assert 'file' not in session_data + session_data['file'] = file_obj + def streamQuery(self, iq_elt, profile): log.debug(u"BS stream query") client = self.host.getClient(profile) diff --git a/src/plugins/plugin_xep_0260.py b/src/plugins/plugin_xep_0260.py index cc2f55fd..86219adc 100644 --- a/src/plugins/plugin_xep_0260.py +++ b/src/plugins/plugin_xep_0260.py @@ -132,6 +132,7 @@ class XEP_0260(object): transport_data = content_data['transport_data'] sid = transport_data['sid'] = unicode(uuid.uuid4()) session_hash = transport_data['session_hash'] = self._s5b.getSessionHash(client.jid, session['peer_jid'], sid) + transport_data['stream_d'] = self._s5b.registerHash(session_hash, None, profile) candidates = transport_data['candidates'] = yield self._s5b.getCandidates(profile) mode = 'tcp' # XXX: we only manage tcp for now transport_elt = self._buildCandidates(session, candidates, sid, session_hash, client, mode) @@ -357,7 +358,8 @@ class XEP_0260(object): session_hash = transport_data['session_hash'] peer_candidates = transport_data['peer_candidates'] file_obj = content_data['file_obj'] - stream_d = self._s5b.registerHash(session_hash, file_obj, profile) + self._s5b.associateFileObj(session_hash, file_obj, profile) + stream_d = transport_data.pop('stream_d') stream_d.chainDeferred(content_data['finished_d']) d = self._s5b.getBestCandidate(peer_candidates, session_hash, profile) d.addCallback(self._foundPeerCandidate, session, transport_data, content_name, client)