Compare commits

..

3 Commits

Author SHA1 Message Date
Ferdinand Schober
70e2d9fecb update macos + windows 2024-08-11 16:28:22 +02:00
Ferdinand Schober
ede8cd4acb include size_of for older rust versions 2024-08-11 16:00:03 +02:00
Ferdinand Schober
1e1476d58e move lan-mouse protocol into separate crate 2024-08-09 15:01:39 +02:00
8 changed files with 61 additions and 54 deletions

18
Cargo.lock generated
View File

@@ -1324,7 +1324,6 @@ dependencies = [
"lan-mouse-proto",
"libadwaita",
"libc",
"local-channel",
"log",
"serde",
"serde_json",
@@ -1404,23 +1403,6 @@ version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
[[package]]
name = "local-channel"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6cbc85e69b8df4b8bb8b89ec634e7189099cea8927a276b7384ce5488e53ec8"
dependencies = [
"futures-core",
"futures-sink",
"local-waker",
]
[[package]]
name = "local-waker"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d873d7c67ce09b42110d801813efbc9364414e356be9935700d368351657487"
[[package]]
name = "lock_api"
version = "0.4.12"

View File

@@ -50,7 +50,6 @@ slab = "0.4.9"
endi = "1.1.0"
thiserror = "1.0.61"
tokio-util = "0.7.11"
local-channel = "0.1.5"
[target.'cfg(unix)'.dependencies]
libc = "0.2.148"

View File

@@ -1,5 +1,5 @@
use local_channel::mpsc::Receiver;
use std::net::IpAddr;
use tokio::sync::mpsc::Receiver;
use hickory_resolver::{error::ResolveError, TokioAsyncResolver};

View File

@@ -1,6 +1,5 @@
use capture_task::CaptureRequest;
use emulation_task::EmulationRequest;
use local_channel::mpsc::{channel, Sender};
use log;
use std::{
cell::{Cell, RefCell},
@@ -9,7 +8,15 @@ use std::{
net::{IpAddr, SocketAddr},
rc::Rc,
};
use tokio::{io::ReadHalf, join, signal, sync::Notify, task::JoinHandle};
use tokio::{
io::ReadHalf,
join, signal,
sync::{
mpsc::{channel, Sender},
Notify,
},
task::JoinHandle,
};
use tokio_util::sync::CancellationToken;
use crate::{
@@ -123,12 +130,12 @@ impl Server {
}
};
let (capture_tx, capture_rx) = channel(); /* requests for input capture */
let (emulation_tx, emulation_rx) = channel(); /* emulation requests */
let (udp_recv_tx, udp_recv_rx) = channel(); /* udp receiver */
let (udp_send_tx, udp_send_rx) = channel(); /* udp sender */
let (request_tx, mut request_rx) = channel(); /* frontend requests */
let (dns_tx, dns_rx) = channel(); /* dns requests */
let (capture_tx, capture_rx) = channel(1); /* requests for input capture */
let (emulation_tx, emulation_rx) = channel(1); /* emulation requests */
let (udp_recv_tx, udp_recv_rx) = channel(1); /* udp receiver */
let (udp_send_tx, udp_send_rx) = channel(1); /* udp sender */
let (request_tx, mut request_rx) = channel(1); /* frontend requests */
let (dns_tx, dns_rx) = channel(1); /* dns requests */
// udp task
let network = network_task::new(self.clone(), udp_recv_tx.clone(), udp_send_rx).await?;
@@ -193,7 +200,7 @@ impl Server {
let request = self.pending_dns_requests.borrow_mut().pop_front();
request
} {
dns_tx.send(request).expect("channel closed");
dns_tx.send(request).await.expect("channel closed");
}
}
_ = self.cancelled() => break,
@@ -206,6 +213,13 @@ impl Server {
log::info!("terminating service");
assert!(!capture_tx.is_closed());
assert!(!emulation_tx.is_closed());
assert!(!udp_recv_tx.is_closed());
assert!(!udp_send_tx.is_closed());
assert!(!request_tx.is_closed());
assert!(!dns_tx.is_closed());
self.cancel();
futures::future::join_all(join_handles).await;
let _ = join!(capture, dns_task, emulation, network, ping);
@@ -363,8 +377,8 @@ impl Server {
None => return,
};
let _ = capture.send(CaptureRequest::Destroy(handle));
let _ = emulate.send(EmulationRequest::Destroy(handle));
let _ = capture.send(CaptureRequest::Destroy(handle)).await;
let _ = emulate.send(EmulationRequest::Destroy(handle)).await;
log::debug!("deactivating client {handle} done");
}
@@ -396,8 +410,10 @@ impl Server {
};
/* notify emulation, capture and frontends */
let _ = capture.send(CaptureRequest::Create(handle, pos.into()));
let _ = emulate.send(EmulationRequest::Create(handle));
let _ = capture
.send(CaptureRequest::Create(handle, pos.into()))
.await;
let _ = emulate.send(EmulationRequest::Create(handle)).await;
log::debug!("activating client {handle} done");
}
@@ -417,8 +433,8 @@ impl Server {
};
if active {
let _ = capture.send(CaptureRequest::Destroy(handle));
let _ = emulate.send(EmulationRequest::Destroy(handle));
let _ = capture.send(CaptureRequest::Destroy(handle)).await;
let _ = emulate.send(EmulationRequest::Destroy(handle)).await;
}
}
@@ -501,11 +517,13 @@ impl Server {
// update state in event input emulator & input capture
if changed {
if active {
let _ = capture.send(CaptureRequest::Destroy(handle));
let _ = emulate.send(EmulationRequest::Destroy(handle));
let _ = capture.send(CaptureRequest::Destroy(handle)).await;
let _ = emulate.send(EmulationRequest::Destroy(handle)).await;
}
let _ = capture.send(CaptureRequest::Create(handle, pos.into()));
let _ = emulate.send(EmulationRequest::Create(handle));
let _ = capture
.send(CaptureRequest::Create(handle, pos.into()))
.await;
let _ = emulate.send(EmulationRequest::Create(handle)).await;
}
}
@@ -577,7 +595,7 @@ async fn listen_frontend(
let request = frontend::wait_for_request(&mut stream).await;
match request {
Ok(request) => {
let _ = request_tx.send(request);
let _ = request_tx.send(request).await;
}
Err(e) => {
if let Some(e) = e.downcast_ref::<io::Error>() {

View File

@@ -1,9 +1,12 @@
use futures::StreamExt;
use lan_mouse_proto::ProtoEvent;
use local_channel::mpsc::{Receiver, Sender};
use std::net::SocketAddr;
use tokio::{process::Command, task::JoinHandle};
use tokio::{
process::Command,
sync::mpsc::{Receiver, Sender},
task::JoinHandle,
};
use input_capture::{
self, CaptureError, CaptureEvent, CaptureHandle, InputCapture, InputCaptureError, Position,
@@ -158,7 +161,7 @@ async fn handle_capture_event(
/* released capture */
State::Receiving => ProtoEvent::Leave(0),
};
sender_tx.send((event, addr)).expect("sender closed");
sender_tx.send((event, addr)).await.expect("sender closed");
};
Ok(())

View File

@@ -1,8 +1,10 @@
use local_channel::mpsc::{Receiver, Sender};
use std::net::SocketAddr;
use lan_mouse_proto::ProtoEvent;
use tokio::task::JoinHandle;
use tokio::{
sync::mpsc::{Receiver, Sender},
task::JoinHandle,
};
use crate::{
client::{ClientHandle, ClientManager},
@@ -138,7 +140,7 @@ async fn handle_incoming_event(
match (event, addr) {
(ProtoEvent::Pong, _) => { /* ignore pong events */ }
(ProtoEvent::Ping, addr) => {
let _ = sender_tx.send((ProtoEvent::Pong, addr));
let _ = sender_tx.send((ProtoEvent::Pong, addr)).await;
}
(ProtoEvent::Leave(_), _) => emulate.release_keys(handle).await?,
(ProtoEvent::Ack(_), _) => server.set_state(State::Sending),
@@ -146,6 +148,7 @@ async fn handle_incoming_event(
server.set_state(State::Receiving);
sender_tx
.send((ProtoEvent::Ack(0), addr))
.await
.expect("no channel")
}
(ProtoEvent::Input(e), _) => {

View File

@@ -1,8 +1,11 @@
use local_channel::mpsc::{Receiver, Sender};
use std::{io, net::SocketAddr};
use thiserror::Error;
use tokio::{net::UdpSocket, task::JoinHandle};
use tokio::{
net::UdpSocket,
sync::mpsc::{Receiver, Sender},
task::JoinHandle,
};
use super::Server;
use lan_mouse_proto::{ProtoEvent, ProtocolError};
@@ -62,7 +65,7 @@ async fn udp_receiver(
) {
loop {
let event = receive_event(socket).await;
receiver_tx.send(event).expect("channel closed");
receiver_tx.send(event).await.expect("channel closed");
}
}

View File

@@ -1,8 +1,7 @@
use std::{net::SocketAddr, time::Duration};
use lan_mouse_proto::ProtoEvent;
use local_channel::mpsc::Sender;
use tokio::task::JoinHandle;
use tokio::{sync::mpsc::Sender, task::JoinHandle};
use crate::client::ClientHandle;
@@ -86,7 +85,7 @@ async fn ping_task(
// ping clients
for addr in ping_addrs {
if sender_ch.send((ProtoEvent::Ping, addr)).is_err() {
if sender_ch.send((ProtoEvent::Ping, addr)).await.is_err() {
break;
}
}
@@ -123,14 +122,14 @@ async fn ping_task(
if receiving {
for h in unresponsive_clients {
log::warn!("device not responding, releasing keys!");
let _ = emulate_notify.send(EmulationRequest::ReleaseKeys(h));
let _ = emulate_notify.send(EmulationRequest::ReleaseKeys(h)).await;
}
} else {
// release pointer if the active client has not responded
if !unresponsive_clients.is_empty() {
log::warn!("client not responding, releasing pointer!");
server.state.replace(State::Receiving);
let _ = capture_notify.send(CaptureRequest::Release);
let _ = capture_notify.send(CaptureRequest::Release).await;
}
}
}