Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0260.py @ 2635:eecd84a2530a
0.7.0a1 release
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 04 Jul 2018 07:26:20 +0200 |
parents | 56f94936df1e |
children | 378188abe941 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
1560 | 2 # -*- coding: utf-8 -*- |
3 | |
4 # SAT plugin for Jingle (XEP-0260) | |
2483 | 5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org) |
1560 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 from sat.core.i18n import _ | |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
21 from sat.core.constants import Const as C |
1560 | 22 from sat.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
23 |
1560 | 24 log = getLogger(__name__) |
25 from sat.core import exceptions | |
26 from wokkel import disco, iwokkel | |
27 from zope.interface import implements | |
28 from twisted.words.xish import domish | |
29 from twisted.words.protocols.jabber import jid | |
30 from twisted.internet import defer | |
31 import uuid | |
32 | |
33 try: | |
34 from twisted.words.protocols.xmlstream import XMPPHandler | |
35 except ImportError: | |
36 from wokkel.subprotocols import XMPPHandler | |
37 | |
38 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
39 NS_JINGLE_S5B = "urn:xmpp:jingle:transports:s5b:1" |
1560 | 40 |
41 PLUGIN_INFO = { | |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
42 C.PI_NAME: "Jingle SOCKS5 Bytestreams", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
43 C.PI_IMPORT_NAME: "XEP-0260", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
44 C.PI_TYPE: "XEP", |
2504
67cc54b01a12
plugin file sharing component: first draft:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
45 C.PI_MODES: C.PLUG_MODE_BOTH, |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
46 C.PI_PROTOCOLS: ["XEP-0260"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
47 C.PI_DEPENDENCIES: ["XEP-0166", "XEP-0065"], |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
48 C.PI_RECOMMENDATIONS: ["XEP-0261"], # needed for fallback |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
49 C.PI_MAIN: "XEP_0260", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
50 C.PI_HANDLER: "yes", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
51 C.PI_DESCRIPTION: _("""Implementation of Jingle SOCKS5 Bytestreams"""), |
1560 | 52 } |
53 | |
54 | |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
55 class ProxyError(Exception): |
1756
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
56 def __str__(self): |
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
57 return "an error happened while trying to use the proxy" |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
58 |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
59 |
1560 | 60 class XEP_0260(object): |
61 # TODO: udp handling | |
62 | |
63 def __init__(self, host): | |
64 log.info(_("plugin Jingle SOCKS5 Bytestreams")) | |
65 self.host = host | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 self._j = host.plugins["XEP-0166"] # shortcut to access jingle |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
67 self._s5b = host.plugins["XEP-0065"] # and socks5 bytestream |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
68 try: |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
69 self._jingle_ibb = host.plugins["XEP-0261"] |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
70 except KeyError: |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
71 self._jingle_ibb = None |
1560 | 72 self._j.registerTransport(NS_JINGLE_S5B, self._j.TRANSPORT_STREAMING, self, 100) |
73 | |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
74 def getHandler(self, client): |
1560 | 75 return XEP_0260_handler() |
76 | |
77 def _parseCandidates(self, transport_elt): | |
78 """Parse <candidate> elements | |
79 | |
80 @param transport_elt(domish.Element): parent <transport> element | |
81 @return (list[plugin_xep_0065.Candidate): list of parsed candidates | |
82 """ | |
83 candidates = [] | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
84 for candidate_elt in transport_elt.elements(NS_JINGLE_S5B, "candidate"): |
1560 | 85 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
86 cid = candidate_elt["cid"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
87 host = candidate_elt["host"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
88 jid_ = jid.JID(candidate_elt["jid"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
89 port = int(candidate_elt.getAttribute("port", 1080)) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
90 priority = int(candidate_elt["priority"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
91 type_ = candidate_elt.getAttribute("type", self._s5b.TYPE_DIRECT) |
1560 | 92 except (KeyError, ValueError): |
93 raise exceptions.DataError() | |
94 candidate = self._s5b.Candidate(host, port, type_, priority, jid_, cid) | |
95 candidates.append(candidate) | |
96 # self._s5b.registerCandidate(candidate) | |
97 return candidates | |
98 | |
99 def _buildCandidates(self, session, candidates, sid, session_hash, client, mode=None): | |
100 """Build <transport> element with candidates | |
101 | |
102 @param session(dict): jingle session data | |
103 @param candidates(iterator[plugin_xep_0065.Candidate]): iterator of candidates to add | |
104 @param sid(unicode): transport stream id | |
105 @param client: %(doc_client)s | |
106 @param mode(str, None): 'tcp' or 'udp', or None to have no attribute | |
107 @return (domish.Element): parent <transport> element where <candidate> elements must be added | |
108 """ | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
109 proxy = next( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
110 ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
111 candidate |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
112 for candidate in candidates |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 if candidate.type == self._s5b.TYPE_PROXY |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
114 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
115 None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
116 ) |
1560 | 117 transport_elt = domish.Element((NS_JINGLE_S5B, "transport")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
118 transport_elt["sid"] = sid |
1560 | 119 if proxy is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
120 transport_elt["dstaddr"] = session_hash |
1560 | 121 if mode is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
122 transport_elt["mode"] = "tcp" # XXX: we only manage tcp for now |
1560 | 123 |
124 for candidate in candidates: | |
125 log.debug(u"Adding candidate: {}".format(candidate)) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
126 candidate_elt = transport_elt.addElement("candidate", NS_JINGLE_S5B) |
1560 | 127 if candidate.id is None: |
128 candidate.id = unicode(uuid.uuid4()) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
129 candidate_elt["cid"] = candidate.id |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
130 candidate_elt["host"] = candidate.host |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
131 candidate_elt["jid"] = candidate.jid.full() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
132 candidate_elt["port"] = unicode(candidate.port) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
133 candidate_elt["priority"] = unicode(candidate.priority) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
134 candidate_elt["type"] = candidate.type |
1560 | 135 return transport_elt |
136 | |
137 @defer.inlineCallbacks | |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
138 def jingleSessionInit(self, client, session, content_name): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
139 content_data = session["contents"][content_name] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
140 transport_data = content_data["transport_data"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
141 sid = transport_data["sid"] = unicode(uuid.uuid4()) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
142 session_hash = transport_data["session_hash"] = self._s5b.getSessionHash( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
143 client.jid, session["peer_jid"], sid |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
144 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
145 transport_data["peer_session_hash"] = self._s5b.getSessionHash( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
146 session["peer_jid"], client.jid, sid |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
147 ) # requester and target are inversed for peer candidates |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
148 transport_data["stream_d"] = self._s5b.registerHash(client, session_hash, None) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 candidates = transport_data["candidates"] = yield self._s5b.getCandidates(client) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
150 mode = "tcp" # XXX: we only manage tcp for now |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
151 transport_elt = self._buildCandidates( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
152 session, candidates, sid, session_hash, client, mode |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
153 ) |
1560 | 154 |
155 defer.returnValue(transport_elt) | |
156 | |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
157 def _proxyActivatedCb(self, iq_result_elt, client, candidate, session, content_name): |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
158 """Called when activation confirmation has been received from proxy |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
159 |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
160 cf XEP-0260 § 2.4 |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
161 """ |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
162 # now that the proxy is activated, we have to inform other peer |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
163 iq_elt, transport_elt = self._j.buildAction( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
164 client, self._j.A_TRANSPORT_INFO, session, content_name |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
165 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
166 activated_elt = transport_elt.addElement("activated") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
167 activated_elt["cid"] = candidate.id |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
168 iq_elt.send() |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
169 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
170 def _proxyActivatedEb(self, stanza_error, client, candidate, session, content_name): |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
171 """Called when activation error has been received from proxy |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
172 |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
173 cf XEP-0260 § 2.4 |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
174 """ |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
175 # TODO: fallback to IBB |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
176 # now that the proxy is activated, we have to inform other peer |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
177 iq_elt, transport_elt = self._j.buildAction( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
178 client, self._j.A_TRANSPORT_INFO, session, content_name |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
179 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
180 transport_elt.addElement("proxy-error") |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
181 iq_elt.send() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
182 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
183 u"Can't activate proxy, we need to fallback to IBB: {reason}".format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
184 reason=stanza_error.value.condition |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
185 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
186 ) |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
187 self.doFallback(session, content_name, client) |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
188 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
189 def _foundPeerCandidate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
190 self, candidate, session, transport_data, content_name, client |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
191 ): |
1560 | 192 """Called when the best candidate from other peer is found |
193 | |
194 @param candidate(XEP_0065.Candidate, None): selected candidate, | |
195 or None if no candidate is accessible | |
196 @param session(dict): session data | |
197 @param transport_data(dict): transport data | |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
198 @param content_name(unicode): name of the current content |
1560 | 199 @param client(unicode): %(doc_client)s |
200 """ | |
201 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
202 transport_data["best_candidate"] = candidate |
1560 | 203 # we need to disconnect all non selected candidates before removing them |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
204 for c in transport_data["peer_candidates"]: |
1560 | 205 if c is None or c is candidate: |
206 continue | |
207 c.discard() | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
208 del transport_data["peer_candidates"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
209 iq_elt, transport_elt = self._j.buildAction( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
210 client, self._j.A_TRANSPORT_INFO, session, content_name |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
211 ) |
1560 | 212 if candidate is None: |
213 log.warning(u"Can't connect to any peer candidate") | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
214 candidate_elt = transport_elt.addElement("candidate-error") |
1560 | 215 else: |
216 log.info(u"Found best peer candidate: {}".format(unicode(candidate))) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
217 candidate_elt = transport_elt.addElement("candidate-used") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
218 candidate_elt["cid"] = candidate.id |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
219 iq_elt.send() # TODO: check result stanza |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
220 self._checkCandidates(session, content_name, transport_data, client) |
1560 | 221 |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
222 def _checkCandidates(self, session, content_name, transport_data, client): |
1560 | 223 """Called when a candidate has been choosed |
224 | |
225 if we have both candidates, we select one, or fallback to an other transport | |
226 @param session(dict): session data | |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
227 @param content_name(unicode): name of the current content |
1560 | 228 @param transport_data(dict): transport data |
229 @param client(unicode): %(doc_client)s | |
230 """ | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
231 content_data = session["contents"][content_name] |
1560 | 232 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
233 best_candidate = transport_data["best_candidate"] |
1560 | 234 except KeyError: |
235 # we have not our best candidate yet | |
236 return | |
237 try: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
238 peer_best_candidate = transport_data["peer_best_candidate"] |
1560 | 239 except KeyError: |
240 # we have not peer best candidate yet | |
241 return | |
242 | |
243 # at this point we have both candidates, it's time to choose one | |
244 if best_candidate is None or peer_best_candidate is None: | |
245 choosed_candidate = best_candidate or peer_best_candidate | |
246 else: | |
247 if best_candidate.priority == peer_best_candidate.priority: | |
248 # same priority, we choose initiator one according to XEP-0260 §2.4 #4 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
249 log.debug( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
250 u"Candidates have same priority, we select the one choosed by initiator" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
251 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
252 if session["initiator"] == client.jid: |
1560 | 253 choosed_candidate = best_candidate |
254 else: | |
255 choosed_candidate = peer_best_candidate | |
256 else: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
257 choosed_candidate = max( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
258 best_candidate, peer_best_candidate, key=lambda c: c.priority |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
259 ) |
1560 | 260 |
261 if choosed_candidate is None: | |
262 log.warning(u"Socks5 negociation failed, we need to fallback to IBB") | |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
263 self.doFallback(session, content_name, client) |
1560 | 264 else: |
1571
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
265 if choosed_candidate == peer_best_candidate: |
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
266 # peer_best_candidate was choosed from the candidates we have sent |
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
267 # so our_candidate is true if choosed_candidate is peer_best_candidate |
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
268 our_candidate = True |
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
269 # than also mean that best_candidate must be discarded ! |
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
270 try: |
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
271 best_candidate.discard() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
272 except AttributeError: # but it can be None |
1571
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
273 pass |
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
274 else: |
c668081eba1c
plugins XEP-0234, XEP-0260, XEP-0261: jingle session termination is managed by application (XEP-0234) instead of transport
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
275 our_candidate = False |
1560 | 276 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
277 log.info( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
278 u"Socks5 negociation successful, {who} candidate will be used: {candidate}".format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
279 who=u"our" if our_candidate else u"other peer", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
280 candidate=choosed_candidate, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
281 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
282 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
283 del transport_data["best_candidate"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
284 del transport_data["peer_best_candidate"] |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
285 |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
286 if choosed_candidate.type == self._s5b.TYPE_PROXY: |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
287 # the stream transfer need to wait for proxy activation |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
288 # (see XEP-0260 § 2.4) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
289 if our_candidate: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
290 d = self._s5b.connectCandidate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
291 client, choosed_candidate, transport_data["session_hash"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
292 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
293 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
294 lambda dummy: choosed_candidate.activate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
295 transport_data["sid"], session["peer_jid"], client |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
296 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
297 ) |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
298 args = [client, choosed_candidate, session, content_name] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
299 d.addCallbacks( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
300 self._proxyActivatedCb, self._proxyActivatedEb, args, None, args |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
301 ) |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
302 else: |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
303 # this Deferred will be called when we'll receive activation confirmation from other peer |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
304 d = transport_data["activation_d"] = defer.Deferred() |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
305 else: |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
306 d = defer.succeed(None) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
307 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
308 if content_data["senders"] == session["role"]: |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
309 # we can now start the stream transfer (or start it after proxy activation) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
310 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
311 lambda dummy: choosed_candidate.startTransfer( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
312 transport_data["session_hash"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
313 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
314 ) |
1756
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
315 d.addErrback(self._startEb, session, content_name, client) |
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
316 |
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
317 def _startEb(self, fail, session, content_name, client): |
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
318 """Called when it's not possible to start the transfer |
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
319 |
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
320 Will try to fallback to IBB |
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
321 """ |
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
322 try: |
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
323 reason = unicode(fail.value) |
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
324 except AttributeError: |
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
325 reason = unicode(fail) |
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
326 log.warning(u"Cant start transfert, we'll try fallback method: {}".format(reason)) |
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
327 self.doFallback(session, content_name, client) |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
328 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
329 def _candidateInfo( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
330 self, candidate_elt, session, content_name, transport_data, client |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
331 ): |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
332 """Called when best candidate has been received from peer (or if none is working) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
333 |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
334 @param candidate_elt(domish.Element): candidate-used or candidate-error element |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
335 (see XEP-0260 §2.3) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
336 @param session(dict): session data |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
337 @param content_name(unicode): name of the current content |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
338 @param transport_data(dict): transport data |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
339 @param client(unicode): %(doc_client)s |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
340 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
341 if candidate_elt.name == "candidate-error": |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
342 # candidate-error, no candidate worked |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
343 transport_data["peer_best_candidate"] = None |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
344 else: |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
345 # candidate-used, one candidate was choosed |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
346 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
347 cid = candidate_elt.attributes["cid"] |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
348 except KeyError: |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
349 log.warning(u"No cid found in <candidate-used>") |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
350 raise exceptions.DataError |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
351 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
352 candidate = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
353 c for c in transport_data["candidates"] if c.id == cid |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
354 ).next() |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
355 except StopIteration: |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
356 log.warning(u"Given cid doesn't correspond to any known candidate !") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
357 raise exceptions.DataError # TODO: send an error to other peer, and use better exception |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
358 except KeyError: |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
359 # a transport-info can also be intentionaly sent too early by other peer |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
360 # but there is little probability |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
361 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
362 u'"candidates" key doesn\'t exists in transport_data, it should at this point' |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
363 ) |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
364 raise exceptions.InternalError |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
365 # at this point we have the candidate choosed by other peer |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
366 transport_data["peer_best_candidate"] = candidate |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
367 log.info(u"Other peer best candidate: {}".format(candidate)) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
368 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
369 del transport_data["candidates"] |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
370 self._checkCandidates(session, content_name, transport_data, client) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
371 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
372 def _proxyActivationInfo( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
373 self, proxy_elt, session, content_name, transport_data, client |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
374 ): |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
375 """Called when proxy has been activated (or has sent an error) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
376 |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
377 @param proxy_elt(domish.Element): <activated/> or <proxy-error/> element |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
378 (see XEP-0260 §2.4) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
379 @param session(dict): session data |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
380 @param content_name(unicode): name of the current content |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
381 @param transport_data(dict): transport data |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
382 @param client(unicode): %(doc_client)s |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
383 """ |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
384 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
385 activation_d = transport_data.pop("activation_d") |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
386 except KeyError: |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
387 log.warning(u"Received unexpected transport-info for proxy activation") |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
388 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
389 if proxy_elt.name == "activated": |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
390 activation_d.callback(None) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
391 else: |
1756
061011fad5b1
plugin XEP-0260: better proxy error handling:
Goffi <goffi@goffi.org>
parents:
1755
diff
changeset
|
392 activation_d.errback(ProxyError()) |
1560 | 393 |
394 @defer.inlineCallbacks | |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
395 def jingleHandler(self, client, action, session, content_name, transport_elt): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
396 content_data = session["contents"][content_name] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
397 transport_data = content_data["transport_data"] |
1560 | 398 |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
399 if action in (self._j.A_ACCEPTED_ACK, self._j.A_PREPARE_RESPONDER): |
1560 | 400 pass |
401 | |
402 elif action == self._j.A_SESSION_ACCEPT: | |
403 # initiator side, we select a candidate in the ones sent by responder | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
404 assert "peer_candidates" not in transport_data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
405 transport_data["peer_candidates"] = self._parseCandidates(transport_elt) |
1560 | 406 |
407 elif action == self._j.A_START: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
408 session_hash = transport_data["session_hash"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
409 peer_candidates = transport_data["peer_candidates"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
410 stream_object = content_data["stream_object"] |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
411 self._s5b.associateStreamObject(client, session_hash, stream_object) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
412 stream_d = transport_data.pop("stream_d") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
413 stream_d.chainDeferred(content_data["finished_d"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
414 peer_session_hash = transport_data["peer_session_hash"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
415 d = self._s5b.getBestCandidate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
416 client, peer_candidates, session_hash, peer_session_hash |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
417 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
418 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
419 self._foundPeerCandidate, session, transport_data, content_name, client |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
420 ) |
1560 | 421 |
422 elif action == self._j.A_SESSION_INITIATE: | |
423 # responder side, we select a candidate in the ones sent by initiator | |
424 # and we give our candidates | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
425 assert "peer_candidates" not in transport_data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
426 sid = transport_data["sid"] = transport_elt["sid"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
427 session_hash = transport_data["session_hash"] = self._s5b.getSessionHash( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
428 client.jid, session["peer_jid"], sid |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
429 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
430 peer_session_hash = transport_data[ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
431 "peer_session_hash" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
432 ] = self._s5b.getSessionHash( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
433 session["peer_jid"], client.jid, sid |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
434 ) # requester and target are inversed for peer candidates |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
435 peer_candidates = transport_data["peer_candidates"] = self._parseCandidates( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
436 transport_elt |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
437 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
438 stream_object = content_data["stream_object"] |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
439 stream_d = self._s5b.registerHash(client, session_hash, stream_object) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
440 stream_d.chainDeferred(content_data["finished_d"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
441 d = self._s5b.getBestCandidate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
442 client, peer_candidates, session_hash, peer_session_hash |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
443 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
444 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
445 self._foundPeerCandidate, session, transport_data, content_name, client |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
446 ) |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
447 candidates = yield self._s5b.getCandidates(client) |
1560 | 448 # we remove duplicate candidates |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
449 candidates = [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
450 candidate for candidate in candidates if candidate not in peer_candidates |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
451 ] |
1560 | 452 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
453 transport_data["candidates"] = candidates |
1560 | 454 # we can now build a new <transport> element with our candidates |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
455 transport_elt = self._buildCandidates( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
456 session, candidates, sid, session_hash, client |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
457 ) |
1560 | 458 |
459 elif action == self._j.A_TRANSPORT_INFO: | |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
460 # transport-info can be about candidate or proxy activation |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
461 candidate_elt = None |
1560 | 462 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
463 for method, names in ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
464 (self._candidateInfo, ("candidate-used", "candidate-error")), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
465 (self._proxyActivationInfo, ("activated", "proxy-error")), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
466 ): |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
467 for name in names: |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
468 try: |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
469 candidate_elt = transport_elt.elements(NS_JINGLE_S5B, name).next() |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
470 except StopIteration: |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
471 continue |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
472 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
473 method( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
474 candidate_elt, session, content_name, transport_data, client |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
475 ) |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
476 break |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
477 |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1567
diff
changeset
|
478 if candidate_elt is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
479 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
480 u"Unexpected transport element: {}".format(transport_elt.toXml()) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
481 ) |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
482 elif action == self._j.A_DESTROY: |
1758
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
483 # the transport is replaced (fallback ?), We need mainly to kill XEP-0065 session. |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
484 # note that sid argument is not necessary for sessions created by this plugin |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
485 self._s5b.killSession(None, transport_data["session_hash"], None, client) |
1560 | 486 else: |
487 log.warning(u"FIXME: unmanaged action {}".format(action)) | |
488 | |
489 defer.returnValue(transport_elt) | |
490 | |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
491 def jingleTerminate(self, client, action, session, content_name, reason_elt): |
1755
d2e023da2983
plugin XEP-0260: kill s5b session if session is declined
Goffi <goffi@goffi.org>
parents:
1631
diff
changeset
|
492 if reason_elt.decline: |
d2e023da2983
plugin XEP-0260: kill s5b session if session is declined
Goffi <goffi@goffi.org>
parents:
1631
diff
changeset
|
493 log.debug(u"Session declined, deleting S5B session") |
d2e023da2983
plugin XEP-0260: kill s5b session if session is declined
Goffi <goffi@goffi.org>
parents:
1631
diff
changeset
|
494 # we just need to clean the S5B session if it is declined |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
495 content_data = session["contents"][content_name] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
496 transport_data = content_data["transport_data"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
497 self._s5b.killSession(None, transport_data["session_hash"], None, client) |
1755
d2e023da2983
plugin XEP-0260: kill s5b session if session is declined
Goffi <goffi@goffi.org>
parents:
1631
diff
changeset
|
498 |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
499 def _doFallback(self, feature_checked, session, content_name, client): |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
500 """Do the fallback, method called once feature is checked |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
501 |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
502 @param feature_checked(bool): True if other peer can do IBB |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
503 """ |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
504 if not feature_checked: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
505 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
506 u"Other peer can't manage jingle IBB, be have to terminate the session" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
507 ) |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
508 self._j.terminate(client, self._j.REASON_CONNECTIVITY_ERROR, session) |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
509 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
510 self._j.transportReplace( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
511 client, self._jingle_ibb.NAMESPACE, session, content_name |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
512 ) |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
513 |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
514 def doFallback(self, session, content_name, client): |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
515 """Fallback to IBB transport, used in last resort |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
516 |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
517 @param session(dict): session data |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
518 @param content_name(unicode): name of the current content |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
519 @param client(unicode): %(doc_client)s |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
520 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
521 if session["role"] != self._j.ROLE_INITIATOR: |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
522 # only initiator must do the fallback, see XEP-0260 §3 |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
523 return |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
524 if self._jingle_ibb is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
525 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
526 u"Jingle IBB (XEP-0261) plugin is not available, we have to close the session" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
527 ) |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
528 self._j.terminate(client, self._j.REASON_CONNECTIVITY_ERROR, session) |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
529 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
530 d = self.host.hasFeature( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
531 client, self._jingle_ibb.NAMESPACE, session["peer_jid"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
532 ) |
1631
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
533 d.addCallback(self._doFallback, session, content_name, client) |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
534 return d |
25906c0dbc63
plugin XEP-0260, XEP-0261: fallback from S5B to IBB is implemented
Goffi <goffi@goffi.org>
parents:
1571
diff
changeset
|
535 |
1560 | 536 |
537 class XEP_0260_handler(XMPPHandler): | |
538 implements(iwokkel.IDisco) | |
539 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
540 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
1560 | 541 return [disco.DiscoFeature(NS_JINGLE_S5B)] |
542 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
543 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
1560 | 544 return [] |