annotate sat/plugins/plugin_xep_0065.py @ 3033:0d55a52056f7

tools (async_process): log command as str
author Goffi <goffi@goffi.org>
date Fri, 16 Aug 2019 17:06:51 +0200
parents ab2696e34d29
children fee60f17ebac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1 #!/usr/bin/env python3
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
goffi@necton2
parents:
diff changeset
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
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2765
diff changeset
9 # 2009-2019 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
23
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
24 # --
0
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
30
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
31 # --
0
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
56
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 742
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
75
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
76 from zope.interface import implementer
15
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
goffi@necton2
parents:
diff changeset
85
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
97 }
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
147 ) = range(8)
0
goffi@necton2
parents:
diff changeset
148
goffi@necton2
parents:
diff changeset
149 SOCKS5_VER = 0x05
goffi@necton2
parents:
diff changeset
150
goffi@necton2
parents:
diff changeset
151 ADDR_IPV4 = 0x01
goffi@necton2
parents:
diff changeset
152 ADDR_DOMAINNAME = 0x03
goffi@necton2
parents:
diff changeset
153 ADDR_IPV6 = 0x04
goffi@necton2
parents:
diff changeset
154
goffi@necton2
parents:
diff changeset
155 CMD_CONNECT = 0x01
goffi@necton2
parents:
diff changeset
156 CMD_BIND = 0x02
goffi@necton2
parents:
diff changeset
157 CMD_UDPASSOC = 0x03
goffi@necton2
parents:
diff changeset
158
goffi@necton2
parents:
diff changeset
159 AUTHMECH_ANON = 0x00
goffi@necton2
parents:
diff changeset
160 AUTHMECH_USERPASS = 0x02
goffi@necton2
parents:
diff changeset
161 AUTHMECH_INVALID = 0xFF
goffi@necton2
parents:
diff changeset
162
goffi@necton2
parents:
diff changeset
163 REPLY_SUCCESS = 0x00
goffi@necton2
parents:
diff changeset
164 REPLY_GENERAL_FAILUR = 0x01
goffi@necton2
parents:
diff changeset
165 REPLY_CONN_NOT_ALLOWED = 0x02
goffi@necton2
parents:
diff changeset
166 REPLY_NETWORK_UNREACHABLE = 0x03
goffi@necton2
parents:
diff changeset
167 REPLY_HOST_UNREACHABLE = 0x04
goffi@necton2
parents:
diff changeset
168 REPLY_CONN_REFUSED = 0x05
goffi@necton2
parents:
diff changeset
169 REPLY_TTL_EXPIRED = 0x06
goffi@necton2
parents:
diff changeset
170 REPLY_CMD_NOT_SUPPORTED = 0x07
goffi@necton2
parents:
diff changeset
171 REPLY_ADDR_NOT_SUPPORTED = 0x08
goffi@necton2
parents:
diff changeset
172
goffi@necton2
parents:
diff changeset
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_)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
201 self.id = id_ if id_ is not None else str(uuid.uuid4())
1559
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 """
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
215 log.debug("Discarding {}".format(self))
1559
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,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
233 id=" id={}".format(self.id if self.id is not None else "").encode(
2624
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):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
239 return "Candidate ({0.priority}): host={0.host} port={0.port} jid={0.jid} type={0.type}{id}".format(
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
240 self, id=" id={}".format(self.id if self.id is not None else "")
2624
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:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
273 raise exceptions.InternalError("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
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
276 def activate(self, client, sid, peer_jid, local_jid):
1570
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()
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
287 iq_elt["from"] = local_jid.full()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
288 iq_elt["to"] = self.jid.full()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
289 query_elt = iq_elt.addElement((NS_BS, "query"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
290 query_elt["sid"] = sid
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
291 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
292 return iq_elt.send()
37d4be4a9fed plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents: 1569
diff changeset
293
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
294 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
295 if self.type == XEP_0065.TYPE_PROXY:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
296 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
297 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
298 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
299 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
300
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
301
1758
a66d34353f34 plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents: 1757
diff changeset
302 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
303 """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
304
1758
a66d34353f34 plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents: 1757
diff changeset
305 @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
306 @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
307 @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
308 @return (str): hash
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
309 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
310 return hashlib.sha1(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
311 (sid + requester_jid.full() + target_jid.full()).encode("utf-8")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
312 ).hexdigest()
0
goffi@necton2
parents:
diff changeset
313
goffi@necton2
parents:
diff changeset
314
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
315 class SOCKSv5(protocol.Protocol):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
316 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
317
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
318 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
319 """
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
320 @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
321 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
322 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
323 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
324 if session_hash is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
325 assert isinstance(session_hash, str)
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
326 self.server_mode = False
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
327 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
328 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
329 else:
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
330 self.server_mode = True
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
331 self.state = STATE_INITIAL
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
332 self.buf = b""
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
333 self.supportedAuthMechs = [AUTHMECH_ANON]
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
334 self.supportedAddrs = [ADDR_DOMAINNAME]
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
335 self.enabledCommands = [CMD_CONNECT]
0
goffi@necton2
parents:
diff changeset
336 self.peersock = None
goffi@necton2
parents:
diff changeset
337 self.addressType = 0
goffi@necton2
parents:
diff changeset
338 self.requestType = 0
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
339 self._stream_object = None
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
340 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
341 # 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
342
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
343 @property
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
344 def stream_object(self):
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
345 if self._stream_object is None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
346 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
347 if self.server_mode:
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
348 self._stream_object.registerProducer(self.transport, True)
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
349 return self._stream_object
0
goffi@necton2
parents:
diff changeset
350
1845
2bde6fc7aabd plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
351 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
352 """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
353
2bde6fc7aabd plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
354 @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
355 """
2bde6fc7aabd plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
356 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
357 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
358 else:
2bde6fc7aabd plugin XEP-0065: fixed timer cancellation when a profile is receiving a file
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
359 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
360
0
goffi@necton2
parents:
diff changeset
361 def _startNegotiation(self):
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
362 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
363 self.state = STATE_CLIENT_AUTH
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
364 self.transport.write(struct.pack("!3B", SOCKS5_VER, 1, AUTHMECH_ANON))
0
goffi@necton2
parents:
diff changeset
365
goffi@necton2
parents:
diff changeset
366 def _parseNegotiation(self):
goffi@necton2
parents:
diff changeset
367 try:
goffi@necton2
parents:
diff changeset
368 # Parse out data
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
369 ver, nmethod = struct.unpack("!BB", self.buf[:2])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
370 methods = struct.unpack("%dB" % nmethod, self.buf[2 : nmethod + 2])
0
goffi@necton2
parents:
diff changeset
371
goffi@necton2
parents:
diff changeset
372 # Ensure version is correct
goffi@necton2
parents:
diff changeset
373 if ver != 5:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
374 self.transport.write(struct.pack("!BB", SOCKS5_VER, AUTHMECH_INVALID))
0
goffi@necton2
parents:
diff changeset
375 self.transport.loseConnection()
goffi@necton2
parents:
diff changeset
376 return
goffi@necton2
parents:
diff changeset
377
goffi@necton2
parents:
diff changeset
378 # Trim off front of the buffer
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
379 self.buf = self.buf[nmethod + 2 :]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
380
0
goffi@necton2
parents:
diff changeset
381 # Check for supported auth mechs
goffi@necton2
parents:
diff changeset
382 for m in self.supportedAuthMechs:
goffi@necton2
parents:
diff changeset
383 if m in methods:
goffi@necton2
parents:
diff changeset
384 # Update internal state, according to selected method
goffi@necton2
parents:
diff changeset
385 if m == AUTHMECH_ANON:
goffi@necton2
parents:
diff changeset
386 self.state = STATE_REQUEST
goffi@necton2
parents:
diff changeset
387 elif m == AUTHMECH_USERPASS:
goffi@necton2
parents:
diff changeset
388 self.state = STATE_AUTH_USERPASS
goffi@necton2
parents:
diff changeset
389 # Complete negotiation w/ this method
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
390 self.transport.write(struct.pack("!BB", SOCKS5_VER, m))
0
goffi@necton2
parents:
diff changeset
391 return
goffi@necton2
parents:
diff changeset
392
goffi@necton2
parents:
diff changeset
393 # No supported mechs found, notify client and close the connection
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
394 log.warning("Unsupported authentication mechanism")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
395 self.transport.write(struct.pack("!BB", SOCKS5_VER, AUTHMECH_INVALID))
0
goffi@necton2
parents:
diff changeset
396 self.transport.loseConnection()
goffi@necton2
parents:
diff changeset
397 except struct.error:
goffi@necton2
parents:
diff changeset
398 pass
goffi@necton2
parents:
diff changeset
399
goffi@necton2
parents:
diff changeset
400 def _parseUserPass(self):
goffi@necton2
parents:
diff changeset
401 try:
goffi@necton2
parents:
diff changeset
402 # Parse out data
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
403 ver, ulen = struct.unpack("BB", self.buf[:2])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
404 uname, = struct.unpack("%ds" % ulen, self.buf[2 : ulen + 2])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
405 plen, = struct.unpack("B", self.buf[ulen + 2])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
406 password, = struct.unpack("%ds" % plen, self.buf[ulen + 3 : ulen + 3 + plen])
0
goffi@necton2
parents:
diff changeset
407 # Trim off fron of the buffer
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
408 self.buf = self.buf[3 + ulen + plen :]
0
goffi@necton2
parents:
diff changeset
409 # Fire event to authenticate user
goffi@necton2
parents:
diff changeset
410 if self.authenticateUserPass(uname, password):
goffi@necton2
parents:
diff changeset
411 # Signal success
goffi@necton2
parents:
diff changeset
412 self.state = STATE_REQUEST
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
413 self.transport.write(struct.pack("!BB", SOCKS5_VER, 0x00))
0
goffi@necton2
parents:
diff changeset
414 else:
goffi@necton2
parents:
diff changeset
415 # Signal failure
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
416 self.transport.write(struct.pack("!BB", SOCKS5_VER, 0x01))
0
goffi@necton2
parents:
diff changeset
417 self.transport.loseConnection()
goffi@necton2
parents:
diff changeset
418 except struct.error:
goffi@necton2
parents:
diff changeset
419 pass
goffi@necton2
parents:
diff changeset
420
goffi@necton2
parents:
diff changeset
421 def sendErrorReply(self, errorcode):
goffi@necton2
parents:
diff changeset
422 # Any other address types are not supported
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
423 result = struct.pack("!BBBBIH", SOCKS5_VER, errorcode, 0, 1, 0, 0)
0
goffi@necton2
parents:
diff changeset
424 self.transport.write(result)
goffi@necton2
parents:
diff changeset
425 self.transport.loseConnection()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
426
0
goffi@necton2
parents:
diff changeset
427 def _parseRequest(self):
goffi@necton2
parents:
diff changeset
428 try:
goffi@necton2
parents:
diff changeset
429 # Parse out data and trim buffer accordingly
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
430 ver, cmd, rsvd, self.addressType = struct.unpack("!BBBB", self.buf[:4])
0
goffi@necton2
parents:
diff changeset
431
goffi@necton2
parents:
diff changeset
432 # Ensure we actually support the requested address type
goffi@necton2
parents:
diff changeset
433 if self.addressType not in self.supportedAddrs:
goffi@necton2
parents:
diff changeset
434 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED)
goffi@necton2
parents:
diff changeset
435 return
goffi@necton2
parents:
diff changeset
436
goffi@necton2
parents:
diff changeset
437 # Deal with addresses
goffi@necton2
parents:
diff changeset
438 if self.addressType == ADDR_IPV4:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
439 addr, port = struct.unpack("!IH", self.buf[4:10])
0
goffi@necton2
parents:
diff changeset
440 self.buf = self.buf[10:]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
441 elif self.addressType == ADDR_DOMAINNAME:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
442 nlen = self.buf[4]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
443 addr, port = struct.unpack("!%dsH" % nlen, self.buf[5:])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
444 self.buf = self.buf[7 + len(addr) :]
0
goffi@necton2
parents:
diff changeset
445 else:
goffi@necton2
parents:
diff changeset
446 # Any other address types are not supported
goffi@necton2
parents:
diff changeset
447 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED)
goffi@necton2
parents:
diff changeset
448 return
goffi@necton2
parents:
diff changeset
449
goffi@necton2
parents:
diff changeset
450 # Ensure command is supported
goffi@necton2
parents:
diff changeset
451 if cmd not in self.enabledCommands:
goffi@necton2
parents:
diff changeset
452 # Send a not supported error
goffi@necton2
parents:
diff changeset
453 self.sendErrorReply(REPLY_CMD_NOT_SUPPORTED)
goffi@necton2
parents:
diff changeset
454 return
goffi@necton2
parents:
diff changeset
455
goffi@necton2
parents:
diff changeset
456 # Process the command
goffi@necton2
parents:
diff changeset
457 if cmd == CMD_CONNECT:
goffi@necton2
parents:
diff changeset
458 self.connectRequested(addr, port)
goffi@necton2
parents:
diff changeset
459 elif cmd == CMD_BIND:
goffi@necton2
parents:
diff changeset
460 self.bindRequested(addr, port)
goffi@necton2
parents:
diff changeset
461 else:
goffi@necton2
parents:
diff changeset
462 # Any other command is not supported
goffi@necton2
parents:
diff changeset
463 self.sendErrorReply(REPLY_CMD_NOT_SUPPORTED)
goffi@necton2
parents:
diff changeset
464
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
465 except struct.error:
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
466 # The buffer is probably not complete, we need to wait more
0
goffi@necton2
parents:
diff changeset
467 return None
goffi@necton2
parents:
diff changeset
468
goffi@necton2
parents:
diff changeset
469 def _makeRequest(self):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
470 hash_ = self._session_hash.encode('utf-8')
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
471 request = struct.pack(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
472 "!5B%dsH" % len(hash_),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
473 SOCKS5_VER,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
474 CMD_CONNECT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
475 0,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
476 ADDR_DOMAINNAME,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
477 len(hash_),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
478 hash_,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
479 0,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
480 )
0
goffi@necton2
parents:
diff changeset
481 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
482 self.state = STATE_CLIENT_REQUEST
0
goffi@necton2
parents:
diff changeset
483
goffi@necton2
parents:
diff changeset
484 def _parseRequestReply(self):
goffi@necton2
parents:
diff changeset
485 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
486 ver, rep, rsvd, self.addressType = struct.unpack("!BBBB", self.buf[:4])
0
goffi@necton2
parents:
diff changeset
487 # Ensure we actually support the requested address type
goffi@necton2
parents:
diff changeset
488 if self.addressType not in self.supportedAddrs:
goffi@necton2
parents:
diff changeset
489 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED)
goffi@necton2
parents:
diff changeset
490 return
goffi@necton2
parents:
diff changeset
491
goffi@necton2
parents:
diff changeset
492 # Deal with addresses
goffi@necton2
parents:
diff changeset
493 if self.addressType == ADDR_IPV4:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
494 addr, port = struct.unpack("!IH", self.buf[4:10])
0
goffi@necton2
parents:
diff changeset
495 self.buf = self.buf[10:]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
496 elif self.addressType == ADDR_DOMAINNAME:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
497 nlen = self.buf[4]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
498 addr, port = struct.unpack("!%dsH" % nlen, self.buf[5:])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
499 self.buf = self.buf[7 + len(addr) :]
0
goffi@necton2
parents:
diff changeset
500 else:
goffi@necton2
parents:
diff changeset
501 # Any other address types are not supported
goffi@necton2
parents:
diff changeset
502 self.sendErrorReply(REPLY_ADDR_NOT_SUPPORTED)
goffi@necton2
parents:
diff changeset
503 return
goffi@necton2
parents:
diff changeset
504
goffi@necton2
parents:
diff changeset
505 # Ensure reply is OK
goffi@necton2
parents:
diff changeset
506 if rep != REPLY_SUCCESS:
goffi@necton2
parents:
diff changeset
507 self.loseConnection()
goffi@necton2
parents:
diff changeset
508 return
goffi@necton2
parents:
diff changeset
509
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
510 self.state = STATE_READY
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
511 self.connection.callback(None)
0
goffi@necton2
parents:
diff changeset
512
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
513 except struct.error:
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
514 # The buffer is probably not complete, we need to wait more
0
goffi@necton2
parents:
diff changeset
515 return None
goffi@necton2
parents:
diff changeset
516
goffi@necton2
parents:
diff changeset
517 def connectionMade(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
518 log.debug(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
519 "Socks5 connectionMade (mode = {})".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
520 "server" if self.state == STATE_INITIAL else "client"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
521 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
522 )
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
523 if self.state == STATE_CLIENT_INITIAL:
0
goffi@necton2
parents:
diff changeset
524 self._startNegotiation()
goffi@necton2
parents:
diff changeset
525
goffi@necton2
parents:
diff changeset
526 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
527 # Check that this session is expected
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
528 if not self.factory.addToSession(addr.decode('utf-8'), self):
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
529 self.sendErrorReply(REPLY_CONN_REFUSED)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
530 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
531 "Unexpected connection request received from {host}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
532 host=self.transport.getPeer().host
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
533 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
534 )
0
goffi@necton2
parents:
diff changeset
535 return
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
536 self._session_hash = addr.decode('utf-8')
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
537 self.connectCompleted(addr, 0)
0
goffi@necton2
parents:
diff changeset
538
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
539 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
540 """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
541
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
542 @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
543 """
1759
81923b3f8b14 plugin XEP-0065: better handling of finished Deferred
Goffi <goffi@goffi.org>
parents: 1758
diff changeset
544 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
545 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
546 self.CHUNK_SIZE = chunk_size
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
547 log.debug("Starting file transfer")
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
548 d = self.stream_object.startStream(self.transport)
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
549 d.addCallback(self.streamFinished)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
550
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
551 def streamFinished(self, d):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
552 log.info(_("File transfer completed, closing connection"))
0
goffi@necton2
parents:
diff changeset
553 self.transport.loseConnection()
goffi@necton2
parents:
diff changeset
554
goffi@necton2
parents:
diff changeset
555 def connectCompleted(self, remotehost, remoteport):
goffi@necton2
parents:
diff changeset
556 if self.addressType == ADDR_IPV4:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
557 result = struct.pack(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
558 "!BBBBIH", SOCKS5_VER, REPLY_SUCCESS, 0, 1, remotehost, remoteport
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
559 )
0
goffi@necton2
parents:
diff changeset
560 elif self.addressType == ADDR_DOMAINNAME:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
561 result = struct.pack(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
562 "!BBBBB%dsH" % len(remotehost),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
563 SOCKS5_VER,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
564 REPLY_SUCCESS,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
565 0,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
566 ADDR_DOMAINNAME,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
567 len(remotehost),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
568 remotehost,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
569 remoteport,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
570 )
0
goffi@necton2
parents:
diff changeset
571 self.transport.write(result)
goffi@necton2
parents:
diff changeset
572 self.state = STATE_READY
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
573
0
goffi@necton2
parents:
diff changeset
574 def bindRequested(self, addr, port):
goffi@necton2
parents:
diff changeset
575 pass
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
576
0
goffi@necton2
parents:
diff changeset
577 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
578 # FIXME: implement authentication and remove the debug printing a password
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
579 log.debug("User/pass: %s/%s" % (user, passwd))
0
goffi@necton2
parents:
diff changeset
580 return True
goffi@necton2
parents:
diff changeset
581
goffi@necton2
parents:
diff changeset
582 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
583 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
584 # 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
585 self.stream_object.write(buf)
1759
81923b3f8b14 plugin XEP-0065: better handling of finished Deferred
Goffi <goffi@goffi.org>
parents: 1758
diff changeset
586 if not self.active:
81923b3f8b14 plugin XEP-0065: better handling of finished Deferred
Goffi <goffi@goffi.org>
parents: 1758
diff changeset
587 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
588 self.getSession()[TIMER_KEY].cancel()
0
goffi@necton2
parents:
diff changeset
589 return
goffi@necton2
parents:
diff changeset
590
goffi@necton2
parents:
diff changeset
591 self.buf = self.buf + buf
goffi@necton2
parents:
diff changeset
592 if self.state == STATE_INITIAL:
goffi@necton2
parents:
diff changeset
593 self._parseNegotiation()
goffi@necton2
parents:
diff changeset
594 if self.state == STATE_AUTH_USERPASS:
goffi@necton2
parents:
diff changeset
595 self._parseUserPass()
goffi@necton2
parents:
diff changeset
596 if self.state == STATE_REQUEST:
goffi@necton2
parents:
diff changeset
597 self._parseRequest()
1559
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_REQUEST:
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
599 self._parseRequestReply()
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
600 if self.state == STATE_CLIENT_AUTH:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
601 ver, method = struct.unpack("!BB", buf)
0
goffi@necton2
parents:
diff changeset
602 self.buf = self.buf[2:]
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
603 if ver != SOCKS5_VER or method != AUTHMECH_ANON:
0
goffi@necton2
parents:
diff changeset
604 self.transport.loseConnection()
goffi@necton2
parents:
diff changeset
605 else:
goffi@necton2
parents:
diff changeset
606 self._makeRequest()
goffi@necton2
parents:
diff changeset
607
goffi@necton2
parents:
diff changeset
608 def connectionLost(self, reason):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
609 log.debug("Socks5 connection lost: {}".format(reason.value))
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
610 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
611 self.connection.errback(reason)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
612 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
613 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
614
0
goffi@necton2
parents:
diff changeset
615
goffi@necton2
parents:
diff changeset
616 class Socks5ServerFactory(protocol.ServerFactory):
goffi@necton2
parents:
diff changeset
617 protocol = SOCKSv5
goffi@necton2
parents:
diff changeset
618
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
619 def __init__(self, parent):
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 @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
622 """
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
623 self.parent = parent
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
624
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
625 def getSession(self, session_hash):
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
626 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
627
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
628 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
629 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
630 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
631 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
632 except (KeyError, IndexError):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
633 log.error("Can't start file transfer, can't find protocol")
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
634 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
635 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
636 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
637
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
638 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
639 """Check is session_hash is valid, and associate protocol with it
0
goffi@necton2
parents:
diff changeset
640
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
641 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
642 @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
643 @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
644 @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
645 """
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
646 assert isinstance(session_hash, str)
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
647 try:
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
648 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
649 except KeyError:
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
650 return False
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
651 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
652 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
653 return True
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
654
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
655 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
656 """Remove a protocol from session_data
0
goffi@necton2
parents:
diff changeset
657
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
658 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
659 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
660 @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
661 @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
662 @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
663 """
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
664 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
665 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
666 protocols.remove(protocol)
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
667 except (KeyError, ValueError):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
668 log.error("Protocol not found in session while it should be there")
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
669 else:
1759
81923b3f8b14 plugin XEP-0065: better handling of finished Deferred
Goffi <goffi@goffi.org>
parents: 1758
diff changeset
670 if protocol.active:
81923b3f8b14 plugin XEP-0065: better handling of finished Deferred
Goffi <goffi@goffi.org>
parents: 1758
diff changeset
671 # 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
672 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
673 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
674 else:
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
675 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
676
0
goffi@necton2
parents:
diff changeset
677
goffi@necton2
parents:
diff changeset
678 class Socks5ClientFactory(protocol.ClientFactory):
goffi@necton2
parents:
diff changeset
679 protocol = SOCKSv5
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
680
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
681 def __init__(self, client, parent, session, session_hash):
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
682 """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
683
1758
a66d34353f34 plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents: 1757
diff changeset
684 @param session(dict): session data
a66d34353f34 plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents: 1757
diff changeset
685 @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
686 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
687 """
1758
a66d34353f34 plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents: 1757
diff changeset
688 self.session = session
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
689 self.session_hash = session_hash
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
690 self.client = client
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
691 self.connection = defer.Deferred()
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
692 self._protocol_instance = None
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
693 self.connector = None
0
goffi@necton2
parents:
diff changeset
694
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
695 def discard(self):
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
696 """Disconnect the client
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
697
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
698 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
699 """
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
700 self.connector.disconnect()
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
701
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
702 def getSession(self):
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
703 return self.session
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
704
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
705 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
706 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
707 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
708
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
709 def clientConnectionFailed(self, connector, reason):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
710 log.debug("Connection failed")
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
711 self.connection.errback(reason)
0
goffi@necton2
parents:
diff changeset
712
goffi@necton2
parents:
diff changeset
713 def clientConnectionLost(self, connector, reason):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
714 log.debug(_("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
715 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
716 # 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
717 # 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
718 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
719 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
720 else:
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
721 self.getSession()[DEFER_KEY].errback(reason)
1759
81923b3f8b14 plugin XEP-0065: better handling of finished Deferred
Goffi <goffi@goffi.org>
parents: 1758
diff changeset
722 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
723
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
724 def buildProtocol(self, addr):
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
725 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
726 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
727 p.factory = self
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
728 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
729 self._protocol_instance = p
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
730 return p
0
goffi@necton2
parents:
diff changeset
731
goffi@necton2
parents:
diff changeset
732
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
733 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
734 NAMESPACE = NS_BS
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
735 TYPE_DIRECT = "direct"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
736 TYPE_ASSISTED = "assisted"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
737 TYPE_TUNEL = "tunel"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
738 TYPE_PROXY = "proxy"
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
739 Candidate = Candidate
20
fc8c202cda87 refactoring: using xml params part IV (default values)
Goffi <goffi@goffi.org>
parents: 19
diff changeset
740
0
goffi@necton2
parents:
diff changeset
741 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 956
diff changeset
742 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
743 self.host = host
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
744
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
745 # session data
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
746 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
747 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
748
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
749 # misc data
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
750 self._server_factory = None
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
751 self._external_port = None
21
633c5ed65701 parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents: 20
diff changeset
752
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
753 # plugins shortcuts
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
754 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
755 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
756 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
757 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
758 log.debug("NAT Port plugin not available")
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
759 self._np = None
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
760
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
761 # parameters
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
762 # 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
763 # host.memory.updateParams(PARAMS)
587
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 getHandler(self, client):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
766 return XEP_0065_handler(self)
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
767
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
768 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
769 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
770 client._s5b_sessions = {}
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 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
773 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
774
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
775 def getSocks5ServerFactory(self):
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
776 """Return server factory
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
777
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
778 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
779 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
780 """
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
781
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
782 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
783 self._server_factory = Socks5ServerFactory(self)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
784 for port in range(SERVER_STARTING_PORT, 65356):
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
785 try:
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
786 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
787 except internet_error.CannotListenError as e:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
788 log.debug(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
789 "Cannot listen on port {port}: {err_msg}{err_num}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
790 port=port,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
791 err_msg=e.socketError.strerror,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
792 err_num=" (error code: {})".format(e.socketError.errno),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
793 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
794 )
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
795 else:
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
796 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
797 break
0
goffi@necton2
parents:
diff changeset
798
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
799 log.info(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
800 _("Socks5 Stream server launched on port {}").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
801 self._server_factory_port
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
802 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
803 )
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
804 return self._server_factory
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
805
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
806 @defer.inlineCallbacks
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
807 def getProxy(self, client, local_jid):
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
808 """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
809
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
810 cache is used between clients using the same server
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
811 @param local_jid(jid.JID): same as for [getCandidates]
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
812 @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
813 or None if not acceptable proxy is found
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
814 @raise exceptions.NotFound: no Proxy found
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
815 """
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 def notFound(server):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
818 log.info("No proxy found on this server")
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
819 self._cache_proxies[server] = None
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
820 raise exceptions.NotFound
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
821
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
822 server = client.host if client.is_component else client.jid.host
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
823 try:
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
824 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
825 except KeyError:
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
826 pass
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
827 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
828 proxy = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
829 yield self.host.findServiceEntities(client, "proxy", "bytestreams")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
830 ).pop()
2502
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
831 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
832 notFound(server)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
833 iq_elt = client.IQ("get")
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
834 iq_elt["from"] = local_jid.full()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
835 iq_elt["to"] = proxy.full()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
836 iq_elt.addElement((NS_BS, "query"))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
837
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
838 try:
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
839 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
840 except jabber_error.StanzaError as failure:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
841 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
842 "Error while requesting proxy info on {jid}: {error}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
843 proxy.full(), failure
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
844 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
845 )
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
846 notFound(server)
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
847
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
848 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
849 query_elt = next(result_elt.elements(NS_BS, "query"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
850 streamhost_elt = next(query_elt.elements(NS_BS, "streamhost"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
851 host = streamhost_elt["host"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
852 jid_ = streamhost_elt["jid"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
853 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
854 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
855 raise KeyError
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
856 jid_ = jid.JID(jid_)
1742
244a605623d6 complete the Exception's list when catching JID error:
souliane <souliane@mailoo.org>
parents: 1675
diff changeset
857 except (StopIteration, KeyError, RuntimeError, jid.InvalidFormat, AttributeError):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
858 log.warning("Invalid proxy data received from {}".format(proxy.full()))
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
859 notFound(server)
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
860
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
861 proxy_infos = self._cache_proxies[server] = ProxyInfos(host, jid_, port)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
862 log.info("Proxy found: {}".format(proxy_infos))
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
863 defer.returnValue(proxy_infos)
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
864
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
865 @defer.inlineCallbacks
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
866 def _getNetworkData(self, client):
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
867 """Retrieve information about network
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
868
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
869 @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
870 @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
871 """
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
872 self.getSocks5ServerFactory()
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
873 local_port = self._server_factory_port
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
874 external_ip = yield self._ip.getExternalIP(client)
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
875 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
876
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
877 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
878 if external_ip != local_ips[0]:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
879 log.info("We are probably behind a NAT")
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 self._np is None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
881 log.warning("NAT port plugin not available, we can't map port")
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
882 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
883 ext_port = yield self._np.mapPort(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
884 local_port, desc="SaT socks5 stream"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
885 )
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
886 if ext_port is None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
887 log.warning("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
888 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
889 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
890
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
891 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
892
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
893 @defer.inlineCallbacks
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
894 def getCandidates(self, client, local_jid):
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
895 """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
896
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
897 @param local_jid(jid.JID): jid to use as local jid
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
898 This is needed for client which can be addressed with a different jid than
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
899 client.jid if a local part is used (e.g. piotr@file.example.net where
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
900 client.jid would be file.example.net)
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
901 @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
902 """
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
903 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
904 local_port, ext_port, local_ips, external_ip = yield self._getNetworkData(client)
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
905 try:
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
906 proxy = yield self.getProxy(client, local_jid)
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
907 except exceptions.NotFound:
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
908 proxy = None
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
909
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
910 # 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
911 candidates = []
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
912
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
913 # 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
914
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 # 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
916 ip = local_ips.pop(0)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
917 candidates.append(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
918 Candidate(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
919 ip,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
920 local_port,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
921 XEP_0065.TYPE_DIRECT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
922 PRIORITY_BEST_DIRECT,
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
923 local_jid,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
924 priority_local=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
925 factory=server_factory,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
926 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
927 )
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
928 for ip in local_ips:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
929 candidates.append(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
930 Candidate(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
931 ip,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
932 local_port,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
933 XEP_0065.TYPE_DIRECT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
934 PRIORITY_DIRECT,
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
935 local_jid,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
936 priority_local=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
937 factory=server_factory,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
938 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
939 )
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
940
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
941 # then the assisted one
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
942 if ext_port is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
943 candidates.append(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
944 Candidate(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
945 external_ip,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
946 ext_port,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
947 XEP_0065.TYPE_ASSISTED,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
948 PRIORITY_ASSISTED,
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
949 local_jid,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
950 priority_local=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
951 factory=server_factory,
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 # finally the proxy
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
956 if proxy:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
957 candidates.append(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
958 Candidate(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
959 proxy.host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
960 proxy.port,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
961 XEP_0065.TYPE_PROXY,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
962 PRIORITY_PROXY,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
963 proxy.jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
964 priority_local=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
965 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
966 )
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
967
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
968 # 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
969 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
970 defer.returnValue(candidates)
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
971
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
972 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
973 """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
974
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
975 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
976 @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
977 @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
978 @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
979 """
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
980 candidate.factory.connector = connector
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
981 return candidate.factory.connection
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
982
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
983 def connectCandidate(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
984 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
985 ):
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
986 """Connect to a candidate
1570
37d4be4a9fed plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents: 1569
diff changeset
987
37d4be4a9fed plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents: 1569
diff changeset
988 Connection will be done with a Socks5ClientFactory
37d4be4a9fed plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents: 1569
diff changeset
989 @param candidate(Candidate): candidate to connect to
37d4be4a9fed plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents: 1569
diff changeset
990 @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
991 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
992 @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
993 None to use session_hash.
a66d34353f34 plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents: 1757
diff changeset
994 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
995 - 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
996 - 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
997 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
998 @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
999 @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
1000 """
1758
a66d34353f34 plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents: 1757
diff changeset
1001 if peer_session_hash is None:
a66d34353f34 plugin XEP-0260, XEP-0065: fixed session hash handling:
Goffi <goffi@goffi.org>
parents: 1757
diff changeset
1002 # 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
1003 peer_session_hash = session_hash
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1004 session = self.getSession(client, session_hash)
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1005 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
1006 candidate.factory = factory
37d4be4a9fed plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents: 1569
diff changeset
1007 if delay is None:
37d4be4a9fed plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents: 1569
diff changeset
1008 d = defer.succeed(candidate.host)
37d4be4a9fed plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents: 1569
diff changeset
1009 else:
37d4be4a9fed plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents: 1569
diff changeset
1010 d = sat_defer.DelayedDeferred(delay, candidate.host)
37d4be4a9fed plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents: 1569
diff changeset
1011 d.addCallback(reactor.connectTCP, candidate.port, factory)
37d4be4a9fed plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents: 1569
diff changeset
1012 d.addCallback(self._addConnector, candidate)
37d4be4a9fed plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents: 1569
diff changeset
1013 return d
37d4be4a9fed plugins XEP-0260, XEP-0065: proxy handling:
Goffi <goffi@goffi.org>
parents: 1569
diff changeset
1014
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1015 def tryCandidates(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1016 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1017 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1018 candidates,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1019 session_hash,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1020 peer_session_hash,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1021 connection_cb=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1022 connection_eb=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1023 ):
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1024 defers_list = []
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1025
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1026 for candidate in candidates:
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1027 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
1028 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
1029 delay += CANDIDATE_DELAY_PROXY
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1030 d = self.connectCandidate(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1031 client, candidate, session_hash, peer_session_hash, delay
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1032 )
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1033 if connection_cb is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1034 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
1035 lambda __, candidate=candidate, client=client: connection_cb(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1036 client, candidate
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1037 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1038 )
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1039 if connection_eb is not None:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1040 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
1041 defers_list.append(d)
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1042
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1043 return defers_list
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1044
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1045 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
1046 """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
1047
d04d7402b8e9 plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents: 1576
diff changeset
1048 @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
1049 @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
1050 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
1051 @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
1052 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
1053 @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
1054 """
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1055 defer_candidates = None
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1056
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1057 def connectionCb(client, candidate):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1058 log.info("Connection of {} successful".format(str(candidate)))
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1059 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
1060 try:
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1061 if other_candidate.priority < candidate.priority:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1062 log.debug("Cancelling {}".format(other_candidate))
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1063 defer_candidates[idx].cancel()
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1064 except AttributeError:
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1065 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
1066
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1067 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
1068 if failure.check(defer.CancelledError):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1069 log.debug("Connection of {} has been cancelled".format(candidate))
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1070 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1071 log.info(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1072 "Connection of {candidate} Failed: {error}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1073 candidate=candidate, error=failure.value
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1074 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1075 )
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1076 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
1077
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1078 def allTested(self):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1079 log.debug("All candidates have been tested")
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1080 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
1081 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
1082
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1083 defer_candidates = self.tryCandidates(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1084 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1085 candidates,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1086 session_hash,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1087 peer_session_hash,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1088 connectionCb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1089 connectionEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1090 )
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1091 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
1092 d_list.addCallback(allTested)
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1093 return d_list
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
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 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
1096 """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
1097
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
1098 @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
1099 @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
1100 """
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1101 log.info("Socks5 Bytestream: TimeOut reached")
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1102 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
1103 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
1104
2502
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
1105 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
1106 """Clean the current session
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
1107
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
1108 @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
1109 @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
1110 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
1111 @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
1112 @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
1113 @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
1114 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1115 log.debug(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1116 "Cleaning session with hash {hash}{id}: {reason}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1117 hash=session_hash,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1118 reason="" if failure_ is None else failure_.value,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1119 id="" if sid is None else " (id: {})".format(sid),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1120 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
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
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1123 try:
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1124 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
1125 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
1126 except KeyError:
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1127 pass
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1128
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
1129 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
1130 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
1131 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
1132 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1133 log.warning("Session id {} is unknown".format(sid))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
1134
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1135 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
1136 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
1137 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1138 log.warning("There is no session with this 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
1139 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
1140 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
1141 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
1142
b57b4683dc33 plugin XEP-0065: session cleaning and timeout + log choosed candidate when using SI File Transfer
Goffi <goffi@goffi.org>
parents: 1583
diff changeset
1143 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1144 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
1145 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
1146 pass
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1147
2502
7ad5f2c4e34a XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents: 2489
diff changeset
1148 return failure_
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
1149
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1150 def startStream(self, client, stream_object, local_jid, to_jid, sid):
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
1151 """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
1152
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1153 @param streamProducer: stream_object to use
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1154 @param local_jid(jid.JID): same as for [getCandidates]
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
1155 @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
1156 @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
1157 @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
1158 @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
1159 @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
1160 """
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1161 session_data = self._createSession(
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1162 client, stream_object, local_jid, 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
1163
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
1164 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
1165
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
1166 def gotCandidates(candidates):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1167 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
1168 iq_elt = client.IQ()
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1169 iq_elt["from"] = local_jid.full()
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
1170 iq_elt["to"] = to_jid.full()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1171 query_elt = iq_elt.addElement((NS_BS, "query"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1172 query_elt["mode"] = "tcp"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1173 query_elt["sid"] = sid
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
1174
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
1175 for candidate in candidates:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1176 streamhost = query_elt.addElement("streamhost")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1177 streamhost["host"] = candidate.host
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1178 streamhost["port"] = str(candidate.port)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1179 streamhost["jid"] = candidate.jid.full()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1180 log.debug("Candidate proposed: {}".format(candidate))
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
1181
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
1182 d = iq_elt.send()
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1183 args = [client, session_data, local_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
1184 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
1185
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1186 self.getCandidates(client, local_jid).addCallback(gotCandidates)
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1187 return session_data[DEFER_KEY]
0
goffi@necton2
parents:
diff changeset
1188
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1189 def _IQNegotiationCb(self, iq_elt, client, session_data, local_jid):
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1190 """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
1191
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1192 @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
1193 @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
1194 @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
1195 """
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1196 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1197 query_elt = next(iq_elt.elements(NS_BS, "query"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1198 streamhost_used_elt = next(query_elt.elements(NS_BS, "streamhost-used"))
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
1199 except StopIteration:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1200 log.warning("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
1201 # FIXME: must clean session
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
1202 return
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
1203
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1204 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
1205 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1206 candidate = next((
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1207 c for c in session_data["candidates"] if c.jid == streamhost_jid
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1208 ))
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
1209 except StopIteration:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1210 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1211 "Candidate [{jid}] is unknown !".format(jid=streamhost_jid.full())
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1212 )
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
1213 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
1214 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1215 log.info("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
1216
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
1217 if candidate.type == XEP_0065.TYPE_PROXY:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1218 log.info("A Socks5 proxy is used")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1219 d = self.connectCandidate(client, candidate, session_data["hash"])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1220 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
1221 lambda __: candidate.activate(
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1222 client, session_data["id"], session_data["peer_jid"], local_jid
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1223 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1224 )
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
1225 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
1226 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
1227 d = defer.succeed(None)
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
1228
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1229 d.addCallback(lambda __: candidate.startTransfer(session_data["hash"]))
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
1230
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
1231 def _activationEb(self, failure):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1232 log.warning("Proxy activation error: {}".format(failure.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
1233
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1234 def _IQNegotiationEb(self, stanza_err, client, session_data, local_jid):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1235 log.warning("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
1236 # 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
1237
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1238 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
1239 """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
1240
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1241 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
1242 """
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1243 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
1244
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1245 def _createSession(self, client, stream_object, local_jid, to_jid, sid,
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1246 requester=False):
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
1247 """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
1248
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1249 @param stream_object(iface.IStreamProducer): File object where data will be
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1250 written
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1251 @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
1252 @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
1253 @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
1254 @return (dict): session data
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1255 """
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
1256 if sid in client.xep_0065_sid_session:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1257 raise exceptions.ConflictError("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
1258 if requester:
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1259 session_hash = getSessionHash(local_jid, to_jid, sid)
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1260 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
1261 else:
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1262 session_hash = getSessionHash(to_jid, local_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
1263 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
1264 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
1265 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
1266 DEFER_KEY: session_d,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1267 TIMER_KEY: reactor.callLater(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1268 TIMEOUT, self._timeOut, session_hash, client
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1269 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1270 }
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
1271 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
1272 session_data.update(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1273 {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1274 "id": sid,
2927
69e4716d6268 plugins (jingle) file transfer: use initial "from" attribute as local jid instead of client.jid:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1275 "local_jid": local_jid,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1276 "peer_jid": to_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1277 "stream_object": stream_object,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1278 "hash": session_hash,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1279 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1280 )
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1281
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1282 return session_data
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1283
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1284 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
1285 """Return session data
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1286
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1287 @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
1288 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
1289 @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
1290 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
1291 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
1292 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
1293 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
1294 @return (dict): session data
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1295 """
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1296 assert isinstance(session_hash, str)
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1297 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
1298 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1299 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
1300 except KeyError as e:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1301 log.warning("The requested session doesn't exists !")
1559
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1302 raise e
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1303 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
1304
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1305 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
1306 """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
1307 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
1308 """
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1309 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
1310
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1311 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
1312 """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
1313
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1314 @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
1315 @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
1316 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
1317 return (dict): session data
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1318 """
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1319 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
1320 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
1321 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
1322 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
1323 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
1324 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
1325 }
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
1326
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1327 if stream_object is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1328 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
1329
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1330 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
1331 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
1332
7cc29634b6ef plugin XEP-0065, XEP-0096: preparation for plugin XEP-0260 implementation:
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
1333 return session_data
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
1334
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1335 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
1336 """Associate a stream object with a session"""
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1337 session_data = self.getSession(client, session_hash)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1338 assert "stream_object" not in session_data
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1339 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
1340
2489
e2a7bb875957 plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
1341 def streamQuery(self, iq_elt, client):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1342 log.debug("BS stream query")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
1343
394
8f3551ceee17 plugin XEP-0065: refactored and misc stuff fixed. Still not finished
Goffi <goffi@goffi.org>
parents: 291
diff changeset
1344 iq_elt.handled = True
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
1345
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1346 query_elt = next(iq_elt.elements(NS_BS, "query"))
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
1347 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1348 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
1349 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1350 log.warning("Invalid bystreams request received")
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 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
1352
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1353 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
1354 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
1355 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
1356
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
1357 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
1358 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
1359 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1360 log.warning("Ignoring unexpected BS transfer: {}".format(sid))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1361 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
1362
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
1363 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
1364
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 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
1366 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
1367 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
1368 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1369 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
1370 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1371 log.warning("malformed streamhost element")
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
1372 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
1373 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
1374 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
1375 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
1376 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
1377 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
1378 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
1379
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
1380 for candidate in candidates:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1381 log.info("Candidate proposed: {}".format(candidate))
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
1382
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1383 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
1384 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
1385
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
1386 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
1387 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
1388 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
1389 return client.sendError(iq_elt, "item-not-found")
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1390 log.info("We choose: {}".format(candidate))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1391 result_elt = xmlstream.toResponse(iq_elt, "result")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1392 query_elt = result_elt.addElement((NS_BS, "query"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1393 query_elt["sid"] = session_data["id"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1394 streamhost_used_elt = query_elt.addElement("streamhost-used")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1395 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
1396 client.send(result_elt)
0
goffi@necton2
parents:
diff changeset
1397
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1398
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2927
diff changeset
1399 @implementer(iwokkel.IDisco)
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
1400 class XEP_0065_handler(XMPPHandler):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
1401
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
1402 def __init__(self, plugin_parent):
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
1403 self.plugin_parent = plugin_parent
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
1404 self.host = plugin_parent.host
398
cb0285372818 File transfer:
Goffi <goffi@goffi.org>
parents: 394
diff changeset
1405
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
1406 def connectionInitialized(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1407 self.xmlstream.addObserver(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1408 BS_REQUEST, self.plugin_parent.streamQuery, client=self.parent
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1409 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
1410
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1411 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
1412 return [disco.DiscoFeature(NS_BS)]
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
1413
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1414 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 60
diff changeset
1415 return []