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;
|
|
|
|
|
2024-10-18 21:04:46 +03:00
|
|
|
use error::{AppResult, HandlerError};
|
2024-10-18 17:40:04 +03:00
|
|
|
use handler::handler;
|
|
|
|
|
|
|
|
use socks5_server as socks;
|
2024-10-18 21:04:46 +03:00
|
|
|
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);
|
|
|
|
|
2024-10-18 21:11:36 +03:00
|
|
|
let listener = TcpListener::bind((config.host, config.port)).await?;
|
2024-10-18 17:40:04 +03:00
|
|
|
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(()) => {}
|
2024-10-18 21:04:46 +03:00
|
|
|
Err(HandlerError {
|
|
|
|
inner: e,
|
|
|
|
stream: mut conn,
|
|
|
|
}) => {
|
|
|
|
eprintln!("{:?}", e);
|
|
|
|
let _ = conn.shutdown().await;
|
2024-10-18 17:40:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|