It works again, just very slowly. I could try to make it faster but not now.
This commit is contained in:
parent
91539e2efe
commit
518b275bd9
|
@ -27,7 +27,6 @@ pub fn listen_to_client(tx: mpsc::Sender<String>, rx: mpsc::Receiver<String>, po
|
|||
}
|
||||
match rx.try_recv() {
|
||||
Ok(value) => {
|
||||
dbg!(&value);
|
||||
match stream.write_all(value.as_bytes()) {
|
||||
Ok(_) => {}
|
||||
Err(_e) => println!("Couldn't send {value}"),
|
||||
|
|
30
src/main.rs
30
src/main.rs
|
@ -8,6 +8,7 @@ use std::collections::HashMap;
|
|||
use std::net::{Shutdown, TcpStream};
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::{env, fs};
|
||||
|
||||
mod listener_server;
|
||||
|
@ -137,10 +138,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let reciever = &command.params[0];
|
||||
if !keys.contains_key(reciever) {
|
||||
writer_channel_tx.send(format!("PRIVMSG {reciever} :START_KEY\r\n"))?;
|
||||
userstring = ircparser::parse(&writer_channel_rx.recv()?).unwrap()[0]
|
||||
.source
|
||||
.clone()
|
||||
.unwrap();
|
||||
|
||||
writer_channel_tx
|
||||
.send(bytes_to_privmsg_base64(public_key.clone(), reciever))?;
|
||||
|
@ -166,8 +163,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
foreign_key.push(recieved.params[1].clone());
|
||||
}
|
||||
foreign_key.pop();
|
||||
|
||||
println!("Got a foreign key from {reciever}");
|
||||
let foreign_key = foreign_key.concat();
|
||||
dbg!(&foreign_key);
|
||||
|
||||
let foreign_key = general_purpose::STANDARD.decode(foreign_key)?;
|
||||
|
||||
|
@ -207,6 +206,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
listener_channel_tx.send(recieved.replace(&server, "127.0.0.1"))?;
|
||||
continue;
|
||||
}
|
||||
|
||||
dbg!(&recieved_parsed);
|
||||
|
||||
if recieved_parsed.params[1] == "START_MESSAGE" {
|
||||
let reciever = get_nick(&recieved_parsed.source.clone().unwrap());
|
||||
|
@ -225,7 +226,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
.unwrap_or("".to_string())
|
||||
.starts_with(&begin_source_reciever)
|
||||
{
|
||||
listener_channel_tx.send(recieved_raw)?;
|
||||
listener_channel_tx.send(recieved_raw.replace(&server, "127.0.0.1"))?;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -240,6 +241,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
listener_channel_tx
|
||||
.send(sample_privmsg.replace("START_MESSAGE", &decrypted_message))?;
|
||||
} else if recieved_parsed.params[1] == "START_KEY" {
|
||||
let reciever = get_nick(&recieved_parsed.source.clone().unwrap());
|
||||
let to_send = bytes_to_privmsg_base64(public_key.clone(), &reciever);
|
||||
writer_channel_tx.send(to_send)?;
|
||||
writer_channel_tx.send(format!("PRIVMSG {reciever} END_KEY\r\n"))?;
|
||||
|
||||
dbg!("Started Getting a key");
|
||||
let reciever = get_nick(&recieved_parsed.source.clone().unwrap());
|
||||
let mut foreign_key: Vec<String> = Vec::new();
|
||||
while !foreign_key.contains(&"END_KEY".to_string()) {
|
||||
|
@ -254,26 +261,25 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
.unwrap_or("".to_string())
|
||||
.starts_with(&begin_source_reciever)
|
||||
{
|
||||
listener_channel_tx.send(recieved_raw)?;
|
||||
listener_channel_tx.send(recieved_raw.replace(&server, "127.0.0.1"))?;
|
||||
continue;
|
||||
}
|
||||
|
||||
foreign_key.push(recieved.params[1].clone());
|
||||
}
|
||||
foreign_key.pop();
|
||||
println!("Got a foreign key from {reciever}");
|
||||
dbg!("Got a foreign key from");
|
||||
dbg!(&reciever);
|
||||
|
||||
let foreign_key = foreign_key.concat();
|
||||
|
||||
let foreign_key = general_purpose::STANDARD.decode(foreign_key)?;
|
||||
dbg!("Decoded the key");
|
||||
|
||||
let key = SignedPublicKey::from_bytes(foreign_key.as_slice())?;
|
||||
dbg!("Deserialized the key");
|
||||
|
||||
keys.insert(reciever.to_string(), key);
|
||||
|
||||
let reciever = get_nick(&recieved_parsed.source.clone().unwrap());
|
||||
let to_send = bytes_to_privmsg_base64(public_key.clone(), &reciever);
|
||||
writer_channel_tx.send(to_send)?;
|
||||
writer_channel_tx.send(format!("PRIVMSG {reciever} END_KEY\r\n"))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue