Skip to main content

Module rpc

Module rpc 

Source
Expand description

The peer-stream RPC framing — how a typed JSON-RPC call rides one mux stream.

dig-rpc is an HTTP JSON-RPC server; the peer surface instead carries JSON-RPC over dig-nat’s multiplexed mTLS streams. dig-peer defines that on-stream framing here and is the CLIENT that speaks it. Each call opens ONE fresh logical stream, writes a single length-prefixed request body, reads a single length-prefixed response body, and lets the stream close — a clean request/response per stream, with concurrency provided by the mux (open many streams).

§Framing (normative)

A body is a u32 big-endian length prefix followed by that many bytes — the SAME uniform framing dig-nat’s control messages use, so the two never disagree. For an unsealed (public-read) call the body is the JSON of a JsonRpcRequest/JsonRpcResponse. For a directed (sealed) call the body is the byte-serialized sealed dig_message envelope wrapping that JSON (§5.4). The MAX_BODY bound guards against a malicious length prefix forcing a huge allocation.

Constants§

MAX_BODY
Maximum length-prefixed body dig-peer will read — guards against a hostile length prefix. Matches dig-nat’s control-frame bound (64 KiB) for small control/RPC messages.

Functions§

from_json
Deserialize a JSON body from the wire into a typed value.
read_framed
Read one length-prefixed body (u32 big-endian length + bytes) from r, bounded by MAX_BODY.
to_json
Serialize a value to a JSON body for the wire.
write_framed
Write a length-prefixed body (u32 big-endian length + bytes) to w.