Struct WebSocketRelayService
pub struct WebSocketRelayService<S = MirrorService> { /* private fields */ }http and std and ws only.Expand description
A utility that can be used by MITM services such as transparent proxies, in order to relay WebSocket messages.
By default they get mirrored but the logic is fully up to you.
This service accepts both a raw BridgeIo and an established
WebSocketBridge. Direct raw-I/O use remains convenient and backwards
compatible. To install message-level layers, wrap this service in those
layers and then place WebSocketRelayIoService around the result.
§KISS
This service is for simple DPI purposes.
Ping and pong are handled locally on each of the two independent WebSocket connections and are not exposed to middleware. A ping is acknowledged on its source connection and also produces an unsolicited pong heartbeat on the opposite connection, so activity on one leg keeps both legs alive without coupling their ping round trips. Other pongs are not forwarded. An incoming close starts coordinated shutdown; data received while closing is discarded rather than passed to middleware.
Middleware is processed independently per direction. Its future can be cancelled when either peer starts closing, so it must be cancel-safe. A failure to send middleware-produced data terminates the relay.
Use WebSocketRelayEventService when middleware also needs to observe
control messages. Fork or create your own relay service for lower-level
purposes such as preserving raw frame boundaries.
Implementations§
§impl<S> WebSocketRelayService<S>
impl<S> WebSocketRelayService<S>
pub fn new(middleware: S) -> WebSocketRelayService<S>
pub fn new(middleware: S) -> WebSocketRelayService<S>
Create a new WebSocketRelayService
pub fn with_close_handshake_timeout(
self,
timeout: Duration,
) -> WebSocketRelayService<S>
pub fn with_close_handshake_timeout( self, timeout: Duration, ) -> WebSocketRelayService<S>
Set how long the relay waits for both peers to finish a coordinated close handshake before dropping the connections.
The default is five seconds. Both connections and their relay state remain alive until the handshake finishes or this timeout expires.
pub fn set_close_handshake_timeout(
&mut self,
timeout: Duration,
) -> &mut WebSocketRelayService<S>
pub fn set_close_handshake_timeout( &mut self, timeout: Duration, ) -> &mut WebSocketRelayService<S>
Set how long the relay waits for both peers to finish a coordinated close handshake before dropping the connections.
The default is five seconds. Both connections and their relay state remain alive until the handshake finishes or this timeout expires.
pub fn with_message_injection(self, enabled: bool) -> WebSocketRelayService<S>
pub fn with_message_injection(self, enabled: bool) -> WebSocketRelayService<S>
Enable external application-data injection through a
WebSocketRelayInjector exposed to middleware extensions.
Disabled by default, avoiding the liveness channel and extension storage for relays that do not need external message injection.
pub fn set_message_injection(
&mut self,
enabled: bool,
) -> &mut WebSocketRelayService<S>
pub fn set_message_injection( &mut self, enabled: bool, ) -> &mut WebSocketRelayService<S>
Enable external application-data injection through a
WebSocketRelayInjector exposed to middleware extensions.
Disabled by default, avoiding the liveness channel and extension storage for relays that do not need external message injection.
pub fn with_message_injection_queue_capacity(
self,
capacity: NonZero<usize>,
) -> WebSocketRelayService<S>
pub fn with_message_injection_queue_capacity( self, capacity: NonZero<usize>, ) -> WebSocketRelayService<S>
Set the maximum number of injected messages waiting per relay side.
The default is 16. Once full,
WebSocketRelayInjector::send returns
ProtocolError::WriteBufferFull without disturbing relay traffic.
pub fn set_message_injection_queue_capacity(
&mut self,
capacity: NonZero<usize>,
) -> &mut WebSocketRelayService<S>
pub fn set_message_injection_queue_capacity( &mut self, capacity: NonZero<usize>, ) -> &mut WebSocketRelayService<S>
Set the maximum number of injected messages waiting per relay side.
The default is 16. Once full,
WebSocketRelayInjector::send returns
ProtocolError::WriteBufferFull without disturbing relay traffic.
pub fn maybe_with_max_injected_message_size(
self,
max_size: Option<usize>,
) -> WebSocketRelayService<S>
pub fn maybe_with_max_injected_message_size( self, max_size: Option<usize>, ) -> WebSocketRelayService<S>
Set the maximum payload size accepted from a relay injector.
The default is 16 MiB. Use
Self::without_max_injected_message_size to disable this
injector-side limit; the destination WebSocket’s own write limits
still apply.
pub fn maybe_set_max_injected_message_size(
&mut self,
max_size: Option<usize>,
) -> &mut WebSocketRelayService<S>
pub fn maybe_set_max_injected_message_size( &mut self, max_size: Option<usize>, ) -> &mut WebSocketRelayService<S>
Set the maximum payload size accepted from a relay injector.
The default is 16 MiB. Use
Self::without_max_injected_message_size to disable this
injector-side limit; the destination WebSocket’s own write limits
still apply.
pub fn with_max_injected_message_size(
self,
max_size: usize,
) -> WebSocketRelayService<S>
pub fn with_max_injected_message_size( self, max_size: usize, ) -> WebSocketRelayService<S>
Set the maximum payload size accepted from a relay injector.
The default is 16 MiB. Use
Self::without_max_injected_message_size to disable this
injector-side limit; the destination WebSocket’s own write limits
still apply.
pub fn set_max_injected_message_size(
&mut self,
max_size: usize,
) -> &mut WebSocketRelayService<S>
pub fn set_max_injected_message_size( &mut self, max_size: usize, ) -> &mut WebSocketRelayService<S>
Set the maximum payload size accepted from a relay injector.
The default is 16 MiB. Use
Self::without_max_injected_message_size to disable this
injector-side limit; the destination WebSocket’s own write limits
still apply.
pub fn without_max_injected_message_size(self) -> WebSocketRelayService<S>
pub fn without_max_injected_message_size(self) -> WebSocketRelayService<S>
Set the maximum payload size accepted from a relay injector.
The default is 16 MiB. Use
Self::without_max_injected_message_size to disable this
injector-side limit; the destination WebSocket’s own write limits
still apply.
pub fn unset_max_injected_message_size(
&mut self,
) -> &mut WebSocketRelayService<S>
pub fn unset_max_injected_message_size( &mut self, ) -> &mut WebSocketRelayService<S>
Set the maximum payload size accepted from a relay injector.
The default is 16 MiB. Use
Self::without_max_injected_message_size to disable this
injector-side limit; the destination WebSocket’s own write limits
still apply.
Trait Implementations§
§impl<S> Clone for WebSocketRelayService<S>where
S: Clone,
impl<S> Clone for WebSocketRelayService<S>where
S: Clone,
§fn clone(&self) -> WebSocketRelayService<S>
fn clone(&self) -> WebSocketRelayService<S>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl<S> Debug for WebSocketRelayService<S>where
S: Debug,
impl<S> Debug for WebSocketRelayService<S>where
S: Debug,
§impl<S, Ingress, Egress> Service<BridgeIo<Ingress, Egress>> for WebSocketRelayService<S>where
S: Service<WebSocketRelayInput>,
<S as Service<WebSocketRelayInput>>::Output: Into<WebSocketRelayOutput>,
<S as Service<WebSocketRelayInput>>::Error: Into<Box<dyn Error + Send + Sync>>,
Ingress: Io + Unpin + ExtensionsRef,
Egress: Io + Unpin + ExtensionsRef,
impl<S, Ingress, Egress> Service<BridgeIo<Ingress, Egress>> for WebSocketRelayService<S>where
S: Service<WebSocketRelayInput>,
<S as Service<WebSocketRelayInput>>::Output: Into<WebSocketRelayOutput>,
<S as Service<WebSocketRelayInput>>::Error: Into<Box<dyn Error + Send + Sync>>,
Ingress: Io + Unpin + ExtensionsRef,
Egress: Io + Unpin + ExtensionsRef,
§async fn serve(
&self,
bridge: BridgeIo<Ingress, Egress>,
) -> Result<<WebSocketRelayService<S> as Service<BridgeIo<Ingress, Egress>>>::Output, <WebSocketRelayService<S> as Service<BridgeIo<Ingress, Egress>>>::Error>
async fn serve( &self, bridge: BridgeIo<Ingress, Egress>, ) -> Result<<WebSocketRelayService<S> as Service<BridgeIo<Ingress, Egress>>>::Output, <WebSocketRelayService<S> as Service<BridgeIo<Ingress, Egress>>>::Error>
§fn boxed(self) -> BoxService<Input, Self::Output, Self::Error>
fn boxed(self) -> BoxService<Input, Self::Output, Self::Error>
§impl<S, Ingress, Egress> Service<WebSocketBridge<Ingress, Egress>> for WebSocketRelayService<S>where
S: Service<WebSocketRelayInput>,
<S as Service<WebSocketRelayInput>>::Output: Into<WebSocketRelayOutput>,
<S as Service<WebSocketRelayInput>>::Error: Into<Box<dyn Error + Send + Sync>>,
Ingress: WebSocketIo,
Egress: WebSocketIo,
impl<S, Ingress, Egress> Service<WebSocketBridge<Ingress, Egress>> for WebSocketRelayService<S>where
S: Service<WebSocketRelayInput>,
<S as Service<WebSocketRelayInput>>::Output: Into<WebSocketRelayOutput>,
<S as Service<WebSocketRelayInput>>::Error: Into<Box<dyn Error + Send + Sync>>,
Ingress: WebSocketIo,
Egress: WebSocketIo,
§async fn serve(
&self,
__arg1: WebSocketBridge<Ingress, Egress>,
) -> Result<<WebSocketRelayService<S> as Service<WebSocketBridge<Ingress, Egress>>>::Output, <WebSocketRelayService<S> as Service<WebSocketBridge<Ingress, Egress>>>::Error>
async fn serve( &self, __arg1: WebSocketBridge<Ingress, Egress>, ) -> Result<<WebSocketRelayService<S> as Service<WebSocketBridge<Ingress, Egress>>>::Output, <WebSocketRelayService<S> as Service<WebSocketBridge<Ingress, Egress>>>::Error>
§fn boxed(self) -> BoxService<Input, Self::Output, Self::Error>
fn boxed(self) -> BoxService<Input, Self::Output, Self::Error>
Auto Trait Implementations§
impl<S> Freeze for WebSocketRelayService<S>where
S: Freeze,
impl<S> RefUnwindSafe for WebSocketRelayService<S>where
S: RefUnwindSafe,
impl<S> Send for WebSocketRelayService<S>where
S: Send,
impl<S> Sync for WebSocketRelayService<S>where
S: Sync,
impl<S> Unpin for WebSocketRelayService<S>where
S: Unpin,
impl<S> UnsafeUnpin for WebSocketRelayService<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for WebSocketRelayService<S>where
S: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<S, Input, Connection> ConnectorService<Input> for Swhere
S: Service<Input, Output = EstablishedClientConnection<Connection, Input>>,
<S as Service<Input>>::Error: Into<ConnectionError>,
Connection: Send + ExtensionsRef,
impl<S, Input, Connection> ConnectorService<Input> for Swhere
S: Service<Input, Output = EstablishedClientConnection<Connection, Input>>,
<S as Service<Input>>::Error: Into<ConnectionError>,
Connection: Send + ExtensionsRef,
§type Connection = Connection
type Connection = Connection
ConnectorService§fn connect(
&self,
input: Input,
) -> impl Future<Output = Result<EstablishedClientConnection<<S as ConnectorService<Input>>::Connection, Input>, ConnectionError>> + Send
fn connect( &self, input: Input, ) -> impl Future<Output = Result<EstablishedClientConnection<<S as ConnectorService<Input>>::Connection, Input>, ConnectionError>> + Send
§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