use std::sync::Arc;
use qrpc::{Ctx, QrpcInstance, QrpcResult, State};
#[path = "common/demo_support.rs"]
mod demo_support;
use demo_support::DemoEnvelope;
#[tokio::main]
async fn main() -> QrpcResult<()> {
let instance =
QrpcInstance::<(), DemoEnvelope, _>::builder(
|_state: State<()>,
_ctx: Ctx<DemoEnvelope>,
source_peer_id: String,
msg: DemoEnvelope| async move {
println!("[serve-20001] recv from={} msg={msg:?}", source_peer_id);
Ok(())
},
)
.with_id("node-serve-20001")
.with_ca_cert("tests/certs/ca.crt")
.with_identity("tests/certs/server.crt", "tests/certs/server.key")
.with_port(20001)
.build()?;
let instance = Arc::new(instance);
let shutdown_instance = Arc::clone(&instance);
tokio::spawn(async move {
let _ = tokio::signal::ctrl_c().await;
shutdown_instance.shutdown().await;
});
println!("[serve-20001] started, press Ctrl+C to stop");
instance.serve().await;
println!("[serve-20001] stopped");
Ok(())
}