use crate::core::{ChannelId, MessageId, PacketNumber};
use crate::reliability::{ChannelReliability, ReliabilityMode};
pub const MAX_WIRE_BYTES: usize = 128;
pub const MAX_INGRESS_BYTES: usize = MAX_WIRE_BYTES * MAX_EVENTS;
pub const MAX_MESSAGE_BYTES: usize = 256;
pub const MAX_EVENTS: usize = 16;
pub const MAX_IN_FLIGHT_PACKETS: usize = 16;
pub const MAX_ACK_TRACKED_PACKETS: usize = 16;
pub const MAX_REASSEMBLY_MESSAGES: usize = 4;
pub const MAX_CHANNEL_POLICIES: usize = 4;
pub const MAX_CHANNEL_SPECS: usize = 4;
pub const DEFAULT_FRAGMENT_BYTES: usize = 32;
pub const DEFAULT_MAX_RETRANSMIT_ATTEMPTS: u8 = 5;
pub const DEFAULT_RETRANSMIT_TIMEOUT_MS: u64 = 250;
pub const DEFAULT_REASSEMBLY_TIMEOUT_MS: u64 = 2_000;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ChannelProfile {
Data,
Log,
}
impl ChannelProfile {
#[must_use]
pub const fn default_for(channel_id: ChannelId) -> Self {
if channel_id.is_log() {
Self::Log
} else {
Self::Data
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ChannelSpec {
pub channel_id: ChannelId,
pub profile: ChannelProfile,
pub reliability_mode: ReliabilityMode,
}
impl ChannelSpec {
#[must_use]
pub const fn new(
channel_id: ChannelId,
profile: ChannelProfile,
reliability_mode: ReliabilityMode,
) -> Self {
Self {
channel_id,
profile,
reliability_mode,
}
}
#[must_use]
pub const fn data(channel_id: ChannelId) -> Self {
Self::new(channel_id, ChannelProfile::Data, ReliabilityMode::Reliable)
}
#[must_use]
pub const fn log(channel_id: ChannelId) -> Self {
Self::new(channel_id, ChannelProfile::Log, ReliabilityMode::BestEffort)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct EngineConfig {
pub initial_packet_number: PacketNumber,
pub initial_message_id: MessageId,
pub fragment_bytes: usize,
pub max_retransmit_attempts: u8,
pub retransmit_timeout_ms: u64,
pub reassembly_timeout_ms: u64,
pub channel_specs: [Option<ChannelSpec>; MAX_CHANNEL_SPECS],
pub channel_policies: [Option<ChannelReliability>; MAX_CHANNEL_POLICIES],
}
impl Default for EngineConfig {
fn default() -> Self {
Self {
initial_packet_number: PacketNumber::ZERO,
initial_message_id: MessageId::ZERO,
fragment_bytes: DEFAULT_FRAGMENT_BYTES,
max_retransmit_attempts: DEFAULT_MAX_RETRANSMIT_ATTEMPTS,
retransmit_timeout_ms: DEFAULT_RETRANSMIT_TIMEOUT_MS,
reassembly_timeout_ms: DEFAULT_REASSEMBLY_TIMEOUT_MS,
channel_specs: [None; MAX_CHANNEL_SPECS],
channel_policies: [None; MAX_CHANNEL_POLICIES],
}
}
}