Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ibigbug committed Oct 1, 2024
1 parent 3934720 commit b3ae33d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
2 changes: 1 addition & 1 deletion clash_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ env_logger = "0.11"
[build-dependencies]
prost-build = "0.13"

[target.'cfg(linux)'.dependencies]
[target.'cfg(target_os="linux")'.dependencies]
unix-udp-sock = { git = "https://github.com/Watfaq/unix-udp-sock.git", rev = "cd3e4eca43e6f3be82a2703c3d711b7e18fbfd18"}

[target.'cfg(macos)'.dependencies]
Expand Down
41 changes: 14 additions & 27 deletions clash_lib/src/proxy/tproxy/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
use std::{net::SocketAddr, sync::Arc};

use crate::{app::dispatcher::Dispatcher, proxy::InboundListener};
use super::tun::TunDatagram;
use crate::{
app::dispatcher::Dispatcher,
proxy::{datagram::UdpPacket, utils::apply_tcp_options, InboundListener},
session::{Network, Session, Type},
};
use async_trait::async_trait;

use tracing::warn;
use socket2::{Domain, Socket};
use std::{
net::SocketAddr,
os::fd::{AsFd, AsRawFd},
sync::Arc,
};
use tokio::net::TcpListener;
use tracing::{trace, warn};

pub struct Listener {
addr: SocketAddr,
Expand Down Expand Up @@ -33,15 +42,6 @@ impl InboundListener for Listener {
}

async fn listen_tcp(&self) -> std::io::Result<()> {
use socket2::Socket;
use tokio::net::TcpListener;
use tracing::trace;

use crate::{
proxy::utils::apply_tcp_options,
session::{Network, Session, Type},
};

let socket =
Socket::new(socket2::Domain::IPV4, socket2::Type::STREAM, None)?;
socket.set_ip_transparent(true)?;
Expand Down Expand Up @@ -77,10 +77,6 @@ impl InboundListener for Listener {
}

async fn listen_udp(&self) -> std::io::Result<()> {
use std::os::fd::{AsFd, AsRawFd};

use socket2::{Domain, Socket};

let socket = Socket::new(Domain::IPV4, socket2::Type::DGRAM, None)?;
socket.set_ip_transparent(true)?;
socket.set_nonblocking(true)?;
Expand Down Expand Up @@ -109,15 +105,6 @@ async fn handle_inbound_datagram(
socket: Arc<unix_udp_sock::UdpSocket>,
dispatcher: Arc<Dispatcher>,
) -> std::io::Result<()> {
use tracing::trace;

use crate::{
proxy::datagram::UdpPacket,
session::{Network, Session, Type},
};

use super::tun::TunDatagram;

// dispatcher <-> tproxy communications
let (l_tx, mut l_rx) = tokio::sync::mpsc::channel(32);

Expand Down

0 comments on commit b3ae33d

Please sign in to comment.