Skip to content

Commit

Permalink
allow manager to bind on unix socket
Browse files Browse the repository at this point in the history
  • Loading branch information
clowwindy committed Aug 5, 2015
1 parent 9c3af61 commit d20a071
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
18 changes: 13 additions & 5 deletions shadowsocks/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,26 @@ def __init__(self, config):
self._loop = eventloop.EventLoop()
self._dns_resolver = asyncdns.DNSResolver()
self._dns_resolver.add_to_loop(self._loop)
self._control_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.IPPROTO_UDP)

self._statistics = collections.defaultdict(int)
self._control_client_addr = None
try:
manager_address = config['manager_address']
if ':' in manager_address:
addr = manager_address.split(':')
addr = addr[0], int(addr[1])
family = socket.AF_INET
else:
addr = manager_address
family = socket.AF_UNIX
# TODO use address instead of port
self._control_socket.bind(('127.0.0.1',
int(config['manager_port'])))
self._control_socket = socket.socket(family,
socket.SOCK_DGRAM)
self._control_socket.bind(addr)
self._control_socket.setblocking(False)
except (OSError, IOError) as e:
logging.error(e)
logging.error('can not bind to manager port')
logging.error('can not bind to manager address')
exit(1)
self._loop.add(self._control_socket,
eventloop.POLL_IN, self)
Expand Down
2 changes: 1 addition & 1 deletion shadowsocks/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def main():
else:
config['port_password'][str(server_port)] = config['password']

if config.get('manager_port', 0):
if config.get('manager_address', 0):
logging.info('entering manager mode')
manager.run(config)
return
Expand Down
8 changes: 4 additions & 4 deletions shadowsocks/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def get_config(is_local):
else:
shortopts = 'hd:s:p:k:m:c:t:vq'
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'workers=',
'forbidden-ip=', 'user=', 'manager-port=', 'version']
'forbidden-ip=', 'user=', 'manager-address=', 'version']
try:
config_path = find_config()
optlist, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
Expand Down Expand Up @@ -181,8 +181,8 @@ def get_config(is_local):
config['fast_open'] = True
elif key == '--workers':
config['workers'] = int(value)
elif key == '--manager-port':
config['manager_port'] = int(value)
elif key == '--manager-address':
config['manager_address'] = value
elif key == '--user':
config['user'] = to_str(value)
elif key == '--forbidden-ip':
Expand Down Expand Up @@ -319,7 +319,7 @@ def print_server_help():
--fast-open use TCP_FASTOPEN, requires Linux 3.7+
--workers WORKERS number of workers, available on Unix/Linux
--forbidden-ip IPLIST comma seperated IP list forbidden to connect
--manager-port PORT optional server manager UDP port
--manager-address ADDR optional server manager UDP address, see wiki
General options:
-h, --help show this help message and exit
Expand Down

0 comments on commit d20a071

Please sign in to comment.