QUIC Transport Layer (palyra-transport-quic)
The palyra-transport-quic crate provides a specialized wrapper around the quinn library to implement a frame-based protocol over QUIC. It handles TLS 1.3 certificate validation, ALPN negotiation (palyra-quic-v1), and stream multiplexing crates/palyra-transport-quic/src/lib.rs#12-14.
Transport Implementation
The transport layer uses bidirectional streams to exchange JSON-serialized frames. Each frame is prefixed with its length to allow robust reading from the QUIC stream crates/palyra-transport-quic/src/lib.rs#149-152.QuicRuntimeRequest: Sent by the node to the daemon. Contains theprotocol_version,method(e.g.,node.health,node.stream_events), and an optionalresume_fromsequence number for event recovery crates/palyra-daemon/src/quic_runtime.rs#42-47.QuicRuntimeResponse: Returned by the daemon. Includes status flags, sequence numbers for events, and protocol error details crates/palyra-daemon/src/quic_runtime.rs#49-60.
Connection Lifecycle
TheQuicRuntime in the daemon manages the lifecycle of these connections, enforcing a concurrency limit (default 256) via a tokio::sync::Semaphore crates/palyra-daemon/src/quic_runtime.rs#16-91.
QUIC Connection Data Flow
Sources: crates/palyra-daemon/src/quic_runtime.rs#82-198, crates/palyra-transport-quic/src/lib.rs#120-176
Node RPC Interface
While QUIC handles the “fast path” of events, theNodeRpcServiceImpl provides a formal gRPC interface (defined in node.proto) for node orchestration. This service is typically exposed on a separate port and requires mTLS for all operations except initial pairing crates/palyra-daemon/src/node_rpc.rs#38-54.
Security and mTLS Enforcement
The Node RPC surface is hardened using certificate-bound identity:- Fingerprint Validation: Every request’s TLS certificate is hashed (SHA-256) and checked against a
RevocationIndexcrates/palyra-daemon/src/node_rpc.rs#56-97. - Device Binding: The
enforce_cert_bound_devicefunction ensures that thedevice_idprovided in the gRPC metadata matches the identity strictly bound to the client certificate during the pairing process crates/palyra-daemon/src/node_rpc.rs#99-129. - Revocation: If a node’s certificate is revoked via the
IdentityManager, theRevocationAwareClientVerifierwill terminate the TLS handshake before the gRPC layer is reached crates/palyra-identity/src/mtls.rs#80-105.
Key RPC Methods
| Method | Purpose | Source |
|---|---|---|
RegisterNode | Announces node presence, platform, and capabilities. | crates/palyra-daemon/src/node_rpc.rs#205 |
StreamEvents | Long-polling or streaming channel for capability dispatch. | crates/palyra-daemon/src/node_rpc.rs#230 |
SubmitCapabilityResult | Returns the JSON output of a remote task execution. | crates/palyra-daemon/src/node_rpc.rs#260 |
MintNodePairingCode | Admin-only: generates a PIN/QR code for new nodes. | crates/palyra-daemon/src/node_rpc.rs#330 |
Node Pairing Handshake
Palyra uses a “Trust On First Use” (TOFU) pairing model with out-of-band verification (PIN or QR code). This process upgrades an unauthenticated connection to a fully mTLS-secured relationship.Handshake Sequence
- Minting: An admin generates a
DevicePairingCodeRecordcrates/palyra-daemon/src/node_runtime.rs#48-54. - Hello: The node sends a
DevicePairingHellocontaining its ephemeral public key and the pairing proof (PIN) crates/palyra-identity/src/pairing/handshake.rs#111-118. - Verification: The daemon verifies the proof and creates a
VerifiedPairingobject crates/palyra-identity/src/pairing/handshake.rs#129-137. - Material Issuance: Once approved (either automatically or via
palyra pairing approve), the daemon issues a client certificate signed by the Gateway CA crates/palyra-daemon/src/node_runtime.rs#79-87.
Node Runtime and Inventory Management
TheNodeRuntimeState manages the inventory of all registered remote nodes and handles the asynchronous dispatch of capabilities.
Remote Capability Dispatch
When the daemon needs to execute a tool on a remote node (e.g., a filesystem operation on a paired laptop), it uses the following flow:- Queueing: The request is added to
queued_by_devicein theCapabilityRuntimeStatecrates/palyra-daemon/src/node_runtime.rs#165-170. - Notification: The node, which is listening via
StreamEvents(gRPC) ornode.stream_events(QUIC), receives aCapabilityDispatchRecordcrates/palyra-daemon/src/node_runtime.rs#151-156. - Execution: The node executes the task and calls
SubmitCapabilityResultcrates/palyra-daemon/src/node_rpc.rs#260. - Completion: The
NodeRuntimeStatematches therequest_idand triggers aoneshot::Senderto return the result to the orchestrator crates/palyra-daemon/src/node_runtime.rs#169-170.
Persisted State
The node inventory and pairing history are persisted innode-runtime.v1.json within the state root crates/palyra-daemon/src/node_runtime.rs#19-22. This includes:
active_pairing_codes: Currently valid PINs crates/palyra-daemon/src/node_runtime.rs#143.nodes: A map ofRegisteredNodeRecordcontaining platform info and last-seen timestamps crates/palyra-daemon/src/node_runtime.rs#130-148.
| System Concept | Code Entity (Rust) | Role |
|---|---|---|
| Node Registry | RegisteredNodeRecord | Stores device capabilities and metadata. |
| Pairing Logic | IdentityManager | Manages CA and certificate issuance. |
| Task Queue | CapabilityRuntimeState | Tracks in-flight remote requests and waiters. |
| CLI Client | run_node_foreground | The primary loop for a remote node instance. |