use core::net::SocketAddr;
use derive_more::{IsVariant, TryUnwrap, Unwrap};
cfg_storage! {
use crate::Name;
}
use crate::{
QueryHandle, ServiceHandle,
wire::{QuestionRef, Ref},
};
#[derive(Debug, Copy, Clone)]
pub struct ServiceQuestion<'a> {
question: QuestionRef<'a>,
src: SocketAddr,
query_id: u16,
truncated: bool,
}
impl<'a> ServiceQuestion<'a> {
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn new(question: QuestionRef<'a>, src: SocketAddr, query_id: u16) -> Self {
Self {
question,
src,
query_id,
truncated: false,
}
}
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn with_truncated(mut self, truncated: bool) -> Self {
self.truncated = truncated;
self
}
#[inline(always)]
pub const fn question(&self) -> &QuestionRef<'a> {
&self.question
}
#[inline(always)]
pub const fn truncated(&self) -> bool {
self.truncated
}
#[inline(always)]
pub const fn src(&self) -> SocketAddr {
self.src
}
#[inline(always)]
pub const fn query_id(&self) -> u16 {
self.query_id
}
}
#[derive(Debug, Copy, Clone)]
pub struct ProbeConflict<'a> {
src: SocketAddr,
record: Ref<'a>,
}
impl<'a> ProbeConflict<'a> {
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn new(src: SocketAddr, record: Ref<'a>) -> Self {
Self { src, record }
}
#[inline(always)]
pub const fn src(&self) -> SocketAddr {
self.src
}
#[inline(always)]
pub const fn record(&self) -> &Ref<'a> {
&self.record
}
}
#[derive(Debug, Copy, Clone)]
pub struct HostConflict<'a> {
record: Ref<'a>,
}
impl<'a> HostConflict<'a> {
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn new(record: Ref<'a>) -> Self {
Self { record }
}
#[inline(always)]
pub const fn record(&self) -> &Ref<'a> {
&self.record
}
}
#[derive(Debug, Copy, Clone)]
pub struct KnownAnswer<'a> {
src: core::net::SocketAddr,
record: Ref<'a>,
}
impl<'a> KnownAnswer<'a> {
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn new(src: core::net::SocketAddr, record: Ref<'a>) -> Self {
Self { src, record }
}
#[inline(always)]
pub const fn record(&self) -> &Ref<'a> {
&self.record
}
#[inline(always)]
pub const fn src(&self) -> core::net::SocketAddr {
self.src
}
}
#[derive(Debug, Copy, Clone, IsVariant, Unwrap, TryUnwrap)]
#[unwrap(ref)]
#[try_unwrap(ref)]
#[non_exhaustive]
pub enum ServiceEvent<'a> {
Question(ServiceQuestion<'a>),
ProbeConflict(ProbeConflict<'a>),
HostConflict(HostConflict<'a>),
KnownAnswer(KnownAnswer<'a>),
}
#[derive(Debug, Copy, Clone, IsVariant, Unwrap, TryUnwrap)]
#[unwrap(ref)]
#[try_unwrap(ref)]
#[non_exhaustive]
pub enum QueryEvent<'a> {
Answer(Ref<'a>),
Truncated,
}
#[derive(Debug, Copy, Clone)]
pub struct ToService<'a> {
handle: ServiceHandle,
event: ServiceEvent<'a>,
}
impl<'a> ToService<'a> {
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn new(handle: ServiceHandle, event: ServiceEvent<'a>) -> Self {
Self { handle, event }
}
#[inline(always)]
pub const fn handle(&self) -> ServiceHandle {
self.handle
}
#[inline(always)]
pub const fn event(&self) -> &ServiceEvent<'a> {
&self.event
}
#[inline(always)]
pub const fn into_event(self) -> ServiceEvent<'a> {
self.event
}
}
#[derive(Debug, Copy, Clone)]
pub struct ToQuery<'a> {
handle: QueryHandle,
event: QueryEvent<'a>,
}
impl<'a> ToQuery<'a> {
#[allow(dead_code)]
#[inline(always)]
pub(crate) const fn new(handle: QueryHandle, event: QueryEvent<'a>) -> Self {
Self { handle, event }
}
#[inline(always)]
pub const fn handle(&self) -> QueryHandle {
self.handle
}
#[inline(always)]
pub const fn event(&self) -> &QueryEvent<'a> {
&self.event
}
#[inline(always)]
pub const fn into_event(self) -> QueryEvent<'a> {
self.event
}
}
#[derive(Debug, Copy, Clone, IsVariant, Unwrap, TryUnwrap)]
#[unwrap(ref)]
#[try_unwrap(ref)]
#[non_exhaustive]
pub enum RouteEvent<'a> {
ToService(ToService<'a>),
ToQuery(ToQuery<'a>),
CacheUpdated,
}
cfg_storage! {
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ServiceRenamed {
new_name: Name,
}
const _: () = {
impl ServiceRenamed {
#[doc(hidden)]
#[inline(always)]
pub fn new(new_name: Name) -> Self {
Self { new_name }
}
#[inline(always)]
pub fn new_name(&self) -> &Name {
&self.new_name
}
}
};
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone, IsVariant, Unwrap, TryUnwrap)]
#[unwrap(ref)]
#[try_unwrap(ref)]
#[non_exhaustive]
pub enum ServiceUpdate {
Established,
Renamed(ServiceRenamed),
Conflict,
HostConflict,
}
}
#[derive(Debug, Clone, Copy, IsVariant, Unwrap, TryUnwrap)]
#[unwrap(ref)]
#[try_unwrap(ref)]
#[non_exhaustive]
pub enum QueryUpdate {
Timeout,
Done,
}
#[derive(Debug, Copy, Clone, IsVariant, Unwrap, TryUnwrap)]
#[unwrap(ref)]
#[try_unwrap(ref)]
#[non_exhaustive]
pub enum EndpointEvent {
CacheExpired,
}