优化延迟优先参数
This commit is contained in:
@@ -86,6 +86,9 @@ impl Context {
|
|||||||
pub fn is_main_tcp(&self) -> bool {
|
pub fn is_main_tcp(&self) -> bool {
|
||||||
self.inner.main_tcp_channel.is_some()
|
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) {
|
pub fn switch(&self, nat_type: NatType) {
|
||||||
match nat_type {
|
match nat_type {
|
||||||
NatType::Symmetric => {
|
NatType::Symmetric => {
|
||||||
@@ -242,8 +245,8 @@ impl Context {
|
|||||||
.or_insert_with(|| Vec::with_capacity(4));
|
.or_insert_with(|| Vec::with_capacity(4));
|
||||||
let mut exist = false;
|
let mut exist = false;
|
||||||
for (x, time) in list.iter_mut() {
|
for (x, time) in list.iter_mut() {
|
||||||
if x.metric < route.metric {
|
if x.metric < route.metric && !self.inner.first_latency {
|
||||||
//不能比当前的路径更长
|
//非优先延迟的情况下 不能比当前的路径更长
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if x.route_key() == key {
|
if x.route_key() == key {
|
||||||
@@ -260,12 +263,16 @@ impl Context {
|
|||||||
if exist {
|
if exist {
|
||||||
list.sort_by_key(|(k, _)| k.rt);
|
list.sort_by_key(|(k, _)| k.rt);
|
||||||
} else {
|
} else {
|
||||||
if route.metric == 1 && !self.inner.first_latency {
|
let max_len = if self.inner.first_latency {
|
||||||
//非优先延迟的情况下 添加了直连的则排除非直连的
|
self.inner.channel_num + 1
|
||||||
list.retain(|(k, _)| k.metric == 1);
|
} else {
|
||||||
}
|
if route.metric == 1 {
|
||||||
|
//非优先延迟的情况下 添加了直连的则排除非直连的
|
||||||
|
list.retain(|(k, _)| k.metric == 1);
|
||||||
|
}
|
||||||
|
self.inner.channel_num
|
||||||
|
};
|
||||||
list.sort_by_key(|(k, _)| k.rt);
|
list.sort_by_key(|(k, _)| k.rt);
|
||||||
let max_len = self.inner.channel_num;
|
|
||||||
if list.len() > max_len {
|
if list.len() > max_len {
|
||||||
list.truncate(max_len);
|
list.truncate(max_len);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ async fn start_heartbeat_(
|
|||||||
|
|
||||||
let src = current_dev.virtual_ip();
|
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 mut route_list: Option<Vec<(Ipv4Addr, Vec<Route>)>> = None;
|
||||||
let peer_list = { device_list.lock().1.clone() };
|
let peer_list = { device_list.lock().1.clone() };
|
||||||
for peer in peer_list {
|
for peer in peer_list {
|
||||||
@@ -223,7 +223,7 @@ async fn start_heartbeat_(
|
|||||||
{
|
{
|
||||||
log::warn!("virtual_ip:{},route:{:?},e:{:?}", peer.virtual_ip, route, e);
|
log::warn!("virtual_ip:{},route:{:?},e:{:?}", peer.virtual_ip, route, e);
|
||||||
}
|
}
|
||||||
if route.is_p2p() {
|
if route.is_p2p() && !sender.is_first_latency() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user