async def _run(self) -> None: async with AsyncioEndpoint.serve(self._connection_config) as endpoint: self._endpoint = endpoint # signal that the endpoint is now available self._endpoint_available.set() # run background task that automatically connects to newly announced endpoints self.run_daemon_task(self._auto_connect_new_announced_endpoints()) # connect to the *main* endpoint which communicates information # about other endpoints that come online. main_endpoint_config = ConnectionConfig.from_name( MAIN_EVENTBUS_ENDPOINT, self._trinity_config.ipc_dir, ) await endpoint.connect_to_endpoints(main_endpoint_config) # announce ourself to the event bus await endpoint.wait_until_endpoint_subscribed_to( MAIN_EVENTBUS_ENDPOINT, EventBusConnected, ) await endpoint.broadcast( EventBusConnected(self._connection_config), BroadcastConfig(filter_endpoint=MAIN_EVENTBUS_ENDPOINT)) # run until the endpoint exits await self.cancellation()
async def announce_endpoint(self) -> None: """ Announce this endpoint to the :class:`~trinity.endpoint.TrinityMainEventBusEndpoint` so that it will be further propagated to all other endpoints, allowing them to connect to us. """ await self.broadcast( EventBusConnected( ConnectionConfig(name=self.name, path=self.ipc_path)), BroadcastConfig(filter_endpoint=MAIN_EVENTBUS_ENDPOINT))