mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 10:14:35 +00:00
fix peer center for latency report
This commit is contained in:
@@ -5,24 +5,6 @@ use crate::{common::PeerId, rpc::DirectConnectedPeerInfo};
|
||||
use super::{Digest, Error};
|
||||
use crate::rpc::PeerInfo;
|
||||
|
||||
pub type LatencyLevel = crate::rpc::cli::LatencyLevel;
|
||||
|
||||
impl LatencyLevel {
|
||||
pub const fn from_latency_ms(lat_ms: u32) -> Self {
|
||||
if lat_ms < 10 {
|
||||
LatencyLevel::VeryLow
|
||||
} else if lat_ms < 50 {
|
||||
LatencyLevel::Low
|
||||
} else if lat_ms < 100 {
|
||||
LatencyLevel::Normal
|
||||
} else if lat_ms < 200 {
|
||||
LatencyLevel::High
|
||||
} else {
|
||||
LatencyLevel::VeryHigh
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type PeerInfoForGlobalMap = crate::rpc::cli::PeerInfoForGlobalMap;
|
||||
|
||||
impl From<Vec<PeerInfo>> for PeerInfoForGlobalMap {
|
||||
@@ -34,10 +16,10 @@ impl From<Vec<PeerInfo>> for PeerInfoForGlobalMap {
|
||||
.iter()
|
||||
.map(|conn| conn.stats.as_ref().unwrap().latency_us)
|
||||
.min()
|
||||
.unwrap_or(0);
|
||||
.unwrap_or(u32::MAX as u64);
|
||||
|
||||
let dp_info = DirectConnectedPeerInfo {
|
||||
latency_level: LatencyLevel::from_latency_ms(min_lat as u32 / 1000) as i32,
|
||||
latency_ms: std::cmp::max(1, (min_lat as u32 / 1000) as i32),
|
||||
};
|
||||
|
||||
// sort conn info so hash result is stable
|
||||
@@ -73,11 +55,7 @@ pub struct GetGlobalPeerMapResponse {
|
||||
pub trait PeerCenterService {
|
||||
// report center server which peer is directly connected to me
|
||||
// digest is a hash of current peer map, if digest not match, we need to transfer the whole map
|
||||
async fn report_peers(
|
||||
my_peer_id: PeerId,
|
||||
peers: Option<PeerInfoForGlobalMap>,
|
||||
digest: Digest,
|
||||
) -> Result<(), Error>;
|
||||
async fn report_peers(my_peer_id: PeerId, peers: PeerInfoForGlobalMap) -> Result<(), Error>;
|
||||
|
||||
async fn get_global_peer_map(digest: Digest)
|
||||
-> Result<Option<GetGlobalPeerMapResponse>, Error>;
|
||||
|
||||
Reference in New Issue
Block a user