⎇ 53dbdf0f1deea10d6fc567ea2b43e1e75d6d60cd
crates/core/ente-echo/src/main.rs
Historia
Quién tocó qué
crudo
chore: monorepo inicial con arje + minga + yahweh absorbidos
1//! ente-echo: Ente proveedor mínimo. Anuncia Capability::Endpoint(ECHO) y
2//! responde a invokes echando el blob recibido. Vehículo para validar el
3//! forwarding bus → proveedor → bus → originator.
4
5use ente_bus::{BusResponse, BusServer, InvokeHandler};
6use ente_card::Capability;
7use ente_echo::{echo_capability, ECHO_IFACE, ECHO_VERSION};
8use tracing::{info, warn};
9use tracing_subscriber::EnvFilter;
10
11struct EchoHandler;
12
13impl InvokeHandler for EchoHandler {
14 fn handle(&mut self, cap: Capability, blob: Vec<u8>) -> BusResponse {
15 match cap {
16 Capability::Endpoint { interface, version }
17 if interface == ECHO_IFACE && version == ECHO_VERSION =>
18 {
19 let preview = String::from_utf8_lossy(&blob).into_owned();
20 info!(text = %preview, len = blob.len(), "echo invoke");
21 BusResponse::Invoked { result: blob }
22 }
23 other => {
24 warn!(?other, "ente-echo: capacidad no soportada");
25 BusResponse::Error("ente-echo solo maneja ECHO_IFACE".into())
26 }
27 }
28 }
29}
30
31#[tokio::main(flavor = "current_thread")]
32async fn main() -> anyhow::Result<()> {
33 let filter = EnvFilter::try_from_default_env()
34 .unwrap_or_else(|_| EnvFilter::new("ente_echo=info"));
35 tracing_subscriber::fmt().with_env_filter(filter).with_target(true).init();
36
37 info!("ente-echo arrancando");
38 let mut server = BusServer::from_env().await?;
39 server.announce(vec![echo_capability()]).await?;
40 info!("Announce OK, sirviendo invokes");
41
42 if let Err(e) = server.serve(EchoHandler).await {
43 warn!(?e, "serve terminó");
44 }
45 Ok(())
46}