use std::time::SystemTime;
use scion_proto::path::{DataPlanePathFingerprint, Path};
use crate::path::manager::reliability::ReliabilityScore;
#[derive(Debug)]
pub struct PathManagerPath {
pub path: Path,
pub fingerprint: DataPlanePathFingerprint,
pub reliability: ReliabilityScore,
}
impl PathManagerPath {
pub fn new(path: Path) -> Self {
let fingerprint = path.data_plane_fingerprint();
Self {
path,
fingerprint,
reliability: ReliabilityScore::new_with_time(SystemTime::now()),
}
}
pub fn scion_path(&self) -> &Path {
&self.path
}
}
impl From<&Path> for PathManagerPath {
fn from(path: &Path) -> Self {
Self::new(path.clone())
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Score(f32);
impl Eq for Score {}
impl Ord for Score {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.0
.partial_cmp(&other.0)
.unwrap_or(std::cmp::Ordering::Equal)
}
}
impl PartialOrd for Score {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Score {
pub fn new_clamped(value: f32) -> Self {
let value = match value.is_nan() {
true => 0.0,
false => value,
};
Score(value.clamp(-1.0, 1.0))
}
pub fn value(&self) -> f32 {
self.0
}
}