socket.SO_REUSEADDR

This commit is contained in:
clowwindy 2014-06-01 14:53:06 +08:00
parent 5e9a9c9beb
commit 3cefe374c2
4 changed files with 14 additions and 10 deletions

View file

@ -157,9 +157,9 @@ class Encryptor(object):
self.cipher_iv = iv[:m[1]] # this iv is for cipher not decipher
if method != 'salsa20-ctr':
import M2Crypto.EVP
return M2Crypto.EVP.Cipher(method.replace('-', '_'), key, iv, op,
key_as_bytes=0, d='md5', salt=None, i=1,
padding=1)
return M2Crypto.EVP.Cipher(method.replace('-', '_'), key, iv,
op, key_as_bytes=0, d='md5',
salt=None, i=1, padding=1)
else:
return encrypt_salsa20.Salsa20Cipher(method, key, iv, op)

View file

@ -55,7 +55,7 @@ def main():
while sys.stdin.read():
pass
except KeyboardInterrupt:
sys.exit(0)
os._exit(0)
if __name__ == '__main__':
main()

View file

@ -294,6 +294,7 @@ class TCPRelay(object):
(listen_addr, listen_port))
af, socktype, proto, canonname, sa = addrs[0]
server_socket = socket.socket(af, socktype, proto)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind(sa)
server_socket.setblocking(False)
server_socket.listen(1024)

View file

@ -56,12 +56,6 @@ def find_config():
def check_config(config):
config['password'] = config.get('password', None)
config['method'] = config.get('method', None)
config['port_password'] = config.get('port_password', None)
config['timeout'] = int(config.get('timeout', 300))
config['fast_open'] = config.get('fast_open', False)
config['workers'] = config.get('workers', 1)
if config.get('local_address', '') in ['0.0.0.0']:
logging.warn('warning: local set to listen 0.0.0.0, which is not safe')
if config.get('server', '') in ['127.0.0.1', 'localhost']:
@ -136,6 +130,15 @@ def get_config(is_local):
sys.exit('config not specified, please read '
'https://github.com/clowwindy/shadowsocks')
config['password'] = config.get('password', None)
config['method'] = config.get('method', None)
config['port_password'] = config.get('port_password', None)
config['timeout'] = int(config.get('timeout', 300))
config['fast_open'] = config.get('fast_open', False)
config['workers'] = config.get('workers', 1)
config['verbose'] = config.get('verbose', False)
config['local_address'] = config.get('local_address', '127.0.0.1')
check_config(config)
if config['verbose']: