use std::{ str::FromStr, net::SocketAddr, }; use tokio::{ io::{split, copy}, net::TcpListener, }; use ciph::salsa::{Psk, Acceptor, Randomness}; #[tokio::main] async fn main() -> Result<(), Box> { const PSK_B64: &str = include_str!("example.psk"); let psk = Psk::from_str(PSK_B64)?; let acceptor = Acceptor::new(psk, Randomness::Entropy); let args: Vec = std::env::args() .collect(); assert!(args.len() >= 2); let listen_addr = args[1].to_owned(); let addr = SocketAddr::from_str(listen_addr.as_str())?; let listener = TcpListener::bind(&addr).await?; loop { let (stream, _) = listener.accept().await?; let establish = acceptor.accept(stream); println!("Client connected!"); let service_fut = async move { println!("Echoing..."); let stream = establish.await.unwrap(); let (mut reader, mut writer) = split(stream); copy(&mut reader, &mut writer).await.unwrap(); println!("Echo complete."); }; tokio::spawn(service_fut); } }