This commit is contained in:
Ferdinand Schober
2024-07-11 16:59:09 +02:00
parent 4c30f032f4
commit 69a5eec944
4 changed files with 24 additions and 35 deletions

View File

@@ -97,14 +97,14 @@ impl Server {
}
};
let timer_notify = Arc::new(Notify::new()); /* notify ping timer restart */
let notify_ping = Arc::new(Notify::new()); /* notify ping timer restart */
let (frontend_tx, frontend_rx) = channel(1); /* events coming from frontends */
let cancellation_token = CancellationToken::new(); /* notify termination */
let notify_capture = Arc::new(Notify::new()); /* notify capture restart */
let notify_emulation = Arc::new(Notify::new()); /* notify emultation restart */
// udp task
let (mut udp_task, udp_send, udp_recv, port_tx) = network_task::new(
let (mut network, udp_send, udp_recv, port_tx) = network_task::new(
self.clone(),
frontend_tx.clone(),
cancellation_token.clone(),
@@ -112,33 +112,33 @@ impl Server {
.await?;
// input capture
let (mut capture_task, capture_channel) = capture_task::new(
let (mut capture, capture_channel) = capture_task::new(
capture_backend,
self.clone(),
udp_send.clone(),
frontend_tx.clone(),
timer_notify.clone(),
notify_ping.clone(),
self.release_bind.clone(),
cancellation_token.clone(),
notify_capture.clone(),
);
// input emulation
let (mut emulation_task, emulate_channel) = emulation_task::new(
let (mut emulation, emulate_channel) = emulation_task::new(
emulation_backend,
self.clone(),
udp_recv,
udp_send.clone(),
capture_channel.clone(),
frontend_tx.clone(),
timer_notify.clone(),
notify_ping.clone(),
cancellation_token.clone(),
notify_emulation.clone(),
);
// create dns resolver
let resolver = dns::DnsResolver::new().await?;
let (mut resolver_task, dns_req) = resolver_task::new(
let (mut resolver, dns_req) = resolver_task::new(
resolver,
self.clone(),
frontend_tx,
@@ -146,7 +146,7 @@ impl Server {
);
// frontend listener
let (mut frontend_task, frontend_tx) = frontend_task::new(
let (mut frontend, frontend_tx) = frontend_task::new(
frontend,
frontend_rx,
self.clone(),
@@ -160,12 +160,12 @@ impl Server {
);
// task that pings clients to see if they are responding
let mut ping_task = ping_task::new(
let mut ping = ping_task::new(
self.clone(),
udp_send.clone(),
emulate_channel.clone(),
capture_channel.clone(),
timer_notify,
notify_ping,
cancellation_token.clone(),
);
@@ -195,26 +195,16 @@ impl Server {
_ = signal::ctrl_c() => {
log::info!("terminating service");
}
_ = &mut capture_task => { }
_ = &mut emulation_task => { }
_ = &mut frontend_task => { }
_ = &mut resolver_task => { }
_ = &mut udp_task => { }
_ = &mut ping_task => { }
_ = &mut capture => { }
_ = &mut emulation => { }
_ = &mut frontend => { }
_ = &mut resolver => { }
_ = &mut network => { }
_ = &mut ping => { }
}
// cancel tasks
cancellation_token.cancel();
let _ = join!(
capture_task,
emulation_task,
frontend_task,
udp_task,
resolver_task
);
ping_task.abort();
let _ = join!(capture, emulation, frontend, network, resolver, ping);
Ok(())
}

View File

@@ -48,9 +48,9 @@ pub enum CaptureEvent {
pub fn new(
backend: Option<CaptureBackend>,
server: Server,
sender_tx: Sender<(Event, SocketAddr)>,
udp_send: Sender<(Event, SocketAddr)>,
frontend_tx: Sender<FrontendEvent>,
timer_notify: Arc<Notify>,
notify_ping: Arc<Notify>,
release_bind: Vec<scancode::Linux>,
cancellation_token: CancellationToken,
notify_capture: Arc<Notify>,
@@ -60,10 +60,10 @@ pub fn new(
let task = tokio::task::spawn_local(capture_task(
backend,
server,
sender_tx,
udp_send,
rx,
frontend_tx,
timer_notify,
notify_ping,
release_bind,
cancellation_token,
notify_capture,

View File

@@ -170,7 +170,7 @@ async fn do_emulation(
}
// release potentially still pressed keys
release_all_keys(&server, &mut emulation).await?;
release_all_keys(server, &mut emulation).await?;
Ok(())
}

View File

@@ -23,13 +23,12 @@ pub fn new(
cancellation_token: CancellationToken,
) -> JoinHandle<()> {
// timer task
let ping_task = tokio::task::spawn_local(async move {
tokio::task::spawn_local(async move {
tokio::select! {
_ = cancellation_token.cancelled() => {}
_ = ping_task(server, sender_ch, emulate_notify, capture_notify, timer_notify) => {}
}
});
ping_task
})
}
async fn ping_task(