proxystore.endpoint.protocol¶
Client-endpoint wire protocol.
Clients communicate with their local endpoint over a TCP connection using
length-prefixed binary messages. This module only contains the encoding and
decoding logic, and it only depends on the standard library so the client
does not require any of the endpoints extra dependencies.
A connection starts with a handshake:
- The client sends a preamble (
MAGICandPROTOCOL_VERSION) followed by aHELLOmessage with a random nonce and the client's versions. - The endpoint replies with its preamble and a message with its own nonce and a proof that it knows the endpoint's token.
- The client verifies the endpoint's proof then sends an
AUTHmessage with its own proof. - The endpoint verifies the client's proof and replies with its information (UUID, name, and versions).
The preamble format must never change so that clients and endpoints using different protocol versions can detect the mismatch. If the protocol versions differ, the endpoint replies with only its preamble and closes the connection.
After the handshake, each request and response is a message consisting of a fixed-size header, JSON-encoded metadata (e.g., the key), and a raw data payload.
PROTOCOL_VERSION
module-attribute
¶
Version of the protocol.
Increment on any incompatible change to the handshake or message formats.
NONCE_SIZE
module-attribute
¶
Size in bytes of the random nonces exchanged in the handshake.
MAX_META_SIZE
module-attribute
¶
Maximum size in bytes of the metadata in a message.
VERSION_DOCS_URL
module-attribute
¶
Documentation on version compatibility between clients and endpoints.
Op
¶
Status
¶
Preamble
dataclass
¶
Preamble(version: int = PROTOCOL_VERSION)
Preamble that starts every connection.
The format of the preamble must never change so that clients and endpoints using different protocol versions can detect the mismatch.
Attributes:
-
version(int) –Protocol version of the sender.
FORMAT
class-attribute
¶
Format of the magic bytes and protocol version.
unpack
classmethod
¶
Unpack a preamble.
Raises:
-
EndpointProtocolError–If the preamble does not start with
MAGIC.
Source code in proxystore/endpoint/protocol.py
Header
dataclass
¶
Message header.
Attributes:
-
code(int) – -
flags(int) –Reserved for future use.
-
meta_len(int) –Length in bytes of the metadata.
-
data_len(int) –Length in bytes of the data.
FORMAT
class-attribute
¶
Format of the code, flags, metadata length, and data length.
unpack
classmethod
¶
Unpack a header.
Raises:
-
EndpointProtocolError–If the metadata length exceeds
MAX_META_SIZE.
Source code in proxystore/endpoint/protocol.py
Versions
¶
Bases: NamedTuple
ProxyStore and Python versions of a client or endpoint.
Attributes:
mismatches
¶
Find differences between this client's and the endpoint's versions.
The ProxyStore versions must match exactly. The Python versions must have the same major and minor version because objects pickled by one Python version may not unpickle with another, but patch releases are compatible.
Parameters:
-
endpoint(Versions) –Versions of the endpoint.
Returns:
Source code in proxystore/endpoint/protocol.py
Hello
dataclass
¶
First message of the handshake sent by the client.
Attributes:
to_meta
¶
from_meta
classmethod
¶
Decode from message metadata.
Raises:
-
EndpointProtocolError–If the metadata is malformed.
Source code in proxystore/endpoint/protocol.py
Challenge
dataclass
¶
Reply of the endpoint to Hello.
Attributes:
-
nonce(bytes) –Random nonce chosen by the endpoint.
-
proof(bytes) –Proof that the endpoint knows the token.
to_meta
¶
from_meta
classmethod
¶
Decode from message metadata.
Raises:
-
EndpointProtocolError–If the metadata is malformed.
Source code in proxystore/endpoint/protocol.py
Auth
dataclass
¶
Auth(proof: bytes)
Second message of the handshake with the proof of the client.
Attributes:
-
proof(bytes) –Proof that the client knows the token.
to_meta
¶
from_meta
classmethod
¶
EndpointInfo
dataclass
¶
Information about an endpoint sent at the end of the handshake.
Attributes:
-
uuid(UUID) –UUID of the endpoint.
-
name(str) –Name of the endpoint.
-
versions(Versions) –Versions of the endpoint.
-
max_object_size(int | None) –Maximum size in bytes of objects that can be set on the endpoint or
Noneif there is no limit.
to_meta
¶
from_meta
classmethod
¶
Decode from message metadata.
Raises:
-
EndpointProtocolError–If the metadata is malformed.
Source code in proxystore/endpoint/protocol.py
Request
dataclass
¶
Metadata of a request sent by a client after the handshake.
Attributes:
-
key(str) –Key of the object.
-
endpoint(UUID | None) –UUID of the endpoint to forward the request to or
Nonefor the local endpoint.
to_meta
¶
from_meta
classmethod
¶
Decode from message metadata.
Raises:
-
EndpointProtocolError–If the metadata is malformed.
Source code in proxystore/endpoint/protocol.py
pack_message
¶
Pack the header and metadata of a message.
The data (if any) is not included so it can be sent separately without being copied.
Parameters:
-
code(int) –Op or status code.
-
meta(dict[str, Any] | None, default:None) –Metadata to include in the message.
-
data_len(int, default:0) –Length in bytes of the data that will follow.
Source code in proxystore/endpoint/protocol.py
encode_meta
¶
decode_meta
¶
Decode message metadata.
Raises:
-
EndpointProtocolError–If the metadata is not a JSON object.