Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardicus committed Oct 6, 2024
1 parent f60a303 commit f97c574
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 47 deletions.
33 changes: 4 additions & 29 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ async fn read_message(
Ok("".to_string())
}

async fn send_chat_message(window: usize, message: Option<String>) {
unsafe {
//PIPE.get().unwrap().tx_chat_input(message).await;
}
}

async fn println_message_str(window: usize, message: &str) {
println_message(window, message.to_string()).await;
}
Expand Down Expand Up @@ -365,18 +359,14 @@ async fn cb_init_incoming(public_key: String) -> bool {
}

async fn terminate(session_tx: mpsc::Sender<(String, String)>) {
let pipe;
unsafe {
pipe = PIPE.get().unwrap().clone();
}
let pipe = PIPE.get().unwrap().clone();
let topic = Topic::Internal.as_str();
let msg = SessionMessage::new_internal(
"internal".to_owned(),
"terminate".to_owned(),
topic.to_string(),
);
pipe.send(WindowCommand::Shutdown()).await;
send_chat_message(1, None).await;

tokio::time::sleep(Duration::from_millis(200)).await;
let _ = session_tx
Expand All @@ -396,10 +386,7 @@ async fn launch_terminal_program(
session_tx: mpsc::Sender<(String, String)>,
mut session: Session<ChaCha20Poly1305EnDeCrypt, PGPEnDeCrypt>,
) -> Result<(), ()> {
let pipe;
unsafe {
pipe = PIPE.get().unwrap().clone();
}
let pipe = PIPE.get().unwrap().clone();
let zc = session.middleware_config.clone();
let zenoh_config = Config::from_file(zc.clone()).unwrap();
let zenoh_session;
Expand All @@ -422,16 +409,11 @@ async fn launch_terminal_program(
let pipe_clone = pipe.clone();
window_manager.serve(pipe_clone, tx).await;
});
let pipe;
unsafe {
pipe = PIPE.get().unwrap().clone();
}
let pipe = PIPE.get().unwrap().clone();
// Initialize
pipe.send(WindowCommand::Init()).await;
tokio::time::sleep(Duration::from_millis(100)).await;

let pgp_handler = PGPEnDeCrypt::new_no_certpass(cert.clone());

// Launch window manager program
tokio::time::sleep(Duration::from_millis(400)).await;
let mut userid = String::new();
Expand All @@ -444,7 +426,6 @@ async fn launch_terminal_program(
// Serve incoming commands
InputCommand::print_small_help().await;
let mut keep_running = true;
let mut print_prompt = true;
while keep_running {
let pending = session.get_pending_request().await;
if pending.is_some() {
Expand Down Expand Up @@ -485,7 +466,6 @@ async fn launch_terminal_program(
),
)
.await;
print_prompt = true;
} else {
println_message_str(1, "-- Declined this chat request.").await;
let _ = session.decline_pending_request(&session_id).await;
Expand Down Expand Up @@ -524,11 +504,6 @@ async fn launch_terminal_program(
let mut s = ">> ".to_string();
s.push_str(&input);
println_message(1, s).await;
if input.len() > 0 {
print_prompt = true;
} else {
print_prompt = false;
}
let cmd = InputCommand::parse_from(&input);
match cmd {
Some(InputCommand::List(_)) => {
Expand Down Expand Up @@ -859,5 +834,5 @@ async fn main() {
};
});

launch_terminal_program(cert.clone(), session.get_tx().await, session.clone()).await;
let _ = launch_terminal_program(cert.clone(), session.get_tx().await, session.clone()).await;
}
20 changes: 10 additions & 10 deletions src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use messages::MessageData::{
use messages::MessagingError::*;
use messages::SessionMessage as Message;
use messages::{
ChatMsg, EncryptedMsg, InitMsg, MessageData, MessageListener, Messageble, MessagebleTopicAsync,
ChatMsg, EncryptedMsg, MessageData, MessageListener, MessagebleTopicAsync,
MessagebleTopicAsyncPublishReads, MessagebleTopicAsyncReadTimeout, MessagingError,
SessionErrorCodes, SessionErrorMsg,
};
Expand Down Expand Up @@ -154,7 +154,7 @@ where

impl Session<ChaCha20Poly1305EnDeCrypt, PGPEnDeCrypt> {
pub fn new(host_encro: PGPEnDeCrypt, middleware_config: String) -> Self {
let (tx, mut rx) = mpsc::channel(100);
let (tx, rx) = mpsc::channel(100);
let (tx_chat, rx_chat) = mpsc::channel(100);
Session {
sessions: Arc::new(Mutex::new(HashMap::new())),
Expand Down Expand Up @@ -258,15 +258,15 @@ impl Session<ChaCha20Poly1305EnDeCrypt, PGPEnDeCrypt> {
let mut session_init_ok_msg_topic = None;
{
let mut requests = self.requests_incoming_initialization.lock().await;
let mut index = None;
let _index;

for (i, (session_data, message, topic)) in requests.iter().enumerate() {
let id = session_data.id.clone();
if id == session_id {
session_init_ok_msg = Some(message.clone());
session_data_incoming = Some(session_data.clone());
session_init_ok_msg_topic = Some(topic.clone());
index = Some(i);
_index = Some(i);
requests.remove(i); // Remove the request while the lock is still active
break;
}
Expand Down Expand Up @@ -612,7 +612,7 @@ impl Session<ChaCha20Poly1305EnDeCrypt, PGPEnDeCrypt> {
) {
let pub_key_fingerprint = self.host_encro.lock().await.get_public_key_fingerprint();
let topic_in = Topic::messaging_topic_in(pub_key_fingerprint.as_ref());
let topic_out = Topic::messaging_topic_in(&other_key_fingerprint);
let _topic_out = Topic::messaging_topic_in(&other_key_fingerprint);

let mut topics: Vec<String> = Vec::new();
topics.push(topic_in);
Expand Down Expand Up @@ -981,7 +981,7 @@ impl Session<ChaCha20Poly1305EnDeCrypt, PGPEnDeCrypt> {
discover_topic_reply.push_str(Topic::reply_suffix());
let _timeout_discovery = Duration::from_secs(5);

let mut this_pub_key = None;
let this_pub_key;
{
this_pub_key = Some(self.host_encro.lock().await.get_public_key_as_base64());
}
Expand Down Expand Up @@ -1160,7 +1160,7 @@ impl Session<ChaCha20Poly1305EnDeCrypt, PGPEnDeCrypt> {
discovered = self.discovered.lock().await;
}

let mut this_fingerprint = None;
let this_fingerprint;
{
this_fingerprint =
Some(self.host_encro.lock().await.get_public_key_fingerprint());
Expand Down Expand Up @@ -1214,7 +1214,7 @@ impl Session<ChaCha20Poly1305EnDeCrypt, PGPEnDeCrypt> {
discovered = self.discovered.lock().await;
}

let mut this_fingerprint = None;
let this_fingerprint;
{
this_fingerprint =
Some(self.host_encro.lock().await.get_public_key_fingerprint());
Expand Down Expand Up @@ -1308,7 +1308,7 @@ impl Session<ChaCha20Poly1305EnDeCrypt, PGPEnDeCrypt> {
let challenge_sig =
match self.host_encro.lock().await.sign(&challenge) {
Ok(s) => s,
Err(e) => {
Err(_e) => {
return Err(SessionErrorMsg {
code: SessionErrorCodes::Encryption as u32,
message: "Failed to create signature of challenge"
Expand Down Expand Up @@ -1494,7 +1494,7 @@ impl Session<ChaCha20Poly1305EnDeCrypt, PGPEnDeCrypt> {
}
}
Encrypted(msg) => {
let mut dec_msg = None;
let dec_msg;
{
let sm = &self.sessions.lock().await;
let cipher = match sm.get(&message.session_id) {
Expand Down
13 changes: 5 additions & 8 deletions src/terminal.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use ncurses::*;
use std::collections::HashMap;

use std::sync::Arc;
use tokio::sync::{mpsc, Mutex, OnceCell, Semaphore};
use tokio::sync::{mpsc, Mutex, OnceCell};
use tokio::time::{timeout, Duration};

use crate::session::crypto::{Cryptical, CrypticalID};
Expand All @@ -15,7 +12,7 @@ use ratatui::{
prelude::Margin,
style::{Color, Modifier, Style, Stylize},
text::{Line, Span, Text},
widgets::{Block, List, ListItem, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState},
widgets::{Block, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState},
DefaultTerminal, Frame,
};

Expand Down Expand Up @@ -257,7 +254,7 @@ impl App {

async fn byte_index(&self) -> usize {
let state = self.state.lock().await;
let mut s = &state.input;
let s = &state.input;
let len = s.len();
let char_index;
{
Expand Down Expand Up @@ -413,7 +410,7 @@ impl App {
.scrollstate_chat
.content_length(state.chat_messages.len());
}
async fn set_last_message(&mut self, window: usize, message: String, style: TextStyle) {
async fn set_last_message(&mut self, _window: usize, message: String, style: TextStyle) {
let mut state = self.state.lock().await;
if state.messages.len() > 0 {
if let Some(last) = state.messages.last_mut() {
Expand Down Expand Up @@ -763,7 +760,7 @@ async fn initialize_global_values() {
let _ = STATE.set(Arc::new(WindowPipe::<AppState>::new()));
}

pub async fn read_app_state() -> Result<AppState, ()> {
async fn read_app_state() -> Result<AppState, ()> {
match STATE.get().unwrap().read().await {
Ok(cmd) => Ok(cmd),
Err(_) => Err(()),
Expand Down

0 comments on commit f97c574

Please sign in to comment.