Skip to content

proxystore.p2p.relay.manager

Helper classes for managing clients connected to a relay server.

Client dataclass

Client(
    name: str,
    uuid: UUID,
    user: UserT,
    websocket: WebSocketServerProtocol,
    created: datetime = _utc_current_time(),
)

Bases: Generic[UserT]

Representation of client connection owned by a user.

Attributes:

  • name (str) –

    Name of client.

  • uuid (UUID) –

    UUID of client.

  • user (UserT) –

    Auth user information.

  • websocket (WebSocketServerProtocol) –

    WebSocket connection to the client.

  • created (datetime) –

    Time the client was created at.

ClientManager

ClientManager()

Bases: Generic[UserT]

Manages active connections with authenticated clients.

Warning

This class is intended for internal use by the RelayServer.

Source code in proxystore/p2p/relay/manager.py
def __init__(self) -> None:
    self._clients_by_uuid: dict[uuid.UUID, Client[UserT]] = {}
    self._clients_by_websocket: dict[
        WebSocketServerProtocol,
        Client[UserT],
    ] = {}

add_client

add_client(client: Client[UserT]) -> None

Add a new authenticated client.

Source code in proxystore/p2p/relay/manager.py
def add_client(self, client: Client[UserT]) -> None:
    """Add a new authenticated client."""
    self._clients_by_uuid[client.uuid] = client
    self._clients_by_websocket[client.websocket] = client

get_clients

get_clients() -> list[Client[UserT]]

Get a list of all clients.

Source code in proxystore/p2p/relay/manager.py
def get_clients(self) -> list[Client[UserT]]:
    """Get a list of all clients."""
    return list(self._clients_by_uuid.values())

get_client_by_uuid

get_client_by_uuid(uuid: UUID) -> Client[UserT] | None

Get a client by the client's UUID.

Source code in proxystore/p2p/relay/manager.py
def get_client_by_uuid(self, uuid: uuid.UUID) -> Client[UserT] | None:
    """Get a client by the client's UUID."""
    return self._clients_by_uuid.get(uuid, None)

get_client_by_websocket

get_client_by_websocket(
    websocket: WebSocketServerProtocol,
) -> Client[UserT] | None

Get a client by the current websocket connection.

Source code in proxystore/p2p/relay/manager.py
def get_client_by_websocket(
    self,
    websocket: WebSocketServerProtocol,
) -> Client[UserT] | None:
    """Get a client by the current websocket connection."""
    return self._clients_by_websocket.get(websocket, None)

remove_client

remove_client(client: Client[UserT]) -> None

Remove a client.

Source code in proxystore/p2p/relay/manager.py
def remove_client(self, client: Client[UserT]) -> None:
    """Remove a client."""
    self._clients_by_uuid.pop(client.uuid, None)
    self._clients_by_websocket.pop(client.websocket, None)