dig_node_control_interface/lib.rs
1//! # dig-node-control-interface — the canonical client ⇄ dig-node CONTROL interface contract
2//!
3//! This crate is the single source of truth for the management/query surface a client — the CLI
4//! `dign`, the browser extension, dig-app, or hub — uses to **control and query a running
5//! dig-node**: node configuration, cache configuration, hosted/pinned stores, §21 whole-store sync,
6//! the peer network, subscription lifecycle, the auto-update beacon, live log level, and the
7//! control-token pairing handshake. Both the node (the server side, dispatching these calls) and
8//! every client (the callers) depend on THIS crate rather than each maintaining a byte-identical
9//! copy of the method catalog, so the two can never silently drift.
10//!
11//! ## The catalog
12//!
13//! - [`ControlMethod`] — every control method's stable wire name, auth requirement, routing, and
14//! category; the enumeration a machine reads to discover the whole surface.
15//! - [`params`] — a typed request-params struct per method, each bound (via [`ControlCall`]) to its
16//! method and its typed result.
17//! - [`results`] — the typed result payloads, field-for-field with what dig-node emits.
18//! Includes [`PeerSoftware`], the one interpreted member of the otherwise-proxied
19//! `control.peerStatus` snapshot: a peer's advertised software build, defined here so every
20//! client reads a gossip handshake's `software_version` string the same way.
21//! - [`error`] — the stable control-error taxonomy ([`ControlErrorCode`]) + the [`ControlError`]
22//! envelope a client branches its UX off.
23//! - [`envelope`] — the minimal JSON-RPC 2.0 request/response the catalog rides in.
24//! - [`traits`] — the two contract traits: [`ControlClient`] (client-facing: build request / parse
25//! response) and [`ControlHandler`] (node-facing: implement to serve, with a routing dispatcher).
26//!
27//! ## Boundary (the 6th directed-boundary contract crate)
28//!
29//! - **dig-rpc-protocol** — node ⇄ node peer wire (PublicRead + Peer tiers).
30//! - **dig-ipc-protocol** — app ⇄ node local session/signing envelope (the transport a client
31//! authenticates over).
32//! - **dig-node-control-interface (this crate)** — the CONTROL METHOD CATALOG a client sends
33//! *inside* that authenticated channel (or over loopback-mTLS + a signed control token, per
34//! CLAUDE.md §5.3): the method names, parameter/result types, and error taxonomy.
35//!
36//! This crate is deliberately **transport-agnostic** — it describes WHAT a client can ask a node to
37//! do and what the node replies, not HOW the bytes travel. Consumers pick the transport and carry
38//! these types over it.
39//!
40//! ## Example — build a typed request and parse the response
41//!
42//! ```
43//! use dig_node_control_interface::{
44//! params::SetCapParams,
45//! traits::{build_request, parse_response},
46//! envelope::JsonRpcResponse,
47//! };
48//! use serde_json::json;
49//!
50//! let call = SetCapParams { cap_bytes: 128 * 1024 * 1024 };
51//! let req = build_request(1.into(), &call);
52//! assert_eq!(req.method, "control.cache.setCap");
53//!
54//! // The node replies with the applied cap; parse it back into the typed result.
55//! let resp = JsonRpcResponse::success(1.into(), json!({ "cap_bytes": 128 * 1024 * 1024 }));
56//! let out = parse_response::<SetCapParams>(resp).unwrap();
57//! assert_eq!(out.cap_bytes, 128 * 1024 * 1024);
58//! ```
59
60#![forbid(unsafe_code)]
61#![warn(missing_docs)]
62
63pub mod envelope;
64pub mod error;
65pub mod method;
66pub mod params;
67pub mod results;
68pub mod traits;
69
70#[cfg(test)]
71mod kats;
72
73pub use error::{ControlError, ControlErrorCode, ControlErrorData};
74pub use method::{Category, ControlMethod, Routing};
75pub use results::{PeerSoftware, SoftwareVersionDetail};
76pub use traits::{ControlCall, ControlClient, ControlHandler, DefaultControlClient};
77
78/// The crate's semantic version, exposed so consumers can assert compatibility at runtime without
79/// re-parsing `Cargo.toml`.
80pub const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION");