pasque 0.3.0

UDP and IP over HTTP/3
Documentation
#[macro_use]
extern crate log;

use clap::Parser;
use std::net::SocketAddr;

use pasque::{
    PsqServer,
    server::Config,
};


#[tokio::main]
async fn main() {
    env_logger::builder().format_timestamp_nanos().init();

    let args = Args::new();
    let config = match Config::read_from_file(args.config()) {
        Ok(c) => c,
        Err(e) => {
            warn!(
                "Could not read config '{}': {}. Applying default configuration.",
                args.config(),
                e,
            );
            Config::create_default()
        }
    };

    let mut psqserver = PsqServer::start(
        &args.address(),
        &config,
    ).await.unwrap();

    loop {
        if let Err(e) = psqserver.process().await {
            error!("PsqServer error: {}", e);
        }
    }
}


#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Args {
    /// Local IP address and UDP port to bind.
    #[arg(short, long, default_value = "0.0.0.0:443", value_delimiter = ' ', num_args = 1..)]
    address: Vec<SocketAddr>,

    /// Configuration file to read.
    #[arg(short, long, default_value = "src/bin/server-example.json")]
    config: String,
}


impl Args {
    pub fn new() -> Args {
        let args = Args::parse();

        args
    }

    pub fn address(&self) -> &Vec<SocketAddr> {
        &self.address
    }

    pub fn config(&self) -> &String {
        &self.config
    }
}