Browse Source

socket.SO_REUSEADDR

auth
clowwindy 11 years ago
parent
commit
3cefe374c2
  1. 6
      shadowsocks/encrypt.py
  2. 2
      shadowsocks/local.py
  3. 1
      shadowsocks/tcprelay.py
  4. 15
      shadowsocks/utils.py

6
shadowsocks/encrypt.py

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

2
shadowsocks/local.py

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

1
shadowsocks/tcprelay.py

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

15
shadowsocks/utils.py

@ -56,12 +56,6 @@ def find_config():
def check_config(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']: 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') 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']: 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 ' sys.exit('config not specified, please read '
'https://github.com/clowwindy/shadowsocks') '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) check_config(config)
if config['verbose']: if config['verbose']:

Loading…
Cancel
Save