Skip to content

Commit

Permalink
log info
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Nov 22, 2024
1 parent 2770521 commit 44ca51c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub use dump_logger::dns2socks_set_log_callback;
const MAX_BUFFER_SIZE: usize = 4096;

pub async fn main_entry(config: Config, shutdown_token: tokio_util::sync::CancellationToken) -> Result<()> {
log::info!("Starting DNS2Socks listening on {}...", config.listen_addr);
let user_key = match (&config.username, &config.password) {
(Some(username), password) => Some(UserKey::new(username, password.clone().unwrap_or_default())),
_ => None,
Expand Down Expand Up @@ -54,11 +55,20 @@ pub async fn main_entry(config: Config, shutdown_token: tokio_util::sync::Cancel
},
}

log::info!("DNS2Socks stopped");

Ok(())
}

pub(crate) async fn udp_thread(opt: Config, user_key: Option<UserKey>, cache: Cache<Vec<Query>, Message>, timeout: Duration) -> Result<()> {
let listener = Arc::new(UdpSocket::bind(&opt.listen_addr).await?);
let listener = match UdpSocket::bind(&opt.listen_addr).await {
Ok(listener) => listener,
Err(e) => {
log::error!("UDP listener {} error \"{}\"", opt.listen_addr, e);
return Err(e.into());
}
};
let listener = Arc::new(listener);
log::info!("Udp listening on: {}", opt.listen_addr);

loop {
Expand Down Expand Up @@ -135,7 +145,13 @@ async fn udp_incoming_handler(
}

pub(crate) async fn tcp_thread(opt: Config, user_key: Option<UserKey>, cache: Cache<Vec<Query>, Message>, timeout: Duration) -> Result<()> {
let listener = TcpListener::bind(&opt.listen_addr).await?;
let listener = match TcpListener::bind(&opt.listen_addr).await {
Ok(listener) => listener,
Err(e) => {
log::error!("TCP listener {} error \"{}\"", opt.listen_addr, e);
return Err(e.into());
}
};
log::info!("TCP listening on: {}", opt.listen_addr);

while let Ok((mut incoming, _)) = listener.accept().await {
Expand Down

0 comments on commit 44ca51c

Please sign in to comment.