Skip to content

Commit

Permalink
feat(local): local-tun build on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Oct 17, 2023
1 parent 3d978ec commit cf8d84b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
9 changes: 8 additions & 1 deletion crates/shadowsocks-service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ use serde::{Deserialize, Serialize};
use shadowsocks::relay::socks5::Address;
use shadowsocks::{
config::{
ManagerAddr, Mode, ReplayAttackPolicy, ServerAddr, ServerConfig, ServerUser, ServerUserManager, ServerWeight,
ManagerAddr,
Mode,
ReplayAttackPolicy,
ServerAddr,
ServerConfig,
ServerUser,
ServerUserManager,
ServerWeight,
},
crypto::CipherKind,
plugin::PluginConfig,
Expand Down
6 changes: 3 additions & 3 deletions crates/shadowsocks-service/src/local/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,6 @@ impl Server {
}
#[cfg(feature = "local-tun")]
ProtocolType::Tun => {
use log::info;
use shadowsocks::net::UnixListener;

let mut builder = TunBuilder::new(context.clone(), balancer);
if let Some(address) = local_config.tun_interface_address {
builder.address(address);
Expand All @@ -397,6 +394,9 @@ impl Server {
} else if let Some(ref fd_path) = local_config.tun_device_fd_from_path {
use std::fs;

use log::info;
use shadowsocks::net::UnixListener;

let _ = fs::remove_file(fd_path);

let listener = match UnixListener::bind(fd_path) {
Expand Down
20 changes: 20 additions & 0 deletions crates/shadowsocks-service/src/local/tun/sys/windows/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
use std::{io, marker::Unpin};

use tokio::io::{AsyncWrite, AsyncWriteExt};
use tun::platform::Device as TunDevice;

/// Packet Information length in bytes
///
/// Tun device on Windows (https://wintun.net) doesn't have Packet Information header, so there is no prefix headers
pub const IFF_PI_PREFIX_LEN: usize = 0;

/// Writing packet with packet information
///
/// Tun device on Windows (https://wintun.net) doesn't have Packet Information header, so there is nothing to prepend on Windows
pub async fn write_packet_with_pi<W: AsyncWrite + Unpin>(writer: &mut W, packet: &[u8]) -> io::Result<()> {
writer.write_all(packet).await
}

/// Set platform specific route configuration
pub async fn set_route_configuration(_device: &TunDevice) -> io::Result<()> {
Ok(())
}
3 changes: 2 additions & 1 deletion crates/shadowsocks/src/dns_resolver/hickory_dns_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use hickory_resolver::{
udp::{DnsUdpSocket, QuicLocalAddr},
TokioTime,
},
AsyncResolver, TokioHandle,
AsyncResolver,
TokioHandle,
};
use log::trace;
use tokio::{io::ReadBuf, net::UdpSocket};
Expand Down

0 comments on commit cf8d84b

Please sign in to comment.