Mercurial > libervia-backend
changeset 1757:abd6d6f89006
plugins XEP-0065, XEP-0260: fixed session creation order: session is created earlied, and file object associated in a second time if needed
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 17 Dec 2015 22:37:58 +0100 |
parents | 061011fad5b1 |
children | a66d34353f34 |
files | src/plugins/plugin_xep_0065.py src/plugins/plugin_xep_0260.py |
diffstat | 2 files changed, 15 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0065.py Thu Dec 17 22:37:56 2015 +0100 +++ b/src/plugins/plugin_xep_0065.py Thu Dec 17 22:37:58 2015 +0100 @@ -1148,7 +1148,8 @@ """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 @@ 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 @@ 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)
--- a/src/plugins/plugin_xep_0260.py Thu Dec 17 22:37:56 2015 +0100 +++ b/src/plugins/plugin_xep_0260.py Thu Dec 17 22:37:58 2015 +0100 @@ -132,6 +132,7 @@ 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 @@ 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)