proxystore.p2p.relay.server¶
Relay server implementation for facilitating WebRTC peer connections.
The relay server (or signaling server) is a lightweight server accessible by all peers (e.g., has a public IP address) that facilitates the establishment of peer WebRTC connections.
RelayServer
¶
RelayServer(
authenticator: Authenticator[UserT],
max_message_bytes: int | None = None,
)
Bases: Generic[UserT]
WebRTC relay server.
The relay server acts as a public third-party that helps two peers (endpoints) establish a peer-to-peer connection during the WebRTC peer connection initiation process. The relay server's responsibility is just to forward session descriptions between two peers, so the server can be relatively lightweight and typically only needs to transfer two messages to establish a peer connection, after which the peers no longer need the relay server.
To learn more about the WebRTC peer connection process, check out https://webrtc.org/getting-started/peer-connections.
The relay server is built on websockets and designed to be
served using serve()
.
Parameters:
-
authenticator
(Authenticator[UserT]
) –Authenticator used to identify users from the opening websocket headers.
-
max_message_bytes
(int | None
, default:None
) –Optional maximum size of client messages in bytes. Clients that send oversized messages will have their connections closed. Note that message size is computed using
sys.getsizeof()
so will also include the PyObject overhead.
Source code in proxystore/p2p/relay/server.py
send
async
¶
send(client: Client[UserT], message: RelayMessage) -> None
Send message on the socket.
Note
Messages are JSON string encoded using
encode_relay_message()
.
Parameters:
-
client
(Client[UserT]
) –Client to send message to.
-
message
(RelayMessage
) –Message to encode and send via the websocket connection to the client.
Source code in proxystore/p2p/relay/server.py
register
async
¶
register(
websocket: ServerConnection,
request: RelayRegistrationRequest,
) -> None
Register client with relay server.
Parameters:
-
websocket
(ServerConnection
) –Websocket connection with client wanting to register.
-
request
(RelayRegistrationRequest
) –Registration request message.
Raises:
-
UnauthorizedError
–if the websocket request headers are missing the authorization headers.
-
ForbiddenError
–if Globus authentication fails.
-
ForbiddenError
–if the requested client UUID is already registered by another user.
Source code in proxystore/p2p/relay/server.py
unregister
async
¶
Unregister the endpoint.
Parameters:
-
client
(Client[UserT]
) –Client to unregister.
-
expected
(bool
) –If the connection was closed intentionally or due to an error.
Source code in proxystore/p2p/relay/server.py
forward
async
¶
forward(
source_client: Client[UserT],
request: PeerConnectionRequest,
) -> None
Forward peer connection request between two clients.
If an error is encountered, the relay server replies to the source
client with an error message set in message.error
.
Parameters:
-
source_client
(Client[UserT]
) –Client making forwarding request.
-
request
(PeerConnectionRequest
) –Peer connection request to forward.
Source code in proxystore/p2p/relay/server.py
handler
async
¶
handler(websocket: ServerConnection) -> None
Websocket server message handler.
The handler will close the connection for the following reasons.
- An unexpected message type is received (code 4000).
- The client can not be authenticated (code 4001).
- The client attempts to access forbidden resources (code 4002).
- The client sends a message larger than the allowed size (code 4003).
Parameters:
-
websocket
(ServerConnection
) –Websocket message was received on.
Source code in proxystore/p2p/relay/server.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|