diff --git a/src/consts.rs b/src/consts.rs index 0bd2090..a7373e0 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -1 +1 @@ -pub static DEFAULT_SOCK_PATH: String = "/tmp/inv_sig_helper.sock"; +pub static DEFAULT_SOCK_PATH: &str = "/tmp/inv_sig_helper.sock"; diff --git a/src/jobs.rs b/src/jobs.rs index c198035..5fd6021 100644 --- a/src/jobs.rs +++ b/src/jobs.rs @@ -14,4 +14,5 @@ impl From for JobOpcode { } } +pub async fn process_fetch_update() {} pub async fn process_decrypt_n_signature(sig: String) {} diff --git a/src/main.rs b/src/main.rs index f4cc578..30828f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ mod consts; mod jobs; use consts::DEFAULT_SOCK_PATH; -use jobs::{process_decrypt_n_signature, JobOpcode}; +use jobs::{process_decrypt_n_signature, process_fetch_update, JobOpcode}; use std::env::args; use tokio::{ io::{AsyncReadExt, BufReader}, @@ -24,7 +24,10 @@ macro_rules! break_fail { #[tokio::main] async fn main() { let args: Vec = args().collect(); - let socket_url: &String = args.get(1).unwrap_or(&DEFAULT_SOCK_PATH); + let socket_url: &str = match args.get(1) { + Some(stringref) => stringref, + None => DEFAULT_SOCK_PATH, + }; let socket = UnixListener::bind(socket_url).unwrap(); @@ -32,7 +35,7 @@ async fn main() { let (socket, _addr) = socket.accept().await.unwrap(); tokio::spawn(async move { - process_socket(socket); + process_socket(socket).await; }); } } @@ -42,21 +45,24 @@ async fn process_socket(socket: UnixStream) { loop { let opcode_byte: u8 = break_fail!(bufreader.read_u8().await); - let opcode: JobOpcode = opcode_byte.try_into().unwrap(); + let opcode: JobOpcode = opcode_byte.into(); match opcode { - JobOpcode::ForceUpdate => {} + JobOpcode::ForceUpdate => { + tokio::spawn(async move { + process_fetch_update().await; + }); + } JobOpcode::DecryptNSignature => { - let sig_size: usize = - usize::try_from(break_fail!(bufreader.read_u16().await)).unwrap(); + let sig_size: usize = usize::from(break_fail!(bufreader.read_u16().await)); let mut buf = vec![0u8; sig_size]; - bufreader.read_exact(&mut buf).await; + break_fail!(bufreader.read_exact(&mut buf).await); let _str = break_fail!(String::from_utf8(buf)); tokio::spawn(async move { - process_decrypt_n_signature(_str); + process_decrypt_n_signature(_str).await; }); } _ => {}