use std::{
net::{
IpAddr,
SocketAddr,
},
time::Duration,
};
use crate::{
CasRef,
Error,
};
pub(super) const DEFAULT_RECONNECT_DELAY: Duration = Duration::from_secs(5);
pub(super) const DEFAULT_RESPONSE_TIMEOUT: Duration = Duration::from_secs(5);
pub(super) const DEFAULT_IDLE_PROBE_INTERVAL: Duration = Duration::from_secs(30);
#[derive(Clone, Debug, PartialEq)]
pub struct CasConfig {
pub id: String,
pub name: String,
pub super_cas_id: u32,
pub first_stream_id: u16,
pub ecmg: EcmgConfig,
pub emmg: Option<EmmgConfig>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct EcmgConfig {
pub channel_id: u16,
pub addr: SocketAddr,
pub reconnect_delay: Duration,
pub response_timeout: Duration,
pub idle_probe_interval: Duration,
}
impl EcmgConfig {
pub fn new(channel_id: u16, addr: SocketAddr) -> Self {
Self {
channel_id,
addr,
reconnect_delay: DEFAULT_RECONNECT_DELAY,
response_timeout: DEFAULT_RESPONSE_TIMEOUT,
idle_probe_interval: DEFAULT_IDLE_PROBE_INTERVAL,
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct EmmgConfig {
pub bind: IpAddr,
pub port: u16,
pub udp: bool,
pub broadcast: bool,
}
impl EmmgConfig {
#[must_use]
pub fn new(port: u16) -> Self {
Self {
bind: IpAddr::from([0, 0, 0, 0]),
port,
udp: false,
broadcast: false,
}
}
}
#[derive(Clone, Debug)]
pub struct ServiceConfig {
pub name: String,
pub crypto_period: Duration,
pub cas: Vec<ServiceCas>,
}
impl ServiceConfig {
pub(super) fn nominal_cp_duration(&self) -> Result<u16, Error> {
let hundred_ms = self.crypto_period.as_millis() / 100;
u16::try_from(hundred_ms).map_err(|_| Error::InvalidCryptoPeriod {
crypto_period: self.crypto_period,
})
}
}
#[derive(Clone, Debug)]
pub struct ServiceCas {
pub cas: CasRef,
pub ecm_pid: u16,
pub access_criteria: Vec<u8>,
}