Skip to content

Commit

Permalink
fix #50
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Mar 18, 2024
1 parent 2b12af2 commit 3dbff37
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
7 changes: 3 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ async fn handle_socks5_cmd_connection(connect: Connect<NeedReply>, target_addr:
log::trace!("{} -> {} tunnel establishing", peer_addr, target_addr);

let client = config.client.as_ref().ok_or("client not exist")?;
let (ip_addr, port) = (client.server_host.as_str(), client.server_port);
let addr = SocketAddr::new(ip_addr.parse()?, port);
let addr = client.server_ip_addr.ok_or("server host")?;

if !config.disable_tls() {
let ws_stream = create_tls_ws_stream(addr, Some(target_addr.clone()), &config, None).await?;
Expand Down Expand Up @@ -250,8 +249,8 @@ pub(crate) async fn create_ws_stream<S: AsyncRead + AsyncWrite + Unpin>(

let b64_dst = dst_addr.as_ref().map(|dst_addr| addess_to_b64str(dst_addr, false));

let host_port = crate::combine_addr_and_port(&client.server_host, client.server_port);
let uri = format!("ws://{}/{}/", host_port, tunnel_path);
let server_ip = client.server_ip_addr.ok_or("server ip addr")?.to_string();
let uri = format!("ws://{}/{}/", server_ip, tunnel_path);

let uri = WeirdUri::new(&uri, b64_dst, udp_tunnel, client.client_id.clone());

Expand Down
5 changes: 4 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ pub struct Client {
pub listen_password: Option<String>,
#[serde(skip)]
pub cache_dns: bool,
#[serde(skip)]
pub(crate) server_ip_addr: Option<SocketAddr>,
}

impl Default for Config {
Expand Down Expand Up @@ -259,7 +261,7 @@ impl Config {
}
if let Some(client) = &mut self.client {
if client.server_host.is_empty() {
return Err(Error::from("We need server_host in client settings"));
return Err(Error::from("We need server host in client settings"));
}
if client.server_port == 0 {
client.server_port = 443;
Expand All @@ -283,6 +285,7 @@ impl Config {
Ipv6Addr::LOCALHOST.to_string()
};
}
client.server_ip_addr = Some(addr);
}
}
Ok(())
Expand Down
10 changes: 2 additions & 8 deletions src/udprelay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ use socks5_impl::{
UdpAssociate,
},
};
use std::{
collections::HashSet,
net::{SocketAddr, ToSocketAddrs},
sync::Arc,
time::Duration,
};
use std::{collections::HashSet, net::SocketAddr, sync::Arc, time::Duration};
use tokio::{
io::{AsyncRead, AsyncWrite},
net::UdpSocket,
Expand Down Expand Up @@ -150,8 +145,7 @@ pub(crate) fn create_udp_tunnel() -> (UdpRequestSender, UdpRequestReceiver, Sock

pub(crate) async fn run_udp_loop(udp_tx: UdpRequestSender, incomings: SocketAddrHashSet, config: Config) -> Result<()> {
let client = config.client.as_ref().ok_or("config client not exist")?;
let mut addr = (client.server_host.as_str(), client.server_port).to_socket_addrs()?;
let svr_addr = addr.next().ok_or("client address not exist")?;
let svr_addr = client.server_ip_addr.ok_or("server ip addr")?;

if !config.disable_tls() {
let ws_stream = client::create_tls_ws_stream(svr_addr, None, &config, Some(true)).await?;
Expand Down

0 comments on commit 3dbff37

Please sign in to comment.