use argon2::{
password_hash::{rand_core::OsRng, PasswordHasher, SaltString},
Argon2,
};
use clap::Parser;
use colored::*;
use rpassword::read_password;
use std::io::Error;
pub const MAX_MSG: usize = 50;
const COST_POW: u32 = 30;
const OPEN_GATEWAY_IN_SEG: u64 = 480;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
#[arg(short, long)]
max_messages: Option<usize>,
#[arg(short, long)]
cost_pow: Option<u32>,
#[arg(short, long)]
expected_time: Option<u64>,
}
#[tokio::main]
async fn main() -> Result<(), Error> {
let args = Args::parse();
let max_messages: usize = match args.max_messages {
Some(max_messages) => max_messages,
None => MAX_MSG,
};
let cost_pow: u32 = match args.cost_pow {
Some(cost_pow) => cost_pow,
None => COST_POW,
};
let expected_time: u64 = match args.expected_time {
Some(expected_time) => expected_time,
None => OPEN_GATEWAY_IN_SEG,
};
println!("Enter the server password (secure as posible & change it every time)");
let password = read_password().unwrap().into_bytes();
let salt = SaltString::generate(&mut OsRng);
let argon2 = Argon2::default();
let password_hash = argon2.hash_password(&password, &salt).unwrap().to_string();
#[allow(clippy::unit_arg)]
let _ = match kkv::server::server(max_messages, cost_pow, expected_time, password_hash).await {
Ok(_) => Ok(()),
Err(e) => Err(println!("{}", e.to_string().red())),
};
Ok(())
}