coding standards

This commit is contained in:
Yann Leboulanger 2011-08-24 10:36:00 +02:00
parent 19bc86d9a3
commit a3d772e505
1 changed files with 107 additions and 111 deletions

View File

@ -142,16 +142,14 @@ class SocksQueue:
if receiving: if receiving:
self.type = 'receiver' self.type = 'receiver'
socks5obj = Socks5Receiver(self.idlequeue, streamhost, sid, socks5obj = Socks5Receiver(self.idlequeue, streamhost, sid,
'client', file_props, 'client', file_props, fingerprint=fp)
fingerprint=fp)
self.add_sockobj(account, socks5obj) self.add_sockobj(account, socks5obj)
else: else:
self.type = 'sender' self.type = 'sender'
socks5obj = Socks5Sender(self.idlequeue, socks5obj = Socks5Sender(self.idlequeue, file_props['sha_str'],
file_props['sha_str'], self, mode='client' , self, mode='client' , _sock=None,
_sock=None, host=str(streamhost['host']), host=str(streamhost['host']), port=int(streamhost['port']),
port=int(streamhost['port']), fingerprint=fp, 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, type='sender')
@ -266,7 +264,6 @@ class SocksQueue:
keys = (fp['sid'], fp['name'], hash) keys = (fp['sid'], fp['name'], hash)
sockobjects[keys] = sockobj sockobjects[keys] = sockobj
def result_sha(self, sha_str, idx): def result_sha(self, sha_str, idx):
if sha_str in self.sha_handlers: if sha_str in self.sha_handlers:
props = self.sha_handlers[sha_str] props = self.sha_handlers[sha_str]
@ -319,7 +316,6 @@ class SocksQueue:
file_props['received-len'] = 0 file_props['received-len'] = 0
sender.file_props = file_props sender.file_props = file_props
def add_file_props(self, account, file_props): def add_file_props(self, account, file_props):
""" """
File_prop to the dict of current file_props. It is identified by account File_prop to the dict of current file_props. It is identified by account
@ -369,9 +365,9 @@ class SocksQueue:
if self.type == 'sender' and \ if self.type == 'sender' and \
not self.isHashInSockObjs(self.senders, sock_hash): not self.isHashInSockObjs(self.senders, sock_hash):
sockobj = Socks5Sender(self.idlequeue, sock_hash, self, sockobj = Socks5Sender(self.idlequeue, sock_hash, self, 'server',
'server', sock[0], sock[1][0], sock[1][1], sock[0], sock[1][0], sock[1][1], fingerprint='server',
fingerprint='server', file_props=listener.file_props) file_props=listener.file_props)
self._add(sockobj, self.senders, listener.file_props, sock_hash) self._add(sockobj, self.senders, listener.file_props, sock_hash)
# Start waiting for data # Start waiting for data
self.idlequeue.plug_idle(sockobj, False, True) self.idlequeue.plug_idle(sockobj, False, True)
@ -386,8 +382,7 @@ class SocksQueue:
sh['target'] = None sh['target'] = None
sockobj = Socks5Receiver(idlequeue=self.idlequeue, sockobj = Socks5Receiver(idlequeue=self.idlequeue,
streamhost=sh,sid=None, streamhost=sh,sid=None, file_props=listener.file_props,
file_props=listener.file_props,
mode='server',fingerprint='server') mode='server',fingerprint='server')
self._add(sockobj, self.readers, listener.file_props, sock_hash) self._add(sockobj, self.readers, listener.file_props, sock_hash)
@ -532,8 +527,8 @@ class Socks5:
errnum = ee[0] errnum = ee[0]
self.connect_timeout += 1 self.connect_timeout += 1
if errnum == 111 or self.connect_timeout > 1000: if errnum == 111 or self.connect_timeout > 1000:
self.queue._connection_refused(self.streamhost, self.queue._connection_refused(self.streamhost, self.file_props,
self.file_props, self.queue_idx) self.queue_idx)
self.connected = False self.connected = False
return None return None
# win32 needs this # win32 needs this
@ -714,7 +709,6 @@ class Socks5:
def pollin(self): def pollin(self):
if self.mode == 'client': if self.mode == 'client':
self.clnt_pollin() self.clnt_pollin()
elif self.mode == 'server': elif self.mode == 'server':
@ -781,7 +775,6 @@ class Socks5:
def pollend(self): def pollend(self):
if self.mode == 'client': if self.mode == 'client':
self.clnt_pollend() self.clnt_pollend()
elif self.mode == 'server': elif self.mode == 'server':
@ -1081,10 +1074,12 @@ class Socks5:
return struct.pack('!BB', 0x05, 0x00) return struct.pack('!BB', 0x05, 0x00)
def _get_connect_buff(self): def _get_connect_buff(self):
''' Connect request by domain name ''' """
Connect request by domain name
"""
buff = struct.pack('!BBBBB%dsBB' % len(self.host), buff = struct.pack('!BBBBB%dsBB' % len(self.host),
0x05, 0x01, 0x00, 0x03, len(self.host), self.host, 0x05, 0x01, 0x00, 0x03, len(self.host), self.host, self.port >> 8,
self.port >> 8, self.port & 0xff) self.port & 0xff)
return buff return buff
def _get_request_buff(self, msg, command = 0x01): def _get_request_buff(self, msg, command = 0x01):
@ -1162,8 +1157,7 @@ class Socks5Sender(Socks5, IdleObject):
""" """
def __init__(self, idlequeue, sock_hash, parent, mode,_sock, host=None, def __init__(self, idlequeue, sock_hash, parent, mode,_sock, host=None,
port=None, fingerprint = None, connected=True, port=None, fingerprint = None, connected=True, file_props={}):
file_props={}):
self.fingerprint = fingerprint self.fingerprint = fingerprint
self.queue_idx = sock_hash self.queue_idx = sock_hash
@ -1261,7 +1255,8 @@ class Socks5Listener(IdleObject):
This class implements IdleObject, but we will expect This class implements IdleObject, but we will expect
only pollin events though only pollin events though
fingerprint: fingerprint of certificates we shall use, set to None if TLS connection not desired fingerprint: fingerprint of certificates we shall use, set to None if
TLS connection not desired
""" """
self.port = port self.port = port
self.ais = socket.getaddrinfo(None, port, socket.AF_UNSPEC, self.ais = socket.getaddrinfo(None, port, socket.AF_UNSPEC,
@ -1356,7 +1351,8 @@ class Socks5Receiver(Socks5, IdleObject):
def __init__(self, idlequeue, streamhost, sid, mode, file_props = None, def __init__(self, idlequeue, streamhost, sid, mode, file_props = None,
fingerprint=None): fingerprint=None):
""" """
fingerprint: fingerprint of certificates we shall use, set to None if TLS connection not desired fingerprint: fingerprint of certificates we shall use, set to None if
TLS connection not desired
""" """
self.queue_idx = -1 self.queue_idx = -1
self.streamhost = streamhost self.streamhost = streamhost