Browse Source

update config

auth
clowwindy 11 years ago
parent
commit
2cdddd4515
  1. 45
      shadowsocks/server.py

45
shadowsocks/server.py

@ -39,6 +39,7 @@ import getopt
import encrypt import encrypt
import os import os
import utils import utils
import tcprelay
import udprelay import udprelay
@ -216,55 +217,43 @@ def main():
utils.print_server_help() utils.print_server_help()
sys.exit(2) sys.exit(2)
config_server = config['server'] config['password'] = config.get('password', None)
config_server_port = config['server_port'] config['method'] = config.get('method', None)
config_key = config['password'] config['port_password'] = config.get('port_password', None)
config_method = config.get('method', None) config['timeout'] = int(config.get('timeout', 300))
config_port_password = config.get('port_password', None) config['fast_open'] = config.get('fast_open', False)
config_timeout = int(config.get('timeout', 300)) config['workers'] = config.get('workers', 1)
config_fast_open = config.get('fast_open', False)
config_workers = config.get('workers', 1)
if not config_key and not config_path:
sys.exit('config not specified, please read '
'https://github.com/clowwindy/shadowsocks')
utils.check_config(config) utils.check_config(config)
if config_port_password: if config['port_password']:
if config_server_port or config_key: if config['server_port'] or config['password']:
logging.warn('warning: port_password should not be used with ' logging.warn('warning: port_password should not be used with '
'server_port and password. server_port and password ' 'server_port and password. server_port and password '
'will be ignored') 'will be ignored')
else: else:
config_port_password = {} config['port_password'] = {}
config_port_password[str(config_server_port)] = config_key config['port_password'][str(config['server_port'])] = config['password']
encrypt.init_table(config_key, config_method) encrypt.init_table(config['password'], config['method'])
addrs = socket.getaddrinfo(config_server, int(8387)) addrs = socket.getaddrinfo(config['server'], int(8387))
if not addrs: if not addrs:
logging.error('cant resolve listen address') logging.error('cant resolve listen address')
sys.exit(1) sys.exit(1)
ThreadingTCPServer.address_family = addrs[0][0] ThreadingTCPServer.address_family = addrs[0][0]
tcp_servers = [] tcp_servers = []
udp_servers = [] udp_servers = []
for port, key in config_port_password.items(): for port, key in config['port_password'].items():
tcp_server = ThreadingTCPServer((config_server, int(port)),
Socks5Server)
tcp_server.key = key
tcp_server.method = config_method
tcp_server.timeout = int(config_timeout)
logging.info("starting server at %s:%d" % logging.info("starting server at %s:%d" %
tuple(tcp_server.server_address[:2])) tuple(tcp_server.server_address[:2]))
tcp_server = tcprelay.TCPRelay(config, False)
tcp_servers.append(tcp_server) tcp_servers.append(tcp_server)
udp_server = udprelay.UDPRelay(config_server, int(port), None, None, udp_server = udprelay.UDPRelay(config, False)
key, config_method, int(config_timeout),
False)
udp_servers.append(udp_server) udp_servers.append(udp_server)
def run_server(): def run_server():
for tcp_server in tcp_servers: for tcp_server in tcp_servers:
threading.Thread(target=tcp_server.serve_forever).start() tcp_server.start()
for udp_server in udp_servers: for udp_server in udp_servers:
udp_server.start() udp_server.start()

Loading…
Cancel
Save