From 1d3e6b77fe260c965c5abfa61f1ab5e2fc0b2806 Mon Sep 17 00:00:00 2001 From: zonyitoo Date: Thu, 15 Apr 2021 17:26:54 +0800 Subject: [PATCH] fixed local-redir compatibility build on windows --- crates/shadowsocks-service/src/config.rs | 4 +++- .../src/local/redir/udprelay/sys/unix/bsd.rs | 2 +- .../src/local/redir/udprelay/sys/windows/mod.rs | 15 +++++++++++---- crates/shadowsocks-service/src/manager/mod.rs | 4 ++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/shadowsocks-service/src/config.rs b/crates/shadowsocks-service/src/config.rs index 65753f0c82ec..6671828309af 100644 --- a/crates/shadowsocks-service/src/config.rs +++ b/crates/shadowsocks-service/src/config.rs @@ -43,6 +43,8 @@ #[cfg(any(target_os = "linux", target_os = "android", target_os = "macos", target_os = "ios"))] use std::ffi::OsString; +#[cfg(any(unix, target_os = "android", feature = "local-flow-stat"))] +use std::path::PathBuf; use std::{ convert::{From, Infallible}, default::Default, @@ -51,7 +53,7 @@ use std::{ io::Read, net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}, option::Option, - path::{Path, PathBuf}, + path::Path, str::FromStr, string::ToString, time::Duration, diff --git a/crates/shadowsocks-service/src/local/redir/udprelay/sys/unix/bsd.rs b/crates/shadowsocks-service/src/local/redir/udprelay/sys/unix/bsd.rs index eab0530cf68b..a87720b8e287 100644 --- a/crates/shadowsocks-service/src/local/redir/udprelay/sys/unix/bsd.rs +++ b/crates/shadowsocks-service/src/local/redir/udprelay/sys/unix/bsd.rs @@ -64,7 +64,7 @@ impl UdpRedirSocket { } /// Send data to the socket to the given target address - pub async fn send_to(&mut self, buf: &[u8], target: SocketAddr) -> io::Result { + pub async fn send_to(&self, buf: &[u8], target: SocketAddr) -> io::Result { poll_fn(|cx| self.poll_send_to(cx, buf, target)).await } diff --git a/crates/shadowsocks-service/src/local/redir/udprelay/sys/windows/mod.rs b/crates/shadowsocks-service/src/local/redir/udprelay/sys/windows/mod.rs index ac26aba738b6..e57ddad40f97 100644 --- a/crates/shadowsocks-service/src/local/redir/udprelay/sys/windows/mod.rs +++ b/crates/shadowsocks-service/src/local/redir/udprelay/sys/windows/mod.rs @@ -1,6 +1,13 @@ -use std::{io, net::SocketAddr}; +use std::{ + io, + net::SocketAddr, + task::{Context, Poll}, +}; -use crate::{config::RedirType, local::redir::redir_ext::UdpSocketRedir}; +use crate::{ + config::RedirType, + local::redir::redir_ext::{RedirSocketOpts, UdpSocketRedir}, +}; pub struct UdpRedirSocket; @@ -15,7 +22,7 @@ impl UdpRedirSocket { /// Create a new UDP socket binded to `addr` /// /// This will allow binding to `addr` that is not in local host - pub fn bind_nonlocal(ty: RedirType, addr: SocketAddr) -> io::Result { + pub fn bind_nonlocal(ty: RedirType, addr: SocketAddr, _redir_opts: &RedirSocketOpts) -> io::Result { UdpRedirSocket::bind(ty, addr, true) } @@ -24,7 +31,7 @@ impl UdpRedirSocket { } /// Send data to the socket to the given target address - pub async fn send_to(&mut self, _buf: &[u8], _target: &SocketAddr) -> io::Result { + pub async fn send_to(&self, _buf: &[u8], _target: SocketAddr) -> io::Result { unimplemented!("UDP transparent proxy is not supported on Windows") } diff --git a/crates/shadowsocks-service/src/manager/mod.rs b/crates/shadowsocks-service/src/manager/mod.rs index 29fc3e9fd362..5067c9a0cc17 100644 --- a/crates/shadowsocks-service/src/manager/mod.rs +++ b/crates/shadowsocks-service/src/manager/mod.rs @@ -4,7 +4,7 @@ use std::{io, sync::Arc}; -use log::{trace, warn}; +use log::trace; use shadowsocks::net::{AcceptOpts, ConnectOpts}; use crate::{ @@ -26,7 +26,7 @@ pub async fn run(config: Config) -> io::Result<()> { if let Some(nofile) = config.nofile { use crate::sys::set_nofile; if let Err(err) = set_nofile(nofile) { - warn!("set_nofile {} failed, error: {}", nofile, err); + log::warn!("set_nofile {} failed, error: {}", nofile, err); } }