Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0065.py @ 2846:58ea675d0f05
quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
if AUTO_RESYNC is False, frontend must call itself the resync method.
This is useful to improve performance, resynchronising all widgets at once may be resource intensive, and it may be more efficient to resync a widget only when it is visible.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 10 Mar 2019 18:02:42 +0100 |
parents | 003b8b4b56a7 |
children | 69e4716d6268 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1845
diff
changeset
|
1 #!/usr/bin/env python2 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2 # -*- coding: utf-8 -*- |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
3 |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
4 # SAT plugin for managing xep-0065 |
0 | 5 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
6 # Copyright (C) |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
7 # 2002, 2003, 2004 Dave Smith (dizzyd@jabber.org) |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
8 # 2007, 2008 Fabio Forno (xmpp:ff@jabber.bluendo.com) |
2771 | 9 # 2009-2019 Jérôme Poisson (goffi@goffi.org) |
0 | 10 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
11 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
12 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
13 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
14 # (at your option) any later version. |
0 | 15 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
16 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
19 # GNU Affero General Public License for more details. |
0 | 20 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
21 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
22 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 23 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
24 # -- |
0 | 25 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
26 # This module is based on proxy65 (http://code.google.com/p/proxy65), |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
27 # originaly written by David Smith and modified by Fabio Forno. |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
28 # It is sublicensed under AGPL v3 (or any later version) as allowed by the original |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
29 # license. |
0 | 30 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
31 # -- |
0 | 32 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
33 # Here is a copy of the original license: |
0 | 34 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
35 # Copyright (C) |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
36 # 2002-2004 Dave Smith (dizzyd@jabber.org) |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
37 # 2007-2008 Fabio Forno (xmpp:ff@jabber.bluendo.com) |
0 | 38 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
39 # Permission is hereby granted, free of charge, to any person obtaining a copy |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
40 # of this software and associated documentation files (the "Software"), to deal |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
41 # in the Software without restriction, including without limitation the rights |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
42 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
43 # copies of the Software, and to permit persons to whom the Software is |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
44 # furnished to do so, subject to the following conditions: |
0 | 45 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
46 # The above copyright notice and this permission notice shall be included in |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
47 # all copies or substantial portions of the Software. |
0 | 48 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
49 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
50 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
51 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
52 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
53 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
54 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
55 # THE SOFTWARE. |
0 | 56 |
771 | 57 from sat.core.i18n import _ |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
956
diff
changeset
|
58 from sat.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
59 |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
956
diff
changeset
|
60 log = getLogger(__name__) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
61 from sat.core.constants import Const as C |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
62 from sat.core import exceptions |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
63 from sat.tools import sat_defer |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
64 from twisted.internet import protocol |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
65 from twisted.internet import reactor |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
66 from twisted.internet import error as internet_error |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
67 from twisted.words.protocols.jabber import error as jabber_error |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
68 from twisted.words.protocols.jabber import jid |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
69 from twisted.words.protocols.jabber import xmlstream |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
70 from twisted.internet import defer |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
71 from collections import namedtuple |
0 | 72 import struct |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
73 import hashlib |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
74 import uuid |
0 | 75 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
76 from zope.interface import implements |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
77 |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
78 try: |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
79 from twisted.words.protocols.xmlstream import XMPPHandler |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
80 except ImportError: |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
81 from wokkel.subprotocols import XMPPHandler |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
82 |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
83 from wokkel import disco, iwokkel |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
84 |
0 | 85 |
86 PLUGIN_INFO = { | |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
87 C.PI_NAME: "XEP 0065 Plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
88 C.PI_IMPORT_NAME: "XEP-0065", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
89 C.PI_TYPE: "XEP", |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
90 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
|
91 C.PI_PROTOCOLS: ["XEP-0065"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
92 C.PI_DEPENDENCIES: ["IP"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
93 C.PI_RECOMMENDATIONS: ["NAT-PORT"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
94 C.PI_MAIN: "XEP_0065", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
95 C.PI_HANDLER: "yes", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
96 C.PI_DESCRIPTION: _("""Implementation of SOCKS5 Bytestreams"""), |
0 | 97 } |
98 | |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
99 IQ_SET = '/iq[@type="set"]' |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
100 NS_BS = "http://jabber.org/protocol/bytestreams" |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
101 BS_REQUEST = IQ_SET + '/query[@xmlns="' + NS_BS + '"]' |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
102 TIMER_KEY = "timer" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
103 DEFER_KEY = "finished" # key of the deferred used to track session end |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
104 SERVER_STARTING_PORT = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 0 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
106 ) # starting number for server port search (0 to ask automatic attribution) |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
107 |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
108 # priorities are candidates local priorities, must be a int between 0 and 65535 |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
109 PRIORITY_BEST_DIRECT = 10000 |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
110 PRIORITY_DIRECT = 5000 |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
111 PRIORITY_ASSISTED = 1000 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
112 PRIORITY_PROXY = 0.2 # proxy is the last option for s5b |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 CANDIDATE_DELAY = 0.2 # see XEP-0260 §4 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
114 CANDIDATE_DELAY_PROXY = 0.2 # additional time for proxy types (see XEP-0260 §4 note 3) |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
115 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
116 TIMEOUT = 300 # maxium time between session creation and stream start |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
117 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
118 # XXX: by default eveything is automatic |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
119 # TODO: use these params to force use of specific proxy/port/IP |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
120 # PARAMS = """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
121 # <params> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
122 # <general> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
123 # <category name="File Transfer"> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
124 # <param name="Force IP" type="string" /> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
125 # <param name="Force Port" type="int" constraint="1;65535" /> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
126 # </category> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
127 # </general> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
128 # <individual> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
129 # <category name="File Transfer"> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
130 # <param name="Force Proxy" value="" type="string" /> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
131 # <param name="Force Proxy host" value="" type="string" /> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
132 # <param name="Force Proxy port" value="" type="int" constraint="1;65535" /> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
133 # </category> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
134 # </individual> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
135 # </params> |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
136 # """ |
0 | 137 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
138 ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
139 STATE_INITIAL, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
140 STATE_AUTH, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
141 STATE_REQUEST, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
142 STATE_READY, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
143 STATE_AUTH_USERPASS, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
144 STATE_CLIENT_INITIAL, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
145 STATE_CLIENT_AUTH, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
146 STATE_CLIENT_REQUEST, |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
147 ) = xrange(8) |
0 | 148 |
149 SOCKS5_VER = 0x05 | |
150 | |
151 ADDR_IPV4 = 0x01 | |
152 ADDR_DOMAINNAME = 0x03 | |
153 ADDR_IPV6 = 0x04 | |
154 | |
155 CMD_CONNECT = 0x01 | |
156 CMD_BIND = 0x02 | |
157 CMD_UDPASSOC = 0x03 | |
158 | |
159 AUTHMECH_ANON = 0x00 | |
160 AUTHMECH_USERPASS = 0x02 | |
161 AUTHMECH_INVALID = 0xFF | |
162 | |
163 REPLY_SUCCESS = 0x00 | |
164 REPLY_GENERAL_FAILUR = 0x01 | |
165 REPLY_CONN_NOT_ALLOWED = 0x02 | |
166 REPLY_NETWORK_UNREACHABLE = 0x03 | |
167 REPLY_HOST_UNREACHABLE = 0x04 | |
168 REPLY_CONN_REFUSED = 0x05 | |
169 REPLY_TTL_EXPIRED = 0x06 | |
170 REPLY_CMD_NOT_SUPPORTED = 0x07 | |
171 REPLY_ADDR_NOT_SUPPORTED = 0x08 | |
172 | |
173 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
174 ProxyInfos = namedtuple("ProxyInfos", ["host", "jid", "port"]) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
175 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
176 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
177 class Candidate(object): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
178 def __init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
179 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
180 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
181 port, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
182 type_, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
183 priority, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
184 jid_, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
185 id_=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
186 priority_local=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
187 factory=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
188 ): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
189 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
190 @param host(unicode): host IP or domain |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
191 @param port(int): port |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
192 @param type_(unicode): stream type (one of XEP_0065.TYPE_*) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
193 @param priority(int): priority |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
194 @param jid_(jid.JID): jid |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
195 @param id_(None, id_): Candidate ID, or None to generate |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
196 @param priority_local(bool): if True, priority is used as local priority, |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
197 else priority is used as global one (and local priority is set to 0) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
198 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
199 assert isinstance(jid_, jid.JID) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
200 self.host, self.port, self.type, self.jid = (host, int(port), type_, jid_) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
201 self.id = id_ if id_ is not None else unicode(uuid.uuid4()) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
202 if priority_local: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
203 self._local_priority = int(priority) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
204 self._priority = self.calculatePriority() |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
205 else: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
206 self._local_priority = 0 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
207 self._priority = int(priority) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
208 self.factory = factory |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
209 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
210 def discard(self): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
211 """Disconnect a candidate if it is connected |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
212 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
213 Used to disconnect tryed client when they are discarded |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
214 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
215 log.debug(u"Discarding {}".format(self)) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
216 try: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
217 self.factory.discard() |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
218 except AttributeError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
219 pass # no discard for Socks5ServerFactory |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
220 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
221 @property |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
222 def local_priority(self): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
223 return self._local_priority |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
224 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
225 @property |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
226 def priority(self): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
227 return self._priority |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
228 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
229 def __str__(self): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
230 # similar to __unicode__ but we don't show jid and we encode id |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
231 return "Candidate ({0.priority}): host={0.host} port={0.port} type={0.type}{id}".format( |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
232 self, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
233 id=u" id={}".format(self.id if self.id is not None else u"").encode( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
234 "utf-8", "ignore" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
235 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
236 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
237 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
238 def __unicode__(self): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
239 return u"Candidate ({0.priority}): host={0.host} port={0.port} jid={0.jid} type={0.type}{id}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
240 self, id=u" id={}".format(self.id if self.id is not None else u"") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
241 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
242 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
243 def __eq__(self, other): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
244 # self.id is is not used in __eq__ as the same candidate can have |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
245 # different ids if proposed by initiator or responder |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
246 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
247 return ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
248 self.host == other.host |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
249 and self.port == other.port |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
250 and self.jid == other.jid |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
251 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
252 except (AttributeError, TypeError): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
253 return False |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
254 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
255 def __ne__(self, other): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
256 return not self.__eq__(other) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
257 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
258 def calculatePriority(self): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
259 """Calculate candidate priority according to XEP-0260 §2.2 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
260 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
261 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
262 @return (int): priority |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
263 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
264 if self.type == XEP_0065.TYPE_DIRECT: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
265 multiplier = 126 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
266 elif self.type == XEP_0065.TYPE_ASSISTED: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
267 multiplier = 120 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
268 elif self.type == XEP_0065.TYPE_TUNEL: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
269 multiplier = 110 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
270 elif self.type == XEP_0065.TYPE_PROXY: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
271 multiplier = 10 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
272 else: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
273 raise exceptions.InternalError(u"Unknown {} type !".format(self.type)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
274 return 2 ** 16 * multiplier + self._local_priority |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
275 |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
276 def activate(self, sid, peer_jid, client): |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
277 """Activate the proxy candidate |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
278 |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
279 Send activation request as explained in XEP-0065 § 6.3.5 |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
280 Must only be used with proxy candidates |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
281 @param sid(unicode): session id (same as for getSessionHash) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
282 @param peer_jid(jid.JID): jid of the other peer |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
283 @return (D(domish.Element)): IQ result (or error) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
284 """ |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
285 assert self.type == XEP_0065.TYPE_PROXY |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
286 iq_elt = client.IQ() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
287 iq_elt["to"] = self.jid.full() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
288 query_elt = iq_elt.addElement((NS_BS, "query")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
289 query_elt["sid"] = sid |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
290 query_elt.addElement("activate", content=peer_jid.full()) |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
291 return iq_elt.send() |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
292 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
293 def startTransfer(self, session_hash=None): |
1581
8cc7d83141a4
plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
294 if self.type == XEP_0065.TYPE_PROXY: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
295 chunk_size = 4096 # Prosody's proxy reject bigger chunks by default |
1581
8cc7d83141a4
plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
296 else: |
8cc7d83141a4
plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
297 chunk_size = None |
8cc7d83141a4
plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
298 self.factory.startTransfer(session_hash, chunk_size=chunk_size) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
299 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
300 |
1758
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
301 def getSessionHash(requester_jid, target_jid, sid): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
302 """Calculate SHA1 Hash according to XEP-0065 §5.3.2 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
303 |
1758
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
304 @param requester_jid(jid.JID): jid of the requester (the one which activate the proxy) |
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
305 @param target_jid(jid.JID): jid of the target |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
306 @param sid(unicode): session id |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
307 @return (str): hash |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
308 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
309 return hashlib.sha1( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
310 (sid + requester_jid.full() + target_jid.full()).encode("utf-8") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
311 ).hexdigest() |
0 | 312 |
313 | |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
314 class SOCKSv5(protocol.Protocol): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
315 CHUNK_SIZE = 2 ** 16 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
316 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
317 def __init__(self, session_hash=None): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
318 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
319 @param session_hash(str): hash of the session |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
320 must only be used in client mode |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
321 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
322 self.connection = defer.Deferred() # called when connection/auth is done |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
323 if session_hash is not None: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
324 self.server_mode = False |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
325 self._session_hash = session_hash |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
326 self.state = STATE_CLIENT_INITIAL |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
327 else: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
328 self.server_mode = True |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
329 self.state = STATE_INITIAL |
0 | 330 self.buf = "" |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
331 self.supportedAuthMechs = [AUTHMECH_ANON] |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
332 self.supportedAddrs = [ADDR_DOMAINNAME] |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
333 self.enabledCommands = [CMD_CONNECT] |
0 | 334 self.peersock = None |
335 self.addressType = 0 | |
336 self.requestType = 0 | |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
337 self._stream_object = None |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
338 self.active = False # set to True when protocol is actually used for transfer |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
339 # used by factories to know when the finished Deferred can be triggered |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
340 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
341 @property |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
342 def stream_object(self): |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
343 if self._stream_object is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
344 self._stream_object = self.getSession()["stream_object"] |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
345 if self.server_mode: |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
346 self._stream_object.registerProducer(self.transport, True) |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
347 return self._stream_object |
0 | 348 |
1845
2bde6fc7aabd
plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
349 def getSession(self): |
2bde6fc7aabd
plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
350 """Return session associated with this candidate |
2bde6fc7aabd
plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
351 |
2bde6fc7aabd
plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
352 @return (dict): session data |
2bde6fc7aabd
plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
353 """ |
2bde6fc7aabd
plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
354 if self.server_mode: |
2bde6fc7aabd
plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
355 return self.factory.getSession(self._session_hash) |
2bde6fc7aabd
plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
356 else: |
2bde6fc7aabd
plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
357 return self.factory.getSession() |
2bde6fc7aabd
plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
358 |
0 | 359 def _startNegotiation(self): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
360 log.debug("starting negotiation (client mode)") |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
361 self.state = STATE_CLIENT_AUTH |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
362 self.transport.write(struct.pack("!3B", SOCKS5_VER, 1, AUTHMECH_ANON)) |
0 | 363 |
364 def _parseNegotiation(self): | |
365 try: | |
366 # Parse out data | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
367 ver, nmethod = struct.unpack("!BB", self.buf[:2]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
368 methods = struct.unpack("%dB" % nmethod, self.buf[2 : nmethod + 2]) |
0 | 369 |
370 # Ensure version is correct | |
371 if ver != 5: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
372 self.transport.write(struct.pack("!BB", SOCKS5_VER, AUTHMECH_INVALID)) |
0 | 373 self.transport.loseConnection() |
374 return | |
375 | |
376 # Trim off front of the buffer | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
377 self.buf = self.buf[nmethod + 2 :] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
378 |
0 | 379 # Check for supported auth mechs |
380 for m in self.supportedAuthMechs: | |
381 if m in methods: | |
382 # Update internal state, according to selected method | |
383 if m == AUTHMECH_ANON: | |
384 self.state = STATE_REQUEST | |
385 elif m == AUTHMECH_USERPASS: | |
386 self.state = STATE_AUTH_USERPASS | |
387 # Complete negotiation w/ this method | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
388 self.transport.write(struct.pack("!BB", SOCKS5_VER, m)) |
0 | 389 return |
390 | |
391 # No supported mechs found, notify client and close the connection | |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
392 log.warning(u"Unsupported authentication mechanism") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
393 self.transport.write(struct.pack("!BB", SOCKS5_VER, AUTHMECH_INVALID)) |
0 | 394 self.transport.loseConnection() |
395 except struct.error: | |
396 pass | |
397 | |
398 def _parseUserPass(self): | |
399 try: | |
400 # Parse out data | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
401 ver, ulen = struct.unpack("BB", self.buf[:2]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
402 uname, = struct.unpack("%ds" % ulen, self.buf[2 : ulen + 2]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
403 plen, = struct.unpack("B", self.buf[ulen + 2]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
404 password, = struct.unpack("%ds" % plen, self.buf[ulen + 3 : ulen + 3 + plen]) |
0 | 405 # Trim off fron of the buffer |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
406 self.buf = self.buf[3 + ulen + plen :] |
0 | 407 # Fire event to authenticate user |
408 if self.authenticateUserPass(uname, password): | |
409 # Signal success | |
410 self.state = STATE_REQUEST | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
411 self.transport.write(struct.pack("!BB", SOCKS5_VER, 0x00)) |
0 | 412 else: |
413 # Signal failure | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
414 self.transport.write(struct.pack("!BB", SOCKS5_VER, 0x01)) |
0 | 415 self.transport.loseConnection() |
416 except struct.error: | |
417 pass | |
418 | |
419 def sendErrorReply(self, errorcode): | |
420 # Any other address types are not supported | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
421 result = struct.pack("!BBBBIH", SOCKS5_VER, errorcode, 0, 1, 0, 0) |
0 | 422 self.transport.write(result) |
423 self.transport.loseConnection() | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
424 |
0 | 425 def _parseRequest(self): |
426 try: | |
427 # Parse out data and trim buffer accordingly | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
428 ver, cmd, rsvd, self.addressType = struct.unpack("!BBBB", self.buf[:4]) |
0 | 429 |
430 # Ensure we actually support the requested address type | |
431 if self.addressType not in self.supportedAddrs: | |
432 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED) | |
433 return | |
434 | |
435 # Deal with addresses | |
436 if self.addressType == ADDR_IPV4: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
437 addr, port = struct.unpack("!IH", self.buf[4:10]) |
0 | 438 self.buf = self.buf[10:] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
439 elif self.addressType == ADDR_DOMAINNAME: |
0 | 440 nlen = ord(self.buf[4]) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
441 addr, port = struct.unpack("!%dsH" % nlen, self.buf[5:]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
442 self.buf = self.buf[7 + len(addr) :] |
0 | 443 else: |
444 # Any other address types are not supported | |
445 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED) | |
446 return | |
447 | |
448 # Ensure command is supported | |
449 if cmd not in self.enabledCommands: | |
450 # Send a not supported error | |
451 self.sendErrorReply(REPLY_CMD_NOT_SUPPORTED) | |
452 return | |
453 | |
454 # Process the command | |
455 if cmd == CMD_CONNECT: | |
456 self.connectRequested(addr, port) | |
457 elif cmd == CMD_BIND: | |
458 self.bindRequested(addr, port) | |
459 else: | |
460 # Any other command is not supported | |
461 self.sendErrorReply(REPLY_CMD_NOT_SUPPORTED) | |
462 | |
941
c6d8fc63b1db
core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
463 except struct.error: |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
464 # The buffer is probably not complete, we need to wait more |
0 | 465 return None |
466 | |
467 def _makeRequest(self): | |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
468 hash_ = self._session_hash |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
469 request = struct.pack( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
470 "!5B%dsH" % len(hash_), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
471 SOCKS5_VER, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
472 CMD_CONNECT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
473 0, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
474 ADDR_DOMAINNAME, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
475 len(hash_), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
476 hash_, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
477 0, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
478 ) |
0 | 479 self.transport.write(request) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
480 self.state = STATE_CLIENT_REQUEST |
0 | 481 |
482 def _parseRequestReply(self): | |
483 try: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
484 ver, rep, rsvd, self.addressType = struct.unpack("!BBBB", self.buf[:4]) |
0 | 485 # Ensure we actually support the requested address type |
486 if self.addressType not in self.supportedAddrs: | |
487 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED) | |
488 return | |
489 | |
490 # Deal with addresses | |
491 if self.addressType == ADDR_IPV4: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
492 addr, port = struct.unpack("!IH", self.buf[4:10]) |
0 | 493 self.buf = self.buf[10:] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
494 elif self.addressType == ADDR_DOMAINNAME: |
0 | 495 nlen = ord(self.buf[4]) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
496 addr, port = struct.unpack("!%dsH" % nlen, self.buf[5:]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
497 self.buf = self.buf[7 + len(addr) :] |
0 | 498 else: |
499 # Any other address types are not supported | |
500 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED) | |
501 return | |
502 | |
503 # Ensure reply is OK | |
504 if rep != REPLY_SUCCESS: | |
505 self.loseConnection() | |
506 return | |
507 | |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
508 self.state = STATE_READY |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
509 self.connection.callback(None) |
0 | 510 |
941
c6d8fc63b1db
core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
511 except struct.error: |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
512 # The buffer is probably not complete, we need to wait more |
0 | 513 return None |
514 | |
515 def connectionMade(self): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
516 log.debug( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
517 u"Socks5 connectionMade (mode = {})".format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
518 "server" if self.state == STATE_INITIAL else "client" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
519 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
520 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
521 if self.state == STATE_CLIENT_INITIAL: |
0 | 522 self._startNegotiation() |
523 | |
524 def connectRequested(self, addr, port): | |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
525 # Check that this session is expected |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
526 if not self.factory.addToSession(addr, self): |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
527 self.sendErrorReply(REPLY_CONN_REFUSED) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
528 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
529 u"Unexpected connection request received from {host}".format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
530 host=self.transport.getPeer().host |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
531 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
532 ) |
0 | 533 return |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
534 self._session_hash = addr |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
535 self.connectCompleted(addr, 0) |
0 | 536 |
1581
8cc7d83141a4
plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
537 def startTransfer(self, chunk_size): |
8cc7d83141a4
plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
538 """Callback called when the result iq is received |
8cc7d83141a4
plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
539 |
8cc7d83141a4
plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
540 @param chunk_size(None, int): size of the buffer, or None for default |
8cc7d83141a4
plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
541 """ |
1759
81923b3f8b14
plugin XEP-0065: better handling of finished Deferred
Goffi <goffi@goffi.org>
parents:
1758
diff
changeset
|
542 self.active = True |
1581
8cc7d83141a4
plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
543 if chunk_size is not None: |
8cc7d83141a4
plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
544 self.CHUNK_SIZE = chunk_size |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
545 log.debug(u"Starting file transfer") |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
546 d = self.stream_object.startStream(self.transport) |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
547 d.addCallback(self.streamFinished) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
548 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
549 def streamFinished(self, d): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
956
diff
changeset
|
550 log.info(_("File transfer completed, closing connection")) |
0 | 551 self.transport.loseConnection() |
552 | |
553 def connectCompleted(self, remotehost, remoteport): | |
554 if self.addressType == ADDR_IPV4: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
555 result = struct.pack( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
556 "!BBBBIH", SOCKS5_VER, REPLY_SUCCESS, 0, 1, remotehost, remoteport |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
557 ) |
0 | 558 elif self.addressType == ADDR_DOMAINNAME: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
559 result = struct.pack( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
560 "!BBBBB%dsH" % len(remotehost), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
561 SOCKS5_VER, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
562 REPLY_SUCCESS, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
563 0, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
564 ADDR_DOMAINNAME, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
565 len(remotehost), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
566 remotehost, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
567 remoteport, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
568 ) |
0 | 569 self.transport.write(result) |
570 self.state = STATE_READY | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
571 |
0 | 572 def bindRequested(self, addr, port): |
573 pass | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
574 |
0 | 575 def authenticateUserPass(self, user, passwd): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
576 # FIXME: implement authentication and remove the debug printing a password |
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
577 log.debug(u"User/pass: %s/%s" % (user, passwd)) |
0 | 578 return True |
579 | |
580 def dataReceived(self, buf): | |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
581 if self.state == STATE_READY: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
582 # Everything is set, we just have to write the incoming data |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
583 self.stream_object.write(buf) |
1759
81923b3f8b14
plugin XEP-0065: better handling of finished Deferred
Goffi <goffi@goffi.org>
parents:
1758
diff
changeset
|
584 if not self.active: |
81923b3f8b14
plugin XEP-0065: better handling of finished Deferred
Goffi <goffi@goffi.org>
parents:
1758
diff
changeset
|
585 self.active = True |
1845
2bde6fc7aabd
plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
586 self.getSession()[TIMER_KEY].cancel() |
0 | 587 return |
588 | |
589 self.buf = self.buf + buf | |
590 if self.state == STATE_INITIAL: | |
591 self._parseNegotiation() | |
592 if self.state == STATE_AUTH_USERPASS: | |
593 self._parseUserPass() | |
594 if self.state == STATE_REQUEST: | |
595 self._parseRequest() | |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
596 if self.state == STATE_CLIENT_REQUEST: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
597 self._parseRequestReply() |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
598 if self.state == STATE_CLIENT_AUTH: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
599 ver, method = struct.unpack("!BB", buf) |
0 | 600 self.buf = self.buf[2:] |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
601 if ver != SOCKS5_VER or method != AUTHMECH_ANON: |
0 | 602 self.transport.loseConnection() |
603 else: | |
604 self._makeRequest() | |
605 | |
606 def connectionLost(self, reason): | |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
607 log.debug(u"Socks5 connection lost: {}".format(reason.value)) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
608 if self.state != STATE_READY: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
609 self.connection.errback(reason) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
610 if self.server_mode: |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
611 self.factory.removeFromSession(self._session_hash, self, reason) |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
612 |
0 | 613 |
614 class Socks5ServerFactory(protocol.ServerFactory): | |
615 protocol = SOCKSv5 | |
616 | |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
617 def __init__(self, parent): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
618 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
619 @param parent(XEP_0065): XEP_0065 parent instance |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
620 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
621 self.parent = parent |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
622 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
623 def getSession(self, session_hash): |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
624 return self.parent.getSession(None, session_hash) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
625 |
1581
8cc7d83141a4
plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
626 def startTransfer(self, session_hash, chunk_size=None): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
627 session = self.getSession(session_hash) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
628 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
629 protocol = session["protocols"][0] |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
630 except (KeyError, IndexError): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
631 log.error(u"Can't start file transfer, can't find protocol") |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
632 else: |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
633 session[TIMER_KEY].cancel() |
1581
8cc7d83141a4
plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
634 protocol.startTransfer(chunk_size) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
635 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
636 def addToSession(self, session_hash, protocol): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
637 """Check is session_hash is valid, and associate protocol with it |
0 | 638 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
639 the session will be associated to the corresponding candidate |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
640 @param session_hash(str): hash of the session |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
641 @param protocol(SOCKSv5): protocol instance |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
642 @param return(bool): True if hash was valid (i.e. expected), False else |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
643 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
644 try: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
645 session_data = self.getSession(session_hash) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
646 except KeyError: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
647 return False |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
648 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
649 session_data.setdefault("protocols", []).append(protocol) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
650 return True |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
651 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
652 def removeFromSession(self, session_hash, protocol, reason): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
653 """Remove a protocol from session_data |
0 | 654 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
655 There can be several protocol instances while candidates are tried, they |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
656 have removed when candidate connection is closed |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
657 @param session_hash(str): hash of the session |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
658 @param protocol(SOCKSv5): protocol instance |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
659 @param reason(failure.Failure): reason of the removal |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
660 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
661 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
662 protocols = self.getSession(session_hash)["protocols"] |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
663 protocols.remove(protocol) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
664 except (KeyError, ValueError): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
665 log.error(u"Protocol not found in session while it should be there") |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
666 else: |
1759
81923b3f8b14
plugin XEP-0065: better handling of finished Deferred
Goffi <goffi@goffi.org>
parents:
1758
diff
changeset
|
667 if protocol.active: |
81923b3f8b14
plugin XEP-0065: better handling of finished Deferred
Goffi <goffi@goffi.org>
parents:
1758
diff
changeset
|
668 # The active protocol has been removed, session is finished |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
669 if reason.check(internet_error.ConnectionDone): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
670 self.getSession(session_hash)[DEFER_KEY].callback(None) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
671 else: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
672 self.getSession(session_hash)[DEFER_KEY].errback(reason) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
673 |
0 | 674 |
675 class Socks5ClientFactory(protocol.ClientFactory): | |
676 protocol = SOCKSv5 | |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
677 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
678 def __init__(self, client, parent, session, session_hash): |
398 | 679 """Init the Client Factory |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
680 |
1758
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
681 @param session(dict): session data |
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
682 @param session_hash(unicode): hash used for peer_connection |
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
683 hash is the same as hostname computed in XEP-0065 § 5.3.2 #1 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
684 """ |
1758
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
685 self.session = session |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
686 self.session_hash = session_hash |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
687 self.client = client |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
688 self.connection = defer.Deferred() |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
689 self._protocol_instance = None |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
690 self.connector = None |
0 | 691 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
692 def discard(self): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
693 """Disconnect the client |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
694 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
695 Also set a discarded flag, which avoid to call the session Deferred |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
696 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
697 self.connector.disconnect() |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
698 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
699 def getSession(self): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
700 return self.session |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
701 |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
702 def startTransfer(self, __=None, chunk_size=None): |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
703 self.session[TIMER_KEY].cancel() |
1581
8cc7d83141a4
plugin XEP-0065: chunk size optimization: 64Kio is used except for proxy were it is set to 4Kio, to avoid wild disconnection by Prosody's proxy
Goffi <goffi@goffi.org>
parents:
1577
diff
changeset
|
704 self._protocol_instance.startTransfer(chunk_size) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
705 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
706 def clientConnectionFailed(self, connector, reason): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
707 log.debug(u"Connection failed") |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
708 self.connection.errback(reason) |
0 | 709 |
710 def clientConnectionLost(self, connector, reason): | |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
711 log.debug(_(u"Socks 5 client connection lost (reason: %s)") % reason.value) |
1759
81923b3f8b14
plugin XEP-0065: better handling of finished Deferred
Goffi <goffi@goffi.org>
parents:
1758
diff
changeset
|
712 if self._protocol_instance.active: |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
713 # This one was used for the transfer, than mean that |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
714 # the Socks5 session is finished |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
715 if reason.check(internet_error.ConnectionDone): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
716 self.getSession()[DEFER_KEY].callback(None) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
717 else: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
718 self.getSession()[DEFER_KEY].errback(reason) |
1759
81923b3f8b14
plugin XEP-0065: better handling of finished Deferred
Goffi <goffi@goffi.org>
parents:
1758
diff
changeset
|
719 self._protocol_instance = None |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
720 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
721 def buildProtocol(self, addr): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
722 log.debug(("Socks 5 client connection started")) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
723 p = self.protocol(session_hash=self.session_hash) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
724 p.factory = self |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
725 p.connection.chainDeferred(self.connection) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
726 self._protocol_instance = p |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
727 return p |
0 | 728 |
729 | |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
730 class XEP_0065(object): |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
731 NAMESPACE = NS_BS |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
732 TYPE_DIRECT = "direct" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
733 TYPE_ASSISTED = "assisted" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
734 TYPE_TUNEL = "tunel" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
735 TYPE_PROXY = "proxy" |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
736 Candidate = Candidate |
20
fc8c202cda87
refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
737 |
0 | 738 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
956
diff
changeset
|
739 log.info(_("Plugin XEP_0065 initialization")) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
740 self.host = host |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
741 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
742 # session data |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
743 self.hash_clients_map = {} # key: hash of the transfer session, value: session data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
744 self._cache_proxies = {} # key: server jid, value: proxy data |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
745 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
746 # misc data |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
747 self._server_factory = None |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
748 self._external_port = None |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
20
diff
changeset
|
749 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
750 # plugins shortcuts |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
751 self._ip = self.host.plugins["IP"] |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
752 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
753 self._np = self.host.plugins["NAT-PORT"] |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
754 except KeyError: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
755 log.debug(u"NAT Port plugin not available") |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
756 self._np = None |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
757 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
758 # parameters |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
759 # XXX: params are not used for now, but they may be used in the futur to force proxy/IP |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
760 # host.memory.updateParams(PARAMS) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
761 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
762 def getHandler(self, client): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
763 return XEP_0065_handler(self) |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
764 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
765 def profileConnected(self, client): |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
766 client.xep_0065_sid_session = {} # key: stream_id, value: session_data(dict) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
767 client._s5b_sessions = {} |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
768 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
769 def getSessionHash(self, from_jid, to_jid, sid): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
770 return getSessionHash(from_jid, to_jid, sid) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
771 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
772 def getSocks5ServerFactory(self): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
773 """Return server factory |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
774 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
775 The server is created if it doesn't exists yet |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
776 self._server_factory_port is set on server creation |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
777 """ |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
778 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
779 if self._server_factory is None: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
780 self._server_factory = Socks5ServerFactory(self) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
781 for port in xrange(SERVER_STARTING_PORT, 65356): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
782 try: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
783 listening_port = reactor.listenTCP(port, self._server_factory) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
784 except internet_error.CannotListenError as e: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
785 log.debug( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
786 u"Cannot listen on port {port}: {err_msg}{err_num}".format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
787 port=port, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
788 err_msg=e.socketError.strerror, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
789 err_num=u" (error code: {})".format(e.socketError.errno), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
790 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
791 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
792 else: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
793 self._server_factory_port = listening_port.getHost().port |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
794 break |
0 | 795 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
796 log.info( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
797 _("Socks5 Stream server launched on port {}").format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
798 self._server_factory_port |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
799 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
800 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
801 return self._server_factory |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
802 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
803 @defer.inlineCallbacks |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
804 def getProxy(self, client): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
805 """Return the proxy available for this profile |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
806 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
807 cache is used between clients using the same server |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
808 @return ((D)(ProxyInfos, None)): Found proxy infos, |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
809 or None if not acceptable proxy is found |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
810 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
811 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
812 def notFound(server): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
813 log.info(u"No proxy found on this server") |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
814 self._cache_proxies[server] = None |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
815 defer.returnValue(None) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
816 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
817 server = client.jid.host |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
818 try: |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
819 defer.returnValue(self._cache_proxies[server]) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
820 except KeyError: |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
821 pass |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
822 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
823 proxy = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
824 yield self.host.findServiceEntities(client, "proxy", "bytestreams") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
825 ).pop() |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
826 except (defer.CancelledError, StopIteration, KeyError): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
827 notFound(server) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
828 iq_elt = client.IQ("get") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
829 iq_elt["to"] = proxy.full() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
830 iq_elt.addElement((NS_BS, "query")) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
831 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
832 try: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
833 result_elt = yield iq_elt.send() |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
834 except jabber_error.StanzaError as failure: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
835 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
836 u"Error while requesting proxy info on {jid}: {error}".format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
837 proxy.full(), failure |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
838 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
839 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
840 notFound(server) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
841 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
842 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
843 query_elt = result_elt.elements(NS_BS, "query").next() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
844 streamhost_elt = query_elt.elements(NS_BS, "streamhost").next() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
845 host = streamhost_elt["host"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
846 jid_ = streamhost_elt["jid"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
847 port = streamhost_elt["port"] |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
848 if not all((host, jid, port)): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
849 raise KeyError |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
850 jid_ = jid.JID(jid_) |
1742
244a605623d6
complete the Exception's list when catching JID error:
souliane <souliane@mailoo.org>
parents:
1675
diff
changeset
|
851 except (StopIteration, KeyError, RuntimeError, jid.InvalidFormat, AttributeError): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
852 log.warning(u"Invalid proxy data received from {}".format(proxy.full())) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
853 notFound(server) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
854 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
855 proxy_infos = self._cache_proxies[server] = ProxyInfos(host, jid_, port) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
856 log.info(u"Proxy found: {}".format(proxy_infos)) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
857 defer.returnValue(proxy_infos) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
858 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
859 @defer.inlineCallbacks |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
860 def _getNetworkData(self, client): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
861 """Retrieve information about network |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
862 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
863 @param client: %(doc_client)s |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
864 @return (D(tuple[local_port, external_port, local_ips, external_ip])): network data |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
865 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
866 self.getSocks5ServerFactory() |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
867 local_port = self._server_factory_port |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
868 external_ip = yield self._ip.getExternalIP(client) |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
869 local_ips = yield self._ip.getLocalIPs(client) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
870 |
1576
d5f59ba166fe
plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
871 if external_ip is not None and self._external_port is None: |
d5f59ba166fe
plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
872 if external_ip != local_ips[0]: |
d5f59ba166fe
plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
873 log.info(u"We are probably behind a NAT") |
d5f59ba166fe
plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
874 if self._np is None: |
d5f59ba166fe
plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
875 log.warning(u"NAT port plugin not available, we can't map port") |
d5f59ba166fe
plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
876 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
877 ext_port = yield self._np.mapPort( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
878 local_port, desc=u"SaT socks5 stream" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
879 ) |
1576
d5f59ba166fe
plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
880 if ext_port is None: |
d5f59ba166fe
plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
881 log.warning(u"Can't map NAT port") |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
882 else: |
1576
d5f59ba166fe
plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
883 self._external_port = ext_port |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
884 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
885 defer.returnValue((local_port, self._external_port, local_ips, external_ip)) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
886 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
887 @defer.inlineCallbacks |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
888 def getCandidates(self, client): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
889 """Return a list of our stream candidates |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
890 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
891 @return (D(list[Candidate])): list of candidates, ordered by priority |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
892 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
893 server_factory = yield self.getSocks5ServerFactory() |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
894 local_port, ext_port, local_ips, external_ip = yield self._getNetworkData(client) |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
895 proxy = yield self.getProxy(client) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
896 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
897 # its time to gather the candidates |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
898 candidates = [] |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
899 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
900 # first the direct ones |
1576
d5f59ba166fe
plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
901 |
d5f59ba166fe
plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
902 # the preferred direct connection |
d5f59ba166fe
plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
903 ip = local_ips.pop(0) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
904 candidates.append( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
905 Candidate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
906 ip, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
907 local_port, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
908 XEP_0065.TYPE_DIRECT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
909 PRIORITY_BEST_DIRECT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
910 client.jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
911 priority_local=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
912 factory=server_factory, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
913 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
914 ) |
1576
d5f59ba166fe
plugins IP: getLocalIPs now return localhost IP instead of an empty list if no non-localhost ip can be found
Goffi <goffi@goffi.org>
parents:
1570
diff
changeset
|
915 for ip in local_ips: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
916 candidates.append( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
917 Candidate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
918 ip, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
919 local_port, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
920 XEP_0065.TYPE_DIRECT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
921 PRIORITY_DIRECT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
922 client.jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
923 priority_local=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
924 factory=server_factory, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
925 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
926 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
927 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
928 # then the assisted one |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
929 if ext_port is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
930 candidates.append( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
931 Candidate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
932 external_ip, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
933 ext_port, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
934 XEP_0065.TYPE_ASSISTED, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
935 PRIORITY_ASSISTED, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
936 client.jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
937 priority_local=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
938 factory=server_factory, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
939 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
940 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
941 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
942 # finally the proxy |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
943 if proxy: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
944 candidates.append( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
945 Candidate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
946 proxy.host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
947 proxy.port, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
948 XEP_0065.TYPE_PROXY, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
949 PRIORITY_PROXY, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
950 proxy.jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
951 priority_local=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
952 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
953 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
954 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
955 # should be already sorted, but just in case the priorities get weird |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
956 candidates.sort(key=lambda c: c.priority, reverse=True) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
957 defer.returnValue(candidates) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
958 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
959 def _addConnector(self, connector, candidate): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
960 """Add connector used to connect to candidate, and return client factory's connection Deferred |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
961 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
962 the connector can be used to disconnect the candidate, and returning the factory's connection Deferred allow to wait for connection completion |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
963 @param connector: a connector implementing IConnector |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
964 @param candidate(Candidate): candidate linked to the connector |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
965 @return (D): Deferred fired when factory connection is done or has failed |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
966 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
967 candidate.factory.connector = connector |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
968 return candidate.factory.connection |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
969 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
970 def connectCandidate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
971 self, client, candidate, session_hash, peer_session_hash=None, delay=None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
972 ): |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
973 """Connect to a candidate |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
974 |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
975 Connection will be done with a Socks5ClientFactory |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
976 @param candidate(Candidate): candidate to connect to |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
977 @param session_hash(unicode): hash of the session |
1758
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
978 hash is the same as hostname computed in XEP-0065 § 5.3.2 #1 |
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
979 @param peer_session_hash(unicode, None): hash used with the peer |
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
980 None to use session_hash. |
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
981 None must be used in 2 cases: |
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
982 - when XEP-0065 is used with XEP-0096 |
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
983 - when a peer connect to a proxy *he proposed himself* |
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
984 in practice, peer_session_hash is only used by tryCandidates |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
985 @param delay(None, float): optional delay to wait before connection, in seconds |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
986 @return (D): Deferred launched when TCP connection + Socks5 connection is done |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
987 """ |
1758
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
988 if peer_session_hash is None: |
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
989 # for XEP-0065, only one hash is needed |
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
990 peer_session_hash = session_hash |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
991 session = self.getSession(client, session_hash) |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
992 factory = Socks5ClientFactory(client, self, session, peer_session_hash) |
1570
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
993 candidate.factory = factory |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
994 if delay is None: |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
995 d = defer.succeed(candidate.host) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
996 else: |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
997 d = sat_defer.DelayedDeferred(delay, candidate.host) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
998 d.addCallback(reactor.connectTCP, candidate.port, factory) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
999 d.addCallback(self._addConnector, candidate) |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
1000 return d |
37d4be4a9fed
plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents:
1569
diff
changeset
|
1001 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1002 def tryCandidates( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1003 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1004 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1005 candidates, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1006 session_hash, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1007 peer_session_hash, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1008 connection_cb=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1009 connection_eb=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1010 ): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1011 defers_list = [] |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1012 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1013 for candidate in candidates: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1014 delay = CANDIDATE_DELAY * len(defers_list) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1015 if candidate.type == XEP_0065.TYPE_PROXY: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1016 delay += CANDIDATE_DELAY_PROXY |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1017 d = self.connectCandidate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1018 client, candidate, session_hash, peer_session_hash, delay |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1019 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1020 if connection_cb is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1021 d.addCallback( |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1022 lambda __, candidate=candidate, client=client: connection_cb( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1023 client, candidate |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1024 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1025 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1026 if connection_eb is not None: |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1027 d.addErrback(connection_eb, client, candidate) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1028 defers_list.append(d) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1029 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1030 return defers_list |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1031 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1032 def getBestCandidate(self, client, candidates, session_hash, peer_session_hash=None): |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1033 """Get best candidate (according to priority) which can connect |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1034 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1035 @param candidates(iterable[Candidate]): candidates to test |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1036 @param session_hash(unicode): hash of the session |
1758
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
1037 hash is the same as hostname computed in XEP-0065 § 5.3.2 #1 |
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
1038 @param peer_session_hash(unicode, None): hash of the other peer |
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
1039 only useful for XEP-0260, must be None for XEP-0065 streamhost candidates |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1040 @return (D(None, Candidate)): best candidate or None if none can connect |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1041 """ |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1042 defer_candidates = None |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1043 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1044 def connectionCb(client, candidate): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1045 log.info(u"Connection of {} successful".format(unicode(candidate))) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1046 for idx, other_candidate in enumerate(candidates): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1047 try: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1048 if other_candidate.priority < candidate.priority: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1049 log.debug(u"Cancelling {}".format(other_candidate)) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1050 defer_candidates[idx].cancel() |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1051 except AttributeError: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1052 assert other_candidate is None |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1053 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1054 def connectionEb(failure, client, candidate): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1055 if failure.check(defer.CancelledError): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1056 log.debug(u"Connection of {} has been cancelled".format(candidate)) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1057 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1058 log.info( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1059 u"Connection of {candidate} Failed: {error}".format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1060 candidate=candidate, error=failure.value |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1061 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1062 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1063 candidates[candidates.index(candidate)] = None |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1064 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1065 def allTested(self): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1066 log.debug(u"All candidates have been tested") |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1067 good_candidates = [c for c in candidates if c] |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1068 return good_candidates[0] if good_candidates else None |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1069 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1070 defer_candidates = self.tryCandidates( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1071 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1072 candidates, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1073 session_hash, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1074 peer_session_hash, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1075 connectionCb, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1076 connectionEb, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1077 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1078 d_list = defer.DeferredList(defer_candidates) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1079 d_list.addCallback(allTested) |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1080 return d_list |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1081 |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1082 def _timeOut(self, session_hash, client): |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1083 """Called when stream was not started quickly enough |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1084 |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1085 @param session_hash(str): hash as returned by getSessionHash |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1086 @param client: %(doc_client)s |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1087 """ |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1088 log.info(u"Socks5 Bytestream: TimeOut reached") |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1089 session = self.getSession(client, session_hash) |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1090 session[DEFER_KEY].errback(exceptions.TimeOutError) |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1091 |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
1092 def killSession(self, failure_, session_hash, sid, client): |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1093 """Clean the current session |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
1094 |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1095 @param session_hash(str): hash as returned by getSessionHash |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1096 @param sid(None, unicode): session id |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1097 or None if self.xep_0065_sid_session was not used |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1098 @param client: %(doc_client)s |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
1099 @param failure_(None, failure.Failure): None if eveything was fine, a failure else |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
1100 @return (None, failure.Failure): failure_ is returned |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1101 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1102 log.debug( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1103 u"Cleaning session with hash {hash}{id}: {reason}".format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1104 hash=session_hash, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1105 reason="" if failure_ is None else failure_.value, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1106 id="" if sid is None else u" (id: {})".format(sid), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1107 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1108 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1109 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1110 try: |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1111 assert self.hash_clients_map[session_hash] == client |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1112 del self.hash_clients_map[session_hash] |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1113 except KeyError: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1114 pass |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1115 |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1116 if sid is not None: |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1117 try: |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1118 del client.xep_0065_sid_session[sid] |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1119 except KeyError: |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1120 log.warning(u"Session id {} is unknown".format(sid)) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
1121 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1122 try: |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1123 session_data = client._s5b_sessions[session_hash] |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1124 except KeyError: |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1125 log.warning(u"There is no session with this hash") |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1126 return |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1127 else: |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1128 del client._s5b_sessions[session_hash] |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1129 |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1130 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1131 session_data["timer"].cancel() |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1132 except (internet_error.AlreadyCalled, internet_error.AlreadyCancelled): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1133 pass |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1134 |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
1135 return failure_ |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1136 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1137 def startStream(self, client, stream_object, to_jid, sid): |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1138 """Launch the stream workflow |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1139 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1140 @param streamProducer: stream_object to use |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1141 @param to_jid: JID of the recipient |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1142 @param sid: Stream session id |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1143 @param successCb: method to call when stream successfuly finished |
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1144 @param failureCb: method to call when something goes wrong |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1145 @return (D): Deferred fired when session is finished |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1146 """ |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1147 session_data = self._createSession(client, stream_object, to_jid, sid, True) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1148 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1149 session_data[client] = client |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1150 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1151 def gotCandidates(candidates): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1152 session_data["candidates"] = candidates |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1153 iq_elt = client.IQ() |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1154 iq_elt["from"] = client.jid.full() |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1155 iq_elt["to"] = to_jid.full() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1156 query_elt = iq_elt.addElement((NS_BS, "query")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1157 query_elt["mode"] = "tcp" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1158 query_elt["sid"] = sid |
398 | 1159 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1160 for candidate in candidates: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1161 streamhost = query_elt.addElement("streamhost") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1162 streamhost["host"] = candidate.host |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1163 streamhost["port"] = str(candidate.port) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1164 streamhost["jid"] = candidate.jid.full() |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1165 log.debug(u"Candidate proposed: {}".format(candidate)) |
398 | 1166 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1167 d = iq_elt.send() |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1168 args = [session_data, client] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1169 d.addCallbacks(self._IQNegotiationCb, self._IQNegotiationEb, args, None, args) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1170 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1171 self.getCandidates(client).addCallback(gotCandidates) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1172 return session_data[DEFER_KEY] |
0 | 1173 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1174 def _IQNegotiationCb(self, iq_elt, session_data, client): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1175 """Called when the result of open iq is received |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1176 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1177 @param session_data(dict): data of the session |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1178 @param client: %(doc_client)s |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1179 @param iq_elt(domish.Element): <iq> result |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1180 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1181 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1182 query_elt = iq_elt.elements(NS_BS, "query").next() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1183 streamhost_used_elt = query_elt.elements(NS_BS, "streamhost-used").next() |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1184 except StopIteration: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1185 log.warning(u"No streamhost found in stream query") |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1186 # FIXME: must clean session |
398 | 1187 return |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1188 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1189 streamhost_jid = jid.JID(streamhost_used_elt["jid"]) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1190 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1191 candidate = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1192 c for c in session_data["candidates"] if c.jid == streamhost_jid |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1193 ).next() |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1194 except StopIteration: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1195 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1196 u"Candidate [{jid}] is unknown !".format(jid=streamhost_jid.full()) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1197 ) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1198 return |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1199 else: |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1200 log.info(u"Candidate choosed by target: {}".format(candidate)) |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1201 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1202 if candidate.type == XEP_0065.TYPE_PROXY: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1203 log.info(u"A Socks5 proxy is used") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1204 d = self.connectCandidate(client, candidate, session_data["hash"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1205 d.addCallback( |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1206 lambda __: candidate.activate( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1207 session_data["id"], session_data["peer_jid"], client |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1208 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1209 ) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1210 d.addErrback(self._activationEb) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1211 else: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1212 d = defer.succeed(None) |
398 | 1213 |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1214 d.addCallback(lambda __: candidate.startTransfer(session_data["hash"])) |
398 | 1215 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1216 def _activationEb(self, failure): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1217 log.warning(u"Proxy activation error: {}".format(failure.value)) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1218 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1219 def _IQNegotiationEb(self, stanza_err, session_data, client): |
1583
d46aae87c03a
plugins XEP-0047, XEP-0065, XEP-0096: fixed use of failure.condition insteand of failure.value + removed gettext use for local logs
Goffi <goffi@goffi.org>
parents:
1581
diff
changeset
|
1220 log.warning(u"Socks5 transfer failed: {}".format(stanza_err.value)) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1221 # FIXME: must clean session |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1222 |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1223 def createSession(self, *args, **kwargs): |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1224 """like [_createSession] but return the session deferred instead of the whole session |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1225 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1226 session deferred is fired when transfer is finished |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1227 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1228 return self._createSession(*args, **kwargs)[DEFER_KEY] |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1229 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1230 def _createSession(self, client, stream_object, to_jid, sid, requester=False): |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1231 """Called when a bytestream is imminent |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1232 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1233 @param stream_object(iface.IStreamProducer): File object where data will be written |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1234 @param to_jid(jid.JId): jid of the other peer |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1235 @param sid(unicode): session id |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1236 @param initiator(bool): if True, this session is create by initiator |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1237 @return (dict): session data |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1238 """ |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1239 if sid in client.xep_0065_sid_session: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1240 raise exceptions.ConflictError(u"A session with this id already exists !") |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1241 if requester: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1242 session_hash = getSessionHash(client.jid, to_jid, sid) |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1243 session_data = self._registerHash(client, session_hash, stream_object) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1244 else: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1245 session_hash = getSessionHash(to_jid, client.jid, sid) |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1246 session_d = defer.Deferred() |
1629
a34d7f621944
plugin XEP-0065: renamed _killSession to killSession as it make sense to kill a session from an other plugin
Goffi <goffi@goffi.org>
parents:
1584
diff
changeset
|
1247 session_d.addBoth(self.killSession, session_hash, sid, client) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1248 session_data = client._s5b_sessions[session_hash] = { |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1249 DEFER_KEY: session_d, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1250 TIMER_KEY: reactor.callLater( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1251 TIMEOUT, self._timeOut, session_hash, client |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1252 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1253 } |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1254 client.xep_0065_sid_session[sid] = session_data |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1255 session_data.update( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1256 { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1257 "id": sid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1258 "peer_jid": to_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1259 "stream_object": stream_object, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1260 "hash": session_hash, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1261 } |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1262 ) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1263 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1264 return session_data |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1265 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1266 def getSession(self, client, session_hash): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1267 """Return session data |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1268 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1269 @param session_hash(unicode): hash of the session |
1758
a66d34353f34
plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents:
1757
diff
changeset
|
1270 hash is the same as hostname computed in XEP-0065 § 5.3.2 #1 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1271 @param client(None, SatXMPPClient): client of the peer |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1272 None is used only if client is unknown (this is only the case |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1273 for incoming request received by Socks5ServerFactory). None must |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1274 only be used by Socks5ServerFactory. |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1275 See comments below for details |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1276 @return (dict): session data |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1277 """ |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1278 if client is None: |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1279 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1280 client = self.hash_clients_map[session_hash] |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1281 except KeyError as e: |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1282 log.warning(u"The requested session doesn't exists !") |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1283 raise e |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1284 return client._s5b_sessions[session_hash] |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1285 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1286 def registerHash(self, *args, **kwargs): |
1845
2bde6fc7aabd
plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1287 """like [_registerHash] but return the session deferred instead of the whole session |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1288 session deferred is fired when transfer is finished |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1289 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1290 return self._registerHash(*args, **kwargs)[DEFER_KEY] |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1291 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1292 def _registerHash(self, client, session_hash, stream_object): |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1293 """Create a session_data associated to hash |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1294 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1295 @param session_hash(str): hash of the session |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1296 @param stream_object(iface.IStreamProducer, IConsumer, None): file-like object |
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:
1742
diff
changeset
|
1297 None if it will be filled later |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1298 return (dict): session data |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1299 """ |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1300 assert session_hash not in client._s5b_sessions |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1301 session_d = defer.Deferred() |
1629
a34d7f621944
plugin XEP-0065: renamed _killSession to killSession as it make sense to kill a session from an other plugin
Goffi <goffi@goffi.org>
parents:
1584
diff
changeset
|
1302 session_d.addBoth(self.killSession, session_hash, None, client) |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1303 session_data = client._s5b_sessions[session_hash] = { |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1304 DEFER_KEY: session_d, |
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1305 TIMER_KEY: reactor.callLater(TIMEOUT, self._timeOut, session_hash, client), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1306 } |
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:
1742
diff
changeset
|
1307 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1308 if stream_object is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1309 session_data["stream_object"] = stream_object |
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:
1742
diff
changeset
|
1310 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1311 assert session_hash not in self.hash_clients_map |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1312 self.hash_clients_map[session_hash] = client |
1559
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1313 |
7cc29634b6ef
plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
1314 return session_data |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
1315 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1316 def associateStreamObject(self, client, session_hash, stream_object): |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1317 """Associate a stream object with a session""" |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1318 session_data = self.getSession(client, session_hash) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1319 assert "stream_object" not in session_data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1320 session_data["stream_object"] = stream_object |
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:
1742
diff
changeset
|
1321 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
1322 def streamQuery(self, iq_elt, client): |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1323 log.debug(u"BS stream query") |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
1324 |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1325 iq_elt.handled = True |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
1326 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1327 query_elt = iq_elt.elements(NS_BS, "query").next() |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1328 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1329 sid = query_elt["sid"] |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1330 except KeyError: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1331 log.warning(u"Invalid bystreams request received") |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1332 return client.sendError(iq_elt, "bad-request") |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1333 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1334 streamhost_elts = list(query_elt.elements(NS_BS, "streamhost")) |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1335 if not streamhost_elts: |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1336 return client.sendError(iq_elt, "bad-request") |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1337 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1338 try: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1339 session_data = client.xep_0065_sid_session[sid] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1340 except KeyError: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1341 log.warning(u"Ignoring unexpected BS transfer: {}".format(sid)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1342 return client.sendError(iq_elt, "not-acceptable") |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1343 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1344 peer_jid = session_data["peer_jid"] = jid.JID(iq_elt["from"]) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
1345 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1346 candidates = [] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1347 nb_sh = len(streamhost_elts) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1348 for idx, sh_elt in enumerate(streamhost_elts): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1349 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1350 host, port, jid_ = sh_elt["host"], sh_elt["port"], jid.JID(sh_elt["jid"]) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1351 except KeyError: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1352 log.warning(u"malformed streamhost element") |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1353 return client.sendError(iq_elt, "bad-request") |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1354 priority = nb_sh - idx |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1355 if jid_.userhostJID() != peer_jid.userhostJID(): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1356 type_ = XEP_0065.TYPE_PROXY |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1357 else: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1358 type_ = XEP_0065.TYPE_DIRECT |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1359 candidates.append(Candidate(host, port, type_, priority, jid_)) |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1360 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1361 for candidate in candidates: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1362 log.info(u"Candidate proposed: {}".format(candidate)) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1363 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1364 d = self.getBestCandidate(client, candidates, session_data["hash"]) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1365 d.addCallback(self._ackStream, iq_elt, session_data, client) |
394
8f3551ceee17
plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
1366 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1367 def _ackStream(self, candidate, iq_elt, session_data, client): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1368 if candidate is None: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1576
diff
changeset
|
1369 log.info("No streamhost candidate worked, we have to end negotiation") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1370 return client.sendError(iq_elt, "item-not-found") |
1584
b57b4683dc33
plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents:
1583
diff
changeset
|
1371 log.info(u"We choose: {}".format(candidate)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1372 result_elt = xmlstream.toResponse(iq_elt, "result") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1373 query_elt = result_elt.addElement((NS_BS, "query")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1374 query_elt["sid"] = session_data["id"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1375 streamhost_used_elt = query_elt.addElement("streamhost-used") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1376 streamhost_used_elt["jid"] = candidate.jid.full() |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
1377 client.send(result_elt) |
0 | 1378 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1379 |
64 | 1380 class XEP_0065_handler(XMPPHandler): |
1381 implements(iwokkel.IDisco) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
1382 |
64 | 1383 def __init__(self, plugin_parent): |
1384 self.plugin_parent = plugin_parent | |
1385 self.host = plugin_parent.host | |
398 | 1386 |
64 | 1387 def connectionInitialized(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1388 self.xmlstream.addObserver( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1389 BS_REQUEST, self.plugin_parent.streamQuery, client=self.parent |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1390 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
1391 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1392 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
64 | 1393 return [disco.DiscoFeature(NS_BS)] |
1394 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1395 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
64 | 1396 return [] |