Skip to content

Commit

Permalink
update socket2 to v0.4
Browse files Browse the repository at this point in the history
- Domain uses IPV4 and IPV6
- Type uses DGRAM
- Protocol uses UDP and TCP
- into_udp_socket uses Into::into

fixes #456
  • Loading branch information
zonyitoo committed Mar 15, 2021
1 parent 46a51c8 commit fd926bb
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 34 deletions.
28 changes: 19 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/shadowsocks-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ rustls-native-certs = { version = "0.5", optional = true }
async-trait = "0.1"
mio = { version = "0.7", optional = true }

socket2 = { version = "0.3", features = ["reuseport"] }
socket2 = { version = "0.4", features = ["all"] }
libc = "0.2"

http = { version = "0.2", optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl TcpStreamRedirExt for TcpStream {
let peer_addr = self.peer_addr()?;
let bind_addr = self.local_addr()?;

PF.natlook(&bind_addr, &peer_addr, Protocol::tcp())
PF.natlook(&bind_addr, &peer_addr, Protocol::TCP)
}
#[cfg(any(
target_os = "freebsd",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ impl UdpRedirSocket {
));
}

let domain = match addr {
SocketAddr::V4(..) => Domain::ipv4(),
SocketAddr::V6(..) => Domain::ipv6(),
};
let socket = Socket::new(domain, Type::dgram(), Some(Protocol::udp()))?;
let socket = Socket::new(Domain::for_address(addr), Type::DGRAM, Some(Protocol::UDP))?;
set_socket_before_bind(&addr, &socket)?;

socket.set_nonblocking(true)?;
Expand All @@ -64,7 +60,7 @@ impl UdpRedirSocket {

socket.bind(&SockAddr::from(addr))?;

let io = AsyncFd::new(socket.into_udp_socket())?;
let io = AsyncFd::new(socket.into())?;
Ok(UdpRedirSocket { io })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ impl UdpRedirSocket {
));
}

let domain = match addr {
SocketAddr::V4(..) => Domain::ipv4(),
SocketAddr::V6(..) => Domain::ipv6(),
};
let socket = Socket::new(domain, Type::dgram(), Some(Protocol::udp()))?;
let socket = Socket::new(Domain::for_address(addr), Type::DGRAM, Some(Protocol::UDP))?;
set_socket_before_bind(&addr, &socket)?;

socket.set_nonblocking(true)?;
Expand All @@ -77,7 +73,7 @@ impl UdpRedirSocket {

socket.bind(&SockAddr::from(addr))?;

let io = AsyncFd::new(socket.into_udp_socket())?;
let io = AsyncFd::new(socket.into())?;
Ok(UdpRedirSocket { io })
}

Expand Down
2 changes: 1 addition & 1 deletion crates/shadowsocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ futures = "0.3"
async-trait = "0.1"

mio = "0.7"
socket2 = "0.3"
socket2 = "0.4"
tokio = { version = "1", features = ["io-util", "macros", "net", "parking_lot", "process", "rt", "sync"] }

trust-dns-resolver = { version = "0.20", optional = true }
Expand Down
7 changes: 2 additions & 5 deletions crates/shadowsocks/src/relay/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,7 @@ pub async fn create_inbound_udp_socket(addr: &SocketAddr) -> io::Result<UdpSocke
if !set_dual_stack {
UdpSocket::bind(addr).await
} else {
let socket = match *addr {
SocketAddr::V4(..) => Socket::new(Domain::ipv4(), Type::dgram(), Some(Protocol::udp()))?,
SocketAddr::V6(..) => Socket::new(Domain::ipv6(), Type::dgram(), Some(Protocol::udp()))?,
};
let socket = Socket::new(Domain::for_address(*addr), Type::DGRAM, Some(Protocol::UDP))?;

if let Err(err) = socket.set_only_v6(false) {
warn!("failed to set IPV6_V6ONLY: false for listener, error: {}", err);
Expand Down Expand Up @@ -352,6 +349,6 @@ pub async fn create_inbound_udp_socket(addr: &SocketAddr) -> io::Result<UdpSocke

// UdpSocket::from_std requires socket to be non-blocked
socket.set_nonblocking(true)?;
UdpSocket::from_std(socket.into_udp_socket())
UdpSocket::from_std(socket.into())
}
}
7 changes: 2 additions & 5 deletions crates/shadowsocks/src/relay/sys/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ pub async fn create_inbound_udp_socket(addr: &SocketAddr) -> io::Result<UdpSocke
let socket = if !set_dual_stack {
UdpSocket::bind(addr).await?
} else {
let socket = match *addr {
SocketAddr::V4(..) => Socket::new(Domain::ipv4(), Type::dgram(), Some(Protocol::udp()))?,
SocketAddr::V6(..) => Socket::new(Domain::ipv6(), Type::dgram(), Some(Protocol::udp()))?,
};
let socket = Socket::new(Domain::for_address(*addr), Type::DGRAM, Some(Protocol::UDP))?;

if let Err(err) = socket.set_only_v6(false) {
warn!("failed to set IPV6_V6ONLY: false for listener, error: {}", err);
Expand Down Expand Up @@ -107,7 +104,7 @@ pub async fn create_inbound_udp_socket(addr: &SocketAddr) -> io::Result<UdpSocke

// UdpSocket::from_std requires socket to be non-blocked
socket.set_nonblocking(true)?;
UdpSocket::from_std(socket.into_udp_socket())?
UdpSocket::from_std(socket.into())?
};

disable_connection_reset(&socket)?;
Expand Down

0 comments on commit fd926bb

Please sign in to comment.