Skip to content

Commit

Permalink
fix(shadowsocks-service): compatible with smoltcp v0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Nov 28, 2024
1 parent 90496e5 commit 103e060
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions crates/shadowsocks-service/src/local/tun/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::{
use log::{debug, error, trace};
use shadowsocks::{net::TcpSocketOpts, relay::socks5::Address};
use smoltcp::{
iface::{Config as InterfaceConfig, Interface, SocketHandle, SocketSet},
iface::{Config as InterfaceConfig, Interface, PollResult, SocketHandle, SocketSet},
phy::{DeviceCapabilities, Medium},
socket::tcp::{Socket as TcpSocket, SocketBuffer as TcpSocketBuffer, State as TcpState},
storage::RingBuffer,
Expand Down Expand Up @@ -324,9 +324,7 @@ impl TcpTun {
}

let before_poll = SmolInstant::now();
let updated_sockets = iface.poll(before_poll, device, &mut socket_set);

if updated_sockets {
if let PollResult::SocketStateChanged = iface.poll(before_poll, device, &mut socket_set) {
trace!("VirtDevice::poll costed {}", SmolInstant::now() - before_poll);
}

Expand Down Expand Up @@ -357,7 +355,10 @@ impl TcpTun {
}

// SHUT_WR
if matches!(control.send_state, TcpSocketState::Close) && socket.send_queue() == 0 && control.send_buffer.is_empty() {
if matches!(control.send_state, TcpSocketState::Close)
&& socket.send_queue() == 0
&& control.send_buffer.is_empty()
{
trace!("closing TCP Write Half, {:?}", socket.state());

// Close the socket. Set to FIN state
Expand Down
6 changes: 3 additions & 3 deletions crates/shadowsocks-service/src/local/tun/virt_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ pub struct VirtRxToken<'a> {
}

impl phy::RxToken for VirtRxToken<'_> {
fn consume<R, F>(mut self, f: F) -> R
fn consume<R, F>(self, f: F) -> R
where
F: FnOnce(&mut [u8]) -> R,
F: FnOnce(&[u8]) -> R,
{
f(&mut self.buffer[..])
f(&self.buffer)
}
}

Expand Down

0 comments on commit 103e060

Please sign in to comment.