transport
transport
¶
WebSocket transport primitives for BigBrotr.
Provides custom WebSocket transport classes for nostr-sdk with SSL verification bypass and UniFFI stderr noise suppression. These are low-level building blocks consumed by bigbrotr.utils.protocol.
Attributes:
-
DEFAULT_TIMEOUT(Final[float]) –Default timeout for network operations (10 seconds).
-
InsecureWebSocketAdapter(Final[float]) –aiohttp WebSocket adapter with SSL disabled.
-
InsecureWebSocketTransport(Final[float]) –nostr-sdk custom transport wrapping the adapter.
Note
The _NostrSdkStderrFilter is installed globally at import time to
suppress UniFFI traceback noise from nostr-sdk's Rust layer. This is
separate from the _StderrSuppressor in
bigbrotr.utils.protocol which provides
batch-level suppression during relay validation.
See Also
bigbrotr.utils.protocol: Higher-level Nostr protocol operations built on these transport primitives. bigbrotr.models.relay.Relay: The relay model consumed by connection functions.
Classes¶
InsecureWebSocketAdapter
¶
InsecureWebSocketAdapter(
ws: ClientWebSocketResponse,
session: ClientSession,
recv_timeout: float = _WS_RECV_TIMEOUT,
close_timeout: float = _WS_CLOSE_TIMEOUT,
)
Bases: WebSocketAdapter
aiohttp-based WebSocket adapter with SSL verification disabled.
Implements the nostr_sdk.WebSocketAdapter interface. Allows connections
to relays with self-signed, expired, or otherwise invalid certificates.
Warning
This adapter creates an ssl.SSLContext with CERT_NONE and
check_hostname=False, disabling all certificate verification.
It should only be used as a fallback after standard SSL has failed.
See Also
InsecureWebSocketTransport: The transport class that creates instances of this adapter.
Source code in src/bigbrotr/utils/transport.py
Functions¶
send
async
¶
Send a WebSocket message (text, binary, ping, or pong).
Source code in src/bigbrotr/utils/transport.py
recv
async
¶
Receive the next WebSocket message (60s timeout).
Returns:
-
WebSocketMessage | None–The received message in nostr-sdk format, or None if the
-
WebSocketMessage | None–connection closed, errored, or timed out.
Source code in src/bigbrotr/utils/transport.py
close_connection
async
¶
Close the WebSocket and session with timeouts to prevent hanging.
Source code in src/bigbrotr/utils/transport.py
InsecureWebSocketTransport
¶
InsecureWebSocketTransport(
recv_timeout: float = _WS_RECV_TIMEOUT,
close_timeout: float = _WS_CLOSE_TIMEOUT,
)
Bases: CustomWebSocketTransport
Custom WebSocket transport with SSL verification disabled.
Used as a fallback for clearnet relays with invalid/expired certificates. Creates aiohttp sessions with an SSL context that accepts any certificate.
Warning
Disables all SSL/TLS certificate verification, including hostname checking and chain validation. This makes the connection vulnerable to man-in-the-middle attacks. Only use when standard SSL verification has already failed and the connection is still desired (e.g., monitoring relays with self-signed certificates).
Note
This transport implements the nostr_sdk.CustomWebSocketTransport
interface so it can be injected into the nostr-sdk client via
ClientBuilder.websocket_transport(). The UniFFI event loop must
be set via uniffi_set_event_loop() before using this transport.
See Also
InsecureWebSocketAdapter:
The per-connection adapter created by this transport.
create_client: Factory function
that wires this transport into a client via allow_insecure=True.
connect_relay: High-level
function that uses this transport as an SSL fallback.
Source code in src/bigbrotr/utils/transport.py
Functions¶
connect
async
¶
Connect to a relay URL without SSL certificate verification.
Parameters:
-
url(str) –WebSocket URL (wss:// or ws://).
-
_mode(ConnectionMode) –Connection mode (unused; aiohttp handles this).
-
timeout(timedelta) –Connection timeout as a timedelta.
Returns:
-
WebSocketAdapterWrapper–Wrapped adapter for nostr-sdk communication.
Raises:
-
OSError–On connection failure (network, timeout, DNS, etc.).
-
CancelledError–If cancelled.