fmt
This commit is contained in:
+11
-14
@@ -595,8 +595,7 @@ impl Channel {
|
|||||||
tcp_r
|
tcp_r
|
||||||
.read_exact(&mut buf[head_reserve..head_reserve + len])
|
.read_exact(&mut buf[head_reserve..head_reserve + len])
|
||||||
.await?;
|
.await?;
|
||||||
handler
|
handler.handle(&mut buf, head_reserve, head_reserve + len, key, &context);
|
||||||
.handle(&mut buf, head_reserve, head_reserve + len, key, &context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async fn start_tcp(
|
async fn start_tcp(
|
||||||
@@ -684,8 +683,7 @@ impl Channel {
|
|||||||
let handler = handler.clone();
|
let handler = handler.clone();
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
while let Ok((mut buf, start, end, route_key)) = buf_receiver.recv() {
|
while let Ok((mut buf, start, end, route_key)) = buf_receiver.recv() {
|
||||||
handler
|
handler.handle(&mut buf, start, end, route_key, &context);
|
||||||
.handle(&mut buf, start, end, route_key, &context);
|
|
||||||
}
|
}
|
||||||
log::warn!("异步处理停止");
|
log::warn!("异步处理停止");
|
||||||
});
|
});
|
||||||
@@ -815,14 +813,13 @@ impl Channel {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handler
|
handler.handle(
|
||||||
.handle(
|
&mut buf,
|
||||||
&mut buf,
|
head_reserve,
|
||||||
head_reserve,
|
end,
|
||||||
end,
|
RouteKey::new(id, addr),
|
||||||
RouteKey::new(id, addr),
|
&context,
|
||||||
&context,
|
);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("udp :{:?}", e);
|
log::error!("udp :{:?}", e);
|
||||||
@@ -864,11 +861,11 @@ impl Channel {
|
|||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
use std::os::windows::io::AsRawSocket;
|
use std::os::windows::io::AsRawSocket;
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let id = 3 + udp.as_raw_socket() as usize;
|
let id = 3 + udp.as_raw_socket() as usize;
|
||||||
#[cfg(any(unix))]
|
#[cfg(any(unix))]
|
||||||
use std::os::fd::AsRawFd;
|
use std::os::fd::AsRawFd;
|
||||||
#[cfg(any(unix))]
|
#[cfg(any(unix))]
|
||||||
let id = 3 + udp.as_raw_fd() as usize;
|
let id = 3 + udp.as_raw_fd() as usize;
|
||||||
|
|
||||||
context.insert_udp(id, udp.clone());
|
context.insert_udp(id, udp.clone());
|
||||||
match buf_sender {
|
match buf_sender {
|
||||||
|
|||||||
@@ -273,8 +273,10 @@ impl ChannelDataHandler {
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"不支持的ip代理Icmp协议:{}",
|
"不支持的ip代理Icmp协议:{}->{}->{}",
|
||||||
destination
|
source,
|
||||||
|
destination,
|
||||||
|
dest_ip
|
||||||
);
|
);
|
||||||
return Err(Error::Warn(
|
return Err(Error::Warn(
|
||||||
"不支持的ip代理Icmp协议".to_string(),
|
"不支持的ip代理Icmp协议".to_string(),
|
||||||
@@ -283,18 +285,36 @@ impl ChannelDataHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
log::warn!("不支持的ip代理ipv4协议:{}", destination);
|
log::warn!(
|
||||||
|
"不支持的ip代理ipv4协议{:?}:{}->{}->{}",
|
||||||
|
ipv4.protocol(),
|
||||||
|
source,
|
||||||
|
destination,
|
||||||
|
ipv4.destination_ip()
|
||||||
|
);
|
||||||
return Err(Error::Warn(
|
return Err(Error::Warn(
|
||||||
"不支持的ip代理ipv4协议".to_string(),
|
"不支持的ip代理ipv4协议".to_string(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log::warn!("没有ip代理规则:{}", destination);
|
log::warn!(
|
||||||
|
"没有ip代理规则{:?}:{}->{}->{}",
|
||||||
|
ipv4.protocol(),
|
||||||
|
source,
|
||||||
|
destination,
|
||||||
|
ipv4.destination_ip()
|
||||||
|
);
|
||||||
return Err(Error::Warn("没有ip代理规则".to_string()));
|
return Err(Error::Warn("没有ip代理规则".to_string()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log::warn!("不支持ip代理:{}", destination);
|
log::warn!(
|
||||||
|
"不支持ip代理{:?}:{}->{}->{}",
|
||||||
|
ipv4.protocol(),
|
||||||
|
source,
|
||||||
|
destination,
|
||||||
|
ipv4.destination_ip()
|
||||||
|
);
|
||||||
return Err(Error::Warn("不支持ip代理".to_string()));
|
return Err(Error::Warn("不支持ip代理".to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -635,9 +655,11 @@ impl ChannelDataHandler {
|
|||||||
{
|
{
|
||||||
let context = context.clone();
|
let context = context.clone();
|
||||||
let nat_test = self.nat_test.clone();
|
let nat_test = self.nat_test.clone();
|
||||||
std::thread::spawn(move ||{
|
std::thread::spawn(move || {
|
||||||
tokio::runtime::Builder::new_current_thread()
|
tokio::runtime::Builder::new_current_thread()
|
||||||
.enable_all().build().unwrap()
|
.enable_all()
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
.block_on(async move {
|
.block_on(async move {
|
||||||
let local_port = context.main_local_ipv4_port().unwrap_or(0);
|
let local_port = context.main_local_ipv4_port().unwrap_or(0);
|
||||||
let local_ipv4_addr = nat::local_ipv4_addr(local_port);
|
let local_ipv4_addr = nat::local_ipv4_addr(local_port);
|
||||||
|
|||||||
@@ -65,9 +65,10 @@ async fn start0(
|
|||||||
let dest_addr = *entry.value();
|
let dest_addr = *entry.value();
|
||||||
drop(entry);
|
drop(entry);
|
||||||
//先使用相同的端口,冲突了再随机端口
|
//先使用相同的端口,冲突了再随机端口
|
||||||
let peer_udp_socket = match UdpSocket::bind(format!("0.0.0.0:{}", sender_addr.port())).await {
|
let peer_udp_socket = match UdpSocket::bind(format!("0.0.0.0:{}", sender_addr.port())).await
|
||||||
Ok(udp) => { udp }
|
{
|
||||||
Err(_) => { UdpSocket::bind("0.0.0.0:0").await? }
|
Ok(udp) => udp,
|
||||||
|
Err(_) => UdpSocket::bind("0.0.0.0:0").await?,
|
||||||
};
|
};
|
||||||
peer_udp_socket.connect(dest_addr).await?;
|
peer_udp_socket.connect(dest_addr).await?;
|
||||||
peer_udp_socket.send(buf).await?;
|
peer_udp_socket.send(buf).await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user