优化延迟优先参数

This commit is contained in:
lubeilin
2023-12-28 23:18:57 +08:00
parent 94d6caef7e
commit 16f833ec72
2 changed files with 16 additions and 9 deletions
+14 -7
View File
@@ -86,6 +86,9 @@ impl Context {
pub fn is_main_tcp(&self) -> bool {
self.inner.main_tcp_channel.is_some()
}
pub fn is_first_latency(&self) -> bool {
self.inner.first_latency
}
pub fn switch(&self, nat_type: NatType) {
match nat_type {
NatType::Symmetric => {
@@ -242,8 +245,8 @@ impl Context {
.or_insert_with(|| Vec::with_capacity(4));
let mut exist = false;
for (x, time) in list.iter_mut() {
if x.metric < route.metric {
//不能比当前的路径更长
if x.metric < route.metric && !self.inner.first_latency {
//非优先延迟的情况下 不能比当前的路径更长
return;
}
if x.route_key() == key {
@@ -260,12 +263,16 @@ impl Context {
if exist {
list.sort_by_key(|(k, _)| k.rt);
} else {
if route.metric == 1 && !self.inner.first_latency {
//非优先延迟的情况下 添加了直连的则排除非直连的
list.retain(|(k, _)| k.metric == 1);
}
let max_len = if self.inner.first_latency {
self.inner.channel_num + 1
} else {
if route.metric == 1 {
//非优先延迟的情况下 添加了直连的则排除非直连的
list.retain(|(k, _)| k.metric == 1);
}
self.inner.channel_num
};
list.sort_by_key(|(k, _)| k.rt);
let max_len = self.inner.channel_num;
if list.len() > max_len {
list.truncate(max_len);
}
+2 -2
View File
@@ -201,7 +201,7 @@ async fn start_heartbeat_(
let src = current_dev.virtual_ip();
if count < 7 || count % 7 == 0 {
if count % 10 == 7 {
let mut route_list: Option<Vec<(Ipv4Addr, Vec<Route>)>> = None;
let peer_list = { device_list.lock().1.clone() };
for peer in peer_list {
@@ -223,7 +223,7 @@ async fn start_heartbeat_(
{
log::warn!("virtual_ip:{},route:{:?},e:{:?}", peer.virtual_ip, route, e);
}
if route.is_p2p() {
if route.is_p2p() && !sender.is_first_latency() {
continue;
}
} else {