diff --git a/shadowsocks/manager.py b/shadowsocks/manager.py index 767c003..2da4f0d 100644 --- a/shadowsocks/manager.py +++ b/shadowsocks/manager.py @@ -40,18 +40,26 @@ class Manager(object): 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) diff --git a/shadowsocks/server.py b/shadowsocks/server.py index 3489bf5..e25db4c 100755 --- a/shadowsocks/server.py +++ b/shadowsocks/server.py @@ -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 diff --git a/shadowsocks/shell.py b/shadowsocks/shell.py index 586c2f6..bdba6c6 100644 --- a/shadowsocks/shell.py +++ b/shadowsocks/shell.py @@ -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) @@ -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': @@ -319,7 +319,7 @@ Proxy options: --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