Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0176.py @ 4116:23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 21 Aug 2023 15:19:45 +0200 |
parents | 4b842c1fb686 |
children | e11b13418ba6 |
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 |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
39 NS_JINGLE_ICE_UDP = "urn:xmpp:jingle:transports:ice-udp:1" |
4045
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 def __init__(self, host): |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 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
|
58 self.host = host |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 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
|
60 self._j.register_transport( |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 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
|
62 ) |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 host.bridge.add_method( |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 "ice_candidates_add", |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 ".plugin", |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 in_sign="sss", |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 out_sign="", |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 method=self._ice_candidates_add, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 async_=True, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 ) |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 host.bridge.add_signal( |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 "ice_candidates_new", ".plugin", signature="sss" |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 ) # args: jingle_sid, candidates_serialised, profile |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 host.bridge.add_signal( |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 "ice_restart", ".plugin", signature="sss" |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 ) # 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
|
77 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 def get_handler(self, client): |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 return XEP_0176_handler() |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 def _ice_candidates_add( |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 self, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 session_id: str, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 media_ice_data_s: str, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 profile_key: str, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 ): |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 client = self.host.get_client(profile_key) |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
88 return defer.ensureDeferred( |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
89 self.ice_candidates_add( |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
90 client, |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
91 session_id, |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
92 data_format.deserialise(media_ice_data_s), |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
93 ) |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
94 ) |
4045
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 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
|
97 """Generate <transport> element from ICE data |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 @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
|
100 - "ufrag" (str): The ICE username fragment. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 - "pwd" (str): The ICE password. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 - "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
|
103 containing: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 - "component_id" (int): The component ID. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 - "foundation" (str): The candidate foundation. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 - "address" (str): The candidate IP address. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 - "port" (int): The candidate port. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 - "priority" (int): The candidate priority. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 - "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
|
110 - "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
|
111 "relay". |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 - "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
|
113 - "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
|
114 - "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
|
115 any. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 - "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
|
117 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 @return: A <transport> element. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 """ |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 try: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 ufrag: str = ice_data["ufrag"] |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 pwd: str = ice_data["pwd"] |
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") |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
125 candidates: List[dict] = ice_data.get("candidates", []) |
4045
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 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
|
128 transport_elt = domish.Element( |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
129 (NS_JINGLE_ICE_UDP, "transport"), attribs={"ufrag": ufrag, "pwd": pwd} |
4045
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: |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
165 ice_data = {"ufrag": transport_elt["ufrag"], "pwd": transport_elt["pwd"]} |
4045
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 except KeyError as e: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 raise exceptions.DataError( |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 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
|
169 ) |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 ice_data["candidates"] = ice_candidates = [] |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 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
|
173 try: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 candidate = { |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 "component_id": int(candidate_elt["component"]), |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 "foundation": candidate_elt["foundation"], |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 "address": candidate_elt["ip"], |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 "port": int(candidate_elt["port"]), |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 "priority": int(candidate_elt["priority"]), |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 "transport": candidate_elt["protocol"], |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 "type": candidate_elt["type"], |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 } |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 except KeyError as e: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 raise exceptions.DataError( |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 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
|
186 ) |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 if candidate_elt.hasAttribute("generation"): |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 candidate["generation"] = candidate_elt["generation"] |
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("network"): |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 candidate["network"] = candidate_elt["network"] |
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("rel-addr"): |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 candidate["rel_addr"] = candidate_elt["rel-addr"] |
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-port"): |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 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
|
199 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 ice_candidates.append(candidate) |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 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
|
203 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 return ice_data |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 async def jingle_session_init( |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 self, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 client: SatXMPPEntity, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 session: dict, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 content_name: str, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 ) -> domish.Element: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 """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
|
213 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 @param client: SatXMPPEntity object representing the client. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 @param session: Dictionary containing session data. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 @param content_name: Name of the content. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 @param ufrag: ICE username fragment. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 @param pwd: ICE password. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 @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
|
220 parse_ice_candidate method. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 @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
|
223 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 @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
|
225 """ |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 content_data = session["contents"][content_name] |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 transport_data = content_data["transport_data"] |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 ice_data = transport_data["local_ice_data"] |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 return self.build_transport(ice_data) |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 async def jingle_handler( |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 self, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 client: SatXMPPEntity, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 action: str, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 session: dict, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 content_name: str, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 transport_elt: domish.Element, |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 ) -> domish.Element: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 """Handle Jingle requests |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 @param client: The SatXMPPEntity instance. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 @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
|
243 @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
|
244 @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
|
245 @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
|
246 element. |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 @return: <transport> element |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 """ |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 content_data = session["contents"][content_name] |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 transport_data = content_data["transport_data"] |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 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
|
253 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
|
254 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
|
255 |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
256 elif action == self._j.A_ACCEPTED_ACK: |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
257 buffer = session.pop("XEP-0176_handler_buffer", None) |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
258 if buffer: |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
259 log.debug("replaying buffered events") |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
260 for args in buffer: |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
261 await self.jingle_handler(*args) |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
262 elif action == self._j.A_PREPARE_RESPONDER: |
4045
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_SESSION_ACCEPT: |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
266 # we check if we have any buffered ICE candidates, and send them if it's the |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
267 # case |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
268 media_type = content_data["application_data"].get("media") |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
269 try: |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
270 buffer = session["XEP-0176_buffer"] |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
271 buffered_ice_data = buffer.pop(media_type) |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
272 except KeyError: |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
273 pass |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
274 else: |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
275 if not buffer: |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
276 del session["XEP-0176_buffer"] |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
277 transport_elt = self.build_transport(buffered_ice_data) |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
278 iq_elt, __ = self._j.build_action( |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
279 client, |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
280 self._j.A_TRANSPORT_INFO, |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
281 session, |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
282 content_name, |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
283 context_elt=transport_elt, |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
284 ) |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
285 await iq_elt.send() |
4045
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 elif action == self._j.A_START: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 pass |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 elif action == self._j.A_SESSION_INITIATE: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 # responder side, we give our candidates |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 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
|
293 elif action == self._j.A_TRANSPORT_INFO: |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
294 if session["state"] == self._j.STATE_PENDING: |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
295 # Session is not yet active; we buffer the arguments to replay them |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
296 # when the session becomes active. This makes the frontend's life easier. |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
297 log.debug("session is not active yet, buffering transport-info element") |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
298 buffer = session.setdefault("XEP-0176_handler_buffer", []) |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
299 buffer.append([client, action, session, content_name, transport_elt]) |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
300 return transport_elt |
4054
4c8bf67bfbeb
plugin XEP-0176: fix candidates data format when calling Bridge's `ice_candidates_new`
Goffi <goffi@goffi.org>
parents:
4052
diff
changeset
|
301 |
4c8bf67bfbeb
plugin XEP-0176: fix candidates data format when calling Bridge's `ice_candidates_new`
Goffi <goffi@goffi.org>
parents:
4052
diff
changeset
|
302 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
|
303 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
|
304 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
|
305 if restart: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 log.debug( |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 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
|
308 f"[{client.profile}]" |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 ) |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 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
|
311 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 self.host.bridge.ice_candidates_new( |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 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
|
314 data_format.serialise({media_type: new_ice_data}), |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
315 client.profile, |
4045
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 ) |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 elif action == self._j.A_DESTROY: |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
318 pass |
4045
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 else: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 log.warning("FIXME: unmanaged action {}".format(action)) |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 return transport_elt |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 |
4052
2ced30f6d5de
plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents:
4045
diff
changeset
|
324 def jingle_terminate( |
2ced30f6d5de
plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents:
4045
diff
changeset
|
325 self, |
2ced30f6d5de
plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents:
4045
diff
changeset
|
326 client: SatXMPPEntity, |
2ced30f6d5de
plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents:
4045
diff
changeset
|
327 action: str, |
2ced30f6d5de
plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents:
4045
diff
changeset
|
328 session: dict, |
2ced30f6d5de
plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents:
4045
diff
changeset
|
329 content_name: str, |
2ced30f6d5de
plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents:
4045
diff
changeset
|
330 reason_elt: domish.Element, |
2ced30f6d5de
plugin XEP-0166, 0176, 0234: minor renaming + type hints
Goffi <goffi@goffi.org>
parents:
4045
diff
changeset
|
331 ) -> None: |
4045
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 log.debug("ICE-UDP session terminated") |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 def update_candidates( |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
335 self, transport_data: dict, new_ice_data: dict, local: bool |
4045
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 ) -> bool: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 """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
|
338 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
339 @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
|
340 @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
|
341 by [self.parse_transport] |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 @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
|
343 @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
|
344 """ |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 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
|
346 try: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
347 ice_data = transport_data[key] |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 except KeyError: |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
349 log.warning(f"no {key} available") |
4045
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 transport_data[key] = new_ice_data |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 else: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 if ( |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 new_ice_data["ufrag"] != ice_data["ufrag"] |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 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
|
355 ): |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 ice_data["ufrag"] = new_ice_data["ufrag"] |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 ice_data["pwd"] = new_ice_data["pwd"] |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 ice_data["candidates"] = new_ice_data["candidates"] |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 return True |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 return False |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 async def ice_candidates_add( |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
363 self, client: SatXMPPEntity, session_id: str, media_ice_data: Dict[str, dict] |
4045
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 ) -> None: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 """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
|
366 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 @param session_id: Session ID |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
368 @param media_ice_data: a map from media type (audio, video) to ICE data |
4045
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
369 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
|
370 """ |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 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
|
372 iq_elt: Optional[domish.Element] = None |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
373 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 for media_type, new_ice_data in media_ice_data.items(): |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
375 if session["state"] == self._j.STATE_PENDING: |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
376 log.debug(f"session not active, buffering") |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
377 buffer = session.setdefault("XEP-0176_buffer", {}) |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
378 media_buffer = buffer.setdefault(media_type, {}) |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
379 |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
380 for key in ["ufrag", "pwd"]: |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
381 if key not in media_buffer: |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
382 media_buffer[key] = new_ice_data[key] |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
383 else: |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
384 if media_buffer[key] != new_ice_data[key]: |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
385 log.warning( |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
386 f"{key} conflict, new value will replace old one\n" |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
387 f"buffer={media_buffer[key]!r}\n" |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
388 f"new={new_ice_data[key]!r}" |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
389 ) |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
390 media_buffer[key] = new_ice_data[key] |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
391 |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
392 media_buffer.setdefault("candidates", []).extend( |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
393 new_ice_data["candidates"] |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
394 ) |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
395 continue |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
396 |
4045
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
397 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
|
398 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
|
399 break |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 else: |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
401 log.warning(f"no media of type {media_type} has been found") |
4045
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
402 continue |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
403 restart = self.update_candidates( |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
404 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
|
405 ) |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
406 if restart: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
407 log.debug( |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
408 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
|
409 f"[{client.profile}]" |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
410 ) |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
411 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
|
412 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
|
413 iq_elt, __ = self._j.build_action( |
4116
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
414 client, |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
415 self._j.A_TRANSPORT_INFO, |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
416 session, |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
417 content_name, |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
418 iq_elt=iq_elt, |
23fa52acf72c
plugin XEP-0167, XEP-0176: transport-info and ICE candidate sending are delayed if session is not active yet
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
419 context_elt=transport_elt, |
4045
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
420 ) |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
421 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
422 if iq_elt is not None: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
423 try: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
424 await iq_elt.send() |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
425 except Exception as e: |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
426 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
|
427 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
428 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
429 @implementer(iwokkel.IDisco) |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
430 class XEP_0176_handler(XMPPHandler): |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
431 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
432 return [disco.DiscoFeature(NS_JINGLE_ICE_UDP)] |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
433 |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
434 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
ae756bf7c3e8
plugin XEP-0176: Jingle ICE-UDP Transport Method implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
435 return [] |