proxystore.p2p.relay_client¶
Client interface to a relay server.
RelayServerClient ¶
RelayServerClient(
address: str,
client_uuid: uuid.UUID | None = None,
client_name: str | None = None,
timeout: float = 10,
ssl: ssl.SSLContext | None = None,
) -> None
Client interface to a relay server.
This interface abstracts the low-level WebSocket connection to a relay server to provide automatic reconnection.
Tip
This class can be used as an async context manager!
Note
WebSocket connections are not opened until a message is sent,
a message is received, or
connect()
is called.
Parameters:
-
address
(
str
) –Address of the relay server. Should start with
ws://
orwss://
. -
client_uuid
(
uuid.UUID | None
) –Optional UUID of the client to use when registering with the relay server. If
None
, one will be generated. -
client_name
(
str | None
) –Optional name of the client to use when registering with the relay server. If
None
, the hostname will be used. -
timeout
(
float
) –Time to wait in seconds on server connections.
-
ssl
(
ssl.SSLContext | None
) –When
None
, the correct value to pass towebsockets.connect()
is inferred fromaddress
. Ifaddress
starts withwss://
the value is True, otherwise is False. Optionally provide a customSSLContext
(useful if the server uses self-signed certificates).
Raises:
-
PeerRegistrationError
–If the connection to the relay server is closed, does not reply to the registration request within the timeout, or replies with an error.
-
ValueError
–If address does not start with
ws://
orwss://
.
Source code in proxystore/p2p/relay_client.py
connect()
async
¶
Connect to the relay server.
Note
Typically this does not need to be called because the send and receive methods will automatically call this.
Note
If an existing and open connection exists, that will be returned. Otherwise, a new connection will be attempted with exponential backoff for connection failures.
Returns:
-
WebSocketClientProtocol
–WebSocket connection to the relay server.
Source code in proxystore/p2p/relay_client.py
close()
async
¶
recv()
async
¶
Receive the next message.
Returns:
Raises:
-
messages.MessageDecodeError
–If the message received cannot be decoded into the appropriate message type.
Source code in proxystore/p2p/relay_client.py
send()
async
¶
Send a message.
Parameters: