qrpc
qrpc is a small QUIC + mTLS messaging library where each QrpcInstance works as both server and client.
Features:
- bidirectional long-lived connections,
- peer registration by unique ID,
- direct send and broadcast,
- typestate builder (
WithoutState/WithState), - user-defined message trait (
QrpcMessage) with no protobuf requirement.
Minimal Usage (Self-Contained, No Proto)
This is the smallest complete setup using:
- an empty
AppStatestruct, - a custom text message type,
- a single
QrpcInstance.
use Arc;
use ;
;
async
Lifecycle APIs
start()starts background accept/connect loops and returns immediately.serve()callsstart()and then blocks untilshutdown()is called.serve_with(|ctx| async { ... })runs one worker callback while serving.- If worker returns
Ok(()), instance keeps serving untilshutdown(). - If worker returns
Err(_), instance logsERRORand keeps serving untilshutdown().
- If worker returns
serve_with_rx(rx)serves while consumingOutboundCmdfrom anmpsc::Receiver.SendTowaits for target peer connection before sending.Broadcastsends to currently connected peers only (no peers => no-op).
Active publish pattern:
use ;
let instance = new;
let worker_instance = clone;
instance
.serve_with
.await?;
TLS Identity Notes
with_identity(cert, key)configures the local server certificate (used when peers dial this node).- By default, outgoing dials reuse the same identity.
- If your certs split EKU (
serverAuthvsclientAuth), also set:with_client_identity(client_cert, client_key)for outgoing dials.
Example:
.with_identity
.with_client_identity
Connection Liveness
- Default keepalive interval:
10s. - Default max idle timeout:
600s(10 minutes). - Tune with builder methods:
with_keep_alive_interval(Some(Duration::from_secs(...)))with_max_idle_timeout(Some(Duration::from_secs(...)))- pass
Noneto disable keepalive or set infinite idle timeout.
Example:
use Duration;
.with_keep_alive_interval
.with_max_idle_timeout
State Rules
- Use
.with_state(S)to build an instance with any custom state typeS. - Callback signature uses
State<T>.Tis extracted fromSviaFromRef<S>. - Callback also receives
Ctx<M>plussource_peer_id: String. Ctx<M>supportssend_to/broadcast/peer_ids/wait_for_peer/shutdown.- By default,
FromRef<T> for Tis available whenT: Clone. - If you need shared ownership, pass
Arc<T>asS(same pattern as axum state). - If you do not call
with_state,build()is available only forS = ()and the builder injects()automatically.
Running Built-in Examples
LICENSE
See LICENSE