use std::{
collections::HashMap,
net::SocketAddr,
time::{Duration, SystemTime, UNIX_EPOCH},
};
use ed25519_dalek::VerifyingKey;
use isocountry::CountryCode;
use language_tags::LanguageTag;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct ExitDescriptor {
pub c2e_listen: SocketAddr,
pub b2e_listen: SocketAddr,
pub country: CountryCode,
pub city: String,
pub load: f32,
pub expiry: u64,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ExitList {
pub all_exits: Vec<(VerifyingKey, ExitDescriptor)>,
pub city_names: HashMap<String, HashMap<LanguageTag, String>>,
}
impl ExitList {
pub fn expiry(&self) -> SystemTime {
UNIX_EPOCH
+ Duration::from_secs(
self.all_exits
.iter()
.map(|exit| exit.1.expiry)
.min()
.unwrap_or_default(),
)
}
}