made the server and the client/server communication functionality work.
This commit is contained in:
+58
-38
@@ -1,9 +1,10 @@
|
||||
use clap::Parser;
|
||||
use std::sync::Arc;
|
||||
use rcgen::generate_simple_self_signed;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::{env, path::PathBuf, process::exit};
|
||||
use tetanus::AppState;
|
||||
use tetanus::funcs::*;
|
||||
use tokio::sync::Mutex;
|
||||
use tetanus::server::start_server;
|
||||
use tetanus::{AppState, server};
|
||||
|
||||
mod install;
|
||||
|
||||
@@ -29,21 +30,13 @@ struct Args {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let args = Args::parse();
|
||||
if args.server {
|
||||
let server = Arc::new(Mutex::new(tetanus::server::ServerState {
|
||||
id: 0,
|
||||
running: true,
|
||||
address: String::from("127.0.0.1:31337"),
|
||||
clients: Vec::new(),
|
||||
key: String::new(),
|
||||
}));
|
||||
tetanus::server::start_server(server).await.unwrap();
|
||||
} else {
|
||||
println!("checking for server or client config files...");
|
||||
let mut config_path = env::home_dir().unwrap();
|
||||
config_path.push(".config/tetanus");
|
||||
if !config_path.exists() {
|
||||
println!("checking for server or client config files...");
|
||||
let mut config_path = PathBuf::new();
|
||||
let mut config_path_opt = env::home_dir();
|
||||
if let Some(home_config_path) = config_path_opt.as_mut() {
|
||||
println!("made it to home_config_path");
|
||||
home_config_path.push(".config/tetanus");
|
||||
if !home_config_path.exists() {
|
||||
println!("no config directory found in home directory...");
|
||||
config_path = PathBuf::from("/etc/tetanus");
|
||||
if !config_path.exists() {
|
||||
@@ -55,28 +48,55 @@ async fn main() {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("found home config_path.");
|
||||
config_path = home_config_path.clone();
|
||||
}
|
||||
let args = Args::parse();
|
||||
let mut client_config_path = config_path.clone();
|
||||
client_config_path.push("client.conf");
|
||||
let mut server_config_path = config_path.clone();
|
||||
server_config_path.push("server.conf");
|
||||
if args.client {
|
||||
if !client_config_path.exists() {
|
||||
eprintln!(
|
||||
"error: no client config path found at {}",
|
||||
client_config_path.display()
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
let args = Args::parse();
|
||||
let mut client_config_path = config_path.clone();
|
||||
client_config_path.push("client.conf");
|
||||
let mut server_config_path = config_path.clone();
|
||||
server_config_path.push("server.conf");
|
||||
if args.client {
|
||||
if !client_config_path.exists() {
|
||||
eprintln!(
|
||||
"error: no client config path found at {}",
|
||||
client_config_path.display()
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
let (mut appstate, rx) = AppState::new();
|
||||
let config_load = appstate.load_config(client_config_path.clone());
|
||||
if config_load.is_err() {
|
||||
eprintln!("error loading config!");
|
||||
exit(1);
|
||||
}
|
||||
appstate.initialize_modules();
|
||||
println!("entering tui...");
|
||||
let _res = run_tui(appstate, rx).unwrap();
|
||||
} else if args.server {
|
||||
let address = "127.0.0.1:31337".to_string();
|
||||
let names = vec!["127.0.0.1".to_string(), "localhost".to_string()];
|
||||
let mut certificate_path = config_path.clone();
|
||||
certificate_path.push("server");
|
||||
let mut key_path = certificate_path.clone();
|
||||
certificate_path.push("cert.pem");
|
||||
key_path.push("key.pem");
|
||||
println!("key paht: {}", key_path.display());
|
||||
println!("cert path: {}", certificate_path.display());
|
||||
let new_server = server::Server {
|
||||
address,
|
||||
clients: Vec::new(),
|
||||
certificate_path,
|
||||
key_path,
|
||||
};
|
||||
let res = start_server(Arc::new(Mutex::new(new_server))).await;
|
||||
match res {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!("error running server {e}");
|
||||
}
|
||||
let (mut appstate, rx) = AppState::new();
|
||||
let config_load = appstate.load_config(client_config_path.clone());
|
||||
if config_load.is_err() {
|
||||
eprintln!("error loading config!");
|
||||
exit(1);
|
||||
}
|
||||
appstate.initialize_modules();
|
||||
let _res = run_tui(appstate, rx).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user