Mercurial > libervia-backend
comparison libervia/backend/plugins/plugin_xep_0260.py @ 4180:b86912d3fd33
plugin IP: fix use of legacy URL + coroutine use:
An https:/salut-a-toi.org URL was used to retrieve external IP, but it's not valid
anymore, resulting in an exception. This feature is currently disabled.
Also moved several methods from legacy inline callbacks to coroutines.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 09 Dec 2023 14:30:54 +0100 |
parents | 4b842c1fb686 |
children | e11b13418ba6 |
comparison
equal
deleted
inserted
replaced
4179:3b95704ab777 | 4180:b86912d3fd33 |
---|---|
132 candidate_elt["port"] = str(candidate.port) | 132 candidate_elt["port"] = str(candidate.port) |
133 candidate_elt["priority"] = str(candidate.priority) | 133 candidate_elt["priority"] = str(candidate.priority) |
134 candidate_elt["type"] = candidate.type | 134 candidate_elt["type"] = candidate.type |
135 return transport_elt | 135 return transport_elt |
136 | 136 |
137 @defer.inlineCallbacks | 137 async def jingle_session_init(self, client, session, content_name): |
138 def jingle_session_init(self, client, session, content_name): | |
139 content_data = session["contents"][content_name] | 138 content_data = session["contents"][content_name] |
140 transport_data = content_data["transport_data"] | 139 transport_data = content_data["transport_data"] |
141 sid = transport_data["sid"] = str(uuid.uuid4()) | 140 sid = transport_data["sid"] = str(uuid.uuid4()) |
142 session_hash = transport_data["session_hash"] = self._s5b.get_session_hash( | 141 session_hash = transport_data["session_hash"] = self._s5b.get_session_hash( |
143 session["local_jid"], session["peer_jid"], sid | 142 session["local_jid"], session["peer_jid"], sid |
144 ) | 143 ) |
145 transport_data["peer_session_hash"] = self._s5b.get_session_hash( | 144 transport_data["peer_session_hash"] = self._s5b.get_session_hash( |
146 session["peer_jid"], session["local_jid"], sid | 145 session["peer_jid"], session["local_jid"], sid |
147 ) # requester and target are inversed for peer candidates | 146 ) # requester and target are inversed for peer candidates |
148 transport_data["stream_d"] = self._s5b.register_hash(client, session_hash, None) | 147 transport_data["stream_d"] = self._s5b.register_hash(client, session_hash, None) |
149 candidates = transport_data["candidates"] = yield self._s5b.get_candidates( | 148 candidates = transport_data["candidates"] = await self._s5b.get_candidates( |
150 client, session["local_jid"]) | 149 client, session["local_jid"]) |
151 mode = "tcp" # XXX: we only manage tcp for now | 150 mode = "tcp" # XXX: we only manage tcp for now |
152 transport_elt = self._build_candidates( | 151 transport_elt = self._build_candidates( |
153 session, candidates, sid, session_hash, client, mode | 152 session, candidates, sid, session_hash, client, mode |
154 ) | 153 ) |
155 | 154 |
156 defer.returnValue(transport_elt) | 155 return transport_elt |
157 | 156 |
158 def _proxy_activated_cb(self, iq_result_elt, client, candidate, session, content_name): | 157 def _proxy_activated_cb(self, iq_result_elt, client, candidate, session, content_name): |
159 """Called when activation confirmation has been received from proxy | 158 """Called when activation confirmation has been received from proxy |
160 | 159 |
161 cf XEP-0260 § 2.4 | 160 cf XEP-0260 § 2.4 |
396 if proxy_elt.name == "activated": | 395 if proxy_elt.name == "activated": |
397 activation_d.callback(None) | 396 activation_d.callback(None) |
398 else: | 397 else: |
399 activation_d.errback(ProxyError()) | 398 activation_d.errback(ProxyError()) |
400 | 399 |
401 @defer.inlineCallbacks | 400 async def jingle_handler(self, client, action, session, content_name, transport_elt): |
402 def jingle_handler(self, client, action, session, content_name, transport_elt): | |
403 content_data = session["contents"][content_name] | 401 content_data = session["contents"][content_name] |
404 transport_data = content_data["transport_data"] | 402 transport_data = content_data["transport_data"] |
405 | 403 |
406 if action in (self._j.A_ACCEPTED_ACK, self._j.A_PREPARE_RESPONDER): | 404 if action in (self._j.A_ACCEPTED_ACK, self._j.A_PREPARE_RESPONDER): |
407 pass | 405 pass |
449 client, peer_candidates, session_hash, peer_session_hash | 447 client, peer_candidates, session_hash, peer_session_hash |
450 ) | 448 ) |
451 d.addCallback( | 449 d.addCallback( |
452 self._found_peer_candidate, session, transport_data, content_name, client | 450 self._found_peer_candidate, session, transport_data, content_name, client |
453 ) | 451 ) |
454 candidates = yield self._s5b.get_candidates(client, session["local_jid"]) | 452 candidates = await self._s5b.get_candidates(client, session["local_jid"]) |
455 # we remove duplicate candidates | 453 # we remove duplicate candidates |
456 candidates = [ | 454 candidates = [ |
457 candidate for candidate in candidates if candidate not in peer_candidates | 455 candidate for candidate in candidates if candidate not in peer_candidates |
458 ] | 456 ] |
459 | 457 |
491 # note that sid argument is not necessary for sessions created by this plugin | 489 # note that sid argument is not necessary for sessions created by this plugin |
492 self._s5b.kill_session(None, transport_data["session_hash"], None, client) | 490 self._s5b.kill_session(None, transport_data["session_hash"], None, client) |
493 else: | 491 else: |
494 log.warning("FIXME: unmanaged action {}".format(action)) | 492 log.warning("FIXME: unmanaged action {}".format(action)) |
495 | 493 |
496 defer.returnValue(transport_elt) | 494 return transport_elt |
497 | 495 |
498 def jingle_terminate(self, client, action, session, content_name, reason_elt): | 496 def jingle_terminate(self, client, action, session, content_name, reason_elt): |
499 if reason_elt.decline: | 497 if reason_elt.decline: |
500 log.debug("Session declined, deleting S5B session") | 498 log.debug("Session declined, deleting S5B session") |
501 # we just need to clean the S5B session if it is declined | 499 # we just need to clean the S5B session if it is declined |