From 6964fb71fc56d39c790eae9530da3a72b03b016f Mon Sep 17 00:00:00 2001 From: 3RDNature <162092918+3RDNature@users.noreply.github.com> Date: Thu, 29 Aug 2024 11:34:30 +0800 Subject: [PATCH] Add a setting "disable_udp_hole_punch" to disable UDP hole punch function (#291) It can solve #289 tentative. Co-authored-by: 3rdnature --- easytier/locales/app.yml | 3 +++ easytier/src/common/config.rs | 2 ++ easytier/src/connector/udp_hole_punch.rs | 3 +++ easytier/src/easytier-core.rs | 7 +++++++ 4 files changed, 15 insertions(+) diff --git a/easytier/locales/app.yml b/easytier/locales/app.yml index 19cda434..20cb6ab9 100644 --- a/easytier/locales/app.yml +++ b/easytier/locales/app.yml @@ -108,6 +108,9 @@ core_clap: disable_p2p: en: "disable p2p communication, will only relay packets with peers specified by --peers" zh-CN: "禁用P2P通信,只通过--peers指定的节点转发数据包" + disable_udp_hole_punching: + en: "disable udp hole punching" + zh-CN: "禁用UDP打洞功能" relay_all_peer_rpc: en: "relay all peer rpc packets, even if the peer is not in the relay network whitelist. this can help peers not in relay network whitelist to establish p2p connection." zh-CN: "转发所有对等节点的RPC数据包,即使对等节点不在转发网络白名单中。这可以帮助白名单外网络中的对等节点建立P2P连接。" diff --git a/easytier/src/common/config.rs b/easytier/src/common/config.rs index fc68d8f5..40266fbe 100644 --- a/easytier/src/common/config.rs +++ b/easytier/src/common/config.rs @@ -178,6 +178,8 @@ pub struct Flags { pub disable_p2p: bool, #[derivative(Default(value = "false"))] pub relay_all_peer_rpc: bool, + #[derivative(Default(value = "false"))] + pub disable_udp_hole_punching: bool, } #[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] diff --git a/easytier/src/connector/udp_hole_punch.rs b/easytier/src/connector/udp_hole_punch.rs index 3970b4b0..caa8b43b 100644 --- a/easytier/src/connector/udp_hole_punch.rs +++ b/easytier/src/connector/udp_hole_punch.rs @@ -605,6 +605,9 @@ impl UdpHolePunchConnector { if self.data.global_ctx.get_flags().disable_p2p { return Ok(()); } + if self.data.global_ctx.get_flags().disable_udp_hole_punching { + return Ok(()); + } self.run_as_client().await?; self.run_as_server().await?; diff --git a/easytier/src/easytier-core.rs b/easytier/src/easytier-core.rs index e5f735cd..b1f0eeaf 100644 --- a/easytier/src/easytier-core.rs +++ b/easytier/src/easytier-core.rs @@ -266,6 +266,13 @@ struct Cli { )] disable_p2p: bool, + #[arg( + long, + help = t!("core_clap.disable_udp_hole_punching").to_string(), + default_value = "false" + )] + disable_udp_hole_punching: bool, + #[arg( long, help = t!("core_clap.relay_all_peer_rpc").to_string(),