Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0260.py @ 1571:c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 08 Nov 2015 14:48:04 +0100 |
parents | 37d4be4a9fed |
children | 25906c0dbc63 |
comparison
equal
deleted
inserted
replaced
1570:37d4be4a9fed | 1571:c668081eba1c |
---|---|
219 choosed_candidate = max(best_candidate, peer_best_candidate, key=lambda c:c.priority) | 219 choosed_candidate = max(best_candidate, peer_best_candidate, key=lambda c:c.priority) |
220 | 220 |
221 if choosed_candidate is None: | 221 if choosed_candidate is None: |
222 log.warning(u"Socks5 negociation failed, we need to fallback to IBB") | 222 log.warning(u"Socks5 negociation failed, we need to fallback to IBB") |
223 else: | 223 else: |
224 # best_peer_candidate was choosed from the candidates we have sent | 224 if choosed_candidate == peer_best_candidate: |
225 # so our_candidate is true if choosed_candidate is peer_best_candidate | 225 # peer_best_candidate was choosed from the candidates we have sent |
226 our_candidate = choosed_candidate==peer_best_candidate | 226 # so our_candidate is true if choosed_candidate is peer_best_candidate |
227 our_candidate = True | |
228 # than also mean that best_candidate must be discarded ! | |
229 try: | |
230 best_candidate.discard() | |
231 except AttributeError: # but it can be None | |
232 pass | |
233 else: | |
234 our_candidate = False | |
227 | 235 |
228 log.info(u"Socks5 negociation successful, {who} candidate will be used: {candidate}".format( | 236 log.info(u"Socks5 negociation successful, {who} candidate will be used: {candidate}".format( |
229 who = u'our' if our_candidate else u'other peer', | 237 who = u'our' if our_candidate else u'other peer', |
230 candidate = choosed_candidate)) | 238 candidate = choosed_candidate)) |
231 del transport_data['best_candidate'] | 239 del transport_data['best_candidate'] |
324 elif action == self._j.A_START: | 332 elif action == self._j.A_START: |
325 session_hash = transport_data['session_hash'] | 333 session_hash = transport_data['session_hash'] |
326 peer_candidates = transport_data['peer_candidates'] | 334 peer_candidates = transport_data['peer_candidates'] |
327 file_obj = content_data['file_obj'] | 335 file_obj = content_data['file_obj'] |
328 stream_d = self._s5b.registerHash(session_hash, file_obj, profile) | 336 stream_d = self._s5b.registerHash(session_hash, file_obj, profile) |
329 args = [session, content_name, profile] | 337 stream_d.chainDeferred(content_data['finished_d']) |
330 stream_d.addCallbacks(self._streamCb, self._streamEb, args, None, args) | |
331 d = self._s5b.getBestCandidate(peer_candidates, session_hash, profile) | 338 d = self._s5b.getBestCandidate(peer_candidates, session_hash, profile) |
332 d.addCallback(self._foundPeerCandidate, session, transport_data, content_name, client) | 339 d.addCallback(self._foundPeerCandidate, session, transport_data, content_name, client) |
333 | 340 |
334 elif action == self._j.A_SESSION_INITIATE: | 341 elif action == self._j.A_SESSION_INITIATE: |
335 # responder side, we select a candidate in the ones sent by initiator | 342 # responder side, we select a candidate in the ones sent by initiator |
338 sid = transport_data['sid'] = transport_elt['sid'] | 345 sid = transport_data['sid'] = transport_elt['sid'] |
339 session_hash = transport_data['session_hash'] = self._s5b.getSessionHash(session['peer_jid'], client.jid, sid) | 346 session_hash = transport_data['session_hash'] = self._s5b.getSessionHash(session['peer_jid'], client.jid, sid) |
340 peer_candidates = transport_data['peer_candidates'] = self._parseCandidates(transport_elt) | 347 peer_candidates = transport_data['peer_candidates'] = self._parseCandidates(transport_elt) |
341 file_obj = content_data['file_obj'] | 348 file_obj = content_data['file_obj'] |
342 stream_d = self._s5b.registerHash(session_hash, file_obj, profile) | 349 stream_d = self._s5b.registerHash(session_hash, file_obj, profile) |
343 args = [session, content_name, profile] | 350 stream_d.chainDeferred(content_data['finished_d']) |
344 stream_d.addCallbacks(self._streamCb, self._streamEb, args, None, args) | |
345 d = self._s5b.getBestCandidate(peer_candidates, session_hash, profile) | 351 d = self._s5b.getBestCandidate(peer_candidates, session_hash, profile) |
346 d.addCallback(self._foundPeerCandidate, session, transport_data, content_name, client) | 352 d.addCallback(self._foundPeerCandidate, session, transport_data, content_name, client) |
347 candidates = yield self._s5b.getCandidates(profile) | 353 candidates = yield self._s5b.getCandidates(profile) |
348 # we remove duplicate candidates | 354 # we remove duplicate candidates |
349 candidates = [candidate for candidate in candidates if candidate not in peer_candidates] | 355 candidates = [candidate for candidate in candidates if candidate not in peer_candidates] |
373 else: | 379 else: |
374 log.warning(u"FIXME: unmanaged action {}".format(action)) | 380 log.warning(u"FIXME: unmanaged action {}".format(action)) |
375 | 381 |
376 defer.returnValue(transport_elt) | 382 defer.returnValue(transport_elt) |
377 | 383 |
378 def _streamCb(self, dummy, session, content_name, profile): | |
379 self._j.contentTerminate(session, content_name, profile=profile) | |
380 | |
381 def _streamEb(self, failure, session, content_name, profile): | |
382 log.warning(u"Error while streaming through s5b: {}".format(failure)) | |
383 self._j.contentTerminate(session, content_name, reason=self._j.REASON_FAILED_TRANSPORT, profile=profile) | |
384 | |
385 | 384 |
386 class XEP_0260_handler(XMPPHandler): | 385 class XEP_0260_handler(XMPPHandler): |
387 implements(iwokkel.IDisco) | 386 implements(iwokkel.IDisco) |
388 | 387 |
389 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): | 388 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |