diff 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
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0260.py	Sun Nov 08 14:44:33 2015 +0100
+++ b/src/plugins/plugin_xep_0260.py	Sun Nov 08 14:48:04 2015 +0100
@@ -221,9 +221,17 @@
         if choosed_candidate is None:
             log.warning(u"Socks5 negociation failed, we need to fallback to IBB")
         else:
-            # best_peer_candidate was choosed from the candidates we have sent
-            # so our_candidate is true if choosed_candidate is peer_best_candidate
-            our_candidate = choosed_candidate==peer_best_candidate
+            if choosed_candidate == peer_best_candidate:
+                # peer_best_candidate was choosed from the candidates we have sent
+                # so our_candidate is true if choosed_candidate is peer_best_candidate
+                our_candidate = True
+                # than also mean that best_candidate must be discarded !
+                try:
+                    best_candidate.discard()
+                except AttributeError: # but it can be None
+                    pass
+            else:
+                our_candidate = False
 
             log.info(u"Socks5 negociation successful, {who} candidate will be used: {candidate}".format(
                 who = u'our' if our_candidate else u'other peer',
@@ -326,8 +334,7 @@
             peer_candidates = transport_data['peer_candidates']
             file_obj = content_data['file_obj']
             stream_d = self._s5b.registerHash(session_hash, file_obj, profile)
-            args = [session, content_name, profile]
-            stream_d.addCallbacks(self._streamCb, self._streamEb, args, None, args)
+            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)
 
@@ -340,8 +347,7 @@
             peer_candidates = transport_data['peer_candidates'] = self._parseCandidates(transport_elt)
             file_obj = content_data['file_obj']
             stream_d = self._s5b.registerHash(session_hash, file_obj, profile)
-            args = [session, content_name, profile]
-            stream_d.addCallbacks(self._streamCb, self._streamEb, args, None, args)
+            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)
             candidates = yield self._s5b.getCandidates(profile)
@@ -375,13 +381,6 @@
 
         defer.returnValue(transport_elt)
 
-    def _streamCb(self, dummy, session, content_name, profile):
-        self._j.contentTerminate(session, content_name, profile=profile)
-
-    def _streamEb(self, failure, session, content_name, profile):
-        log.warning(u"Error while streaming through s5b: {}".format(failure))
-        self._j.contentTerminate(session, content_name, reason=self._j.REASON_FAILED_TRANSPORT, profile=profile)
-
 
 class XEP_0260_handler(XMPPHandler):
     implements(iwokkel.IDisco)