make using rac url

This commit is contained in:
MeexReay 2025-06-19 23:08:44 +03:00
parent a5ea227748
commit f4ad746453
6 changed files with 196 additions and 652 deletions

800
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -15,4 +15,4 @@ log = "0.4.27"
regex = "1.11.1"
colored = "3.0.0"
lazy_static = "1.5.0"
bRAC = { git = "https://github.com/MeexReay/bRAC.git" }
bRAC = { git = "https://github.com/MeexReay/bRAC.git", default-features = false }

4
shell.nix Normal file
View File

@ -0,0 +1,4 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [ pkg-config openssl ];
}

View File

@ -132,7 +132,7 @@ pub fn on_register_user(
info!("user registered: {name}");
ctx.push_account(account);
ctx.push_account(account)?;
Ok(None)
}

View File

@ -1,5 +1,6 @@
use std::sync::Arc;
use bRAC::proto::parse_rac_url;
use clap::Parser;
use log::info;
@ -13,7 +14,7 @@ pub mod util;
#[derive(Parser, Debug)]
#[command(version)]
pub struct Args {
/// Server host
/// Server host (RAC URL)
#[arg(short = 'H', long)]
host: String,
@ -53,10 +54,6 @@ pub struct Args {
#[arg(long, default_value_t = 4194304)]
messages_total_limit: usize,
/// Enable SSL (RACS)
#[arg(short = 'l', long)]
enable_ssl: bool,
/// Set ssl certificate path (x509)
#[arg(long)]
ssl_key: Option<String>,
@ -65,9 +62,9 @@ pub struct Args {
#[arg(long)]
ssl_cert: Option<String>,
/// Enable WRAC
/// Enable Proxy-Mode
#[arg(short = 'w', long)]
enable_wrac: bool,
proxy_to: Option<String>,
}
fn main() {
@ -83,5 +80,7 @@ fn main() {
info!("Server started on {}", &args.host);
run_listener(context);
let (host, ssl, wrac) = parse_rac_url(&args.host).expect("INVALID RAC URL");
run_listener(context, &host, ssl, wrac);
}

View File

@ -24,8 +24,9 @@ fn accept_stream(
stream: impl Read + Write,
addr: SocketAddr,
ctx: Arc<Context>,
wrac: bool,
) -> Result<(), Box<dyn Error>> {
if ctx.args.enable_wrac {
if wrac {
accept_wrac_stream(stream, addr, ctx)?;
} else {
accept_rac_stream(stream, addr, ctx)?;
@ -34,9 +35,8 @@ fn accept_stream(
Ok(())
}
fn run_normal_listener(ctx: Arc<Context>) {
let listener =
TcpListener::bind(&ctx.args.host).expect("error trying bind to the provided addr");
fn run_normal_listener(ctx: Arc<Context>, host: &str, wrac: bool) {
let listener = TcpListener::bind(host).expect("error trying bind to the provided addr");
for stream in listener.incoming() {
let Ok(stream) = stream else { continue };
@ -47,7 +47,7 @@ fn run_normal_listener(ctx: Arc<Context>) {
let Ok(addr) = stream.peer_addr() else {
return;
};
match accept_stream(stream, addr, ctx) {
match accept_stream(stream, addr, ctx, wrac) {
Ok(_) => {}
Err(e) => {
debug!("{}", e)
@ -57,9 +57,8 @@ fn run_normal_listener(ctx: Arc<Context>) {
}
}
fn run_secure_listener(ctx: Arc<Context>) {
let listener =
TcpListener::bind(&ctx.args.host).expect("error trying bind to the provided addr");
fn run_secure_listener(ctx: Arc<Context>, host: &str, wrac: bool) {
let listener = TcpListener::bind(host).expect("error trying bind to the provided addr");
let server_config = Arc::new(
ServerConfig::builder()
@ -101,7 +100,7 @@ fn run_secure_listener(ctx: Arc<Context>) {
};
}
match accept_stream(stream, addr, ctx) {
match accept_stream(stream, addr, ctx, wrac) {
Ok(_) => {}
Err(e) => {
debug!("{}", e)
@ -111,10 +110,10 @@ fn run_secure_listener(ctx: Arc<Context>) {
}
}
pub fn run_listener(ctx: Arc<Context>) {
if ctx.args.enable_ssl {
run_secure_listener(ctx);
pub fn run_listener(ctx: Arc<Context>, host: &str, ssl: bool, wrac: bool) {
if ssl {
run_secure_listener(ctx, host, wrac);
} else {
run_normal_listener(ctx);
run_normal_listener(ctx, host, wrac);
}
}