optimize the condition of enabling kcp (#1210)

This commit is contained in:
Sijie.Sun
2025-08-09 16:16:09 +08:00
committed by GitHub
parent 37b24164b6
commit 8ffc2f12e4
11 changed files with 110 additions and 18 deletions

View File

@@ -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)]