mirror of
https://github.com/EasyTier/astral.git
synced 2025-05-19 10:30:24 +00:00
修复延迟检测问题 更新逻辑不正确 若干体验上问题
This commit is contained in:
+13
-1
@@ -292,6 +292,7 @@ pub struct KVNodeInfo {
|
||||
pub ipv4: String,
|
||||
pub latency_ms: f64,
|
||||
pub nat: String, // NAT类型
|
||||
pub loss_rate: f32,
|
||||
pub connections: Vec<KVNodeConnectionStats>,
|
||||
pub version: String,
|
||||
pub cost: i32,
|
||||
@@ -330,7 +331,6 @@ pub fn get_network_status() -> KVNetworkStatus {
|
||||
hostname: route.hostname.clone(),
|
||||
ipv4,
|
||||
latency_ms: if let Some(peer) = &pair.peer {
|
||||
// 类似cli.rs中的get_latency_ms方法
|
||||
let mut min_latency = u64::MAX;
|
||||
for conn in &peer.conns {
|
||||
if let Some(stats) = &conn.stats {
|
||||
@@ -348,6 +348,15 @@ pub fn get_network_status() -> KVNetworkStatus {
|
||||
// 如果没有peer信息,则使用路由路径延迟
|
||||
f64::from(route.path_latency.max(0)) / 1000.0
|
||||
},
|
||||
loss_rate: if let Some(peer) = &pair.peer {
|
||||
let mut total_loss_rate = 0.0;
|
||||
for conn in &peer.conns {
|
||||
total_loss_rate += conn.loss_rate;
|
||||
}
|
||||
total_loss_rate
|
||||
} else {
|
||||
0.0 // 如果没有连接信息,默认为0
|
||||
},
|
||||
nat: route.stun_info.as_ref().map_or_else(
|
||||
|| "Unknown".to_string(),
|
||||
|stun| {
|
||||
@@ -571,6 +580,9 @@ pub fn create_server(
|
||||
let cfg = create_config();
|
||||
cfg.set_hostname(Option::from(username));
|
||||
cfg.set_dhcp(enable_dhcp);
|
||||
let mut flags = cfg.get_flags();
|
||||
flags.dev_name = "Astral".to_string();
|
||||
cfg.set_flags(flags);
|
||||
let peer_config = PeerConfig {
|
||||
uri: ("tcp://".to_string() + &severurl).parse().unwrap(),
|
||||
};
|
||||
|
||||
@@ -496,6 +496,13 @@ impl SseDecode for bool {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for f32 {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
deserializer.cursor.read_f32::<NativeEndian>().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for f64 {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@@ -547,6 +554,7 @@ impl SseDecode for crate::api::simple::KVNodeInfo {
|
||||
let mut var_ipv4 = <String>::sse_decode(deserializer);
|
||||
let mut var_latencyMs = <f64>::sse_decode(deserializer);
|
||||
let mut var_nat = <String>::sse_decode(deserializer);
|
||||
let mut var_lossRate = <f32>::sse_decode(deserializer);
|
||||
let mut var_connections =
|
||||
<Vec<crate::api::simple::KVNodeConnectionStats>>::sse_decode(deserializer);
|
||||
let mut var_version = <String>::sse_decode(deserializer);
|
||||
@@ -556,6 +564,7 @@ impl SseDecode for crate::api::simple::KVNodeInfo {
|
||||
ipv4: var_ipv4,
|
||||
latency_ms: var_latencyMs,
|
||||
nat: var_nat,
|
||||
loss_rate: var_lossRate,
|
||||
connections: var_connections,
|
||||
version: var_version,
|
||||
cost: var_cost,
|
||||
@@ -822,6 +831,7 @@ impl flutter_rust_bridge::IntoDart for crate::api::simple::KVNodeInfo {
|
||||
self.ipv4.into_into_dart().into_dart(),
|
||||
self.latency_ms.into_into_dart().into_dart(),
|
||||
self.nat.into_into_dart().into_dart(),
|
||||
self.loss_rate.into_into_dart().into_dart(),
|
||||
self.connections.into_into_dart().into_dart(),
|
||||
self.version.into_into_dart().into_dart(),
|
||||
self.cost.into_into_dart().into_dart(),
|
||||
@@ -928,6 +938,13 @@ impl SseEncode for bool {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for f32 {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
serializer.cursor.write_f32::<NativeEndian>(self).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for f64 {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
@@ -968,6 +985,7 @@ impl SseEncode for crate::api::simple::KVNodeInfo {
|
||||
<String>::sse_encode(self.ipv4, serializer);
|
||||
<f64>::sse_encode(self.latency_ms, serializer);
|
||||
<String>::sse_encode(self.nat, serializer);
|
||||
<f32>::sse_encode(self.loss_rate, serializer);
|
||||
<Vec<crate::api::simple::KVNodeConnectionStats>>::sse_encode(self.connections, serializer);
|
||||
<String>::sse_encode(self.version, serializer);
|
||||
<i32>::sse_encode(self.cost, serializer);
|
||||
|
||||
Reference in New Issue
Block a user