16 lines
661 B
Rust
16 lines
661 B
Rust
use std::{net::SocketAddr, sync::{atomic::AtomicBool, Arc}};
|
|
use smol::{spawn, net::TcpListener};
|
|
|
|
pub async fn run(local: SocketAddr, remote: SocketAddr, name: String, kill: Option<Arc<AtomicBool>>) {
|
|
match TcpListener::bind(local).await {
|
|
Ok(listener) => {
|
|
eprintln!("[OK] forwarding from {local} to {remote} {name}");
|
|
loop {
|
|
let (connection, _) = listener.accept().await.unwrap();
|
|
spawn(crate::protocol::client(connection, remote, name.clone(), kill.as_ref().map(Arc::clone))).detach();
|
|
}
|
|
},
|
|
Err(e) => eprintln!("[ERR] Couldn't listen on {local}: {e}"),
|
|
}
|
|
}
|