comparison src/plugins/plugin_xep_0260.py @ 1756:061011fad5b1

plugin XEP-0260: better proxy error handling: - display a better message in logs - fixed fallback to IBB
author Goffi <goffi@goffi.org>
date Thu, 17 Dec 2015 22:37:56 +0100
parents d2e023da2983
children abd6d6f89006
comparison
equal deleted inserted replaced
1755:d2e023da2983 1756:061011fad5b1
48 "description": _("""Implementation of Jingle SOCKS5 Bytestreams""") 48 "description": _("""Implementation of Jingle SOCKS5 Bytestreams""")
49 } 49 }
50 50
51 51
52 class ProxyError(Exception): 52 class ProxyError(Exception):
53 pass 53
54 def __str__(self):
55 return "an error happened while trying to use the proxy"
54 56
55 57
56 class XEP_0260(object): 58 class XEP_0260(object):
57 # TODO: udp handling 59 # TODO: udp handling
58 60
155 # TODO: fallback to IBB 157 # TODO: fallback to IBB
156 # now that the proxy is activated, we have to inform other peer 158 # now that the proxy is activated, we have to inform other peer
157 iq_elt, transport_elt = self._j.buildAction(self._j.A_TRANSPORT_INFO, session, content_name, profile) 159 iq_elt, transport_elt = self._j.buildAction(self._j.A_TRANSPORT_INFO, session, content_name, profile)
158 transport_elt.addElement('proxy-error') 160 transport_elt.addElement('proxy-error')
159 iq_elt.send() 161 iq_elt.send()
160 log.warning(u"Can't activate proxy, we need to fallback to IBB") 162 log.warning(u"Can't activate proxy, we need to fallback to IBB: {reason}"
163 .format(reason = stanza_error.value.condition))
161 client = self.host.getClient(profile) 164 client = self.host.getClient(profile)
162 self.doFallback(session, content_name, client) 165 self.doFallback(session, content_name, client)
163 166
164 def _foundPeerCandidate(self, candidate, session, transport_data, content_name, client): 167 def _foundPeerCandidate(self, candidate, session, transport_data, content_name, client):
165 """Called when the best candidate from other peer is found 168 """Called when the best candidate from other peer is found
262 d = defer.succeed(None) 265 d = defer.succeed(None)
263 266
264 if content_data['senders'] == session['role']: 267 if content_data['senders'] == session['role']:
265 # we can now start the file transfer (or start it after proxy activation) 268 # we can now start the file transfer (or start it after proxy activation)
266 d.addCallback(lambda dummy: choosed_candidate.startTransfer(transport_data['session_hash'])) 269 d.addCallback(lambda dummy: choosed_candidate.startTransfer(transport_data['session_hash']))
270 d.addErrback(self._startEb, session, content_name, client)
271
272 def _startEb(self, fail, session, content_name, client):
273 """Called when it's not possible to start the transfer
274
275 Will try to fallback to IBB
276 """
277 try:
278 reason = unicode(fail.value)
279 except AttributeError:
280 reason = unicode(fail)
281 log.warning(u"Cant start transfert, we'll try fallback method: {}".format(reason))
282 self.doFallback(session, content_name, client)
267 283
268 def _candidateInfo(self, candidate_elt, session, content_name, transport_data, client): 284 def _candidateInfo(self, candidate_elt, session, content_name, transport_data, client):
269 """Called when best candidate has been received from peer (or if none is working) 285 """Called when best candidate has been received from peer (or if none is working)
270 286
271 @param candidate_elt(domish.Element): candidate-used or candidate-error element 287 @param candidate_elt(domish.Element): candidate-used or candidate-error element
318 log.warning(u"Received unexpected transport-info for proxy activation") 334 log.warning(u"Received unexpected transport-info for proxy activation")
319 335
320 if proxy_elt.name == 'activated': 336 if proxy_elt.name == 'activated':
321 activation_d.callback(None) 337 activation_d.callback(None)
322 else: 338 else:
323 activation_d.errback(ProxyError) 339 activation_d.errback(ProxyError())
324 340
325 @defer.inlineCallbacks 341 @defer.inlineCallbacks
326 def jingleHandler(self, action, session, content_name, transport_elt, profile): 342 def jingleHandler(self, action, session, content_name, transport_elt, profile):
327 client = self.host.getClient(profile) 343 client = self.host.getClient(profile)
328 content_data = session['contents'][content_name] 344 content_data = session['contents'][content_name]