refactoring
This commit is contained in:
parent
a3d2696987
commit
6f9c540392
|
@ -197,8 +197,8 @@ class ConnectionJingle(object):
|
||||||
def get_files_info(self, hash_=None, name=None):
|
def get_files_info(self, hash_=None, name=None):
|
||||||
if hash_:
|
if hash_:
|
||||||
for f in self.files: # DEBUG
|
for f in self.files: # DEBUG
|
||||||
#if f['hash'] == '1294809248109223':
|
if f['hash'] == '1294809248109223':
|
||||||
if f['hash'] == hash_:
|
#if f['hash'] == hash_:
|
||||||
return f
|
return f
|
||||||
elif name:
|
elif name:
|
||||||
for f in self.files:
|
for f in self.files:
|
||||||
|
|
|
@ -155,7 +155,7 @@ class JingleFileTransfer(JingleContent):
|
||||||
h = xmpp.Hashes()
|
h = xmpp.Hashes()
|
||||||
hash_ = h.calculateHash(self.file_props.algo, file_)
|
hash_ = h.calculateHash(self.file_props.algo, file_)
|
||||||
# DEBUG
|
# DEBUG
|
||||||
#hash_ = '1294809248109223'
|
hash_ = '1294809248109223'
|
||||||
if not hash_:
|
if not hash_:
|
||||||
# Hash alogrithm not supported
|
# Hash alogrithm not supported
|
||||||
return
|
return
|
||||||
|
|
|
@ -153,37 +153,34 @@ class StateTransfering(JingleFileTransferStates):
|
||||||
streamhost_used = self.jft.nominated_cand['peer-cand']
|
streamhost_used = self.jft.nominated_cand['peer-cand']
|
||||||
if streamhost_used['type'] == 'proxy':
|
if streamhost_used['type'] == 'proxy':
|
||||||
self.jft.file_props.is_a_proxy = True
|
self.jft.file_props.is_a_proxy = True
|
||||||
# This needs to be changed when requesting
|
if self.jft.file_props.type_ == 's' and self.jft.weinitiate:
|
||||||
if self.jft.weinitiate:
|
|
||||||
self.jft.file_props.proxy_sender = streamhost_used['initiator']
|
self.jft.file_props.proxy_sender = streamhost_used['initiator']
|
||||||
self.jft.file_props.proxy_receiver = streamhost_used['target']
|
self.jft.file_props.proxy_receiver = streamhost_used['target']
|
||||||
else:
|
else:
|
||||||
self.jft.file_props.proxy_sender = streamhost_used['target']
|
self.jft.file_props.proxy_sender = streamhost_used['target']
|
||||||
self.jft.file_props.proxy_receiver = streamhost_used[
|
self.jft.file_props.proxy_receiver = streamhost_used[
|
||||||
'initiator']
|
'initiator']
|
||||||
# This needs to be changed when requesting
|
if self.jft.file_props.type_ == 's':
|
||||||
if not self.jft.weinitiate 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
|
|
||||||
# This needs to be changed when requesting
|
|
||||||
if self.jft.weinitiate and streamhost_used['type'] == 'proxy':
|
|
||||||
s = gajim.socks5queue.senders
|
s = gajim.socks5queue.senders
|
||||||
for sender in s:
|
for sender in s:
|
||||||
if s[sender].host == streamhost_used['host'] and \
|
if s[sender].host == streamhost_used['host'] and \
|
||||||
s[sender].connected:
|
s[sender].connected:
|
||||||
return
|
return
|
||||||
if streamhost_used['type'] == 'proxy':
|
elif self.jft.file_props.type_ == 'r':
|
||||||
|
r = gajim.socks5queue.readers
|
||||||
|
for reader in r:
|
||||||
|
if r[reader].host == streamhost_used['host'] and \
|
||||||
|
r[reader].connected:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
raise TypeError
|
||||||
self.jft.file_props.streamhost_used = True
|
self.jft.file_props.streamhost_used = True
|
||||||
streamhost_used['sid'] = self.jft.file_props.sid
|
streamhost_used['sid'] = self.jft.file_props.sid
|
||||||
self.jft.file_props.streamhosts = []
|
self.jft.file_props.streamhosts = []
|
||||||
self.jft.file_props.streamhosts.append(streamhost_used)
|
self.jft.file_props.streamhosts.append(streamhost_used)
|
||||||
self.jft.file_props.proxyhosts = []
|
self.jft.file_props.proxyhosts = []
|
||||||
self.jft.file_props.proxyhosts.append(streamhost_used)
|
self.jft.file_props.proxyhosts.append(streamhost_used)
|
||||||
# This needs to be changed when requesting
|
if self.jft.file_props.type_ == 's':
|
||||||
if self.jft.weinitiate:
|
|
||||||
gajim.socks5queue.idx += 1
|
gajim.socks5queue.idx += 1
|
||||||
idx = gajim.socks5queue.idx
|
idx = gajim.socks5queue.idx
|
||||||
sockobj = Socks5SenderClient(gajim.idlequeue, idx,
|
sockobj = Socks5SenderClient(gajim.idlequeue, idx,
|
||||||
|
@ -198,7 +195,7 @@ class StateTransfering(JingleFileTransferStates):
|
||||||
sockobj.proxy = True
|
sockobj.proxy = True
|
||||||
sockobj.streamhost = streamhost_used
|
sockobj.streamhost = streamhost_used
|
||||||
gajim.socks5queue.add_sockobj(self.jft.session.connection.name,
|
gajim.socks5queue.add_sockobj(self.jft.session.connection.name,
|
||||||
sockobj, 'sender')
|
sockobj)
|
||||||
streamhost_used['idx'] = sockobj.queue_idx
|
streamhost_used['idx'] = sockobj.queue_idx
|
||||||
# If we offered the nominated candidate used, we activate
|
# If we offered the nominated candidate used, we activate
|
||||||
# the proxy
|
# the proxy
|
||||||
|
@ -214,7 +211,6 @@ class StateTransfering(JingleFileTransferStates):
|
||||||
def action(self, args=None):
|
def action(self, args=None):
|
||||||
if self.jft.transport.type_ == TransportType.IBB:
|
if self.jft.transport.type_ == TransportType.IBB:
|
||||||
self.__start_IBB_transfer(self.jft.session.connection)
|
self.__start_IBB_transfer(self.jft.session.connection)
|
||||||
|
|
||||||
elif self.jft.transport.type_ == TransportType.SOCKS5:
|
elif self.jft.transport.type_ == TransportType.SOCKS5:
|
||||||
self.__start_SOCK5_transfer()
|
self.__start_SOCK5_transfer()
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,6 @@ class SocksQueue:
|
||||||
authentication using sid for generated SHA
|
authentication using sid for generated SHA
|
||||||
"""
|
"""
|
||||||
sid = file_props.sid
|
sid = file_props.sid
|
||||||
self.type_ = typ # It says whether we are sending or receiving
|
|
||||||
self.sha_handlers[sha_str] = (sha_handler, sid)
|
self.sha_handlers[sha_str] = (sha_handler, sid)
|
||||||
if self.listener is None or self.listener.connections == []:
|
if self.listener is None or self.listener.connections == []:
|
||||||
self.listener = Socks5Listener(self.idlequeue, port, file_props,
|
self.listener = Socks5Listener(self.idlequeue, port, file_props,
|
||||||
|
@ -135,7 +134,7 @@ class SocksQueue:
|
||||||
else:
|
else:
|
||||||
fp = fingerprint
|
fp = fingerprint
|
||||||
if receiving:
|
if receiving:
|
||||||
self.type_ = 'receiver'
|
file_props.type_ = 'r'
|
||||||
socks5obj = Socks5ReceiverClient(self.idlequeue, streamhost,
|
socks5obj = Socks5ReceiverClient(self.idlequeue, streamhost,
|
||||||
sid, file_props, fingerprint=fp)
|
sid, file_props, fingerprint=fp)
|
||||||
self.add_sockobj(account, socks5obj)
|
self.add_sockobj(account, socks5obj)
|
||||||
|
@ -145,7 +144,7 @@ class SocksQueue:
|
||||||
else:
|
else:
|
||||||
idx = self.idx
|
idx = self.idx
|
||||||
self.idx = self.idx + 1
|
self.idx = self.idx + 1
|
||||||
self.type_ = 'sender'
|
file_props.type_ = 's'
|
||||||
if 'type' in streamhost and streamhost['type'] == 'proxy':
|
if 'type' in streamhost and streamhost['type'] == 'proxy':
|
||||||
file_props.is_a_proxy = True
|
file_props.is_a_proxy = True
|
||||||
file_props.proxy_sender = streamhost['target']
|
file_props.proxy_sender = streamhost['target']
|
||||||
|
@ -155,7 +154,7 @@ class SocksQueue:
|
||||||
port=int(streamhost['port']),fingerprint=fp,
|
port=int(streamhost['port']),fingerprint=fp,
|
||||||
connected=False, file_props=file_props)
|
connected=False, file_props=file_props)
|
||||||
socks5obj.streamhost = streamhost
|
socks5obj.streamhost = streamhost
|
||||||
self.add_sockobj(account, socks5obj, type_='sender')
|
self.add_sockobj(account, socks5obj)
|
||||||
|
|
||||||
streamhost['idx'] = socks5obj.queue_idx
|
streamhost['idx'] = socks5obj.queue_idx
|
||||||
|
|
||||||
|
@ -168,7 +167,7 @@ class SocksQueue:
|
||||||
if host != streamhost and 'idx' in host:
|
if host != streamhost and 'idx' in host:
|
||||||
if host['state'] == 1:
|
if host['state'] == 1:
|
||||||
# remove current
|
# remove current
|
||||||
if self.type_ == 'sender':
|
if file_props.type_ == 's':
|
||||||
self.remove_sender(streamhost['idx'], False)
|
self.remove_sender(streamhost['idx'], False)
|
||||||
else:
|
else:
|
||||||
self.remove_receiver(streamhost['idx'])
|
self.remove_receiver(streamhost['idx'])
|
||||||
|
@ -176,7 +175,7 @@ class SocksQueue:
|
||||||
# set state -2, meaning that this streamhost is stopped,
|
# set state -2, meaning that this streamhost is stopped,
|
||||||
# but it may be connectected later
|
# but it may be connectected later
|
||||||
if host['state'] >= 0:
|
if host['state'] >= 0:
|
||||||
if self.type_ == 'sender':
|
if file_props.type_ == 's':
|
||||||
self.remove_sender(host['idx'], False)
|
self.remove_sender(host['idx'], False)
|
||||||
else:
|
else:
|
||||||
self.remove_receiver(host['idx'])
|
self.remove_receiver(host['idx'])
|
||||||
|
@ -239,12 +238,12 @@ class SocksQueue:
|
||||||
file_props.failure_cb(file_props.sid)
|
file_props.failure_cb(file_props.sid)
|
||||||
file_props.failure_cb = None
|
file_props.failure_cb = None
|
||||||
|
|
||||||
def add_sockobj(self, account, sockobj, type_='receiver'):
|
def add_sockobj(self, account, sockobj):
|
||||||
"""
|
"""
|
||||||
Add new file a sockobj type receiver or sender, and use it to connect
|
Add new file a sockobj type receiver or sender, and use it to connect
|
||||||
to server
|
to server
|
||||||
"""
|
"""
|
||||||
if type_ == 'receiver':
|
if sockobj.file_props.type_ == 'r':
|
||||||
self._add(sockobj, self.readers, sockobj.file_props, self.idx)
|
self._add(sockobj, self.readers, sockobj.file_props, self.idx)
|
||||||
else:
|
else:
|
||||||
self._add(sockobj, self.senders, sockobj.file_props, self.idx)
|
self._add(sockobj, self.senders, sockobj.file_props, self.idx)
|
||||||
|
@ -327,7 +326,7 @@ class SocksQueue:
|
||||||
|
|
||||||
def on_connection_accepted(self, sock, listener):
|
def on_connection_accepted(self, sock, listener):
|
||||||
sock_hash = sock.__hash__()
|
sock_hash = sock.__hash__()
|
||||||
if self.type_ == 'sender' and \
|
if listener.file_props.type_ == 's' and \
|
||||||
not self.isHashInSockObjs(self.senders, sock_hash):
|
not self.isHashInSockObjs(self.senders, sock_hash):
|
||||||
sockobj = Socks5SenderServer(self.idlequeue, sock_hash, self,
|
sockobj = Socks5SenderServer(self.idlequeue, sock_hash, self,
|
||||||
sock[0], sock[1][0], sock[1][1], fingerprint='server',
|
sock[0], sock[1][0], sock[1][1], fingerprint='server',
|
||||||
|
@ -336,7 +335,7 @@ class SocksQueue:
|
||||||
# Start waiting for data
|
# Start waiting for data
|
||||||
self.idlequeue.plug_idle(sockobj, False, True)
|
self.idlequeue.plug_idle(sockobj, False, True)
|
||||||
self.connected += 1
|
self.connected += 1
|
||||||
if self.type_ == 'receiver' and \
|
if listener.file_props.type_ == 'r' and \
|
||||||
not self.isHashInSockObjs(self.readers, sock_hash):
|
not self.isHashInSockObjs(self.readers, sock_hash):
|
||||||
sh = {}
|
sh = {}
|
||||||
sh['host'] = sock[1][0]
|
sh['host'] = sock[1][0]
|
||||||
|
@ -441,7 +440,6 @@ class Socks5:
|
||||||
self.remaining_buff = ''
|
self.remaining_buff = ''
|
||||||
self.file = None
|
self.file = None
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.type_ = ''
|
|
||||||
self.mode = ''
|
self.mode = ''
|
||||||
|
|
||||||
def _is_connected(self):
|
def _is_connected(self):
|
||||||
|
@ -914,7 +912,6 @@ class Socks5Sender(IdleObject):
|
||||||
self.file_props.elapsed_time = 0
|
self.file_props.elapsed_time = 0
|
||||||
self.file_props.last_time = self.idlequeue.current_time()
|
self.file_props.last_time = self.idlequeue.current_time()
|
||||||
self.file_props.received_len = 0
|
self.file_props.received_len = 0
|
||||||
self.type_ = 'sender'
|
|
||||||
|
|
||||||
def start_transfer(self):
|
def start_transfer(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1076,7 +1073,7 @@ class Socks5Server(Socks5):
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
elif self.state == 5:
|
elif self.state == 5:
|
||||||
self.state = 7
|
self.state = 7
|
||||||
if self.type_ == 'sender':
|
if self.file_props.type_ == 's':
|
||||||
# We wait for the end of the negotiation to
|
# We wait for the end of the negotiation to
|
||||||
# send the file
|
# send the file
|
||||||
self.idlequeue.plug_idle(self, False, False)
|
self.idlequeue.plug_idle(self, False, False)
|
||||||
|
@ -1186,7 +1183,7 @@ class Socks5Client(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:
|
if self.file_props.type_ == 's' and self.proxy:
|
||||||
self.queue.process_result(self.send_file(), self)
|
self.queue.process_result(self.send_file(), self)
|
||||||
return
|
return
|
||||||
if result == 0:
|
if result == 0:
|
||||||
|
|
Loading…
Reference in New Issue