From e4fa96cce3aab9f057a4e1283ee490c9e4621bfa Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 2 Nov 2011 00:09:33 +0100 Subject: [PATCH] make jingleFT work when receiver's proxy is used --- src/common/jingle_ft.py | 29 +++++++++++++++++++++++------ src/common/jingle_transport.py | 3 --- src/common/socks5.py | 6 +++++- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/common/jingle_ft.py b/src/common/jingle_ft.py index 527673eda..c0a0ae412 100644 --- a/src/common/jingle_ft.py +++ b/src/common/jingle_ft.py @@ -387,6 +387,12 @@ class JingleFileTransfer(JingleContent): if streamhost_used['type'] == 'proxy': self.file_props['is_a_proxy'] = True + if self.weinitiate: + self.file_props['proxy_sender'] = streamhost_used['initiator'] + self.file_props['proxy_receiver'] = streamhost_used['target'] + else: + self.file_props['proxy_sender'] = streamhost_used['target'] + self.file_props['proxy_receiver'] = streamhost_used['initiator'] if not self.weinitiate and streamhost_used['type'] == 'proxy': r = gajim.socks5queue.readers @@ -394,7 +400,14 @@ class JingleFileTransfer(JingleContent): if r[reader].host == streamhost_used['host'] and \ r[reader].connected: return - + + if self.weinitiate and streamhost_used['type'] == 'proxy': + s = gajim.socks5queue.senders + for sender in s: + if s[sender].host == streamhost_used['host'] and \ + s[sender].connected: + return + if streamhost_used['type'] == 'proxy': self.file_props['streamhost-used'] = True streamhost_used['sid'] = self.file_props['sid'] @@ -402,11 +415,11 @@ class JingleFileTransfer(JingleContent): self.file_props['streamhosts'].append(streamhost_used) self.file_props['proxyhosts'] = [] self.file_props['proxyhosts'].append(streamhost_used) - self.file_props['is_a_proxy'] = True - - gajim.socks5queue.idx += 1 - idx = gajim.socks5queue.idx - sockobj = Socks5Sender(gajim.idlequeue, idx, + + if self.weinitiate: + gajim.socks5queue.idx += 1 + idx = gajim.socks5queue.idx + sockobj = Socks5Sender(gajim.idlequeue, idx, gajim.socks5queue, mode='client', _sock=None, @@ -415,6 +428,10 @@ class JingleFileTransfer(JingleContent): fingerprint=None, connected=False, file_props=self.file_props) + else: + sockobj = Socks5Receiver(gajim.idlequeue, streamhost_used, + sid=self.file_props['sid'], mode='client', + file_props=self.file_props, fingerprint=None) sockobj.proxy = True sockobj.streamhost = streamhost_used gajim.socks5queue.add_sockobj(self.session.connection.name, diff --git a/src/common/jingle_transport.py b/src/common/jingle_transport.py index 868e0f373..1bed1aa1a 100644 --- a/src/common/jingle_transport.py +++ b/src/common/jingle_transport.py @@ -223,9 +223,6 @@ class JingleTransportSocks5(JingleTransport): proxyhosts = socks5conn._get_file_transfer_proxies_from_config(self.file_props) if proxyhosts: - self.file_props['proxy_receiver'] = unicode( - self.file_props['receiver']) - self.file_props['proxy_sender'] = unicode(self.file_props['sender']) self.file_props['proxyhosts'] = proxyhosts for proxyhost in proxyhosts: diff --git a/src/common/socks5.py b/src/common/socks5.py index faf3cce8a..cc3ad7753 100644 --- a/src/common/socks5.py +++ b/src/common/socks5.py @@ -115,7 +115,7 @@ class SocksQueue: for proxy in file_props['proxyhosts']: if proxy['host'] == streamhost['host']: self.on_success[file_props['sid']](proxy) - return 2 + return 1 return 0 if 'streamhosts' in file_props: for host in file_props['streamhosts']: @@ -154,6 +154,10 @@ class SocksQueue: idx = self.idx self.idx = self.idx + 1 self.type = 'sender' + if 'type' in streamhost and streamhost['type'] == 'proxy': + file_props['is_a_proxy'] = True + file_props['proxy_sender'] = streamhost['target'] + file_props['proxy_receiver'] = streamhost['initiator'] socks5obj = Socks5Sender(self.idlequeue, idx, self, mode='client' , _sock=None, host=str(streamhost['host']), port=int(streamhost['port']),