mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 10:14:35 +00:00
optimize the condition of enabling kcp (#1210)
This commit is contained in:
@@ -163,6 +163,10 @@ impl ForeignNetworkEntry {
|
||||
config.set_network_identity(network.clone());
|
||||
config.set_hostname(Some(format!("PublicServer_{}", global_ctx.get_hostname())));
|
||||
|
||||
let mut flags = config.get_flags();
|
||||
flags.disable_relay_kcp = !global_ctx.get_flags().enable_relay_foreign_network_kcp;
|
||||
config.set_flags(flags);
|
||||
|
||||
let foreign_global_ctx = Arc::new(GlobalCtx::new(config));
|
||||
foreign_global_ctx
|
||||
.replace_stun_info_collector(Box::new(global_ctx.get_stun_info_collector().clone()));
|
||||
|
||||
@@ -1360,6 +1360,38 @@ impl PeerManager {
|
||||
tracing::info!("close_peer_conn in foreign network manager done: {:?}", ret);
|
||||
ret
|
||||
}
|
||||
|
||||
pub async fn check_allow_kcp_to_dst(&self, dst_ip: &IpAddr) -> bool {
|
||||
let route = self.get_route();
|
||||
let Some(dst_peer_id) = route.get_peer_id_by_ip(dst_ip).await else {
|
||||
return false;
|
||||
};
|
||||
let Some(peer_info) = route.get_peer_info(dst_peer_id).await else {
|
||||
return false;
|
||||
};
|
||||
|
||||
// check dst allow kcp input
|
||||
if !peer_info.feature_flag.map(|x| x.kcp_input).unwrap_or(false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let next_hop_policy = Self::get_next_hop_policy( self.global_ctx.get_flags().latency_first);
|
||||
// check relay node allow relay kcp.
|
||||
let Some(next_hop_id) = route.get_next_hop_with_policy(dst_peer_id, next_hop_policy).await else {
|
||||
return false;
|
||||
};
|
||||
|
||||
let Some(next_hop_info) = route.get_peer_info(next_hop_id).await else {
|
||||
return false;
|
||||
};
|
||||
|
||||
// check next hop allow kcp relay
|
||||
if next_hop_info.feature_flag.map(|x| x.no_relay_kcp).unwrap_or(false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -86,6 +86,13 @@ pub trait Route {
|
||||
None
|
||||
}
|
||||
|
||||
async fn get_peer_id_by_ip(&self, ip: &std::net::IpAddr) -> Option<PeerId> {
|
||||
match ip {
|
||||
std::net::IpAddr::V4(v4) => self.get_peer_id_by_ipv4(v4).await,
|
||||
std::net::IpAddr::V6(v6) => self.get_peer_id_by_ipv6(v6).await,
|
||||
}
|
||||
}
|
||||
|
||||
async fn list_peers_own_foreign_network(
|
||||
&self,
|
||||
_network_identity: &NetworkIdentity,
|
||||
|
||||
Reference in New Issue
Block a user