mirror of
https://github.com/MeexReay/sRAC.git
synced 2025-06-23 18:12:57 +03:00
make using rac url
This commit is contained in:
parent
a5ea227748
commit
f4ad746453
800
Cargo.lock
generated
800
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -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
4
shell.nix
Normal file
@ -0,0 +1,4 @@
|
||||
{ pkgs ? import <nixpkgs> {} }:
|
||||
pkgs.mkShell {
|
||||
buildInputs = with pkgs; [ pkg-config openssl ];
|
||||
}
|
@ -132,7 +132,7 @@ pub fn on_register_user(
|
||||
|
||||
info!("user registered: {name}");
|
||||
|
||||
ctx.push_account(account);
|
||||
ctx.push_account(account)?;
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
15
src/main.rs
15
src/main.rs
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user