use crate::{
connection::Limits,
event::{
api::{EndpointType, SocketAddress},
IntoEvent as _,
},
inet,
transport::parameters::{DcSupportedVersions, InitialFlowControlLimits},
varint::VarInt,
};
use core::time::Duration;
mod disabled;
mod traits;
#[cfg(any(test, feature = "testing"))]
pub mod testing;
pub use disabled::*;
pub use traits::*;
pub type Version = u32;
pub const SUPPORTED_VERSIONS: [Version; 1] = [0x0];
pub fn select_version(client_supported_versions: DcSupportedVersions) -> Option<Version> {
let client_supported_versions = client_supported_versions.into_iter().as_slice();
SUPPORTED_VERSIONS
.iter()
.find(|&supported_version| client_supported_versions.contains(supported_version))
.copied()
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct ConnectionInfo<'a> {
pub remote_address: SocketAddress<'a>,
pub dc_version: u32,
pub application_params: ApplicationParams,
pub endpoint_type: EndpointType,
}
impl<'a> ConnectionInfo<'a> {
#[inline]
#[doc(hidden)]
pub fn new(
remote_address: &'a inet::SocketAddress,
dc_version: Version,
application_params: ApplicationParams,
endpoint_type: EndpointType,
) -> Self {
Self {
remote_address: remote_address.into_event(),
dc_version,
application_params,
endpoint_type,
}
}
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct DatagramInfo<'a> {
pub remote_address: SocketAddress<'a>,
}
impl<'a> DatagramInfo<'a> {
#[inline]
#[doc(hidden)]
pub fn new(remote_address: &'a inet::SocketAddress) -> Self {
Self {
remote_address: remote_address.into_event(),
}
}
}
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub struct ApplicationParams {
pub max_datagram_size: u16,
pub remote_max_data: VarInt,
pub local_send_max_data: VarInt,
pub local_recv_max_data: VarInt,
pub max_idle_timeout: Option<Duration>,
pub max_ack_delay: Duration,
}
impl ApplicationParams {
pub fn new(
max_datagram_size: u16,
peer_flow_control_limits: &InitialFlowControlLimits,
limits: &Limits,
) -> Self {
Self {
max_datagram_size,
remote_max_data: peer_flow_control_limits.max_data,
local_send_max_data: limits.initial_stream_limits().max_data_bidi_local,
local_recv_max_data: limits.initial_stream_limits().max_data_bidi_remote,
max_idle_timeout: limits.max_idle_timeout(),
max_ack_delay: limits.max_ack_delay.into(),
}
}
}