proxystore.p2p.manager¶
Manager of many peer-to-peer connections.
PeerManager
¶
PeerManager(
relay_client: RelayClient,
*,
timeout: int = 30,
peer_channels: int = 1
)
Peer Connections Manager.
Handles establishing peer connections via aiortc, responding to requests for new peer connections from the relay server, and sending and receiving data to/from existing peer connections.
Example
from proxystore.p2p.manager import PeerManager
from proxystore.p2p.relay import BasicRelayClient
relay_client = BasicRelayClient(relay_server_address)
pm1 = await PeerManager(relay_client)
pm2 = await PeerManager(relay_client)
await pm1.send(pm2.uuid, 'hello hello')
source_uuid, message = await pm2.recv()
assert source_uuid == pm1.uuid
assert message == 'hello hello'
await pm1.close()
await pm2.close()
Note
The class can also be used as an asynchronous context manager.
Parameters:
-
relay_client
(RelayClient
) –Established client interface to a relay server.
-
timeout
(int
, default:30
) –Timeout in seconds when waiting for a peer connection to be established.
-
peer_channels
(int
, default:1
) –number of datachannels to split message sending over between each peer.
Raises:
-
ValueError
–If the relay server address does not start with "ws://" or "wss://".
Source code in proxystore/p2p/manager.py
relay_client
property
¶
relay_client: RelayClient
Relay client interface.
Raises:
-
RuntimeError
–if the manager is not initialized with
await
orPeerManager.async_init()
has not been called.
async_init
async
¶
Connect to relay server and being listening to incoming messages.
Source code in proxystore/p2p/manager.py
close
async
¶
Close the connection manager.
Warning
This will close all create peer connections and close the connection to the relay server.
Source code in proxystore/p2p/manager.py
close_connection
async
¶
Close a peer connection if it exists.
This will close the associated
PeerConnection
and
cancel the asyncio task handling peer messages. If the
PeerManager
is used to
send a message from the peer again, a new connection will be
established.
Parameters:
-
peers
(Iterable[UUID]
) –Iterable containing the two peer UUIDs taking part in the connection that should be closed.
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
, default:30
) –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(peer_uuid: UUID) -> PeerConnection
Get connection to the peer.
Parameters:
-
peer_uuid
(UUID
) –UUID of peer to make connection with.
Returns:
-
PeerConnection
–The peer connection object.