Skip to content

Commit

Permalink
chore(deps): bump tun2 from 2.0.8 to 3.1.0 (#1640)
Browse files Browse the repository at this point in the history
* chore(deps): bump tun2 from 2.0.8 to 3.1.0

Bumps [tun2](/~https://github.com/ssrlive/rust-tun) from 2.0.8 to 3.1.0.
- [Release notes](/~https://github.com/ssrlive/rust-tun/releases)
- [Commits](/~https://github.com/ssrlive/rust-tun/commits)

---
updated-dependencies:
- dependency-name: tun2
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix: AsyncDevice impls Deref

* fix: fake tun impls Deref

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: zonyitoo <zonyitoo@gmail.com>
  • Loading branch information
dependabot[bot] and zonyitoo authored Sep 5, 2024
1 parent 2361f2f commit f41fc6f
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 24 deletions.
106 changes: 95 additions & 11 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 @@ -186,7 +186,7 @@ flate2 = { version = "1.0", optional = true }
brotli = { version = "6.0", optional = true }
zstd = { version = "0.13", optional = true }

tun2 = { version = "2.0.8", optional = true, default-features = false, features = [
tun2 = { version = "3.1.0", optional = true, default-features = false, features = [
"async",
] }
etherparse = { version = "0.15", optional = true }
Expand Down
15 changes: 15 additions & 0 deletions crates/shadowsocks-service/src/local/tun/fake_tun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::{
io::{self, Read, Write},
net::IpAddr,
ops::{Deref, DerefMut},
pin::Pin,
task::{Context, Poll},
};
Expand Down Expand Up @@ -118,6 +119,20 @@ impl AsMut<FakeDevice> for AsyncDevice {
}
}

impl Deref for AsyncDevice {
type Target = FakeDevice;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for AsyncDevice {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl AsyncRead for AsyncDevice {
fn poll_read(self: Pin<&mut Self>, _cx: &mut Context<'_>, _buf: &mut ReadBuf<'_>) -> Poll<io::Result<()>> {
Err(io::Error::new(io::ErrorKind::Other, "not implemented")).into()
Expand Down
16 changes: 4 additions & 12 deletions crates/shadowsocks-service/src/local/tun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ impl TunBuilder {
self.udp_capacity,
);

let tcp = TcpTun::new(
self.context,
self.balancer,
device.as_ref().mtu().unwrap_or(1500) as u32,
);
let tcp = TcpTun::new(self.context, self.balancer, device.mtu().unwrap_or(1500) as u32);

Ok(Tun {
device,
Expand Down Expand Up @@ -160,23 +156,19 @@ impl Tun {
pub async fn run(mut self) -> io::Result<()> {
info!(
"shadowsocks tun device {}, mode {}",
self.device
.as_ref()
.tun_name()
.or_else(|r| Ok::<_, ()>(r.to_string()))
.unwrap(),
self.device.tun_name().or_else(|r| Ok::<_, ()>(r.to_string())).unwrap(),
self.mode,
);

let address = match self.device.as_ref().address() {
let address = match self.device.address() {
Ok(a) => a,
Err(err) => {
error!("[TUN] failed to get device address, error: {}", err);
return Err(io::Error::new(io::ErrorKind::Other, err));
}
};

let netmask = match self.device.as_ref().netmask() {
let netmask = match self.device.netmask() {
Ok(n) => n,
Err(err) => {
error!("[TUN] failed to get device netmask, error: {}", err);
Expand Down

0 comments on commit f41fc6f

Please sign in to comment.