Commit ae33330a authored by dkirov's avatar dkirov

send fake activate stanza to assert that proxy

works correctly
parent 1f43ebfe
......@@ -285,7 +285,9 @@ class ConnectionBytestream:
def _bytestreamErrorCB(self, con, iq_obj):
gajim.log.debug('_bytestreamErrorCB')
id = unicode(iq_obj.getAttr('id'))
frm = helpers.get_full_jid_from_iq(iq_obj)
query = iq_obj.getTag('query')
gajim.proxy65_manager.error_cb(frm, query)
jid = helpers.get_jid_from_iq(iq_obj)
id = id[3:]
if not self.files_props.has_key(id):
......
......@@ -626,6 +626,15 @@ distro_info = {
'Redhat Linux': '/etc/redhat-release'
}
def get_random_string_16():
''' create random string of length 16'''
rng = range(65, 90)
rng.extend(range(48, 57))
char_sequence = map(lambda e:chr(e), rng)
from random import sample
return reduce(lambda e1, e2: e1 + e2,
sample(char_sequence, 16))
def get_os_info():
if os.name == 'nt':
ver = os.sys.getwindowsversion()
......
......@@ -18,12 +18,14 @@ import struct
import common.xmpp
from common import gajim
from common import helpers
from socks5 import Socks5
from common.xmpp.idlequeue import IdleObject
S_INITIAL = 0
S_STARTED = 1
S_RESOLVED = 2
S_ACTIVATED = 3
S_FINISHED = 4
CONNECT_TIMEOUT = 20
......@@ -68,6 +70,15 @@ class Proxy65Manager:
self.proxies[proxy].resolve_result(host, port, jid)
# we can have only one streamhost
raise common.xmpp.NodeProcessed
def error_cb(self, proxy, query):
if not self.proxies.has_key(proxy):
return
resolver = self.proxies[proxy]
sid = query.getAttr('sid')
if resolver.sid == sid:
resolver.keep_conf()
def get_proxy(self, proxy):
if self.proxies.has_key(proxy):
resolver = self.proxies[proxy]
......@@ -87,11 +98,16 @@ class ProxyResolver:
self.host_tester.connect()
def _on_connect_success(self):
conf = gajim.config
conf.add_per('ft_proxies65_cache', self.proxy)
conf.set_per('ft_proxies65_cache', self.proxy, 'host', self.host)
conf.set_per('ft_proxies65_cache', self.proxy, 'port', self.port)
conf.set_per('ft_proxies65_cache', self.proxy, 'jid', self.jid)
iq = common.xmpp.Protocol(name = 'iq', to = self.jid, typ = 'set')
query = iq.setTag('query')
query.setNamespace(common.xmpp.NS_BYTESTREAM)
query.setAttr('sid', self.sid)
activate = query.setTag('activate')
# activate.setData(self.jid + "/" + self.sid)
self.active_connection.send(iq)
self.state = S_ACTIVATED
def keep_conf(self):
self.state = S_FINISHED
def _on_connect_failure(self):
......@@ -139,6 +155,7 @@ class ProxyResolver:
self.jid = None
self.host = None
self.port = None
self.sid = helpers.get_random_string_16()
class HostTester(Socks5, IdleObject):
''' fake proxy tester. '''
......
......@@ -525,15 +525,6 @@ _('Connection with peer cannot be established.'))
return iter
iter = self.model.iter_next(iter)
def get_sid(self):
''' create random string of length 16'''
rng = range(65, 90)
rng.extend(range(48, 57))
char_sequence = map(lambda e:chr(e), rng)
from random import sample
return reduce(lambda e1, e2: e1 + e2,
sample(char_sequence, 16))
def get_send_file_props(self, account, contact, file_path, file_name):
''' create new file_props dict and set initial file transfer
properties in it'''
......@@ -551,7 +542,7 @@ _('Connection with peer cannot be established.'))
return None
file_props['elapsed-time'] = 0
file_props['size'] = unicode(stat[6])
file_props['sid'] = self.get_sid()
file_props['sid'] = helpers.get_random_string_16()
file_props['completed'] = False
file_props['started'] = False
file_props['sender'] = account
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment