smp-socks/src/main.rs

41 lines
992 B
Rust
Raw Normal View History

2024-10-18 17:40:04 +03:00
mod config;
mod error;
mod handler;
2024-10-18 20:42:08 +03:00
mod host;
2024-10-18 17:40:04 +03:00
mod serde_addr;
use std::sync::Arc;
use error::{AppResult, HandlerError};
2024-10-18 17:40:04 +03:00
use handler::handler;
use socks5_server as socks;
use tokio::{io::AsyncWriteExt, net::TcpListener};
2024-10-18 17:40:04 +03:00
#[tokio::main]
async fn main() -> AppResult<()> {
let config = Arc::new(config::parse()?);
let auth = Arc::new(socks::auth::NoAuth);
let listener = TcpListener::bind((config.host.as_str(), config.port)).await?;
let server = socks::Server::new(listener, auth);
while let Ok((conn, _addr)) = server.accept().await {
let config = config.clone();
tokio::spawn(async move {
match handler(conn, config).await {
Ok(()) => {}
Err(HandlerError {
inner: e,
stream: mut conn,
}) => {
eprintln!("{:?}", e);
let _ = conn.shutdown().await;
2024-10-18 17:40:04 +03:00
}
}
});
}
Ok(())
}