server updates
This commit is contained in:
parent
24fb41a0d5
commit
de2c99731f
@ -92,7 +92,7 @@ impl KeyboardAggregator {
|
||||
self.dev_log(|| debug!(?report, "Keyboard HID report"));
|
||||
self.send_report(report);
|
||||
if self.is_magic_chord() {
|
||||
self.dev_log(|| warn!("Magic chord pressed => 🧙♂️🪄💥 AVADA KEDAVRA!!! 💀"));
|
||||
self.dev_log(|| warn!("Magic chord pressed => 🧙♂️🪄 AVADA KEDAVRA!!! 💥💀"));
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,50 +36,55 @@ impl Relay for Handler {
|
||||
let (tx, rx) = tokio::sync::mpsc::channel(32);
|
||||
|
||||
tokio::spawn(async move {
|
||||
while let Some(msg) = in_stream.next().await.transpose()? {
|
||||
match msg.kind {
|
||||
/* ───── KEYBOARD ───── */
|
||||
Some(hid_report::Kind::KeyboardReport(ref v)) if v.len() == 8 => {
|
||||
match kb.lock().await.write_all(v).await {
|
||||
Ok(_) => info!("⌨️ → /dev/hidg0 (8 B)"),
|
||||
loop {
|
||||
match in_stream.next().await {
|
||||
/* ──────────────── message received ──────────────── */
|
||||
Some(Ok(msg)) => {
|
||||
// 1. write to the right gadget ---------------------------------
|
||||
let io_res = match &msg.kind {
|
||||
Some(hid_report::Kind::KeyboardReport(v)) if v.len() == 8 => {
|
||||
kb.lock().await.write_all(v).await.map(|_| "⌨️ → /dev/hidg0 (8 B)")
|
||||
}
|
||||
Some(hid_report::Kind::MouseReport(v)) if v.len() == 4 => {
|
||||
ms.lock().await.write_all(v).await.map(|_| "🖱️ → /dev/hidg1 (4 B)")
|
||||
}
|
||||
_ => {
|
||||
error!(?msg.kind, "⚠️ malformed packet");
|
||||
continue; // skip echo
|
||||
}
|
||||
};
|
||||
|
||||
// 2. I/O result -------------------------------------------------
|
||||
match io_res {
|
||||
Ok(msg_txt) => info!("{msg_txt}"),
|
||||
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {
|
||||
trace!("⌨️ /dev/hidg0 busy, dropped packet");
|
||||
continue;
|
||||
trace!("🐛 gadget busy, dropped packet");
|
||||
continue; // skip echo
|
||||
}
|
||||
Err(e) => {
|
||||
error!("⌨️ write error: {e}");
|
||||
continue;
|
||||
error!("write error: {e}");
|
||||
continue; // skip echo
|
||||
}
|
||||
}
|
||||
|
||||
// 3. echo back (best‑effort) -----------------------------------
|
||||
let _ = tx.try_send(Ok(msg));
|
||||
}
|
||||
|
||||
/* ───── MOUSE ───── */
|
||||
Some(hid_report::Kind::MouseReport(ref v)) if v.len() == 4 => {
|
||||
match ms.lock().await.write_all(v).await {
|
||||
Ok(_) => info!("🖱️ → /dev/hidg1 (4 B)"),
|
||||
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {
|
||||
trace!("🖱️ /dev/hidg1 busy, dropped packet");
|
||||
continue;
|
||||
}
|
||||
Err(e) => {
|
||||
error!("🖱️ write error: {e}");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ───── bad / unknown ───── */
|
||||
_ => {
|
||||
error!(?msg.kind, "⚠️ malformed packet");
|
||||
continue;
|
||||
|
||||
/* ──────────────── benign back‑pressure error ──────────────── */
|
||||
Some(Err(status)) => {
|
||||
trace!("grpc recv error (ignored): {status}");
|
||||
continue; // keep the stream alive
|
||||
}
|
||||
|
||||
/* ──────────────── client closed the stream ──────────────── */
|
||||
None => break,
|
||||
}
|
||||
|
||||
// echo back so the client knows we’re alive
|
||||
let _ = tx.send(Ok(msg)).await;
|
||||
}
|
||||
|
||||
info!("🔚 client stream closed");
|
||||
Ok::<_, Status>(())
|
||||
// dropping `tx` here terminates the server→client stream gracefully
|
||||
Ok::<(), Status>(())
|
||||
});
|
||||
|
||||
Ok(Response::new(Box::pin(ReceiverStream::new(rx))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user