|
@ -98,7 +98,8 @@ class Socks5Server(SocketServer.StreamRequestHandler): |
|
|
|
|
|
|
|
|
def handle(self): |
|
|
def handle(self): |
|
|
try: |
|
|
try: |
|
|
self.encryptor = encrypt.Encryptor(self.server.key, self.server.method) |
|
|
self.encryptor = encrypt.Encryptor(self.server.key, |
|
|
|
|
|
self.server.method) |
|
|
sock = self.connection |
|
|
sock = self.connection |
|
|
iv_len = self.encryptor.iv_len() |
|
|
iv_len = self.encryptor.iv_len() |
|
|
if iv_len: |
|
|
if iv_len: |
|
@ -159,7 +160,8 @@ def main(): |
|
|
try: |
|
|
try: |
|
|
config = json.load(f) |
|
|
config = json.load(f) |
|
|
except ValueError as e: |
|
|
except ValueError as e: |
|
|
logging.error('found an error in config.json: %s', e.message) |
|
|
logging.error('found an error in config.json: %s', |
|
|
|
|
|
e.message) |
|
|
sys.exit(1) |
|
|
sys.exit(1) |
|
|
logging.info('loading config from %s' % config_path) |
|
|
logging.info('loading config from %s' % config_path) |
|
|
else: |
|
|
else: |
|
@ -189,13 +191,16 @@ def main(): |
|
|
TIMEOUT = config.get('timeout', 600) |
|
|
TIMEOUT = config.get('timeout', 600) |
|
|
|
|
|
|
|
|
if not KEY and not config_path: |
|
|
if not KEY and not config_path: |
|
|
sys.exit('config not specified, please read https://github.com/clowwindy/shadowsocks') |
|
|
sys.exit('config not specified, please read ' |
|
|
|
|
|
'https://github.com/clowwindy/shadowsocks') |
|
|
|
|
|
|
|
|
utils.check_config(config) |
|
|
utils.check_config(config) |
|
|
|
|
|
|
|
|
if PORTPASSWORD: |
|
|
if PORTPASSWORD: |
|
|
if PORT or KEY: |
|
|
if PORT or KEY: |
|
|
logging.warn('warning: port_password should not be used with server_port and password. server_port and password will be ignored') |
|
|
logging.warn('warning: port_password should not be used with ' |
|
|
|
|
|
'server_port and password. server_port and password ' |
|
|
|
|
|
'will be ignored') |
|
|
else: |
|
|
else: |
|
|
PORTPASSWORD = {} |
|
|
PORTPASSWORD = {} |
|
|
PORTPASSWORD[str(PORT)] = KEY |
|
|
PORTPASSWORD[str(PORT)] = KEY |
|
@ -206,9 +211,12 @@ def main(): |
|
|
for port, key in PORTPASSWORD.items(): |
|
|
for port, key in PORTPASSWORD.items(): |
|
|
server = ThreadingTCPServer((SERVER, int(port)), Socks5Server) |
|
|
server = ThreadingTCPServer((SERVER, int(port)), Socks5Server) |
|
|
server.key, server.method, server.timeout = key, METHOD, int(TIMEOUT) |
|
|
server.key, server.method, server.timeout = key, METHOD, int(TIMEOUT) |
|
|
logging.info("starting server at %s:%d" % tuple(server.server_address[:2])) |
|
|
logging.info("starting server at %s:%d" % |
|
|
|
|
|
tuple(server.server_address[:2])) |
|
|
threading.Thread(target=server.serve_forever).start() |
|
|
threading.Thread(target=server.serve_forever).start() |
|
|
|
|
|
udprelay.UDPRelay(SERVER, int(port), None, None, key, METHOD, |
|
|
|
|
|
int(TIMEOUT), False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|
try: |
|
|
try: |
|
|