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 by its
idle timeout, and all end when the demux stops serving. 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 and counted 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>
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 fn stats(&self) -> DemuxStatsHandle
pub fn stats(&self) -> DemuxStatsHandle
Read this demux’s counters, also while it serves.
pub async fn serve<Svc>(
self,
exec: Executor,
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,
exec: Executor,
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 exec, until the listening
socket fails or exec’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> Freeze 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,
Option<BoxService<SocketAddress, S, Box<dyn Error + Send + Sync>>>: 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