Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0260.py @ 2927:69e4716d6268
plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
while client.jid is fine in a client context, for components it's not the right jid to use: it is the jid of the component itself while the file transfer/jingle session entity may be established with this jid + a local part (e.g. if client is files.example.net, session may be established with louise@files.example.net, in which case "from" is louise@files.example.net, while client.jid will be files.example.net).
As a consequence, using client.jid was causing trouble with components.
This patch fixes it for jingle and plugins linked to file transfer by keeping a "local_jid" variable in the session, where the jid from the original "from" attribute is used.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 28 Apr 2019 08:55:13 +0200 |
parents | 003b8b4b56a7 |
children | ab2696e34d29 |
comparison
equal
deleted
inserted
replaced
2926:4cd7545c4ebb | 2927:69e4716d6268 |
---|---|
138 def jingleSessionInit(self, client, session, content_name): | 138 def jingleSessionInit(self, client, session, content_name): |
139 content_data = session["contents"][content_name] | 139 content_data = session["contents"][content_name] |
140 transport_data = content_data["transport_data"] | 140 transport_data = content_data["transport_data"] |
141 sid = transport_data["sid"] = unicode(uuid.uuid4()) | 141 sid = transport_data["sid"] = unicode(uuid.uuid4()) |
142 session_hash = transport_data["session_hash"] = self._s5b.getSessionHash( | 142 session_hash = transport_data["session_hash"] = self._s5b.getSessionHash( |
143 client.jid, session["peer_jid"], sid | 143 session[u"local_jid"], session["peer_jid"], sid |
144 ) | 144 ) |
145 transport_data["peer_session_hash"] = self._s5b.getSessionHash( | 145 transport_data["peer_session_hash"] = self._s5b.getSessionHash( |
146 session["peer_jid"], client.jid, sid | 146 session["peer_jid"], session[u"local_jid"], sid |
147 ) # requester and target are inversed for peer candidates | 147 ) # requester and target are inversed for peer candidates |
148 transport_data["stream_d"] = self._s5b.registerHash(client, session_hash, None) | 148 transport_data["stream_d"] = self._s5b.registerHash(client, session_hash, None) |
149 candidates = transport_data["candidates"] = yield self._s5b.getCandidates(client) | 149 candidates = transport_data["candidates"] = yield self._s5b.getCandidates( |
150 client, session["local_jid"]) | |
150 mode = "tcp" # XXX: we only manage tcp for now | 151 mode = "tcp" # XXX: we only manage tcp for now |
151 transport_elt = self._buildCandidates( | 152 transport_elt = self._buildCandidates( |
152 session, candidates, sid, session_hash, client, mode | 153 session, candidates, sid, session_hash, client, mode |
153 ) | 154 ) |
154 | 155 |
247 if best_candidate.priority == peer_best_candidate.priority: | 248 if best_candidate.priority == peer_best_candidate.priority: |
248 # same priority, we choose initiator one according to XEP-0260 §2.4 #4 | 249 # same priority, we choose initiator one according to XEP-0260 §2.4 #4 |
249 log.debug( | 250 log.debug( |
250 u"Candidates have same priority, we select the one choosed by initiator" | 251 u"Candidates have same priority, we select the one choosed by initiator" |
251 ) | 252 ) |
252 if session["initiator"] == client.jid: | 253 if session["initiator"] == session[u"local_jid"]: |
253 choosed_candidate = best_candidate | 254 choosed_candidate = best_candidate |
254 else: | 255 else: |
255 choosed_candidate = peer_best_candidate | 256 choosed_candidate = peer_best_candidate |
256 else: | 257 else: |
257 choosed_candidate = max( | 258 choosed_candidate = max( |
423 # responder side, we select a candidate in the ones sent by initiator | 424 # responder side, we select a candidate in the ones sent by initiator |
424 # and we give our candidates | 425 # and we give our candidates |
425 assert "peer_candidates" not in transport_data | 426 assert "peer_candidates" not in transport_data |
426 sid = transport_data["sid"] = transport_elt["sid"] | 427 sid = transport_data["sid"] = transport_elt["sid"] |
427 session_hash = transport_data["session_hash"] = self._s5b.getSessionHash( | 428 session_hash = transport_data["session_hash"] = self._s5b.getSessionHash( |
428 client.jid, session["peer_jid"], sid | 429 session["local_jid"], session["peer_jid"], sid |
429 ) | 430 ) |
430 peer_session_hash = transport_data[ | 431 peer_session_hash = transport_data[ |
431 "peer_session_hash" | 432 "peer_session_hash" |
432 ] = self._s5b.getSessionHash( | 433 ] = self._s5b.getSessionHash( |
433 session["peer_jid"], client.jid, sid | 434 session["peer_jid"], session["local_jid"], sid |
434 ) # requester and target are inversed for peer candidates | 435 ) # requester and target are inversed for peer candidates |
435 peer_candidates = transport_data["peer_candidates"] = self._parseCandidates( | 436 peer_candidates = transport_data["peer_candidates"] = self._parseCandidates( |
436 transport_elt | 437 transport_elt |
437 ) | 438 ) |
438 stream_object = content_data["stream_object"] | 439 stream_object = content_data["stream_object"] |
442 client, peer_candidates, session_hash, peer_session_hash | 443 client, peer_candidates, session_hash, peer_session_hash |
443 ) | 444 ) |
444 d.addCallback( | 445 d.addCallback( |
445 self._foundPeerCandidate, session, transport_data, content_name, client | 446 self._foundPeerCandidate, session, transport_data, content_name, client |
446 ) | 447 ) |
447 candidates = yield self._s5b.getCandidates(client) | 448 candidates = yield self._s5b.getCandidates(client, session["local_jid"]) |
448 # we remove duplicate candidates | 449 # we remove duplicate candidates |
449 candidates = [ | 450 candidates = [ |
450 candidate for candidate in candidates if candidate not in peer_candidates | 451 candidate for candidate in candidates if candidate not in peer_candidates |
451 ] | 452 ] |
452 | 453 |