#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used, clippy::panic))]
use common::quic::Congestion;
use common::remote::RemoteRequest;
use common::tls::{ClientTlsConfig, ServerTlsConfig};
use std::fmt;
use std::net::{IpAddr, SocketAddr};
use tracing::{error, info};
pub mod cert;
pub mod client;
pub mod common;
pub mod embedded;
pub mod server;
#[derive(Debug)]
pub struct ServerConfig {
pub host: IpAddr,
pub port: u16,
pub allow_reverse: bool,
pub tls: ServerTlsConfig,
pub congestion: Congestion,
}
#[derive(Debug, Clone)]
pub struct ServerEndpoint {
pub addr: SocketAddr,
pub host: String,
}
impl fmt::Display for ServerEndpoint {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.host == self.addr.ip().to_string() {
write!(f, "{}", self.addr)
} else {
write!(f, "{} ({})", self.host, self.addr)
}
}
}
#[derive(Debug)]
pub struct ClientConfig {
pub server: ServerEndpoint,
pub remotes: Vec<RemoteRequest>,
pub tls: ClientTlsConfig,
pub congestion: Congestion,
}
pub fn run_server(config: ServerConfig) {
info!("running server");
match server::run(config) {
Ok(_) => {}
Err(e) => {
error!("an error occurred: {}", e)
}
}
}
pub fn run_client(config: ClientConfig) {
info!("running client");
match client::run(config) {
Ok(_) => {}
Err(e) => {
error!("an error occured: {}", e)
}
}
}