plugins XEP-0065, XEP-0260: fixed session creation order: session is created earlied, and file object associated in a second time if needed
This commit is contained in:
parent
bb82cfc78a
commit
84fbbbc299
2 changed files with 15 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue