nostr_tools.check_connectivity¶
- async nostr_tools.check_connectivity(client)[source]¶
Check if the relay is connectable and measure connection time.
This function attempts to establish a WebSocket connection to the relay and measures the round-trip time for the connection establishment.
- Parameters:
client (
Client) – An instance of Client (must not be already connected)- Returns:
- (rtt_open in ms or None, openable as bool)
rtt_open: Connection time in milliseconds, or None if failed
openable: True if connection succeeded, False otherwise
- Return type:
- Raises:
ClientConnectionError – If client is already connected
Examples
Test relay connectivity:
>>> client = Client(relay) >>> rtt, is_openable = await check_connectivity(client) >>> if is_openable: ... print(f"Relay is reachable in {rtt}ms") ... else: ... print("Relay is not reachable")
Use in relay testing:
>>> for relay_url in relay_list: ... client = Client(Relay(relay_url)) ... rtt, openable = await check_connectivity(client) ... if openable: ... print(f"{relay_url}: {rtt}ms")