proxystore.p2p.manager
Manager of many peer-to-peer connections.
PeerManager ¶
PeerManager(
uuid: UUID,
signaling_server: str,
name: str | None = None,
*,
timeout: int = 30,
peer_channels: int = 1,
verify_certificate: bool = True
) -> None
Peer Connections Manager.
Handles establishing peer connections via aiortc, responding to requests for new peer connections from the signaling server, and sending and receiving data to/from existing peer connections.
Example
from proxystore.p2p.manager import PeerManager
pm1 = await PeerManager(uuid.uuid4(), signaling_server_address)
pm2 = await PeerManager(uuid.uuid4(), signaling_server_address)
await pm1.send(pm2.uuid, 'hello hello')
source_uuid, message = await pm2.recv()
assert source_uuid == pm1.uuid
assert message == 'hello hello'
pm1.close()
pm2.close()
Warning
The class must be initialized with await or inside an async with statement to correctly configure all async tasks and connections.
Parameters:
-
uuid
(
UUID
) –UUID of the client.
-
signaling_server
(
str
) –Address of signaling server to use for establishing peer-to-peer connections.
-
name
(
str | None
) –Readable name of the client to use in logging. If unspecified, the hostname will be used.
-
timeout
(
int
) –Timeout in seconds when waiting for a peer or signaling server connection to be established.
-
peer_channels
(
int
) –number of datachannels to split message sending over between each peer.
-
verify_certificate
(
bool
) –Verify the signaling server's SSL certificate,
Raises:
-
ValueError
–If the signaling server address does not start with "ws://" or "wss://".
Source code in proxystore/p2p/manager.py
async_init
async
¶
Connect to signaling server.
Source code in proxystore/p2p/manager.py
close
async
¶
Close the connection manager.
Source code in proxystore/p2p/manager.py
recv
async
¶
Receive next message from a peer.
Returns:
send
async
¶
Send message to peer.
Parameters:
-
peer_uuid
(
UUID
) –UUID of peer to send message to.
-
message
(
bytes | str
) –Message to send to peer.
-
timeout
(
float
) –Timeout to wait on peer connection to be ready.
Raises:
-
PeerConnectionTimeoutError
–If the peer connection is not established within the timeout.
Source code in proxystore/p2p/manager.py
get_connection
async
¶
Get connection to the peer.
Parameters:
-
peer_uuid
(
UUID
) –UUID of peer to make connection with.
Returns:
-
PeerConnection
–The peer connection object.