async def _run(): if self._start_callback: await self._start_callback() self._rpc_task = None self._rpc_close_task = None if self._rpc_info: rpc_api, rpc_port = self._rpc_info self._rpc_task = asyncio.create_task( start_rpc_server( rpc_api(self._api), self.self_hostname, self.daemon_port, rpc_port, self.stop, )) self._reconnect_tasks = [ start_reconnect_task(self._server, _, self._log, self._auth_connect_peers) for _ in self._connect_peers ] self._server_sockets = [ await start_server(self._server, self._on_connect_callback) for _ in self._server_listen_ports ] signal.signal(signal.SIGINT, global_signal_handler) signal.signal(signal.SIGTERM, global_signal_handler) if platform == "win32" or platform == "cygwin": # pylint: disable=E1101 signal.signal(signal.SIGBREAK, global_signal_handler) # type: ignore
async def _run(): if self._start_callback: await self._start_callback() self._introducer_poll_task = None if self._periodic_introducer_poll: ( peer_info, introducer_connect_interval, target_peer_count, ) = self._periodic_introducer_poll self._introducer_poll_task = create_periodic_introducer_poll_task( self._server, peer_info, self._server.global_connections, introducer_connect_interval, target_peer_count, ) self._rpc_task = None if self._rpc_info: rpc_api, rpc_port = self._rpc_info self._rpc_task = asyncio.create_task( start_rpc_server( rpc_api(self._api), self.self_hostname, self.daemon_port, rpc_port, self.stop, )) self._reconnect_tasks = [ start_reconnect_task(self._server, _, self._log, self._auth_connect_peers) for _ in self._connect_peers ] self._server_sockets = [ await start_server(self._server, self._on_connect_callback) for _ in self._server_listen_ports ] try: asyncio.get_running_loop().add_signal_handler( signal.SIGINT, self.stop) asyncio.get_running_loop().add_signal_handler( signal.SIGTERM, self.stop) except NotImplementedError: self._log.info("signal handlers unsupported") for _ in self._server_sockets: await _.wait_closed() await self._server.await_closed() if self._stop_callback: self._stop_callback() if self._await_closed_callback: await self._await_closed_callback()
async def start(self, **kwargs): # we include `kwargs` as a hack for the wallet, which for some # reason allows parameters to `_start`. This is serious BRAIN DAMAGE, # and should be fixed at some point. # TODO: move those parameters to `__init__` if self._did_start: return self._did_start = True self._enable_signals() await self._node._start(**kwargs) for port in self._upnp_ports: upnp_remap_port(port) await self._server.start_server(self._on_connect_callback) self._reconnect_tasks = [ start_reconnect_task(self._server, _, self._log, self._auth_connect_peers) for _ in self._connect_peers ] self._log.info( f"Started {self._service_name} service on network_id: {self._network_id.hex()}" ) self._rpc_close_task = None if self._rpc_info: rpc_api, rpc_port = self._rpc_info self._rpc_task = asyncio.create_task( start_rpc_server( rpc_api(self._node), self.self_hostname, self.daemon_port, rpc_port, self.stop, self.root_path, self.config, self._connect_to_daemon, ))