annotate libervia/backend/plugins/plugin_xep_0176.py @ 4108:238e305f2306

plugin JID Search: JID search plugin, first draft
author Goffi <goffi@goffi.org>
date Thu, 06 Jul 2023 11:34:51 +0200
parents 4b842c1fb686
children 23fa52acf72c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4045
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia plugin for Jingle (XEP-0176)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 from typing import Dict, List, Optional
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 import uuid
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
21
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from twisted.internet import defer
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from twisted.words.protocols.jabber.xmlstream import XMPPHandler
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from twisted.words.xish import domish
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from wokkel import disco, iwokkel
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from zope.interface import implementer
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
27
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4054
diff changeset
28 from libervia.backend.core import exceptions
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4054
diff changeset
29 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4054
diff changeset
30 from libervia.backend.core.core_types import SatXMPPEntity
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4054
diff changeset
31 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4054
diff changeset
32 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4054
diff changeset
33 from libervia.backend.tools.common import data_format
4045
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 from .plugin_xep_0166 import BaseTransportHandler
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 log = getLogger(__name__)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
38
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 NS_JINGLE_ICE_UDP= "urn:xmpp:jingle:transports:ice-udp:1"
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 PLUGIN_INFO = {
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_NAME: "Jingle ICE-UDP Transport Method",
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 C.PI_IMPORT_NAME: "XEP-0176",
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 C.PI_TYPE: "XEP",
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 C.PI_MODES: C.PLUG_MODE_BOTH,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 C.PI_PROTOCOLS: ["XEP-0176"],
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 C.PI_DEPENDENCIES: ["XEP-0166"],
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 C.PI_RECOMMENDATIONS: [],
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 C.PI_MAIN: "XEP_0176",
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 C.PI_HANDLER: "yes",
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 C.PI_DESCRIPTION: _("""Implementation of Jingle ICE-UDP transport"""),
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 }
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
53
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
54
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 class XEP_0176(BaseTransportHandler):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
56
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 def __init__(self, host):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 log.info(f"plugin {PLUGIN_INFO[C.PI_NAME]!r} initialization")
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.host = host
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 self._j = host.plugins["XEP-0166"] # shortcut to access jingle
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 self._j.register_transport(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 NS_JINGLE_ICE_UDP, self._j.TRANSPORT_DATAGRAM, self, 100
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 )
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 host.bridge.add_method(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 "ice_candidates_add",
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 ".plugin",
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 in_sign="sss",
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 out_sign="",
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 method=self._ice_candidates_add,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 async_=True,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 )
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 host.bridge.add_signal(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 "ice_candidates_new", ".plugin", signature="sss"
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 ) # args: jingle_sid, candidates_serialised, profile
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 host.bridge.add_signal(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 "ice_restart", ".plugin", signature="sss"
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 ) # args: jingle_sid, side ("local" or "peer"), profile
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
78
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 def get_handler(self, client):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 return XEP_0176_handler()
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
81
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 def _ice_candidates_add(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 session_id: str,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 media_ice_data_s: str,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 profile_key: str,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 ):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 client = self.host.get_client(profile_key)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 return defer.ensureDeferred(self.ice_candidates_add(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 client,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 session_id,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 data_format.deserialise(media_ice_data_s),
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 ))
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
94
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 def build_transport(self, ice_data: dict) -> domish.Element:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 """Generate <transport> element from ICE data
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
97
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 @param ice_data: a dict containing the following keys:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 - "ufrag" (str): The ICE username fragment.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 - "pwd" (str): The ICE password.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 - "candidates" (List[dict]): A list of ICE candidate dictionaries, each
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 containing:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 - "component_id" (int): The component ID.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 - "foundation" (str): The candidate foundation.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 - "address" (str): The candidate IP address.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 - "port" (int): The candidate port.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 - "priority" (int): The candidate priority.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 - "transport" (str): The candidate transport protocol, e.g., "udp".
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 - "type" (str): The candidate type, e.g., "host", "srflx", "prflx", or
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 "relay".
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 - "generation" (str, optional): The candidate generation. Defaults to "0".
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 - "network" (str, optional): The candidate network. Defaults to "0".
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 - "rel_addr" (str, optional): The related address for the candidate, if
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 any.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 - "rel_port" (int, optional): The related port for the candidate, if any.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
116
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 @return: A <transport> element.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 """
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 try:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 ufrag: str = ice_data["ufrag"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 pwd: str = ice_data["pwd"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 candidates: List[dict] = ice_data["candidates"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 except KeyError as e:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 raise exceptions.DataError(f"ICE {e} must be provided")
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
125
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 candidates.sort(key=lambda c: int(c.get("priority", 0)), reverse=True)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 transport_elt = domish.Element(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 (NS_JINGLE_ICE_UDP, "transport"),
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 attribs={"ufrag": ufrag, "pwd": pwd}
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 )
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
131
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 for candidate in candidates:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 try:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 candidate_elt = transport_elt.addElement("candidate")
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 candidate_elt["component"] = str(candidate["component_id"])
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 candidate_elt["foundation"] = candidate["foundation"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 candidate_elt["generation"] = str(candidate.get("generation", "0"))
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 candidate_elt["id"] = candidate.get("id") or str(uuid.uuid4())
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 candidate_elt["ip"] = candidate["address"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 candidate_elt["network"] = str(candidate.get("network", "0"))
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 candidate_elt["port"] = str(candidate["port"])
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 candidate_elt["priority"] = str(candidate["priority"])
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 candidate_elt["protocol"] = candidate["transport"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 candidate_elt["type"] = candidate["type"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 except KeyError as e:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 raise exceptions.DataError(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 f"Mandatory ICE candidate attribute {e} is missing"
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 )
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
149
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 if "rel_addr" in candidate and "rel_port" in candidate:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 candidate_elt["rel-addr"] = candidate["rel_addr"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 candidate_elt["rel-port"] = str(candidate["rel_port"])
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
153
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 self.host.trigger.point("XEP-0176_build_transport", transport_elt, ice_data)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
155
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 return transport_elt
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
157
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 def parse_transport(self, transport_elt: domish.Element) -> dict:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 """Parse <transport> to a dict
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
160
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 @param transport_elt: <transport> element
4054
4c8bf67bfbeb plugin XEP-0176: fix candidates data format when calling Bridge's `ice_candidates_new`
Goffi <goffi@goffi.org>
parents: 4052
diff changeset
162 @return: ICE data (as in [build_transport])
4045
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 """
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 try:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 ice_data = {
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 "ufrag": transport_elt["ufrag"],
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 "pwd": transport_elt["pwd"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 }
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 except KeyError as e:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 raise exceptions.DataError(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 f"<transport> is missing mandatory attribute {e}: {transport_elt.toXml()}"
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 )
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 ice_data["candidates"] = ice_candidates = []
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
174
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 for candidate_elt in transport_elt.elements(NS_JINGLE_ICE_UDP, "candidate"):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 try:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 candidate = {
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 "component_id": int(candidate_elt["component"]),
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 "foundation": candidate_elt["foundation"],
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 "address": candidate_elt["ip"],
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 "port": int(candidate_elt["port"]),
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 "priority": int(candidate_elt["priority"]),
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 "transport": candidate_elt["protocol"],
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 "type": candidate_elt["type"],
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 }
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 except KeyError as e:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 raise exceptions.DataError(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 f"Mandatory attribute {e} is missing in candidate element"
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 )
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
190
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 if candidate_elt.hasAttribute("generation"):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 candidate["generation"] = candidate_elt["generation"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
193
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 if candidate_elt.hasAttribute("network"):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 candidate["network"] = candidate_elt["network"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
196
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 if candidate_elt.hasAttribute("rel-addr"):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 candidate["rel_addr"] = candidate_elt["rel-addr"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
199
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 if candidate_elt.hasAttribute("rel-port"):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 candidate["rel_port"] = int(candidate_elt["rel-port"])
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
202
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 ice_candidates.append(candidate)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
204
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 self.host.trigger.point("XEP-0176_parse_transport", transport_elt, ice_data)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
206
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 return ice_data
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
208
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 async def jingle_session_init(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 self,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 client: SatXMPPEntity,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 session: dict,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 content_name: str,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 ) -> domish.Element:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 """Create a Jingle session initiation transport element with ICE candidates.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
216
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 @param client: SatXMPPEntity object representing the client.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 @param session: Dictionary containing session data.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 @param content_name: Name of the content.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 @param ufrag: ICE username fragment.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 @param pwd: ICE password.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 @param candidates: List of ICE candidate dictionaries parsed from the
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 parse_ice_candidate method.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
224
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 @return: domish.Element representing the Jingle transport element.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
226
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 @raise exceptions.DataError: If mandatory data is missing from the candidates.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 """
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 content_data = session["contents"][content_name]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 transport_data = content_data["transport_data"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 ice_data = transport_data["local_ice_data"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 return self.build_transport(ice_data)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
233
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 async def jingle_handler(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 self,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 client: SatXMPPEntity,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 action: str,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 session: dict,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 content_name: str,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 transport_elt: domish.Element,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 ) -> domish.Element:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 """Handle Jingle requests
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
243
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 @param client: The SatXMPPEntity instance.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
245 @param action: The action to be performed with the session.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 @param session: A dictionary containing the session information.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 @param content_name: The name of the content.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 @param transport_elt: The domish.Element instance representing the transport
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 element.
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
250
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 @return: <transport> element
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 """
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 content_data = session["contents"][content_name]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 transport_data = content_data["transport_data"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 if action in (self._j.A_PREPARE_CONFIRMATION, self._j.A_PREPARE_INITIATOR):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 peer_ice_data = self.parse_transport(transport_elt)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 transport_data["peer_ice_data"] = peer_ice_data
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
258
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 elif action in (self._j.A_ACCEPTED_ACK, self._j.A_PREPARE_RESPONDER):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 pass
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
261
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 elif action == self._j.A_SESSION_ACCEPT:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 pass
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
264
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 elif action == self._j.A_START:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 pass
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
267
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 elif action == self._j.A_SESSION_INITIATE:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 # responder side, we give our candidates
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 transport_elt = self.build_transport(transport_data["local_ice_data"])
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 elif action == self._j.A_TRANSPORT_INFO:
4054
4c8bf67bfbeb plugin XEP-0176: fix candidates data format when calling Bridge's `ice_candidates_new`
Goffi <goffi@goffi.org>
parents: 4052
diff changeset
272
4c8bf67bfbeb plugin XEP-0176: fix candidates data format when calling Bridge's `ice_candidates_new`
Goffi <goffi@goffi.org>
parents: 4052
diff changeset
273 media_type = content_data["application_data"].get("media")
4045
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 new_ice_data = self.parse_transport(transport_elt)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 restart = self.update_candidates(transport_data, new_ice_data, local=False)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
276 if restart:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
277 log.debug(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
278 f"Peer ICE restart detected on session {session['id']} "
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 f"[{client.profile}]"
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
280 )
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
281 self.host.bridge.ice_restart(session["id"], "peer", client.profile)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
282
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
283 self.host.bridge.ice_candidates_new(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
284 session["id"],
4054
4c8bf67bfbeb plugin XEP-0176: fix candidates data format when calling Bridge's `ice_candidates_new`
Goffi <goffi@goffi.org>
parents: 4052
diff changeset
285 data_format.serialise({media_type: new_ice_data}),
4045
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
286 client.profile
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
287 )
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 elif action == self._j.A_DESTROY:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 pass
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 else:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 log.warning("FIXME: unmanaged action {}".format(action))
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
292
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 return transport_elt
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
294
4052
2ced30f6d5de plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents: 4045
diff changeset
295 def jingle_terminate(
2ced30f6d5de plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents: 4045
diff changeset
296 self,
2ced30f6d5de plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents: 4045
diff changeset
297 client: SatXMPPEntity,
2ced30f6d5de plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents: 4045
diff changeset
298 action: str,
2ced30f6d5de plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents: 4045
diff changeset
299 session: dict,
2ced30f6d5de plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents: 4045
diff changeset
300 content_name: str,
2ced30f6d5de plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents: 4045
diff changeset
301 reason_elt: domish.Element,
2ced30f6d5de plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents: 4045
diff changeset
302 ) -> None:
4045
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
303 log.debug("ICE-UDP session terminated")
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
304
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 def update_candidates(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 self,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 transport_data: dict,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 new_ice_data: dict,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
309 local: bool
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 ) -> bool:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
311 """Update ICE candidates when new one are received
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
312
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 @param transport_data: transport_data of the content linked to the candidates
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
314 @param new_ice_data: new ICE data, in the same format as returned
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
315 by [self.parse_transport]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
316 @param local: True if it's our candidates, False if it's peer ones
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 @return: True if there is a ICE restart
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
318 """
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 key = "local_ice_data" if local else "peer_ice_data"
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
320 try:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
321 ice_data = transport_data[key]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 except KeyError:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
323 log.warning(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
324 f"no {key} available"
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 )
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
326 transport_data[key] = new_ice_data
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
327 else:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
328 if (
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
329 new_ice_data["ufrag"] != ice_data["ufrag"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
330 or new_ice_data["pwd"] != ice_data["pwd"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
331 ):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
332 ice_data["ufrag"] = new_ice_data["ufrag"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
333 ice_data["pwd"] = new_ice_data["pwd"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
334 ice_data["candidates"] = new_ice_data["candidates"]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
335 return True
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
336 return False
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
337
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
338 async def ice_candidates_add(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
339 self,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
340 client: SatXMPPEntity,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
341 session_id: str,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
342 media_ice_data: Dict[str, dict]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
343 ) -> None:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
344 """Called when a new ICE candidates are available for a session
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
345
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 @param session_id: Session ID
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 @param candidates: a map from media type (audio, video) to ICE data
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 ICE data must be in the same format as in [self.parse_transport]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 """
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 session = self._j.get_session(client, session_id)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 iq_elt: Optional[domish.Element] = None
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
352
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
353 for media_type, new_ice_data in media_ice_data.items():
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
354 for content_name, content_data in session["contents"].items():
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
355 if content_data["application_data"].get("media") == media_type:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
356 break
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
357 else:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
358 log.warning(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
359 "no media of type {media_type} has been found"
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
360 )
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
361 continue
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 restart = self.update_candidates(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
363 content_data["transport_data"], new_ice_data, True
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
364 )
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
365 if restart:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
366 log.debug(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 f"Local ICE restart detected on session {session['id']} "
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
368 f"[{client.profile}]"
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
369 )
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
370 self.host.bridge.ice_restart(session["id"], "local", client.profile)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
371 transport_elt = self.build_transport(new_ice_data)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
372 iq_elt, __ = self._j.build_action(
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
373 client, self._j.A_TRANSPORT_INFO, session, content_name, iq_elt=iq_elt,
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
374 transport_elt=transport_elt
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
375 )
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
376
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
377 if iq_elt is not None:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
378 try:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
379 await iq_elt.send()
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
380 except Exception as e:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
381 log.warning(f"Could not send new ICE candidates: {e}")
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
382
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
383 else:
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
384 log.error("Could not find any content to apply new ICE candidates")
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
385
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
386
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
387 @implementer(iwokkel.IDisco)
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
388 class XEP_0176_handler(XMPPHandler):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
389
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
390 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
391 return [disco.DiscoFeature(NS_JINGLE_ICE_UDP)]
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
392
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
393 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
ae756bf7c3e8 plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
394 return []