octoproxy_server/
lib.rs

1use anyhow::{Context, Result};
2use std::path::PathBuf;
3
4use config::Config;
5use octoproxy_lib::build_rt;
6use tracing_subscriber::EnvFilter;
7
8use clap::Parser;
9
10mod config;
11mod proxy;
12
13/// Server commandline args
14#[derive(Debug, Parser)]
15#[command(author, version, about, long_about = None)]
16pub struct Cmd {
17    /// http proxy server listening address
18    #[arg(short = 'l', long = "listen")]
19    listen_address: Option<String>,
20    /// trusted client cert
21    #[arg(long = "auth")]
22    auth: Option<PathBuf>,
23    /// config
24    #[arg(short = 'c', long = "config", default_value = "config.toml")]
25    config: PathBuf,
26}
27
28impl Cmd {
29    pub fn run(self) -> Result<()> {
30        let rt = build_rt();
31        rt.block_on(self.run_main())
32    }
33
34    /// client run function, distribute the listener service, and help selecting backend,
35    /// and spawn the each transmission action
36    async fn run_main(self) -> Result<()> {
37        let config = Config::new(self).context("Could not init config")?;
38
39        let env = EnvFilter::builder()
40            .with_default_directive(config.log_level.into())
41            .from_env_lossy();
42
43        tracing_subscriber::fmt().with_env_filter(env).init();
44        let h2_task = config.run_h2();
45        let quic_task = config.run_quic();
46
47        let _ = tokio::join!(quic_task, h2_task);
48        Ok(())
49    }
50}