async def run(self) -> None: self.manager.run_daemon_child_service(Canary()) identity_scheme_registry = default_identity_scheme_registry message_type_registry = v51_registry enr_database_file = self._boot_info.base_dir / ENR_DATABASE_FILENAME enr_db: QueryableENRDatabaseAPI = QueryableENRDB( sqlite3.connect(enr_database_file), identity_scheme_registry) local_private_key = get_local_private_key(self._boot_info) enr_manager = ENRManager( enr_db=enr_db, private_key=local_private_key, ) port = self._boot_info.port events = Events() if b"udp" not in enr_manager.enr: enr_manager.update((b"udp", port)) elif enr_manager.enr[b"udp"] != port: enr_manager.update((b"udp", port)) listen_on_ip_address: AnyIPAddress if self._boot_info.listen_on is None: listen_on_ip_address = DEFAULT_LISTEN else: listen_on_ip_address = self._boot_info.listen_on # Update the ENR if an explicit listening address was provided enr_manager.update( (IP_V4_ADDRESS_ENR_KEY, listen_on_ip_address.packed)) listen_on = Endpoint(listen_on_ip_address.packed, self._boot_info.port) if self._boot_info.is_upnp_enabled: upnp_service = UPnPService(port) self.manager.run_daemon_child_service(upnp_service) self.manager.run_daemon_task(self._update_enr_ip_from_upnp, enr_manager, upnp_service) bootnodes = self._boot_info.bootnodes self.client = Client( local_private_key=local_private_key, listen_on=listen_on, enr_db=enr_db, session_cache_size=self._args.session_cache_size, events=events, message_type_registry=message_type_registry, ) self.network = Network( client=self.client, bootnodes=bootnodes, ) if self._boot_info.is_rpc_enabled: handlers = merge( get_core_rpc_handlers(enr_manager, self.network.routing_table), get_v51_rpc_handlers(self.network), ) self.rpc_server = RPCServer(self._boot_info.ipc_path, handlers) self.manager.run_daemon_child_service(self.rpc_server) self.logger.info("Starting DDHT...") self.logger.info("Protocol-Version: %s", self._boot_info.protocol_version.value) self.logger.info("DDHT base dir : %s", self._boot_info.base_dir) self.logger.info("Listening on : %s", listen_on) self.logger.info("Local Node ID : %s", encode_hex(enr_manager.enr.node_id)) self.logger.info( "Local ENR : seq=%d enr=%s", enr_manager.enr.sequence_number, enr_manager.enr, ) self.manager.run_daemon_child_service(self.network) self._ready.set() await self.manager.wait_finished()
async def rpc_server(ipc_path, alice, alice_alexandria_network): server = RPCServer(ipc_path, get_alexandria_rpc_handlers(alice_alexandria_network)) async with background_trio_service(server): await server.wait_serving() yield server
async def run(self) -> None: identity_scheme_registry = default_identity_scheme_registry message_type_registry = v51_registry enr_database_dir = self._boot_info.base_dir / ENR_DATABASE_DIR_NAME enr_database_dir.mkdir(exist_ok=True) enr_db = ENRDB(LevelDB(enr_database_dir), identity_scheme_registry) local_private_key = get_local_private_key(self._boot_info) enr_manager = ENRManager( enr_db=enr_db, private_key=local_private_key, ) port = self._boot_info.port events = Events() if b"udp" not in enr_manager.enr: enr_manager.update((b"udp", port)) listen_on_ip_address: AnyIPAddress if self._boot_info.listen_on is None: listen_on_ip_address = DEFAULT_LISTEN else: listen_on_ip_address = self._boot_info.listen_on # Update the ENR if an explicit listening address was provided enr_manager.update( (IP_V4_ADDRESS_ENR_KEY, listen_on_ip_address.packed)) listen_on = Endpoint(listen_on_ip_address.packed, self._boot_info.port) if self._boot_info.is_upnp_enabled: upnp_service = UPnPService(port) self.manager.run_daemon_child_service(upnp_service) self.manager.run_daemon_task(self._update_enr_ip_from_upnp, enr_manager, upnp_service) bootnodes = self._boot_info.bootnodes client = Client( local_private_key=local_private_key, listen_on=listen_on, enr_db=enr_db, events=events, message_type_registry=message_type_registry, ) network = Network( client=client, bootnodes=bootnodes, ) if self._boot_info.is_rpc_enabled: handlers = merge( get_core_rpc_handlers(network.routing_table), get_v51_rpc_handlers(network), ) rpc_server = RPCServer(self._boot_info.ipc_path, handlers) self.manager.run_daemon_child_service(rpc_server) self.logger.info("Protocol-Version: %s", self._boot_info.protocol_version.value) self.logger.info("DDHT base dir: %s", self._boot_info.base_dir) self.logger.info("Starting discovery service...") self.logger.info("Listening on %s:%d", listen_on, port) self.logger.info("Local Node ID: %s", encode_hex(enr_manager.enr.node_id)) self.logger.info("Local ENR: seq=%d enr=%s", enr_manager.enr.sequence_number, enr_manager.enr) self.manager.run_daemon_child_service(network) self.manager.run_daemon_child_service(rpc_server)
async def rpc_server(ipc_path, alice): async with alice.network() as network: server = RPCServer(ipc_path, get_v51_rpc_handlers(network)) async with background_trio_service(server): await server.wait_serving() yield server
async def rpc_server(ipc_path, routing_table, enr): server = RPCServer(ipc_path, get_core_rpc_handlers(enr, routing_table)) async with background_trio_service(server): await server.wait_serving() yield server