comparison libervia/backend/plugins/plugin_xep_0260.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents e11b13418ba6
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
95 candidate = self._s5b.Candidate(host, port, type_, priority, jid_, cid) 95 candidate = self._s5b.Candidate(host, port, type_, priority, jid_, cid)
96 candidates.append(candidate) 96 candidates.append(candidate)
97 # self._s5b.registerCandidate(candidate) 97 # self._s5b.registerCandidate(candidate)
98 return candidates 98 return candidates
99 99
100 def _build_candidates(self, session, candidates, sid, session_hash, client, mode=None): 100 def _build_candidates(
101 self, session, candidates, sid, session_hash, client, mode=None
102 ):
101 """Build <transport> element with candidates 103 """Build <transport> element with candidates
102 104
103 @param session(dict): jingle session data 105 @param session(dict): jingle session data
104 @param candidates(iterator[plugin_xep_0065.Candidate]): iterator of candidates to add 106 @param candidates(iterator[plugin_xep_0065.Candidate]): iterator of candidates to add
105 @param sid(unicode): transport stream id 107 @param sid(unicode): transport stream id
145 transport_data["peer_session_hash"] = self._s5b.get_session_hash( 147 transport_data["peer_session_hash"] = self._s5b.get_session_hash(
146 session["peer_jid"], session["local_jid"], sid 148 session["peer_jid"], session["local_jid"], sid
147 ) # requester and target are inversed for peer candidates 149 ) # requester and target are inversed for peer candidates
148 transport_data["stream_d"] = self._s5b.register_hash(client, session_hash, None) 150 transport_data["stream_d"] = self._s5b.register_hash(client, session_hash, None)
149 candidates = transport_data["candidates"] = await self._s5b.get_candidates( 151 candidates = transport_data["candidates"] = await self._s5b.get_candidates(
150 client, session["local_jid"]) 152 client, session["local_jid"]
153 )
151 mode = "tcp" # XXX: we only manage tcp for now 154 mode = "tcp" # XXX: we only manage tcp for now
152 transport_elt = self._build_candidates( 155 transport_elt = self._build_candidates(
153 session, candidates, sid, session_hash, client, mode 156 session, candidates, sid, session_hash, client, mode
154 ) 157 )
155 158
156 return transport_elt 159 return transport_elt
157 160
158 def _proxy_activated_cb(self, iq_result_elt, client, candidate, session, content_name): 161 def _proxy_activated_cb(
162 self, iq_result_elt, client, candidate, session, content_name
163 ):
159 """Called when activation confirmation has been received from proxy 164 """Called when activation confirmation has been received from proxy
160 165
161 cf XEP-0260 § 2.4 166 cf XEP-0260 § 2.4
162 """ 167 """
163 # now that the proxy is activated, we have to inform other peer 168 # now that the proxy is activated, we have to inform other peer
302 transport_data["sid"], session["peer_jid"], client 307 transport_data["sid"], session["peer_jid"], client
303 ) 308 )
304 ) 309 )
305 args = [client, choosed_candidate, session, content_name] 310 args = [client, choosed_candidate, session, content_name]
306 d.addCallbacks( 311 d.addCallbacks(
307 self._proxy_activated_cb, self._proxy_activated_eb, args, None, args 312 self._proxy_activated_cb,
313 self._proxy_activated_eb,
314 args,
315 None,
316 args,
308 ) 317 )
309 else: 318 else:
310 # this Deferred will be called when we'll receive activation confirmation from other peer 319 # this Deferred will be called when we'll receive activation confirmation from other peer
311 d = transport_data["activation_d"] = defer.Deferred() 320 d = transport_data["activation_d"] = defer.Deferred()
312 else: 321 else:
354 cid = candidate_elt.attributes["cid"] 363 cid = candidate_elt.attributes["cid"]
355 except KeyError: 364 except KeyError:
356 log.warning("No cid found in <candidate-used>") 365 log.warning("No cid found in <candidate-used>")
357 raise exceptions.DataError 366 raise exceptions.DataError
358 try: 367 try:
359 candidate = next(( 368 candidate = next((c for c in transport_data["candidates"] if c.id == cid))
360 c for c in transport_data["candidates"] if c.id == cid
361 ))
362 except StopIteration: 369 except StopIteration:
363 log.warning("Given cid doesn't correspond to any known candidate !") 370 log.warning("Given cid doesn't correspond to any known candidate !")
364 raise exceptions.DataError # TODO: send an error to other peer, and use better exception 371 raise exceptions.DataError # TODO: send an error to other peer, and use better exception
365 except KeyError: 372 except KeyError:
366 # a transport-info can also be intentionaly sent too early by other peer 373 # a transport-info can also be intentionaly sent too early by other peer
431 assert "peer_candidates" not in transport_data 438 assert "peer_candidates" not in transport_data
432 sid = transport_data["sid"] = transport_elt["sid"] 439 sid = transport_data["sid"] = transport_elt["sid"]
433 session_hash = transport_data["session_hash"] = self._s5b.get_session_hash( 440 session_hash = transport_data["session_hash"] = self._s5b.get_session_hash(
434 session["local_jid"], session["peer_jid"], sid 441 session["local_jid"], session["peer_jid"], sid
435 ) 442 )
436 peer_session_hash = transport_data[ 443 peer_session_hash = transport_data["peer_session_hash"] = (
437 "peer_session_hash" 444 self._s5b.get_session_hash(session["peer_jid"], session["local_jid"], sid)
438 ] = self._s5b.get_session_hash(
439 session["peer_jid"], session["local_jid"], sid
440 ) # requester and target are inversed for peer candidates 445 ) # requester and target are inversed for peer candidates
441 peer_candidates = transport_data["peer_candidates"] = self._parse_candidates( 446 peer_candidates = transport_data["peer_candidates"] = self._parse_candidates(
442 transport_elt 447 transport_elt
443 ) 448 )
444 stream_object = content_data["stream_object"] 449 stream_object = content_data["stream_object"]
503 self._s5b.kill_session(None, transport_data["session_hash"], None, client) 508 self._s5b.kill_session(None, transport_data["session_hash"], None, client)
504 509
505 def _do_fallback(self, feature_checked, session, content_name, client): 510 def _do_fallback(self, feature_checked, session, content_name, client):
506 """Do the fallback, method called once feature is checked 511 """Do the fallback, method called once feature is checked
507 512
508 @param feature_checked(bool): True if other peer can do IBB 513 @param feature_checked(bool): True if other peer can do IBB
509 """ 514 """
510 if not feature_checked: 515 if not feature_checked:
511 log.warning( 516 log.warning(
512 "Other peer can't manage jingle IBB, be have to terminate the session" 517 "Other peer can't manage jingle IBB, be have to terminate the session"
513 ) 518 )
514 self._j.terminate(client, self._j.REASON_CONNECTIVITY_ERROR, session) 519 self._j.terminate(client, self._j.REASON_CONNECTIVITY_ERROR, session)