fix clippy

This commit is contained in:
Ferdinand Schober
2024-10-08 17:52:45 +02:00
parent 4a64a97273
commit b6c2cfe8a6
8 changed files with 44 additions and 28 deletions

View File

@@ -283,8 +283,8 @@ impl Cli {
FrontendEvent::PublicKeyFingerprint(fp) => { FrontendEvent::PublicKeyFingerprint(fp) => {
eprintln!("the public key fingerprint of this device is {fp}"); eprintln!("the public key fingerprint of this device is {fp}");
} }
FrontendEvent::IncomingConnected(fp, addr, pos) => {} FrontendEvent::IncomingConnected(..) => {}
FrontendEvent::IncomingDisconnected(fp) => {} FrontendEvent::IncomingDisconnected(..) => {}
} }
} }

View File

@@ -12,6 +12,12 @@ glib::wrapper! {
@implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget; @implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget;
} }
impl Default for KeyRow {
fn default() -> Self {
Self::new()
}
}
impl KeyRow { impl KeyRow {
pub fn new() -> Self { pub fn new() -> Self {
Object::builder().build() Object::builder().build()

View File

@@ -142,8 +142,8 @@ fn build_ui(app: &Application) {
FrontendEvent::PublicKeyFingerprint(fp) => { FrontendEvent::PublicKeyFingerprint(fp) => {
window.set_pk_fp(&fp); window.set_pk_fp(&fp);
} }
FrontendEvent::IncomingConnected(fp, addr, pos) => {} FrontendEvent::IncomingConnected(..) => {}
FrontendEvent::IncomingDisconnected(fp) => {} FrontendEvent::IncomingDisconnected(..) => {}
} }
} }
} }

View File

@@ -332,8 +332,7 @@ impl Config {
let authorized_fingerprints = config_toml let authorized_fingerprints = config_toml
.as_mut() .as_mut()
.map(|c| std::mem::take(&mut c.authorized_fingerprints)) .and_then(|c| std::mem::take(&mut c.authorized_fingerprints))
.flatten()
.unwrap_or_default(); .unwrap_or_default();
let mut clients: Vec<(TomlClient, Position)> = vec![]; let mut clients: Vec<(TomlClient, Position)> = vec![];

View File

@@ -223,7 +223,7 @@ async fn receive_loop(
tx: Sender<(ClientHandle, ProtoEvent)>, tx: Sender<(ClientHandle, ProtoEvent)>,
) { ) {
let mut buf = [0u8; MAX_EVENT_SIZE]; let mut buf = [0u8; MAX_EVENT_SIZE];
while let Ok(_) = conn.recv(&mut buf).await { while conn.recv(&mut buf).await.is_ok() {
if let Ok(event) = buf.try_into() { if let Ok(event) = buf.try_into() {
match event { match event {
ProtoEvent::Pong(b) => { ProtoEvent::Pong(b) => {

View File

@@ -25,12 +25,11 @@ pub fn generate_fingerprint(cert: &[u8]) -> String {
.iter() .iter()
.map(|x| format!("{x:02x}")) .map(|x| format!("{x:02x}"))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let fingerprint = bytes.join(":").to_lowercase(); bytes.join(":").to_lowercase()
fingerprint
} }
pub fn certificate_fingerprint(cert: &Certificate) -> String { pub fn certificate_fingerprint(cert: &Certificate) -> String {
let certificate = cert.certificate.get(0).expect("certificate missing"); let certificate = cert.certificate.first().expect("certificate missing");
generate_fingerprint(certificate) generate_fingerprint(certificate)
} }
@@ -46,9 +45,9 @@ pub fn load_certificate(path: &Path) -> Result<Certificate, Error> {
pub(crate) fn load_or_generate_key_and_cert(path: &Path) -> Result<Certificate, Error> { pub(crate) fn load_or_generate_key_and_cert(path: &Path) -> Result<Certificate, Error> {
if path.exists() && path.is_file() { if path.exists() && path.is_file() {
return Ok(load_certificate(path)?); Ok(load_certificate(path)?)
} else { } else {
return Ok(generate_key_and_cert(path)?); generate_key_and_cert(path)
} }
} }

View File

@@ -32,11 +32,13 @@ pub enum ListenerCreationError {
WebrtcDtls(#[from] webrtc_dtls::Error), WebrtcDtls(#[from] webrtc_dtls::Error),
} }
type ArcConn = Arc<dyn Conn + Send + Sync>;
pub(crate) struct LanMouseListener { pub(crate) struct LanMouseListener {
listen_rx: Receiver<(ProtoEvent, SocketAddr)>, listen_rx: Receiver<(ProtoEvent, SocketAddr)>,
listen_tx: Sender<(ProtoEvent, SocketAddr)>, listen_tx: Sender<(ProtoEvent, SocketAddr)>,
listen_task: JoinHandle<()>, listen_task: JoinHandle<()>,
conns: Rc<Mutex<Vec<(SocketAddr, Arc<dyn Conn + Send + Sync>)>>>, conns: Rc<Mutex<Vec<(SocketAddr, ArcConn)>>>,
} }
type VerifyPeerCertificateFn = Arc< type VerifyPeerCertificateFn = Arc<
@@ -82,8 +84,7 @@ impl LanMouseListener {
let listener = listen(listen_addr, cfg).await?; let listener = listen(listen_addr, cfg).await?;
let conns: Rc<Mutex<Vec<(SocketAddr, Arc<dyn Conn + Send + Sync>)>>> = let conns: Rc<Mutex<Vec<(SocketAddr, ArcConn)>>> = Rc::new(Mutex::new(Vec::new()));
Rc::new(Mutex::new(Vec::new()));
let conns_clone = conns.clone(); let conns_clone = conns.clone();
@@ -156,7 +157,7 @@ impl LanMouseListener {
{ {
let conn: &DTLSConn = conn.as_any().downcast_ref().expect("dtls conn"); let conn: &DTLSConn = conn.as_any().downcast_ref().expect("dtls conn");
let certs = conn.connection_state().await.peer_certificates; let certs = conn.connection_state().await.peer_certificates;
let cert = certs.get(0)?; let cert = certs.first()?;
let fingerprint = crypto::generate_fingerprint(cert); let fingerprint = crypto::generate_fingerprint(cert);
Some(fingerprint) Some(fingerprint)
} else { } else {
@@ -177,9 +178,9 @@ impl Stream for LanMouseListener {
} }
async fn read_loop( async fn read_loop(
conns: Rc<Mutex<Vec<(SocketAddr, Arc<dyn Conn + Send + Sync>)>>>, conns: Rc<Mutex<Vec<(SocketAddr, ArcConn)>>>,
addr: SocketAddr, addr: SocketAddr,
conn: Arc<dyn Conn + Send + Sync>, conn: ArcConn,
dtls_tx: Sender<(ProtoEvent, SocketAddr)>, dtls_tx: Sender<(ProtoEvent, SocketAddr)>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let mut b = [0u8; MAX_EVENT_SIZE]; let mut b = [0u8; MAX_EVENT_SIZE];

View File

@@ -22,7 +22,6 @@ use std::{
net::{IpAddr, SocketAddr}, net::{IpAddr, SocketAddr},
rc::Rc, rc::Rc,
sync::{Arc, RwLock}, sync::{Arc, RwLock},
u64,
}; };
use thiserror::Error; use thiserror::Error;
use tokio::{signal, sync::Notify}; use tokio::{signal, sync::Notify};
@@ -56,6 +55,13 @@ enum IncomingEvent {
}, },
} }
#[derive(Debug)]
pub struct Incoming {
fingerprint: String,
addr: SocketAddr,
pos: Position,
}
#[derive(Clone)] #[derive(Clone)]
pub struct Service { pub struct Service {
active: Rc<Cell<Option<ClientHandle>>>, active: Rc<Cell<Option<ClientHandle>>>,
@@ -70,7 +76,7 @@ pub struct Service {
capture_status: Rc<Cell<Status>>, capture_status: Rc<Cell<Status>>,
pub(crate) emulation_status: Rc<Cell<Status>>, pub(crate) emulation_status: Rc<Cell<Status>>,
pub(crate) should_release: Rc<RefCell<Option<ReleaseToken>>>, pub(crate) should_release: Rc<RefCell<Option<ReleaseToken>>>,
incoming_conns: Rc<RefCell<HashMap<ClientHandle, (String, SocketAddr, Position)>>>, incoming_conns: Rc<RefCell<HashMap<ClientHandle, Incoming>>>,
cert: Certificate, cert: Certificate,
next_trigger_handle: u64, next_trigger_handle: u64,
} }
@@ -203,8 +209,8 @@ impl Service {
} }
}, },
handle = capture.entered() => { handle = capture.entered() => {
if let Some((_fp, addr, _pos)) = self.incoming_conns.borrow().get(&handle) { if let Some(incoming) = self.incoming_conns.borrow().get(&handle) {
emulation.notify_release(*addr); emulation.notify_release(incoming.addr);
} }
}, },
_ = self.cancelled() => break, _ = self.cancelled() => break,
@@ -237,9 +243,14 @@ impl Service {
let handle = Self::ENTER_HANDLE_BEGIN + self.next_trigger_handle; let handle = Self::ENTER_HANDLE_BEGIN + self.next_trigger_handle;
self.next_trigger_handle += 1; self.next_trigger_handle += 1;
capture.create(handle, pos); capture.create(handle, pos);
self.incoming_conns self.incoming_conns.borrow_mut().insert(
.borrow_mut() handle,
.insert(handle, (fingerprint, addr, pos)); Incoming {
fingerprint,
addr,
pos,
},
);
} }
fn remove_incoming(&mut self, addr: SocketAddr, capture: &Capture) -> Option<String> { fn remove_incoming(&mut self, addr: SocketAddr, capture: &Capture) -> Option<String> {
@@ -247,20 +258,20 @@ impl Service {
.incoming_conns .incoming_conns
.borrow() .borrow()
.iter() .iter()
.find(|(_, (_, a, _))| *a == addr) .find(|(_, incoming)| incoming.addr == addr)
.map(|(k, _)| *k)?; .map(|(k, _)| *k)?;
capture.destroy(handle); capture.destroy(handle);
self.incoming_conns self.incoming_conns
.borrow_mut() .borrow_mut()
.remove(&handle) .remove(&handle)
.map(|(f, _, _)| f) .map(|incoming| incoming.fingerprint)
} }
pub(crate) fn get_incoming_pos(&self, handle: ClientHandle) -> Option<Position> { pub(crate) fn get_incoming_pos(&self, handle: ClientHandle) -> Option<Position> {
self.incoming_conns self.incoming_conns
.borrow() .borrow()
.get(&handle) .get(&handle)
.map(|&(_, _, p)| p) .map(|incoming| incoming.pos)
} }
fn notify_frontend(&self, event: FrontendEvent) { fn notify_frontend(&self, event: FrontendEvent) {