Struct DatagramDemux
pub struct DatagramDemux<S> { /* private fields */ }std and udp only.Expand description
Splits the datagrams of one listening socket into an association per (local, peer)
address pair, each served by its own service as a DemuxedSocket: the datagram
counterpart of accepting connections.
Every association is bounded: by DemuxConfig::associations, by its queue and its
DemuxBytes::association, and by its idle timeout, and all end when the demux stops
serving; every datagram dropped is counted in its DemuxDrops. A reply leaves the
listening socket for the association’s peer only, from the address the client sent to. A
transparently redirected datagram, whose original destination is not the listening address,
cannot be answered from there; it is dropped rather than answered from the wrong address,
unless the socket selects a reply’s whole source (DatagramCapabilities::send_source_port
with send_source_ip), as a transparent proxy flow does, or the demux can bind a socket at
that destination (DatagramDemux::with_reply_sockets): then every original destination is
an association of its own, answered from that destination. A redirected association carries
its original destination as its ConnectorTarget, which one addressed to this listener
itself never has (its port and its IP, or for a wildcard listener also loopback or any of
the host’s addresses), so a bridge cannot loop it back. Admission and inspection limits
belong to the association’s service.
Implementations§
§impl<S> DatagramDemux<S>where
S: DatagramSocket,
impl<S> DatagramDemux<S>where
S: DatagramSocket,
pub fn new(socket: S, config: DemuxConfig) -> DatagramDemux<S>
pub fn with_drops(self, drops: DemuxDrops) -> DatagramDemux<S>
pub fn with_drops(self, drops: DemuxDrops) -> DatagramDemux<S>
Count the datagrams this demux drops in drops, which other demuxes may share.
pub fn drops(&self) -> DemuxDrops
pub fn drops(&self) -> DemuxDrops
The counts of the datagrams this demux drops, readable while it serves.
Hold what this demux queues within budget too, which other demuxes may share.
pub fn with_reply_sockets<B>(self, bind: B) -> DatagramDemux<S>where
B: Service<SocketAddress, Output = S>,
<B as Service<SocketAddress>>::Error: Into<Box<dyn Error + Send + Sync>>,
pub fn with_reply_sockets<B>(self, bind: B) -> DatagramDemux<S>where
B: Service<SocketAddress, Output = S>,
<B as Service<SocketAddress>>::Error: Into<Box<dyn Error + Send + Sync>>,
Answer a redirected datagram the listening socket cannot from a socket that bind
binds at its original destination, as a transparent proxy must for a client that
accepts replies only from where it sent to.
Associations addressed to one destination share its socket, which closes with the
last of them and is read too, since redirection may deliver to it. On Linux, a
UdpSocketFactory binds such sockets when its
SocketOptions set ip_transparent,
ip_transparent_v6 and reuse_address.
pub async fn serve<Svc>(
self,
weak_scope: WeakScope,
service: Svc,
) -> Result<(), DatagramError>where
S: Send + 'static,
<S as DatagramSocket>::Sender: Clone,
Svc: Service<DemuxedSocket<<S as DatagramSocket>::Sender>> + Clone,
<Svc as Service<DemuxedSocket<<S as DatagramSocket>::Sender>>>::Error: Into<Box<dyn Error + Send + Sync>>,
pub async fn serve<Svc>(
self,
weak_scope: WeakScope,
service: Svc,
) -> Result<(), DatagramError>where
S: Send + 'static,
<S as DatagramSocket>::Sender: Clone,
Svc: Service<DemuxedSocket<<S as DatagramSocket>::Sender>> + Clone,
<Svc as Service<DemuxedSocket<<S as DatagramSocket>::Sender>>>::Error: Into<Box<dyn Error + Send + Sync>>,
Serve every new association with service, spawned on scope, until the listening
socket fails or scope’s graceful shutdown begins.
Trait Implementations§
§impl<S> Debug for DatagramDemux<S>where
S: Debug,
impl<S> Debug for DatagramDemux<S>where
S: Debug,
§impl<S> Drop for DatagramDemux<S>
A demux that stops serving ends its associations too: nothing more arrives for them.
impl<S> Drop for DatagramDemux<S>
A demux that stops serving ends its associations too: nothing more arrives for them.
Auto Trait Implementations§
impl<S> !RefUnwindSafe for DatagramDemux<S>
impl<S> !UnwindSafe for DatagramDemux<S>
impl<S> Forget for DatagramDemux<S>
impl<S> Freeze for DatagramDemux<S>where
S: Freeze,
NonZero<usize>: Freeze,
*const ArcInner<Mutex<RawMutex, Registry>> is !null: Freeze,
PhantomData<ArcInner<Mutex<RawMutex, Registry>>>: Freeze,
*const ArcInner<Atomic<usize>> is !null: Freeze,
PhantomData<ArcInner<Atomic<usize>>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<IpAddr>: Freeze,
*const ArcInner<dyn DynService<SocketAddress, Output = S, Error = Box<dyn Error + Send + Sync>> + Send + Sync> is !null: Freeze,
PhantomData<ArcInner<dyn DynService<SocketAddress, Output = S, Error = Box<dyn Error + Send + Sync>> + Send + Sync>>: Freeze,
*const ArcInner<Shared> is !null: Freeze,
PhantomData<ArcInner<Shared>>: Freeze,
*const ArcInner<Counters> is !null: Freeze,
PhantomData<ArcInner<Counters>>: Freeze,
impl<S> Move for DatagramDemux<S>
impl<S> Send for DatagramDemux<S>
impl<S> Sync for DatagramDemux<S>
impl<S> Unpin for DatagramDemux<S>
impl<S> UnsafeUnpin for DatagramDemux<S>where
S: UnsafeUnpin,
NonZeroUsizeInner: UnsafeUnpin,
*const ArcInner<Mutex<RawMutex, Registry>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<RawMutex, Registry>>>: UnsafeUnpin,
*const ArcInner<Atomic<usize>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Atomic<usize>>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<IpAddr>: UnsafeUnpin,
*const ArcInner<dyn DynService<SocketAddress, Output = S, Error = Box<dyn Error + Send + Sync>> + Send + Sync> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn DynService<SocketAddress, Output = S, Error = Box<dyn Error + Send + Sync>> + Send + Sync>>: UnsafeUnpin,
*const ArcInner<Shared> is !null: UnsafeUnpin,
PhantomData<ArcInner<Shared>>: UnsafeUnpin,
*const ArcInner<Counters> is !null: UnsafeUnpin,
PhantomData<ArcInner<Counters>>: UnsafeUnpin,
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more