mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-06 17:59:11 +00:00
refactor: handle quic proxy internally instead of use external udp port (#1743)
* deprecate quic_listen_port, add disable_relay_quic and enable_relay_foreign_network_quic * add set_src_modified to TcpProxyForWrappedSrcTrait * prioritize quic over kcp
This commit is contained in:
@@ -31,7 +31,7 @@ use crate::gateway::icmp_proxy::IcmpProxy;
|
||||
#[cfg(feature = "kcp")]
|
||||
use crate::gateway::kcp_proxy::{KcpProxyDst, KcpProxyDstRpcService, KcpProxySrc};
|
||||
#[cfg(feature = "quic")]
|
||||
use crate::gateway::quic_proxy::{QUICProxyDst, QUICProxyDstRpcService, QUICProxySrc};
|
||||
use crate::gateway::quic_proxy::{QuicProxy, QuicProxyDstRpcService};
|
||||
use crate::gateway::tcp_proxy::{NatDstTcpConnector, TcpProxy, TcpProxyRpcService};
|
||||
use crate::gateway::udp_proxy::UdpProxy;
|
||||
use crate::peer_center::instance::PeerCenterInstance;
|
||||
@@ -541,9 +541,7 @@ pub struct Instance {
|
||||
kcp_proxy_dst: Option<KcpProxyDst>,
|
||||
|
||||
#[cfg(feature = "quic")]
|
||||
quic_proxy_src: Option<QUICProxySrc>,
|
||||
#[cfg(feature = "quic")]
|
||||
quic_proxy_dst: Option<QUICProxyDst>,
|
||||
quic_proxy: Option<QuicProxy>,
|
||||
|
||||
peer_center: Arc<PeerCenterInstance>,
|
||||
|
||||
@@ -627,9 +625,7 @@ impl Instance {
|
||||
kcp_proxy_dst: None,
|
||||
|
||||
#[cfg(feature = "quic")]
|
||||
quic_proxy_src: None,
|
||||
#[cfg(feature = "quic")]
|
||||
quic_proxy_dst: None,
|
||||
quic_proxy: None,
|
||||
|
||||
peer_center,
|
||||
|
||||
@@ -927,21 +923,6 @@ impl Instance {
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(feature = "quic")]
|
||||
async fn run_quic_dst(&mut self) -> Result<(), Error> {
|
||||
if self.global_ctx.get_flags().disable_quic_input {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let route = Arc::new(self.peer_manager.get_route());
|
||||
let quic_dst = QUICProxyDst::new(self.global_ctx.clone(), route)?;
|
||||
quic_dst.start().await?;
|
||||
self.global_ctx
|
||||
.set_quic_proxy_port(Some(quic_dst.local_addr()?.port()));
|
||||
self.quic_proxy_dst = Some(quic_dst);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn run(&mut self) -> Result<(), Error> {
|
||||
self.listener_manager
|
||||
.lock()
|
||||
@@ -982,19 +963,13 @@ impl Instance {
|
||||
}
|
||||
|
||||
#[cfg(feature = "quic")]
|
||||
if self.global_ctx.get_flags().enable_quic_proxy {
|
||||
let quic_src = QUICProxySrc::new(self.get_peer_manager()).await;
|
||||
quic_src.start().await;
|
||||
self.quic_proxy_src = Some(quic_src);
|
||||
}
|
||||
|
||||
#[cfg(feature = "quic")]
|
||||
if !self.global_ctx.get_flags().disable_quic_input {
|
||||
if let Err(e) = self.run_quic_dst().await {
|
||||
eprintln!(
|
||||
"quic input start failed: {:?} (some platforms may not support)",
|
||||
e
|
||||
);
|
||||
{
|
||||
let quic_src = self.global_ctx.get_flags().enable_quic_proxy;
|
||||
let quic_dst = !self.global_ctx.get_flags().disable_quic_input;
|
||||
if quic_src || quic_dst {
|
||||
let mut quic_proxy = QuicProxy::new(self.get_peer_manager());
|
||||
quic_proxy.run(quic_src, quic_dst).await;
|
||||
self.quic_proxy = Some(quic_proxy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1423,19 +1398,20 @@ impl Instance {
|
||||
}
|
||||
|
||||
#[cfg(feature = "quic")]
|
||||
if let Some(quic_proxy) = self.quic_proxy_src.as_ref() {
|
||||
tcp_proxy_rpc_services.insert(
|
||||
"quic_src".to_string(),
|
||||
Arc::new(TcpProxyRpcService::new(quic_proxy.get_tcp_proxy())),
|
||||
);
|
||||
}
|
||||
if let Some(quic_proxy) = self.quic_proxy.as_ref() {
|
||||
if let Some(quic_src) = quic_proxy.src() {
|
||||
tcp_proxy_rpc_services.insert(
|
||||
"quic_src".to_string(),
|
||||
Arc::new(TcpProxyRpcService::new(quic_src.get_tcp_proxy())),
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "quic")]
|
||||
if let Some(quic_proxy) = self.quic_proxy_dst.as_ref() {
|
||||
tcp_proxy_rpc_services.insert(
|
||||
"quic_dst".to_string(),
|
||||
Arc::new(QUICProxyDstRpcService::new(quic_proxy)),
|
||||
);
|
||||
if let Some(quic_dst) = quic_proxy.dst() {
|
||||
tcp_proxy_rpc_services.insert(
|
||||
"quic_dst".to_string(),
|
||||
Arc::new(QuicProxyDstRpcService::new(quic_dst)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
tcp_proxy_rpc_services
|
||||
|
||||
Reference in New Issue
Block a user