fixsending through a proxy

This commit is contained in:
Yann Leboulanger 2012-08-28 19:10:13 +02:00
parent 27a8cf325a
commit 2bcc753c67
2 changed files with 32 additions and 29 deletions

View File

@ -41,7 +41,7 @@ from common import dataforms
from common import ged from common import ged
from common import jingle_xtls from common import jingle_xtls
from common.file_props import FilesProp from common.file_props import FilesProp
from common.socks5 import Socks5ReceiverClient from common.socks5 import Socks5SenderClient
import logging import logging
log = logging.getLogger('gajim.c.p.bytestream') log = logging.getLogger('gajim.c.p.bytestream')
@ -581,8 +581,8 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
""" """
if not self.connection or self.connected < 2: if not self.connection or self.connected < 2:
return return
file_props = FilesProp.getFileProp(self.connection, proxy['sid']) file_props = FilesProp.getFileProp(self.name, proxy['sid'])
iq = xmpp.Iq(to=proxy['initiator'], typ='set') iq = xmpp.Iq(to=proxy['initiator'], typ='set')
auth_id = "au_" + proxy['sid'] auth_id = "au_" + proxy['sid']
iq.setID(auth_id) iq.setID(auth_id)
query = iq.setTag('query', namespace=xmpp.NS_BYTESTREAM) query = iq.setTag('query', namespace=xmpp.NS_BYTESTREAM)
@ -721,10 +721,15 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
file_props.streamhost_used = True file_props.streamhost_used = True
file_props.streamhosts.append(proxy) file_props.streamhosts.append(proxy)
file_props.is_a_proxy = True file_props.is_a_proxy = True
receiver = Socks5ReceiverClient(gajim.idlequeue, proxy, idx = gajim.socks5queue.idx
file_props.sid, file_props) sender = Socks5SenderClient(gajim.idlequeue, idx,
proxy['idx'] = receiver.queue_idx gajim.socks5queue, _sock=None, host=str(proxy['host']),
gajim.socks5queue.on_success = self._proxy_auth_ok port=int(proxy['port']), fingerprint=None,
connected=False, file_props=file_props)
sender.streamhost = proxy
gajim.socks5queue.add_sockobj(self.name, sender, 'sender')
proxy['idx'] = sender.queue_idx
gajim.socks5queue.on_success[file_props.sid] = self._proxy_auth_ok
raise xmpp.NodeProcessed raise xmpp.NodeProcessed
else: else:

View File

@ -263,32 +263,30 @@ class SocksQueue:
props[0](props[1], idx) props[0](props[1], idx)
def activate_proxy(self, idx): def activate_proxy(self, idx):
if not self.isHashInSockObjs(self.readers, idx): if not self.isHashInSockObjs(self.senders, idx):
return return
for key in self.readers.keys(): for key in self.senders.keys():
if idx in key: if idx in key:
reader = self.readers[key] sender = self.senders[key]
if reader.file_props.type_ != 's': if sender.file_props.type_ != 's':
return return
if reader.state != 5: sender.state = 6
return if sender.connected:
reader.state = 6 sender.file_props.error = 0
if reader.connected: sender.file_props.disconnect_cb = sender.disconnect
reader.file_props.error = 0 sender.file_props.started = True
reader.file_props.disconnect_cb = reader.disconnect sender.file_props.completed = False
reader.file_props.started = True sender.file_props.paused = False
reader.file_props.completed = False sender.file_props.stalled = False
reader.file_props.paused = False sender.file_props.elapsed_time = 0
reader.file_props.stalled = False sender.file_props.last_time = self.idlequeue.current_time()
reader.file_props.elapsed_time = 0 sender.file_props.received_len = 0
reader.file_props.last_time = self.idlequeue.current_time() sender.pauses = 0
reader.file_props.received_len = 0
reader.pauses = 0
# start sending file to proxy # start sending file to proxy
self.idlequeue.set_read_timeout(reader.fd, STALLED_TIMEOUT) self.idlequeue.set_read_timeout(sender.fd, STALLED_TIMEOUT)
self.idlequeue.plug_idle(reader, True, False) self.idlequeue.plug_idle(sender, True, False)
result = reader.write_next() result = sender.write_next()
self.process_result(result, reader) self.process_result(result, sender)
def send_file(self, file_props, account, mode): def send_file(self, file_props, account, mode):
for key in self.senders.keys(): for key in self.senders.keys():