40 lines
983 B
Rust
40 lines
983 B
Rust
mod config;
|
|
mod error;
|
|
mod handler;
|
|
mod host;
|
|
mod serde_addr;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use error::{AppResult, HandlerError};
|
|
use handler::handler;
|
|
|
|
use socks5_server as socks;
|
|
use tokio::{io::AsyncWriteExt, net::TcpListener};
|
|
|
|
#[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, 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;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
Ok(())
|
|
}
|