Skip to main content

Module server

Module server 

Source
Expand description

The RpcServer — Axum-based JSON-RPC server with lifecycle integration for dig_service::ShutdownToken.

§Responsibilities

  • Build an Axum Router with:
    • POST / — JSON-RPC dispatch.
    • GET /healthz — liveness.
    • GET /metrics — Prometheus (behind the metrics feature, wired by the binary).
  • Attach the middleware stack: request-id, panic-catch, audit, rate-limit, allow-list.
  • Drive axum-server with TLS configured per RpcServerMode.
  • Exit serve when the supplied ShutdownToken fires.

§v0.1 scope

The v0.1 server implements the full JSON-RPC dispatch pipeline and includes per-request rate limiting. Full mTLS client-cert extraction is wired via rustls’s WebPkiClientVerifier at TLS-handshake time, but binaries that want to resolve the authenticated cert to a Role in middleware should plug in a pluggable extractor (v0.2 enhancement).

§Minimal example

use std::sync::Arc;
use dig_rpc::{RpcServer, RpcServerMode, MethodRegistry, MethodMeta, RateBucket};
use dig_rpc::role::Role;
let api: Arc<MyApi> = Arc::new(MyApi);
let registry = MethodRegistry::new();
registry.register(MethodMeta::read("healthz", Role::Explorer, RateBucket::ReadLight));

let server = RpcServer::new(api, registry, RpcServerMode::public_plaintext("127.0.0.1:9447".parse().unwrap()));
let shutdown = dig_service::ShutdownToken::new();
match server.serve(shutdown).await {
    Ok(()) => unreachable!(),
    Err(e) => return e,
}

Structs§

RpcServer
The JSON-RPC server itself.

Enums§

RpcServerMode
Server deployment mode.