annotate src/plugins/plugin_xep_0260.py @ 2221:a6c9bc4d1de0

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