Skip to content

Commit

Permalink
socks udp代理账号密码支持
Browse files Browse the repository at this point in the history
  • Loading branch information
chending committed Jan 30, 2024
1 parent 2e7055b commit 9251fc0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion leaf/src/app/outbound/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,15 @@ impl OutboundManager {
.map_err(|e| anyhow!("invalid [{}] outbound settings: {}", &tag, e))?;
let stream = Box::new(socks::outbound::StreamHandler {
address: settings.address.clone(),
port: settings.port as u16,
port: settings.port.clone() as u16,
username: settings.username.clone(),
password: settings.password.clone(),
});
let datagram = Box::new(socks::outbound::DatagramHandler {
address: settings.address.clone(),
port: settings.port as u16,
username: settings.username.clone(),
password: settings.password.clone(),
dns_client: dns_client.clone(),
});
HandlerBuilder::default()
Expand Down
11 changes: 10 additions & 1 deletion leaf/src/proxy/socks/outbound/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::{app::SyncDnsClient, proxy::*, session::*};
pub struct Handler {
pub address: String,
pub port: u16,
pub username: String,
pub password: String,
pub dns_client: SyncDnsClient,
}

Expand All @@ -39,7 +41,14 @@ impl OutboundDatagramHandler for Handler {
.new_tcp_stream(self.dns_client.clone(), &self.address, &self.port)
.await?;
let socket = self.new_udp_socket(&sess.source).await?;
let socket = SocksDatagram::associate(stream, socket, None::<Auth>, None::<AddrKind>)
let auth = match (&self.username, &self.password) {
(auth_username, _) if auth_username.is_empty() => None,
(auth_username, auth_password) => Some(Auth {
username: auth_username.to_owned(),
password: auth_password.to_owned(),
}),
};
let socket = SocksDatagram::associate(stream, socket, auth, None::<AddrKind>)
.map_err(|x| Error::new(ErrorKind::Other, x))
.await?;
Ok(Box::new(Datagram { socket }))
Expand Down

0 comments on commit 9251fc0

Please sign in to comment.