use std::net::SocketAddr;
use bornera_core::{ConnectionEpoch, ConnectionId, EndpointId, LaneId};
use calandria::{Deadline, ResourceOwnerId, TimerOwnerId};
use crate::TcpSocketPolicy;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct ConnectionIdentity {
endpoint: EndpointId,
lane: LaneId,
connection: ConnectionId,
epoch: ConnectionEpoch,
}
impl ConnectionIdentity {
pub const fn new(
endpoint: EndpointId,
lane: LaneId,
connection: ConnectionId,
epoch: ConnectionEpoch,
) -> Self {
Self {
endpoint,
lane,
connection,
epoch,
}
}
pub const fn endpoint(self) -> EndpointId {
self.endpoint
}
pub const fn lane(self) -> LaneId {
self.lane
}
pub const fn connection(self) -> ConnectionId {
self.connection
}
pub const fn epoch(self) -> ConnectionEpoch {
self.epoch
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ConnectionSlotConfig {
identity: ConnectionIdentity,
connect_deadline: Deadline,
timer_owner: TimerOwnerId,
socket_policy: TcpSocketPolicy,
}
impl ConnectionSlotConfig {
pub const fn new(
identity: ConnectionIdentity,
connect_deadline: Deadline,
timer_owner: TimerOwnerId,
) -> Self {
Self {
identity,
connect_deadline,
timer_owner,
socket_policy: TcpSocketPolicy::DEFAULT,
}
}
#[must_use]
pub const fn socket_policy(mut self, policy: TcpSocketPolicy) -> Self {
self.socket_policy = policy;
self
}
pub(crate) const fn identity(self) -> ConnectionIdentity {
self.identity
}
pub(crate) const fn connect_deadline(self) -> Deadline {
self.connect_deadline
}
pub(crate) const fn timer_owner(self) -> TimerOwnerId {
self.timer_owner
}
pub(crate) const fn tcp_policy(self) -> TcpSocketPolicy {
self.socket_policy
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ConnectionConfig {
slot: ConnectionSlotConfig,
address: SocketAddr,
}
impl ConnectionConfig {
pub const fn new(
identity: ConnectionIdentity,
address: SocketAddr,
connect_deadline: Deadline,
timer_owner: TimerOwnerId,
) -> Self {
Self {
slot: ConnectionSlotConfig::new(identity, connect_deadline, timer_owner),
address,
}
}
#[must_use]
pub const fn socket_policy(mut self, policy: TcpSocketPolicy) -> Self {
self.slot = self.slot.socket_policy(policy);
self
}
pub(crate) const fn identity(self) -> ConnectionIdentity {
self.slot.identity()
}
pub(crate) const fn address(self) -> SocketAddr {
self.address
}
pub(crate) const fn slot(self) -> ConnectionSlotConfig {
self.slot
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ConnectionSetConfig {
resource_owner: ResourceOwnerId,
}
impl ConnectionSetConfig {
pub const fn new(resource_owner: ResourceOwnerId) -> Self {
Self { resource_owner }
}
pub(crate) const fn resource_owner(self) -> ResourceOwnerId {
self.resource_owner
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct StandaloneConnectionConfig {
set: ConnectionSetConfig,
connection: ConnectionConfig,
}
impl StandaloneConnectionConfig {
pub const fn new(set: ConnectionSetConfig, connection: ConnectionConfig) -> Self {
Self { set, connection }
}
pub(crate) const fn set(self) -> ConnectionSetConfig {
self.set
}
pub(crate) const fn connection(self) -> ConnectionConfig {
self.connection
}
}