2020-11-01 16:46:47 +00:00
|
|
|
mod chat;
|
2020-11-22 14:31:45 +00:00
|
|
|
|
|
|
|
mod db;
|
2020-09-10 22:01:13 +00:00
|
|
|
mod encrypting;
|
2020-11-01 16:46:47 +00:00
|
|
|
use async_std::io;
|
|
|
|
use chat::front_conn::listen_client;
|
2020-11-22 17:03:34 +00:00
|
|
|
use chat::types::PackedMessage;
|
2020-09-10 22:01:13 +00:00
|
|
|
|
2020-11-22 14:31:45 +00:00
|
|
|
use std::{
|
|
|
|
sync::{
|
|
|
|
mpsc,
|
|
|
|
mpsc::{Receiver, Sender},
|
|
|
|
},
|
|
|
|
thread,
|
|
|
|
};
|
2020-11-22 16:19:32 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
+-----------------------------------------------------------------------------------+
|
|
|
|
| Client |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| +----------------------------+ +---------------------------------+ |
|
|
|
|
| | Thread 1 | | Thread 2 | | +-------------------+
|
|
|
|
+--------------+ | | +-----------------------+ | | +--------------------------+ | | | |
|
|
|
|
| | | | | Decode -----------------------> | | | | |
|
|
|
|
| ----------------------------> | | | | to JSON --------------------------------> |
|
|
|
|
| | | | | | | | | | | | | |
|
|
|
|
| | | | | | | | | | | | | |
|
|
|
|
| | | | +-----------------------+ | | | | | | | |
|
|
|
|
| Server | | | | | +--------------------------+ | | | Frontend |
|
|
|
|
| | | | | | | | | |
|
|
|
|
| | | | +----------------------+ | | +-----------------------------+ | | | |
|
|
|
|
| | | | | | | | | | | | | |
|
|
|
|
| | | | | Encode | | | | | | | | |
|
|
|
|
| | | | | <----------------------------- from JSON <-------------------------------- |
|
|
|
|
| | | | | | | | | | | | | |
|
|
|
|
| | | | +----------------------+ | | +-----------------------------+ | | | |
|
|
|
|
+--------------+ | | | | | | | |
|
|
|
|
| +----------------------------+ +---------------------------------+ | +-------------------+
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
+-----------------------------------------------------------------------------------+
|
|
|
|
*/
|
2020-11-01 16:46:47 +00:00
|
|
|
fn main() -> io::Result<()> {
|
2020-11-22 17:03:34 +00:00
|
|
|
let (server_sender, server_receiver): (Sender<PackedMessage>, Receiver<PackedMessage>) =
|
|
|
|
mpsc::channel();
|
|
|
|
let (client_sender, client_receiver): (Sender<PackedMessage>, Receiver<PackedMessage>) =
|
|
|
|
mpsc::channel();
|
2020-11-22 14:31:45 +00:00
|
|
|
|
2020-11-22 17:03:34 +00:00
|
|
|
let server_thread = thread::spawn(move || {
|
|
|
|
let cr = client_sender;
|
|
|
|
let sr = server_receiver;
|
2020-11-22 14:31:45 +00:00
|
|
|
|
2020-11-22 17:03:34 +00:00
|
|
|
println!("Multithreadding YAY!!! {}", sr.recv().unwrap().message);
|
2020-11-22 14:31:45 +00:00
|
|
|
});
|
2020-11-22 17:03:34 +00:00
|
|
|
let client_thread = thread::spawn(move || {
|
|
|
|
let ss = server_sender;
|
|
|
|
let cr = client_receiver;
|
2020-11-22 14:31:45 +00:00
|
|
|
|
2020-11-22 17:03:34 +00:00
|
|
|
thread::spawn(|| listen_client(ss));
|
2020-11-22 14:31:45 +00:00
|
|
|
});
|
2020-11-22 17:03:34 +00:00
|
|
|
server_thread.join();
|
|
|
|
client_thread.join();
|
2020-11-22 14:31:45 +00:00
|
|
|
Ok(())
|
2020-11-01 16:46:47 +00:00
|
|
|
}
|
|
|
|
/*
|
2020-09-10 22:01:13 +00:00
|
|
|
fn main() {
|
2020-11-01 16:46:47 +00:00
|
|
|
let server = TcpListener::bind("127.0.0.1:9001").unwrap();
|
|
|
|
println!("{:?}", &server);
|
|
|
|
for stream in server.incoming() {
|
|
|
|
spawn(move || {
|
|
|
|
println!("{:?}", &stream);
|
|
|
|
let mut websocket: WebSocket<std::net::TcpStream> = accept(stream.unwrap()).unwrap();
|
|
|
|
loop {
|
|
|
|
let msg = websocket.read_message().unwrap();
|
|
|
|
|
|
|
|
// We do not want to send back ping/pong messages.
|
|
|
|
if msg.is_binary() || msg.is_text() {
|
|
|
|
websocket.write_message(msg).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
/*
|
|
|
|
let (one, two) = keys;
|
2020-09-10 22:01:13 +00:00
|
|
|
|
2020-11-01 16:46:47 +00:00
|
|
|
let value =String::from_utf8_lossy(&*one);
|
|
|
|
let strVal = String::from(value);
|
|
|
|
let newbytes = strVal.into_bytes();
|
|
|
|
print!("{:?}", newbytes);
|
2020-09-10 22:01:13 +00:00
|
|
|
|
2020-11-01 16:46:47 +00:00
|
|
|
let newkey = PrivateKey::import(newbytes);
|
2020-09-10 22:01:13 +00:00
|
|
|
|
2020-11-01 16:46:47 +00:00
|
|
|
Let conn = Connection::open("myfile.db").unwrap();
|
2020-09-10 22:01:13 +00:00
|
|
|
|
2020-11-01 16:46:47 +00:00
|
|
|
conn.execute("CREATE TABLE person (
|
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
email TEXT NOT NULL
|
|
|
|
)", NO_PARAMS).unwrap();
|
|
|
|
let name: String = "Steve Example".to_string();
|
|
|
|
let email: String = "steve@example.org".to_string();
|
|
|
|
conn.execute("INSERT INTO person (name, email) VALUES (?1, ?2)",
|
|
|
|
&[&name, &email]).unwrap();
|
2020-09-10 22:01:13 +00:00
|
|
|
|
|
|
|
}
|
2020-11-01 16:46:47 +00:00
|
|
|
*/
|
|
|
|
//let mut std = cli::cli_base::get_stdin();
|