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) => {
eprintln!("the public key fingerprint of this device is {fp}");
}
FrontendEvent::IncomingConnected(fp, addr, pos) => {}
FrontendEvent::IncomingDisconnected(fp) => {}
FrontendEvent::IncomingConnected(..) => {}
FrontendEvent::IncomingDisconnected(..) => {}
}
}

View File

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

View File

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

View File

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

View File

@@ -223,7 +223,7 @@ async fn receive_loop(
tx: Sender<(ClientHandle, ProtoEvent)>,
) {
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() {
match event {
ProtoEvent::Pong(b) => {

View File

@@ -25,12 +25,11 @@ pub fn generate_fingerprint(cert: &[u8]) -> String {
.iter()
.map(|x| format!("{x:02x}"))
.collect::<Vec<_>>();
let fingerprint = bytes.join(":").to_lowercase();
fingerprint
bytes.join(":").to_lowercase()
}
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)
}
@@ -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> {
if path.exists() && path.is_file() {
return Ok(load_certificate(path)?);
Ok(load_certificate(path)?)
} 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),
}
type ArcConn = Arc<dyn Conn + Send + Sync>;
pub(crate) struct LanMouseListener {
listen_rx: Receiver<(ProtoEvent, SocketAddr)>,
listen_tx: Sender<(ProtoEvent, SocketAddr)>,
listen_task: JoinHandle<()>,
conns: Rc<Mutex<Vec<(SocketAddr, Arc<dyn Conn + Send + Sync>)>>>,
conns: Rc<Mutex<Vec<(SocketAddr, ArcConn)>>>,
}
type VerifyPeerCertificateFn = Arc<
@@ -82,8 +84,7 @@ impl LanMouseListener {
let listener = listen(listen_addr, cfg).await?;
let conns: Rc<Mutex<Vec<(SocketAddr, Arc<dyn Conn + Send + Sync>)>>> =
Rc::new(Mutex::new(Vec::new()));
let conns: Rc<Mutex<Vec<(SocketAddr, ArcConn)>>> = Rc::new(Mutex::new(Vec::new()));
let conns_clone = conns.clone();
@@ -156,7 +157,7 @@ impl LanMouseListener {
{
let conn: &DTLSConn = conn.as_any().downcast_ref().expect("dtls conn");
let certs = conn.connection_state().await.peer_certificates;
let cert = certs.get(0)?;
let cert = certs.first()?;
let fingerprint = crypto::generate_fingerprint(cert);
Some(fingerprint)
} else {
@@ -177,9 +178,9 @@ impl Stream for LanMouseListener {
}
async fn read_loop(
conns: Rc<Mutex<Vec<(SocketAddr, Arc<dyn Conn + Send + Sync>)>>>,
conns: Rc<Mutex<Vec<(SocketAddr, ArcConn)>>>,
addr: SocketAddr,
conn: Arc<dyn Conn + Send + Sync>,
conn: ArcConn,
dtls_tx: Sender<(ProtoEvent, SocketAddr)>,
) -> Result<(), Error> {
let mut b = [0u8; MAX_EVENT_SIZE];

View File

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