Fix bugs
This commit is contained in:
parent
041583de8d
commit
d3e6989dcd
1 changed files with 11 additions and 7 deletions
18
server.py
18
server.py
|
@ -44,14 +44,14 @@ class Crypto(object):
|
||||||
table = list(trans)
|
table = list(trans)
|
||||||
for i in xrange(1, 1024):
|
for i in xrange(1, 1024):
|
||||||
table.sort(lambda x, y: int(a % (ord(x) + i) - a % (ord(y) + i)))
|
table.sort(lambda x, y: int(a % (ord(x) + i) - a % (ord(y) + i)))
|
||||||
self._encrypt_table = ''.join(table)
|
self.encrypt_table = ''.join(table)
|
||||||
self._decrypt_table = string.maketrans(self._encrypt_table, trans)
|
self.decrypt_table = string.maketrans(self.encrypt_table, trans)
|
||||||
|
|
||||||
def encrypt(self, data):
|
def encrypt(self, data):
|
||||||
return data.translate(self._encrypt_table)
|
return data.translate(self.encrypt_table)
|
||||||
|
|
||||||
def decrypt(self, data):
|
def decrypt(self, data):
|
||||||
return data.translate(self._decrypt_table)
|
return data.translate(self.decrypt_table)
|
||||||
|
|
||||||
|
|
||||||
class Socks5Server(netutil.TCPServer):
|
class Socks5Server(netutil.TCPServer):
|
||||||
|
@ -62,8 +62,12 @@ class Socks5Server(netutil.TCPServer):
|
||||||
|
|
||||||
|
|
||||||
class PairedStream(iostream.IOStream):
|
class PairedStream(iostream.IOStream):
|
||||||
|
def __init__(self, soc):
|
||||||
|
super(PairedStream, self).__init__(soc)
|
||||||
|
self.remote = None
|
||||||
|
|
||||||
def on_close(self):
|
def on_close(self):
|
||||||
remote = getattr(self, "remote")
|
remote = self.remote
|
||||||
if isinstance(remote, PairedStream) and not remote.closed():
|
if isinstance(remote, PairedStream) and not remote.closed():
|
||||||
if remote.writing():
|
if remote.writing():
|
||||||
remote.write("", callback=remote.close())
|
remote.write("", callback=remote.close())
|
||||||
|
@ -114,11 +118,11 @@ class ConnHandler(PairedStream):
|
||||||
|
|
||||||
def on_client_read(self, data):
|
def on_client_read(self, data):
|
||||||
if data:
|
if data:
|
||||||
self.remote.write(crypto.encrypt(data))
|
self.remote.write(crypto.decrypt(data))
|
||||||
|
|
||||||
def on_remote_read(self, data):
|
def on_remote_read(self, data):
|
||||||
if data:
|
if data:
|
||||||
self.write(crypto.decrypt(data))
|
self.write(crypto.encrypt(data))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue