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.dev_log(|| debug!(?report, "Keyboard HID report"));
|
||||||
self.send_report(report);
|
self.send_report(report);
|
||||||
if self.is_magic_chord() {
|
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);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,50 +36,55 @@ impl Relay for Handler {
|
|||||||
let (tx, rx) = tokio::sync::mpsc::channel(32);
|
let (tx, rx) = tokio::sync::mpsc::channel(32);
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Some(msg) = in_stream.next().await.transpose()? {
|
loop {
|
||||||
match msg.kind {
|
match in_stream.next().await {
|
||||||
/* ───── KEYBOARD ───── */
|
/* ──────────────── message received ──────────────── */
|
||||||
Some(hid_report::Kind::KeyboardReport(ref v)) if v.len() == 8 => {
|
Some(Ok(msg)) => {
|
||||||
match kb.lock().await.write_all(v).await {
|
// 1. write to the right gadget ---------------------------------
|
||||||
Ok(_) => info!("⌨️ → /dev/hidg0 (8 B)"),
|
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 => {
|
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {
|
||||||
trace!("⌨️ /dev/hidg0 busy, dropped packet");
|
trace!("🐛 gadget busy, dropped packet");
|
||||||
continue;
|
continue; // skip echo
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("⌨️ write error: {e}");
|
error!("write error: {e}");
|
||||||
continue;
|
continue; // skip echo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3. echo back (best‑effort) -----------------------------------
|
||||||
|
let _ = tx.try_send(Ok(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ───── MOUSE ───── */
|
/* ──────────────── benign back‑pressure error ──────────────── */
|
||||||
Some(hid_report::Kind::MouseReport(ref v)) if v.len() == 4 => {
|
Some(Err(status)) => {
|
||||||
match ms.lock().await.write_all(v).await {
|
trace!("grpc recv error (ignored): {status}");
|
||||||
Ok(_) => info!("🖱️ → /dev/hidg1 (4 B)"),
|
continue; // keep the stream alive
|
||||||
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 ───── */
|
/* ──────────────── client closed the stream ──────────────── */
|
||||||
_ => {
|
None => break,
|
||||||
error!(?msg.kind, "⚠️ malformed packet");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// echo back so the client knows we’re alive
|
|
||||||
let _ = tx.send(Ok(msg)).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("🔚 client stream closed");
|
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))))
|
Ok(Response::new(Box::pin(ReceiverStream::new(rx))))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user