use relay_core_lib::{start_proxy, engine::TcpCaptureSource};
use tokio::net::TcpListener;
use std::sync::Arc;
use std::path::Path;
use relay_core_lib::interceptor::NoOpInterceptor;
use relay_core_lib::tls::CertificateAuthority;
use relay_core_api::policy::ProxyPolicy;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let _ = rustls::crypto::ring::default_provider().install_default();
let addr = "127.0.0.1:8080";
let listener = TcpListener::bind(addr).await?;
println!("Proxy listening on {}", addr);
let source = TcpCaptureSource::new(listener);
let (tx, mut rx) = tokio::sync::mpsc::channel(100);
tokio::spawn(async move {
while let Some(_) = rx.recv().await {}
});
let interceptor = Arc::new(NoOpInterceptor);
let ca_cert_path = Path::new("custom_ca.crt");
let ca_key_path = Path::new("custom_ca.key");
println!("Loading CA from {:?}", ca_cert_path);
let ca = Arc::new(CertificateAuthority::load_or_create(ca_cert_path, ca_key_path)?);
println!("CA Loaded Successfully!");
println!("CA Subject: RelayCraft CA (Self-signed)");
println!("CA Certificate PEM:\n{}", ca.get_ca_cert_pem());
let (_tx, policy_rx) = tokio::sync::watch::channel(ProxyPolicy::default());
println!("Starting proxy...");
start_proxy(source, tx, interceptor, ca, policy_rx, None, None).await?;
Ok(())
}