socks5 proxy fixed
This commit is contained in:
parent
4c112419c0
commit
212f33cafa
5 changed files with 127 additions and 84 deletions
|
@ -101,7 +101,6 @@ class JingleContent(object):
|
||||||
Add a list of candidates to the list of remote candidates
|
Add a list of candidates to the list of remote candidates
|
||||||
"""
|
"""
|
||||||
self.transport.remote_candidates = candidates
|
self.transport.remote_candidates = candidates
|
||||||
pass
|
|
||||||
|
|
||||||
def on_stanza(self, stanza, content, error, action):
|
def on_stanza(self, stanza, content, error, action):
|
||||||
"""
|
"""
|
||||||
|
@ -112,15 +111,14 @@ class JingleContent(object):
|
||||||
callback(stanza, content, error, action)
|
callback(stanza, content, error, action)
|
||||||
|
|
||||||
def __on_transport_replace(self, stanza, content, error, action):
|
def __on_transport_replace(self, stanza, content, error, action):
|
||||||
|
|
||||||
content.addChild(node=self.transport.make_transport())
|
content.addChild(node=self.transport.make_transport())
|
||||||
|
|
||||||
def __on_transport_info(self, stanza, content, error, action):
|
def __on_transport_info(self, stanza, content, error, action):
|
||||||
"""
|
"""
|
||||||
Got a new transport candidate
|
Got a new transport candidate
|
||||||
"""
|
"""
|
||||||
candidates = self.transport.parse_transport_stanza(
|
candidates = self.transport.parse_transport_stanza(
|
||||||
content.getTag('transport'))
|
content.getTag('transport'))
|
||||||
if candidates:
|
if candidates:
|
||||||
self.add_remote_candidates(candidates)
|
self.add_remote_candidates(candidates)
|
||||||
|
|
||||||
|
@ -139,7 +137,7 @@ class JingleContent(object):
|
||||||
content = self.__content()
|
content = self.__content()
|
||||||
content.addChild(node=self.transport.make_transport([candidate]))
|
content.addChild(node=self.transport.make_transport([candidate]))
|
||||||
self.session.send_transport_info(content)
|
self.session.send_transport_info(content)
|
||||||
|
|
||||||
def send_error_candidate(self):
|
def send_error_candidate(self):
|
||||||
"""
|
"""
|
||||||
Sends a candidate-error when we can't connect to a candidate.
|
Sends a candidate-error when we can't connect to a candidate.
|
||||||
|
@ -149,7 +147,7 @@ class JingleContent(object):
|
||||||
tp.addChild(name='candidate-error')
|
tp.addChild(name='candidate-error')
|
||||||
content.addChild(node=tp)
|
content.addChild(node=tp)
|
||||||
self.session.send_transport_info(content)
|
self.session.send_transport_info(content)
|
||||||
|
|
||||||
|
|
||||||
def send_description_info(self):
|
def send_description_info(self):
|
||||||
content = self.__content()
|
content = self.__content()
|
||||||
|
|
|
@ -24,7 +24,7 @@ import xmpp
|
||||||
from jingle_content import contents, JingleContent
|
from jingle_content import contents, JingleContent
|
||||||
from jingle_transport import JingleTransportICEUDP, JingleTransportSocks5
|
from jingle_transport import JingleTransportICEUDP, JingleTransportSocks5
|
||||||
from common import helpers
|
from common import helpers
|
||||||
from common.socks5 import Socks5Receiver
|
from common.socks5 import Socks5Receiver, Socks5Sender
|
||||||
from common.connection_handlers_events import FileRequestReceivedEvent
|
from common.connection_handlers_events import FileRequestReceivedEvent
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
@ -181,6 +181,14 @@ class JingleFileTransfer(JingleContent):
|
||||||
self.state = STATE_CAND_RECEIVED_PENDING_REPLY
|
self.state = STATE_CAND_RECEIVED_PENDING_REPLY
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if content.getTag('transport').getTag('activated'):
|
||||||
|
self.state = STATE_TRANSFERING
|
||||||
|
jid = gajim.get_jid_without_resource(self.session.ourjid)
|
||||||
|
gajim.socks5queue.send_file(self.file_props,
|
||||||
|
self.session.connection.name, 'client')
|
||||||
|
return
|
||||||
|
|
||||||
streamhost_cid = content.getTag('transport').getTag('candidate-used').\
|
streamhost_cid = content.getTag('transport').getTag('candidate-used').\
|
||||||
getAttr('cid')
|
getAttr('cid')
|
||||||
streamhost_used = None
|
streamhost_used = None
|
||||||
|
@ -274,7 +282,7 @@ class JingleFileTransfer(JingleContent):
|
||||||
self.session.send_transport_info(content)
|
self.session.send_transport_info(content)
|
||||||
|
|
||||||
|
|
||||||
def _on_connect_error(self, to, _id, sid, code=404):
|
def _on_connect_error(self, sid):
|
||||||
self.nominated_cand['our-cand'] = False
|
self.nominated_cand['our-cand'] = False
|
||||||
self.send_error_candidate()
|
self.send_error_candidate()
|
||||||
|
|
||||||
|
@ -321,7 +329,6 @@ class JingleFileTransfer(JingleContent):
|
||||||
|
|
||||||
receiver = self.file_props['receiver']
|
receiver = self.file_props['receiver']
|
||||||
sender = self.file_props['sender']
|
sender = self.file_props['sender']
|
||||||
|
|
||||||
sha_str = helpers.get_auth_sha(self.file_props['sid'], sender,
|
sha_str = helpers.get_auth_sha(self.file_props['sid'], sender,
|
||||||
receiver)
|
receiver)
|
||||||
self.file_props['sha_str'] = sha_str
|
self.file_props['sha_str'] = sha_str
|
||||||
|
@ -368,36 +375,52 @@ class JingleFileTransfer(JingleContent):
|
||||||
|
|
||||||
self.state = STATE_TRANSFERING
|
self.state = STATE_TRANSFERING
|
||||||
|
|
||||||
# It tells wether we start the transfer as client or server
|
|
||||||
type = None
|
|
||||||
|
|
||||||
if self.isOurCandUsed():
|
if self.isOurCandUsed():
|
||||||
type = 'client'
|
|
||||||
streamhost_used = self.nominated_cand['our-cand']
|
streamhost_used = self.nominated_cand['our-cand']
|
||||||
else:
|
else:
|
||||||
type = 'server'
|
|
||||||
streamhost_used = self.nominated_cand['peer-cand']
|
streamhost_used = self.nominated_cand['peer-cand']
|
||||||
|
|
||||||
|
if streamhost_used['type'] == 'proxy':
|
||||||
|
self.file_props['is_a_proxy'] = True
|
||||||
|
|
||||||
# FIXME if streamhost_used is none where do we get the proxy host
|
if not self.weinitiate and streamhost_used['type'] == 'proxy':
|
||||||
if streamhost_used and streamhost_used['type'] == 'proxy':
|
r = gajim.socks5queue.readers
|
||||||
|
for reader in r:
|
||||||
|
if r[reader].host == streamhost_used['host'] and \
|
||||||
|
r[reader].connected:
|
||||||
|
return
|
||||||
|
|
||||||
|
if streamhost_used['type'] == 'proxy':
|
||||||
self.file_props['streamhost-used'] = True
|
self.file_props['streamhost-used'] = True
|
||||||
for proxy in self.file_props['proxyhosts']:
|
streamhost_used['sid'] = self.file_props['sid']
|
||||||
if proxy['host'] == streamhost_used['host'] and \
|
self.file_props['streamhosts'] = []
|
||||||
proxy['port'] == streamhost_used['port'] and \
|
self.file_props['streamhosts'].append(streamhost_used)
|
||||||
proxy['jid'] == streamhost_used['jid']:
|
self.file_props['proxyhosts'] = []
|
||||||
host_used = proxy
|
self.file_props['proxyhosts'].append(streamhost_used)
|
||||||
break
|
self.file_props['is_a_proxy'] = True
|
||||||
if 'streamhosts' not in self.file_props:
|
|
||||||
self.file_props['streamhosts'] = []
|
gajim.socks5queue.idx += 1
|
||||||
self.file_props['streamhosts'].append(streamhost_used)
|
idx = gajim.socks5queue.idx
|
||||||
self.file_props['is_a_proxy'] = True
|
sockobj = Socks5Sender(gajim.idlequeue, idx,
|
||||||
receiver = Socks5Receiver(gajim.idlequeue, streamhost_used,
|
gajim.socks5queue,
|
||||||
self.file_props['sid'], self.file_props)
|
mode='client',
|
||||||
gajim.socks5queue.add_receiver(self.session.connection.name,
|
_sock=None,
|
||||||
receiver)
|
host=str(streamhost_used['host']),
|
||||||
streamhost_used['idx'] = receiver.queue_idx
|
port=int(streamhost_used['port']),
|
||||||
|
fingerprint=None,
|
||||||
|
connected=False,
|
||||||
|
file_props=self.file_props)
|
||||||
|
sockobj.proxy = True
|
||||||
|
sockobj.streamhost = streamhost_used
|
||||||
|
gajim.socks5queue.add_sockobj(self.session.connection.name,
|
||||||
|
sockobj, 'sender')
|
||||||
|
streamhost_used['idx'] = sockobj.queue_idx
|
||||||
|
# If we offered the nominated candidate used, we activate
|
||||||
|
# the proxy
|
||||||
|
if not self.isOurCandUsed():
|
||||||
gajim.socks5queue.on_success[self.file_props['sid']] = \
|
gajim.socks5queue.on_success[self.file_props['sid']] = \
|
||||||
self.transport._on_proxy_auth_ok
|
self.transport._on_proxy_auth_ok
|
||||||
|
# TODO: add on failure
|
||||||
else:
|
else:
|
||||||
jid = gajim.get_jid_without_resource(self.session.ourjid)
|
jid = gajim.get_jid_without_resource(self.session.ourjid)
|
||||||
gajim.socks5queue.send_file(self.file_props,
|
gajim.socks5queue.send_file(self.file_props,
|
||||||
|
|
|
@ -118,7 +118,7 @@ class JingleTransportSocks5(JingleTransport):
|
||||||
return xmpp.Node('candidate', attrs=attrs)
|
return xmpp.Node('candidate', attrs=attrs)
|
||||||
|
|
||||||
def make_transport(self, candidates=None, add_candidates = True):
|
def make_transport(self, candidates=None, add_candidates = True):
|
||||||
if add_candidates:
|
if add_candidates:
|
||||||
self._add_local_ips_as_candidates()
|
self._add_local_ips_as_candidates()
|
||||||
self._add_additional_candidates()
|
self._add_additional_candidates()
|
||||||
self._add_proxy_candidates()
|
self._add_proxy_candidates()
|
||||||
|
@ -139,10 +139,10 @@ class JingleTransportSocks5(JingleTransport):
|
||||||
'state': 0,
|
'state': 0,
|
||||||
'target': self.ourjid,
|
'target': self.ourjid,
|
||||||
'host': candidate['host'],
|
'host': candidate['host'],
|
||||||
'port': candidate['port'],
|
'port': int(candidate['port']),
|
||||||
'cid': candidate['cid'],
|
'cid': candidate['cid'],
|
||||||
'type': typ,
|
'type': typ,
|
||||||
'priority': candidate['priority']
|
'priority': candidate['priority']
|
||||||
}
|
}
|
||||||
candidates.append(cand)
|
candidates.append(cand)
|
||||||
|
|
||||||
|
@ -151,11 +151,22 @@ class JingleTransportSocks5(JingleTransport):
|
||||||
return candidates
|
return candidates
|
||||||
|
|
||||||
|
|
||||||
|
def _add_candidates(self, candidates):
|
||||||
|
for cand in candidates:
|
||||||
|
in_remote = False
|
||||||
|
for cand2 in self.remote_candidates:
|
||||||
|
if cand['host'] == cand2['host'] and \
|
||||||
|
cand['port'] == cand2['port']:
|
||||||
|
in_remote = True
|
||||||
|
break
|
||||||
|
if not in_remote:
|
||||||
|
self.candidates.append(cand)
|
||||||
|
|
||||||
def _add_local_ips_as_candidates(self):
|
def _add_local_ips_as_candidates(self):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return
|
||||||
local_ip_cand = []
|
local_ip_cand = []
|
||||||
port = gajim.config.get('file_transfers_port')
|
port = int(gajim.config.get('file_transfers_port'))
|
||||||
type_preference = 126 #type preference of connection type. XEP-0260 section 2.2
|
type_preference = 126 #type preference of connection type. XEP-0260 section 2.2
|
||||||
c = {'host': self.connection.peerhost[0]}
|
c = {'host': self.connection.peerhost[0]}
|
||||||
c['candidate_id'] = self.connection.connection.getAnID()
|
c['candidate_id'] = self.connection.connection.getAnID()
|
||||||
|
@ -178,14 +189,14 @@ class JingleTransportSocks5(JingleTransport):
|
||||||
c['target'] = self.file_props['receiver']
|
c['target'] = self.file_props['receiver']
|
||||||
local_ip_cand.append(c)
|
local_ip_cand.append(c)
|
||||||
|
|
||||||
self.candidates += local_ip_cand
|
self._add_candidates(local_ip_cand)
|
||||||
|
|
||||||
def _add_additional_candidates(self):
|
def _add_additional_candidates(self):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return
|
||||||
type_preference = 126
|
type_preference = 126
|
||||||
additional_ip_cand = []
|
additional_ip_cand = []
|
||||||
port = gajim.config.get('file_transfers_port')
|
port = int(gajim.config.get('file_transfers_port'))
|
||||||
ft_add_hosts = gajim.config.get('ft_add_hosts_to_send')
|
ft_add_hosts = gajim.config.get('ft_add_hosts_to_send')
|
||||||
|
|
||||||
if ft_add_hosts:
|
if ft_add_hosts:
|
||||||
|
@ -200,7 +211,8 @@ class JingleTransportSocks5(JingleTransport):
|
||||||
c['initiator'] = self.file_props['sender']
|
c['initiator'] = self.file_props['sender']
|
||||||
c['target'] = self.file_props['receiver']
|
c['target'] = self.file_props['receiver']
|
||||||
additional_ip_cand.append(c)
|
additional_ip_cand.append(c)
|
||||||
self.candidates += additional_ip_cand
|
|
||||||
|
self._add_candidates(additional_ip_cand)
|
||||||
|
|
||||||
def _add_proxy_candidates(self):
|
def _add_proxy_candidates(self):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
|
@ -219,14 +231,15 @@ class JingleTransportSocks5(JingleTransport):
|
||||||
for proxyhost in proxyhosts:
|
for proxyhost in proxyhosts:
|
||||||
c = {'host': proxyhost['host']}
|
c = {'host': proxyhost['host']}
|
||||||
c['candidate_id'] = self.connection.connection.getAnID()
|
c['candidate_id'] = self.connection.connection.getAnID()
|
||||||
c['port'] = proxyhost['port']
|
c['port'] = int(proxyhost['port'])
|
||||||
c['type'] = 'proxy'
|
c['type'] = 'proxy'
|
||||||
c['jid'] = proxyhost['jid']
|
c['jid'] = proxyhost['jid']
|
||||||
c['priority'] = (2**16) * type_preference
|
c['priority'] = (2**16) * type_preference
|
||||||
c['initiator'] = self.file_props['sender']
|
c['initiator'] = self.file_props['sender']
|
||||||
c['target'] = self.file_props['receiver']
|
c['target'] = self.file_props['receiver']
|
||||||
proxy_cand.append(c)
|
proxy_cand.append(c)
|
||||||
self.candidates += proxy_cand
|
|
||||||
|
self._add_candidates(proxy_cand)
|
||||||
|
|
||||||
def get_content(self):
|
def get_content(self):
|
||||||
sesn = self.connection.get_jingle_session(self.ourjid,
|
sesn = self.connection.get_jingle_session(self.ourjid,
|
||||||
|
@ -240,54 +253,59 @@ class JingleTransportSocks5(JingleTransport):
|
||||||
# send activate request to proxy, send activated confirmation to peer
|
# send activate request to proxy, send activated confirmation to peer
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return
|
||||||
file_props = self.file_props
|
sesn = self.connection.get_jingle_session(self.ourjid,
|
||||||
iq = xmpp.Iq(to=proxy['initiator'], typ='set')
|
self.file_props['session-sid'])
|
||||||
|
if sesn is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
iq = xmpp.Iq(to=proxy['jid'], frm=self.ourjid, 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)
|
||||||
query.setAttr('sid', proxy['sid'])
|
query.setAttr('sid', proxy['sid'])
|
||||||
activate = query.setTag('activate')
|
activate = query.setTag('activate')
|
||||||
activate.setData(file_props['proxy_receiver'])
|
activate.setData(sesn.peerjid)
|
||||||
iq.setID(auth_id)
|
iq.setID(auth_id)
|
||||||
self.connection.connection.send(iq)
|
self.connection.connection.send(iq)
|
||||||
|
|
||||||
|
|
||||||
content = xmpp.Node('content')
|
content = xmpp.Node('content')
|
||||||
content.setAttr('creator', 'initiator')
|
content.setAttr('creator', 'initiator')
|
||||||
c = self.get_content()
|
c = self.get_content()
|
||||||
content.setAttr('name', c.name)
|
content.setAttr('name', c.name)
|
||||||
transport = xmpp.Node('transport')
|
transport = xmpp.Node('transport')
|
||||||
transport.setNamespace(xmpp.NS_JINGLE_BYTESTREAM)
|
transport.setNamespace(xmpp.NS_JINGLE_BYTESTREAM)
|
||||||
|
transport.setAttr('sid', proxy['sid'])
|
||||||
activated = xmpp.Node('activated')
|
activated = xmpp.Node('activated')
|
||||||
cid = None
|
cid = None
|
||||||
for host in self.candidates:
|
|
||||||
if host['host'] == proxy['host'] and host['jid'] == proxy['jid'] \
|
if 'cid' in proxy:
|
||||||
and host['port'] == proxy['port']:
|
cid = proxy['cid']
|
||||||
cid = host['candidate_id']
|
else:
|
||||||
break
|
for host in self.candidates:
|
||||||
|
if host['host'] == proxy['host'] and host['jid'] == proxy['jid'] \
|
||||||
|
and host['port'] == proxy['port']:
|
||||||
|
cid = host['candidate_id']
|
||||||
|
break
|
||||||
if cid is None:
|
if cid is None:
|
||||||
return
|
raise Exception, 'cid is missing'
|
||||||
activated.setAttr('cid', cid)
|
activated.setAttr('cid', cid)
|
||||||
transport.addChild(node=activated)
|
transport.addChild(node=activated)
|
||||||
content.addChild(node=transport)
|
content.addChild(node=transport)
|
||||||
sesn = self.connection.get_jingle_session(self.ourjid,
|
|
||||||
self.file_props['session-sid'])
|
|
||||||
|
|
||||||
if sesn is None:
|
|
||||||
return
|
|
||||||
sesn.send_transport_info(content)
|
sesn.send_transport_info(content)
|
||||||
|
|
||||||
|
|
||||||
class JingleTransportIBB(JingleTransport):
|
class JingleTransportIBB(JingleTransport):
|
||||||
|
|
||||||
def __init__(self, node=None, block_sz=None):
|
def __init__(self, node=None, block_sz=None):
|
||||||
|
|
||||||
JingleTransport.__init__(self, TransportType.streaming)
|
JingleTransport.__init__(self, TransportType.streaming)
|
||||||
|
|
||||||
if block_sz:
|
if block_sz:
|
||||||
self.block_sz = block_sz
|
self.block_sz = block_sz
|
||||||
else:
|
else:
|
||||||
self.block_sz = '4096'
|
self.block_sz = '4096'
|
||||||
|
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self.sid = None
|
self.sid = None
|
||||||
if node and node.getAttr('sid'):
|
if node and node.getAttr('sid'):
|
||||||
|
@ -296,19 +314,19 @@ class JingleTransportIBB(JingleTransport):
|
||||||
|
|
||||||
def set_sid(self, sid):
|
def set_sid(self, sid):
|
||||||
self.sid = sid
|
self.sid = sid
|
||||||
|
|
||||||
def make_transport(self):
|
def make_transport(self):
|
||||||
|
|
||||||
transport = xmpp.Node('transport')
|
transport = xmpp.Node('transport')
|
||||||
transport.setNamespace(xmpp.NS_JINGLE_IBB)
|
transport.setNamespace(xmpp.NS_JINGLE_IBB)
|
||||||
transport.setAttr('block-size', self.block_sz)
|
transport.setAttr('block-size', self.block_sz)
|
||||||
transport.setAttr('sid', self.sid)
|
transport.setAttr('sid', self.sid)
|
||||||
return transport
|
return transport
|
||||||
|
|
||||||
def set_file_props(self, file_props):
|
def set_file_props(self, file_props):
|
||||||
self.file_props = file_props
|
self.file_props = file_props
|
||||||
|
|
||||||
|
|
||||||
import farsight
|
import farsight
|
||||||
|
|
||||||
class JingleTransportICEUDP(JingleTransport):
|
class JingleTransportICEUDP(JingleTransport):
|
||||||
|
|
|
@ -363,7 +363,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
|
||||||
|
|
||||||
port = gajim.config.get('file_transfers_port')
|
port = gajim.config.get('file_transfers_port')
|
||||||
listener = gajim.socks5queue.start_listener(port, sha_str,
|
listener = gajim.socks5queue.start_listener(port, sha_str,
|
||||||
self._result_socks5_sid, file_props['sid'])
|
self._result_socks5_sid, file_props)
|
||||||
if not listener:
|
if not listener:
|
||||||
file_props['error'] = -5
|
file_props['error'] = -5
|
||||||
from common.connection_handlers_events import FileRequestErrorEvent
|
from common.connection_handlers_events import FileRequestErrorEvent
|
||||||
|
@ -660,7 +660,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
|
||||||
if 'stopped' in file_props and file_props['stopped']:
|
if 'stopped' in file_props and file_props['stopped']:
|
||||||
self.remove_transfer(file_props)
|
self.remove_transfer(file_props)
|
||||||
else:
|
else:
|
||||||
gajim.socks5queue.send_file(file_props, self.name)
|
gajim.socks5queue.send_file(file_props, self.name, 'client')
|
||||||
if 'fast' in file_props:
|
if 'fast' in file_props:
|
||||||
fasts = file_props['fast']
|
fasts = file_props['fast']
|
||||||
if len(fasts) > 0:
|
if len(fasts) > 0:
|
||||||
|
|
|
@ -113,8 +113,8 @@ class SocksQueue:
|
||||||
file_props['streamhost-used'] is True:
|
file_props['streamhost-used'] is True:
|
||||||
if 'proxyhosts' in file_props:
|
if 'proxyhosts' in file_props:
|
||||||
for proxy in file_props['proxyhosts']:
|
for proxy in file_props['proxyhosts']:
|
||||||
if proxy == streamhost:
|
if proxy['host'] == streamhost['host']:
|
||||||
self.on_success[file_props['sid']](streamhost)
|
self.on_success[file_props['sid']](proxy)
|
||||||
return 2
|
return 2
|
||||||
return 0
|
return 0
|
||||||
if 'streamhosts' in file_props:
|
if 'streamhosts' in file_props:
|
||||||
|
@ -145,8 +145,13 @@ class SocksQueue:
|
||||||
'client', file_props, fingerprint=fp)
|
'client', file_props, fingerprint=fp)
|
||||||
self.add_sockobj(account, socks5obj)
|
self.add_sockobj(account, socks5obj)
|
||||||
else:
|
else:
|
||||||
|
if 'sha_str' in file_props:
|
||||||
|
idx = file_props['sha_str']
|
||||||
|
else:
|
||||||
|
idx = self.idx
|
||||||
|
self.idx = self.idx + 1
|
||||||
self.type = 'sender'
|
self.type = 'sender'
|
||||||
socks5obj = Socks5Sender(self.idlequeue, file_props['sha_str'],
|
socks5obj = Socks5Sender(self.idlequeue, idx,
|
||||||
self, mode='client' , _sock=None,
|
self, mode='client' , _sock=None,
|
||||||
host=str(streamhost['host']), port=int(streamhost['port']),
|
host=str(streamhost['host']), port=int(streamhost['port']),
|
||||||
fingerprint=fp, connected=False, file_props=file_props)
|
fingerprint=fp, connected=False, file_props=file_props)
|
||||||
|
@ -202,7 +207,6 @@ class SocksQueue:
|
||||||
if host['state'] == -2:
|
if host['state'] == -2:
|
||||||
host['state'] = 0
|
host['state'] = 0
|
||||||
# FIXME: make the sender reconnect also
|
# FIXME: make the sender reconnect also
|
||||||
print 'reconnecting using socks receiver'
|
|
||||||
client = Socks5Receiver(self.idlequeue, host, host['sid'],
|
client = Socks5Receiver(self.idlequeue, host, host['sid'],
|
||||||
'client',file_props)
|
'client',file_props)
|
||||||
self.add_sockobj(client.account, client)
|
self.add_sockobj(client.account, client)
|
||||||
|
@ -225,15 +229,16 @@ class SocksQueue:
|
||||||
if file_props is None:
|
if file_props is None:
|
||||||
return
|
return
|
||||||
streamhost['state'] = -1
|
streamhost['state'] = -1
|
||||||
|
# FIXME: should only the receiver be remove? what if we are sending?
|
||||||
self.remove_receiver(idx, False)
|
self.remove_receiver(idx, False)
|
||||||
if 'streamhosts' in file_props:
|
if 'streamhosts' in file_props:
|
||||||
for host in file_props['streamhosts']:
|
for host in file_props['streamhosts']:
|
||||||
if host['state'] != -1:
|
if host['state'] != -1:
|
||||||
return
|
return
|
||||||
|
self.readers = {}
|
||||||
# failure_cb exists - this means that it has never been called
|
# failure_cb exists - this means that it has never been called
|
||||||
if 'failure_cb' in file_props and file_props['failure_cb']:
|
if 'failure_cb' in file_props and file_props['failure_cb']:
|
||||||
file_props['failure_cb'](streamhost['initiator'], None,
|
file_props['failure_cb'](file_props['sid'])
|
||||||
file_props['sid'], code = 404)
|
|
||||||
del(file_props['failure_cb'])
|
del(file_props['failure_cb'])
|
||||||
|
|
||||||
def add_sockobj(self, account, sockobj, type='receiver'):
|
def add_sockobj(self, account, sockobj, type='receiver'):
|
||||||
|
@ -306,15 +311,10 @@ class SocksQueue:
|
||||||
sender = self.senders[key]
|
sender = self.senders[key]
|
||||||
file_props['streamhost-used'] = True
|
file_props['streamhost-used'] = True
|
||||||
sender.account = account
|
sender.account = account
|
||||||
if file_props['type'] == 's':
|
|
||||||
sender.file_props = file_props
|
sender.file_props = file_props
|
||||||
result = sender.send_file()
|
result = sender.send_file()
|
||||||
self.process_result(result, sender)
|
self.process_result(result, sender)
|
||||||
else:
|
|
||||||
file_props['elapsed-time'] = 0
|
|
||||||
file_props['last-time'] = self.idlequeue.current_time()
|
|
||||||
file_props['received-len'] = 0
|
|
||||||
sender.file_props = file_props
|
|
||||||
|
|
||||||
def add_file_props(self, account, file_props):
|
def add_file_props(self, account, file_props):
|
||||||
"""
|
"""
|
||||||
|
@ -611,6 +611,10 @@ class Socks5:
|
||||||
if self.queue.on_success:
|
if self.queue.on_success:
|
||||||
result = self.queue.send_success_reply(self.file_props,
|
result = self.queue.send_success_reply(self.file_props,
|
||||||
self.streamhost)
|
self.streamhost)
|
||||||
|
if self.type == 'sender' and self.proxy:
|
||||||
|
self.queue.process_result( self.send_file()
|
||||||
|
, self)
|
||||||
|
return
|
||||||
|
|
||||||
if result == 0:
|
if result == 0:
|
||||||
self.state = 8
|
self.state = 8
|
||||||
|
@ -1143,6 +1147,7 @@ class Socks5:
|
||||||
"""
|
"""
|
||||||
Get sha of sid + Initiator jid + Target jid
|
Get sha of sid + Initiator jid + Target jid
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if 'is_a_proxy' in self.file_props:
|
if 'is_a_proxy' in self.file_props:
|
||||||
del(self.file_props['is_a_proxy'])
|
del(self.file_props['is_a_proxy'])
|
||||||
return hashlib.sha1('%s%s%s' % (self.sid,
|
return hashlib.sha1('%s%s%s' % (self.sid,
|
||||||
|
@ -1164,10 +1169,10 @@ class Socks5Sender(Socks5, IdleObject):
|
||||||
self.queue = parent
|
self.queue = parent
|
||||||
self.mode = mode # client or server
|
self.mode = mode # client or server
|
||||||
self.file_props = file_props
|
self.file_props = file_props
|
||||||
|
self.proxy = False
|
||||||
|
|
||||||
|
|
||||||
|
Socks5.__init__(self, idlequeue, host, port, None, None,file_props['sid'])
|
||||||
Socks5.__init__(self, idlequeue, host, port, None, None, None)
|
|
||||||
self._sock = _sock
|
self._sock = _sock
|
||||||
|
|
||||||
|
|
||||||
|
@ -1380,7 +1385,6 @@ class Socks5Receiver(Socks5, IdleObject):
|
||||||
"""
|
"""
|
||||||
Start receiving the file over verified connection
|
Start receiving the file over verified connection
|
||||||
"""
|
"""
|
||||||
print "receiving file"
|
|
||||||
if self.file_props['started']:
|
if self.file_props['started']:
|
||||||
return
|
return
|
||||||
self.file_props['error'] = 0
|
self.file_props['error'] = 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue