proxystore.p2p.relay¶
Relay server implementation for 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.
Client
dataclass
¶
Representation of client connection.
Attributes:
-
name
(
str
) –Name of client.
-
uuid
(
UUID
) –UUID of client.
-
websocket
(
WebSocketServerProtocol
) –WebSocket connection to the client.
RelayServer ¶
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 websockets.serve()
.
Example
Source code in proxystore/p2p/relay.py
send()
async
¶
Send message on the socket.
Parameters:
-
websocket
(
WebSocketServerProtocol
) –Websocket to send message on.
-
message
(
messages.Message
) –Message to json encode and send.
Source code in proxystore/p2p/relay.py
register()
async
¶
Register peer with relay server.
Parameters:
-
websocket
(
WebSocketServerProtocol
) –Websocket connection with client wanting to register.
-
request
(
messages.ServerRegistration
) –Registration request message.
Source code in proxystore/p2p/relay.py
unregister()
async
¶
Unregister the endpoint.
Parameters:
-
websocket
(
WebSocketServerProtocol
) –Websocket connection that was closed.
-
expected
(
bool
) –If the connection was closed intentionally or due to an error.
Source code in proxystore/p2p/relay.py
connect()
async
¶
Pass peer connection messages between clients.
Parameters:
-
websocket
(
WebSocketServerProtocol
) –Websocket connection with client that sent the peer connection message.
-
message
(
messages.PeerConnection
) –Message to forward to peer client.
Source code in proxystore/p2p/relay.py
handler()
async
¶
Websocket server message handler.
Parameters:
-
websocket
(
WebSocketServerProtocol
) –Websocket message was received on.
-
uri
(
str
) –URI message was sent to.
Source code in proxystore/p2p/relay.py
serve()
async
¶
Run the relay server.
Initializes a RelayServer
and starts a websocket server listening on host:port
for new connections
and incoming messages.
Parameters:
-
host
(
str
) –Host to listen on.
-
port
(
int
) –Port to listen on.
-
certfile
(
str | None
) –Optional certificate file (PEM format) to enable TLS while serving.
-
keyfile
(
str | None
) –Optional private key file. If not specified, the key will be taken from the certfile.
Source code in proxystore/p2p/relay.py
cli() ¶
cli(
host: str,
port: int,
certfile: str | None,
keyfile: str | None,
log_dir: str | None,
log_level: str,
) -> None
Run a relay server instance.
The relay server is used by clients to establish peer-to-peer WebRTC connections.
Source code in proxystore/p2p/relay.py
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 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
|