mirror of
https://github.com/EasyTier/EasyTier.git
synced 2024-11-16 03:32:43 +08:00
fix udp proxy not work when being exit node (#133)
This commit is contained in:
parent
6e77e6b5e7
commit
b43c078152
|
@ -63,6 +63,8 @@ pub struct GlobalCtx {
|
||||||
stun_info_collection: Box<dyn StunInfoCollectorTrait>,
|
stun_info_collection: Box<dyn StunInfoCollectorTrait>,
|
||||||
|
|
||||||
running_listeners: Mutex<Vec<url::Url>>,
|
running_listeners: Mutex<Vec<url::Url>>,
|
||||||
|
|
||||||
|
enable_exit_node: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for GlobalCtx {
|
impl std::fmt::Debug for GlobalCtx {
|
||||||
|
@ -90,6 +92,8 @@ impl GlobalCtx {
|
||||||
|
|
||||||
let stun_info_collection = Arc::new(StunInfoCollector::new_with_default_servers());
|
let stun_info_collection = Arc::new(StunInfoCollector::new_with_default_servers());
|
||||||
|
|
||||||
|
let enable_exit_node = config_fs.get_flags().enable_exit_node;
|
||||||
|
|
||||||
GlobalCtx {
|
GlobalCtx {
|
||||||
inst_name: config_fs.get_inst_name(),
|
inst_name: config_fs.get_inst_name(),
|
||||||
id,
|
id,
|
||||||
|
@ -108,6 +112,8 @@ impl GlobalCtx {
|
||||||
stun_info_collection: Box::new(stun_info_collection),
|
stun_info_collection: Box::new(stun_info_collection),
|
||||||
|
|
||||||
running_listeners: Mutex::new(Vec::new()),
|
running_listeners: Mutex::new(Vec::new()),
|
||||||
|
|
||||||
|
enable_exit_node,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,6 +230,10 @@ impl GlobalCtx {
|
||||||
hasher.write(&key[0..16]);
|
hasher.write(&key[0..16]);
|
||||||
key
|
key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn enable_exit_node(&self) -> bool {
|
||||||
|
self.enable_exit_node
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -246,6 +246,10 @@ impl IcmpProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn try_handle_peer_packet(&self, packet: &ZCPacket) -> Option<()> {
|
async fn try_handle_peer_packet(&self, packet: &ZCPacket) -> Option<()> {
|
||||||
|
if self.cidr_set.is_empty() && !self.global_ctx.enable_exit_node() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let _ = self.global_ctx.get_ipv4()?;
|
let _ = self.global_ctx.get_ipv4()?;
|
||||||
let hdr = packet.peer_manager_header().unwrap();
|
let hdr = packet.peer_manager_header().unwrap();
|
||||||
let is_exit_node = hdr.is_exit_node();
|
let is_exit_node = hdr.is_exit_node();
|
||||||
|
|
|
@ -356,6 +356,10 @@ impl TcpProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn try_handle_peer_packet(&self, packet: &mut ZCPacket) -> Option<()> {
|
async fn try_handle_peer_packet(&self, packet: &mut ZCPacket) -> Option<()> {
|
||||||
|
if self.cidr_set.is_empty() && !self.global_ctx.enable_exit_node() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let ipv4_addr = self.global_ctx.get_ipv4()?;
|
let ipv4_addr = self.global_ctx.get_ipv4()?;
|
||||||
let hdr = packet.peer_manager_header().unwrap();
|
let hdr = packet.peer_manager_header().unwrap();
|
||||||
let is_exit_node = hdr.is_exit_node();
|
let is_exit_node = hdr.is_exit_node();
|
||||||
|
|
|
@ -227,7 +227,7 @@ pub struct UdpProxy {
|
||||||
|
|
||||||
impl UdpProxy {
|
impl UdpProxy {
|
||||||
async fn try_handle_packet(&self, packet: &ZCPacket) -> Option<()> {
|
async fn try_handle_packet(&self, packet: &ZCPacket) -> Option<()> {
|
||||||
if self.cidr_set.is_empty() {
|
if self.cidr_set.is_empty() && !self.global_ctx.enable_exit_node() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user